teach add_submodule_odb() to look for alternates

Since we allow to link other object databases when loading a submodules database we should also load possible alternates. Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Heiko Voigt committed May 14, 2012 at 18:24 UTC 5e73633dbf8a62190611f6eb438a1a2eaaffa919
4 files changed +39 -2
cache.h
+1
@@ -960,6 +960,7 @@ extern struct alternate_object_database {
960 char base[FLEX_ARRAY]; /* more */
961 } *alt_odb_list;
962 extern void prepare_alt_odb(void);
963 +extern void read_info_alternates(const char * relative_base, int depth);
964 extern void add_to_alternates_file(const char *reference);
965 typedef int alt_odb_fn(struct alternate_object_database *, void *);
966 extern void foreach_alt_odb(alt_odb_fn, void*);
sha1_file.c
+1 -2
@@ -228,7 +228,6 @@ char *sha1_pack_index_name(const unsigned char *sha1)
228 struct alternate_object_database *alt_odb_list;
229 static struct alternate_object_database **alt_odb_tail;
230
231 -static void read_info_alternates(const char * alternates, int depth);
231 static int git_open_noatime(const char *name);
232
233 /*
@@ -353,7 +352,7 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
352 }
353 }
354
356 -static void read_info_alternates(const char * relative_base, int depth)
355 +void read_info_alternates(const char * relative_base, int depth)
356 {
357 char *map;
358 size_t mapsz;
submodule.c
+3
@@ -63,6 +63,9 @@ static int add_submodule_odb(const char *path)
63 alt_odb->name[40] = '\0';
64 alt_odb->name[41] = '\0';
65 alt_odb_list = alt_odb;
66 +
67 + /* add possible alternates from the submodule */
68 + read_info_alternates(objects_directory.buf, 0);
69 prepare_alt_odb();
70 done:
71 strbuf_release(&objects_directory);
t/t4041-diff-submodule-option.sh
+34
@@ -458,4 +458,38 @@ EOF
458 test_cmp expected actual
459 '
460
461 +test_expect_success 'diff --submodule with objects referenced by alternates' '
462 + mkdir sub_alt &&
463 + (cd sub_alt &&
464 + git init &&
465 + echo a >a &&
466 + git add a &&
467 + git commit -m a
468 + ) &&
469 + mkdir super &&
470 + (cd super &&
471 + git clone -s ../sub_alt sub &&
472 + git init &&
473 + git add sub &&
474 + git commit -m "sub a"
475 + ) &&
476 + (cd sub_alt &&
477 + sha1_before=$(git rev-parse --short HEAD)
478 + echo b >b &&
479 + git add b &&
480 + git commit -m b
481 + sha1_after=$(git rev-parse --short HEAD)
482 + echo "Submodule sub $sha1_before..$sha1_after:
483 + > b" >../expected
484 + ) &&
485 + (cd super &&
486 + (cd sub &&
487 + git fetch &&
488 + git checkout origin/master
489 + ) &&
490 + git diff --submodule > ../actual
491 + )
492 + test_cmp expected actual
493 +'
494 +
495 test_done