Simplify setup process for a ssh remote.

Now it suffices to run git remote add, followed by git-annex sync. Now the
remote is automatically initialized for use by git-annex, where before the
git-annex branch had to manually be pushed before using git-annex sync.
Note that this involved changes to git-annex-shell, so if the remote is
using an old version, the manual push is still needed.

Implementation required git-annex-shell be changed, so configlist can
autoinit a repository even when no git-annex branch has been pushed yet.
Unfortunate because we'll have to wait for it to get deployed to servers
before being able to rely on this change in the documentation.

Did consider making git-annex sync push the git-annex branch to repos that
didn't have a uuid, but this seemed difficult to do without complicating it
in messy ways.

It would be cleaner to split a command out from configlist to handle
the initialization. But this is difficult without sacrificing backwards
compatability, for users of old git-annex versions which would not use the
new command.
This commit is contained in:
Joey Hess 2015-08-05 13:49:54 -04:00
parent b1b757bffa
commit c5b8484c2e
23 changed files with 75 additions and 45 deletions

View file

@ -34,7 +34,7 @@ import qualified Command.GCryptSetup
cmds_readonly :: [Command] cmds_readonly :: [Command]
cmds_readonly = cmds_readonly =
[ gitAnnexShellCheck Command.ConfigList.cmd [ Command.ConfigList.cmd
, gitAnnexShellCheck Command.InAnnex.cmd , gitAnnexShellCheck Command.InAnnex.cmd
, gitAnnexShellCheck Command.SendKey.cmd , gitAnnexShellCheck Command.SendKey.cmd
, gitAnnexShellCheck Command.TransferInfo.cmd , gitAnnexShellCheck Command.TransferInfo.cmd
@ -146,6 +146,7 @@ checkField (field, val)
| field == fieldName remoteUUID = fieldCheck remoteUUID val | field == fieldName remoteUUID = fieldCheck remoteUUID val
| field == fieldName associatedFile = fieldCheck associatedFile val | field == fieldName associatedFile = fieldCheck associatedFile val
| field == fieldName direct = fieldCheck direct val | field == fieldName direct = fieldCheck direct val
| field == fieldName autoInit = fieldCheck autoInit val
| otherwise = False | otherwise = False
failure :: IO () failure :: IO ()

View file

@ -34,3 +34,6 @@ associatedFile = Field "associatedfile" $ \f ->
direct :: Field direct :: Field
direct = Field "direct" $ \f -> f == "1" direct = Field "direct" $ \f -> f == "1"
autoInit :: Field
autoInit = Field "autoinit" $ \f -> f == "1"

View file

@ -14,9 +14,10 @@ import Annex.Init
import qualified Annex.Branch import qualified Annex.Branch
import qualified Git.Config import qualified Git.Config
import Remote.GCrypt (coreGCryptId) import Remote.GCrypt (coreGCryptId)
import qualified CmdLine.GitAnnexShell.Fields as Fields
cmd :: Command cmd :: Command
cmd = noCommit $ cmd = noCommit $ dontCheck repoExists $
command "configlist" SectionPlumbing command "configlist" SectionPlumbing
"outputs relevant git configuration" "outputs relevant git configuration"
paramNothing (withParams seek) paramNothing (withParams seek)
@ -34,13 +35,14 @@ start = do
showConfig k v = liftIO $ putStrLn $ k ++ "=" ++ v showConfig k v = liftIO $ putStrLn $ k ++ "=" ++ v
{- The repository may not yet have a UUID; automatically initialize it {- The repository may not yet have a UUID; automatically initialize it
- when there's a git-annex branch available. -} - when there's a git-annex branch available or if the autoinit field was
- set. -}
findOrGenUUID :: Annex UUID findOrGenUUID :: Annex UUID
findOrGenUUID = do findOrGenUUID = do
u <- getUUID u <- getUUID
if u /= NoUUID if u /= NoUUID
then return u then return u
else ifM Annex.Branch.hasSibling else ifM (Annex.Branch.hasSibling <||> (isJust <$> Fields.getField Fields.autoInit))
( do ( do
initialize Nothing initialize Nothing
getUUID getUUID

View file

@ -137,19 +137,24 @@ remoteBranch :: Remote -> Git.Ref -> Git.Ref
remoteBranch remote = Git.Ref.underBase $ "refs/remotes/" ++ Remote.name remote remoteBranch remote = Git.Ref.underBase $ "refs/remotes/" ++ Remote.name remote
syncRemotes :: [String] -> Annex [Remote] syncRemotes :: [String] -> Annex [Remote]
syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted ) syncRemotes ps = do
-- Get remote list first, doing automatic initialization
-- of remotes when possible.
syncRemotes' ps =<< Remote.remoteList' True
syncRemotes' :: [String] -> [Remote] -> Annex [Remote]
syncRemotes' ps remotelist = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
where where
pickfast = (++) <$> listed <*> (filterM good =<< fastest <$> available) pickfast = (++) <$> listed <*> (filterM good (fastest available))
wanted wanted
| null rs = filterM good =<< concat . Remote.byCost <$> available | null ps = filterM good (concat $ Remote.byCost available)
| otherwise = listed | otherwise = listed
listed = concat <$> mapM Remote.byNameOrGroup rs listed = concat <$> mapM Remote.byNameOrGroup ps
available = filter (remoteAnnexSync . Remote.gitconfig) available = filter (remoteAnnexSync . Remote.gitconfig)
. filter (not . Remote.isXMPPRemote) $ filter (not . Remote.isXMPPRemote) remotelist
<$> Remote.remoteList
good r good r
| Remote.gitSyncableRemote r = Remote.Git.repoAvail $ Remote.repo r | Remote.gitSyncableRemote r = Remote.Git.repoAvail $ Remote.repo r

View file

@ -20,6 +20,7 @@ module Remote (
remoteTypes, remoteTypes,
remoteList, remoteList,
remoteList',
gitSyncableRemote, gitSyncableRemote,
remoteMap, remoteMap,
remoteMap', remoteMap',

View file

@ -43,8 +43,8 @@ remote = RemoteType {
} }
-- There is only one bittorrent remote, and it always exists. -- There is only one bittorrent remote, and it always exists.
list :: Annex [Git.Repo] list :: Bool -> Annex [Git.Repo]
list = do list _autoinit = do
r <- liftIO $ Git.Construct.remoteNamed "bittorrent" (pure Git.Construct.fromUnknown) r <- liftIO $ Git.Construct.remoteNamed "bittorrent" (pure Git.Construct.fromUnknown)
return [r] return [r]

View file

@ -36,7 +36,7 @@ type BupRepo = String
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "bup", typename = "bup",
enumerate = findSpecialRemotes "buprepo", enumerate = const (findSpecialRemotes "buprepo"),
generate = gen, generate = gen,
setup = bupSetup setup = bupSetup
} }

View file

@ -31,7 +31,7 @@ data DdarRepo = DdarRepo
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "ddar", typename = "ddar",
enumerate = findSpecialRemotes "ddarrepo", enumerate = const (findSpecialRemotes "ddarrepo"),
generate = gen, generate = gen,
setup = ddarSetup setup = ddarSetup
} }

View file

@ -33,7 +33,7 @@ import Utility.Metered
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "directory", typename = "directory",
enumerate = findSpecialRemotes "directory", enumerate = const (findSpecialRemotes "directory"),
generate = gen, generate = gen,
setup = directorySetup setup = directorySetup
} }

View file

@ -34,7 +34,7 @@ import qualified Data.Map as M
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "external", typename = "external",
enumerate = findSpecialRemotes "externaltype", enumerate = const (findSpecialRemotes "externaltype"),
generate = gen, generate = gen,
setup = externalSetup setup = externalSetup
} }

View file

@ -54,7 +54,7 @@ remote = RemoteType {
typename = "gcrypt", typename = "gcrypt",
-- Remote.Git takes care of enumerating gcrypt remotes too, -- Remote.Git takes care of enumerating gcrypt remotes too,
-- and will call our gen on them. -- and will call our gen on them.
enumerate = return [], enumerate = const (return []),
generate = gen, generate = gen,
setup = gCryptSetup setup = gCryptSetup
} }

View file

@ -67,11 +67,11 @@ remote = RemoteType {
setup = gitSetup setup = gitSetup
} }
list :: Annex [Git.Repo] list :: Bool -> Annex [Git.Repo]
list = do list autoinit = do
c <- fromRepo Git.config c <- fromRepo Git.config
rs <- mapM (tweakurl c) =<< fromRepo Git.remotes rs <- mapM (tweakurl c) =<< fromRepo Git.remotes
mapM configRead rs mapM (configRead autoinit) rs
where where
annexurl n = "remote." ++ n ++ ".annexurl" annexurl n = "remote." ++ n ++ ".annexurl"
tweakurl c r = do tweakurl c r = do
@ -116,14 +116,14 @@ gitSetup (Just u) _ c = do
- -
- Conversely, the config of an URL remote is only read when there is no - Conversely, the config of an URL remote is only read when there is no
- cached UUID value. -} - cached UUID value. -}
configRead :: Git.Repo -> Annex Git.Repo configRead :: Bool -> Git.Repo -> Annex Git.Repo
configRead r = do configRead autoinit r = do
gc <- Annex.getRemoteGitConfig r gc <- Annex.getRemoteGitConfig r
u <- getRepoUUID r u <- getRepoUUID r
case (repoCheap r, remoteAnnexIgnore gc, u) of case (repoCheap r, remoteAnnexIgnore gc, u) of
(_, True, _) -> return r (_, True, _) -> return r
(True, _, _) -> tryGitConfigRead r (True, _, _) -> tryGitConfigRead autoinit r
(False, _, NoUUID) -> tryGitConfigRead r (False, _, NoUUID) -> tryGitConfigRead autoinit r
_ -> return r _ -> return r
gen :: Git.Repo -> UUID -> RemoteConfig -> RemoteGitConfig -> Annex (Maybe Remote) gen :: Git.Repo -> UUID -> RemoteConfig -> RemoteGitConfig -> Annex (Maybe Remote)
@ -196,11 +196,12 @@ repoAvail r
{- Tries to read the config for a specified remote, updates state, and {- Tries to read the config for a specified remote, updates state, and
- returns the updated repo. -} - returns the updated repo. -}
tryGitConfigRead :: Git.Repo -> Annex Git.Repo tryGitConfigRead :: Bool -> Git.Repo -> Annex Git.Repo
tryGitConfigRead r tryGitConfigRead autoinit r
| haveconfig r = return r -- already read | haveconfig r = return r -- already read
| Git.repoIsSsh r = store $ do | Git.repoIsSsh r = store $ do
v <- Ssh.onRemote r (pipedconfig, return (Left $ error "configlist failed")) "configlist" [] [] liftIO $ print autoinit
v <- Ssh.onRemote r (pipedconfig, return (Left $ error "configlist failed")) "configlist" [] configlistfields
case v of case v of
Right r' Right r'
| haveconfig r' -> return r' | haveconfig r' -> return r'
@ -302,6 +303,10 @@ tryGitConfigRead r
Annex.BranchState.disableUpdate Annex.BranchState.disableUpdate
void $ tryNonAsync $ ensureInitialized void $ tryNonAsync $ ensureInitialized
Annex.getState Annex.repo Annex.getState Annex.repo
configlistfields = if autoinit
then [(Fields.autoInit, "1")]
else []
{- Checks if a given remote has the content for a key in its annex. -} {- Checks if a given remote has the content for a key in its annex. -}
inAnnex :: Remote -> Key -> Annex Bool inAnnex :: Remote -> Key -> Annex Bool

View file

@ -31,7 +31,7 @@ type Archive = FilePath
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "glacier", typename = "glacier",
enumerate = findSpecialRemotes "glacier", enumerate = const (findSpecialRemotes "glacier"),
generate = gen, generate = gen,
setup = glacierSetup setup = glacierSetup
} }

View file

@ -27,7 +27,7 @@ type HookName = String
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "hook", typename = "hook",
enumerate = findSpecialRemotes "hooktype", enumerate = const (findSpecialRemotes "hooktype"),
generate = gen, generate = gen,
setup = hookSetup setup = hookSetup
} }

View file

@ -72,14 +72,19 @@ remoteList :: Annex [Remote]
remoteList = do remoteList = do
rs <- Annex.getState Annex.remotes rs <- Annex.getState Annex.remotes
if null rs if null rs
then do then remoteList' False
m <- readRemoteLog
rs' <- concat <$> mapM (process m) remoteTypes
Annex.changeState $ \s -> s { Annex.remotes = rs' }
return rs'
else return rs else return rs
remoteList' :: Bool -> Annex [Remote]
remoteList' autoinit = do
m <- readRemoteLog
rs <- concat <$> mapM (process m) remoteTypes
Annex.changeState $ \s -> s { Annex.remotes = rs }
return rs
where where
process m t = enumerate t >>= mapM (remoteGen m t) >>= return . catMaybes process m t = enumerate t autoinit
>>= mapM (remoteGen m t)
>>= return . catMaybes
{- Forces the remoteList to be re-generated, re-reading the git config. -} {- Forces the remoteList to be re-generated, re-reading the git config. -}
remoteListRefresh :: Annex [Remote] remoteListRefresh :: Annex [Remote]
@ -109,7 +114,7 @@ updateRemote remote = do
where where
updaterepo r updaterepo r
| Git.repoIsLocal r || Git.repoIsLocalUnknown r = | Git.repoIsLocal r || Git.repoIsLocalUnknown r =
Remote.Git.configRead r Remote.Git.configRead False r
| otherwise = return r | otherwise = return r
{- Checks if a remote is syncable using git. -} {- Checks if a remote is syncable using git. -}

View file

@ -44,7 +44,7 @@ import qualified Data.Map as M
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "rsync", typename = "rsync",
enumerate = findSpecialRemotes "rsyncurl", enumerate = const (findSpecialRemotes "rsyncurl"),
generate = gen, generate = gen,
setup = rsyncSetup setup = rsyncSetup
} }

View file

@ -54,7 +54,7 @@ type BucketName = String
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "S3", typename = "S3",
enumerate = findSpecialRemotes "s3", enumerate = const (findSpecialRemotes "s3"),
generate = gen, generate = gen,
setup = s3Setup setup = s3Setup
} }

View file

@ -53,7 +53,7 @@ type Capability = String
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "tahoe", typename = "tahoe",
enumerate = findSpecialRemotes "tahoe", enumerate = const (findSpecialRemotes "tahoe"),
generate = gen, generate = gen,
setup = tahoeSetup setup = tahoeSetup
} }

View file

@ -36,8 +36,8 @@ remote = RemoteType {
-- There is only one web remote, and it always exists. -- There is only one web remote, and it always exists.
-- (If the web should cease to exist, remove this module and redistribute -- (If the web should cease to exist, remove this module and redistribute
-- a new release to the survivors by carrier pigeon.) -- a new release to the survivors by carrier pigeon.)
list :: Annex [Git.Repo] list :: Bool -> Annex [Git.Repo]
list = do list _autoinit = do
r <- liftIO $ Git.Construct.remoteNamed "web" (pure Git.Construct.fromUnknown) r <- liftIO $ Git.Construct.remoteNamed "web" (pure Git.Construct.fromUnknown)
return [r] return [r]

View file

@ -36,7 +36,7 @@ import Remote.WebDAV.DavLocation
remote :: RemoteType remote :: RemoteType
remote = RemoteType { remote = RemoteType {
typename = "webdav", typename = "webdav",
enumerate = findSpecialRemotes "webdav", enumerate = const (findSpecialRemotes "webdav"),
generate = gen, generate = gen,
setup = webdavSetup setup = webdavSetup
} }

View file

@ -40,7 +40,8 @@ data RemoteTypeA a = RemoteType {
-- human visible type name -- human visible type name
typename :: String, typename :: String,
-- enumerates remotes of this type -- enumerates remotes of this type
enumerate :: a [Git.Repo], -- The Bool is True if automatic initialization of remotes is desired
enumerate :: Bool -> a [Git.Repo],
-- generates a remote of this type -- generates a remote of this type
generate :: Git.Repo -> UUID -> RemoteConfig -> RemoteGitConfig -> a (Maybe (RemoteA a)), generate :: Git.Repo -> UUID -> RemoteConfig -> RemoteGitConfig -> a (Maybe (RemoteA a)),
-- initializes or changes a remote -- initializes or changes a remote

6
debian/changelog vendored
View file

@ -22,6 +22,12 @@ git-annex (5.20150732) UNRELEASED; urgency=medium
* Linux standalone: Work around problem that prevented it from working * Linux standalone: Work around problem that prevented it from working
properly if unpacked into a directory that contains ":" or ";" in its properly if unpacked into a directory that contains ":" or ";" in its
name. name.
* Simplify setup process for a ssh remote. Now it suffices to run git
remote add, followed by git-annex sync. Now the remote is automatically
initialized for use by git-annex, where before the git-annex branch had
to manually be pushed before using git-annex sync. Note that this
involved changes to git-annex-shell, so if the remote is using an old
version, the manual push is still needed.
-- Joey Hess <id@joeyh.name> Fri, 31 Jul 2015 12:31:39 -0400 -- Joey Hess <id@joeyh.name> Fri, 31 Jul 2015 12:31:39 -0400

View file

@ -31,7 +31,8 @@ first "/~/" or "/~user/" is expanded to the specified home directory.
When run in a repository that does not yet have an annex.uuid, one When run in a repository that does not yet have an annex.uuid, one
will be created, as long as a git-annex branch has already been pushed to will be created, as long as a git-annex branch has already been pushed to
the repository. the repository, or if the autoinit= flag is used to indicate
initialization is desired.
* inannex directory [key ...] * inannex directory [key ...]
@ -95,7 +96,7 @@ to git-annex-shell are:
on new dashed options). on new dashed options).
Currently used fields include remoteuuid=, associatedfile=, Currently used fields include remoteuuid=, associatedfile=,
and direct= direct=, and autoinit=
# HOOK # HOOK