annex.tune.branchhash1=true bugfix

Fix support for repositories tuned with annex.tune.branchhash1=true,
including --all not working and git-annex log not displaying anything for
annexed files.
This commit is contained in:
Joey Hess 2020-02-14 15:22:48 -04:00
parent c265cf27a0
commit 879f52a116
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 61 additions and 23 deletions

View file

@ -577,10 +577,11 @@ performTransitionsLocked jl ts neednewlocalbranch transitionedrefs = do
-} -}
run [] = noop run [] = noop
run changers = do run changers = do
config <- Annex.getGitConfig
trustmap <- calcTrustMap <$> getStaged trustLog trustmap <- calcTrustMap <$> getStaged trustLog
remoteconfigmap <- calcRemoteConfigMap <$> getStaged remoteLog remoteconfigmap <- calcRemoteConfigMap <$> getStaged remoteLog
-- partially apply, improves performance -- partially apply, improves performance
let changers' = map (\c -> c trustmap remoteconfigmap) changers let changers' = map (\c -> c config trustmap remoteconfigmap) changers
fs <- branchFiles fs <- branchFiles
forM_ fs $ \f -> do forM_ fs $ \f -> do
content <- getStaged f content <- getStaged f

View file

@ -22,6 +22,7 @@ import Types.TrustLevel
import Types.UUID import Types.UUID
import Types.MetaData import Types.MetaData
import Types.Remote import Types.Remote
import Types.GitConfig
import Types.ProposedAccepted import Types.ProposedAccepted
import Annex.SpecialRemote.Config import Annex.SpecialRemote.Config
@ -35,7 +36,7 @@ data FileTransition
= ChangeFile Builder = ChangeFile Builder
| PreserveFile | PreserveFile
type TransitionCalculator = TrustMap -> M.Map UUID RemoteConfig -> RawFilePath -> L.ByteString -> FileTransition type TransitionCalculator = GitConfig -> TrustMap -> M.Map UUID RemoteConfig -> RawFilePath -> L.ByteString -> FileTransition
getTransitionCalculator :: Transition -> Maybe TransitionCalculator getTransitionCalculator :: Transition -> Maybe TransitionCalculator
getTransitionCalculator ForgetGitHistory = Nothing getTransitionCalculator ForgetGitHistory = Nothing
@ -54,7 +55,7 @@ getTransitionCalculator ForgetDeadRemotes = Just dropDead
-- is not removed from the remote log, for the same reason the trust log -- is not removed from the remote log, for the same reason the trust log
-- is not changed. -- is not changed.
dropDead :: TransitionCalculator dropDead :: TransitionCalculator
dropDead trustmap remoteconfigmap f content = case getLogVariety f of dropDead config trustmap remoteconfigmap f content = case getLogVariety config f of
Just OldUUIDBasedLog Just OldUUIDBasedLog
| f == trustLog -> PreserveFile | f == trustLog -> PreserveFile
| f == remoteLog -> ChangeFile $ | f == remoteLog -> ChangeFile $

View file

@ -9,6 +9,9 @@ git-annex (7.20200205) UNRELEASED; urgency=medium
be used, to clearly state why. be used, to clearly state why.
* Avoid throwing fatal errors when asked to write to a readonly * Avoid throwing fatal errors when asked to write to a readonly
git remote on http. git remote on http.
* Fix support for repositories tuned with annex.tune.branchhash1=true,
including --all not working and git-annex log not displaying anything
for annexed files.
-- Joey Hess <id@joeyh.name> Fri, 14 Feb 2020 14:12:25 -0400 -- Joey Hess <id@joeyh.name> Fri, 14 Feb 2020 14:12:25 -0400

View file

@ -210,6 +210,7 @@ getAllLog = getGitLog []
getGitLog :: [FilePath] -> [CommandParam] -> Annex ([RefChange], IO Bool) getGitLog :: [FilePath] -> [CommandParam] -> Annex ([RefChange], IO Bool)
getGitLog fs os = do getGitLog fs os = do
config <- Annex.getGitConfig
(ls, cleanup) <- inRepo $ pipeNullSplit $ (ls, cleanup) <- inRepo $ pipeNullSplit $
[ Param "log" [ Param "log"
, Param "-z" , Param "-z"
@ -220,7 +221,7 @@ getGitLog fs os = do
[ Param $ Git.fromRef Annex.Branch.fullname [ Param $ Git.fromRef Annex.Branch.fullname
, Param "--" , Param "--"
] ++ map Param fs ] ++ map Param fs
return (parseGitRawLog (map decodeBL' ls), cleanup) return (parseGitRawLog config (map decodeBL' ls), cleanup)
-- Parses chunked git log --raw output, which looks something like: -- Parses chunked git log --raw output, which looks something like:
-- --
@ -236,8 +237,8 @@ getGitLog fs os = do
-- --
-- The timestamp is not included before all changelines, so -- The timestamp is not included before all changelines, so
-- keep track of the most recently seen timestamp. -- keep track of the most recently seen timestamp.
parseGitRawLog :: [String] -> [RefChange] parseGitRawLog :: GitConfig -> [String] -> [RefChange]
parseGitRawLog = parse epoch parseGitRawLog config = parse epoch
where where
epoch = toEnum 0 :: POSIXTime epoch = toEnum 0 :: POSIXTime
parse oldts ([]:rest) = parse oldts rest parse oldts ([]:rest) = parse oldts rest
@ -250,7 +251,7 @@ parseGitRawLog = parse epoch
(tss, cl') -> (parseTimeStamp tss, cl') (tss, cl') -> (parseTimeStamp tss, cl')
mrc = do mrc = do
(old, new) <- parseRawChangeLine cl (old, new) <- parseRawChangeLine cl
key <- locationLogFileKey (toRawFilePath c2) key <- locationLogFileKey config (toRawFilePath c2)
return $ RefChange return $ RefChange
{ changetime = ts { changetime = ts
, oldref = old , oldref = old

31
Logs.hs
View file

@ -1,6 +1,6 @@
{- git-annex log file names {- git-annex log file names
- -
- Copyright 2013-2019 Joey Hess <id@joeyh.name> - Copyright 2013-2020 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -27,8 +27,8 @@ data LogVariety
{- Converts a path from the git-annex branch into one of the varieties {- Converts a path from the git-annex branch into one of the varieties
- of logs used by git-annex, if it's a known path. -} - of logs used by git-annex, if it's a known path. -}
getLogVariety :: RawFilePath -> Maybe LogVariety getLogVariety :: GitConfig -> RawFilePath -> Maybe LogVariety
getLogVariety f getLogVariety config f
| f `elem` topLevelOldUUIDBasedLogs = Just OldUUIDBasedLog | f `elem` topLevelOldUUIDBasedLogs = Just OldUUIDBasedLog
| f `elem` topLevelNewUUIDBasedLogs = Just NewUUIDBasedLog | f `elem` topLevelNewUUIDBasedLogs = Just NewUUIDBasedLog
| isRemoteStateLog f = Just NewUUIDBasedLog | isRemoteStateLog f = Just NewUUIDBasedLog
@ -36,7 +36,7 @@ getLogVariety f
| isChunkLog f = ChunkLog <$> extLogFileKey chunkLogExt f | isChunkLog f = ChunkLog <$> extLogFileKey chunkLogExt f
| isRemoteMetaDataLog f = Just RemoteMetaDataLog | isRemoteMetaDataLog f = Just RemoteMetaDataLog
| isMetaDataLog f || f `elem` otherLogs = Just OtherLog | isMetaDataLog f || f `elem` otherLogs = Just OtherLog
| otherwise = PresenceLog <$> firstJust (presenceLogs f) | otherwise = PresenceLog <$> firstJust (presenceLogs config f)
{- All the old-format uuid-based logs stored in the top of the git-annex branch. -} {- All the old-format uuid-based logs stored in the top of the git-annex branch. -}
topLevelOldUUIDBasedLogs :: [RawFilePath] topLevelOldUUIDBasedLogs :: [RawFilePath]
@ -61,10 +61,10 @@ topLevelNewUUIDBasedLogs =
{- All the ways to get a key from a presence log file -} {- All the ways to get a key from a presence log file -}
presenceLogs :: RawFilePath -> [Maybe Key] presenceLogs :: GitConfig -> RawFilePath -> [Maybe Key]
presenceLogs f = presenceLogs config f =
[ urlLogFileKey f [ urlLogFileKey f
, locationLogFileKey f , locationLogFileKey config f
] ]
{- Top-level logs that are neither UUID based nor presence logs. -} {- Top-level logs that are neither UUID based nor presence logs. -}
@ -218,8 +218,17 @@ urlLogFileKey :: RawFilePath -> Maybe Key
urlLogFileKey = extLogFileKey urlLogExt urlLogFileKey = extLogFileKey urlLogExt
{- Converts a pathname into a key if it's a location log. -} {- Converts a pathname into a key if it's a location log. -}
locationLogFileKey :: RawFilePath -> Maybe Key locationLogFileKey :: GitConfig -> RawFilePath -> Maybe Key
locationLogFileKey path locationLogFileKey config path
-- Want only xx/yy/foo.log, not .log files in other places. | length (splitDirectories (fromRawFilePath path)) /= locationLogFileDepth config = Nothing
| length (splitDirectories (fromRawFilePath path)) /= 3 = Nothing
| otherwise = extLogFileKey ".log" path | otherwise = extLogFileKey ".log" path
{- Depth of location log files within the git-annex branch.
-
- Normally they are xx/yy/key.log so depth 3.
- The same extension is also used for other logs that
- are not location logs. -}
locationLogFileDepth :: GitConfig -> Int
locationLogFileDepth config = hashlevels + 1
where
HashLevels hashlevels = branchHashLevels config

View file

@ -130,8 +130,10 @@ loggedKeys :: Annex [Unchecked Key]
loggedKeys = loggedKeys' (not <$$> checkDead) loggedKeys = loggedKeys' (not <$$> checkDead)
loggedKeys' :: (Key -> Annex Bool) -> Annex [Unchecked Key] loggedKeys' :: (Key -> Annex Bool) -> Annex [Unchecked Key]
loggedKeys' check = mapMaybe (defercheck <$$> locationLogFileKey) loggedKeys' check = do
<$> Annex.Branch.files config <- Annex.getGitConfig
mapMaybe (defercheck <$$> locationLogFileKey config)
<$> Annex.Branch.files
where where
defercheck k = Unchecked $ ifM (check k) defercheck k = Unchecked $ ifM (check k)
( return (Just k) ( return (Just k)

View file

@ -67,16 +67,17 @@ upgrade = do
locationLogs :: Annex [(Key, FilePath)] locationLogs :: Annex [(Key, FilePath)]
locationLogs = do locationLogs = do
config <- Annex.getGitConfig
dir <- fromRepo gitStateDir dir <- fromRepo gitStateDir
liftIO $ do liftIO $ do
levela <- dirContents dir levela <- dirContents dir
levelb <- mapM tryDirContents levela levelb <- mapM tryDirContents levela
files <- mapM tryDirContents (concat levelb) files <- mapM tryDirContents (concat levelb)
return $ mapMaybe islogfile (concat files) return $ mapMaybe (islogfile config) (concat files)
where where
tryDirContents d = catchDefaultIO [] $ dirContents d tryDirContents d = catchDefaultIO [] $ dirContents d
islogfile f = maybe Nothing (\k -> Just (k, f)) $ islogfile config f = maybe Nothing (\k -> Just (k, f)) $
locationLogFileKey (toRawFilePath f) locationLogFileKey config (toRawFilePath f)
inject :: FilePath -> FilePath -> Annex () inject :: FilePath -> FilePath -> Annex ()
inject source dest = do inject source dest = do

View file

@ -87,3 +87,5 @@ Repository status:
Of course, I love it! Great project, thanks, Joey! Of course, I love it! Great project, thanks, Joey!
However, /me always wants more features from it. It's great that git-annex continues to develop. However, /me always wants more features from it. It's great that git-annex continues to develop.
> [[fixed|done]] --[[Joey]]

View file

@ -0,0 +1,18 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2020-02-14T19:01:50Z"
content="""
Indeed this is a bug. Easy to see why, note that "3":
locationLogFileKey path
-- Want only xx/yy/foo.log, not .log files in other places.
| length (splitDirectories (fromRawFilePath path)) /= 3 = Nothing
So this also affected some other things that use that. Including `git-annex log`,
potentially something to do with v2 upgrade (if a v2 repo could be tuned this way?),
and handling transitions set up by `git annex forget`.
(I also checked if annex.tune.objecthash1 similarly broke stuff that
enumerated .git/annex/objects, but that was handled ok already.)
"""]]