11 int get_verbosely = 0;
12 static unsigned char current_commit_sha1[20];
14 static const char commitS[] = "commit";
15 static const char treeS[] = "tree";
16 static const char blobS[] = "blob";
18 void pull_say(const char *fmt, const char *hex) {
20 fprintf(stderr, fmt, hex);
23 static void report_missing(const char *what, const unsigned char *missing)
27 strcpy(missing_hex, sha1_to_hex(missing));;
29 "Cannot obtain needed %s %s\nwhile processing commit %s.\n",
30 what, missing_hex, sha1_to_hex(current_commit_sha1));
33 static int make_sure_we_have_it(const char *what, unsigned char *sha1)
36 if (has_sha1_file(sha1))
40 report_missing(what, sha1);
43 status = sha1_delta_base(sha1, delta_sha1);
45 status = make_sure_we_have_it(what, delta_sha1);
50 static int process_tree(unsigned char *sha1)
52 struct tree *tree = lookup_tree(sha1);
53 struct tree_entry_list *entries;
58 for (entries = tree->entries; entries; entries = entries->next) {
59 const char *what = entries->directory ? treeS : blobS;
60 if (make_sure_we_have_it(what, entries->item.tree->object.sha1))
62 if (entries->directory) {
63 if (process_tree(entries->item.tree->object.sha1))
70 static int process_commit(unsigned char *sha1)
72 struct commit *obj = lookup_commit(sha1);
74 if (make_sure_we_have_it(commitS, sha1))
77 if (parse_commit(obj))
81 if (make_sure_we_have_it(treeS, obj->tree->object.sha1))
83 if (process_tree(obj->tree->object.sha1))
89 struct commit_list *parents = obj->parents;
90 for (; parents; parents = parents->next) {
91 if (has_sha1_file(parents->item->object.sha1))
93 if (make_sure_we_have_it(NULL,
94 parents->item->object.sha1)) {
95 /* The server might not have it, and
100 if (process_commit(parents->item->object.sha1))
102 memcpy(current_commit_sha1, sha1, 20);
108 int pull(char *target)
111 unsigned char sha1[20];
112 retval = get_sha1_hex(target, sha1);
115 retval = make_sure_we_have_it(commitS, sha1);
118 memcpy(current_commit_sha1, sha1, 20);
119 return process_commit(sha1);