avoid update-index race
This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
parent
82c5dd8a01
commit
54d49eeac8
7 changed files with 91 additions and 46 deletions
11
Git/Index.hs
11
Git/Index.hs
|
@ -1,6 +1,6 @@
|
|||
{- git index file stuff
|
||||
-
|
||||
- Copyright 2011 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2018 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
@ -47,12 +47,17 @@ override index _r = do
|
|||
reset (Just v) = setEnv indexEnv v True
|
||||
reset _ = unsetEnv var
|
||||
|
||||
{- The normal index file. Does not check GIT_INDEX_FILE. -}
|
||||
indexFile :: Repo -> FilePath
|
||||
indexFile r = localGitDir r </> "index"
|
||||
|
||||
{- The index file git will currently use, checking GIT_INDEX_FILE. -}
|
||||
currentIndexFile :: Repo -> IO FilePath
|
||||
currentIndexFile r = fromMaybe (indexFile r) <$> getEnv indexEnv
|
||||
|
||||
{- Git locks the index by creating this file. -}
|
||||
indexFileLock :: Repo -> FilePath
|
||||
indexFileLock r = indexFile r ++ ".lock"
|
||||
indexFileLock :: FilePath -> FilePath
|
||||
indexFileLock f = f ++ ".lock"
|
||||
|
||||
{- When the pre-commit hook is run, and git commit has been run with
|
||||
- a file or files specified to commit, rather than committing the staged
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{- git-update-index library
|
||||
-
|
||||
- Copyright 2011-2013 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2018 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
@ -21,6 +21,7 @@ module Git.UpdateIndex (
|
|||
unstageFile,
|
||||
stageSymlink,
|
||||
stageDiffTreeItem,
|
||||
refreshIndex,
|
||||
) where
|
||||
|
||||
import Common
|
||||
|
@ -123,3 +124,23 @@ stageDiffTreeItem d = case toTreeItemType (Diff.dstmode d) of
|
|||
|
||||
indexPath :: TopFilePath -> InternalGitPath
|
||||
indexPath = toInternalGitPath . getTopFilePath
|
||||
|
||||
{- Refreshes the index, by checking file stat information. -}
|
||||
refreshIndex :: Repo -> ((FilePath -> IO ()) -> IO ()) -> IO Bool
|
||||
refreshIndex repo feeder = do
|
||||
(Just h, _, _, p) <- createProcess (gitCreateProcess params repo)
|
||||
{ std_in = CreatePipe }
|
||||
feeder $ \f -> do
|
||||
hPutStr h f
|
||||
hPutStr h "\0"
|
||||
hFlush h
|
||||
hClose h
|
||||
checkSuccessProcess p
|
||||
where
|
||||
params =
|
||||
[ Param "update-index"
|
||||
, Param "-q"
|
||||
, Param "--refresh"
|
||||
, Param "-z"
|
||||
, Param "--stdin"
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue