10 int get_verbosely
= 0;
11 static unsigned char current_commit_sha1
[20];
13 static const char commitS
[] = "commit";
14 static const char treeS
[] = "tree";
15 static const char blobS
[] = "blob";
17 void pull_say(const char *fmt
, const char *hex
) {
19 fprintf(stderr
, fmt
, hex
);
22 static void report_missing(const char *what
, const unsigned char *missing
)
26 strcpy(missing_hex
, sha1_to_hex(missing
));;
28 "Cannot obtain needed %s %s\nwhile processing commit %s.\n",
29 what
, missing_hex
, sha1_to_hex(current_commit_sha1
));
32 static int make_sure_we_have_it(const char *what
, unsigned char *sha1
)
35 if (has_sha1_file(sha1
))
39 report_missing(what
, sha1
);
43 static int process_tree(unsigned char *sha1
)
45 struct tree
*tree
= lookup_tree(sha1
);
46 struct tree_entry_list
*entries
;
51 for (entries
= tree
->entries
; entries
; entries
= entries
->next
) {
52 const char *what
= entries
->directory
? treeS
: blobS
;
53 if (make_sure_we_have_it(what
, entries
->item
.tree
->object
.sha1
))
55 if (entries
->directory
) {
56 if (process_tree(entries
->item
.tree
->object
.sha1
))
63 static int process_commit(unsigned char *sha1
)
65 struct commit
*obj
= lookup_commit(sha1
);
67 if (make_sure_we_have_it(commitS
, sha1
))
70 if (parse_commit(obj
))
74 if (make_sure_we_have_it(treeS
, obj
->tree
->object
.sha1
))
76 if (process_tree(obj
->tree
->object
.sha1
))
82 struct commit_list
*parents
= obj
->parents
;
83 for (; parents
; parents
= parents
->next
) {
84 if (has_sha1_file(parents
->item
->object
.sha1
))
86 if (make_sure_we_have_it(NULL
,
87 parents
->item
->object
.sha1
)) {
88 /* The server might not have it, and
93 if (process_commit(parents
->item
->object
.sha1
))
95 memcpy(current_commit_sha1
, sha1
, 20);
101 int pull(char *target
)
104 unsigned char sha1
[20];
105 retval
= get_sha1_hex(target
, sha1
);
108 retval
= make_sure_we_have_it(commitS
, sha1
);
111 memcpy(current_commit_sha1
, sha1
, 20);
112 return process_commit(sha1
);