add a UUID type
Should have done this a long time ago.
This commit is contained in:
parent
b08f7c428b
commit
63a292324d
18 changed files with 67 additions and 55 deletions
|
@ -29,16 +29,15 @@ import Logs.Presence
|
|||
|
||||
{- Log a change in the presence of a key's value in a repository. -}
|
||||
logChange :: Git.Repo -> Key -> UUID -> LogStatus -> Annex ()
|
||||
logChange repo key u s
|
||||
| null u = error $
|
||||
"unknown UUID for " ++ Git.repoDescribe repo ++
|
||||
" (have you run git annex init there?)"
|
||||
| otherwise = addLog (logFile key) =<< logNow s u
|
||||
logChange _ key (UUID u) s = addLog (logFile key) =<< logNow s u
|
||||
logChange repo _ NoUUID _ = error $
|
||||
"unknown UUID for " ++ Git.repoDescribe repo ++
|
||||
" (have you run git annex init there?)"
|
||||
|
||||
{- Returns a list of repository UUIDs that, according to the log, have
|
||||
- the value of a key. -}
|
||||
keyLocations :: Key -> Annex [UUID]
|
||||
keyLocations = currentLog . logFile
|
||||
keyLocations key = map read <$> (currentLog . logFile) key
|
||||
|
||||
{- Finds all keys that have location log information.
|
||||
- (There may be duplicate keys in the list.) -}
|
||||
|
|
|
@ -53,13 +53,12 @@ parseTrust s
|
|||
|
||||
{- Changes the trust level for a uuid in the trustLog. -}
|
||||
trustSet :: UUID -> TrustLevel -> Annex ()
|
||||
trustSet uuid level = do
|
||||
when (null uuid) $
|
||||
error "unknown UUID; cannot modify trust level"
|
||||
trustSet uuid@(UUID _) level = do
|
||||
ts <- liftIO $ getPOSIXTime
|
||||
Annex.Branch.change trustLog $
|
||||
showLog show . changeLog ts uuid level . parseLog parseTrust
|
||||
Annex.changeState $ \s -> s { Annex.trustmap = Nothing }
|
||||
trustSet NoUUID _ = error "unknown UUID; cannot modify trust level"
|
||||
|
||||
{- Partitions a list of UUIDs to those matching a TrustLevel and not. -}
|
||||
trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])
|
||||
|
|
|
@ -50,9 +50,9 @@ showLog :: (a -> String) -> Log a -> String
|
|||
showLog shower = unlines . map showpair . M.toList
|
||||
where
|
||||
showpair (k, LogEntry (Date p) v) =
|
||||
unwords [k, shower v, tskey ++ show p]
|
||||
unwords [show k, shower v, tskey ++ show p]
|
||||
showpair (k, LogEntry Unknown v) =
|
||||
unwords [k, shower v]
|
||||
unwords [show k, shower v]
|
||||
|
||||
parseLog :: (String -> Maybe a) -> String -> Log a
|
||||
parseLog parser = M.fromListWith best . catMaybes . map pair . lines
|
||||
|
@ -61,7 +61,7 @@ parseLog parser = M.fromListWith best . catMaybes . map pair . lines
|
|||
| null ws = Nothing
|
||||
| otherwise = case parser $ unwords info of
|
||||
Nothing -> Nothing
|
||||
Just v -> Just (u, LogEntry c v)
|
||||
Just v -> Just (read u, LogEntry c v)
|
||||
where
|
||||
ws = words line
|
||||
u = head ws
|
||||
|
@ -103,8 +103,8 @@ prop_TimeStamp_sane = Unknown < Date 1
|
|||
prop_addLog_sane :: Bool
|
||||
prop_addLog_sane = newWins && newestWins
|
||||
where
|
||||
newWins = addLog "foo" (LogEntry (Date 1) "new") l == l2
|
||||
newestWins = addLog "foo" (LogEntry (Date 1) "newest") l2 /= l2
|
||||
newWins = addLog (UUID "foo") (LogEntry (Date 1) "new") l == l2
|
||||
newestWins = addLog (UUID "foo") (LogEntry (Date 1) "newest") l2 /= l2
|
||||
|
||||
l = M.fromList [("foo", LogEntry (Date 0) "old")]
|
||||
l2 = M.fromList [("foo", LogEntry (Date 1) "new")]
|
||||
l = M.fromList [(UUID "foo", LogEntry (Date 0) "old")]
|
||||
l2 = M.fromList [(UUID "foo", LogEntry (Date 1) "new")]
|
||||
|
|
|
@ -21,7 +21,7 @@ type URLString = String
|
|||
|
||||
-- Dummy uuid for the whole web. Do not alter.
|
||||
webUUID :: UUID
|
||||
webUUID = "00000000-0000-0000-0000-000000000001"
|
||||
webUUID = UUID "00000000-0000-0000-0000-000000000001"
|
||||
|
||||
{- The urls for a key are stored in remote/web/hash/key.log
|
||||
- in the git-annex branch. -}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue