diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-19 23:05:08 +0300 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-19 23:05:08 +0300 |
commit | 5e947c91d49aacc8abb5b3f018737c72c52486a9 (patch) | |
tree | 692d72036f7f06c03571652107b9b279948e9106 /include | |
parent | 46c84c72600c0aed379e0df659ad1ca518fdd7cb (diff) |
index: use the checksum to check whether it's been modified
We currently use a timetamp to check whether an index file has been
modified since we last read it, but this is racy. If two updates happen
in the same second and we read after the first one, we won't detect the
second one.
Instead read the SHA-1 checksum of the file, which are its last 20 bytes which
gives us a sure-fire way to detect whether the file has changed since we
last read it.
As we're now keeping track of it, expose an accessor to this data.
Diffstat (limited to 'include')
-rw-r--r-- | include/git2/index.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/git2/index.h b/include/git2/index.h index 49bbe1614..7caf3ed78 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -274,6 +274,18 @@ GIT_EXTERN(int) git_index_write(git_index *index); GIT_EXTERN(const char *) git_index_path(const git_index *index); /** + * Get the checksum of the index + * + * This checksum is the SHA-1 hash over the index file (except the + * last 20 bytes which are the checksum itself). In cases where the + * index does not exist on-disk, it will be zeroed out. + * + * @param index an existing index object + * @return a pointer to the checksum of the index + */ +GIT_EXTERN(const git_oid *) git_index_checksum(git_index *index); + +/** * Read a tree into the index file with stats * * The current index contents will be replaced by the specified tree. |