Skip to content

Commit fcfda02

Browse files
kaysieversLinus Torvalds
authored andcommitted
[PATCH] control/limit output of git-rev-list
gitweb.cgi's default view is the log of the last day and git-rev-list can stop crawling the whole repo if we have all our data to display in the browser. Also the rss-feed query needs only the last 20 items. This will speeds up these queries dramatically. usage: rev-list [OPTION] commit-id --max-count=nr --max-age=epoch --min-age=epoch Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 22b7810 commit fcfda02

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

rev-list.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,31 @@ int main(int argc, char **argv)
66
unsigned char sha1[20];
77
struct commit_list *list = NULL;
88
struct commit *commit;
9+
char *commit_arg = NULL;
10+
int i;
11+
unsigned long max_age = -1;
12+
unsigned long min_age = -1;
13+
int max_count = -1;
914

10-
if (argc != 2 || get_sha1(argv[1], sha1))
11-
usage("rev-list <commit-id>");
15+
for (i = 1 ; i < argc; i++) {
16+
char *arg = argv[i];
17+
18+
if (!strncmp(arg, "--max-count=", 12)) {
19+
max_count = atoi(arg + 12);
20+
} else if (!strncmp(arg, "--max-age=", 10)) {
21+
max_age = atoi(arg + 10);
22+
} else if (!strncmp(arg, "--min-age=", 10)) {
23+
min_age = atoi(arg + 10);
24+
} else {
25+
commit_arg = arg;
26+
}
27+
}
28+
29+
if (!commit_arg || get_sha1(commit_arg, sha1))
30+
usage("usage: rev-list [OPTION] commit-id\n"
31+
" --max-count=nr\n"
32+
" --max-age=epoch\n"
33+
" --min-age=epoch\n");
1234

1335
commit = lookup_commit(sha1);
1436
if (!commit || parse_commit(commit) < 0)
@@ -17,6 +39,13 @@ int main(int argc, char **argv)
1739
commit_list_insert(commit, &list);
1840
do {
1941
struct commit *commit = pop_most_recent_commit(&list, 0x1);
42+
43+
if (min_age != -1 && (commit->date > min_age))
44+
continue;
45+
if (max_age != -1 && (commit->date < max_age))
46+
break;
47+
if (max_count != -1 && !max_count--)
48+
break;
2049
printf("%s\n", sha1_to_hex(commit->object.sha1));
2150
} while (list);
2251
return 0;

0 commit comments

Comments
 (0)