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

allow git-bundle to create bottomless bundle

Mark Levedahl <mlevedahl@gmail.com> writes: > Junio C Hamano wrote: >> While "git bundle" was a useful way to sneakernet incremental >> changes, we did not allow: >> > Thanks - I've been thinking for months I could fix this bug, never > figured it out and didn't want to nag Dscho one more time. I confirm > that this allows creation of bundles with arbitrary refs, not just > those under refs/heads. Yahoo! Actually, there is another bug nearby. If you do: git bundle create v2.6-20-v2.6.22.bndl v2.6.20..v2.6.22 the bundle records that it requires v2.6.20^0 commit (correct) and gives you tag v2.6.22 (incorrect); the bug is that the object it lists in fact is the commit v2.6.22^0, not the tag. This is because the revision range operation .. is always about set of commits, but the code near where my patch touches does not validate that the sha1 value obtained from dwim_ref() against the commit object name e->item->sha1 before placing the head information in the commit. The attached patch attempts to fix this problem. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 8, 2007 at 22:04 UTC c06793a4ed1bf81902c324d1ed88dd055c3aa468
1 file changed +33
builtin-bundle.c
+33
@@ -279,8 +279,41 @@ static int create_bundle(struct bundle_header *header, const char *path,
279 if (!(e->item->flags & SHOWN) && e->item->type == OBJ_COMMIT) {
280 warning("ref '%s' is excluded by the rev-list options",
281 e->name);
282 + free(ref);
283 continue;
284 }
285 + /*
286 + * If you run "git bundle create bndl v1.0..v2.0", the
287 + * name of the positive ref is "v2.0" but that is the
288 + * commit that is referenced by the tag, and not the tag
289 + * itself.
290 + */
291 + if (hashcmp(sha1, e->item->sha1)) {
292 + /*
293 + * Is this the positive end of a range expressed
294 + * in terms of a tag (e.g. v2.0 from the range
295 + * "v1.0..v2.0")?
296 + */
297 + struct commit *one = lookup_commit_reference(sha1);
298 + struct object *obj;
299 +
300 + if (e->item == &(one->object)) {
301 + /*
302 + * Need to include e->name as an
303 + * independent ref to the pack-objects
304 + * input, so that the tag is included
305 + * in the output; otherwise we would
306 + * end up triggering "empty bundle"
307 + * error.
308 + */
309 + obj = parse_object(sha1);
310 + obj->flags |= SHOWN;
311 + add_pending_object(&revs, obj, e->name);
312 + }
313 + free(ref);
314 + continue;
315 + }
316 +
317 ref_count++;
318 write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
319 write_or_die(bundle_fd, " ", 1);