Skip to content

Commit b2a6d1c

Browse files
committed
bundle: allow the same ref to be given more than once
"git bundle create x master master" used to create a bundle that lists the same branch (master) twice. Cloning from such a bundle resulted in a needless warning "warning: Duplicated ref: refs/remotes/origin/master". Signed-off-by: Junio C Hamano <[email protected]>
1 parent f0298cf commit b2a6d1c

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

bundle.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ int create_bundle(struct bundle_header *header, const char *path,
240240
return error("unrecognized argument: %s'", argv[i]);
241241
}
242242

243+
object_array_remove_duplicates(&revs.pending);
244+
243245
for (i = 0; i < revs.pending.nr; i++) {
244246
struct object_array_entry *e = revs.pending.objects + i;
245247
unsigned char sha1[20];

object.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,22 @@ void add_object_array_with_mode(struct object *obj, const char *name, struct obj
268268
objects[nr].mode = mode;
269269
array->nr = ++nr;
270270
}
271+
272+
void object_array_remove_duplicates(struct object_array *array)
273+
{
274+
int ref, src, dst;
275+
struct object_array_entry *objects = array->objects;
276+
277+
for (ref = 0; ref < array->nr - 1; ref++) {
278+
for (src = ref + 1, dst = src;
279+
src < array->nr;
280+
src++) {
281+
if (!strcmp(objects[ref].name, objects[src].name))
282+
continue;
283+
if (src != dst)
284+
objects[dst] = objects[src];
285+
dst++;
286+
}
287+
array->nr = dst;
288+
}
289+
}

object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ int object_list_contains(struct object_list *list, struct object *obj);
7171
/* Object array handling .. */
7272
void add_object_array(struct object *obj, const char *name, struct object_array *array);
7373
void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode);
74+
void object_array_remove_duplicates(struct object_array *);
7475

7576
#endif /* OBJECT_H */

t/t5701-clone-local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_expect_success 'preparing origin repository' '
1111
git clone --bare . x &&
1212
test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true &&
1313
test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true
14-
git bundle create b1.bundle master HEAD &&
14+
git bundle create b1.bundle --all &&
1515
git bundle create b2.bundle master &&
1616
mkdir dir &&
1717
cp b1.bundle dir/b3

0 commit comments

Comments
 (0)