Skip to content

Commit ae03ee6

Browse files
peffgitster
authored andcommitted
show: add space between multiple items
When showing an annotated tag, "git show" will always display the pointed-to object. However, it didn't separate the two with whitespace, making it more difficult to notice where the new object started. For example: $ git tag -m 'my message' foo $ git show foo tag foo Tagger: Jeff King <[email protected]> Date: Fri Jul 17 18:46:25 2009 -0400 my message commit 41cabf8fed2694ba33e01d64f9094f2fc5e5805a Author: Jeff King <[email protected]> Date: Thu Jul 16 17:31:34 2009 -0400 ... This patch respects and sets the rev.shown_one member to prepend a blank line before showing a second item. We use this member of rev_info instead of a local flag, because the log_tree_commit we call into for showing commits already respects and sets that flag. Meaning that everything will be spaced properly if you intermix commits and tags, like: $ git show v1.6.3 v1.6.2 HEAD In that case, a single blank line will separate the first tag, the commit it points to, the second tag, the commit that one points to, and the final commit. While we're at it, let's also support trees, so that even something as crazy as $ git show HEAD^{tree} HEAD~1^{tree} HEAD will also be spaced in an easy-to-read way. However, we intentionally do _not_ insert blank lines for blobs, so that specifying multiple blobs gives a strict concatenation. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca4ca9e commit ae03ee6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

builtin-log.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,14 @@ int cmd_show(int argc, const char **argv, const char *prefix)
329329
case OBJ_TAG: {
330330
struct tag *t = (struct tag *)o;
331331

332+
if (rev.shown_one)
333+
putchar('\n');
332334
printf("%stag %s%s\n",
333335
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
334336
t->tag,
335337
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
336338
ret = show_object(o->sha1, 1, &rev);
339+
rev.shown_one = 1;
337340
if (ret)
338341
break;
339342
o = parse_object(t->tagged->sha1);
@@ -345,12 +348,15 @@ int cmd_show(int argc, const char **argv, const char *prefix)
345348
break;
346349
}
347350
case OBJ_TREE:
351+
if (rev.shown_one)
352+
putchar('\n');
348353
printf("%stree %s%s\n\n",
349354
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
350355
name,
351356
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
352357
read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
353358
show_tree_object, NULL);
359+
rev.shown_one = 1;
354360
break;
355361
case OBJ_COMMIT:
356362
rev.pending.nr = rev.pending.alloc = 0;

0 commit comments

Comments
 (0)