push RawFilePath down into Annex.ReplaceFile
authorJoey Hess <joeyh@joeyh.name>
Thu, 26 Oct 2023 17:36:49 +0000 (13:36 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 26 Oct 2023 17:36:49 +0000 (13:36 -0400)
Minor optimisation, but a win in every case, except for a couple where
it's a wash.

Note that replaceFile still takes a FilePath, because it needs to
operate on Chars to truncate unicode filenames properly.

12 files changed:
Annex/AutoMerge.hs
Annex/Content.hs
Annex/Content/PointerFile.hs
Annex/Ingest.hs
Annex/ReplaceFile.hs
Assistant/Threads/Watcher.hs
Command/Fix.hs
Command/Fsck.hs
Command/Lock.hs
Command/ReKey.hs
Command/Unlock.hs
Logs/File.hs

index 77afe521c9e36b42e6cf9802e491dbf800e45f1d..bb43d0593bcbc94051f2d2da0389f15133a2ff12 100644 (file)
@@ -242,7 +242,7 @@ resolveMerge' unstagedmap (Just us) them inoverlay u = do
                stageSymlink dest' =<< hashSymlink l
 
        replacewithsymlink dest link = replaceWorkTreeFile dest $
-               makeGitLink link . toRawFilePath
+               makeGitLink link
 
        makepointer key dest destmode = do
                unless inoverlay $ 
@@ -267,10 +267,10 @@ resolveMerge' unstagedmap (Just us) them inoverlay u = do
                        Nothing -> noop
                        Just sha -> replaceWorkTreeFile item $ \tmp -> do
                                c <- catObject sha
-                               liftIO $ L.writeFile tmp c
+                               liftIO $ L.writeFile (decodeBS tmp) c
                                when isexecutable $
                                        liftIO $ void $ tryIO $ 
-                                               modifyFileMode (toRawFilePath tmp) $
+                                               modifyFileMode tmp $
                                                        addModes executeModes
 
                -- Update the work tree to reflect the graft.
index b212fcc77a16c93c77455969ab814bc9b4e21cc1..6a028d901dce9a40de2669571a22a5f486de46e3 100644 (file)
@@ -477,7 +477,7 @@ linkToAnnex key src srcic = ifM (checkSecureHashes' key)
 linkFromAnnex :: Key -> RawFilePath -> Maybe FileMode -> Annex LinkAnnexResult
 linkFromAnnex key dest destmode =
        replaceFile' (const noop) (fromRawFilePath dest) (== LinkAnnexOk) $ \tmp ->
-               linkFromAnnex' key (toRawFilePath tmp) destmode
+               linkFromAnnex' key tmp destmode
 
 {- This is only safe to use when dest is not a worktree file. -}
 linkFromAnnex' :: Key -> RawFilePath -> Maybe FileMode -> Annex LinkAnnexResult
index 7fc4be53272fb78b467814e60a2c77de34486555..c2acc9ab9398dd36cc035ffca737715e6cd70f66 100644 (file)
@@ -38,11 +38,10 @@ populatePointerFile restage k obj f = go =<< liftIO (isPointerFile f)
                destmode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus f
                liftIO $ removeWhenExistsWith R.removeLink f
                (ic, populated) <- replaceWorkTreeFile f' $ \tmp -> do
-                       let tmp' = toRawFilePath tmp
-                       ok <- linkOrCopy k obj tmp' destmode >>= \case
-                               Just _ -> thawContent tmp' >> return True
-                               Nothing -> liftIO (writePointerFile tmp' k destmode) >> return False
-                       ic <- withTSDelta (liftIO . genInodeCache tmp')
+                       ok <- linkOrCopy k obj tmp destmode >>= \case
+                               Just _ -> thawContent tmp >> return True
+                               Nothing -> liftIO (writePointerFile tmp k destmode) >> return False
+                       ic <- withTSDelta (liftIO . genInodeCache tmp)
                        return (ic, ok)
                maybe noop (restagePointerFile restage f) ic
                if populated
@@ -60,14 +59,13 @@ depopulatePointerFile key file = do
        secureErase file
        liftIO $ removeWhenExistsWith R.removeLink file
        ic <- replaceWorkTreeFile (fromRawFilePath file) $ \tmp -> do
-               let tmp' = toRawFilePath tmp
-               liftIO $ writePointerFile tmp' key mode
+               liftIO $ writePointerFile tmp key mode
 #if ! defined(mingw32_HOST_OS)
                -- Don't advance mtime; this avoids unnecessary re-smudging
                -- by git in some cases.
                liftIO $ maybe noop
-                       (\t -> touch tmp' t False)
+                       (\t -> touch tmp t False)
                        (fmap Posix.modificationTimeHiRes st)
 #endif
-               withTSDelta (liftIO . genInodeCache tmp')
+               withTSDelta (liftIO . genInodeCache tmp)
        maybe noop (restagePointerFile (Restage True) file) ic
index 26a5e388ebe63251b14b1abf264fe78f0ac3d20b..c07c11ef120c223f4fed5d02efe5bd56510a6872 100644 (file)
@@ -306,7 +306,7 @@ restoreFile file key e = do
 makeLink :: RawFilePath -> Key -> Maybe InodeCache -> Annex LinkTarget
 makeLink file key mcache = flip catchNonAsync (restoreFile file key) $ do
        l <- calcRepo $ gitAnnexLink file key
-       replaceWorkTreeFile file' $ makeAnnexLink l . toRawFilePath
+       replaceWorkTreeFile file' $ makeAnnexLink l
 
        -- touch symlink to have same time as the original file,
        -- as provided in the InodeCache
index 9f671cb9d6b8c7fde4010eded37209a62c52b7df..21735eba14ad619438a88e1a71505cfdef385729 100644 (file)
@@ -26,17 +26,17 @@ import Utility.Path.Max
 #endif
 
 {- replaceFile on a file located inside the gitAnnexDir. -}
-replaceGitAnnexDirFile :: FilePath -> (FilePath -> Annex a) -> Annex a
+replaceGitAnnexDirFile :: FilePath -> (RawFilePath -> Annex a) -> Annex a
 replaceGitAnnexDirFile = replaceFile createAnnexDirectory
 
 {- replaceFile on a file located inside the .git directory. -}
-replaceGitDirFile :: FilePath -> (FilePath -> Annex a) -> Annex a
+replaceGitDirFile :: FilePath -> (RawFilePath -> Annex a) -> Annex a
 replaceGitDirFile = replaceFile $ \dir -> do
        top <- fromRepo localGitDir
        liftIO $ createDirectoryUnder [top] dir
 
 {- replaceFile on a worktree file. -}
-replaceWorkTreeFile :: FilePath -> (FilePath -> Annex a) -> Annex a
+replaceWorkTreeFile :: FilePath -> (RawFilePath -> Annex a) -> Annex a
 replaceWorkTreeFile = replaceFile createWorkTreeDirectory
 
 {- Replaces a possibly already existing file with a new version, 
@@ -54,10 +54,10 @@ replaceWorkTreeFile = replaceFile createWorkTreeDirectory
  - The createdirectory action is only run when moving the file into place
  - fails, and can create any parent directory structure needed.
  -}
-replaceFile :: (RawFilePath -> Annex ()) -> FilePath -> (FilePath -> Annex a) -> Annex a
+replaceFile :: (RawFilePath -> Annex ()) -> FilePath -> (RawFilePath -> Annex a) -> Annex a
 replaceFile createdirectory file action = replaceFile' createdirectory file (const True) action
 
-replaceFile' :: (RawFilePath -> Annex ()) -> FilePath -> (a -> Bool) -> (FilePath -> Annex a) -> Annex a
+replaceFile' :: (RawFilePath -> Annex ()) -> FilePath -> (a -> Bool) -> (RawFilePath -> Annex a) -> Annex a
 replaceFile' createdirectory file checkres action = withOtherTmp $ \othertmpdir -> do
        let othertmpdir' = fromRawFilePath othertmpdir
 #ifndef mingw32_HOST_OS
@@ -72,10 +72,10 @@ replaceFile' createdirectory file checkres action = withOtherTmp $ \othertmpdir
        let basetmp = "t"
 #endif
        withTmpDirIn othertmpdir' basetmp $ \tmpdir -> do
-               let tmpfile = tmpdir </> basetmp
+               let tmpfile = toRawFilePath (tmpdir </> basetmp)
                r <- action tmpfile
                when (checkres r) $
-                       replaceFileFrom (toRawFilePath tmpfile) (toRawFilePath file) createdirectory
+                       replaceFileFrom tmpfile (toRawFilePath file) createdirectory
                return r
 
 replaceFileFrom :: RawFilePath -> RawFilePath -> (RawFilePath -> Annex ()) -> Annex ()
index 1f5ebf80a06d7f8302b26d073d6e607a318e492d..2df29ce76c4410196760e143f99e84b6cd67c9d2 100644 (file)
@@ -293,7 +293,7 @@ onAddSymlink' linktarget mk file filestatus = go mk
                        then ensurestaged (Just link) =<< getDaemonStatus
                        else do
                                liftAnnex $ replaceWorkTreeFile file $
-                                       makeAnnexLink link . toRawFilePath
+                                       makeAnnexLink link
                                addLink file link (Just key)
        -- other symlink, not git-annex
        go Nothing = ensurestaged linktarget =<< getDaemonStatus
index 28c8cfa9be4ed8c409c5047642ce90993a2f789f..6ca5f5b2b7f5d590d0055fc3be5dfc7e766f15ec 100644 (file)
@@ -73,12 +73,11 @@ start fixwhat si file key = do
 breakHardLink :: RawFilePath -> Key -> RawFilePath -> CommandPerform
 breakHardLink file key obj = do
        replaceWorkTreeFile (fromRawFilePath file) $ \tmp -> do
-               let tmp' = toRawFilePath tmp
                mode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus file
-               unlessM (checkedCopyFile key obj tmp' mode) $
+               unlessM (checkedCopyFile key obj tmp mode) $
                        giveup "unable to break hard link"
-               thawContent tmp'
-               Database.Keys.storeInodeCaches key [tmp']
+               thawContent tmp
+               Database.Keys.storeInodeCaches key [tmp]
                modifyContentDir obj $ freezeContent obj
        next $ return True
 
@@ -86,7 +85,7 @@ makeHardLink :: RawFilePath -> Key -> CommandPerform
 makeHardLink file key = do
        replaceWorkTreeFile (fromRawFilePath file) $ \tmp -> do
                mode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus file
-               linkFromAnnex' key (toRawFilePath tmp) mode >>= \case
+               linkFromAnnex' key tmp mode >>= \case
                        LinkAnnexFailed -> giveup "unable to make hard link"
                        _ -> noop
        next $ return True
@@ -99,10 +98,9 @@ fixSymlink file link = do
                <$> R.getSymbolicLinkStatus file
 #endif
        replaceWorkTreeFile (fromRawFilePath file) $ \tmpfile -> do
-               let tmpfile' = toRawFilePath tmpfile
-               liftIO $ R.createSymbolicLink link tmpfile'
+               liftIO $ R.createSymbolicLink link tmpfile
 #if ! defined(mingw32_HOST_OS)
-               liftIO $ maybe noop (\t -> touch tmpfile' t False) mtime
+               liftIO $ maybe noop (\t -> touch tmpfile t False) mtime
 #endif
        stageSymlink file =<< hashSymlink link
        next $ return True
index b25e49b73e96fc326eff4057036b46e1cd751e98..748f77ab0183249f59ecb318177678498c44822c 100644 (file)
@@ -417,16 +417,15 @@ verifyWorkTree key file = do
                Just k | k == key -> whenM (inAnnex key) $ do
                        showNote "fixing worktree content"
                        replaceWorkTreeFile (fromRawFilePath file) $ \tmp -> do
-                               let tmp' = toRawFilePath tmp
                                mode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus file
                                ifM (annexThin <$> Annex.getGitConfig)
-                                       ( void $ linkFromAnnex' key tmp' mode
+                                       ( void $ linkFromAnnex' key tmp mode
                                        , do
                                                obj <- calcRepo (gitAnnexLocation key)
-                                               void $ checkedCopyFile key obj tmp' mode
-                                               thawContent tmp'
+                                               void $ checkedCopyFile key obj tmp mode
+                                               thawContent tmp
                                        )
-                               Database.Keys.storeInodeCaches key [tmp']
+                               Database.Keys.storeInodeCaches key [tmp]
                _ -> return ()
        return True
 
index d547a07f9310c2a33e8fe7e2052b8da01033cfc8..7aace76c9b336de5fe70e4c55c4e82b36ff4fcb1 100644 (file)
@@ -79,7 +79,7 @@ perform file key = do
                mfc <- withTSDelta (liftIO . genInodeCache file)
                unlessM (sameInodeCache obj (maybeToList mfc)) $ do
                        modifyContentDir obj $ replaceGitAnnexDirFile (fromRawFilePath obj) $ \tmp -> do
-                               unlessM (checkedCopyFile key obj (toRawFilePath tmp) Nothing) $
+                               unlessM (checkedCopyFile key obj tmp Nothing) $
                                        giveup "unable to lock file"
                        Database.Keys.storeInodeCaches key [obj]
 
index 5958f48ac57167188f5eb2c196a7accbe9226bd5..0b9d94e31bdc4e10b025b7ed90e44a854ce4d6a5 100644 (file)
@@ -111,10 +111,9 @@ linkKey file oldkey newkey = ifM (isJust <$> isAnnexLink file)
                        when (linkCount st > 1) $ do
                                freezeContent oldobj
                                replaceWorkTreeFile (fromRawFilePath file) $ \tmp -> do
-                                       let tmp' = toRawFilePath tmp
-                                       unlessM (checkedCopyFile oldkey oldobj tmp' Nothing) $
+                                       unlessM (checkedCopyFile oldkey oldobj tmp Nothing) $
                                                giveup "can't lock old key"
-                                       thawContent tmp'
+                                       thawContent tmp
                ic <- withTSDelta (liftIO . genInodeCache file)
                case v of
                        Left e -> do
index c0c79a7a6ad0b687a115481de50e1bc01d715afa..25e4d9aa0458f42afe8776ff3d0dc4e78c60402d 100644 (file)
@@ -54,14 +54,14 @@ perform dest key = do
        destic <- replaceWorkTreeFile (fromRawFilePath dest) $ \tmp -> do
                ifM (inAnnex key)
                        ( do
-                               r <- linkFromAnnex' key (toRawFilePath tmp) destmode
+                               r <- linkFromAnnex' key tmp destmode
                                case r of
                                        LinkAnnexOk -> return ()
                                        LinkAnnexNoop -> return ()
                                        LinkAnnexFailed -> giveup "unlock failed"
-                       , liftIO $ writePointerFile (toRawFilePath tmp) key destmode
+                       , liftIO $ writePointerFile tmp key destmode
                        )
-               withTSDelta (liftIO . genInodeCache (toRawFilePath tmp))
+               withTSDelta (liftIO . genInodeCache tmp)
        next $ cleanup dest destic key destmode
 
 cleanup :: RawFilePath -> Maybe InodeCache -> Key -> Maybe FileMode -> CommandCleanup
index 56b0c90dda361cf1c0c138a4b48037e5e7d85fe6..94b299223895715a75a0375f32b3af8c946f3f5c 100644 (file)
@@ -47,8 +47,8 @@ withLogHandle f a = do
                bracket (setup tmp) cleanup a
   where
        setup tmp = do
-               setAnnexFilePerm (toRawFilePath tmp)
-               liftIO $ openFile tmp WriteMode
+               setAnnexFilePerm tmp
+               liftIO $ openFile (fromRawFilePath tmp) WriteMode
        cleanup h = liftIO $ hClose h
 
 -- | Appends a line to a log file, first locking it to prevent