Skip to content
This repository
Newer
Older
100644 321 lines (277 sloc) 7.384 kb
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
1 #include "cache.h"
30ae764b »
2007-09-10 Modularize commit-walker
2 #include "walker.h"
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
3 #include "commit.h"
4 #include "tree.h"
1bc995a3 »
2006-05-29 Convert fetch.c: process_tree() to raw tree walker
5 #include "tree-walk.h"
3173bd49 »
2005-06-21 [PATCH] Pull misc objects
6 #include "tag.h"
7 #include "blob.h"
cd541a68 »
2005-06-06 [PATCH] Generic support for pulling refs
8 #include "refs.h"
9
b2d62f16 »
2005-05-04 Make git-*-pull say who wants them for missing objects.
10 static unsigned char current_commit_sha1[20];
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
11
30ae764b »
2007-09-10 Modularize commit-walker
12 void walker_say(struct walker *walker, const char *fmt, const char *hex)
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
13 {
30ae764b »
2007-09-10 Modularize commit-walker
14 if (walker->get_verbosely)
e78d9772 »
2005-05-06 Implement -v (verbose) option for pull methods other than local trans…
15 fprintf(stderr, fmt, hex);
16 }
17
0d7a6e4e »
2006-12-12 Clarify fetch error for missing objects.
18 static void report_missing(const struct object *obj)
b2d62f16 »
2005-05-04 Make git-*-pull say who wants them for missing objects.
19 {
20 char missing_hex[41];
ba19a808 »
2009-02-10 Drop double-semicolon in C
21 strcpy(missing_hex, sha1_to_hex(obj->sha1));
0d7a6e4e »
2006-12-12 Clarify fetch error for missing objects.
22 fprintf(stderr, "Cannot obtain needed %s %s\n",
23 obj->type ? typename(obj->type): "object", missing_hex);
24 if (!is_null_sha1(current_commit_sha1))
25 fprintf(stderr, "while processing commit %s.\n",
26 sha1_to_hex(current_commit_sha1));
b2d62f16 »
2005-05-04 Make git-*-pull say who wants them for missing objects.
27 }
28
30ae764b »
2007-09-10 Modularize commit-walker
29 static int process(struct walker *walker, struct object *obj);
3173bd49 »
2005-06-21 [PATCH] Pull misc objects
30
30ae764b »
2007-09-10 Modularize commit-walker
31 static int process_tree(struct walker *walker, struct tree *tree)
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
32 {
1bc995a3 »
2006-05-29 Convert fetch.c: process_tree() to raw tree walker
33 struct tree_desc desc;
4c068a98 »
2006-05-30 tree_entry(): new tree-walking helper function
34 struct name_entry entry;
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
35
36 if (parse_tree(tree))
37 return -1;
38
6fda5e51 »
2007-03-21 Initialize tree descriptors with a helper function rather than by hand.
39 init_tree_desc(&desc, tree->buffer, tree->size);
4c068a98 »
2006-05-30 tree_entry(): new tree-walking helper function
40 while (tree_entry(&desc, &entry)) {
6f9012b6 »
2006-06-02 fetch.c: do not call process_tree() from process_tree().
41 struct object *obj = NULL;
42
582c7393 »
2007-06-26 Ignore submodule commits when fetching over dumb protocols
43 /* submodule commits are not stored in the superproject */
68fb4650 »
2007-06-26 Merge branch 'maint'
44 if (S_ISGITLINK(entry.mode))
582c7393 »
2007-06-26 Ignore submodule commits when fetching over dumb protocols
45 continue;
4c068a98 »
2006-05-30 tree_entry(): new tree-walking helper function
46 if (S_ISDIR(entry.mode)) {
47 struct tree *tree = lookup_tree(entry.sha1);
6f9012b6 »
2006-06-02 fetch.c: do not call process_tree() from process_tree().
48 if (tree)
49 obj = &tree->object;
50 }
51 else {
4c068a98 »
2006-05-30 tree_entry(): new tree-walking helper function
52 struct blob *blob = lookup_blob(entry.sha1);
6f9012b6 »
2006-06-02 fetch.c: do not call process_tree() from process_tree().
53 if (blob)
54 obj = &blob->object;
2d9c58c6 »
2006-05-29 Remove "tree->entries" tree-entry list from tree parser
55 }
30ae764b »
2007-09-10 Modularize commit-walker
56 if (!obj || process(walker, obj))
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
57 return -1;
58 }
2d9c58c6 »
2006-05-29 Remove "tree->entries" tree-entry list from tree parser
59 free(tree->buffer);
60 tree->buffer = NULL;
1bc995a3 »
2006-05-29 Convert fetch.c: process_tree() to raw tree walker
61 tree->size = 0;
541fc218 »
2008-06-04 Fix "git clone http://$URL" to check out the worktree when asked
62 tree->object.parsed = 0;
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
63 return 0;
64 }
65
24451c31 »
2005-09-21 [PATCH] fetch.c: Clean up object flag definitions
66 #define COMPLETE (1U << 0)
67 #define SEEN (1U << 1)
68 #define TO_SCAN (1U << 2)
85d106c2 »
2005-09-18 Improve the safety check used in fetch.c
69
d0ac30f2 »
2005-09-16 [PATCH] fetch.c: cleanups
70 static struct commit_list *complete = NULL;
22c6e1d0 »
2005-09-14 [PATCH] Fix fetch completeness assumptions
71
30ae764b »
2007-09-10 Modularize commit-walker
72 static int process_commit(struct walker *walker, struct commit *commit)
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
73 {
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
74 if (parse_commit(commit))
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
75 return -1;
76
22c6e1d0 »
2005-09-14 [PATCH] Fix fetch completeness assumptions
77 while (complete && complete->item->date >= commit->date) {
d0ac30f2 »
2005-09-16 [PATCH] fetch.c: cleanups
78 pop_most_recent_commit(&complete, COMPLETE);
22c6e1d0 »
2005-09-14 [PATCH] Fix fetch completeness assumptions
79 }
80
d0ac30f2 »
2005-09-16 [PATCH] fetch.c: cleanups
81 if (commit->object.flags & COMPLETE)
22c6e1d0 »
2005-09-14 [PATCH] Fix fetch completeness assumptions
82 return 0;
83
e702496e »
2006-08-23 Convert memcpy(a,b,20) to hashcpy(a,b).
84 hashcpy(current_commit_sha1, commit->object.sha1);
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
85
30ae764b »
2007-09-10 Modularize commit-walker
86 walker_say(walker, "walk %s\n", sha1_to_hex(commit->object.sha1));
85d106c2 »
2005-09-18 Improve the safety check used in fetch.c
87
30ae764b »
2007-09-10 Modularize commit-walker
88 if (walker->get_tree) {
89 if (process(walker, &commit->tree->object))
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
90 return -1;
30ae764b »
2007-09-10 Modularize commit-walker
91 if (!walker->get_all)
92 walker->get_tree = 0;
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
93 }
30ae764b »
2007-09-10 Modularize commit-walker
94 if (walker->get_history) {
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
95 struct commit_list *parents = commit->parents;
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
96 for (; parents; parents = parents->next) {
30ae764b »
2007-09-10 Modularize commit-walker
97 if (process(walker, &parents->item->object))
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
98 return -1;
99 }
100 }
101 return 0;
102 }
103
30ae764b »
2007-09-10 Modularize commit-walker
104 static int process_tag(struct walker *walker, struct tag *tag)
3173bd49 »
2005-06-21 [PATCH] Pull misc objects
105 {
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
106 if (parse_tag(tag))
3173bd49 »
2005-06-21 [PATCH] Pull misc objects
107 return -1;
30ae764b »
2007-09-10 Modularize commit-walker
108 return process(walker, tag->tagged);
3173bd49 »
2005-06-21 [PATCH] Pull misc objects
109 }
110
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
111 static struct object_list *process_queue = NULL;
112 static struct object_list **process_queue_end = &process_queue;
113
30ae764b »
2007-09-10 Modularize commit-walker
114 static int process_object(struct walker *walker, struct object *obj)
3173bd49 »
2005-06-21 [PATCH] Pull misc objects
115 {
1974632c »
2006-07-11 Remove TYPE_* constant macros and use object_type enums consistently.
116 if (obj->type == OBJ_COMMIT) {
30ae764b »
2007-09-10 Modularize commit-walker
117 if (process_commit(walker, (struct commit *)obj))
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
118 return -1;
119 return 0;
120 }
1974632c »
2006-07-11 Remove TYPE_* constant macros and use object_type enums consistently.
121 if (obj->type == OBJ_TREE) {
30ae764b »
2007-09-10 Modularize commit-walker
122 if (process_tree(walker, (struct tree *)obj))
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
123 return -1;
124 return 0;
125 }
1974632c »
2006-07-11 Remove TYPE_* constant macros and use object_type enums consistently.
126 if (obj->type == OBJ_BLOB) {
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
127 return 0;
128 }
1974632c »
2006-07-11 Remove TYPE_* constant macros and use object_type enums consistently.
129 if (obj->type == OBJ_TAG) {
30ae764b »
2007-09-10 Modularize commit-walker
130 if (process_tag(walker, (struct tag *)obj))
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
131 return -1;
3173bd49 »
2005-06-21 [PATCH] Pull misc objects
132 return 0;
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
133 }
134 return error("Unable to determine requirements "
135 "of type %s for %s",
885a86ab »
2006-06-14 Shrink "struct object" a bit
136 typename(obj->type), sha1_to_hex(obj->sha1));
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
137 }
138
30ae764b »
2007-09-10 Modularize commit-walker
139 static int process(struct walker *walker, struct object *obj)
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
140 {
a82d07e5 »
2005-09-21 [PATCH] fetch.c: Make process() look at each object only once
141 if (obj->flags & SEEN)
142 return 0;
143 obj->flags |= SEEN;
144
80077f07 »
2005-09-21 [PATCH] fetch.c: Remove useless lookup_object_type() call in process()
145 if (has_sha1_file(obj->sha1)) {
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
146 /* We already have it, so we should scan it now. */
85d106c2 »
2005-09-18 Improve the safety check used in fetch.c
147 obj->flags |= TO_SCAN;
e5f38ec3 »
2006-06-06 ref-log: style fixes.
148 }
149 else {
7b64d06b »
2005-09-21 [PATCH] fetch.c: Remove some duplicated code in process()
150 if (obj->flags & COMPLETE)
151 return 0;
30ae764b »
2007-09-10 Modularize commit-walker
152 walker->prefetch(walker, obj->sha1);
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
153 }
a6080a0a »
2007-06-07 War on whitespace
154
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
155 object_list_insert(obj, process_queue_end);
156 process_queue_end = &(*process_queue_end)->next;
157 return 0;
158 }
159
30ae764b »
2007-09-10 Modularize commit-walker
160 static int loop(struct walker *walker)
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
161 {
85d106c2 »
2005-09-18 Improve the safety check used in fetch.c
162 struct object_list *elem;
163
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
164 while (process_queue) {
165 struct object *obj = process_queue->item;
85d106c2 »
2005-09-18 Improve the safety check used in fetch.c
166 elem = process_queue;
167 process_queue = elem->next;
168 free(elem);
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
169 if (!process_queue)
170 process_queue_end = &process_queue;
171
85d106c2 »
2005-09-18 Improve the safety check used in fetch.c
172 /* If we are not scanning this object, we placed it in
173 * the queue because we needed to fetch it first.
174 */
175 if (! (obj->flags & TO_SCAN)) {
30ae764b »
2007-09-10 Modularize commit-walker
176 if (walker->fetch(walker, obj->sha1)) {
0d7a6e4e »
2006-12-12 Clarify fetch error for missing objects.
177 report_missing(obj);
85d106c2 »
2005-09-18 Improve the safety check used in fetch.c
178 return -1;
179 }
180 }
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
181 if (!obj->type)
182 parse_object(obj->sha1);
30ae764b »
2007-09-10 Modularize commit-walker
183 if (process_object(walker, obj))
f88fcf8b »
2005-08-11 [PATCH] Fix parallel pull dependancy tracking.
184 return -1;
1e8be59d »
2005-08-02 [PATCH] Parallelize the pull algorithm
185 }
186 return 0;
3173bd49 »
2005-06-21 [PATCH] Pull misc objects
187 }
188
30ae764b »
2007-09-10 Modularize commit-walker
189 static int interpret_target(struct walker *walker, char *target, unsigned char *sha1)
cd541a68 »
2005-06-06 [PATCH] Generic support for pulling refs
190 {
191 if (!get_sha1_hex(target, sha1))
192 return 0;
193 if (!check_ref_format(target)) {
59c69c0c »
2008-10-18 make alloc_ref_from_str() the new alloc_ref()
194 struct ref *ref = alloc_ref(target);
c13b2633 »
2008-04-26 Make walker.fetch_ref() take a struct ref.
195 if (!walker->fetch_ref(walker, ref)) {
196 hashcpy(sha1, ref->old_sha1);
197 free(ref);
cd541a68 »
2005-06-06 [PATCH] Generic support for pulling refs
198 return 0;
199 }
c13b2633 »
2008-04-26 Make walker.fetch_ref() take a struct ref.
200 free(ref);
cd541a68 »
2005-06-06 [PATCH] Generic support for pulling refs
201 }
202 return -1;
203 }
204
8da19775 »
2006-09-20 Tell between packed, unpacked and symbolic refs.
205 static int mark_complete(const char *path, const unsigned char *sha1, int flag, void *cb_data)
22c6e1d0 »
2005-09-14 [PATCH] Fix fetch completeness assumptions
206 {
d0ac30f2 »
2005-09-16 [PATCH] fetch.c: cleanups
207 struct commit *commit = lookup_commit_reference_gently(sha1, 1);
208 if (commit) {
209 commit->object.flags |= COMPLETE;
47e44ed1 »
2010-11-26 commit: Add commit_list prefix in two function names.
210 commit_list_insert_by_date(commit, &complete);
22c6e1d0 »
2005-09-14 [PATCH] Fix fetch completeness assumptions
211 }
212 return 0;
213 }
cd541a68 »
2005-06-06 [PATCH] Generic support for pulling refs
214
30ae764b »
2007-09-10 Modularize commit-walker
215 int walker_targets_stdin(char ***target, const char ***write_ref)
8e87ca66 »
2006-07-27 Teach git-local-fetch the --stdin switch
216 {
217 int targets = 0, targets_alloc = 0;
f285a2d7 »
2008-10-09 Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializer
218 struct strbuf buf = STRBUF_INIT;
8e87ca66 »
2006-07-27 Teach git-local-fetch the --stdin switch
219 *target = NULL; *write_ref = NULL;
220 while (1) {
221 char *rf_one = NULL;
222 char *tg_one;
223
e6c019d0 »
2007-09-17 Drop strbuf's 'eof' marker, and make read_line a first class citizen.
224 if (strbuf_getline(&buf, stdin, '\n') == EOF)
8e87ca66 »
2006-07-27 Teach git-local-fetch the --stdin switch
225 break;
226 tg_one = buf.buf;
227 rf_one = strchr(tg_one, '\t');
228 if (rf_one)
229 *rf_one++ = 0;
230
231 if (targets >= targets_alloc) {
232 targets_alloc = targets_alloc ? targets_alloc * 2 : 64;
233 *target = xrealloc(*target, targets_alloc * sizeof(**target));
234 *write_ref = xrealloc(*write_ref, targets_alloc * sizeof(**write_ref));
235 }
9befac47 »
2006-09-02 Replace uses of strdup with xstrdup.
236 (*target)[targets] = xstrdup(tg_one);
237 (*write_ref)[targets] = rf_one ? xstrdup(rf_one) : NULL;
8e87ca66 »
2006-07-27 Teach git-local-fetch the --stdin switch
238 targets++;
239 }
e6c019d0 »
2007-09-17 Drop strbuf's 'eof' marker, and make read_line a first class citizen.
240 strbuf_release(&buf);
8e87ca66 »
2006-07-27 Teach git-local-fetch the --stdin switch
241 return targets;
242 }
243
30ae764b »
2007-09-10 Modularize commit-walker
244 void walker_targets_free(int targets, char **target, const char **write_ref)
8e87ca66 »
2006-07-27 Teach git-local-fetch the --stdin switch
245 {
246 while (targets--) {
247 free(target[targets]);
24deea52 »
2009-07-22 janitor: useless checks before free
248 if (write_ref)
8e87ca66 »
2006-07-27 Teach git-local-fetch the --stdin switch
249 free((char *) write_ref[targets]);
250 }
251 }
252
30ae764b »
2007-09-10 Modularize commit-walker
253 int walker_fetch(struct walker *walker, int targets, char **target,
254 const char **write_ref, const char *write_ref_log_details)
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
255 {
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
256 struct ref_lock **lock = xcalloc(targets, sizeof(struct ref_lock *));
257 unsigned char *sha1 = xmalloc(targets * 20);
d0740d92 »
2006-05-19 Log ref updates made by fetch.
258 char *msg;
259 int ret;
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
260 int i;
cd541a68 »
2005-06-06 [PATCH] Generic support for pulling refs
261
98533b90 »
2005-09-15 Avoid wasting memory while keeping track of what we have during fetch.
262 save_commit_buffer = 0;
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
263
264 for (i = 0; i < targets; i++) {
1b03dfed »
2006-07-29 Fix http-fetch
265 if (!write_ref || !write_ref[i])
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
266 continue;
267
4431fcc4 »
2006-09-27 Clean-up lock-ref implementation
268 lock[i] = lock_ref_sha1(write_ref[i], NULL);
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
269 if (!lock[i]) {
270 error("Can't lock ref %s", write_ref[i]);
271 goto unlock_and_fail;
d0740d92 »
2006-05-19 Log ref updates made by fetch.
272 }
cd541a68 »
2005-06-06 [PATCH] Generic support for pulling refs
273 }
274
30ae764b »
2007-09-10 Modularize commit-walker
275 if (!walker->get_recover)
cb5d709f »
2006-09-20 Add callback data to for_each_ref() family.
276 for_each_ref(mark_complete, NULL);
22c6e1d0 »
2005-09-14 [PATCH] Fix fetch completeness assumptions
277
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
278 for (i = 0; i < targets; i++) {
30ae764b »
2007-09-10 Modularize commit-walker
279 if (interpret_target(walker, target[i], &sha1[20 * i])) {
5f48741a »
2007-12-18 Clarify error response from 'git fetch' for bad responses
280 error("Could not interpret response from server '%s' as something to pull", target[i]);
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
281 goto unlock_and_fail;
282 }
30ae764b »
2007-09-10 Modularize commit-walker
283 if (process(walker, lookup_unknown_object(&sha1[20 * i])))
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
284 goto unlock_and_fail;
4bd18c43 »
2006-05-17 Improve abstraction of ref lock/write.
285 }
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
286
30ae764b »
2007-09-10 Modularize commit-walker
287 if (loop(walker))
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
288 goto unlock_and_fail;
289
290 if (write_ref_log_details) {
291 msg = xmalloc(strlen(write_ref_log_details) + 12);
292 sprintf(msg, "fetch from %s", write_ref_log_details);
293 } else {
294 msg = NULL;
4bd18c43 »
2006-05-17 Improve abstraction of ref lock/write.
295 }
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
296 for (i = 0; i < targets; i++) {
1b03dfed »
2006-07-29 Fix http-fetch
297 if (!write_ref || !write_ref[i])
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
298 continue;
299 ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)");
300 lock[i] = NULL;
301 if (ret)
302 goto unlock_and_fail;
4bd18c43 »
2006-05-17 Improve abstraction of ref lock/write.
303 }
4cac42b1 »
2006-08-27 free(NULL) is perfectly valid.
304 free(msg);
4bd18c43 »
2006-05-17 Improve abstraction of ref lock/write.
305
cd541a68 »
2005-06-06 [PATCH] Generic support for pulling refs
306 return 0;
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
307
308 unlock_and_fail:
309 for (i = 0; i < targets; i++)
310 if (lock[i])
311 unlock_ref(lock[i]);
30ae764b »
2007-09-10 Modularize commit-walker
312
4211e4d1 »
2006-07-27 Make pull() support fetching multiple targets at once
313 return -1;
4250a5e5 »
2005-04-30 [PATCH] Split out "pull" from particular methods
314 }
30ae764b »
2007-09-10 Modularize commit-walker
315
316 void walker_free(struct walker *walker)
317 {
318 walker->cleanup(walker);
319 free(walker);
320 }
Something went wrong with that request. Please try again.