10 static unsigned char current_commit_sha1[20];
12 static const char commitS[] = "commit";
13 static const char treeS[] = "tree";
14 static const char blobS[] = "blob";
16 static void report_missing(const char *what, const unsigned char *missing)
20 strcpy(missing_hex, sha1_to_hex(missing));;
22 "Cannot obtain needed %s %s\nwhile processing commit %s.\n",
23 what, missing_hex, sha1_to_hex(current_commit_sha1));
26 static int make_sure_we_have_it(const char *what, unsigned char *sha1)
29 if (has_sha1_file(sha1))
33 report_missing(what, sha1);
37 static int process_tree(unsigned char *sha1)
39 struct tree *tree = lookup_tree(sha1);
40 struct tree_entry_list *entries;
45 for (entries = tree->entries; entries; entries = entries->next) {
46 const char *what = entries->directory ? treeS : blobS;
47 if (make_sure_we_have_it(what, entries->item.tree->object.sha1))
49 if (entries->directory) {
50 if (process_tree(entries->item.tree->object.sha1))
57 static int process_commit(unsigned char *sha1)
59 struct commit *obj = lookup_commit(sha1);
61 if (make_sure_we_have_it(commitS, sha1))
64 if (parse_commit(obj))
68 if (make_sure_we_have_it(treeS, obj->tree->object.sha1))
70 if (process_tree(obj->tree->object.sha1))
76 struct commit_list *parents = obj->parents;
77 for (; parents; parents = parents->next) {
78 if (has_sha1_file(parents->item->object.sha1))
80 if (make_sure_we_have_it(NULL,
81 parents->item->object.sha1)) {
82 /* The server might not have it, and
87 if (process_commit(parents->item->object.sha1))
89 memcpy(current_commit_sha1, sha1, 20);
95 int pull(char *target)
98 unsigned char sha1[20];
99 retval = get_sha1_hex(target, sha1);
102 retval = make_sure_we_have_it(commitS, sha1);
105 memcpy(current_commit_sha1, sha1, 20);
106 return process_commit(sha1);