sync: Now supports remote groups, the same way git remote update does.
This commit is contained in:
parent
f7333d29ae
commit
aba3e11776
5 changed files with 37 additions and 5 deletions
|
@ -6,7 +6,17 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Command.Sync where
|
module Command.Sync (
|
||||||
|
cmd,
|
||||||
|
prepMerge,
|
||||||
|
mergeLocal,
|
||||||
|
mergeRemote,
|
||||||
|
commitStaged,
|
||||||
|
pushBranch,
|
||||||
|
updateBranch,
|
||||||
|
syncBranch,
|
||||||
|
updateSyncBranch,
|
||||||
|
) where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
|
@ -109,16 +119,21 @@ syncRemotes :: [String] -> Annex [Remote]
|
||||||
syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
|
syncRemotes rs = 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 rs = filterM good =<< concat . Remote.byCost <$> available
|
||||||
| otherwise = listed
|
| otherwise = listed
|
||||||
listed = catMaybes <$> mapM (Remote.byName . Just) rs
|
|
||||||
|
listed = concat <$> mapM Remote.byNameOrGroup rs
|
||||||
|
|
||||||
available = filter (remoteAnnexSync . Remote.gitconfig)
|
available = filter (remoteAnnexSync . Remote.gitconfig)
|
||||||
. filter (not . Remote.isXMPPRemote)
|
. filter (not . Remote.isXMPPRemote)
|
||||||
<$> Remote.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
|
||||||
| otherwise = return True
|
| otherwise = return True
|
||||||
|
|
||||||
fastest = fromMaybe [] . headMaybe . Remote.byCost
|
fastest = fromMaybe [] . headMaybe . Remote.byCost
|
||||||
|
|
||||||
commit :: CommandStart
|
commit :: CommandStart
|
||||||
|
|
15
Remote.hs
15
Remote.hs
|
@ -26,6 +26,7 @@ module Remote (
|
||||||
uuidDescriptions,
|
uuidDescriptions,
|
||||||
byName,
|
byName,
|
||||||
byName',
|
byName',
|
||||||
|
byNameOrGroup,
|
||||||
byNameOnly,
|
byNameOnly,
|
||||||
byNameWithUUID,
|
byNameWithUUID,
|
||||||
byCost,
|
byCost,
|
||||||
|
@ -94,7 +95,11 @@ addName desc n
|
||||||
| otherwise = desc ++ " [" ++ n ++ "]"
|
| otherwise = desc ++ " [" ++ n ++ "]"
|
||||||
|
|
||||||
{- When a name is specified, looks up the remote matching that name.
|
{- When a name is specified, looks up the remote matching that name.
|
||||||
- (Or it can be a UUID.) -}
|
- (Or it can be a UUID.)
|
||||||
|
-
|
||||||
|
- Throws an error if a name is specified and no matching remote can be
|
||||||
|
- found.
|
||||||
|
-}
|
||||||
byName :: Maybe RemoteName -> Annex (Maybe Remote)
|
byName :: Maybe RemoteName -> Annex (Maybe Remote)
|
||||||
byName Nothing = return Nothing
|
byName Nothing = return Nothing
|
||||||
byName (Just n) = either error Just <$> byName' n
|
byName (Just n) = either error Just <$> byName' n
|
||||||
|
@ -121,6 +126,14 @@ byName' n = go . filter matching <$> remoteList
|
||||||
go (match:_) = Right match
|
go (match:_) = Right match
|
||||||
matching r = n == name r || toUUID n == uuid r
|
matching r = n == name r || toUUID n == uuid r
|
||||||
|
|
||||||
|
{- Finds the remote or remote group matching the name. -}
|
||||||
|
byNameOrGroup :: RemoteName -> Annex [Remote]
|
||||||
|
byNameOrGroup n = go =<< getConfigMaybe (ConfigKey ("remotes." ++ n))
|
||||||
|
where
|
||||||
|
go (Just l) = concatMap maybeToList <$>
|
||||||
|
mapM (Remote.byName . Just) (split " " l)
|
||||||
|
go Nothing = maybeToList <$> Remote.byName (Just n)
|
||||||
|
|
||||||
{- Only matches remote name, not UUID -}
|
{- Only matches remote name, not UUID -}
|
||||||
byNameOnly :: RemoteName -> Annex (Maybe Remote)
|
byNameOnly :: RemoteName -> Annex (Maybe Remote)
|
||||||
byNameOnly n = headMaybe . filter matching <$> remoteList
|
byNameOnly n = headMaybe . filter matching <$> remoteList
|
||||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -2,6 +2,7 @@ git-annex (5.20141220) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
* vicfg: Avoid crashing on badly encoded config data.
|
* vicfg: Avoid crashing on badly encoded config data.
|
||||||
* Work around statfs() overflow on some XFS systems.
|
* Work around statfs() overflow on some XFS systems.
|
||||||
|
* sync: Now supports remote groups, the same way git remote update does.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Mon, 22 Dec 2014 15:16:38 -0400
|
-- Joey Hess <id@joeyh.name> Mon, 22 Dec 2014 15:16:38 -0400
|
||||||
|
|
||||||
|
|
|
@ -143,8 +143,9 @@ subdirectories).
|
||||||
* `sync [remote ...]`
|
* `sync [remote ...]`
|
||||||
|
|
||||||
Use this command when you want to synchronize the local repository with
|
Use this command when you want to synchronize the local repository with
|
||||||
one or more of its remotes. You can specify the remotes to sync with by
|
one or more of its remotes. You can specify the remotes (or remote
|
||||||
name; the default is to sync with all remotes.
|
groups) to sync with by name; the default if none are specified is to
|
||||||
|
sync with all remotes.
|
||||||
Or specify `--fast` to sync with the remotes with the
|
Or specify `--fast` to sync with the remotes with the
|
||||||
lowest annex-cost value.
|
lowest annex-cost value.
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
`git remote update $group` looks at the $group.away git config and fetches
|
`git remote update $group` looks at the $group.away git config and fetches
|
||||||
from the listed remotes. It would be useful if `git annex sync $group` did the same.
|
from the listed remotes. It would be useful if `git annex sync $group` did the same.
|
||||||
--[[Joey]]
|
--[[Joey]]
|
||||||
|
|
||||||
|
[[done]]
|
||||||
|
|
Loading…
Reference in a new issue