summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-12-16 15:36:59 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-12-16 15:37:50 -0400
commit353b59a000dd0e4941b3c36a7fd02d23f3cf44a1 (patch)
tree3d39f2107a921d9cf3bc6bb6c922a58046c460a8
parent6c59cea78aa11aea9031eb162b4158fa1d955f4f (diff)
p2p: --link no longer takes a remote name, instead the --name option can be used.
-rw-r--r--CHANGELOG2
-rw-r--r--Command/P2P.hs36
-rw-r--r--doc/git-annex-p2p.mdwn12
-rw-r--r--doc/tips/peer_to_peer_network_with_tor.mdwn2
4 files changed, 39 insertions, 13 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 044ab199b..b4659fa02 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,8 @@ git-annex (6.20161211) UNRELEASED; urgency=medium
have TCPKeepAlive enabled by default.
* Make all --batch input, as well as fromkey and registerurl stdin
be processed without requiring it to be in the current encoding.
+ * p2p: --link no longer takes a remote name, instead the --name
+ option can be used.
-- Joey Hess <id@joeyh.name> Sun, 11 Dec 2016 21:29:51 -0400
diff --git a/Command/P2P.hs b/Command/P2P.hs
index ea4dd7c65..d59d774c4 100644
--- a/Command/P2P.hs
+++ b/Command/P2P.hs
@@ -27,25 +27,43 @@ cmd = command "p2p" SectionSetup
data P2POpts
= GenAddresses
- | LinkRemote RemoteName
+ | LinkRemote
-optParser :: CmdParamsDesc -> Parser P2POpts
-optParser _ = genaddresses <|> linkremote
+optParser :: CmdParamsDesc -> Parser (P2POpts, Maybe RemoteName)
+optParser _ = (,)
+ <$> (genaddresses <|> linkremote)
+ <*> optional name
where
genaddresses = flag' GenAddresses
( long "gen-addresses"
<> help "generate addresses that allow accessing this repository over P2P networks"
)
- linkremote = LinkRemote <$> strOption
+ linkremote = flag' LinkRemote
( long "link"
- <> metavar paramRemote
- <> help "specify name to use for git remote"
+ <> help "set up a P2P link to a git remote"
+ )
+ name = strOption
+ ( long "name"
+ <> metavar paramName
+ <> help "name of remote"
)
-seek :: P2POpts -> CommandSeek
-seek GenAddresses = genAddresses =<< loadP2PAddresses
-seek (LinkRemote name) = commandAction $
+seek :: (P2POpts, Maybe RemoteName) -> CommandSeek
+seek (GenAddresses, _) = genAddresses =<< loadP2PAddresses
+seek (LinkRemote, Just name) = commandAction $
linkRemote (Git.Remote.makeLegalName name)
+seek (LinkRemote, Nothing) = commandAction $
+ linkRemote =<< unusedPeerRemoteName
+
+unusedPeerRemoteName :: Annex RemoteName
+unusedPeerRemoteName = go (1 :: Integer) =<< usednames
+ where
+ usednames = mapMaybe remoteName . remotes <$> Annex.gitRepo
+ go n names = do
+ let name = "peer" ++ show n
+ if name `elem` names
+ then go (n+1) names
+ else return name
-- Only addresses are output to stdout, to allow scripting.
genAddresses :: [P2PAddress] -> Annex ()
diff --git a/doc/git-annex-p2p.mdwn b/doc/git-annex-p2p.mdwn
index 5bf48178f..6c50c9dd2 100644
--- a/doc/git-annex-p2p.mdwn
+++ b/doc/git-annex-p2p.mdwn
@@ -22,14 +22,20 @@ services.
over the available P2P networks. The address or addresses is output to
stdout.
-* `--link remotename`
+* `--link`
- Sets up a git remote with the specified remotename that is accessed over
- a P2P network.
+ Sets up a git remote that is accessed over a P2P network.
This will prompt for an address to be entered; you should paste in the
address that was generated by --gen-address in the remote repository.
+ Defaults to making the git remote be named "peer1", "peer2",
+ etc. This can be overridden with the `--name` option.
+
+* `--name`
+
+ Specify a name to use when setting up a git remote.
+
# SEE ALSO
[[git-annex]](1)
diff --git a/doc/tips/peer_to_peer_network_with_tor.mdwn b/doc/tips/peer_to_peer_network_with_tor.mdwn
index 11d977cca..9c97735e4 100644
--- a/doc/tips/peer_to_peer_network_with_tor.mdwn
+++ b/doc/tips/peer_to_peer_network_with_tor.mdwn
@@ -46,7 +46,7 @@ Now, tell the new peer about the address of the first peer.
This will make a git remote named "peer1", which connects,
through Tor, to the repository on the other peer.
- git annex p2p --link peer1
+ git annex p2p --link --name peer1
That command will prompt for an address; paste in the address that was
generated on the first peer, and then press Enter.