diff options
author | Joey Hess <joey@kitenet.net> | 2012-05-19 10:51:22 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-05-19 11:08:50 -0400 |
commit | ebbd24e5ed6bbb41305d8105d7fac355dcf15bbc (patch) | |
tree | b97c41c31ceab8ccf89ed1cf20d86915b4270283 | |
parent | 9d9814477601217c8d39d75cc03e27ee4d734de3 (diff) |
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.
-rw-r--r-- | Git/Config.hs | 26 | ||||
-rw-r--r-- | 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 |