Merge branch 'as/maint-graph-interesting-fix'
* as/maint-graph-interesting-fix: Add tests for rev-list --graph with options that simplify history graph API: fix bug in graph_is_interesting()
This commit is contained in:
commit
24343c6099
5
graph.c
5
graph.c
@ -291,9 +291,10 @@ static int graph_is_interesting(struct git_graph *graph, struct commit *commit)
|
||||
}
|
||||
|
||||
/*
|
||||
* Uninteresting and pruned commits won't be printed
|
||||
* Otherwise, use get_commit_action() to see if this commit is
|
||||
* interesting
|
||||
*/
|
||||
return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1;
|
||||
return get_commit_action(graph->revs, commit) == commit_show;
|
||||
}
|
||||
|
||||
static struct commit_list *next_interesting_parent(struct git_graph *graph,
|
||||
|
17
revision.c
17
revision.c
@ -1664,7 +1664,7 @@ static inline int want_ancestry(struct rev_info *revs)
|
||||
return (revs->rewrite_parents || revs->children.name);
|
||||
}
|
||||
|
||||
enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
|
||||
enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit)
|
||||
{
|
||||
if (commit->object.flags & SHOWN)
|
||||
return commit_ignore;
|
||||
@ -1692,12 +1692,23 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
|
||||
if (!commit->parents || !commit->parents->next)
|
||||
return commit_ignore;
|
||||
}
|
||||
if (want_ancestry(revs) && rewrite_parents(revs, commit) < 0)
|
||||
return commit_error;
|
||||
}
|
||||
return commit_show;
|
||||
}
|
||||
|
||||
enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
|
||||
{
|
||||
enum commit_action action = get_commit_action(revs, commit);
|
||||
|
||||
if (action == commit_show &&
|
||||
!revs->show_all &&
|
||||
revs->prune && revs->dense && want_ancestry(revs)) {
|
||||
if (rewrite_parents(revs, commit) < 0)
|
||||
return commit_error;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
static struct commit *get_revision_1(struct rev_info *revs)
|
||||
{
|
||||
if (!revs->commits)
|
||||
|
@ -168,6 +168,7 @@ enum commit_action {
|
||||
commit_error
|
||||
};
|
||||
|
||||
extern enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit);
|
||||
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
|
||||
|
||||
#endif
|
||||
|
31
t/t6015-rev-list-show-all-parents.sh
Executable file
31
t/t6015-rev-list-show-all-parents.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='--show-all --parents does not rewrite TREESAME commits'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'set up --show-all --parents test' '
|
||||
test_commit one foo.txt &&
|
||||
commit1=`git rev-list -1 HEAD` &&
|
||||
test_commit two bar.txt &&
|
||||
commit2=`git rev-list -1 HEAD` &&
|
||||
test_commit three foo.txt &&
|
||||
commit3=`git rev-list -1 HEAD`
|
||||
'
|
||||
|
||||
test_expect_success '--parents rewrites TREESAME parents correctly' '
|
||||
echo $commit3 $commit1 > expected &&
|
||||
echo $commit1 >> expected &&
|
||||
git rev-list --parents HEAD -- foo.txt > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success '--parents --show-all does not rewrites TREESAME parents' '
|
||||
echo $commit3 $commit2 > expected &&
|
||||
echo $commit2 $commit1 >> expected &&
|
||||
echo $commit1 >> expected &&
|
||||
git rev-list --parents --show-all HEAD -- foo.txt > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_done
|
276
t/t6016-rev-list-graph-simplify-history.sh
Executable file
276
t/t6016-rev-list-graph-simplify-history.sh
Executable file
@ -0,0 +1,276 @@
|
||||
#!/bin/sh
|
||||
|
||||
# There's more than one "correct" way to represent the history graphically.
|
||||
# These tests depend on the current behavior of the graphing code. If the
|
||||
# graphing code is ever changed to draw the output differently, these tests
|
||||
# cases will need to be updated to know about the new layout.
|
||||
|
||||
test_description='--graph and simplified history'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'set up rev-list --graph test' '
|
||||
# 3 commits on branch A
|
||||
test_commit A1 foo.txt &&
|
||||
test_commit A2 bar.txt &&
|
||||
test_commit A3 bar.txt &&
|
||||
git branch -m master A &&
|
||||
|
||||
# 2 commits on branch B, started from A1
|
||||
git checkout -b B A1 &&
|
||||
test_commit B1 foo.txt &&
|
||||
test_commit B2 abc.txt &&
|
||||
|
||||
# 2 commits on branch C, started from A2
|
||||
git checkout -b C A2 &&
|
||||
test_commit C1 xyz.txt &&
|
||||
test_commit C2 xyz.txt &&
|
||||
|
||||
# Octopus merge B and C into branch A
|
||||
git checkout A &&
|
||||
git merge B C &&
|
||||
git tag A4
|
||||
|
||||
test_commit A5 bar.txt &&
|
||||
|
||||
# More commits on C, then merge C into A
|
||||
git checkout C &&
|
||||
test_commit C3 foo.txt &&
|
||||
test_commit C4 bar.txt &&
|
||||
git checkout A &&
|
||||
git merge -s ours C &&
|
||||
git tag A6
|
||||
|
||||
test_commit A7 bar.txt &&
|
||||
|
||||
# Store commit names in variables for later use
|
||||
A1=$(git rev-parse --verify A1) &&
|
||||
A2=$(git rev-parse --verify A2) &&
|
||||
A3=$(git rev-parse --verify A3) &&
|
||||
A4=$(git rev-parse --verify A4) &&
|
||||
A5=$(git rev-parse --verify A5) &&
|
||||
A6=$(git rev-parse --verify A6) &&
|
||||
A7=$(git rev-parse --verify A7) &&
|
||||
B1=$(git rev-parse --verify B1) &&
|
||||
B2=$(git rev-parse --verify B2) &&
|
||||
C1=$(git rev-parse --verify C1) &&
|
||||
C2=$(git rev-parse --verify C2) &&
|
||||
C3=$(git rev-parse --verify C3) &&
|
||||
C4=$(git rev-parse --verify C4)
|
||||
'
|
||||
|
||||
test_expect_success '--graph --all' '
|
||||
rm -f expected &&
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "| * $C3" >> expected &&
|
||||
echo "* | $A5" >> expected &&
|
||||
echo "| | " >> expected &&
|
||||
echo "| \\ " >> expected &&
|
||||
echo "*-. \\ $A4" >> expected &&
|
||||
echo "|\\ \\ \\ " >> expected &&
|
||||
echo "| | |/ " >> expected &&
|
||||
echo "| | * $C2" >> expected &&
|
||||
echo "| | * $C1" >> expected &&
|
||||
echo "| * | $B2" >> expected &&
|
||||
echo "| * | $B1" >> expected &&
|
||||
echo "* | | $A3" >> expected &&
|
||||
echo "| |/ " >> expected &&
|
||||
echo "|/| " >> expected &&
|
||||
echo "* | $A2" >> expected &&
|
||||
echo "|/ " >> expected &&
|
||||
echo "* $A1" >> expected &&
|
||||
git rev-list --graph --all > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
# Make sure the graph_is_interesting() code still realizes
|
||||
# that undecorated merges are interesting, even with --simplify-by-decoration
|
||||
test_expect_success '--graph --simplify-by-decoration' '
|
||||
rm -f expected &&
|
||||
git tag -d A4
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "| * $C3" >> expected &&
|
||||
echo "* | $A5" >> expected &&
|
||||
echo "| | " >> expected &&
|
||||
echo "| \\ " >> expected &&
|
||||
echo "*-. \\ $A4" >> expected &&
|
||||
echo "|\\ \\ \\ " >> expected &&
|
||||
echo "| | |/ " >> expected &&
|
||||
echo "| | * $C2" >> expected &&
|
||||
echo "| | * $C1" >> expected &&
|
||||
echo "| * | $B2" >> expected &&
|
||||
echo "| * | $B1" >> expected &&
|
||||
echo "* | | $A3" >> expected &&
|
||||
echo "| |/ " >> expected &&
|
||||
echo "|/| " >> expected &&
|
||||
echo "* | $A2" >> expected &&
|
||||
echo "|/ " >> expected &&
|
||||
echo "* $A1" >> expected &&
|
||||
git rev-list --graph --all --simplify-by-decoration > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
# Get rid of all decorations on branch B, and graph with it simplified away
|
||||
test_expect_success '--graph --simplify-by-decoration prune branch B' '
|
||||
rm -f expected &&
|
||||
git tag -d B2
|
||||
git tag -d B1
|
||||
git branch -d B
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "| * $C3" >> expected &&
|
||||
echo "* | $A5" >> expected &&
|
||||
echo "* | $A4" >> expected &&
|
||||
echo "|\\ \\ " >> expected &&
|
||||
echo "| |/ " >> expected &&
|
||||
echo "| * $C2" >> expected &&
|
||||
echo "| * $C1" >> expected &&
|
||||
echo "* | $A3" >> expected &&
|
||||
echo "|/ " >> expected &&
|
||||
echo "* $A2" >> expected &&
|
||||
echo "* $A1" >> expected &&
|
||||
git rev-list --graph --simplify-by-decoration --all > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success '--graph --full-history -- bar.txt' '
|
||||
rm -f expected &&
|
||||
git tag -d B2
|
||||
git tag -d B1
|
||||
git branch -d B
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "* | $A5" >> expected &&
|
||||
echo "* | $A4" >> expected &&
|
||||
echo "|\\ \\ " >> expected &&
|
||||
echo "| |/ " >> expected &&
|
||||
echo "* | $A3" >> expected &&
|
||||
echo "|/ " >> expected &&
|
||||
echo "* $A2" >> expected &&
|
||||
git rev-list --graph --full-history --all -- bar.txt > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
|
||||
rm -f expected &&
|
||||
git tag -d B2
|
||||
git tag -d B1
|
||||
git branch -d B
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "* | $A5" >> expected &&
|
||||
echo "* | $A3" >> expected &&
|
||||
echo "|/ " >> expected &&
|
||||
echo "* $A2" >> expected &&
|
||||
git rev-list --graph --full-history --simplify-merges --all \
|
||||
-- bar.txt > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success '--graph -- bar.txt' '
|
||||
rm -f expected &&
|
||||
git tag -d B2
|
||||
git tag -d B1
|
||||
git branch -d B
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A5" >> expected &&
|
||||
echo "* $A3" >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "|/ " >> expected &&
|
||||
echo "* $A2" >> expected &&
|
||||
git rev-list --graph --all -- bar.txt > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success '--graph --sparse -- bar.txt' '
|
||||
rm -f expected &&
|
||||
git tag -d B2
|
||||
git tag -d B1
|
||||
git branch -d B
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "* $A5" >> expected &&
|
||||
echo "* $A4" >> expected &&
|
||||
echo "* $A3" >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "| * $C3" >> expected &&
|
||||
echo "| * $C2" >> expected &&
|
||||
echo "| * $C1" >> expected &&
|
||||
echo "|/ " >> expected &&
|
||||
echo "* $A2" >> expected &&
|
||||
echo "* $A1" >> expected &&
|
||||
git rev-list --graph --sparse --all -- bar.txt > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success '--graph ^C4' '
|
||||
rm -f expected &&
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "* $A5" >> expected &&
|
||||
echo "* $A4" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $B2" >> expected &&
|
||||
echo "| * $B1" >> expected &&
|
||||
echo "* $A3" >> expected &&
|
||||
git rev-list --graph --all ^C4 > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success '--graph ^C3' '
|
||||
rm -f expected &&
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "* $A5" >> expected &&
|
||||
echo "* $A4" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $B2" >> expected &&
|
||||
echo "| * $B1" >> expected &&
|
||||
echo "* $A3" >> expected &&
|
||||
git rev-list --graph --all ^C3 > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
# I don't think the ordering of the boundary commits is really
|
||||
# that important, but this test depends on it. If the ordering ever changes
|
||||
# in the code, we'll need to update this test.
|
||||
test_expect_success '--graph --boundary ^C3' '
|
||||
rm -f expected &&
|
||||
echo "* $A7" >> expected &&
|
||||
echo "* $A6" >> expected &&
|
||||
echo "|\\ " >> expected &&
|
||||
echo "| * $C4" >> expected &&
|
||||
echo "* | $A5" >> expected &&
|
||||
echo "| | " >> expected &&
|
||||
echo "| \\ " >> expected &&
|
||||
echo "*-. \\ $A4" >> expected &&
|
||||
echo "|\\ \\ \\ " >> expected &&
|
||||
echo "| * | | $B2" >> expected &&
|
||||
echo "| * | | $B1" >> expected &&
|
||||
echo "* | | | $A3" >> expected &&
|
||||
echo "o | | | $A2" >> expected &&
|
||||
echo "|/ / / " >> expected &&
|
||||
echo "o | | $A1" >> expected &&
|
||||
echo " / / " >> expected &&
|
||||
echo "| o $C3" >> expected &&
|
||||
echo "|/ " >> expected &&
|
||||
echo "o $C2" >> expected &&
|
||||
git rev-list --graph --boundary --all ^C3 > actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_done
|
Loading…
Reference in New Issue
Block a user