[PATCH] Build commands through object files
[git/dscho.git] / build-rev-cache.c
blob948898beb40bde59fdc425260e7208b26b00e271
1 #include "refs.h"
2 #include "cache.h"
3 #include "commit.h"
4 #include "rev-cache.h"
6 static void process_head_list(int verbose)
8 char buf[512];
10 while (fgets(buf, sizeof(buf), stdin)) {
11 unsigned char sha1[20];
12 struct commit *commit;
14 if (get_sha1_hex(buf, sha1)) {
15 error("ignoring: %s", buf);
16 continue;
18 if (!(commit = lookup_commit_reference(sha1))) {
19 error("not a commit: %s", sha1_to_hex(sha1));
20 continue;
22 record_rev_cache(commit->object.sha1, verbose ? stderr : NULL);
27 static const char *build_rev_cache_usage =
28 "git-build-rev-cache <rev-cache-file> < list-of-heads";
30 int main(int ac, char **av)
32 int verbose = 0;
33 const char *path;
35 while (1 < ac && av[1][0] == '-') {
36 if (!strcmp(av[1], "-v"))
37 verbose = 1;
38 else
39 usage(build_rev_cache_usage);
40 ac--; av++;
43 if (ac != 2)
44 usage(build_rev_cache_usage);
46 path = av[1];
48 /* read existing rev-cache */
49 read_rev_cache(path, NULL, 0);
51 process_head_list(verbose);
53 /* update the rev-cache database by appending newly found one to it */
54 write_rev_cache(path, path);
55 return 0;