split-index: convert struct split_index to object_id

Convert the base_sha1 member of struct split_index to use struct object_id and rename it base_oid. Include cache.h to make the structure visible. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 2, 2018 at 00:25 UTC 2182abd94bf69a8daba18e71efae3e9f02a6c465
5 files changed +22 -20
builtin/rev-parse.c
+2 -2
@@ -887,8 +887,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
887 if (read_cache() < 0)
888 die(_("Could not read the index"));
889 if (the_index.split_index) {
890 - const unsigned char *sha1 = the_index.split_index->base_sha1;
891 - const char *path = git_path("sharedindex.%s", sha1_to_hex(sha1));
890 + const struct object_id *oid = &the_index.split_index->base_oid;
891 + const char *path = git_path("sharedindex.%s", oid_to_hex(oid));
892 strbuf_reset(&buf);
893 puts(relative_path(path, prefix, &buf));
894 }
read-cache.c
+11 -11
@@ -1878,7 +1878,7 @@ int read_index_from(struct index_state *istate, const char *path,
1878 uint64_t start = getnanotime();
1879 struct split_index *split_index;
1880 int ret;
1881 - char *base_sha1_hex;
1881 + char *base_oid_hex;
1882 char *base_path;
1883
1884 /* istate->initialized covers both .git/index and .git/sharedindex.xxx */
@@ -1889,7 +1889,7 @@ int read_index_from(struct index_state *istate, const char *path,
1889 trace_performance_since(start, "read cache %s", path);
1890
1891 split_index = istate->split_index;
1892 - if (!split_index || is_null_sha1(split_index->base_sha1)) {
1892 + if (!split_index || is_null_oid(&split_index->base_oid)) {
1893 post_read_index_from(istate);
1894 return ret;
1895 }
@@ -1899,12 +1899,12 @@ int read_index_from(struct index_state *istate, const char *path,
1899 else
1900 split_index->base = xcalloc(1, sizeof(*split_index->base));
1901
1902 - base_sha1_hex = sha1_to_hex(split_index->base_sha1);
1903 - base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_sha1_hex);
1902 + base_oid_hex = oid_to_hex(&split_index->base_oid);
1903 + base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
1904 ret = do_read_index(split_index->base, base_path, 1);
1905 - if (hashcmp(split_index->base_sha1, split_index->base->sha1))
1905 + if (hashcmp(split_index->base_oid.hash, split_index->base->sha1))
1906 die("broken index, expect %s in %s, got %s",
1907 - base_sha1_hex, base_path,
1907 + base_oid_hex, base_path,
1908 sha1_to_hex(split_index->base->sha1));
1909
1910 freshen_shared_index(base_path, 0);
@@ -2499,7 +2499,7 @@ static int write_shared_index(struct index_state *istate,
2499 ret = rename_tempfile(temp,
2500 git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
2501 if (!ret) {
2502 - hashcpy(si->base_sha1, si->base->sha1);
2502 + hashcpy(si->base_oid.hash, si->base->sha1);
2503 clean_shared_index_files(sha1_to_hex(si->base->sha1));
2504 }
2505
@@ -2554,13 +2554,13 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
2554 if (!si || alternate_index_output ||
2555 (istate->cache_changed & ~EXTMASK)) {
2556 if (si)
2557 - hashclr(si->base_sha1);
2557 + oidclr(&si->base_oid);
2558 ret = do_write_locked_index(istate, lock, flags);
2559 goto out;
2560 }
2561
2562 if (getenv("GIT_TEST_SPLIT_INDEX")) {
2563 - int v = si->base_sha1[0];
2563 + int v = si->base_oid.hash[0];
2564 if ((v & 15) < 6)
2565 istate->cache_changed |= SPLIT_INDEX_ORDERED;
2566 }
@@ -2575,7 +2575,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
2575
2576 temp = mks_tempfile(git_path("sharedindex_XXXXXX"));
2577 if (!temp) {
2578 - hashclr(si->base_sha1);
2578 + oidclr(&si->base_oid);
2579 ret = do_write_locked_index(istate, lock, flags);
2580 goto out;
2581 }
@@ -2595,7 +2595,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
2595 /* Freshen the shared index only if the split-index was written */
2596 if (!ret && !new_shared_index) {
2597 const char *shared_index = git_path("sharedindex.%s",
2598 - sha1_to_hex(si->base_sha1));
2598 + oid_to_hex(&si->base_oid));
2599 freshen_shared_index(shared_index, 1);
2600 }
2601
split-index.c
+5 -5
@@ -18,12 +18,12 @@ int read_link_extension(struct index_state *istate,
18 struct split_index *si;
19 int ret;
20
21 - if (sz < 20)
21 + if (sz < the_hash_algo->rawsz)
22 return error("corrupt link extension (too short)");
23 si = init_split_index(istate);
24 - hashcpy(si->base_sha1, data);
25 - data += 20;
26 - sz -= 20;
24 + hashcpy(si->base_oid.hash, data);
25 + data += the_hash_algo->rawsz;
26 + sz -= the_hash_algo->rawsz;
27 if (!sz)
28 return 0;
29 si->delete_bitmap = ewah_new();
@@ -45,7 +45,7 @@ int write_link_extension(struct strbuf *sb,
45 struct index_state *istate)
46 {
47 struct split_index *si = istate->split_index;
48 - strbuf_add(sb, si->base_sha1, 20);
48 + strbuf_add(sb, si->base_oid.hash, the_hash_algo->rawsz);
49 if (!si->delete_bitmap && !si->replace_bitmap)
50 return 0;
51 ewah_serialize_strbuf(si->delete_bitmap, sb);
split-index.h
+3 -1
@@ -1,12 +1,14 @@
1 #ifndef SPLIT_INDEX_H
2 #define SPLIT_INDEX_H
3
4 +#include "cache.h"
5 +
6 struct index_state;
7 struct strbuf;
8 struct ewah_bitmap;
9
10 struct split_index {
9 - unsigned char base_sha1[20];
11 + struct object_id base_oid;
12 struct index_state *base;
13 struct ewah_bitmap *delete_bitmap;
14 struct ewah_bitmap *replace_bitmap;
t/helper/test-dump-split-index.c
+1 -1
@@ -20,7 +20,7 @@ int cmd__dump_split_index(int ac, const char **av)
20 printf("not a split index\n");
21 return 0;
22 }
23 - printf("base %s\n", sha1_to_hex(si->base_sha1));
23 + printf("base %s\n", oid_to_hex(&si->base_oid));
24 for (i = 0; i < the_index.cache_nr; i++) {
25 struct cache_entry *ce = the_index.cache[i];
26 printf("%06o %s %d\t%s\n", ce->ce_mode,