From ebbd24e5ed6bbb41305d8105d7fac355dcf15bbc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 19 May 2012 10:51:22 -0400 Subject: more worktree improvements Avoid more expensive code path when no core.worktree is configured. Don't change worktree when reading config if one is already set. This could happen if GIT_CORE_WORKTREE is set, and the repo also has core.worktree, and the config is reread. Now GIT_CORE_WORKTREE will prevail. --- Git/Config.hs | 26 ++++++++++++++------------ Git/CurrentRepo.hs | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Git/Config.hs b/Git/Config.hs index 38e1ca4be..dab1cdf5e 100644 --- a/Git/Config.hs +++ b/Git/Config.hs @@ -78,19 +78,15 @@ store s repo = do - based on the core.bare and core.worktree settings. -} updateLocation :: Repo -> Repo -updateLocation r = go $ location r +updateLocation r@(Repo { location = LocalUnknown d }) + | isBare r = newloc $ Local d Nothing + | otherwise = newloc $ Local (d ".git") (Just d) where - go (LocalUnknown d) - | isbare = ret $ Local d Nothing - | otherwise = ret $ Local (d ".git") (Just d) - go l@(Local {}) = ret l - go _ = r - isbare = fromMaybe False $ isTrue =<< getMaybe "core.bare" r - ret l = r { location = l' } - where - l' = maybe l (setworktree l) $ - getMaybe "core.worktree" r - setworktree l t = l { worktree = Just t } + newloc l = r { location = getworktree l } + getworktree l = case workTree r of + Nothing -> l + wt -> l { worktree = wt } +updateLocation r = r {- Parses git config --list or git config --null --list output into a - config map. -} @@ -114,3 +110,9 @@ isTrue s | otherwise = Nothing where s' = map toLower s + +isBare :: Repo -> Bool +isBare r = fromMaybe False $ isTrue =<< getMaybe "core.bare" r + +workTree :: Repo -> Maybe FilePath +workTree = getMaybe "core.worktree" diff --git a/Git/CurrentRepo.hs b/Git/CurrentRepo.hs index a40b412f5..de11ce217 100644 --- a/Git/CurrentRepo.hs +++ b/Git/CurrentRepo.hs @@ -31,7 +31,7 @@ get :: IO Repo get = do gd <- pathenv "GIT_DIR" r <- configure gd =<< maybe fromCwd fromPath gd - wt <- maybe (worktree $ location r) Just <$> pathenv "GIT_WORK_TREE" + wt <- maybe (Git.Config.workTree r) Just <$> pathenv "GIT_WORK_TREE" case wt of Nothing -> return r Just d -> do -- cgit v1.2.3