[PATCH] rev-list: make --max- and --min-age a bit more usable.
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:10
Subsystem:
the rest · Maintainer:
Linus Torvalds
Possibly related (same subject, not in this thread)
- 2016-06-15 · Re: [PATCH] rev-list: make --max- and --min-age a bit more usable. · Junio C Hamano <hidden>
Linus Torvalds [off-list ref] writes:
I've several times been surprised to see people not realize that "git-whatchanged" takes a file list to limit the files it is interested in. I also suspect people don't realize that you can limit it by time and version and file list, all at the same time.
The current "time based limiting" is not very user friendly, so people not knowing the limit-by-time is not a surprise.
git-whatchanged -p --pretty=short --since="2 weeks ago" v0.99.8..v0.99.9 Makefile is a valid query
Well, it is not a valid query ;-) Nobody implemented --since
yet, but you could spell it --max-age. It would not grok "2
weeks ago" though.
With the attached patch, you could at least do:
git log --max-age='2005-10-25' v0.99.8..v0.99.9 Makefile
There are still a couple of things that bothers me.
(1) The underlying workhorse, rev-list, takes max-age and
min-age. While these names are logically correct, it feels
a bit hard and counterintuitive when deciding which one to
use in order to ask "what are the ones that happened after
Wednesday last week?". The query talks about the commits
being young, so --max-age=2005-10-26 is the right query
(i.e. "I want to discard things that are older than that
time"), but as soon as I type "max", my mind starts
comparing date strings, and surely 2005-10-21 is smaller
than 2005-10-26 and I am saying 2005-10-26 is the max, which
confuses me to think that 2005-10-21 would be included in
the result (it would not be -- we are talking about age, so
2005-10-21 one is older, which means its age is greater than
specified). It takes some mental effort to do this, at least
for me.
I *hate* to suggest this change at this late stage of the
game, but maybe they should be renamed or at least acquire
less confusing synonyms, perhaps?
--max-age = --min-timestamp, --since
--min-age = --max-timestamp, --until
(2) If I run the above --max-age query, the last commit
displayed is this one:
commit f3123c4ab3d3698262e59561ac084de45b10365a
Author: Junio C Hamano [off-list ref]
Date: Sat Oct 22 01:28:13 2005 -0700
This is because the age limit uses commit date (which is a
sensible thing to do) while the display shows author date.
To an uninitiated, this takes some explanation and
justification (i.e. counterintuitive again).
Incidenally, I have not found a way to prettyprint the
commit date; --pretty=raw gives that information, but in
really raw format. --pretty=full does not even give any
timestamp.
Again I *hate* to suggest this, but maybe --pretty=full
should show both author and commit timestamp as well, like
this?
commit f3123c4ab3d3698262e59561ac084de45b10365a
Author: Junio C Hamano [off-list ref]
A-Date: Sat Oct 22 01:28:13 2005 -0700
Commit: Junio C Hamano [off-list ref]
C-Date: Wed Oct 26 12:37:49 2005 -0700
-- >8 -- cut here -- >8 --
Earlier we just did atoi to accept these parameters, which meant
that the user needed to specify the raw UNIX time format to use
them.
This still does not make it accept '2 weeks ago', but at least
it now can take --max-age='2005-10-15', which is a start.
Signed-off-by: Junio C Hamano <redacted>
---
rev-list.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
applies-to: 0c9683fe37dbc43713faaa15fcce14bfe5621bba
9dc13af3f916803d270d3387032eb0e91b940417diff --git a/rev-list.c b/rev-list.c
index 6e6ffde..7a73703 100644
--- a/rev-list.c
+++ b/rev-list.c@@ -712,6 +712,21 @@ static void handle_all(struct commit_lis global_lst = NULL; } +static unsigned long getdate(const char *arg, const char *label) +{ + char text[80]; + unsigned long date; + + if (parse_date(arg, text, sizeof(text)) < 0) { + /* Maybe handle "4 days ago" and the like here... */ + die("bad time specification for %s: %s", label, arg); + } + date = strtoul(text, NULL, 10); + if (date == ULONG_MAX) + die("unparsable time specification for %s: %s", label, arg); + return date; +} + int main(int argc, const char **argv) { const char *prefix = setup_git_directory();
@@ -730,12 +745,12 @@ int main(int argc, const char **argv) continue; } if (!strncmp(arg, "--max-age=", 10)) { - max_age = atoi(arg + 10); + max_age = getdate(arg + 10, "max-age"); limited = 1; continue; } if (!strncmp(arg, "--min-age=", 10)) { - min_age = atoi(arg + 10); + min_age = getdate(arg + 10, "min-age"); limited = 1; continue; }
--- 0.99.9.GIT