Skip to content

Commit 2182abd

Browse files
bk2204gitster
authored andcommitted
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>
1 parent 34caab0 commit 2182abd

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

builtin/rev-parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
887887
if (read_cache() < 0)
888888
die(_("Could not read the index"));
889889
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));
892892
strbuf_reset(&buf);
893893
puts(relative_path(path, prefix, &buf));
894894
}

read-cache.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ int read_index_from(struct index_state *istate, const char *path,
18781878
uint64_t start = getnanotime();
18791879
struct split_index *split_index;
18801880
int ret;
1881-
char *base_sha1_hex;
1881+
char *base_oid_hex;
18821882
char *base_path;
18831883

18841884
/* 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,
18891889
trace_performance_since(start, "read cache %s", path);
18901890

18911891
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)) {
18931893
post_read_index_from(istate);
18941894
return ret;
18951895
}
@@ -1899,12 +1899,12 @@ int read_index_from(struct index_state *istate, const char *path,
18991899
else
19001900
split_index->base = xcalloc(1, sizeof(*split_index->base));
19011901

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);
19041904
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))
19061906
die("broken index, expect %s in %s, got %s",
1907-
base_sha1_hex, base_path,
1907+
base_oid_hex, base_path,
19081908
sha1_to_hex(split_index->base->sha1));
19091909

19101910
freshen_shared_index(base_path, 0);
@@ -2499,7 +2499,7 @@ static int write_shared_index(struct index_state *istate,
24992499
ret = rename_tempfile(temp,
25002500
git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
25012501
if (!ret) {
2502-
hashcpy(si->base_sha1, si->base->sha1);
2502+
hashcpy(si->base_oid.hash, si->base->sha1);
25032503
clean_shared_index_files(sha1_to_hex(si->base->sha1));
25042504
}
25052505

@@ -2554,13 +2554,13 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
25542554
if (!si || alternate_index_output ||
25552555
(istate->cache_changed & ~EXTMASK)) {
25562556
if (si)
2557-
hashclr(si->base_sha1);
2557+
oidclr(&si->base_oid);
25582558
ret = do_write_locked_index(istate, lock, flags);
25592559
goto out;
25602560
}
25612561

25622562
if (getenv("GIT_TEST_SPLIT_INDEX")) {
2563-
int v = si->base_sha1[0];
2563+
int v = si->base_oid.hash[0];
25642564
if ((v & 15) < 6)
25652565
istate->cache_changed |= SPLIT_INDEX_ORDERED;
25662566
}
@@ -2575,7 +2575,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
25752575

25762576
temp = mks_tempfile(git_path("sharedindex_XXXXXX"));
25772577
if (!temp) {
2578-
hashclr(si->base_sha1);
2578+
oidclr(&si->base_oid);
25792579
ret = do_write_locked_index(istate, lock, flags);
25802580
goto out;
25812581
}
@@ -2595,7 +2595,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
25952595
/* Freshen the shared index only if the split-index was written */
25962596
if (!ret && !new_shared_index) {
25972597
const char *shared_index = git_path("sharedindex.%s",
2598-
sha1_to_hex(si->base_sha1));
2598+
oid_to_hex(&si->base_oid));
25992599
freshen_shared_index(shared_index, 1);
26002600
}
26012601

split-index.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ int read_link_extension(struct index_state *istate,
1818
struct split_index *si;
1919
int ret;
2020

21-
if (sz < 20)
21+
if (sz < the_hash_algo->rawsz)
2222
return error("corrupt link extension (too short)");
2323
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;
2727
if (!sz)
2828
return 0;
2929
si->delete_bitmap = ewah_new();
@@ -45,7 +45,7 @@ int write_link_extension(struct strbuf *sb,
4545
struct index_state *istate)
4646
{
4747
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);
4949
if (!si->delete_bitmap && !si->replace_bitmap)
5050
return 0;
5151
ewah_serialize_strbuf(si->delete_bitmap, sb);

split-index.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#ifndef SPLIT_INDEX_H
22
#define SPLIT_INDEX_H
33

4+
#include "cache.h"
5+
46
struct index_state;
57
struct strbuf;
68
struct ewah_bitmap;
79

810
struct split_index {
9-
unsigned char base_sha1[20];
11+
struct object_id base_oid;
1012
struct index_state *base;
1113
struct ewah_bitmap *delete_bitmap;
1214
struct ewah_bitmap *replace_bitmap;

t/helper/test-dump-split-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int cmd__dump_split_index(int ac, const char **av)
2020
printf("not a split index\n");
2121
return 0;
2222
}
23-
printf("base %s\n", sha1_to_hex(si->base_sha1));
23+
printf("base %s\n", oid_to_hex(&si->base_oid));
2424
for (i = 0; i < the_index.cache_nr; i++) {
2525
struct cache_entry *ce = the_index.cache[i];
2626
printf("%06o %s %d\t%s\n", ce->ce_mode,

0 commit comments

Comments
 (0)