Skip to content

Commit 69e8260

Browse files
committed
Merge branch 'hv/submodule-alt-odb' into maint
When a submodule repository uses alternate object store mechanism, some commands that were started from the superproject did not notice it and failed with "No such object" errors. The subcommands of "git submodule" command that recursed into the submodule in a separate process were OK; only the ones that cheated and peeked directly into the submodule's repository from the primary process were affected. By Heiko Voigt * hv/submodule-alt-odb: teach add_submodule_odb() to look for alternates
2 parents 98eb3fc + 5e73633 commit 69e8260

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
@@ -992,6 +992,7 @@ extern struct alternate_object_database {
992992
char base[FLEX_ARRAY]; /* more */
993993
} *alt_odb_list;
994994
extern void prepare_alt_odb(void);
995+
extern void read_info_alternates(const char * relative_base, int depth);
995996
extern void add_to_alternates_file(const char *reference);
996997
typedef int alt_odb_fn(struct alternate_object_database *, void *);
997998
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)