From f0298cf1c6a7b5cc8b79d84a03b0ce07df2d9e6b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 16 Jan 2009 13:52:53 +0100 Subject: revision walker: include a detached HEAD in --all When HEAD is detached, --all should list it, too, logically, as a detached HEAD is by definition a temporary, unnamed branch. It is especially necessary to list it when garbage collecting, as the detached HEAD would be trashed. Noticed by Thomas Rast. Note that this affects creating bundles with --all; I contend that it is a good change to add the HEAD, so that cloning from such a bundle will give you a current branch. However, I had to fix t5701 as it assumed that --all does not imply HEAD. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/revision.c b/revision.c index 45fd7a3..f6ccb97 100644 --- a/revision.c +++ b/revision.c @@ -1223,6 +1223,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch if (!strcmp(arg, "--all")) { handle_refs(revs, flags, for_each_ref); + handle_refs(revs, flags, head_ref); continue; } if (!strcmp(arg, "--branches")) { diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh index 8dfaaa4..14413f8 100755 --- a/t/t5701-clone-local.sh +++ b/t/t5701-clone-local.sh @@ -11,8 +11,8 @@ test_expect_success 'preparing origin repository' ' git clone --bare . x && test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true && test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true - git bundle create b1.bundle --all HEAD && - git bundle create b2.bundle --all && + git bundle create b1.bundle master HEAD && + git bundle create b2.bundle master && mkdir dir && cp b1.bundle dir/b3 cp b1.bundle b4 diff --git a/t/t6014-rev-list-all.sh b/t/t6014-rev-list-all.sh new file mode 100755 index 0000000..991ab4a --- /dev/null +++ b/t/t6014-rev-list-all.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +test_description='--all includes detached HEADs' + +. ./test-lib.sh + + +commit () { + test_tick && + echo $1 > foo && + git add foo && + git commit -m "$1" +} + +test_expect_success 'setup' ' + + commit one && + commit two && + git checkout HEAD^ && + commit detached + +' + +test_expect_success 'rev-list --all lists detached HEAD' ' + + test 3 = $(git rev-list --all | wc -l) + +' + +test_expect_success 'repack does not lose detached HEAD' ' + + git gc && + git prune --expire=now && + git show HEAD + +' + +test_done -- cgit v0.10.2-6-g49f6 From b2a6d1c6868b6d5e7d2b4fa9129341220a1e848a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 17 Jan 2009 22:27:08 -0800 Subject: 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 diff --git a/bundle.c b/bundle.c index daecd8e..b20f210 100644 --- a/bundle.c +++ b/bundle.c @@ -240,6 +240,8 @@ int create_bundle(struct bundle_header *header, const char *path, return error("unrecognized argument: %s'", argv[i]); } + object_array_remove_duplicates(&revs.pending); + for (i = 0; i < revs.pending.nr; i++) { struct object_array_entry *e = revs.pending.objects + i; unsigned char sha1[20]; diff --git a/object.c b/object.c index 50b6528..7e6a92c 100644 --- a/object.c +++ b/object.c @@ -268,3 +268,22 @@ void add_object_array_with_mode(struct object *obj, const char *name, struct obj objects[nr].mode = mode; array->nr = ++nr; } + +void object_array_remove_duplicates(struct object_array *array) +{ + int ref, src, dst; + struct object_array_entry *objects = array->objects; + + for (ref = 0; ref < array->nr - 1; ref++) { + for (src = ref + 1, dst = src; + src < array->nr; + src++) { + if (!strcmp(objects[ref].name, objects[src].name)) + continue; + if (src != dst) + objects[dst] = objects[src]; + dst++; + } + array->nr = dst; + } +} diff --git a/object.h b/object.h index 036bd66..3193916 100644 --- a/object.h +++ b/object.h @@ -71,5 +71,6 @@ int object_list_contains(struct object_list *list, struct object *obj); /* Object array handling .. */ void add_object_array(struct object *obj, const char *name, struct object_array *array); void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode); +void object_array_remove_duplicates(struct object_array *); #endif /* OBJECT_H */ diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh index 14413f8..fe0fda2 100755 --- a/t/t5701-clone-local.sh +++ b/t/t5701-clone-local.sh @@ -11,7 +11,7 @@ test_expect_success 'preparing origin repository' ' git clone --bare . x && test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true && test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true - git bundle create b1.bundle master HEAD && + git bundle create b1.bundle --all && git bundle create b2.bundle master && mkdir dir && cp b1.bundle dir/b3 -- cgit v0.10.2-6-g49f6