reorder repo parameters last
Many functions took the repo as their first parameter. Changing it consistently to be the last parameter allows doing some useful things with currying, that reduce boilerplate. In particular, g <- gitRepo is almost never needed now, instead use inRepo to run an IO action in the repo, and fromRepo to get a value from the repo. This also provides more opportunities to use monadic and applicative combinators.
This commit is contained in:
parent
2ff8915365
commit
bf460a0a98
46 changed files with 338 additions and 390 deletions
|
@ -45,23 +45,23 @@ getUUID = getRepoUUID =<< gitRepo
|
|||
{- Looks up a repo's UUID. May return "" if none is known. -}
|
||||
getRepoUUID :: Git.Repo -> Annex UUID
|
||||
getRepoUUID r = do
|
||||
g <- gitRepo
|
||||
|
||||
let c = cached g
|
||||
c <- fromRepo cached
|
||||
let u = getUncachedUUID r
|
||||
|
||||
if c /= u && u /= NoUUID
|
||||
then do
|
||||
updatecache g u
|
||||
updatecache u
|
||||
return u
|
||||
else return c
|
||||
where
|
||||
cached g = toUUID $ Git.configGet g cachekey ""
|
||||
updatecache g u = when (g /= r) $ storeUUID cachekey u
|
||||
cached g = toUUID $ Git.configGet cachekey "" g
|
||||
updatecache u = do
|
||||
g <- gitRepo
|
||||
when (g /= r) $ storeUUID cachekey u
|
||||
cachekey = "remote." ++ fromMaybe "" (Git.repoRemoteName r) ++ ".annex-uuid"
|
||||
|
||||
getUncachedUUID :: Git.Repo -> UUID
|
||||
getUncachedUUID r = toUUID $ Git.configGet r configkey ""
|
||||
getUncachedUUID = toUUID . Git.configGet configkey ""
|
||||
|
||||
{- Make sure that the repo has an annex.uuid setting. -}
|
||||
prepUUID :: Annex ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue