mirror of
https://git.proxmox.com/git/libgit2
synced 2026-08-26 20:08:02 +00:00
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.
This commit is contained in:
@@ -273,6 +273,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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user