Skip to content

Commit de6ae5f

Browse files
chriscoolgitster
authored andcommitted
read-cache: refactor read_index_from()
It looks better and is simpler to review when we don't compute the same things many times in the function. It will also help make the following commit simpler. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0441f7 commit de6ae5f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

read-cache.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,8 @@ int read_index_from(struct index_state *istate, const char *path)
16991699
{
17001700
struct split_index *split_index;
17011701
int ret;
1702+
char *base_sha1_hex;
1703+
const char *base_path;
17021704

17031705
/* istate->initialized covers both .git/index and .git/sharedindex.xxx */
17041706
if (istate->initialized)
@@ -1716,15 +1718,15 @@ int read_index_from(struct index_state *istate, const char *path)
17161718
discard_index(split_index->base);
17171719
else
17181720
split_index->base = xcalloc(1, sizeof(*split_index->base));
1719-
ret = do_read_index(split_index->base,
1720-
git_path("sharedindex.%s",
1721-
sha1_to_hex(split_index->base_sha1)), 1);
1721+
1722+
base_sha1_hex = sha1_to_hex(split_index->base_sha1);
1723+
base_path = git_path("sharedindex.%s", base_sha1_hex);
1724+
ret = do_read_index(split_index->base, base_path, 1);
17221725
if (hashcmp(split_index->base_sha1, split_index->base->sha1))
17231726
die("broken index, expect %s in %s, got %s",
1724-
sha1_to_hex(split_index->base_sha1),
1725-
git_path("sharedindex.%s",
1726-
sha1_to_hex(split_index->base_sha1)),
1727+
base_sha1_hex, base_path,
17271728
sha1_to_hex(split_index->base->sha1));
1729+
17281730
merge_base_index(istate);
17291731
post_read_index_from(istate);
17301732
return ret;

0 commit comments

Comments
 (0)