Commit 7db40d45 by Carlos Martín Nieto

index: use git_futils_readbuffer_updated

This helps readability a bit as well.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
parent c4982328
...@@ -248,8 +248,9 @@ void git_index_clear(git_index *index) ...@@ -248,8 +248,9 @@ void git_index_clear(git_index *index)
int git_index_read(git_index *index) int git_index_read(git_index *index)
{ {
struct stat indexst; int error = GIT_SUCCESS, updated;
int error = GIT_SUCCESS; git_fbuffer buffer = GIT_FBUFFER_INIT;
time_t mtime;
assert(index->index_file_path); assert(index->index_file_path);
...@@ -259,30 +260,24 @@ int git_index_read(git_index *index) ...@@ -259,30 +260,24 @@ int git_index_read(git_index *index)
return GIT_SUCCESS; return GIT_SUCCESS;
} }
if (p_stat(index->index_file_path, &indexst) < 0) /* We don't want to update the mtime if we fail to parse the index */
return git__throw(GIT_EOSERR, "Failed to read index. %s does not exist or is corrupted", index->index_file_path); mtime = index->last_modified;
error = git_futils_readbuffer_updated(&buffer, index->index_file_path, &mtime, &updated);
if (!S_ISREG(indexst.st_mode)) if (error < GIT_SUCCESS)
return git__throw(GIT_ENOTFOUND, "Failed to read index. %s is not an index file", index->index_file_path); return git__rethrow(error, "Failed to read index");
if (indexst.st_mtime != index->last_modified) {
git_fbuffer buffer;
if ((error = git_futils_readbuffer(&buffer, index->index_file_path)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to read index");
if (updated) {
git_index_clear(index); git_index_clear(index);
error = parse_index(index, buffer.data, buffer.len); error = parse_index(index, buffer.data, buffer.len);
if (error == GIT_SUCCESS) if (error == GIT_SUCCESS)
index->last_modified = indexst.st_mtime; index->last_modified = mtime;
git_futils_freebuffer(&buffer); git_futils_freebuffer(&buffer);
} }
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to read index"); return git__rethrow(error, "Failed to parse index");
return error; return error;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment