From: Joey Hess Date: Fri, 16 Jul 2021 18:16:05 +0000 (-0400) Subject: split annexLocations X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~2^2^2~69^2~59 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=635e7f3e262b3d190a982a900c8a4eda3d84ea8b;p=git-annex.git split annexLocations To avoid mistakes like commit 0ccbed4f6fe0149229533b8448eee7dd6f90dc29, be explicit about the two variants of this. Incidentially avoids a small amount of overhead in calling reverse. Sponsored-by: Shae Erisson on Patreon --- diff --git a/Annex/Locations.hs b/Annex/Locations.hs index 47323a716d..e611e0adcb 100644 --- a/Annex/Locations.hs +++ b/Annex/Locations.hs @@ -1,6 +1,6 @@ {- git-annex file locations - - - Copyright 2010-2020 Joey Hess + - Copyright 2010-2021 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -22,7 +22,8 @@ module Annex.Locations ( gitAnnexContentLock, gitAnnexInodeSentinal, gitAnnexInodeSentinalCache, - annexLocations, + annexLocationsBare, + annexLocationsNonBare, gitAnnexDir, gitAnnexObjectDir, gitAnnexTmpOtherDir, @@ -134,13 +135,20 @@ objectDir = fromRawFilePath objectDir' objectDir' :: RawFilePath objectDir' = P.addTrailingPathSeparator $ annexDir P. "objects" -{- Annexed file's possible locations relative to the .git directory. - - There are two different possibilities, using different hashes. +{- Annexed file's possible locations relative to the .git directory + - in a non-bare repository. - - - Also, some repositories have a Difference in hash directory depth. - -} -annexLocations :: GitConfig -> Key -> [RawFilePath] -annexLocations config key = map (annexLocation config key) dirHashes + - Normally it is hashDirMixed. However, it's always possible that a + - bare repository was converted to non-bare, or that the cripped + - filesystem setting changed, so still need to check both. -} +annexLocationsNonBare :: GitConfig -> Key -> [RawFilePath] +annexLocationsNonBare config key = + map (annexLocation config key) [hashDirMixed, hashDirLower] + +{- Annexed file's possible locations relative to a bare repository. -} +annexLocationsBare :: GitConfig -> Key -> [RawFilePath] +annexLocationsBare config key = + map (annexLocation config key) [hashDirLower, hashDirMixed] annexLocation :: GitConfig -> Key -> (HashLevels -> Hasher) -> RawFilePath annexLocation config key hasher = objectDir' P. keyPath key (hasher $ objectHashLevels config) @@ -171,26 +179,20 @@ gitAnnexLocation' :: Key -> Git.Repo -> GitConfig -> Bool -> Bool -> (RawFilePat gitAnnexLocation' key r config crippled symlinkssupported checker gitdir {- Bare repositories default to hashDirLower for new - content, as it's more portable. But check all locations. -} - | Git.repoIsLocalBare r = checkall id + | Git.repoIsLocalBare r = checkall annexLocationsBare {- If the repository is configured to only use lower, no need - to check both. -} | hasDifference ObjectHashLower (annexDifferences config) = only hashDirLower - {- Repositories on crippled filesystems use hashDirLower - - for new content, unless symlinks are supported too. - - Then hashDirMixed is used. But, the content could be - - in either location so check both. -} + {- Repositories on crippled filesystems use same layout as bare + - repos for new content, unless symlinks are supported too. -} | crippled = if symlinkssupported - then checkall reverse - else checkall id - {- Regular repositories usually only use hashDirMixed. - - However, it's always possible that a bare repository was - - converted to non-bare, or that the cripped filesystem - - setting changed, so still need to check both. -} - | otherwise = checkall reverse + then checkall annexLocationsNonBare + else checkall annexLocationsBare + | otherwise = checkall annexLocationsNonBare where only = return . inrepo . annexLocation config key - checkall f = check $ map inrepo $ f $ annexLocations config key + checkall f = check $ map inrepo $ f config key inrepo d = gitdir P. d check locs@(l:_) = fromMaybe l <$> firstM checker locs @@ -624,8 +626,8 @@ keyPath key hasher = hasher key P. f P. f {- All possibile locations to store a key in a special remote - using different directory hashes. - - - This is compatible with the annexLocations, for interoperability between - - special remotes and git-annex repos. + - This is compatible with the annexLocationsNonBare and annexLocationsBare, + - for interoperability between special remotes and git-annex repos. -} keyPaths :: Key -> [RawFilePath] keyPaths key = map (\h -> keyPath key (h def)) dirHashes diff --git a/Remote/Git.hs b/Remote/Git.hs index c2a23789a5..bd659184c7 100644 --- a/Remote/Git.hs +++ b/Remote/Git.hs @@ -429,8 +429,8 @@ keyUrls gc repo r key = map tourl locs' -- If the remote is known to not be bare, try the hash locations -- used for non-bare repos first, as an optimisation. locs - | remoteAnnexBare remoteconfig == Just False = reverse (annexLocations gc key) - | otherwise = annexLocations gc key + | remoteAnnexBare remoteconfig == Just False = annexLocationsNonBare gc key + | otherwise = annexLocationsBare gc key #ifndef mingw32_HOST_OS locs' = map fromRawFilePath locs #else