Skip to content

Commit 6631c73

Browse files
Linus TorvaldsJunio C Hamano
Linus Torvalds
authored and
Junio C Hamano
committed
revision.c: --full-history fix.
With history simplification, we still show merges that are required to make the history _complete_, i.e. say that you had: a | b / \ c d | | and neither "a" nor "b" actually changed the file, but both "c" and "d" did: in this case we have to leave "b" around just because otherwise there would be no way to show the _relationship_, even if "b" itself doesn't actually change the tree in any way what-so-ever. It would make sense to make that further simplification if the "--parents" flag wasn't present. In that case the user is literally asking for a list of commits and is not interested in the relationship between them. This patch also fixes a real bug. Without this patch, the "--parents --full-history" combination (which you'd get if you do something like gitk --full-history Makefile or similar) will actually _drop_ merges where all children are identical. That's wrong in the --full-history case, because it means that the graph ends up missing lots of entries. In the process, this also should make git-rev-list --full-history Makefile give just the _true_ list of all commits that changed Makefile (and properly ignore merges that were identical in one parent), because now we're not asking for "--parent", so we don't need the unnecessary merge commits to keep the history together. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac3bc6c commit 6631c73

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

revision.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ int rev_same_tree_as_empty(struct rev_info *revs, struct tree *t1)
280280
static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
281281
{
282282
struct commit_list **pp, *parent;
283-
int tree_changed = 0;
283+
int tree_changed = 0, tree_same = 0;
284284

285285
if (!commit->tree)
286286
return;
@@ -298,6 +298,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
298298
parse_commit(p);
299299
switch (rev_compare_tree(revs, p->tree, commit->tree)) {
300300
case REV_TREE_SAME:
301+
tree_same = 1;
301302
if (!revs->simplify_history || (p->object.flags & UNINTERESTING)) {
302303
/* Even if a merge with an uninteresting
303304
* side branch brought the entire change
@@ -334,7 +335,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
334335
}
335336
die("bad tree compare for commit %s", sha1_to_hex(commit->object.sha1));
336337
}
337-
if (tree_changed)
338+
if (tree_changed && !tree_same)
338339
commit->object.flags |= TREECHANGE;
339340
}
340341

@@ -896,6 +897,8 @@ static int rewrite_one(struct rev_info *revs, struct commit **pp)
896897
struct commit *p = *pp;
897898
if (!revs->limited)
898899
add_parents_to_list(revs, p, &revs->commits);
900+
if (p->parents && p->parents->next)
901+
return 0;
899902
if (p->object.flags & (TREECHANGE | UNINTERESTING))
900903
return 0;
901904
if (!p->parents)
@@ -988,8 +991,15 @@ struct commit *get_revision(struct rev_info *revs)
988991
commit->parents && commit->parents->next)
989992
continue;
990993
if (revs->prune_fn && revs->dense) {
991-
if (!(commit->object.flags & TREECHANGE))
992-
continue;
994+
/* Commit without changes? */
995+
if (!(commit->object.flags & TREECHANGE)) {
996+
/* drop merges unless we want parenthood */
997+
if (!revs->parents)
998+
continue;
999+
/* non-merge - always ignore it */
1000+
if (commit->parents && !commit->parents->next)
1001+
continue;
1002+
}
9931003
if (revs->parents)
9941004
rewrite_parents(revs, commit);
9951005
}

0 commit comments

Comments
 (0)