branch: colour upstream branches
Otherwise when using 'git branch -vv' it's hard to see them among so much output. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									924f6c3d39
								
							
						
					
					
						commit
						dbda21fa87
					
				|  | @ -807,7 +807,8 @@ color.branch:: | ||||||
| color.branch.<slot>:: | color.branch.<slot>:: | ||||||
| 	Use customized color for branch coloration. `<slot>` is one of | 	Use customized color for branch coloration. `<slot>` is one of | ||||||
| 	`current` (the current branch), `local` (a local branch), | 	`current` (the current branch), `local` (a local branch), | ||||||
| 	`remote` (a remote-tracking branch in refs/remotes/), `plain` (other | 	`remote` (a remote-tracking branch in refs/remotes/), | ||||||
|  | 	`upstream` (upstream tracking branch), `plain` (other | ||||||
| 	refs). | 	refs). | ||||||
| + | + | ||||||
| The value for these configuration variables is a list of colors (at most | The value for these configuration variables is a list of colors (at most | ||||||
|  |  | ||||||
|  | @ -41,13 +41,15 @@ static char branch_colors[][COLOR_MAXLEN] = { | ||||||
| 	GIT_COLOR_RED,		/* REMOTE */ | 	GIT_COLOR_RED,		/* REMOTE */ | ||||||
| 	GIT_COLOR_NORMAL,	/* LOCAL */ | 	GIT_COLOR_NORMAL,	/* LOCAL */ | ||||||
| 	GIT_COLOR_GREEN,	/* CURRENT */ | 	GIT_COLOR_GREEN,	/* CURRENT */ | ||||||
|  | 	GIT_COLOR_BLUE,		/* UPSTREAM */ | ||||||
| }; | }; | ||||||
| enum color_branch { | enum color_branch { | ||||||
| 	BRANCH_COLOR_RESET = 0, | 	BRANCH_COLOR_RESET = 0, | ||||||
| 	BRANCH_COLOR_PLAIN = 1, | 	BRANCH_COLOR_PLAIN = 1, | ||||||
| 	BRANCH_COLOR_REMOTE = 2, | 	BRANCH_COLOR_REMOTE = 2, | ||||||
| 	BRANCH_COLOR_LOCAL = 3, | 	BRANCH_COLOR_LOCAL = 3, | ||||||
| 	BRANCH_COLOR_CURRENT = 4 | 	BRANCH_COLOR_CURRENT = 4, | ||||||
|  | 	BRANCH_COLOR_UPSTREAM = 5 | ||||||
| }; | }; | ||||||
|  |  | ||||||
| static enum merge_filter { | static enum merge_filter { | ||||||
|  | @ -72,6 +74,8 @@ static int parse_branch_color_slot(const char *var, int ofs) | ||||||
| 		return BRANCH_COLOR_LOCAL; | 		return BRANCH_COLOR_LOCAL; | ||||||
| 	if (!strcasecmp(var+ofs, "current")) | 	if (!strcasecmp(var+ofs, "current")) | ||||||
| 		return BRANCH_COLOR_CURRENT; | 		return BRANCH_COLOR_CURRENT; | ||||||
|  | 	if (!strcasecmp(var+ofs, "upstream")) | ||||||
|  | 		return BRANCH_COLOR_UPSTREAM; | ||||||
| 	return -1; | 	return -1; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -418,36 +422,52 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name, | ||||||
| 	int ours, theirs; | 	int ours, theirs; | ||||||
| 	char *ref = NULL; | 	char *ref = NULL; | ||||||
| 	struct branch *branch = branch_get(branch_name); | 	struct branch *branch = branch_get(branch_name); | ||||||
|  | 	struct strbuf fancy = STRBUF_INIT; | ||||||
|  |  | ||||||
| 	if (!stat_tracking_info(branch, &ours, &theirs)) { | 	if (!stat_tracking_info(branch, &ours, &theirs)) { | ||||||
| 		if (branch && branch->merge && branch->merge[0]->dst && | 		if (branch && branch->merge && branch->merge[0]->dst && | ||||||
| 		    show_upstream_ref) | 		    show_upstream_ref) { | ||||||
| 			strbuf_addf(stat, "[%s] ", | 			ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0); | ||||||
| 			    shorten_unambiguous_ref(branch->merge[0]->dst, 0)); | 			if (want_color(branch_use_color)) | ||||||
|  | 				strbuf_addf(stat, "[%s%s%s] ", | ||||||
|  | 						branch_get_color(BRANCH_COLOR_UPSTREAM), | ||||||
|  | 						ref, branch_get_color(BRANCH_COLOR_RESET)); | ||||||
|  | 			else | ||||||
|  | 				strbuf_addf(stat, "[%s] ", ref); | ||||||
|  | 		} | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (show_upstream_ref) | 	if (show_upstream_ref) { | ||||||
| 		ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0); | 		ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0); | ||||||
|  | 		if (want_color(branch_use_color)) | ||||||
|  | 			strbuf_addf(&fancy, "%s%s%s", | ||||||
|  | 					branch_get_color(BRANCH_COLOR_UPSTREAM), | ||||||
|  | 					ref, branch_get_color(BRANCH_COLOR_RESET)); | ||||||
|  | 		else | ||||||
|  | 			strbuf_addstr(&fancy, ref); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if (!ours) { | 	if (!ours) { | ||||||
| 		if (ref) | 		if (ref) | ||||||
| 			strbuf_addf(stat, _("[%s: behind %d]"), ref, theirs); | 			strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs); | ||||||
| 		else | 		else | ||||||
| 			strbuf_addf(stat, _("[behind %d]"), theirs); | 			strbuf_addf(stat, _("[behind %d]"), theirs); | ||||||
|  |  | ||||||
| 	} else if (!theirs) { | 	} else if (!theirs) { | ||||||
| 		if (ref) | 		if (ref) | ||||||
| 			strbuf_addf(stat, _("[%s: ahead %d]"), ref, ours); | 			strbuf_addf(stat, _("[%s: ahead %d]"), fancy.buf, ours); | ||||||
| 		else | 		else | ||||||
| 			strbuf_addf(stat, _("[ahead %d]"), ours); | 			strbuf_addf(stat, _("[ahead %d]"), ours); | ||||||
| 	} else { | 	} else { | ||||||
| 		if (ref) | 		if (ref) | ||||||
| 			strbuf_addf(stat, _("[%s: ahead %d, behind %d]"), | 			strbuf_addf(stat, _("[%s: ahead %d, behind %d]"), | ||||||
| 				    ref, ours, theirs); | 				    fancy.buf, ours, theirs); | ||||||
| 		else | 		else | ||||||
| 			strbuf_addf(stat, _("[ahead %d, behind %d]"), | 			strbuf_addf(stat, _("[ahead %d, behind %d]"), | ||||||
| 				    ours, theirs); | 				    ours, theirs); | ||||||
| 	} | 	} | ||||||
|  | 	strbuf_release(&fancy); | ||||||
| 	strbuf_addch(stat, ' '); | 	strbuf_addch(stat, ' '); | ||||||
| 	free(ref); | 	free(ref); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Felipe Contreras
						Felipe Contreras