summaryrefslogtreecommitdiff
path: root/range-diff.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2018-08-13 11:33:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-13 17:44:52 (GMT)
commitd1f87a2d9c4877ada003c231b92de7560eab62ed (patch)
tree3b133f8532e498711526e82a95ae284084c206b2 /range-diff.c
parent7190a67eab181ebfbf61f4c8afaa3a149f685853 (diff)
downloadgit-d1f87a2d9c4877ada003c231b92de7560eab62ed.zip
git-d1f87a2d9c4877ada003c231b92de7560eab62ed.tar.gz
git-d1f87a2d9c4877ada003c231b92de7560eab62ed.tar.bz2
range-diff: left-pad patch numbers
As pointed out by Elijah Newren, tbdiff has this neat little alignment trick where it outputs the commit pairs with patch numbers that are padded to the maximal patch number's width: 1: cafedead = 1: acefade first patch [...] 314: beefeada < 314: facecab up to PI! Let's do the same in range-diff, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.c')
-rw-r--r--range-diff.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/range-diff.c b/range-diff.c
index b1663da..b6b9aba 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -259,6 +259,7 @@ static void get_correspondences(struct string_list *a, struct string_list *b,
}
static void output_pair_header(struct diff_options *diffopt,
+ int patch_no_width,
struct strbuf *buf,
struct strbuf *dashes,
struct patch_util *a_util,
@@ -295,9 +296,9 @@ static void output_pair_header(struct diff_options *diffopt,
strbuf_reset(buf);
strbuf_addstr(buf, status == '!' ? color_old : color);
if (!a_util)
- strbuf_addf(buf, "-: %s ", dashes->buf);
+ strbuf_addf(buf, "%*s: %s ", patch_no_width, "-", dashes->buf);
else
- strbuf_addf(buf, "%d: %s ", a_util->i + 1,
+ strbuf_addf(buf, "%*d: %s ", patch_no_width, a_util->i + 1,
find_unique_abbrev(&a_util->oid, DEFAULT_ABBREV));
if (status == '!')
@@ -307,9 +308,9 @@ static void output_pair_header(struct diff_options *diffopt,
strbuf_addf(buf, "%s%s", color_reset, color_new);
if (!b_util)
- strbuf_addf(buf, " -: %s", dashes->buf);
+ strbuf_addf(buf, " %*s: %s", patch_no_width, "-", dashes->buf);
else
- strbuf_addf(buf, " %d: %s", b_util->i + 1,
+ strbuf_addf(buf, " %*d: %s", patch_no_width, b_util->i + 1,
find_unique_abbrev(&b_util->oid, DEFAULT_ABBREV));
commit = lookup_commit_reference(the_repository, oid);
@@ -357,6 +358,7 @@ static void output(struct string_list *a, struct string_list *b,
struct diff_options *diffopt)
{
struct strbuf buf = STRBUF_INIT, dashes = STRBUF_INIT;
+ int patch_no_width = decimal_width(1 + (a->nr > b->nr ? a->nr : b->nr));
int i = 0, j = 0;
/*
@@ -378,7 +380,7 @@ static void output(struct string_list *a, struct string_list *b,
/* Show unmatched LHS commit whose predecessors were shown. */
if (i < a->nr && a_util->matching < 0) {
- output_pair_header(diffopt,
+ output_pair_header(diffopt, patch_no_width,
&buf, &dashes, a_util, NULL);
i++;
continue;
@@ -386,7 +388,7 @@ static void output(struct string_list *a, struct string_list *b,
/* Show unmatched RHS commits. */
while (j < b->nr && b_util->matching < 0) {
- output_pair_header(diffopt,
+ output_pair_header(diffopt, patch_no_width,
&buf, &dashes, NULL, b_util);
b_util = ++j < b->nr ? b->items[j].util : NULL;
}
@@ -394,7 +396,7 @@ static void output(struct string_list *a, struct string_list *b,
/* Show matching LHS/RHS pair. */
if (j < b->nr) {
a_util = a->items[b_util->matching].util;
- output_pair_header(diffopt,
+ output_pair_header(diffopt, patch_no_width,
&buf, &dashes, a_util, b_util);
if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT))
patch_diff(a->items[b_util->matching].string,