12 static int commits
= 0;
18 static int fetch(unsigned char *sha1
)
20 if (has_sha1_file(sha1
))
22 write(fd_out
, sha1
, 20);
23 return write_sha1_from_fd(sha1
, fd_in
);
26 static int process_tree(unsigned char *sha1
)
28 struct tree
*tree
= lookup_tree(sha1
);
29 struct tree_entry_list
*entries
;
34 for (entries
= tree
->entries
; entries
; entries
= entries
->next
) {
36 fprintf(stderr, "Tree %s ", sha1_to_hex(sha1));
37 fprintf(stderr, "needs %s\n",
38 sha1_to_hex(entries->item.tree->object.sha1));
40 if (fetch(entries
->item
.tree
->object
.sha1
)) {
41 return error("Missing item %s",
42 sha1_to_hex(entries
->item
.tree
->object
.sha1
));
44 if (entries
->directory
) {
45 if (process_tree(entries
->item
.tree
->object
.sha1
))
52 static int process_commit(unsigned char *sha1
)
54 struct commit
*obj
= lookup_commit(sha1
);
57 return error("Fetching %s", sha1_to_hex(sha1
));
60 if (parse_commit(obj
))
64 if (fetch(obj
->tree
->object
.sha1
))
66 if (process_tree(obj
->tree
->object
.sha1
))
72 struct commit_list
*parents
= obj
->parents
;
73 for (; parents
; parents
= parents
->next
) {
74 if (has_sha1_file(parents
->item
->object
.sha1
))
76 if (fetch(parents
->item
->object
.sha1
)) {
77 /* The server might not have it, and
80 error("Missing tree %s; continuing",
81 sha1_to_hex(parents
->item
->object
.sha1
));
84 if (process_commit(parents
->item
->object
.sha1
))
91 int main(int argc
, char **argv
)
96 unsigned char sha1
[20];
98 while (arg
< argc
&& argv
[arg
][0] == '-') {
99 if (argv
[arg
][1] == 't') {
101 } else if (argv
[arg
][1] == 'c') {
103 } else if (argv
[arg
][1] == 'a') {
110 if (argc
< arg
+ 2) {
111 usage("rpull [-c] [-t] [-a] commit-id url");
114 commit_id
= argv
[arg
];
117 if (setup_connection(&fd_in
, &fd_out
, "rpush", url
, arg
, argv
+ 1))
120 get_sha1_hex(commit_id
, sha1
);
124 if (process_commit(sha1
))