sync: Fix locking problems during merge when annex.pidlock is set

Presumably git merge sometimes needs to verifiy if a worktree file is
modified, and so will then run git-annex filter-process which would try to
take the pid lock. And for whatever reason, git-annex sync already had the
pidlock held. I have not replicated that, but it does make enough sense to
deploy the workaround.

Like I said back in commit 7bdb0cdc0d,

   Arguably, it would be better to have a way to make any process git-annex
   runs have the env var set. But then it would need to take the pid lock
   when running any and all processes, and that would be a problem when
   git-annex runs two processes concurrently. So, I'm left doing it ad-hoc
   in places where git-annex really does run a child process, directly
   or indirectly via a particular git command.

Sponsored-by: KDM on Patreon
This commit is contained in:
Joey Hess 2023-12-04 13:37:58 -04:00
parent 37ff9b6401
commit 0485dd3161
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 41 additions and 9 deletions

View file

@ -76,6 +76,7 @@ import Annex.TaggedPush
import Annex.CurrentBranch
import Annex.Import
import Annex.CheckIgnore
import Annex.PidLock
import Types.FileMatcher
import Types.GitConfig
import Types.Availability
@ -352,15 +353,16 @@ mergeConfig mergeunrelated = do
]
merge :: CurrBranch -> [Git.Merge.MergeConfig] -> SyncOptions -> Git.Branch.CommitMode -> [Git.Branch] -> Annex Bool
merge currbranch mergeconfig o commitmode tomergel = do
canresolvemerge <- if resolveMergeOverride o
then getGitConfigVal annexResolveMerge
else return False
and <$> case currbranch of
(Just b, Just adj) -> forM tomergel $ \tomerge ->
mergeToAdjustedBranch tomerge (b, adj) mergeconfig canresolvemerge commitmode
(b, _) -> forM tomergel $ \tomerge ->
autoMergeFrom tomerge b mergeconfig commitmode canresolvemerge
merge currbranch mergeconfig o commitmode tomergel =
runsGitAnnexChildProcessViaGit $ do
canresolvemerge <- if resolveMergeOverride o
then getGitConfigVal annexResolveMerge
else return False
and <$> case currbranch of
(Just b, Just adj) -> forM tomergel $ \tomerge ->
mergeToAdjustedBranch tomerge (b, adj) mergeconfig canresolvemerge commitmode
(b, _) -> forM tomergel $ \tomerge ->
autoMergeFrom tomerge b mergeconfig commitmode canresolvemerge
syncBranch :: Git.Branch -> Git.Branch
syncBranch = Git.Ref.underBase "refs/heads/synced" . origBranch