Skip to content

Commit 470d7c1

Browse files
Ben PeartBen Peart
authored andcommitted
PR 133870: Update logic to disable SHA to that it will coexist with split-index.
- Update logic to disable SHA to that it will coexist with split-index. - Add additional performance tracing around key index functions (read, write, hash).
1 parent 0f80273 commit 470d7c1

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

name-hash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ static void lazy_init_name_hash(struct index_state *istate)
118118

119119
if (istate->name_hash_initialized)
120120
return;
121+
uint64_t start = getnanotime();
121122
hashmap_init(&istate->name_hash, (hashmap_cmp_fn) cache_entry_cmp,
122123
istate->cache_nr);
123124
hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp, 0);
124125
for (nr = 0; nr < istate->cache_nr; nr++)
125126
hash_index_entry(istate, istate->cache[nr]);
126127
istate->name_hash_initialized = 1;
128+
trace_performance_since(start, "lazy_init_name_hash");
127129
}
128130

129131
void add_name_hash(struct index_state *istate, struct cache_entry *ce)

read-cache.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,9 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
13611361
if (hdr_version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < hdr_version)
13621362
return error("bad index version %d", hdr_version);
13631363

1364+
/* Initialize the sha before bailing out early so that split-index still works */
1365+
git_SHA1_Init(&c);
1366+
13641367
/*
13651368
Since gitmodules_config runs this code
13661369
and is called before git_config(git_default_config, ...)
@@ -1369,7 +1372,6 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
13691372
if (gvfs_config_load_and_is_set(GVFS_SKIP_SHA_ON_INDEX))
13701373
return 0;
13711374

1372-
git_SHA1_Init(&c);
13731375
git_SHA1_Update(&c, hdr, size - 20);
13741376
git_SHA1_Final(sha1, &c);
13751377
if (hashcmp(sha1, (unsigned char *)hdr + size - 20))
@@ -1656,11 +1658,13 @@ int read_index_from(struct index_state *istate, const char *path)
16561658
if (istate->initialized)
16571659
return istate->cache_nr;
16581660

1661+
uint64_t start = getnanotime();
16591662
ret = do_read_index(istate, path, 0);
16601663

16611664
split_index = istate->split_index;
16621665
if (!split_index || is_null_sha1(split_index->base_sha1)) {
16631666
post_read_index_from(istate);
1667+
trace_performance_since(start, "read_index_from");
16641668
return ret;
16651669
}
16661670

@@ -1679,6 +1683,7 @@ int read_index_from(struct index_state *istate, const char *path)
16791683
sha1_to_hex(split_index->base->sha1));
16801684
merge_base_index(istate);
16811685
post_read_index_from(istate);
1686+
trace_performance_since(start, "read_index_from");
16821687
return ret;
16831688
}
16841689

@@ -1795,8 +1800,6 @@ static int ce_flush(git_SHA_CTX *context, int fd, unsigned char *sha1)
17951800
/* Append the SHA1 signature at the end */
17961801
if (!gvfs_config_is_set(GVFS_SKIP_SHA_ON_INDEX))
17971802
git_SHA1_Final(write_buffer + left, context);
1798-
else
1799-
hashclr(write_buffer + left);
18001803
hashcpy(sha1, write_buffer + left);
18011804
left += 20;
18021805
return (write_in_full(fd, write_buffer, left) != left) ? -1 : 0;
@@ -2193,13 +2196,17 @@ static int write_shared_index(struct index_state *istate,
21932196
int write_locked_index(struct index_state *istate, struct lock_file *lock,
21942197
unsigned flags)
21952198
{
2199+
uint64_t start = getnanotime();
21962200
struct split_index *si = istate->split_index;
2201+
int ret;
21972202

21982203
if (!si || alternate_index_output ||
21992204
(istate->cache_changed & ~EXTMASK)) {
22002205
if (si)
22012206
hashclr(si->base_sha1);
2202-
return do_write_locked_index(istate, lock, flags);
2207+
ret = do_write_locked_index(istate, lock, flags);
2208+
trace_performance_since(start, "write_locked_index");
2209+
return ret;
22032210
}
22042211

22052212
if (getenv("GIT_TEST_SPLIT_INDEX")) {
@@ -2208,12 +2215,16 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
22082215
istate->cache_changed |= SPLIT_INDEX_ORDERED;
22092216
}
22102217
if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
2211-
int ret = write_shared_index(istate, lock, flags);
2212-
if (ret)
2218+
ret = write_shared_index(istate, lock, flags);
2219+
if (ret) {
2220+
trace_performance_since(start, "write_locked_index");
22132221
return ret;
2222+
}
22142223
}
22152224

2216-
return write_split_index(istate, lock, flags);
2225+
ret = write_split_index(istate, lock, flags);
2226+
trace_performance_since(start, "write_locked_index");
2227+
return ret;
22172228
}
22182229

22192230
/*

0 commit comments

Comments
 (0)