Added remote.annex-scp-options and remote.annex-ssh-options.

This commit is contained in:
Joey Hess 2010-10-31 22:56:56 -04:00
parent e70812eca9
commit 0194394be6
3 changed files with 34 additions and 21 deletions

View file

@ -115,33 +115,28 @@ reposByCost l = do
-} -}
repoCost :: Git.Repo -> Annex Int repoCost :: Git.Repo -> Annex Int
repoCost r = do repoCost r = do
g <- Annex.gitRepo cost <- repoConfig r "annex-cost" ""
if (not $ null $ config g) if (not $ null cost)
then return $ read $ config g then return $ read cost
else if (Git.repoIsUrl r) else if (Git.repoIsUrl r)
then return 200 then return 200
else return 100 else return 100
where
config g = Git.configGet g configkey ""
configkey = "remote." ++ (Git.repoRemoteName r) ++ ".annex-cost"
{- Checks if a repo should be ignored, based either on annex-ignore {- Checks if a repo should be ignored, based either on annex-ignore
- setting, or on command-line options. Allows command-line to override - setting, or on command-line options. Allows command-line to override
- annex-ignore. -} - annex-ignore. -}
repoNotIgnored :: Git.Repo -> Annex Bool repoNotIgnored :: Git.Repo -> Annex Bool
repoNotIgnored r = do repoNotIgnored r = do
g <- Annex.gitRepo ignored <- repoConfig r "annex-ignore" "false"
fromName <- Annex.flagGet "fromrepository" fromName <- Annex.flagGet "fromrepository"
toName <- Annex.flagGet "torepository" toName <- Annex.flagGet "torepository"
let name = if (not $ null fromName) then fromName else toName let name = if (not $ null fromName) then fromName else toName
if (not $ null name) if (not $ null name)
then return $ match name then return $ match name
else return $ not $ ignored g else return $ not $ isIgnored ignored
where where
match name = name == Git.repoRemoteName r match name = name == Git.repoRemoteName r
ignored g = Git.configTrue $ config g isIgnored ignored = Git.configTrue ignored
config g = Git.configGet g configkey ""
configkey = "remote." ++ (Git.repoRemoteName r) ++ ".annex-ignore"
{- Returns the remote specified by --from or --to, may fail with error. -} {- Returns the remote specified by --from or --to, may fail with error. -}
commandLineRemote :: Annex Git.Repo commandLineRemote :: Annex Git.Repo
@ -195,8 +190,7 @@ copyFromRemote r key file = do
else error "copying from non-ssh repo not supported" else error "copying from non-ssh repo not supported"
where where
getlocal = liftIO $ boolSystem "cp" ["-a", keyloc, file] getlocal = liftIO $ boolSystem "cp" ["-a", keyloc, file]
getssh = do getssh = scp r [sshLocation r keyloc, file]
scp [sshLocation r keyloc, file]
keyloc = annexLocation r key keyloc = annexLocation r key
{- Tries to copy a key's content to a file on a remote. -} {- Tries to copy a key's content to a file on a remote. -}
@ -211,20 +205,23 @@ copyToRemote r key file = do
else error "copying to non-ssh repo not supported" else error "copying to non-ssh repo not supported"
where where
putlocal src = liftIO $ boolSystem "cp" ["-a", src, file] putlocal src = liftIO $ boolSystem "cp" ["-a", src, file]
putssh src = do putssh src = scp r [src, sshLocation r file]
scp [src, sshLocation r file]
sshLocation :: Git.Repo -> FilePath -> FilePath sshLocation :: Git.Repo -> FilePath -> FilePath
sshLocation r file = (Git.urlHost r) ++ ":" ++ shellEscape file sshLocation r file = (Git.urlHost r) ++ ":" ++ shellEscape file
scp :: [String] -> Annex Bool {- Runs scp against a specified remote. (Honors annex-scp-options.) -}
scp params = do scp :: Git.Repo -> [String] -> Annex Bool
scp r params = do
scpoptions <- repoConfig r "annex-scp-options" ""
Core.showProgress -- make way for scp progress bar Core.showProgress -- make way for scp progress bar
liftIO $ boolSystem "scp" ("-p":params) liftIO $ boolSystem "scp" $ "-p":(words scpoptions) ++ params
{- Runs a command in a remote. -} {- Runs a command in a remote, using ssh if necessary.
- (Honors annex-ssh-options.) -}
runCmd :: Git.Repo -> String -> [String] -> Annex Bool runCmd :: Git.Repo -> String -> [String] -> Annex Bool
runCmd r command params = do runCmd r command params = do
sshoptions <- repoConfig r "annex-ssh-options" ""
if (not $ Git.repoIsUrl r) if (not $ Git.repoIsUrl r)
then do then do
cwd <- liftIO $ getCurrentDirectory cwd <- liftIO $ getCurrentDirectory
@ -233,8 +230,18 @@ runCmd r command params = do
boolSystem command params boolSystem command params
else if (Git.repoIsSsh r) else if (Git.repoIsSsh r)
then do then do
liftIO $ boolSystem "ssh" [Git.urlHost r, liftIO $ boolSystem "ssh" $
"cd " ++ (shellEscape $ Git.workTree r) ++ (words sshoptions) ++
[Git.urlHost r, "cd " ++
(shellEscape $ Git.workTree r) ++
" && " ++ (shellEscape command) ++ " " ++ " && " ++ (shellEscape command) ++ " " ++
(unwords $ map shellEscape params)] (unwords $ map shellEscape params)]
else error "running command in non-ssh repo not supported" else error "running command in non-ssh repo not supported"
{- Looks up a per-remote config option in git config. -}
repoConfig :: Git.Repo -> String -> String -> Annex String
repoConfig r key def = do
g <- Annex.gitRepo
return $ Git.configGet g fullkey def
where
fullkey = "remote." ++ (Git.repoRemoteName r) ++ "." ++ key

1
debian/changelog vendored
View file

@ -8,6 +8,7 @@ git-annex (0.03) UNRELEASED; urgency=low
* Fixed memory leak; git-annex no longer reads the whole file list * Fixed memory leak; git-annex no longer reads the whole file list
from git before starting, and will be much faster with large repos. from git before starting, and will be much faster with large repos.
* Fix crash on unknown symlinks. * Fix crash on unknown symlinks.
* Added remote.annex-scp-options and remote.annex-ssh-options.
-- Joey Hess <joeyh@debian.org> Thu, 28 Oct 2010 13:46:59 -0400 -- Joey Hess <joeyh@debian.org> Thu, 28 Oct 2010 13:46:59 -0400

View file

@ -196,6 +196,11 @@ Like other git commands, git-annex is configured via `.git/config`.
from ever using this remote. from ever using this remote.
* `remote.<name>.annex-uuid` -- git-annex caches UUIDs of repositories * `remote.<name>.annex-uuid` -- git-annex caches UUIDs of repositories
here. here.
* `remote.<name>.annex-scp-options` -- Options to use when using scp
to or from this repository. For example, to force ipv6, and limit
the bandwidth to 100Kbit/s, set it to "-6 -l 100"
* `remote.<name>.annex-ssh-options` -- Options to use when using ssh
to talk to this repository.
# FILES # FILES