rev-list --min-parents,--max-parents: doc, test and completion

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>
This commit is contained in:
Michael J Gruber 2011-03-23 10:38:51 +01:00 committed by Junio C Hamano
parent ad5aeeded3
commit 6a6ebded7f
4 changed files with 129 additions and 3 deletions

View file

@ -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 ]

View file

@ -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

View file

@ -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="

View file

@ -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 &&
@ -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