Skip to content

Commit dd1072d

Browse files
To1negitster
authored andcommitted
bundle: remove unneeded code
The changes in commit c06793a (allow git-bundle to create bottomless bundle, 2007-08-08) ensure annotated tags are properly preserved when creating a bundle using a revision range operation. At the time the range notation would peel the ends to their corresponding commit, meaning ref v2.0 would point to the v2.0^0 commit. So the above workaround was introduced. This code looks up the ref before it's written to the bundle, and if the ref doesn't point to the object we expect (for tags this would be a tag object), we skip the ref from the bundle. Instead, when the ref is a tag that's the positive end of the range (e.g. v2.0 from the range "v1.0..v2.0"), then that ref is written to the bundle instead. Later, in 895c5ba (revision: do not peel tags used in range notation, 2013-09-19), the behavior of parsing ranges was changed and the problem was fixed at the cause. But the workaround in bundle.c was not reverted. Now it seems this workaround can cause a race condition. git-bundle(1) uses setup_revisions() to parse the input into `struct rev_info`. Later, in write_bundle_refs(), it uses this info to write refs to the bundle. As mentioned at this point each ref is looked up again and checked whether it points to the object we expect. If not, the ref is not written to the bundle. But, when creating a bundle in a heavy traffic repository (a repo with many references, and frequent ref updates) it's possible a branch ref was updated between setup_revisions() and write_bundle_refs() and thus the extra check causes the ref to be skipped. The workaround was originally added to deal with tags, but the code path also gets hit by non-tag refs, causing this race condition. Because it's no longer needed, remove it and fix the possible race condition. Signed-off-by: Toon Claes <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 92999a4 commit dd1072d

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

bundle.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -420,36 +420,6 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
420420
e->name);
421421
goto skip_write_ref;
422422
}
423-
/*
424-
* If you run "git bundle create bndl v1.0..v2.0", the
425-
* name of the positive ref is "v2.0" but that is the
426-
* commit that is referenced by the tag, and not the tag
427-
* itself.
428-
*/
429-
if (!oideq(&oid, &e->item->oid)) {
430-
/*
431-
* Is this the positive end of a range expressed
432-
* in terms of a tag (e.g. v2.0 from the range
433-
* "v1.0..v2.0")?
434-
*/
435-
struct commit *one = lookup_commit_reference(revs->repo, &oid);
436-
struct object *obj;
437-
438-
if (e->item == &(one->object)) {
439-
/*
440-
* Need to include e->name as an
441-
* independent ref to the pack-objects
442-
* input, so that the tag is included
443-
* in the output; otherwise we would
444-
* end up triggering "empty bundle"
445-
* error.
446-
*/
447-
obj = parse_object_or_die(&oid, e->name);
448-
obj->flags |= SHOWN;
449-
add_pending_object(revs, obj, e->name);
450-
}
451-
goto skip_write_ref;
452-
}
453423

454424
ref_count++;
455425
write_or_die(bundle_fd, oid_to_hex(&e->item->oid), the_hash_algo->hexsz);

t/t6020-bundle-misc.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,50 @@ test_expect_success 'unfiltered bundle with --objects' '
505505
test_cmp expect actual
506506
'
507507

508+
test_expect_success 'full bundle upto annotated tag' '
509+
git bundle create v2.bdl \
510+
v2 &&
511+
512+
git bundle verify v2.bdl |
513+
make_user_friendly_and_stable_output >actual &&
514+
515+
format_and_save_expect <<-EOF &&
516+
The bundle contains this ref:
517+
<TAG-2> refs/tags/v2
518+
The bundle records a complete history.
519+
$HASH_MESSAGE
520+
EOF
521+
test_cmp expect actual
522+
'
523+
524+
test_expect_success 'clone from full bundle upto annotated tag' '
525+
git clone --mirror v2.bdl tag-clone.git &&
526+
git -C tag-clone.git show-ref |
527+
make_user_friendly_and_stable_output >actual &&
528+
cat >expect <<-\EOF &&
529+
<TAG-2> refs/tags/v2
530+
EOF
531+
test_cmp expect actual
532+
'
533+
534+
test_expect_success 'incremental bundle between two annotated tags' '
535+
git bundle create v1-v2.bdl \
536+
v1..v2 &&
537+
538+
git bundle verify v1-v2.bdl |
539+
make_user_friendly_and_stable_output >actual &&
540+
541+
format_and_save_expect <<-EOF &&
542+
The bundle contains this ref:
543+
<TAG-2> refs/tags/v2
544+
The bundle requires these 2 refs:
545+
<COMMIT-E> Z
546+
<COMMIT-B> Z
547+
$HASH_MESSAGE
548+
EOF
549+
test_cmp expect actual
550+
'
551+
508552
for filter in "blob:none" "tree:0" "tree:1" "blob:limit=100"
509553
do
510554
test_expect_success "filtered bundle: $filter" '

0 commit comments

Comments
 (0)