summaryrefslogtreecommitdiff
path: root/t/t4217-log-limit.sh
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@vmiklos.hu>2022-04-23 14:59:57 +0200
committerJunio C Hamano <gitster@pobox.com>2022-04-23 09:36:07 -0700
commit96697781e06e1b67aeee35a8798deb37e0b87ef4 (patch)
treeb187e290137ea128162943238f369cb65fb21066 /t/t4217-log-limit.sh
parent6cd33dceed60949e2dbc32e3f0f5e67c4c882e1e (diff)
downloadgit-96697781e06e1b67aeee35a8798deb37e0b87ef4.tar.gz
log: "--since-as-filter" option is a non-terminating "--since" variant
The "--since=<time>" option of "git log" limits the commits displayed by the command by stopping the traversal once it sees a commit whose timestamp is older than the given time and not digging further into its parents. This is OK in a history where a commit always has a newer timestamp than any of its parents'. Once you see a commit older than the given <time>, all ancestor commits of it are even older than the time anyway. It poses, however, a problem when there is a commit with a wrong timestamp that makes it appear older than its parents. Stopping traversal at the "incorrectly old" commit will hide its ancestors that are newer than that wrong commit and are newer than the cut-off time given with the --since option. --max-age and --after being the synonyms to --since, they share the same issue. Add a new "--since-as-filter" option that is a variant of "--since=<time>". Instead of stopping the traversal to hide an old enough commit and its all ancestors, exclude commits with an old timestamp from the output but still keep digging the history. Without other traversal stopping options, this will force the command in "git log" family to dig down the history to the root. It may be an acceptable cost for a small project with short history and many commits with screwy timestamps. It is quite unlikely for us to add traversal stopper other than since, so have this as a --since-as-filter option, rather than a separate --as-filter, that would be probably more confusing. Signed-off-by: Miklos Vajna <vmiklos@vmiklos.hu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4217-log-limit.sh')
-rwxr-xr-xt/t4217-log-limit.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/t/t4217-log-limit.sh b/t/t4217-log-limit.sh
new file mode 100755
index 0000000000..6e01e2629c
--- /dev/null
+++ b/t/t4217-log-limit.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+test_description='git log with filter options limiting the output'
+
+. ./test-lib.sh
+
+test_expect_success 'setup test' '
+ git init &&
+ echo a >file &&
+ git add file &&
+ GIT_COMMITTER_DATE="2021-02-01 00:00" git commit -m init &&
+ echo a >>file &&
+ git add file &&
+ GIT_COMMITTER_DATE="2022-02-01 00:00" git commit -m first &&
+ echo a >>file &&
+ git add file &&
+ GIT_COMMITTER_DATE="2021-03-01 00:00" git commit -m second &&
+ echo a >>file &&
+ git add file &&
+ GIT_COMMITTER_DATE="2022-03-01 00:00" git commit -m third
+'
+
+test_expect_success 'git log --since-as-filter=...' '
+ git log --since-as-filter="2022-01-01" --format=%s >actual &&
+ cat >expect <<-\EOF &&
+ third
+ first
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'git log --children --since-as-filter=...' '
+ git log --children --since-as-filter="2022-01-01" --format=%s >actual &&
+ cat >expect <<-\EOF &&
+ third
+ first
+ EOF
+ test_cmp expect actual
+'
+
+test_done