Skip to content

Commit 8abc618

Browse files
committed
Merge branch 'js/maint-all-implies-HEAD' into maint
* js/maint-all-implies-HEAD: bundle: allow the same ref to be given more than once revision walker: include a detached HEAD in --all
2 parents 8c4c286 + b2a6d1c commit 8abc618

File tree

6 files changed

+63
-2
lines changed

6 files changed

+63
-2
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
@@ -82,5 +82,6 @@ int object_list_contains(struct object_list *list, struct object *obj);
8282
/* Object array handling .. */
8383
void add_object_array(struct object *obj, const char *name, struct object_array *array);
8484
void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode);
85+
void object_array_remove_duplicates(struct object_array *);
8586

8687
#endif /* OBJECT_H */

revision.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
12631263

12641264
if (!strcmp(arg, "--all")) {
12651265
handle_refs(revs, flags, for_each_ref);
1266+
handle_refs(revs, flags, head_ref);
12661267
continue;
12671268
}
12681269
if (!strcmp(arg, "--branches")) {

t/t5701-clone-local.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ 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 --all HEAD &&
15-
git bundle create b2.bundle --all &&
14+
git bundle create b1.bundle --all &&
15+
git bundle create b2.bundle master &&
1616
mkdir dir &&
1717
cp b1.bundle dir/b3
1818
cp b1.bundle b4

t/t6014-rev-list-all.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
test_description='--all includes detached HEADs'
4+
5+
. ./test-lib.sh
6+
7+
8+
commit () {
9+
test_tick &&
10+
echo $1 > foo &&
11+
git add foo &&
12+
git commit -m "$1"
13+
}
14+
15+
test_expect_success 'setup' '
16+
17+
commit one &&
18+
commit two &&
19+
git checkout HEAD^ &&
20+
commit detached
21+
22+
'
23+
24+
test_expect_success 'rev-list --all lists detached HEAD' '
25+
26+
test 3 = $(git rev-list --all | wc -l)
27+
28+
'
29+
30+
test_expect_success 'repack does not lose detached HEAD' '
31+
32+
git gc &&
33+
git prune --expire=now &&
34+
git show HEAD
35+
36+
'
37+
38+
test_done

0 commit comments

Comments
 (0)