From 9bb68caba5cf32009f35945e819fba877ec0f438 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 20 Jan 2016 16:55:06 -0400 Subject: optimise getUUID This avoids a Map lookup each time it's called, instead the GitConfig field lazily looks it up once and then caches. --- Annex/UUID.hs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'Annex/UUID.hs') 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..annex-uuid - - - Copyright 2010-2013 Joey Hess + - Copyright 2010-2016 Joey Hess - - 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 -- cgit v1.2.3