Clean up handling of git directory and git worktree.

Baked into the code was an assumption that a repository's git directory
could be determined by adding ".git" to its work tree (or nothing for bare
repos). That fails when core.worktree, or GIT_DIR and GIT_WORK_TREE are
used to separate the two.

This was attacked at the type level, by storing the gitdir and worktree
separately, so Nothing for the worktree means a bare repo.

A complication arose because we don't learn where a repository is bare
until its configuration is read. So another Location type handles
repositories that have not had their config read yet. I am not entirely
happy with this being a Location type, rather than representing them
entirely separate from the Git type. The new code is not worse than the
old, but better types could enforce more safety.

Added support for core.worktree. Overriding it with -c isn't supported
because it's not really clear what to do if a git repo's config is read, is
not bare, and is then overridden to bare. What is the right git directory
in this case? I will worry about this if/when someone has a use case for
overriding core.worktree with -c. (See Git.Config.updateLocation)

Also removed and renamed some functions like gitDir and workTree that
misused git's terminology.

One minor regression is known: git annex add in a bare repository does not
print a nice error message, but runs git ls-files in a way that fails
earlier with a less nice error message. This is because before --work-tree
was always passed to git commands, even in a bare repo, while now it's not.
This commit is contained in:
Joey Hess 2012-05-18 16:38:26 -04:00
parent a2be4265bf
commit bb4f31a0ee
21 changed files with 144 additions and 104 deletions

View file

@ -34,6 +34,7 @@ import Common.Annex
import Logs.Location import Logs.Location
import Annex.UUID import Annex.UUID
import qualified Git import qualified Git
import qualified Git.Config
import qualified Annex import qualified Annex
import qualified Annex.Queue import qualified Annex.Queue
import qualified Annex.Branch import qualified Annex.Branch
@ -303,7 +304,7 @@ saveState oneshot = doSideAction $ do
ifM alwayscommit ifM alwayscommit
( Annex.Branch.commit "update" , Annex.Branch.stage) ( Annex.Branch.commit "update" , Annex.Branch.stage)
where where
alwayscommit = fromMaybe True . Git.configTrue alwayscommit = fromMaybe True . Git.Config.isTrue
<$> getConfig (annexConfig "alwayscommit") "" <$> getConfig (annexConfig "alwayscommit") ""
{- Downloads content from any of a list of urls. -} {- Downloads content from any of a list of urls. -}

View file

@ -14,7 +14,7 @@ import qualified Data.Map as M
import Common.Annex import Common.Annex
import Annex.LockPool import Annex.LockPool
import qualified Git import qualified Git.Config
import Config import Config
import qualified Build.SysConfig as SysConfig import qualified Build.SysConfig as SysConfig
import Annex.Perms import Annex.Perms
@ -47,7 +47,7 @@ sshInfo (host, port) = ifM caching
) )
where where
caching = fromMaybe SysConfig.sshconnectioncaching caching = fromMaybe SysConfig.sshconnectioncaching
. Git.configTrue . Git.Config.isTrue
<$> getConfig (annexConfig "sshcaching") "" <$> getConfig (annexConfig "sshcaching") ""
cacheParams :: FilePath -> [CommandParam] cacheParams :: FilePath -> [CommandParam]

View file

@ -133,7 +133,7 @@ compareChanges format changes = concatMap diff $ zip changes (drop 1 changes)
- *lot* for newish files. -} - *lot* for newish files. -}
getLog :: Key -> [CommandParam] -> Annex [String] getLog :: Key -> [CommandParam] -> Annex [String]
getLog key os = do getLog key os = do
top <- fromRepo Git.workTree top <- fromRepo Git.repoPath
p <- liftIO $ relPathCwdToFile top p <- liftIO $ relPathCwdToFile top
let logfile = p </> Logs.Location.logFile key let logfile = p </> Logs.Location.logFile key
inRepo $ pipeNullSplit $ inRepo $ pipeNullSplit $

View file

@ -156,14 +156,14 @@ absRepo :: Git.Repo -> Git.Repo -> Annex Git.Repo
absRepo reference r absRepo reference r
| Git.repoIsUrl reference = return $ Git.Construct.localToUrl reference r | Git.repoIsUrl reference = return $ Git.Construct.localToUrl reference r
| Git.repoIsUrl r = return r | Git.repoIsUrl r = return r
| otherwise = liftIO $ Git.Construct.fromAbsPath =<< absPath (Git.workTree r) | otherwise = liftIO $ Git.Construct.fromAbsPath =<< absPath (Git.repoPath r)
{- Checks if two repos are the same. -} {- Checks if two repos are the same. -}
same :: Git.Repo -> Git.Repo -> Bool same :: Git.Repo -> Git.Repo -> Bool
same a b same a b
| both Git.repoIsSsh = matching Git.Url.authority && matching Git.workTree | both Git.repoIsSsh = matching Git.Url.authority && matching Git.repoPath
| both Git.repoIsUrl && neither Git.repoIsSsh = matching show | both Git.repoIsUrl && neither Git.repoIsSsh = matching show
| neither Git.repoIsSsh = matching Git.workTree | neither Git.repoIsSsh = matching Git.repoPath
| otherwise = False | otherwise = False
where where
@ -210,7 +210,7 @@ tryScan r
where where
sshcmd = cddir ++ " && " ++ sshcmd = cddir ++ " && " ++
"git config --null --list" "git config --null --list"
dir = Git.workTree r dir = Git.repoPath r
cddir cddir
| "/~" `isPrefixOf` dir = | "/~" `isPrefixOf` dir =
let (userhome, reldir) = span (/= '/') (drop 1 dir) let (userhome, reldir) = span (/= '/') (drop 1 dir)

View file

@ -231,7 +231,7 @@ withKeysReferenced' :: v -> (Key -> v -> Annex v) -> Annex v
withKeysReferenced' initial a = go initial =<< files withKeysReferenced' initial a = go initial =<< files
where where
files = do files = do
top <- fromRepo Git.workTree top <- fromRepo Git.repoPath
inRepo $ LsFiles.inRepo [top] inRepo $ LsFiles.inRepo [top]
go v [] = return v go v [] = return v
go v (f:fs) = do go v (f:fs) = do

View file

@ -84,7 +84,7 @@ prop_cost_sane = False `notElem`
{- Checks if a repo should be ignored. -} {- Checks if a repo should be ignored. -}
repoNotIgnored :: Git.Repo -> Annex Bool repoNotIgnored :: Git.Repo -> Annex Bool
repoNotIgnored r = not . fromMaybe False . Git.configTrue repoNotIgnored r = not . fromMaybe False . Git.Config.isTrue
<$> getRemoteConfig r "ignore" "" <$> getRemoteConfig r "ignore" ""
{- If a value is specified, it is used; otherwise the default is looked up {- If a value is specified, it is used; otherwise the default is looked up

77
Git.hs
View file

@ -3,7 +3,7 @@
- This is written to be completely independant of git-annex and should be - This is written to be completely independant of git-annex and should be
- suitable for other uses. - suitable for other uses.
- -
- Copyright 2010, 2011 Joey Hess <joey@kitenet.net> - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
- -
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
@ -17,19 +17,17 @@ module Git (
repoIsUrl, repoIsUrl,
repoIsSsh, repoIsSsh,
repoIsHttp, repoIsHttp,
repoIsLocal,
repoIsLocalBare, repoIsLocalBare,
repoDescribe, repoDescribe,
repoLocation, repoLocation,
workTree, repoPath,
gitDir, localGitDir,
configTrue,
attributes, attributes,
hookPath, hookPath,
assertLocal, assertLocal,
) where ) where
import qualified Data.Map as M
import Data.Char
import Network.URI (uriPath, uriScheme, unEscapeString) import Network.URI (uriPath, uriScheme, unEscapeString)
import System.Posix.Files import System.Posix.Files
@ -41,15 +39,34 @@ import Utility.FileMode
repoDescribe :: Repo -> String repoDescribe :: Repo -> String
repoDescribe Repo { remoteName = Just name } = name repoDescribe Repo { remoteName = Just name } = name
repoDescribe Repo { location = Url url } = show url repoDescribe Repo { location = Url url } = show url
repoDescribe Repo { location = Dir dir } = dir repoDescribe Repo { location = Local { worktree = Just dir } } = dir
repoDescribe Repo { location = Local { gitdir = dir } } = dir
repoDescribe Repo { location = LocalUnknown dir } = dir
repoDescribe Repo { location = Unknown } = "UNKNOWN" repoDescribe Repo { location = Unknown } = "UNKNOWN"
{- Location of the repo, either as a path or url. -} {- Location of the repo, either as a path or url. -}
repoLocation :: Repo -> String repoLocation :: Repo -> String
repoLocation Repo { location = Url url } = show url repoLocation Repo { location = Url url } = show url
repoLocation Repo { location = Dir dir } = dir repoLocation Repo { location = Local { worktree = Just dir } } = dir
repoLocation Repo { location = Local { gitdir = dir } } = dir
repoLocation Repo { location = LocalUnknown dir } = dir
repoLocation Repo { location = Unknown } = undefined repoLocation Repo { location = Unknown } = undefined
{- Path to a repository. For non-bare, this is the worktree, for bare,
- it's the gitdir, and for URL repositories, is the path on the remote
- host. -}
repoPath :: Repo -> FilePath
repoPath Repo { location = Url u } = unEscapeString $ uriPath u
repoPath Repo { location = Local { worktree = Just d } } = d
repoPath Repo { location = Local { gitdir = d } } = d
repoPath Repo { location = LocalUnknown dir } = dir
repoPath Repo { location = Unknown } = undefined
{- Path to a local repository's .git directory. -}
localGitDir :: Repo -> FilePath
localGitDir Repo { location = Local { gitdir = d } } = d
localGitDir _ = undefined
{- Some code needs to vary between URL and normal repos, {- Some code needs to vary between URL and normal repos,
- or bare and non-bare, these functions help with that. -} - or bare and non-bare, these functions help with that. -}
repoIsUrl :: Repo -> Bool repoIsUrl :: Repo -> Bool
@ -74,11 +91,12 @@ repoIsHttp Repo { location = Url url }
| otherwise = False | otherwise = False
repoIsHttp _ = False repoIsHttp _ = False
configAvail ::Repo -> Bool repoIsLocal :: Repo -> Bool
configAvail Repo { config = c } = c /= M.empty repoIsLocal Repo { location = Local { } } = True
repoIsLocal _ = False
repoIsLocalBare :: Repo -> Bool repoIsLocalBare :: Repo -> Bool
repoIsLocalBare r@(Repo { location = Dir _ }) = configAvail r && configBare r repoIsLocalBare Repo { location = Local { worktree = Nothing } } = True
repoIsLocalBare _ = False repoIsLocalBare _ = False
assertLocal :: Repo -> a -> a assertLocal :: Repo -> a -> a
@ -90,49 +108,18 @@ assertLocal repo action
] ]
| otherwise = action | otherwise = action
configBare :: Repo -> Bool
configBare repo = maybe unknown (fromMaybe False . configTrue) $
M.lookup "core.bare" $ config repo
where
unknown = error $ "it is not known if git repo " ++
repoDescribe repo ++
" is a bare repository; config not read"
{- Path to a repository's gitattributes file. -} {- Path to a repository's gitattributes file. -}
attributes :: Repo -> FilePath attributes :: Repo -> FilePath
attributes repo attributes repo
| configBare repo = workTree repo ++ "/info/.gitattributes" | repoIsLocalBare repo = repoPath repo ++ "/info/.gitattributes"
| otherwise = workTree repo ++ "/.gitattributes" | otherwise = repoPath repo ++ "/.gitattributes"
{- Path to a repository's .git directory. -}
gitDir :: Repo -> FilePath
gitDir repo
| configBare repo = workTree repo
| otherwise = workTree repo </> ".git"
{- Path to a given hook script in a repository, only if the hook exists {- Path to a given hook script in a repository, only if the hook exists
- and is executable. -} - and is executable. -}
hookPath :: String -> Repo -> IO (Maybe FilePath) hookPath :: String -> Repo -> IO (Maybe FilePath)
hookPath script repo = do hookPath script repo = do
let hook = gitDir repo </> "hooks" </> script let hook = localGitDir repo </> "hooks" </> script
ifM (catchBoolIO $ isexecutable hook) ifM (catchBoolIO $ isexecutable hook)
( return $ Just hook , return Nothing ) ( return $ Just hook , return Nothing )
where where
isexecutable f = isExecutable . fileMode <$> getFileStatus f isexecutable f = isExecutable . fileMode <$> getFileStatus f
{- Path to a repository's --work-tree, that is, its top.
-
- Note that for URL repositories, this is the path on the remote host. -}
workTree :: Repo -> FilePath
workTree Repo { location = Url u } = unEscapeString $ uriPath u
workTree Repo { location = Dir d } = d
workTree Repo { location = Unknown } = undefined
{- Checks if a string from git config is a true value. -}
configTrue :: String -> Maybe Bool
configTrue s
| s' == "true" = Just True
| s' == "false" = Just False
| otherwise = Nothing
where
s' = map toLower s

View file

@ -1,6 +1,6 @@
{- running git commands {- running git commands
- -
- Copyright 2010, 2011 Joey Hess <joey@kitenet.net> - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
- -
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
@ -18,11 +18,12 @@ import Git.Types
{- Constructs a git command line operating on the specified repo. -} {- Constructs a git command line operating on the specified repo. -}
gitCommandLine :: [CommandParam] -> Repo -> [CommandParam] gitCommandLine :: [CommandParam] -> Repo -> [CommandParam]
gitCommandLine params repo@(Repo { location = Dir _ } ) = gitCommandLine params Repo { location = l@(Local _ _ ) } = setdir : settree ++ params
-- force use of specified repo via --git-dir and --work-tree where
[ Param ("--git-dir=" ++ gitDir repo) setdir = Param $ "--git-dir=" ++ gitdir l
, Param ("--work-tree=" ++ workTree repo) settree = case worktree l of
] ++ params Nothing -> []
Just t -> [Param $ "--work-tree=" ++ t]
gitCommandLine _ repo = assertLocal repo $ error "internal" gitCommandLine _ repo = assertLocal repo $ error "internal"
{- Runs git in the specified repo. -} {- Runs git in the specified repo. -}

View file

@ -1,15 +1,14 @@
{- git repository configuration handling {- git repository configuration handling
- -
- Copyright 2010,2011 Joey Hess <joey@kitenet.net> - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
- -
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
module Git.Config where module Git.Config where
import System.Posix.Directory
import Control.Exception (bracket_)
import qualified Data.Map as M import qualified Data.Map as M
import Data.Char
import Common import Common
import Git import Git
@ -30,17 +29,14 @@ getMaybe key repo = M.lookup key (config repo)
{- Runs git config and populates a repo with its config. -} {- Runs git config and populates a repo with its config. -}
read :: Repo -> IO Repo read :: Repo -> IO Repo
read repo@(Repo { location = Dir d }) = bracketcd d $ read repo@(Repo { location = Local { gitdir = d } }) = read' repo d
read repo@(Repo { location = LocalUnknown d }) = read' repo d
read r = assertLocal r $ error "internal"
{- Cannot use pipeRead because it relies on the config having {- Cannot use pipeRead because it relies on the config having
been already read. Instead, chdir to the repo. -} been already read. Instead, chdir to the repo. -}
read' :: Repo -> FilePath -> IO Repo
read' repo d = bracketCd d $
pOpen ReadFromPipe "git" ["config", "--null", "--list"] $ hRead repo pOpen ReadFromPipe "git" ["config", "--null", "--list"] $ hRead repo
where
bracketcd to a = bracketcd' to a =<< getCurrentDirectory
bracketcd' to a cwd
| dirContains to cwd = a
| otherwise = bracket_ (changeWorkingDirectory to) (changeWorkingDirectory cwd) a
read r = assertLocal r $
error $ "internal error; trying to read config of " ++ show r
{- Reads git config from a handle and populates a repo with it. -} {- Reads git config from a handle and populates a repo with it. -}
hRead :: Repo -> Handle -> IO Repo hRead :: Repo -> Handle -> IO Repo
@ -48,19 +44,42 @@ hRead repo h = do
val <- hGetContentsStrict h val <- hGetContentsStrict h
store val repo store val repo
{- Stores a git config into a repo, returning the new version of the repo. {- Stores a git config into a Repo, returning the new version of the Repo.
- The git config may be multiple lines, or a single line. Config settings - The git config may be multiple lines, or a single line.
- can be updated inrementally. -} - Config settings can be updated incrementally.
-}
store :: String -> Repo -> IO Repo store :: String -> Repo -> IO Repo
store s repo = do store s repo = do
let c = parse s let c = parse s
let repo' = repo let repo' = updateLocation $ repo
{ config = (M.map Prelude.head c) `M.union` config repo { config = (M.map Prelude.head c) `M.union` config repo
, fullconfig = M.unionWith (++) c (fullconfig repo) , fullconfig = M.unionWith (++) c (fullconfig repo)
} }
print repo'
rs <- Git.Construct.fromRemotes repo' rs <- Git.Construct.fromRemotes repo'
return $ repo' { remotes = rs } return $ repo' { remotes = rs }
{- Updates the location of a repo, based on its configuration.
-
- Git.Construct makes LocalUknown repos, of which only a directory is
- known. Once the config is read, this can be fixed up to a Local repo,
- based on the core.bare and core.worktree settings.
-}
updateLocation :: Repo -> Repo
updateLocation r = go $ location r
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 }
{- Parses git config --list or git config --null --list output into a {- Parses git config --list or git config --null --list output into a
- config map. -} - config map. -}
parse :: String -> M.Map String [String] parse :: String -> M.Map String [String]
@ -74,3 +93,12 @@ parse s
ls = lines s ls = lines s
sep c = M.fromListWith (++) . map (\(k,v) -> (k, [v])) . sep c = M.fromListWith (++) . map (\(k,v) -> (k, [v])) .
map (separate (== c)) map (separate (== c))
{- Checks if a string from git config is a true value. -}
isTrue :: String -> Maybe Bool
isTrue s
| s' == "true" = Just True
| s' == "false" = Just False
| otherwise = Nothing
where
s' = map toLower s

View file

@ -1,6 +1,6 @@
{- Construction of Git Repo objects {- Construction of Git Repo objects
- -
- Copyright 2010,2011 Joey Hess <joey@kitenet.net> - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
- -
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
@ -58,7 +58,7 @@ fromCurrent = do
fromCwd :: IO Repo fromCwd :: IO Repo
fromCwd = getCurrentDirectory >>= seekUp isRepoTop >>= maybe norepo makerepo fromCwd = getCurrentDirectory >>= seekUp isRepoTop >>= maybe norepo makerepo
where where
makerepo = newFrom . Dir makerepo = newFrom . LocalUnknown
norepo = error "Not in a git repository." norepo = error "Not in a git repository."
{- Local Repo constructor, accepts a relative or absolute path. -} {- Local Repo constructor, accepts a relative or absolute path. -}
@ -74,7 +74,7 @@ fromAbsPath dir
| otherwise = | otherwise =
error $ "internal error, " ++ dir ++ " is not absolute" error $ "internal error, " ++ dir ++ " is not absolute"
where where
ret = newFrom . Dir ret = newFrom . LocalUnknown
{- Git always looks for "dir.git" in preference to {- Git always looks for "dir.git" in preference to
- to "dir", even if dir ends in a "/". -} - to "dir", even if dir ends in a "/". -}
canondir = dropTrailingPathSeparator dir canondir = dropTrailingPathSeparator dir
@ -122,7 +122,7 @@ localToUrl reference r
absurl = absurl =
Url.scheme reference ++ "//" ++ Url.scheme reference ++ "//" ++
Url.authority reference ++ Url.authority reference ++
workTree r repoPath r
{- Calculates a list of a repo's configured remotes, by parsing its config. -} {- Calculates a list of a repo's configured remotes, by parsing its config. -}
fromRemotes :: Repo -> IO [Repo] fromRemotes :: Repo -> IO [Repo]
@ -191,7 +191,7 @@ fromRemoteLocation s repo = gen $ calcloc s
fromRemotePath :: FilePath -> Repo -> IO Repo fromRemotePath :: FilePath -> Repo -> IO Repo
fromRemotePath dir repo = do fromRemotePath dir repo = do
dir' <- expandTilde dir dir' <- expandTilde dir
fromAbsPath $ workTree repo </> dir' fromAbsPath $ repoPath repo </> dir'
{- Git remotes can have a directory that is specified relative {- Git remotes can have a directory that is specified relative
- to the user's home directory, or that contains tilde expansions. - to the user's home directory, or that contains tilde expansions.

View file

@ -69,7 +69,7 @@ typeChanged' ps l repo = do
fs <- pipeNullSplit (prefix ++ ps ++ suffix) repo fs <- pipeNullSplit (prefix ++ ps ++ suffix) repo
-- git diff returns filenames relative to the top of the git repo; -- git diff returns filenames relative to the top of the git repo;
-- convert to filenames relative to the cwd, like git ls-files. -- convert to filenames relative to the cwd, like git ls-files.
let top = workTree repo let top = repoPath repo
cwd <- getCurrentDirectory cwd <- getCurrentDirectory
return $ map (\f -> relPathDirToFile cwd $ top </> f) fs return $ map (\f -> relPathDirToFile cwd $ top </> f) fs
where where

View file

@ -1,6 +1,6 @@
{- git data types {- git data types
- -
- Copyright 2010,2011 Joey Hess <joey@kitenet.net> - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
- -
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
@ -10,9 +10,21 @@ module Git.Types where
import Network.URI import Network.URI
import qualified Data.Map as M import qualified Data.Map as M
{- There are two types of repositories; those on local disk and those {- Support repositories on local disk, and repositories accessed via an URL.
- accessed via an URL. -} -
data RepoLocation = Dir FilePath | Url URI | Unknown - Repos on local disk have a git directory, and unless bare, a worktree.
-
- A local repo may not have had its config read yet, in which case all
- that's known about it is its path.
-
- Finally, an Unknown repository may be known to exist, but nothing
- else known about it.
-}
data RepoLocation
= Local { gitdir :: FilePath, worktree :: Maybe FilePath }
| LocalUnknown FilePath
| Url URI
| Unknown
deriving (Show, Eq) deriving (Show, Eq)
data Repo = Repo { data Repo = Repo {

View file

@ -72,7 +72,7 @@ unlessBare :: Annex () -> Annex ()
unlessBare = unlessM $ fromRepo Git.repoIsLocalBare unlessBare = unlessM $ fromRepo Git.repoIsLocalBare
preCommitHook :: Annex FilePath preCommitHook :: Annex FilePath
preCommitHook = (</>) <$> fromRepo Git.gitDir <*> pure "hooks/pre-commit" preCommitHook = (</>) <$> fromRepo Git.localGitDir <*> pure "hooks/pre-commit"
preCommitScript :: String preCommitScript :: String
preCommitScript = preCommitScript =

View file

@ -85,28 +85,24 @@ gitAnnexLocation key r
| Git.repoIsLocalBare r = | Git.repoIsLocalBare r =
{- Bare repositories default to hashDirLower for new {- Bare repositories default to hashDirLower for new
- content, as it's more portable. -} - content, as it's more portable. -}
check (map inrepo $ annexLocations key) check $ map inrepo $ annexLocations key
| otherwise = | otherwise =
{- Non-bare repositories only use hashDirMixed, so {- Non-bare repositories only use hashDirMixed, so
- don't need to do any work to check if the file is - don't need to do any work to check if the file is
- present. -} - present. -}
return $ inrepo ".git" </> annexLocation key hashDirMixed return $ inrepo $ annexLocation key hashDirMixed
where where
inrepo d = Git.workTree r </> d inrepo d = Git.localGitDir r </> d
check locs@(l:_) = fromMaybe l <$> firstM doesFileExist locs check locs@(l:_) = fromMaybe l <$> firstM doesFileExist locs
check [] = error "internal" check [] = error "internal"
{- The annex directory of a repository. -} {- The annex directory of a repository. -}
gitAnnexDir :: Git.Repo -> FilePath gitAnnexDir :: Git.Repo -> FilePath
gitAnnexDir r gitAnnexDir r = addTrailingPathSeparator $ Git.localGitDir r </> annexDir
| Git.repoIsLocalBare r = addTrailingPathSeparator $ Git.workTree r </> annexDir
| otherwise = addTrailingPathSeparator $ Git.workTree r </> ".git" </> annexDir
{- The part of the annex directory where file contents are stored. -} {- The part of the annex directory where file contents are stored. -}
gitAnnexObjectDir :: Git.Repo -> FilePath gitAnnexObjectDir :: Git.Repo -> FilePath
gitAnnexObjectDir r gitAnnexObjectDir r = addTrailingPathSeparator $ Git.localGitDir r </> objectDir
| Git.repoIsLocalBare r = addTrailingPathSeparator $ Git.workTree r </> objectDir
| otherwise = addTrailingPathSeparator $ Git.workTree r </> ".git" </> objectDir
{- .git/annex/tmp/ is used for temp files -} {- .git/annex/tmp/ is used for temp files -}
gitAnnexTmpDir :: Git.Repo -> FilePath gitAnnexTmpDir :: Git.Repo -> FilePath

View file

@ -184,7 +184,7 @@ storeBupUUID u buprepo = do
onBupRemote :: Git.Repo -> (FilePath -> [CommandParam] -> IO a) -> FilePath -> [CommandParam] -> Annex a onBupRemote :: Git.Repo -> (FilePath -> [CommandParam] -> IO a) -> FilePath -> [CommandParam] -> Annex a
onBupRemote r a command params = do onBupRemote r a command params = do
let dir = shellEscape (Git.workTree r) let dir = shellEscape (Git.repoPath r)
sshparams <- sshToRepo r [Param $ sshparams <- sshToRepo r [Param $
"cd " ++ dir ++ " && " ++ unwords (command : toCommand params)] "cd " ++ dir ++ " && " ++ unwords (command : toCommand params)]
liftIO $ a "ssh" sshparams liftIO $ a "ssh" sshparams

View file

@ -34,7 +34,7 @@ git_annex_shell r command params
return $ Just ("ssh", sshparams) return $ Just ("ssh", sshparams)
| otherwise = return Nothing | otherwise = return Nothing
where where
dir = Git.workTree r dir = Git.repoPath r
shellcmd = "git-annex-shell" shellcmd = "git-annex-shell"
shellopts = Param command : File dir : params shellopts = Param command : File dir : params
sshcmd uuid = unwords $ sshcmd uuid = unwords $

View file

@ -82,7 +82,7 @@ moveContent = do
updateSymlinks :: Annex () updateSymlinks :: Annex ()
updateSymlinks = do updateSymlinks = do
showAction "updating symlinks" showAction "updating symlinks"
top <- fromRepo Git.workTree top <- fromRepo Git.repoPath
files <- inRepo $ LsFiles.inRepo [top] files <- inRepo $ LsFiles.inRepo [top]
forM_ files fixlink forM_ files fixlink
where where
@ -236,4 +236,4 @@ stateDir :: FilePath
stateDir = addTrailingPathSeparator ".git-annex" stateDir = addTrailingPathSeparator ".git-annex"
gitStateDir :: Git.Repo -> FilePath gitStateDir :: Git.Repo -> FilePath
gitStateDir repo = addTrailingPathSeparator $ Git.workTree repo </> stateDir gitStateDir repo = addTrailingPathSeparator $ Git.repoPath repo </> stateDir

View file

@ -134,4 +134,4 @@ gitAttributesUnWrite repo = do
stateDir :: FilePath stateDir :: FilePath
stateDir = addTrailingPathSeparator ".git-annex" stateDir = addTrailingPathSeparator ".git-annex"
gitStateDir :: Git.Repo -> FilePath gitStateDir :: Git.Repo -> FilePath
gitStateDir repo = addTrailingPathSeparator $ Git.workTree repo </> stateDir gitStateDir repo = addTrailingPathSeparator $ Git.repoPath repo </> stateDir

View file

@ -15,11 +15,14 @@ import Control.Monad
import Control.Monad.IfElse import Control.Monad.IfElse
import System.FilePath import System.FilePath
import Control.Applicative import Control.Applicative
import Control.Exception (bracket_)
import System.Posix.Directory
import Utility.SafeCommand import Utility.SafeCommand
import Utility.TempFile import Utility.TempFile
import Utility.Exception import Utility.Exception
import Utility.Monad import Utility.Monad
import Utility.Path
{- Lists the contents of a directory. {- Lists the contents of a directory.
- Unlike getDirectoryContents, paths are not relative to the directory. -} - Unlike getDirectoryContents, paths are not relative to the directory. -}
@ -60,3 +63,14 @@ moveFile src dest = tryIO (rename src dest) >>= onrename
case r of case r of
(Left _) -> return False (Left _) -> return False
(Right s) -> return $ isDirectory s (Right s) -> return $ isDirectory s
{- Runs an action in another directory. -}
bracketCd :: FilePath -> IO a -> IO a
bracketCd dir a = go =<< getCurrentDirectory
where
go cwd
| dirContains dir cwd = a
| otherwise = bracket_
(changeWorkingDirectory dir)
(changeWorkingDirectory cwd)
a

1
debian/changelog vendored
View file

@ -2,6 +2,7 @@ git-annex (3.20120512) UNRELEASED; urgency=low
* Pass -a to cp even when it supports --reflink=auto, to preserve * Pass -a to cp even when it supports --reflink=auto, to preserve
permissions. permissions.
* Clean up handling of git directory and git worktree.
-- Joey Hess <joeyh@debian.org> Tue, 15 May 2012 14:17:49 -0400 -- Joey Hess <joeyh@debian.org> Tue, 15 May 2012 14:17:49 -0400

View file

@ -22,7 +22,7 @@ usage :: IO a
usage = error $ "bad parameters\n\n" ++ header usage = error $ "bad parameters\n\n" ++ header
tmpIndex :: Git.Repo -> FilePath tmpIndex :: Git.Repo -> FilePath
tmpIndex g = Git.gitDir g </> "index.git-union-merge" tmpIndex g = Git.localGitDir g </> "index.git-union-merge"
setup :: Git.Repo -> IO () setup :: Git.Repo -> IO ()
setup = cleanup -- idempotency setup = cleanup -- idempotency