]> dgit.raspbian.org Git - git-annex.git/commitdiff
split annexLocations
authorJoey Hess <joeyh@joeyh.name>
Fri, 16 Jul 2021 18:16:05 +0000 (14:16 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 16 Jul 2021 18:17:56 +0000 (14:17 -0400)
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
Annex/Locations.hs
Remote/Git.hs

index 47323a716da884f39abd74aa23691cc4a97b3f06..e611e0adcb1410d4bfb11bb432a493696055d23a 100644 (file)
@@ -1,6 +1,6 @@
 {- git-annex file locations
  -
- - Copyright 2010-2020 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2021 Joey Hess <id@joeyh.name>
  -
  - 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
index c2a23789a5b664850f92a16491c141d41c7dbaac..bd659184c7bac8d1ab7ee1c003f7fbf1450688b5 100644 (file)
@@ -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