@matheusbsbs / matheus-bagliano / commits / 4211e4d10c
Fork 0

Make pull() support fetching multiple targets at once

pull() now takes an array of arguments instead of just one of each kind. Currently, no users use the new capability, but that'll change. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>

Petr Baudis committed Jul 27, 2006 at 23:56 UTC 4211e4d10cd98b1aeed97bdb6cdebb9411956bb5
5 files changed +49 -37
fetch.c
+45 -33
@@ -210,55 +210,67 @@ static int mark_complete(const char *path, const unsigned char *sha1)
210 return 0;
211 }
212
213 -int pull(char *target, const char *write_ref,
213 +int pull(int targets, char **target, const char **write_ref,
214 const char *write_ref_log_details)
215 {
216 - struct ref_lock *lock = NULL;
217 - unsigned char sha1[20];
216 + struct ref_lock **lock = xcalloc(targets, sizeof(struct ref_lock *));
217 + unsigned char *sha1 = xmalloc(targets * 20);
218 char *msg;
219 int ret;
220 + int i;
221
222 save_commit_buffer = 0;
223 track_object_refs = 0;
223 - if (write_ref) {
224 - lock = lock_ref_sha1(write_ref, NULL, 0);
225 - if (!lock) {
226 - error("Can't lock ref %s", write_ref);
227 - return -1;
224 +
225 + for (i = 0; i < targets; i++) {
226 + if (!write_ref[i])
227 + continue;
228 +
229 + lock[i] = lock_ref_sha1(write_ref[i], NULL, 0);
230 + if (!lock[i]) {
231 + error("Can't lock ref %s", write_ref[i]);
232 + goto unlock_and_fail;
233 }
234 }
235
236 if (!get_recover)
237 for_each_ref(mark_complete);
238
234 - if (interpret_target(target, sha1)) {
235 - error("Could not interpret %s as something to pull", target);
236 - if (lock)
237 - unlock_ref(lock);
238 - return -1;
239 + for (i = 0; i < targets; i++) {
240 + if (interpret_target(target[i], &sha1[20 * i])) {
241 + error("Could not interpret %s as something to pull", target[i]);
242 + goto unlock_and_fail;
243 + }
244 + if (process(lookup_unknown_object(&sha1[20 * i])))
245 + goto unlock_and_fail;
246 }
240 - if (process(lookup_unknown_object(sha1))) {
241 - if (lock)
242 - unlock_ref(lock);
243 - return -1;
247 +
248 + if (loop())
249 + goto unlock_and_fail;
250 +
251 + if (write_ref_log_details) {
252 + msg = xmalloc(strlen(write_ref_log_details) + 12);
253 + sprintf(msg, "fetch from %s", write_ref_log_details);
254 + } else {
255 + msg = NULL;
256 }
245 - if (loop()) {
246 - if (lock)
247 - unlock_ref(lock);
248 - return -1;
257 + for (i = 0; i < targets; i++) {
258 + if (!write_ref[i])
259 + continue;
260 + ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)");
261 + lock[i] = NULL;
262 + if (ret)
263 + goto unlock_and_fail;
264 }
265 + if (msg)
266 + free(msg);
267
251 - if (write_ref) {
252 - if (write_ref_log_details) {
253 - msg = xmalloc(strlen(write_ref_log_details) + 12);
254 - sprintf(msg, "fetch from %s", write_ref_log_details);
255 - }
256 - else
257 - msg = NULL;
258 - ret = write_ref_sha1(lock, sha1, msg ? msg : "fetch (unknown)");
259 - if (msg)
260 - free(msg);
261 - return ret;
262 - }
268 return 0;
269 +
270 +
271 +unlock_and_fail:
272 + for (i = 0; i < targets; i++)
273 + if (lock[i])
274 + unlock_ref(lock[i]);
275 + return -1;
276 }
fetch.h
+1 -1
@@ -42,7 +42,7 @@ extern void pull_say(const char *, const char *);
42
43 /* If write_ref is set, the ref filename to write the target value to. */
44 /* If write_ref_log_details is set, additional text will appear in the ref log. */
45 -extern int pull(char *target, const char *write_ref,
45 +extern int pull(int targets, char **target, const char **write_ref,
46 const char *write_ref_log_details);
47
48 #endif /* PULL_H */
http-fetch.c
+1 -1
@@ -1268,7 +1268,7 @@ int main(int argc, char **argv)
1268 alt->path_len = strlen(path);
1269 }
1270
1271 - if (pull(commit_id, write_ref, url))
1271 + if (pull(1, &commit_id, &write_ref, url))
1272 rc = 1;
1273
1274 http_cleanup();
local-fetch.c
+1 -1
@@ -242,7 +242,7 @@ int main(int argc, char **argv)
242 commit_id = argv[arg];
243 path = argv[arg + 1];
244
245 - if (pull(commit_id, write_ref, path))
245 + if (pull(1, &commit_id, &write_ref, path))
246 return 1;
247
248 return 0;
ssh-fetch.c
+1 -1
@@ -167,7 +167,7 @@ int main(int argc, char **argv)
167 if (get_version())
168 return 1;
169
170 - if (pull(commit_id, write_ref, url))
170 + if (pull(1, &commit_id, &write_ref, url))
171 return 1;
172
173 return 0;