Re: Joining cg-*-id
From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:07
Subsystem:
the rest · Maintainer:
Linus Torvalds
On Tue, 20 Sep 2005, Petr Baudis wrote:
I'll just drop the date revision specifier support from Cogito. I don't know if any measurable number of people actually use it in the real world anyway.
I think the date specifier makes sense for cg-log, though. Ie it doesn't make sense as a generic cg-*-id thing, but it _does_ make sense as a totally log-specific case. Maybe it could use "-d" instead of "-r", since it's really a totally separate control. For example, there's nothing wrong with cg-log -d yesterday v2.6.12.. which would limit the revisions _both_ to a date _and_ to a version. So it's just "diff against time" that makes no sense. But both "git log" and "git whatchanged" are sensible in time: there's no problem with saying "what commits happened in the last 24 hours", but there _is_ a problem with saying "show me the difference from 24 hours ago". See? The "list of commits" is sensible, it's just the "one revision" thing that isn't. Here's a stupid example of how to do this in git. With this silly patch, this like git whatchanged --since="1 month ago" git log --since="5 days ago" gitk --since=yesterday all work. I don't know how _useful_ it is, but it's kind of cool. (Side note: the "gitk" thing works really badly. gitk doesn't quote its arguments to "git-rev-list", so something like gitk --since="1 month ago" does NOT work, while "--since=yesterday" does, because it has no spaces. Gaah. "Obi-Paul Mackerras, you're our only hope") Linus ---
diff --git a/rev-parse.c b/rev-parse.c
--- a/rev-parse.c
+++ b/rev-parse.c@@ -6,6 +6,7 @@ #include "cache.h" #include "commit.h" #include "refs.h" +#include "quote.h" #define DO_REVS 1 #define DO_NOREV 2
@@ -125,6 +126,27 @@ static int show_reference(const char *re return 0; } +static void show_datestring(const char *datestr) +{ + FILE *date; + static char buffer[100] = "--max-age="; + static char cmd[1000]; + int len; + + /* date handling requires both flags and revs */ + if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS)) + return; + snprintf(cmd, sizeof(cmd), "date --date=%s +%%s", sq_quote(datestr)); + date = popen(cmd, "r"); + if (!date || !fgets(buffer + 10, sizeof(buffer) - 10, date)) + die("git-rev-list: bad date string"); + pclose(date); + len = strlen(buffer); + if (buffer[len-1] == '\n') + buffer[--len] = 0; + show(buffer); +} + int main(int argc, char **argv) { int i, as_is = 0, verify = 0;
@@ -207,6 +229,10 @@ int main(int argc, char **argv) printf("%s/.git\n", cwd); continue; } + if (!strncmp(arg, "--since=", 8)) { + show_datestring(arg+8); + continue; + } if (verify) die("Needed a single revision"); show_flag(arg);