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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Mar 6, 2017 at 10:42 UTC de6ae5f9e3e0960e2adcba4688ed4293edc8424a
1 file changed +8 -6
read-cache.c
+8 -6
@@ -1699,6 +1699,8 @@ int read_index_from(struct index_state *istate, const char *path)
1699 {
1700 struct split_index *split_index;
1701 int ret;
1702 + char *base_sha1_hex;
1703 + const char *base_path;
1704
1705 /* istate->initialized covers both .git/index and .git/sharedindex.xxx */
1706 if (istate->initialized)
@@ -1716,15 +1718,15 @@ int read_index_from(struct index_state *istate, const char *path)
1718 discard_index(split_index->base);
1719 else
1720 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);
1725 if (hashcmp(split_index->base_sha1, split_index->base->sha1))
1726 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,
1728 sha1_to_hex(split_index->base->sha1));
1729 +
1730 merge_base_index(istate);
1731 post_read_index_from(istate);
1732 return ret;