aboutsummaryrefslogtreecommitdiff
path: root/Annex/UUID.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-01-20 16:55:06 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-01-20 16:55:06 -0400
commit9bb68caba5cf32009f35945e819fba877ec0f438 (patch)
tree27d9cc159d195374fa95424f186d9ad9c732d514 /Annex/UUID.hs
parent10c579282b4f0acc7f26d8084916f7d538a89bd8 (diff)
optimise getUUID
This avoids a Map lookup each time it's called, instead the GitConfig field lazily looks it up once and then caches.
Diffstat (limited to 'Annex/UUID.hs')
-rw-r--r--Annex/UUID.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/Annex/UUID.hs b/Annex/UUID.hs
index 69d4ab6c4..1e80d6fe1 100644
--- a/Annex/UUID.hs
+++ b/Annex/UUID.hs
@@ -6,7 +6,7 @@
- UUIDs of remotes are cached in git config, using keys named
- remote.<name>.annex-uuid
-
- - Copyright 2010-2013 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -29,6 +29,7 @@ module Annex.UUID (
) where
import Annex.Common
+import qualified Annex
import qualified Git
import qualified Git.Config
import Config
@@ -58,9 +59,10 @@ gCryptNameSpace = U5.generateNamed U5.namespaceURL $
{- Get current repository's UUID. -}
getUUID :: Annex UUID
-getUUID = getRepoUUID =<< gitRepo
+getUUID = annexUUID <$> Annex.getGitConfig
-{- Looks up a repo's UUID, caching it in .git/config if it's not already. -}
+{- Looks up a remote repo's UUID, caching it in .git/config if
+ - it's not already. -}
getRepoUUID :: Git.Repo -> Annex UUID
getRepoUUID r = do
c <- toUUID <$> getConfig cachekey ""
@@ -78,7 +80,9 @@ getRepoUUID r = do
cachekey = remoteConfig r "uuid"
removeRepoUUID :: Annex ()
-removeRepoUUID = unsetConfig configkey
+removeRepoUUID = do
+ unsetConfig configkey
+ storeUUID NoUUID
getUncachedUUID :: Git.Repo -> UUID
getUncachedUUID = toUUID . Git.Config.get key ""
@@ -98,7 +102,9 @@ prepUUID = whenM ((==) NoUUID <$> getUUID) $
storeUUID =<< liftIO genUUID
storeUUID :: UUID -> Annex ()
-storeUUID = storeUUIDIn configkey
+storeUUID u = do
+ Annex.changeGitConfig $ \c -> c { annexUUID = u }
+ storeUUIDIn configkey u
storeUUIDIn :: ConfigKey -> UUID -> Annex ()
storeUUIDIn configfield = setConfig configfield . fromUUID