Skip to content

Commit

Permalink
teach add_submodule_odb() to look for alternates
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Heiko Voigt authored and Junio C Hamano committed May 14, 2012
1 parent d0f1ea6 commit 5e73633
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,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*);
Expand Down
3 changes: 1 addition & 2 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,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);

/*
Expand Down Expand Up @@ -353,7 +352,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;
Expand Down
3 changes: 3 additions & 0 deletions submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions t/t4041-diff-submodule-option.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5e73633

Please sign in to comment.