[PATCH] Support downloading packs by HTTP (whitespace fixed)
[git/git.git] / missing-revs.c
1 #include "cache.h"
2 #include "rev-cache.h"
3
4 static const char missing_revs_usage[] =
5 "git-missing-revs <rev-cache-file> <want-sha1>...";
6
7 #define REV_WANT 01
8 #define REV_HAVE 02
9
10 static void process(struct rev_cache *head_list)
11 {
12 while (head_list) {
13 struct rev_cache *rc = head_list;
14 struct rev_list_elem *e;
15 head_list = rc->head_list;
16 rc->head_list = NULL;
17 if (has_sha1_file(rc->sha1)) {
18 rc->work |= REV_HAVE;
19 continue;
20 }
21 if (rc->work & (REV_WANT|REV_HAVE))
22 continue;
23 rc->work |= REV_WANT;
24 printf("%s\n", sha1_to_hex(rc->sha1));
25 for (e = rc->parents; e; e = e->next) {
26 if (e->ri->work & REV_HAVE)
27 continue;
28 e->ri->head_list = head_list;
29 head_list = e->ri;
30 }
31 }
32 }
33
34 int main(int ac, char **av)
35 {
36 const char *rev_cache_file;
37 struct rev_cache *head_list = NULL;
38 int i;
39
40 if (ac < 3)
41 usage(missing_revs_usage);
42 rev_cache_file = av[1];
43 read_rev_cache(rev_cache_file, NULL, 0);
44 for (i = 2; i < ac; i++) {
45 unsigned char sha1[20];
46 int pos;
47 struct rev_cache *rc;
48 if (get_sha1_hex(av[i], sha1))
49 die("%s: not an SHA1", av[i]);
50 if ((pos = find_rev_cache(sha1)) < 0) {
51 /* We could be asked for tags, which would not
52 * appear in the rev-cache.
53 */
54 puts(av[i]);
55 continue;
56 }
57 rc = rev_cache[pos];
58 rc->head_list = head_list;
59 head_list = rc;
60 }
61 process(head_list);
62 return 0;
63 }