@matheusbsbs / matheus-bagliano / commits / c2dea5a11c
Fork 0

git-bundle: various fixups

verify_bundle() returned with an error early only when all prerequisite commits were missing. It should error out much earlier when some are missing. When the rev-list is limited in ways other than revision range (e.g. --max-count or --max-age), create_bundle() listed all positive refs given from the command line as if they are available, but resulting pack may not have some of them. Add a logic to make sure all of them are included, and error out otherwise. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 5, 2007 at 16:16 UTC c2dea5a11cc7106d0beec9931e527467b7189ab3
1 file changed +33 -13
builtin-bundle.c
+33 -13
@@ -189,7 +189,7 @@ static int verify_bundle(struct bundle_header *header)
189 error(message);
190 error("%s %s", sha1_to_hex(e->sha1), e->name);
191 }
192 - if (revs.pending.nr == 0)
192 + if (revs.pending.nr != p->nr)
193 return ret;
194 req_nr = revs.pending.nr;
195 setup_revisions(2, argv, &revs, NULL);
@@ -279,6 +279,7 @@ static int create_bundle(struct bundle_header *header, const char *path,
279 int pid, in, out, i, status;
280 char buffer[1024];
281 struct rev_info revs;
282 + struct object_array tips;
283
284 bundle_fd = (!strcmp(path, "-") ? 1 :
285 open(path, O_CREAT | O_WRONLY, 0666));
@@ -316,19 +317,23 @@ static int create_bundle(struct bundle_header *header, const char *path,
317 argc = setup_revisions(argc, argv, &revs, NULL);
318 if (argc > 1)
319 return error("unrecognized argument: %s'", argv[1]);
320 +
321 + memset(&tips, 0, sizeof(tips));
322 for (i = 0; i < revs.pending.nr; i++) {
323 struct object_array_entry *e = revs.pending.objects + i;
321 - if (!(e->item->flags & UNINTERESTING)) {
322 - unsigned char sha1[20];
323 - char *ref;
324 - if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
325 - continue;
326 - write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
327 - write_or_die(bundle_fd, " ", 1);
328 - write_or_die(bundle_fd, ref, strlen(ref));
329 - write_or_die(bundle_fd, "\n", 1);
330 - free(ref);
331 - }
324 + unsigned char sha1[20];
325 + char *ref;
326 +
327 + if (e->item->flags & UNINTERESTING)
328 + continue;
329 + if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
330 + continue;
331 + write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
332 + write_or_die(bundle_fd, " ", 1);
333 + write_or_die(bundle_fd, ref, strlen(ref));
334 + write_or_die(bundle_fd, "\n", 1);
335 + add_object_array(e->item, e->name, &tips);
336 + free(ref);
337 }
338
339 /* end header */
@@ -356,7 +361,22 @@ static int create_bundle(struct bundle_header *header, const char *path,
361 return -1;
362 if (!WIFEXITED(status) || WEXITSTATUS(status))
363 return error ("pack-objects died");
359 - return 0;
364 +
365 + /*
366 + * Make sure the refs we wrote out is correct; --max-count and
367 + * other limiting options could have prevented all the tips
368 + * from getting output.
369 + */
370 + status = 0;
371 + for (i = 0; i < tips.nr; i++) {
372 + if (!(tips.objects[i].item->flags & SHOWN)) {
373 + status = 1;
374 + error("%s: not included in the resulting pack",
375 + tips.objects[i].name);
376 + }
377 + }
378 +
379 + return status;
380 }
381
382 static int unbundle(struct bundle_header *header, int bundle_fd,