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.
This commit is contained in:
Joey Hess 2012-05-19 10:51:22 -04:00
parent 9d98144776
commit ebbd24e5ed
2 changed files with 15 additions and 13 deletions

View file

@ -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"

View file

@ -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