range-diff: adjust the output of the commit pairs
This not only uses "dashed stand-ins" for "pairs" where one side is missing (i.e. unmatched commits that are present only in one of the two commit ranges), but also adds onelines for the reader's pleasure. This change brings `git range-diff` yet another step closer to feature parity with tbdiff: it now shows the oneline, too, and indicates with `=` when the commits have identical diffs. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Aug 13, 2018 at 04:33 UTC
eb0be38cc94d308fc114289e9555523ae34433b1
1 file changed
+50
-9
range-diff.c
+50
-9
@@ -7,6 +7,8 @@
7
#include "xdiff-interface.h"
8
#include "linear-assignment.h"
9
#include "diffcore.h"
10
+#include "commit.h"
11
+#include "pretty.h"
12
13
struct patch_util {
14
/* For the search for an exact match */
@@ -255,9 +257,49 @@ static void get_correspondences(struct string_list *a, struct string_list *b,
257
free(b2a);
258
}
259
258
-static const char *short_oid(struct patch_util *util)
260
+static void output_pair_header(struct strbuf *buf,
261
+ struct strbuf *dashes,
262
+ struct patch_util *a_util,
263
+ struct patch_util *b_util)
264
{
260
- return find_unique_abbrev(&util->oid, DEFAULT_ABBREV);
265
+ struct object_id *oid = a_util ? &a_util->oid : &b_util->oid;
266
+ struct commit *commit;
267
+
268
+ if (!dashes->len)
269
+ strbuf_addchars(dashes, '-',
270
+ strlen(find_unique_abbrev(oid,
271
+ DEFAULT_ABBREV)));
272
+
273
+ strbuf_reset(buf);
274
+ if (!a_util)
275
+ strbuf_addf(buf, "-: %s ", dashes->buf);
276
+ else
277
+ strbuf_addf(buf, "%d: %s ", a_util->i + 1,
278
+ find_unique_abbrev(&a_util->oid, DEFAULT_ABBREV));
279
+
280
+ if (!a_util)
281
+ strbuf_addch(buf, '>');
282
+ else if (!b_util)
283
+ strbuf_addch(buf, '<');
284
+ else if (strcmp(a_util->patch, b_util->patch))
285
+ strbuf_addch(buf, '!');
286
+ else
287
+ strbuf_addch(buf, '=');
288
+
289
+ if (!b_util)
290
+ strbuf_addf(buf, " -: %s", dashes->buf);
291
+ else
292
+ strbuf_addf(buf, " %d: %s", b_util->i + 1,
293
+ find_unique_abbrev(&b_util->oid, DEFAULT_ABBREV));
294
+
295
+ commit = lookup_commit_reference(the_repository, oid);
296
+ if (commit) {
297
+ strbuf_addch(buf, ' ');
298
+ pp_commit_easy(CMIT_FMT_ONELINE, commit, buf);
299
+ }
300
+ strbuf_addch(buf, '\n');
301
+
302
+ fwrite(buf->buf, buf->len, 1, stdout);
303
}
304
305
static struct diff_filespec *get_filespec(const char *name, const char *p)
@@ -286,6 +328,7 @@ static void patch_diff(const char *a, const char *b,
328
static void output(struct string_list *a, struct string_list *b,
329
struct diff_options *diffopt)
330
{
331
+ struct strbuf buf = STRBUF_INIT, dashes = STRBUF_INIT;
332
int i = 0, j = 0;
333
334
/*
@@ -307,25 +350,21 @@ static void output(struct string_list *a, struct string_list *b,
350
351
/* Show unmatched LHS commit whose predecessors were shown. */
352
if (i < a->nr && a_util->matching < 0) {
310
- printf("%d: %s < -: --------\n",
311
- i + 1, short_oid(a_util));
353
+ output_pair_header(&buf, &dashes, a_util, NULL);
354
i++;
355
continue;
356
}
357
358
/* Show unmatched RHS commits. */
359
while (j < b->nr && b_util->matching < 0) {
318
- printf("-: -------- > %d: %s\n",
319
- j + 1, short_oid(b_util));
360
+ output_pair_header(&buf, &dashes, NULL, b_util);
361
b_util = ++j < b->nr ? b->items[j].util : NULL;
362
}
363
364
/* Show matching LHS/RHS pair. */
365
if (j < b->nr) {
366
a_util = a->items[b_util->matching].util;
326
- printf("%d: %s ! %d: %s\n",
327
- b_util->matching + 1, short_oid(a_util),
328
- j + 1, short_oid(b_util));
367
+ output_pair_header(&buf, &dashes, a_util, b_util);
368
if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT))
369
patch_diff(a->items[b_util->matching].string,
370
b->items[j].string, diffopt);
@@ -333,6 +372,8 @@ static void output(struct string_list *a, struct string_list *b,
372
j++;
373
}
374
}
375
+ strbuf_release(&buf);
376
+ strbuf_release(&dashes);
377
}
378
379
int show_range_diff(const char *range1, const char *range2,