28#ifndef KIGIT_LOCK_RETRY_H
29#define KIGIT_LOCK_RETRY_H
70 explicit REPO_ACTION_LOCK(
const std::filesystem::path& aCommonDir,
const char* aName =
"kicad-action" );
REPO_ACTION_LOCK(const std::filesystem::path &aCommonDir, const char *aName="kicad-action")
aCommonDir is as git_repository_commondir gives it. aName picks an independent lock in that directory...
std::filesystem::path m_path
REPO_ACTION_LOCK & operator=(const REPO_ACTION_LOCK &)=delete
int TryAcquire()
Try once without waiting. 0 once held, GIT_ELOCKED while another holder has it, GIT_ERROR otherwise.
REPO_ACTION_LOCK(const REPO_ACTION_LOCK &)=delete
int Acquire(std::chrono::milliseconds aBudget=BACKEND_LOCK_BUDGET)
TryAcquire again after each contention until it is held, fails otherwise, or aBudget is spent.
const std::string & Error() const
Why the last TryAcquire could not use the lock file, or empty when it could.
#define APIEXPORT
Macros which export functions from a DLL/DSO.
bool IsLockContention(int aGitError)
True when aGitError says another writer held a lock or moved a ref first.
constexpr std::chrono::milliseconds BACKEND_LOCK_BUDGET
Budget for a backend call, which never runs on the UI thread.
int EditIndexLocked(git_repository *aRepo, const std::function< int(git_index *aIndex)> &aEdit)
Rewrite aRepo's index the way git does, holding index.lock from a fresh read of the file to the renam...
int WithLockRetry(std::chrono::milliseconds aBudget, const std::function< int()> &aOp)
Run aOp, which returns 0 or a libgit2 error code, again after each lock contention until it succeeds,...
std::unique_ptr< REPO_ACTION_LOCK > RepoActionLock(git_repository *aRepo, const char *aName)
The lock aName in aRepo's common git directory, which every worktree of the repository shares.