git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Fix branches file configuration

From
AMAndrew Morton <akpm@linux-foundation.org>
Date
Mar 25, 2008, 23:50 UTC
Message-ID
<20080325165027.c23b6ebb.akpm@linux-foundation.org>
In-Reply-To
<alpine.LNX.1.00.0803251931500.19665@iabervon.org>
On Tue, 25 Mar 2008 19:35:28 -0400 (EDT) Daniel Barkalow <barkalow@iabervon.org> wrote:
Show 12 quoted lines
> It turns out that .git/branches/foo should fetch into refs/heads/foo.
> 
> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
> ---
> We still don't have a test for that bit of the behavior, so I could have 
> it still doing the wrong thing. But it at least should do what I think 
> people want.
> 
> Andrew, could you give this a try, on top of current master (or, for that 
> matter, any released version that doesn't work), and let me know if it 
> does the wrong thing?
> 
I tried it on 1.5.5-rc1.  It seems to dtrt from a quick test.
Show 39 quoted lines
> diff --git a/remote.c b/remote.c
> index 40ed246..a027bca 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -232,7 +232,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;
> @@ -258,17 +258,16 @@ static void read_branches_file(struct remote *remote)
>  	strcpy(p, s);
>  	if (slash)
>  		strcat(p, slash);
> +	strbuf_init(&branch, 0);
>  	frag = strchr(p, '#');
>  	if (frag) {
>  		*(frag++) = '\0';
> -		branch = xmalloc(strlen(frag) + 12);
> -		strcpy(branch, "refs/heads/");
> -		strcat(branch, frag);
> -	} else {
> -		branch = "refs/heads/master";
> -	}
> +		strbuf_addf(&branch, "refs/heads/%s", frag);
> +	} else
> +		strbuf_addstr(&branch, "refs/heads/master");
>  	add_url_alias(remote, p);
> -	add_fetch_refspec(remote, branch);
> +	strbuf_addf(&branch, ":refs/heads/%s", remote->name);
> +	add_fetch_refspec(remote, strbuf_detach(&branch, 0));
>  	remote->fetch_tags = 1; /* always auto-follow */
>  }
>  
> -- 
> 1.5.4.3.610.gea6cd
Previous: Daniel BarkalowNext: Junio C Hamano
Message 2 of 8 in “Fix branches file configuration”
  1. Fix branches file configurationDaniel Barkalow, Mar 25, 2008
  2. Andrew MortonMar 25, 2008
  3. Junio C HamanoMar 25, 2008
  4. Andrew MortonMar 26, 2008
  5. Daniel BarkalowMar 26, 2008
  6. Junio C HamanoMar 26, 2008
  7. Junio C HamanoMar 26, 2008
  8. git-fetch test: test tracking fetch results, not just FETCH_HEADJunio C Hamano, Mar 26, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.