From: W. Trevor King Date: Sat, 8 Feb 2014 22:21:56 +0000 (+1600) Subject: [PATCH] nmbug: Add 'clone' and replace FETCH_HEAD with @{upstream} X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ed33fc0f4696e0969e1952681d4c1d5614ba0fed;p=notmuch-archives.git [PATCH] nmbug: Add 'clone' and replace FETCH_HEAD with @{upstream} --- diff --git a/d6/057719285f9b0020fd31c41b126abc1ae1ad59 b/d6/057719285f9b0020fd31c41b126abc1ae1ad59 new file mode 100644 index 000000000..86cab5d8c --- /dev/null +++ b/d6/057719285f9b0020fd31c41b126abc1ae1ad59 @@ -0,0 +1,301 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id EE642431FBD + for ; Sat, 8 Feb 2014 14:22:11 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.1 +X-Spam-Level: +X-Spam-Status: No, score=-0.1 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 8qDefOaO-4zx for ; + Sat, 8 Feb 2014 14:22:04 -0800 (PST) +Received: from qmta06.westchester.pa.mail.comcast.net + (qmta06.westchester.pa.mail.comcast.net [76.96.62.56]) + by olra.theworths.org (Postfix) with ESMTP id 9E88A431FBC + for ; Sat, 8 Feb 2014 14:22:04 -0800 (PST) +Received: from omta10.westchester.pa.mail.comcast.net ([76.96.62.28]) + by qmta06.westchester.pa.mail.comcast.net with comcast + id PyKz1n0050cZkys56yN4fV; Sat, 08 Feb 2014 22:22:04 +0000 +Received: from odin.tremily.us ([24.18.63.50]) + by omta10.westchester.pa.mail.comcast.net with comcast + id PyN21n011152l3L3WyN3qs; Sat, 08 Feb 2014 22:22:04 +0000 +Received: by odin.tremily.us (Postfix, from userid 1000) + id 9B1B9100CE27; Sat, 8 Feb 2014 14:22:02 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tremily.us; s=odin; + t=1391898122; bh=o75bWkeWM0p2RXTBJ3lBe0hiw5/97kKcUod/5gi1uD8=; + h=From:To:Cc:Subject:Date; + b=KRXpRjE4Mv9/mJpgRox6+mlXco3JJiXrqqpsHzliMDmB7vneLeY4BwVbKznDTU8ty + 9YnZAOGwIwXEr7WF5NXL7I9Vq1UAMoWV2nkXqiiT4sErFi9BHxp8Clr8lWrAPtxJ1p + zTVIdOBHdCi+mMbsvK84Kbj4+R7buwgSil6O0VE4= +From: "W. Trevor King" +To: notmuch@notmuchmail.org +Subject: [PATCH] nmbug: Add 'clone' and replace FETCH_HEAD with @{upstream} +Date: Sat, 8 Feb 2014 14:21:56 -0800 +Message-Id: + <80db13662a0313711ca3a91e338a63d35e64a83c.1391898002.git.wking@tremily.us> +X-Mailer: git-send-email 1.8.3.2 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; + s=q20121106; t=1391898124; + bh=bmBTU1oJm+L9LEh/+EQcR5h/juBlcwMTDf00HAHRAno=; + h=Received:Received:Received:From:To:Subject:Date:Message-Id: + MIME-Version:Content-Type; + b=MJ458FFdKX88XxPL/2j3r2/GBNZRYbeIFZiX0HonsxyFnPxxeOCM4SMmW1gCYQu3E + H7Wjm9kgJEXerpWXhVRk6iJ4YbxYYPW23n8lt8edTUuEHuXS1ibHm98gb3PjWhKsNo + TYumjEjbmlG2wSwxKp1QErDbuVTkoke9zJ4pUQtonlK+MOaEyiR3l7XUW3l62SuH1Q + 42H0O0uIGRw24jpRLpttGx2CUQIf6fqhZspCfE8khPDuD0pr78cGx/jIOeBg8JRcj9 + /jHAZ7vHHSUJ5vnWbYrMAdNX9CrO+5pIK0B5OKUTEhT+ohTIdv0aAJ5Nwx1HHqICJG + AHg2WH4ozuJeg== +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 08 Feb 2014 22:22:12 -0000 + +From: "W. Trevor King" + +With two branches getting fetched (master and config), the branch +referenced by FETCH_HEAD is ambiguous. For example, I have: + + $ cat FETCH_HEAD + 41d7bfa7184cc93c9dac139d1674e9530799e3b0 \ + not-for-merge branch 'config' of http://nmbug.tethera.net/git/nmbug-tags + acd379ccb973c45713eee9db177efc530f921954 \ + not-for-merge branch 'master' of http://nmbug.tethera.net/git/nmbug-tags + +(where I wrapped the line by hand). This means that FETCH_HEAD +references the config branch: + + $ git rev-parse FETCH_HEAD + 41d7bfa7184cc93c9dac139d1674e9530799e3b0 + +which breaks all of the FETCH_HEAD logic in nmbug (where FETCH_HEAD is +assumed to point to the master branch). + +Instead of relying on FETCH_HEAD, use @{upstream} as the +remote-tracking branch that should be merged/diffed/integrated into +HEAD. @{upstream} was added in Git v1.7.0 (2010-02-12) [1], so +relying on it should be fairly safe. One tricky bit is that bare +repositories don't set upstream tracking branches by default: + + $ git clone --bare http://nmbug.tethera.net/git/nmbug-tags.git nmbug-bare + $ cd nmbug-bare + $ git remote show origin + * remote origin + Fetch URL: http://nmbug.tethera.net/git/nmbug-tags.git + Push URL: http://nmbug.tethera.net/git/nmbug-tags.git + HEAD branch: master + Local refs configured for 'git push': + config pushes to config (up to date) + master pushes to master (up to date) + +While in a non-bare clone: + + $ git clone http://nmbug.tethera.net/git/nmbug-tags.git + $ cd nmbug-tags + $ git remote show origin + * remote origin + Fetch URL: http://nmbug.tethera.net/git/nmbug-tags.git + Push URL: http://nmbug.tethera.net/git/nmbug-tags.git + HEAD branch: master + Remote branches: + config tracked + master tracked + Local branch configured for 'git pull': + master merges with remote master + Local ref configured for 'git push': + master pushes to master (up to date) + +>From the clone docs [2]: + + --bare:: + Make a 'bare' Git repository… + Also the branch heads at the remote are copied directly + to corresponding local branch heads, without mapping + them to `refs/remotes/origin/`. When this option is + used, neither remote-tracking branches nor the related + configuration variables are created. + +To use @{upstream}, we need to restore the local vs. remote-tracking +distinction, so this commit adds 'nmbug clone', which adds the +following configuration adjustments: + + $ git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*' + $ git config branch.$branch.remote origin + $ git config branch.$branch.merge refs/heads/$branch + +where $branch is the branch referenced by the remote's HEAD, which +'git clone' uses to setup the local branch. After tweaking the +config, we populate the new remote-tracking branches with: + + $ git fetch origin + +After which: + + $ git rev-parse @{upstream} + acd379ccb973c45713eee9db177efc530f921954 + +gives us the master-branch commit. Existing nmbug users will have to +run the configuration tweaks and re-fetch by hand. If you don't have +any local commits, you could also blow away your NMBGIT repository and +re-clone from scratch: + + $ nmbug clone http://nmbug.tethera.net/git/nmbug-tags.git + +Besides removing the ambiguity of FETCH_HEAD, this commit allows users +to configure which upstream branch they want nmbug to track via 'git +config', in case they want to change their upstream repository. + +[1]: http://git.kernel.org/cgit/git/git.git/tree/Documentation/RelNotes/1.7.0.txt +[2]: http://git.kernel.org/cgit/git/git.git/tree/Documentation/git-clone.txt +--- + devel/nmbug/nmbug | 49 +++++++++++++++++++++++++++++++++++-------------- + 1 file changed, 35 insertions(+), 14 deletions(-) + +diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug +index 90d98b6..3c1d597 100755 +--- a/devel/nmbug/nmbug ++++ b/devel/nmbug/nmbug +@@ -26,6 +26,7 @@ my $ESCAPED_RX = qr{$ESCAPE_CHAR([A-Fa-f0-9]{2})}; + my %command = ( + archive => \&do_archive, + checkout => \&do_checkout, ++ clone => \&do_clone, + commit => \&do_commit, + fetch => \&do_fetch, + help => \&do_help, +@@ -125,6 +126,17 @@ sub do_archive { + system ('git', "--git-dir=$NMBGIT", 'archive', 'HEAD'); + } + ++sub do_clone { ++ my $repository = shift; ++ system ('git', 'clone', '--bare', $repository, $NMBGIT) == 0 ++ or die "'git clone' exited with nonzero value\n"; ++ my $branch = git ('symbolic-ref', 'HEAD'); ++ $branch =~ s|^refs/heads/||; ++ git ('config', 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*'); ++ git ('config', "branch.$branch.remote", 'origin'); ++ git ('config', "branch.$branch.merge", 'refs/heads/$branch'); ++ do_fetch(); ++} + + sub is_committed { + my $status = shift; +@@ -332,21 +344,24 @@ To discard your changes, run 'nmbug checkout' + + sub do_pull { + my $remote = shift || 'origin'; ++ my $branch = shift || 'master'; + + git ( 'fetch', $remote); + +- do_merge (); ++ do_merge ("$remote/$branch"); + } + + + sub do_merge { ++ my $commit = shift || '@{upstream}'; ++ + insist_committed (); + + my $tempwork = tempdir ('/tmp/nmbug-merge.XXXXXX', CLEANUP => 1); + + git ( { GIT_WORK_TREE => $tempwork }, 'checkout', '-f', 'HEAD'); + +- git ( { GIT_WORK_TREE => $tempwork }, 'merge', 'FETCH_HEAD'); ++ git ( { GIT_WORK_TREE => $tempwork }, 'merge', $commit); + + do_checkout (); + } +@@ -407,13 +422,12 @@ sub do_status { + + + sub is_unmerged { ++ my $commit = shift || '@{upstream}'; + +- return 0 if (! -f $NMBGIT.'/FETCH_HEAD'); +- +- my $fetch_head = git ('rev-parse', 'FETCH_HEAD'); +- my $base = git ( 'merge-base', 'HEAD', 'FETCH_HEAD'); ++ my $upstream = git ('rev-parse', $commit); ++ my $base = git ( 'merge-base', 'HEAD', $commit); + +- return ($base ne $fetch_head); ++ return ($base ne $upstream); + + } + +@@ -473,7 +487,7 @@ sub diff_index { + sub diff_refs { + my $filter = shift; + my $ref1 = shift || 'HEAD'; +- my $ref2 = shift || 'FETCH_HEAD'; ++ my $ref2 = shift || '@{upstream}'; + + my $fh= git_pipe ( 'diff', "--diff-filter=$filter", '--name-only', + $ref1, $ref2); +@@ -561,10 +575,11 @@ git. Any extra arguments are used (one per line) as a commit message. + + push local nmbug git state to remote repo + +-=item B [remote] ++=item B [remote] [branch] + + pull (merge) remote repo changes to notmuch. B is equivalent to +-B followed by B. ++B followed by B. The default remote is C, and ++the default branch is C. + + =back + +@@ -572,6 +587,12 @@ B followed by B. + + =over 8 + ++=item B repository ++ ++Create a local nmbug repository from a remote source. This wraps ++C, adding some configuration adjustments to setup ++remote-tracking branches and upstreams. ++ + =item B + + Update the notmuch database from git. This is mainly useful to discard +@@ -589,12 +610,12 @@ print help [for subcommand] + =item B [parameters] + + A simple wrapper for git log. After running C, you can +-inspect the changes with C ++inspect the changes with C + +-=item B ++=item B [commit] + +-Merge changes from FETCH_HEAD into HEAD, and load the result into +-notmuch. ++Merge changes from C into HEAD, and load the result into ++notmuch. The default commit is C<@{upstream}>. + + =item B + +-- +1.8.3.2 +