[PATCH] Move pathspec to the beginning of the diffcore chain.
[git/haiku.git] / rev-list.c
blob93bee1962bed94df4b91d54e7f38d5e204451a88
1 #include "cache.h"
2 #include "commit.h"
4 static const char rev_list_usage[] =
5 "usage: git-rev-list [OPTION] commit-id <commit-id>\n"
6 " --max-count=nr\n"
7 " --max-age=epoch\n"
8 " --min-age=epoch\n"
9 " --header";
11 int main(int argc, char **argv)
13 int nr_sha;
14 unsigned char sha1[2][20];
15 struct commit_list *list = NULL;
16 struct commit *commit, *end;
17 int i, verbose_header = 0;
18 unsigned long max_age = -1;
19 unsigned long min_age = -1;
20 int max_count = -1;
22 nr_sha = 0;
23 for (i = 1 ; i < argc; i++) {
24 char *arg = argv[i];
26 if (!strncmp(arg, "--max-count=", 12)) {
27 max_count = atoi(arg + 12);
28 continue;
30 if (!strncmp(arg, "--max-age=", 10)) {
31 max_age = atoi(arg + 10);
32 continue;
34 if (!strncmp(arg, "--min-age=", 10)) {
35 min_age = atoi(arg + 10);
36 continue;
38 if (!strcmp(arg, "--header")) {
39 verbose_header = 1;
40 continue;
43 if (nr_sha > 2 || get_sha1(arg, sha1[nr_sha]))
44 usage(rev_list_usage);
45 nr_sha++;
48 if (!nr_sha)
49 usage(rev_list_usage);
51 commit = lookup_commit_reference(sha1[0]);
52 if (!commit || parse_commit(commit) < 0)
53 die("bad starting commit object");
55 end = NULL;
56 if (nr_sha > 1) {
57 end = lookup_commit_reference(sha1[1]);
58 if (!end || parse_commit(end) < 0)
59 die("bad ending commit object");
62 commit_list_insert(commit, &list);
63 do {
64 struct commit *commit = pop_most_recent_commit(&list, 0x1);
66 if (commit == end)
67 break;
68 if (min_age != -1 && (commit->date > min_age))
69 continue;
70 if (max_age != -1 && (commit->date < max_age))
71 break;
72 if (max_count != -1 && !max_count--)
73 break;
74 printf("%s\n", sha1_to_hex(commit->object.sha1));
75 if (verbose_header)
76 printf("%s%c", commit->buffer, 0);
77 } while (list);
78 return 0;