improve config reading when operating on remote on same host
Before the config was read each time onLocal was called, and entirely redundantly since it's read for same-host remotes on startup. Also a minor bug fix: When rsyncing to a same-host remote, use the rsync-options from the repository that the user ran git-annex in, not those of the receiving repository.
This commit is contained in:
parent
373cad993d
commit
c30366e95a
2 changed files with 17 additions and 10 deletions
1
Annex.hs
1
Annex.hs
|
@ -12,6 +12,7 @@ module Annex (
|
||||||
AnnexState(..),
|
AnnexState(..),
|
||||||
OutputType(..),
|
OutputType(..),
|
||||||
new,
|
new,
|
||||||
|
newState,
|
||||||
run,
|
run,
|
||||||
eval,
|
eval,
|
||||||
getState,
|
getState,
|
||||||
|
|
|
@ -57,7 +57,8 @@ gen r u _ = do
|
||||||
- cached UUID value. -}
|
- cached UUID value. -}
|
||||||
let cheap = not $ Git.repoIsUrl r
|
let cheap = not $ Git.repoIsUrl r
|
||||||
r' <- case (cheap, u) of
|
r' <- case (cheap, u) of
|
||||||
(True, _) -> tryGitConfigRead r
|
(True, _) -> do
|
||||||
|
tryGitConfigRead r
|
||||||
(False, "") -> tryGitConfigRead r
|
(False, "") -> tryGitConfigRead r
|
||||||
_ -> return r
|
_ -> return r
|
||||||
|
|
||||||
|
@ -147,8 +148,12 @@ inAnnex r key
|
||||||
- monad using that repository. -}
|
- monad using that repository. -}
|
||||||
onLocal :: Git.Repo -> Annex a -> IO a
|
onLocal :: Git.Repo -> Annex a -> IO a
|
||||||
onLocal r a = do
|
onLocal r a = do
|
||||||
annex <- Annex.new r
|
-- Avoid re-reading the repository's configuration if it was
|
||||||
Annex.eval annex $ do
|
-- already read.
|
||||||
|
state <- if (M.null $ Git.configMap r)
|
||||||
|
then Annex.new r
|
||||||
|
else return $ Annex.newState r
|
||||||
|
Annex.eval state $ do
|
||||||
-- No need to update the branch; its data is not used
|
-- No need to update the branch; its data is not used
|
||||||
-- for anything onLocal is used to do.
|
-- for anything onLocal is used to do.
|
||||||
Annex.Branch.disableUpdate
|
Annex.Branch.disableUpdate
|
||||||
|
@ -168,7 +173,9 @@ dropKey r key
|
||||||
{- Tries to copy a key's content from a remote's annex to a file. -}
|
{- Tries to copy a key's content from a remote's annex to a file. -}
|
||||||
copyFromRemote :: Git.Repo -> Key -> FilePath -> Annex Bool
|
copyFromRemote :: Git.Repo -> Key -> FilePath -> Annex Bool
|
||||||
copyFromRemote r key file
|
copyFromRemote r key file
|
||||||
| not $ Git.repoIsUrl r = rsyncOrCopyFile r (gitAnnexLocation r key) file
|
| not $ Git.repoIsUrl r = do
|
||||||
|
params <- rsyncParams r
|
||||||
|
rsyncOrCopyFile params (gitAnnexLocation r key) file
|
||||||
| Git.repoIsSsh r = rsyncHelper =<< rsyncParamsRemote r True key file
|
| Git.repoIsSsh r = rsyncHelper =<< rsyncParamsRemote r True key file
|
||||||
| Git.repoIsHttp r = liftIO $ Url.download (keyUrl r key) file
|
| Git.repoIsHttp r = liftIO $ Url.download (keyUrl r key) file
|
||||||
| otherwise = error "copying from non-ssh, non-http repo not supported"
|
| otherwise = error "copying from non-ssh, non-http repo not supported"
|
||||||
|
@ -179,9 +186,10 @@ copyToRemote r key
|
||||||
| not $ Git.repoIsUrl r = do
|
| not $ Git.repoIsUrl r = do
|
||||||
g <- gitRepo
|
g <- gitRepo
|
||||||
let keysrc = gitAnnexLocation g key
|
let keysrc = gitAnnexLocation g key
|
||||||
|
params <- rsyncParams r
|
||||||
-- run copy from perspective of remote
|
-- run copy from perspective of remote
|
||||||
liftIO $ onLocal r $ Annex.Content.getViaTmp key $
|
liftIO $ onLocal r $ Annex.Content.getViaTmp key $
|
||||||
rsyncOrCopyFile r keysrc
|
rsyncOrCopyFile params keysrc
|
||||||
| Git.repoIsSsh r = do
|
| Git.repoIsSsh r = do
|
||||||
g <- gitRepo
|
g <- gitRepo
|
||||||
let keysrc = gitAnnexLocation g key
|
let keysrc = gitAnnexLocation g key
|
||||||
|
@ -200,15 +208,13 @@ rsyncHelper p = do
|
||||||
|
|
||||||
{- Copys a file with rsync unless both locations are on the same
|
{- Copys a file with rsync unless both locations are on the same
|
||||||
- filesystem. Then cp could be faster. -}
|
- filesystem. Then cp could be faster. -}
|
||||||
rsyncOrCopyFile :: Git.Repo -> FilePath -> FilePath -> Annex Bool
|
rsyncOrCopyFile :: [CommandParam] -> FilePath -> FilePath -> Annex Bool
|
||||||
rsyncOrCopyFile r src dest = do
|
rsyncOrCopyFile rsyncparams src dest = do
|
||||||
ss <- liftIO $ getFileStatus $ parentDir src
|
ss <- liftIO $ getFileStatus $ parentDir src
|
||||||
ds <- liftIO $ getFileStatus $ parentDir dest
|
ds <- liftIO $ getFileStatus $ parentDir dest
|
||||||
if deviceID ss == deviceID ds
|
if deviceID ss == deviceID ds
|
||||||
then liftIO $ copyFileExternal src dest
|
then liftIO $ copyFileExternal src dest
|
||||||
else do
|
else rsyncHelper $ rsyncparams ++ [Param src, Param dest]
|
||||||
params <- rsyncParams r
|
|
||||||
rsyncHelper $ params ++ [Param src, Param dest]
|
|
||||||
|
|
||||||
{- Generates rsync parameters that ssh to the remote and asks it
|
{- Generates rsync parameters that ssh to the remote and asks it
|
||||||
- to either receive or send the key's content. -}
|
- to either receive or send the key's content. -}
|
||||||
|
|
Loading…
Add table
Reference in a new issue