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

Simplify and fix --first-parent implementation

The purpose of --first-parent is to view the tree without looking at side branche. This is accomplished by pretending there are no other parents than the first parent when encountering a merge. The current code marks the other parents as seen, which means that the tree traversal will behave differently depending on the order merges are handled. When a fast forward is artificially recorded as a merge, ----- / \ D---E---F---G master the current first-parent code considers E to be seen and stops the traversal after showing G and F. Signed-off-by: Stephen R. van den Berg <srb@cuci.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen R. van den Berg committed Apr 27, 2008 at 19:32 UTC d9c292e8bbd51c84cb9ecd86cb89b8a1b35a2a82
1 file changed +4 -6
revision.c
+4 -6
@@ -415,7 +415,6 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
415 {
416 struct commit_list *parent = commit->parents;
417 unsigned left_flag;
418 - int add, rest;
418
419 if (commit->object.flags & ADDED)
420 return 0;
@@ -462,19 +461,18 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
461
462 left_flag = (commit->object.flags & SYMMETRIC_LEFT);
463
465 - rest = !revs->first_parent_only;
466 - for (parent = commit->parents, add = 1; parent; add = rest) {
464 + for (parent = commit->parents; parent; parent = parent->next) {
465 struct commit *p = parent->item;
466
469 - parent = parent->next;
467 if (parse_commit(p) < 0)
468 return -1;
469 p->object.flags |= left_flag;
470 if (p->object.flags & SEEN)
471 continue;
472 p->object.flags |= SEEN;
476 - if (add)
477 - insert_by_date(p, list);
473 + insert_by_date(p, list);
474 + if(revs->first_parent_only)
475 + break;
476 }
477 return 0;
478 }