* [PATCH v3] branch: colour upstream branches
@ 2013-04-15 2:37 Felipe Contreras
2013-04-15 2:55 ` Junio C Hamano
2013-04-15 12:16 ` Duy Nguyen
0 siblings, 2 replies; 3+ messages in thread
From: Felipe Contreras @ 2013-04-15 2:37 UTC (permalink / raw
To: git; +Cc: Junio C Hamano, Jeff King, Thomas Rast, Duy Nguyen,
Felipe Contreras
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>
---
This time with strbuf.
Documentation/config.txt | 3 ++-
builtin/branch.c | 38 ++++++++++++++++++++++++++++++--------
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index bc750d5..302533f 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -794,7 +794,8 @@ color.branch::
color.branch.<slot>::
Use customized color for branch coloration. `<slot>` is one of
`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).
+
The value for these configuration variables is a list of colors (at most
diff --git a/builtin/branch.c b/builtin/branch.c
index 00d17d2..26e9322 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -40,13 +40,15 @@ static char branch_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RED, /* REMOTE */
GIT_COLOR_NORMAL, /* LOCAL */
GIT_COLOR_GREEN, /* CURRENT */
+ GIT_COLOR_BLUE, /* UPSTREAM */
};
enum color_branch {
BRANCH_COLOR_RESET = 0,
BRANCH_COLOR_PLAIN = 1,
BRANCH_COLOR_REMOTE = 2,
BRANCH_COLOR_LOCAL = 3,
- BRANCH_COLOR_CURRENT = 4
+ BRANCH_COLOR_CURRENT = 4,
+ BRANCH_COLOR_UPSTREAM = 5,
};
static enum merge_filter {
@@ -71,6 +73,8 @@ static int parse_branch_color_slot(const char *var, int ofs)
return BRANCH_COLOR_LOCAL;
if (!strcasecmp(var+ofs, "current"))
return BRANCH_COLOR_CURRENT;
+ if (!strcasecmp(var+ofs, "upstream"))
+ return BRANCH_COLOR_UPSTREAM;
return -1;
}
@@ -417,36 +421,54 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
int ours, theirs;
char *ref = NULL;
struct branch *branch = branch_get(branch_name);
+ struct strbuf fancy;
+
+ strbuf_init(&fancy, 0);
if (!stat_tracking_info(branch, &ours, &theirs)) {
if (branch && branch->merge && branch->merge[0]->dst &&
- show_upstream_ref)
- strbuf_addf(stat, "[%s] ",
- shorten_unambiguous_ref(branch->merge[0]->dst, 0));
+ show_upstream_ref) {
+ ref = 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;
}
- if (show_upstream_ref)
+ if (show_upstream_ref) {
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 (ref)
- strbuf_addf(stat, _("[%s: behind %d]"), ref, theirs);
+ strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs);
else
strbuf_addf(stat, _("[behind %d]"), theirs);
} else if (!theirs) {
if (ref)
- strbuf_addf(stat, _("[%s: ahead %d]"), ref, ours);
+ strbuf_addf(stat, _("[%s: ahead %d]"), fancy.buf, ours);
else
strbuf_addf(stat, _("[ahead %d]"), ours);
} else {
if (ref)
strbuf_addf(stat, _("[%s: ahead %d, behind %d]"),
- ref, ours, theirs);
+ fancy.buf, ours, theirs);
else
strbuf_addf(stat, _("[ahead %d, behind %d]"),
ours, theirs);
}
+ strbuf_release(&fancy);
strbuf_addch(stat, ' ');
free(ref);
}
--
1.8.2.1.643.ge3cc75d
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] branch: colour upstream branches
2013-04-15 2:37 [PATCH v3] branch: colour upstream branches Felipe Contreras
@ 2013-04-15 2:55 ` Junio C Hamano
2013-04-15 12:16 ` Duy Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2013-04-15 2:55 UTC (permalink / raw
To: Felipe Contreras; +Cc: git, Jeff King, Thomas Rast, Duy Nguyen
Felipe Contreras <felipe.contreras@gmail.com> writes:
> 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>
> ---
>
> This time with strbuf.
>
> Documentation/config.txt | 3 ++-
> builtin/branch.c | 38 ++++++++++++++++++++++++++++++--------
> 2 files changed, 32 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index bc750d5..302533f 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -794,7 +794,8 @@ color.branch::
> color.branch.<slot>::
> Use customized color for branch coloration. `<slot>` is one of
> `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).
> +
> The value for these configuration variables is a list of colors (at most
> diff --git a/builtin/branch.c b/builtin/branch.c
> index 00d17d2..26e9322 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -40,13 +40,15 @@ static char branch_colors[][COLOR_MAXLEN] = {
> GIT_COLOR_RED, /* REMOTE */
> GIT_COLOR_NORMAL, /* LOCAL */
> GIT_COLOR_GREEN, /* CURRENT */
> + GIT_COLOR_BLUE, /* UPSTREAM */
> };
> enum color_branch {
> BRANCH_COLOR_RESET = 0,
> BRANCH_COLOR_PLAIN = 1,
> BRANCH_COLOR_REMOTE = 2,
> BRANCH_COLOR_LOCAL = 3,
> - BRANCH_COLOR_CURRENT = 4
> + BRANCH_COLOR_CURRENT = 4,
> + BRANCH_COLOR_UPSTREAM = 5,
> };
We had to fix these "trailing comma in enums" to help other peoples'
compilers a few times. Yes, they happily take the trailing comma at
the end of array values above. Don't complain to me ;-)
> @@ -417,36 +421,54 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
> int ours, theirs;
> char *ref = NULL;
> struct branch *branch = branch_get(branch_name);
> + struct strbuf fancy;
> +
> + strbuf_init(&fancy, 0);
>
> if (!stat_tracking_info(branch, &ours, &theirs)) {
> if (branch && branch->merge && branch->merge[0]->dst &&
> - show_upstream_ref)
> - strbuf_addf(stat, "[%s] ",
> - shorten_unambiguous_ref(branch->merge[0]->dst, 0));
> + show_upstream_ref) {
> + ref = 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;
> }
>
> - if (show_upstream_ref)
> + if (show_upstream_ref) {
> 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 (ref)
> - strbuf_addf(stat, _("[%s: behind %d]"), ref, theirs);
> + strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs);
> else
> strbuf_addf(stat, _("[behind %d]"), theirs);
>
> } else if (!theirs) {
> if (ref)
> - strbuf_addf(stat, _("[%s: ahead %d]"), ref, ours);
> + strbuf_addf(stat, _("[%s: ahead %d]"), fancy.buf, ours);
> else
> strbuf_addf(stat, _("[ahead %d]"), ours);
> } else {
> if (ref)
> strbuf_addf(stat, _("[%s: ahead %d, behind %d]"),
> - ref, ours, theirs);
> + fancy.buf, ours, theirs);
> else
> strbuf_addf(stat, _("[ahead %d, behind %d]"),
> ours, theirs);
> }
> + strbuf_release(&fancy);
> strbuf_addch(stat, ' ');
> free(ref);
> }
Fairly straight-forward and looks good.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] branch: colour upstream branches
2013-04-15 2:37 [PATCH v3] branch: colour upstream branches Felipe Contreras
2013-04-15 2:55 ` Junio C Hamano
@ 2013-04-15 12:16 ` Duy Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Duy Nguyen @ 2013-04-15 12:16 UTC (permalink / raw
To: Felipe Contreras; +Cc: Git Mailing List, Junio C Hamano, Jeff King, Thomas Rast
On Mon, Apr 15, 2013 at 12:37 PM, Felipe Contreras
<felipe.contreras@gmail.com> wrote:
> @@ -417,36 +421,54 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
> int ours, theirs;
> char *ref = NULL;
> struct branch *branch = branch_get(branch_name);
> + struct strbuf fancy;
> +
> + strbuf_init(&fancy, 0);
Nitpick. You could have done "struct strbuf fancy = STRBUF_INIT;". No
need to resend, I think, unless there are other changes.
--
Duy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-04-15 12:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-15 2:37 [PATCH v3] branch: colour upstream branches Felipe Contreras
2013-04-15 2:55 ` Junio C Hamano
2013-04-15 12:16 ` Duy Nguyen
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).