@matheusbsbs / matheus-bagliano / commits / b2d4c56f2f
Fork 0

diff-tree: abbreviate merge parent object names with --abbrev --pretty.

When --abbrev is in effect, abbreviate the merge parent names in prettyprinted output. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 25, 2006 at 02:37 UTC b2d4c56f2f370481c80e478ac323ebb13eece807
5 files changed +18 -9
commit.c
+14 -5
@@ -426,9 +426,10 @@ static int is_empty_line(const char *line, int len)
426 return !len;
427 }
428
429 -static int add_parent_info(enum cmit_fmt fmt, char *buf, const char *line, int parents)
429 +static int add_parent_info(enum cmit_fmt fmt, char *buf, const char *line, int parents, int abbrev)
430 {
431 int offset = 0;
432 + unsigned char sha1[20];
433
434 if (fmt == CMIT_FMT_ONELINE)
435 return offset;
@@ -437,17 +438,25 @@ static int add_parent_info(enum cmit_fmt fmt, char *buf, const char *line, int p
438 break;
439 case 2:
440 /* Go back to the previous line: 40 characters of previous parent, and one '\n' */
440 - offset = sprintf(buf, "Merge: %.40s\n", line-41);
441 + if (abbrev && !get_sha1_hex(line-41, sha1))
442 + offset = sprintf(buf, "Merge: %s\n",
443 + find_unique_abbrev(sha1, abbrev));
444 + else
445 + offset = sprintf(buf, "Merge: %.40s\n", line-41);
446 /* Fallthrough */
447 default:
448 /* Replace the previous '\n' with a space */
449 buf[offset-1] = ' ';
445 - offset += sprintf(buf + offset, "%.40s\n", line+7);
450 + if (abbrev && !get_sha1_hex(line+7, sha1))
451 + offset += sprintf(buf + offset, "%s\n",
452 + find_unique_abbrev(sha1, abbrev));
453 + else
454 + offset += sprintf(buf + offset, "%.40s\n", line+7);
455 }
456 return offset;
457 }
458
450 -unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned long len, char *buf, unsigned long space)
459 +unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned long len, char *buf, unsigned long space, int abbrev)
460 {
461 int hdr = 1, body = 0;
462 unsigned long offset = 0;
@@ -488,7 +497,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned l
497 if (!memcmp(line, "parent ", 7)) {
498 if (linelen != 48)
499 die("bad parent line in commit");
491 - offset += add_parent_info(fmt, buf + offset, line, ++parents);
500 + offset += add_parent_info(fmt, buf + offset, line, ++parents, abbrev);
501 }
502
503 /*
commit.h
+1 -1
@@ -48,7 +48,7 @@ enum cmit_fmt {
48 };
49
50 extern enum cmit_fmt get_commit_format(const char *arg);
51 -extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned long len, char *buf, unsigned long space);
51 +extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned long len, char *buf, unsigned long space, int abbrev);
52
53 /** Removes the first commit from a list sorted by date, and adds all
54 * of its parents.
diff-tree.c
+1 -1
@@ -84,7 +84,7 @@ static const char *generate_header(const unsigned char *commit_sha1,
84 diff_unique_abbrev(parent_sha1, abbrev) : "root");
85 offset += pretty_print_commit(commit_format, msg, len,
86 this_header + offset,
87 - sizeof(this_header) - offset);
87 + sizeof(this_header) - offset, abbrev);
88 return this_header;
89 }
90
rev-list.c
+1 -1
@@ -81,7 +81,7 @@ static void show_commit(struct commit *commit)
81
82 if (verbose_header) {
83 static char pretty_header[16384];
84 - pretty_print_commit(commit_format, commit->buffer, ~0, pretty_header, sizeof(pretty_header));
84 + pretty_print_commit(commit_format, commit->buffer, ~0, pretty_header, sizeof(pretty_header), 0);
85 printf("%s%c", pretty_header, hdr_termination);
86 }
87 fflush(stdout);
show-branch.c
+1 -1
@@ -259,7 +259,7 @@ static void show_one_commit(struct commit *commit, int no_name)
259 struct commit_name *name = commit->object.util;
260 if (commit->object.parsed)
261 pretty_print_commit(CMIT_FMT_ONELINE, commit->buffer, ~0,
262 - pretty, sizeof(pretty));
262 + pretty, sizeof(pretty), 0);
263 else
264 strcpy(pretty, "(unavailable)");
265 if (!strncmp(pretty, "[PATCH] ", 8))