]> git.ipfire.org Git - thirdparty/git.git/blame - rev-list.c
commit: save the commit buffer off when parsing a commit
[thirdparty/git.git] / rev-list.c
CommitLineData
64745109
LT
1#include "cache.h"
2#include "commit.h"
3
4int main(int argc, char **argv)
5{
6 unsigned char sha1[20];
7 struct commit_list *list = NULL;
8 struct commit *commit;
fcfda02b
KS
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;
64745109 14
fcfda02b
KS
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))
667bb59b 30 usage("usage: git-rev-list [OPTION] commit-id\n"
fcfda02b
KS
31 " --max-count=nr\n"
32 " --max-age=epoch\n"
33 " --min-age=epoch\n");
64745109
LT
34
35 commit = lookup_commit(sha1);
36 if (!commit || parse_commit(commit) < 0)
37 die("bad commit object");
38
39 commit_list_insert(commit, &list);
40 do {
58e28af6 41 struct commit *commit = pop_most_recent_commit(&list, 0x1);
fcfda02b
KS
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;
64745109
LT
49 printf("%s\n", sha1_to_hex(commit->object.sha1));
50 } while (list);
51 return 0;
52}