Merge branch 'hv/submodule-alt-odb'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 May 2012 20:35:05 +0000 (13:35 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 May 2012 20:35:06 +0000 (13:35 -0700)
When peeking into object stores of submodules, the code forgot that they
might borrow objects from alternate object stores on their own.

By Heiko Voigt
* hv/submodule-alt-odb:
teach add_submodule_odb() to look for alternates

cache.h
sha1_file.c
submodule.c
t/t4041-diff-submodule-option.sh
diff --git a/cache.h b/cache.h
index e14ffcd914be8759a5f5a71fa7fc71e4f9774f0e..cc5048c202b6799591e7121de91ee2c6cdce9997 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -947,6 +947,7 @@ extern struct alternate_object_database {
        char base[FLEX_ARRAY]; /* more */
 } *alt_odb_list;
 extern void prepare_alt_odb(void);
+extern void read_info_alternates(const char * relative_base, int depth);
 extern void add_to_alternates_file(const char *reference);
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
 extern void foreach_alt_odb(alt_odb_fn, void*);
index 3c4f1652f13479238dee56674cbb86d299363be1..4ccaf7ac197c28400eddd496abcfc725528ca32b 100644 (file)
@@ -229,7 +229,6 @@ char *sha1_pack_index_name(const unsigned char *sha1)
 struct alternate_object_database *alt_odb_list;
 static struct alternate_object_database **alt_odb_tail;
 
-static void read_info_alternates(const char * alternates, int depth);
 static int git_open_noatime(const char *name);
 
 /*
@@ -354,7 +353,7 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
        }
 }
 
-static void read_info_alternates(const char * relative_base, int depth)
+void read_info_alternates(const char * relative_base, int depth)
 {
        char *map;
        size_t mapsz;
index 784b58039dd078fc1e0c4554820cd0e99c8e41d2..959d349ea7426344289020ee4216785fa65ec1e6 100644 (file)
@@ -63,6 +63,9 @@ static int add_submodule_odb(const char *path)
        alt_odb->name[40] = '\0';
        alt_odb->name[41] = '\0';
        alt_odb_list = alt_odb;
+
+       /* add possible alternates from the submodule */
+       read_info_alternates(objects_directory.buf, 0);
        prepare_alt_odb();
 done:
        strbuf_release(&objects_directory);
index bf9a7526bd38a17e0e991739db8c4a1f8541b2f6..6c01d0c056e2608393ed16eea29dd45fc79d786c 100755 (executable)
@@ -458,4 +458,38 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'diff --submodule with objects referenced by alternates' '
+       mkdir sub_alt &&
+       (cd sub_alt &&
+               git init &&
+               echo a >a &&
+               git add a &&
+               git commit -m a
+       ) &&
+       mkdir super &&
+       (cd super &&
+               git clone -s ../sub_alt sub &&
+               git init &&
+               git add sub &&
+               git commit -m "sub a"
+       ) &&
+       (cd sub_alt &&
+               sha1_before=$(git rev-parse --short HEAD)
+               echo b >b &&
+               git add b &&
+               git commit -m b
+               sha1_after=$(git rev-parse --short HEAD)
+               echo "Submodule sub $sha1_before..$sha1_after:
+  > b" >../expected
+       ) &&
+       (cd super &&
+               (cd sub &&
+                       git fetch &&
+                       git checkout origin/master
+               ) &&
+               git diff --submodule > ../actual
+       )
+       test_cmp expected actual
+'
+
 test_done