Skip to content

Commit 5e73633

Browse files
hvoigtgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0f1ea6 commit 5e73633

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ extern struct alternate_object_database {
960960
char base[FLEX_ARRAY]; /* more */
961961
} *alt_odb_list;
962962
extern void prepare_alt_odb(void);
963+
extern void read_info_alternates(const char * relative_base, int depth);
963964
extern void add_to_alternates_file(const char *reference);
964965
typedef int alt_odb_fn(struct alternate_object_database *, void *);
965966
extern void foreach_alt_odb(alt_odb_fn, void*);

sha1_file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ char *sha1_pack_index_name(const unsigned char *sha1)
228228
struct alternate_object_database *alt_odb_list;
229229
static struct alternate_object_database **alt_odb_tail;
230230

231-
static void read_info_alternates(const char * alternates, int depth);
232231
static int git_open_noatime(const char *name);
233232

234233
/*
@@ -353,7 +352,7 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
353352
}
354353
}
355354

356-
static void read_info_alternates(const char * relative_base, int depth)
355+
void read_info_alternates(const char * relative_base, int depth)
357356
{
358357
char *map;
359358
size_t mapsz;

submodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ static int add_submodule_odb(const char *path)
6363
alt_odb->name[40] = '\0';
6464
alt_odb->name[41] = '\0';
6565
alt_odb_list = alt_odb;
66+
67+
/* add possible alternates from the submodule */
68+
read_info_alternates(objects_directory.buf, 0);
6669
prepare_alt_odb();
6770
done:
6871
strbuf_release(&objects_directory);

t/t4041-diff-submodule-option.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,38 @@ EOF
458458
test_cmp expected actual
459459
'
460460

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+
461495
test_done

0 commit comments

Comments
 (0)