@matheusbsbs / matheus-bagliano / commits / c1babb1d65
Fork 0

[PATCH] Teach "git-rev-parse" about date-based cut-offs

This adds the options "--since=date" and "--before=date" to git-rev-parse, which knows how to translate them into seconds since the epoch for git-rev-list. With this, you can do git log --since="2 weeks ago" or git log --until=yesterday to show the commits that have happened in the last two weeks or are older than 24 hours, respectively. The flags "--after=" and "--before" are synonyms for --since and --until, and you can combine them, so git log --after="Aug 5" --before="Aug 10" is a valid (but strange) thing to do. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Sep 20, 2005 at 14:13 UTC c1babb1d65e034a058c14379eabec8eb374757ca
1 file changed +41
rev-parse.c
+41
@@ -6,6 +6,7 @@
6 #include "cache.h"
7 #include "commit.h"
8 #include "refs.h"
9 +#include "quote.h"
10
11 #define DO_REVS 1
12 #define DO_NOREV 2
@@ -125,6 +126,30 @@ static int show_reference(const char *refname, const unsigned char *sha1)
126 return 0;
127 }
128
129 +static void show_datestring(const char *flag, const char *datestr)
130 +{
131 + FILE *date;
132 + static char buffer[100];
133 + static char cmd[1000];
134 + int len;
135 +
136 + /* date handling requires both flags and revs */
137 + if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS))
138 + return;
139 + len = strlen(flag);
140 + memcpy(buffer, flag, len);
141 +
142 + snprintf(cmd, sizeof(cmd), "date --date=%s +%%s", sq_quote(datestr));
143 + date = popen(cmd, "r");
144 + if (!date || !fgets(buffer + len, sizeof(buffer) - len, date))
145 + die("git-rev-list: bad date string");
146 + pclose(date);
147 + len = strlen(buffer);
148 + if (buffer[len-1] == '\n')
149 + buffer[--len] = 0;
150 + show(buffer);
151 +}
152 +
153 int main(int argc, char **argv)
154 {
155 int i, as_is = 0, verify = 0;
@@ -207,6 +232,22 @@ int main(int argc, char **argv)
232 printf("%s/.git\n", cwd);
233 continue;
234 }
235 + if (!strncmp(arg, "--since=", 8)) {
236 + show_datestring("--max-age=", arg+8);
237 + continue;
238 + }
239 + if (!strncmp(arg, "--after=", 8)) {
240 + show_datestring("--max-age=", arg+8);
241 + continue;
242 + }
243 + if (!strncmp(arg, "--before=", 9)) {
244 + show_datestring("--min-age=", arg+9);
245 + continue;
246 + }
247 + if (!strncmp(arg, "--until=", 8)) {
248 + show_datestring("--min-age=", arg+8);
249 + continue;
250 + }
251 if (verify)
252 die("Needed a single revision");
253 show_flag(arg);