add a UUIDDesc type containing a ByteString
Groundwork for handling uuid.log using ByteString
This commit is contained in:
parent
b781fbcccf
commit
894716512d
21 changed files with 94 additions and 74 deletions
34
Logs/UUID.hs
34
Logs/UUID.hs
|
@ -1,10 +1,4 @@
|
|||
{- git-annex uuids
|
||||
-
|
||||
- Each git repository used by git-annex has an annex.uuid setting that
|
||||
- uniquely identifies that repository.
|
||||
-
|
||||
- UUIDs of remotes are cached in git config, using keys named
|
||||
- remote.<name>.annex-uuid
|
||||
{- git-annex uuid log
|
||||
-
|
||||
- uuid.log stores a list of known uuids, and their descriptions.
|
||||
-
|
||||
|
@ -16,8 +10,8 @@
|
|||
module Logs.UUID (
|
||||
uuidLog,
|
||||
describeUUID,
|
||||
uuidMap,
|
||||
uuidMapLoad
|
||||
uuidDescMap,
|
||||
uuidDescMapLoad
|
||||
) where
|
||||
|
||||
import Types.UUID
|
||||
|
@ -28,15 +22,16 @@ import qualified Annex.Branch
|
|||
import Logs
|
||||
import Logs.UUIDBased
|
||||
import qualified Annex.UUID
|
||||
import Utility.FileSystemEncoding
|
||||
|
||||
import qualified Data.Map.Strict as M
|
||||
|
||||
{- Records a description for a uuid in the log. -}
|
||||
describeUUID :: UUID -> String -> Annex ()
|
||||
describeUUID :: UUID -> UUIDDesc -> Annex ()
|
||||
describeUUID uuid desc = do
|
||||
c <- liftIO currentVectorClock
|
||||
Annex.Branch.change uuidLog $
|
||||
showLog id . changeLog c uuid desc . fixBadUUID . parseLog Just
|
||||
showLog id . changeLog c uuid (fromUUIDDesc desc) . fixBadUUID . parseLog Just
|
||||
|
||||
{- Temporarily here to fix badly formatted uuid logs generated by
|
||||
- versions 3.20111105 and 3.20111025.
|
||||
|
@ -68,19 +63,20 @@ fixBadUUID = M.fromList . map fixup . M.toList
|
|||
isuuid s = length s == 36 && length (splitc '-' s) == 5
|
||||
|
||||
{- The map is cached for speed. -}
|
||||
uuidMap :: Annex UUIDMap
|
||||
uuidMap = maybe uuidMapLoad return =<< Annex.getState Annex.uuidmap
|
||||
uuidDescMap :: Annex UUIDDescMap
|
||||
uuidDescMap = maybe uuidDescMapLoad return =<< Annex.getState Annex.uuiddescmap
|
||||
|
||||
{- Read the uuidLog into a simple Map.
|
||||
-
|
||||
- The UUID of the current repository is included explicitly, since
|
||||
- it may not have been described and so otherwise would not appear. -}
|
||||
uuidMapLoad :: Annex UUIDMap
|
||||
uuidMapLoad = do
|
||||
m <- (simpleMap . parseLog Just) <$> Annex.Branch.get uuidLog
|
||||
- it may not have been described and otherwise would not appear. -}
|
||||
uuidDescMapLoad :: Annex UUIDDescMap
|
||||
uuidDescMapLoad = do
|
||||
m <- (simpleMap . parseLog (Just . UUIDDesc . encodeBS))
|
||||
<$> Annex.Branch.get uuidLog
|
||||
u <- Annex.UUID.getUUID
|
||||
let m' = M.insertWith preferold u "" m
|
||||
Annex.changeState $ \s -> s { Annex.uuidmap = Just m' }
|
||||
let m' = M.insertWith preferold u mempty m
|
||||
Annex.changeState $ \s -> s { Annex.uuiddescmap = Just m' }
|
||||
return m'
|
||||
where
|
||||
preferold = flip const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue