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 <gitster@pobox.com>
Junio C Hamano committed
Jan 17, 2009 at 22:27 UTC
b2a6d1c6868b6d5e7d2b4fa9129341220a1e848a
4 files changed
+23
-1
bundle.c
+2
@@ -240,6 +240,8 @@ int create_bundle(struct bundle_header *header, const char *path,
240
return error("unrecognized argument: %s'", argv[i]);
241
}
242
243
+ object_array_remove_duplicates(&revs.pending);
244
+
245
for (i = 0; i < revs.pending.nr; i++) {
246
struct object_array_entry *e = revs.pending.objects + i;
247
unsigned char sha1[20];
object.c
+19
@@ -268,3 +268,22 @@ void add_object_array_with_mode(struct object *obj, const char *name, struct obj
268
objects[nr].mode = mode;
269
array->nr = ++nr;
270
}
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
+1
@@ -71,5 +71,6 @@ int object_list_contains(struct object_list *list, struct object *obj);
71
/* Object array handling .. */
72
void add_object_array(struct object *obj, const char *name, struct object_array *array);
73
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 *);
75
76
#endif /* OBJECT_H */
t/t5701-clone-local.sh
+1
-1
@@ -11,7 +11,7 @@ test_expect_success 'preparing origin repository' '
11
git clone --bare . x &&
12
test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true &&
13
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 &&
15
git bundle create b2.bundle master &&
16
mkdir dir &&
17
cp b1.bundle dir/b3