Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Tue, 19 Feb 2008, Jay Soffian wrote:

> On Feb 19, 2008 5:55 AM, Johannes Schindelin <Johannes.Schindelin@xxxxxx> wrote:
> >
> > Ah, yes.  But I still maintain that xstrdup()ing orig_ref only to free 
> > it later is ugly.  Why not have the "tracking.src ? tracking.src : 
> > orig_ref" as I suggested?  The free() obviously can stay, since it 
> > will say "free(NULL)" in the case of tracking.matches == 0.
> 
> How about this?
> 
> static int setup_tracking(const char *new_ref, const char *orig_ref,
>                           enum branch_track track)
> {
> 	char key[1024];
> 	struct tracking tracking;
> 
> 	if (strlen(new_ref) > 1024 - 7 - 7 - 1)
> 		return error("Tracking not set up: name too long: %s",
> 				new_ref);
> 
> 	memset(&tracking, 0, sizeof(tracking));
> 	tracking.spec.dst = (char *)orig_ref;
> 	if (for_each_remote(find_tracked_branch, &tracking))
> 		return 1;
> 
> 	if (!tracking.matches && track != BRANCH_TRACK_ALWAYS)
> 		return 1;
> 
> 	if (tracking.matches > 1)
> 		return error("Not tracking: ambiguous information for ref %s",
> 				orig_ref);
> 
> 	sprintf(key, "branch.%s.remote", new_ref);
> 	git_config_set(key, tracking.remote ?  tracking.remote : ".");
> 	sprintf(key, "branch.%s.merge", new_ref);
> 	git_config_set(key, tracking.src ? tracking.src : orig_ref);
> 	free(tracking.src);
> 	printf("Branch %s set up to track %s branch %s.\n", new_ref,
> 		tracking.remote ? "remote" : "local", orig_ref);
> 
> 	return 0;
> }

I like it.

Ciao,
Dscho

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux