[PATCH] Add tests for diff-tree
[git/dscho.git] / rev-list.c
blob94e52d2edf78f8fce4c8f6dce290f4f13ca901b3
1 #include "cache.h"
2 #include "commit.h"
4 int main(int argc, char **argv)
6 unsigned char sha1[20];
7 struct commit_list *list = NULL;
8 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;
15 for (i = 1 ; i < argc; i++) {
16 char *arg = argv[i];
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;
29 if (!commit_arg || get_sha1(commit_arg, sha1))
30 usage("usage: git-rev-list [OPTION] commit-id\n"
31 " --max-count=nr\n"
32 " --max-age=epoch\n"
33 " --min-age=epoch\n");
35 commit = lookup_commit(sha1);
36 if (!commit || parse_commit(commit) < 0)
37 die("bad commit object");
39 commit_list_insert(commit, &list);
40 do {
41 struct commit *commit = pop_most_recent_commit(&list, 0x1);
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;
49 printf("%s\n", sha1_to_hex(commit->object.sha1));
50 } while (list);
51 return 0;