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

pretty_print_commit: honor grafts.

When displaying Merge: lines, we used to take the real commit parents from the commit objects. Use the parsed parents from the commit object instead, so that we honor fake parent information from info/grafts. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 27, 2006 at 02:17 UTC f2d4227530499db3e273ae84f30adfd4b70791c6
1 file changed +26 -26
commit.c
+26 -26
@@ -426,33 +426,27 @@ 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, int abbrev)
429 +static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *commit, int abbrev)
430 {
431 - int offset = 0;
432 - unsigned char sha1[20];
431 + struct commit_list *parent = commit->parents;
432 + int offset;
433
434 - if (fmt == CMIT_FMT_ONELINE)
435 - return offset;
436 - switch (parents) {
437 - case 1:
438 - break;
439 - case 2:
440 - /* Go back to the previous line: 40 characters of previous parent, and one '\n' */
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] = ' ';
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);
434 + if ((fmt == CMIT_FMT_ONELINE) || !parent || !parent->next)
435 + return 0;
436 +
437 + offset = sprintf(buf, "Merge:");
438 +
439 + while (parent) {
440 + struct commit *p = parent->item;
441 + parent = parent->next;
442 +
443 + offset += sprintf(buf + offset,
444 + abbrev ? " %s..." : " %s",
445 + abbrev
446 + ? find_unique_abbrev(p->object.sha1, abbrev)
447 + : sha1_to_hex(p->object.sha1));
448 }
449 + buf[offset++] = '\n';
450 return offset;
451 }
452
@@ -460,8 +454,8 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
454 {
455 int hdr = 1, body = 0;
456 unsigned long offset = 0;
463 - int parents = 0;
457 int indent = (fmt == CMIT_FMT_ONELINE) ? 0 : 4;
458 + int parents_shown = 0;
459 const char *msg = commit->buffer;
460
461 for (;;) {
@@ -498,9 +492,15 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
492 if (!memcmp(line, "parent ", 7)) {
493 if (linelen != 48)
494 die("bad parent line in commit");
501 - offset += add_parent_info(fmt, buf + offset, line, ++parents, abbrev);
495 + continue;
496 }
497
498 + if (!parents_shown) {
499 + offset += add_merge_info(fmt, buf + offset,
500 + commit, abbrev);
501 + parents_shown = 1;
502 + continue;
503 + }
504 /*
505 * MEDIUM == DEFAULT shows only author with dates.
506 * FULL shows both authors but not dates.