[PATCH] Add debugging help for case #16 to read-tree.c
[git/jnareb-git/bp-gitweb.git] / export.c
blobce10b5a298699897bfefa4a5093f92b8c9501450
1 #include "cache.h"
2 #include "commit.h"
4 /*
5 * Show one commit
6 */
7 static void show_commit(struct commit *commit)
9 char cmdline[400];
10 char hex[100];
12 strcpy(hex, sha1_to_hex(commit->object.sha1));
13 printf("Id: %s\n", hex);
14 fflush(NULL);
15 sprintf(cmdline, "git-cat-file commit %s", hex);
16 system(cmdline);
17 if (commit->parents) {
18 char *against = sha1_to_hex(commit->parents->item->object.sha1);
19 printf("\n\n======== diff against %s ========\n", against);
20 fflush(NULL);
21 sprintf(cmdline, "git-diff-tree -p %s %s", against, hex);
22 system(cmdline);
24 printf("======== end ========\n\n");
28 * Show all unseen commits, depth-first
30 static void show_unseen(struct commit *top)
32 struct commit_list *parents;
34 if (top->object.flags & 2)
35 return;
36 top->object.flags |= 2;
37 parents = top->parents;
38 while (parents) {
39 show_unseen(parents->item);
40 parents = parents->next;
42 show_commit(top);
45 static void export(struct commit *top, struct commit *base)
47 mark_reachable(&top->object, 1);
48 if (base)
49 mark_reachable(&base->object, 2);
50 show_unseen(top);
53 static struct commit *get_commit(unsigned char *sha1)
55 struct commit *commit = lookup_commit(sha1);
56 if (!commit->object.parsed) {
57 struct commit_list *parents;
59 if (parse_commit(commit) < 0)
60 die("unable to parse commit %s", sha1_to_hex(sha1));
61 parents = commit->parents;
62 while (parents) {
63 get_commit(parents->item->object.sha1);
64 parents = parents->next;
67 return commit;
70 int main(int argc, char **argv)
72 unsigned char base_sha1[20];
73 unsigned char top_sha1[20];
75 if (argc < 2 || argc > 4 ||
76 get_sha1(argv[1], top_sha1) ||
77 (argc == 3 && get_sha1(argv[2], base_sha1)))
78 usage("git-export top [base]");
79 export(get_commit(top_sha1), argc==3 ? get_commit(base_sha1) : NULL);
80 return 0;