Skip to content

Commit

Permalink
rev-list --min-parents,--max-parents: doc, test and completion
Browse files Browse the repository at this point in the history
This also adds test for "--merges" and "--no-merges" which we did not
have so far.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael J Gruber authored and Junio C Hamano committed Mar 23, 2011
1 parent ad5aeed commit 6a6ebde
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Documentation/git-rev-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ SYNOPSIS
[ \--sparse ]
[ \--merges ]
[ \--no-merges ]
[ \--min-parents=<number> ]
[ \--no-min-parents ]
[ \--max-parents=<number> ]
[ \--no-max-parents ]
[ \--first-parent ]
[ \--remove-empty ]
[ \--full-history ]
Expand Down
19 changes: 17 additions & 2 deletions Documentation/rev-list-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,26 @@ endif::git-rev-list[]

--merges::

Print only merge commits.
Print only merge commits. This is exactly the same as `--min-parents=2`.

--no-merges::

Do not print commits with more than one parent.
Do not print commits with more than one parent. This is
exactly the same as `--max-parents=1`.

--min-parents=<number>::
--max-parents=<number>::
--no-min-parents::
--no-max-parents::

Show only commits which have at least (or at most) that many
commits. In particular, `--max-parents=1` is the same as `--no-merges`,
`--min-parents=2` is the same as `--merges`. `--max-parents=0`
gives all root commits and `--min-parents=3` all octopus merges.
+
`--no-min-parents` and `--no-max-parents` reset these limits (to no limit)
again. Equivalent forms are `--min-parents=0` (any commit has 0 or more
parents) and `--max-parents=-1` (negative numbers denote no upper limit).

--first-parent::
Follow only the first parent commit upon seeing a merge
Expand Down
2 changes: 2 additions & 0 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,8 @@ __git_log_common_options="
--max-count=
--max-age= --since= --after=
--min-age= --until= --before=
--min-parents= --max-parents=
--no-min-parents --no-max-parents
"
# Options that go well for log and gitk (not shortlog)
__git_log_gitk_options="
Expand Down
107 changes: 106 additions & 1 deletion t/t6009-rev-list-parent.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#!/bin/sh

test_description='properly cull all ancestors'
test_description='ancestor culling and limiting by parent number'

. ./test-lib.sh

check_revlist () {
rev_list_args="$1" &&
shift &&
git rev-parse "$@" >expect &&
git rev-list $rev_list_args --all >actual &&
test_cmp expect actual
}

test_expect_success setup '
touch file &&
Expand All @@ -28,4 +36,101 @@ test_expect_success 'one is ancestor of others and should not be shown' '
'

test_expect_success 'setup roots, merges and octopuses' '
git checkout --orphan newroot &&
test_commit five &&
git checkout -b sidebranch two &&
test_commit six &&
git checkout -b anotherbranch three &&
test_commit seven &&
git checkout -b yetanotherbranch four &&
test_commit eight &&
git checkout master &&
test_merge normalmerge newroot &&
test_tick &&
git merge -m tripus sidebranch anotherbranch &&
git tag tripus &&
git checkout -b tetrabranch normalmerge &&
test_tick &&
git merge -m tetrapus sidebranch anotherbranch yetanotherbranch &&
git tag tetrapus &&
git checkout master
'

test_expect_success 'rev-list roots' '
check_revlist "--max-parents=0" one five
'

test_expect_success 'rev-list no merges' '
check_revlist "--max-parents=1" one eight seven six five four three two &&
check_revlist "--no-merges" one eight seven six five four three two
'

test_expect_success 'rev-list no octopuses' '
check_revlist "--max-parents=2" one normalmerge eight seven six five four three two
'

test_expect_success 'rev-list no roots' '
check_revlist "--min-parents=1" tetrapus tripus normalmerge eight seven six four three two
'

test_expect_success 'rev-list merges' '
check_revlist "--min-parents=2" tetrapus tripus normalmerge &&
check_revlist "--merges" tetrapus tripus normalmerge
'

test_expect_success 'rev-list octopus' '
check_revlist "--min-parents=3" tetrapus tripus
'

test_expect_success 'rev-list ordinary commits' '
check_revlist "--min-parents=1 --max-parents=1" eight seven six four three two
'

test_expect_success 'rev-list --merges --no-merges yields empty set' '
check_revlist "--min-parents=2 --no-merges" &&
check_revlist "--merges --no-merges" &&
check_revlist "--no-merges --merges"
'

test_expect_success 'rev-list override and infinities' '
check_revlist "--min-parents=2 --max-parents=1 --max-parents=3" tripus normalmerge &&
check_revlist "--min-parents=1 --min-parents=2 --max-parents=7" tetrapus tripus normalmerge &&
check_revlist "--min-parents=2 --max-parents=8" tetrapus tripus normalmerge &&
check_revlist "--min-parents=2 --max-parents=-1" tetrapus tripus normalmerge &&
check_revlist "--min-parents=2 --no-max-parents" tetrapus tripus normalmerge &&
check_revlist "--max-parents=0 --min-parents=1 --no-min-parents" one five
'

test_expect_success 'set up dodecapus' '
for i in 1 2 3 4 5 6 7 8 9 10 11
do
git checkout -b root$i five || return
test_commit $i || return
done &&
git checkout master &&
test_tick &&
git merge -m dodecapus root{1,2,3,4,5,6,7,8,9,10,11} &&
git tag dodecapus
'

test_expect_success 'test with dodecapus' '
check_revlist "--min-parents=4" dodecapus tetrapus &&
check_revlist "--min-parents=8" dodecapus &&
check_revlist "--min-parents=12" dodecapus &&
check_revlist "--min-parents=13" &&
check_revlist "--min-parents=4 --max-parents=11" tetrapus
'
test_done

0 comments on commit 6a6ebde

Please sign in to comment.