9 /* 1 means "get delta", 2 means "really check delta harder */
12 int get_verbosely
= 0;
13 static unsigned char current_commit_sha1
[20];
15 static const char commitS
[] = "commit";
16 static const char treeS
[] = "tree";
17 static const char blobS
[] = "blob";
19 void pull_say(const char *fmt
, const char *hex
) {
21 fprintf(stderr
, fmt
, hex
);
24 static void report_missing(const char *what
, const unsigned char *missing
)
28 strcpy(missing_hex
, sha1_to_hex(missing
));;
30 "Cannot obtain needed %s %s\nwhile processing commit %s.\n",
31 what
, missing_hex
, sha1_to_hex(current_commit_sha1
));
34 static int make_sure_we_have_it(const char *what
, unsigned char *sha1
)
38 if (!has_sha1_file(sha1
)) {
41 report_missing(what
, sha1
);
43 else if (get_delta
< 2)
48 status
= sha1_delta_base(sha1
, delta_sha1
);
50 status
= make_sure_we_have_it(what
, delta_sha1
);
55 static int process_tree(unsigned char *sha1
)
57 struct tree
*tree
= lookup_tree(sha1
);
58 struct tree_entry_list
*entries
;
63 for (entries
= tree
->entries
; entries
; entries
= entries
->next
) {
64 const char *what
= entries
->directory
? treeS
: blobS
;
65 if (make_sure_we_have_it(what
, entries
->item
.tree
->object
.sha1
))
67 if (entries
->directory
) {
68 if (process_tree(entries
->item
.tree
->object
.sha1
))
75 static int process_commit(unsigned char *sha1
)
77 struct commit
*obj
= lookup_commit(sha1
);
79 if (make_sure_we_have_it(commitS
, sha1
))
82 if (parse_commit(obj
))
86 if (make_sure_we_have_it(treeS
, obj
->tree
->object
.sha1
))
88 if (process_tree(obj
->tree
->object
.sha1
))
94 struct commit_list
*parents
= obj
->parents
;
95 for (; parents
; parents
= parents
->next
) {
96 if (has_sha1_file(parents
->item
->object
.sha1
))
98 if (make_sure_we_have_it(NULL
,
99 parents
->item
->object
.sha1
)) {
100 /* The server might not have it, and
105 if (process_commit(parents
->item
->object
.sha1
))
107 memcpy(current_commit_sha1
, sha1
, 20);
113 int pull(char *target
)
116 unsigned char sha1
[20];
117 retval
= get_sha1_hex(target
, sha1
);
120 retval
= make_sure_we_have_it(commitS
, sha1
);
123 memcpy(current_commit_sha1
, sha1
, 20);
124 return process_commit(sha1
);