git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: git@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] Fix branches file configuration
Date: Wed, 26 Mar 2008 01:03:01 -0700	[thread overview]
Message-ID: <7v7ifpgbey.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 7v4paugcyn.fsf@gitster.siamese.dyndns.org

From: Daniel Barkalow <barkalow@iabervon.org>
Date: Tue, 25 Mar 2008 19:35:28 -0400
Subject: [PATCH] Fix branches file configuration

Fetched remote branch from .git/branches/foo should fetch into
refs/heads/foo.  Also when partial URL is given, the fetched head should
always be remote HEAD, and the result should not be stored anywhere.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 Junio C Hamano <gitster@pobox.com> writes:

 > Daniel Barkalow <barkalow@iabervon.org> writes:
 >
 >> ... (See line 115 of 755225de:git-parse-remote.sh)
 >
 > Yeah, sounds like it.  Will queue in 'next', for eventual inclusion in
 > 'maint'.  This is a 1.5.4 regression fix, together with "push --tags" fix
 > we discussed today.

 Actually there seems to be one more difference.  Here is what I think is
 needed for 'maint'.

 remote.c |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/remote.c b/remote.c
index 95d65a0..d8a4671 100644
--- a/remote.c
+++ b/remote.c
@@ -171,7 +171,7 @@ static void read_branches_file(struct remote *remote)
 {
 	const char *slash = strchr(remote->name, '/');
 	char *frag;
-	char *branch;
+	struct strbuf branch;
 	int n = slash ? slash - remote->name : 1000;
 	FILE *f = fopen(git_path("branches/%.*s", n, remote->name), "r");
 	char *s, *p;
@@ -197,17 +197,33 @@ static void read_branches_file(struct remote *remote)
 	strcpy(p, s);
 	if (slash)
 		strcat(p, slash);
+
+	/*
+	 * With "slash", e.g. "git fetch jgarzik/netdev-2.6" when
+	 * reading from $GIT_DIR/branches/jgarzik fetches "HEAD" from
+	 * the partial URL obtained from the branches file plus
+	 * "/netdev-2.6" and does not store it in any tracking ref.
+	 * #branch specifier in the file is ignored.
+	 *
+	 * Otherwise, the branches file would have URL and optionally
+	 * #branch specified.  The "master" (or specified) branch is
+	 * fetched and stored in the local branch of the same name.
+	 */
+	strbuf_init(&branch, 0);
 	frag = strchr(p, '#');
 	if (frag) {
 		*(frag++) = '\0';
-		branch = xmalloc(strlen(frag) + 12);
-		strcpy(branch, "refs/heads/");
-		strcat(branch, frag);
+		strbuf_addf(&branch, "refs/heads/%s", frag);
+	} else
+		strbuf_addstr(&branch, "refs/heads/master");
+	if (!slash) {
+		strbuf_addf(&branch, ":refs/heads/%s", remote->name);
 	} else {
-		branch = "refs/heads/master";
+		strbuf_reset(&branch);
+		strbuf_addstr(&branch, "HEAD:");
 	}
 	add_url(remote, p);
-	add_fetch_refspec(remote, branch);
+	add_fetch_refspec(remote, strbuf_detach(&branch, 0));
 	remote->fetch_tags = 1; /* always auto-follow */
 }
 
-- 
1.5.5.rc1.128.g340c

  reply	other threads:[~2008-03-26  8:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-25 23:35 [PATCH] Fix branches file configuration Daniel Barkalow
2008-03-25 23:50 ` Andrew Morton
2008-03-25 23:56 ` Junio C Hamano
2008-03-26  0:03   ` Andrew Morton
2008-03-26  6:51   ` Daniel Barkalow
2008-03-26  7:29     ` Junio C Hamano
2008-03-26  8:03       ` Junio C Hamano [this message]
2008-03-26  8:33 ` [PATCH] git-fetch test: test tracking fetch results, not just FETCH_HEAD Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v7ifpgbey.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=akpm@linux-foundation.org \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).