git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] rev-list: make --max- and --min-age a bit more usable.

From
Junio C Hamano <junkio@cox.net>
Date
Nov 2, 2005, 19:02 UTC
Message-ID
<7vbr12swj3.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0510301838110.27915@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> 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 <junkio@cox.net>
        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 <junkio@cox.net>
        A-Date: Sat Oct 22 01:28:13 2005 -0700
        Commit: Junio C Hamano <junkio@cox.net>
        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 <junkio@cox.net>
---
 rev-list.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

applies-to: 0c9683fe37dbc43713faaa15fcce14bfe5621bba 9dc13af3f916803d270d3387032eb0e91b940417

diff --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
Previous: Daniel BarkalowNext: Linus Torvalds
Message 24 of 26 in “GIT 0.99.9”
  1. Junio C HamanoOct 30, 2005
  2. A Large Angry SCMOct 30, 2005
  3. Junio C HamanoOct 30, 2005
  4. A Large Angry SCMOct 30, 2005
  5. Johannes SchindelinOct 30, 2005
  6. Linus TorvaldsOct 30, 2005
  7. rev-list --sparse?Junio C Hamano, Oct 30, 2005
  8. Linus TorvaldsOct 30, 2005
  9. Junio C HamanoOct 30, 2005
  10. Wolfgang DenkOct 30, 2005
  11. Junio C HamanoOct 30, 2005
  12. Wolfgang DenkOct 30, 2005
  13. Junio C HamanoOct 30, 2005
  14. Wolfgang DenkOct 30, 2005
  15. Ryan AndersonOct 30, 2005
  16. Junio C HamanoOct 30, 2005
  17. H. Peter AnvinOct 30, 2005
  18. Linus TorvaldsOct 31, 2005
  19. Junio C HamanoOct 31, 2005
  20. Linus TorvaldsOct 31, 2005
  21. Date-based limits (Was Re: GIT 0.99.9)Daniel Barkalow, Oct 31, 2005
  22. Junio C HamanoNov 1, 2005
  23. Daniel BarkalowNov 1, 2005
  24. rev-list: make --max- and --min-age a bit more usable.Junio C Hamano, Nov 2, 2005
  25. Linus TorvaldsNov 3, 2005
  26. Junio C HamanoNov 3, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.