diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2014-06-13 19:19:35 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-06-13 11:49:39 -0700 |
commit | e93021b20a73af8ff51f9ddd8c98f44fd103f360 (patch) | |
tree | 81eac1241c7421e98d705fba74ebb4e76f8faca4 /read-cache.c | |
parent | d4a2024aef90fa5dd2b0e5027f9340719ff20748 (diff) | |
download | git-e93021b20a73af8ff51f9ddd8c98f44fd103f360.tar.gz |
read-cache: save index SHA-1 after reading
Also update SHA-1 after writing. If we do not do that, the second
read_index() will see "initialized" variable already set and not read
.git/index again, which is fine, except istate->sha1 now has a stale
value.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/read-cache.c b/read-cache.c index d1ad227720..b4653c083a 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1481,6 +1481,7 @@ int read_index_from(struct index_state *istate, const char *path) if (verify_hdr(hdr, mmap_size) < 0) goto unmap; + hashcpy(istate->sha1, (const unsigned char *)hdr + mmap_size - 20); istate->version = ntohl(hdr->hdr_version); istate->cache_nr = ntohl(hdr->hdr_entries); istate->cache_alloc = alloc_nr(istate->cache_nr); @@ -1616,7 +1617,7 @@ static int write_index_ext_header(git_SHA_CTX *context, int fd, (ce_write(context, fd, &sz, 4) < 0)) ? -1 : 0; } -static int ce_flush(git_SHA_CTX *context, int fd) +static int ce_flush(git_SHA_CTX *context, int fd, unsigned char *sha1) { unsigned int left = write_buffer_len; @@ -1634,6 +1635,7 @@ static int ce_flush(git_SHA_CTX *context, int fd) /* Append the SHA1 signature at the end */ git_SHA1_Final(write_buffer + left, context); + hashcpy(sha1, write_buffer + left); left += 20; return (write_in_full(fd, write_buffer, left) != left) ? -1 : 0; } @@ -1872,7 +1874,7 @@ static int do_write_index(struct index_state *istate, int newfd) return -1; } - if (ce_flush(&c, newfd) || fstat(newfd, &st)) + if (ce_flush(&c, newfd, istate->sha1) || fstat(newfd, &st)) return -1; istate->timestamp.sec = (unsigned int)st.st_mtime; istate->timestamp.nsec = ST_MTIME_NSEC(st); |