diff options
| author | David Turner <novalis@novalis.org> | 2021-04-14 21:52:36 -0400 |
|---|---|---|
| committer | David Turner <novalis@novalis.org> | 2021-04-20 09:24:25 -0400 |
| commit | 95b7a6398fe499fb37e49a528292c9ab2e1e8fc9 (patch) | |
| tree | e821a5c9ea3b4d5d1688571572d84f97e211c321 /include | |
| parent | ac77d306f539938aa599ba81faee52854c262328 (diff) | |
| download | libgit2-95b7a6398fe499fb37e49a528292c9ab2e1e8fc9.tar.gz | |
git_reference_create_matching: Treat all-zero OID as "must be absent"
This is pretty useful in avoiding races: I want to create a ref only if
it doesn't already exist. I can't check first because of TOCTOU -- by
the time I finish the check, someone else might have already created
the ref. And I can't take a lock because then I can't do the create,
since the create expects to take the lock.
The semantics are inspired by git update-ref, which allows an all-zero old
value to mean that the ref must not exist.
Diffstat (limited to 'include')
| -rw-r--r-- | include/git2/refs.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/include/git2/refs.h b/include/git2/refs.h index 8bc99e15e..7ebb209b2 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -97,6 +97,9 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co * of updating does not match the one passed through `current_value` * (i.e. if the ref has changed since the user read it). * + * If `current_value` is all zeros, this function will return GIT_EMODIFIED + * if the ref already exists. + * * @param out Pointer to the newly created reference * @param repo Repository where that reference will live * @param name The name of the reference |
