Skip to content

Commit efe4be1

Browse files
trastgitster
authored andcommitted
bundle: keep around names passed to add_pending_object()
The 'name' field passed to add_pending_object() is used to later deduplicate in object_array_remove_duplicates(). git-bundle had a bug in this area since 18449ab (git-bundle: avoid packing objects which are in the prerequisites, 2007-03-08): it passed the name of each boundary object in a static buffer. In other words, all that object_array_remove_duplicates() saw was the name of the *last* added boundary object. The recent switch to a strbuf in bc2fed4 (bundle: use a strbuf to scan the log for boundary commits, 2012-02-22) made this slightly worse: we now free the buffer at the end, so it is not even guaranteed that it still points into addressable memory by the time object_array_remove_ duplicates looks at it. On the plus side however, it was now detectable by valgrind. The fix is easy: pass a copy of the string to add_pending_object. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa98285 commit efe4be1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

bundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ int create_bundle(struct bundle_header *header, const char *path,
273273
if (!get_sha1_hex(buf.buf + 1, sha1)) {
274274
struct object *object = parse_object(sha1);
275275
object->flags |= UNINTERESTING;
276-
add_pending_object(&revs, object, buf.buf);
276+
add_pending_object(&revs, object, xstrdup(buf.buf));
277277
}
278278
} else if (!get_sha1_hex(buf.buf, sha1)) {
279279
struct object *object = parse_object(sha1);

t/t5510-fetch.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,19 @@ test_expect_success "should be able to fetch with duplicate refspecs" '
442442
)
443443
'
444444

445+
test_expect_success 'all boundary commits are excluded' '
446+
test_commit base &&
447+
test_commit oneside &&
448+
git checkout HEAD^ &&
449+
test_commit otherside &&
450+
git checkout master &&
451+
test_tick &&
452+
git merge otherside &&
453+
ad=$(git log --no-walk --format=%ad HEAD) &&
454+
git bundle create twoside-boundary.bdl master --since="$ad" &&
455+
convert_bundle_to_pack <twoside-boundary.bdl >twoside-boundary.pack &&
456+
pack=$(git index-pack --fix-thin --stdin <twoside-boundary.pack) &&
457+
test_bundle_object_count .git/objects/pack/pack-${pack##pack }.pack 3
458+
'
459+
445460
test_done

0 commit comments

Comments
 (0)