annotate mercurial/sshrepo.py @ 5107:0edea751bbb2

test-grep: use lowercase hg command
author Matt Mackall <mpm@selenic.com>
date Wed, 15 Aug 2007 15:30:33 -0500
parents 6b4127c7d52a
children 664a1c312972 6d5ed61c508c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1096
ae4f1f48c569 sshrepo: adjust file comment
mpm@selenic.com
parents: 1094 1089
diff changeset
1 # sshrepo.py - ssh repository proxy class for mercurial
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
2 #
2859
345bac2bc4ec update copyrights.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2740
diff changeset
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
4 #
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
5 # This software may be used and distributed according to the terms
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
6 # of the GNU General Public License, incorporated herein by reference.
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
7
1103
808a9f0e7af0 Fix sshrepo imports
mpm@selenic.com
parents: 1096
diff changeset
8 from node import *
808a9f0e7af0 Fix sshrepo imports
mpm@selenic.com
parents: 1096
diff changeset
9 from remoterepo import *
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
10 from i18n import _
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3766
diff changeset
11 import hg, os, re, stat, util
60
e32fdbd97839 Add hg:// protocol
mpm@selenic.com
parents: 56
diff changeset
12
926
b765e970c9ff Add a local() method to repository classes
mpm@selenic.com
parents: 923
diff changeset
13 class sshrepository(remoterepository):
2549
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
14 def __init__(self, ui, path, create=0):
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
15 self._url = path
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
16 self.ui = ui
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
17
3599
e00920b4f1cb sshrepo: fix the parsing of the ssh url
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3447
diff changeset
18 m = re.match(r'^ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?$', path)
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
19 if not m:
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
20 self.raise_(hg.RepoError(_("couldn't parse location %s") % path))
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
21
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
22 self.user = m.group(2)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
23 self.host = m.group(3)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
24 self.port = m.group(5)
1069
4337cd845a2a Allow using a ssh repository without a path.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
25 self.path = m.group(7) or "."
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
26
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
27 args = self.user and ("%s@%s" % (self.user, self.host)) or self.host
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
28 args = self.port and ("%s -p %s") % (args, self.port) or args
817
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
29
961
3e11d5038649 Add --ssh and --remotecmd to push
mpm@selenic.com
parents: 934
diff changeset
30 sshcmd = self.ui.config("ui", "ssh", "ssh")
3e11d5038649 Add --ssh and --remotecmd to push
mpm@selenic.com
parents: 934
diff changeset
31 remotecmd = self.ui.config("ui", "remotecmd", "hg")
2549
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
32
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
33 if create:
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
34 cmd = '%s %s "%s init %s"'
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
35 cmd = cmd % (sshcmd, args, remotecmd, self.path)
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
36
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
37 ui.note('running %s\n' % cmd)
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
38 res = os.system(cmd)
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
39 if res != 0:
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
40 self.raise_(hg.RepoError(_("could not create remote repo")))
2549
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
41
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
42 self.validate_repo(ui, sshcmd, args, remotecmd)
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
43
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
44 def url(self):
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
45 return self._url
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
46
2549
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
47 def validate_repo(self, ui, sshcmd, args, remotecmd):
3034
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
48 # cleanup up previous run
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
49 self.cleanup()
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
50
1330
0fcde73dc3ca Give ssh a better chance of working on Windows.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1251
diff changeset
51 cmd = '%s %s "%s -R %s serve --stdio"'
1069
4337cd845a2a Allow using a ssh repository without a path.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
52 cmd = cmd % (sshcmd, args, remotecmd, self.path)
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
53
1332
404484c9628e Help debugability: print ssh command being used when --verbose.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1330
diff changeset
54 ui.note('running %s\n' % cmd)
1330
0fcde73dc3ca Give ssh a better chance of working on Windows.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1251
diff changeset
55 self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b')
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
56
2028
1f1fc418a96c ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents: 2019
diff changeset
57 # skip any noise generated by remote shell
2421
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
58 self.do_cmd("hello")
2028
1f1fc418a96c ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents: 2019
diff changeset
59 r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
2420
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
60 lines = ["", "dummy"]
2046
d14497cbd668 Show remote ssh noise only with --debug and increase the limit to 500 lines.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2040
diff changeset
61 max_noise = 500
2420
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
62 while lines[-1] and max_noise:
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
63 l = r.readline()
2028
1f1fc418a96c ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents: 2019
diff changeset
64 self.readerr()
2420
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
65 if lines[-1] == "1\n" and l == "\n":
2028
1f1fc418a96c ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents: 2019
diff changeset
66 break
2420
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
67 if l:
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
68 ui.debug(_("remote: "), l)
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
69 lines.append(l)
2040
cd7711268774 Don't enter an endless loop if remote hg doesn't answer, show remote noise.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2028
diff changeset
70 max_noise -= 1
cd7711268774 Don't enter an endless loop if remote hg doesn't answer, show remote noise.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2028
diff changeset
71 else:
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
72 self.raise_(hg.RepoError(_("no suitable response from remote hg")))
2028
1f1fc418a96c ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents: 2019
diff changeset
73
2421
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
74 self.capabilities = ()
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
75 lines.reverse()
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
76 for l in lines:
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
77 if l.startswith("capabilities:"):
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
78 self.capabilities = l[:-1].split(":")[1].split()
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
79 break
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
80
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
81 def readerr(self):
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
82 while 1:
2176
9b42304d9896 fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2046
diff changeset
83 size = util.fstat(self.pipee).st_size
1357
94586af53d2f Replacing select.select() with os.fstat() which works also on windows.
zbynek@alex.kolej.mff.cuni.cz
parents: 1332
diff changeset
84 if size == 0: break
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
85 l = self.pipee.readline()
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
86 if not l: break
1402
9d2c2e6b32b5 i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1400
diff changeset
87 self.ui.status(_("remote: "), l)
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
88
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
89 def raise_(self, exception):
3380
8770b4870e22 portability fix for test-ssh
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3275
diff changeset
90 self.cleanup()
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
91 raise exception
3380
8770b4870e22 portability fix for test-ssh
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3275
diff changeset
92
3034
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
93 def cleanup(self):
817
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
94 try:
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
95 self.pipeo.close()
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
96 self.pipei.close()
1358
20abfd48e21c Partially revert ssh change so we read all of remote ssh stream
Matt Mackall <mpm@selenic.com>
parents: 1357
diff changeset
97 # read the error descriptor until EOF
20abfd48e21c Partially revert ssh change so we read all of remote ssh stream
Matt Mackall <mpm@selenic.com>
parents: 1357
diff changeset
98 for l in self.pipee:
1402
9d2c2e6b32b5 i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1400
diff changeset
99 self.ui.status(_("remote: "), l)
817
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
100 self.pipee.close()
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
101 except:
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
102 pass
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
103
3034
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
104 __del__ = cleanup
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
105
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
106 def do_cmd(self, cmd, **args):
1402
9d2c2e6b32b5 i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1400
diff changeset
107 self.ui.debug(_("sending %s command\n") % cmd)
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
108 self.pipeo.write("%s\n" % cmd)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
109 for k, v in args.items():
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
110 self.pipeo.write("%s %d\n" % (k, len(v)))
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
111 self.pipeo.write(v)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
112 self.pipeo.flush()
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
113
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
114 return self.pipei
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
115
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
116 def call(self, cmd, **args):
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
117 r = self.do_cmd(cmd, **args)
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
118 l = r.readline()
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
119 self.readerr()
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
120 try:
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
121 l = int(l)
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
122 except:
3766
581665242c07 Use UnexpectedOutput exception instead of RepoError in sshrepo, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3765
diff changeset
123 self.raise_(util.UnexpectedOutput(_("unexpected response:"), l))
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
124 return r.read(l)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
125
638
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
126 def lock(self):
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
127 self.call("lock")
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
128 return remotelock(self)
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
129
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
130 def unlock(self):
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
131 self.call("unlock")
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
132
3446
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
133 def lookup(self, key):
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
134 d = self.call("lookup", key=key)
3447
ef1032c223e7 sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents: 3446
diff changeset
135 success, data = d[:-1].split(" ", 1)
3764
6652209d104d Don't show traceback on 'hg clone -r unknown ssh://hg.example.com/'.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3599
diff changeset
136 if int(success):
6652209d104d Don't show traceback on 'hg clone -r unknown ssh://hg.example.com/'.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3599
diff changeset
137 return bin(data)
6652209d104d Don't show traceback on 'hg clone -r unknown ssh://hg.example.com/'.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3599
diff changeset
138 else:
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
139 self.raise_(hg.RepoError(data))
3446
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
140
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
141 def heads(self):
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
142 d = self.call("heads")
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
143 try:
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
144 return map(bin, d[:-1].split(" "))
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
145 except:
3766
581665242c07 Use UnexpectedOutput exception instead of RepoError in sshrepo, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3765
diff changeset
146 self.raise_(util.UnexpectedOutput(_("unexpected response:"), d))
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
147
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
148 def branches(self, nodes):
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
149 n = " ".join(map(hex, nodes))
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
150 d = self.call("branches", nodes=n)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
151 try:
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
152 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
153 return br
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
154 except:
3766
581665242c07 Use UnexpectedOutput exception instead of RepoError in sshrepo, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3765
diff changeset
155 self.raise_(util.UnexpectedOutput(_("unexpected response:"), d))
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
156
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
157 def between(self, pairs):
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
158 n = "\n".join(["-".join(map(hex, p)) for p in pairs])
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
159 d = self.call("between", pairs=n)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
160 try:
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
161 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
162 return p
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
163 except:
3766
581665242c07 Use UnexpectedOutput exception instead of RepoError in sshrepo, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3765
diff changeset
164 self.raise_(util.UnexpectedOutput(_("unexpected response:"), d))
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
165
1736
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1402
diff changeset
166 def changegroup(self, nodes, kind):
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
167 n = " ".join(map(hex, nodes))
2449
6ff30968f911 fix unused variable warning from pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2441
diff changeset
168 return self.do_cmd("changegroup", roots=n)
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
169
3446
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
170 def changegroupsubset(self, bases, heads, kind):
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
171 bases = " ".join(map(hex, bases))
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
172 heads = " ".join(map(hex, heads))
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
173 return self.do_cmd("changegroupsubset", bases=bases, heads=heads)
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
174
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
175 def unbundle(self, cg, heads, source):
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
176 d = self.call("unbundle", heads=' '.join(map(hex, heads)))
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
177 if d:
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
178 self.raise_(hg.RepoError(_("push refused: %s") % d))
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
179
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
180 while 1:
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
181 d = cg.read(4096)
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
182 if not d: break
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
183 self.pipeo.write(str(len(d)) + '\n')
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
184 self.pipeo.write(d)
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
185 self.readerr()
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
186
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
187 self.pipeo.write('0\n')
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
188 self.pipeo.flush()
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
189
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
190 self.readerr()
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
191 d = self.pipei.readline()
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
192 if d != '\n':
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
193 return 1
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
194
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
195 l = int(self.pipei.readline())
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
196 r = self.pipei.read(l)
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
197 if not r:
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
198 return 1
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
199 return int(r)
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
200
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
201 def addchangegroup(self, cg, source, url):
639
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
202 d = self.call("addchangegroup")
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
203 if d:
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
204 self.raise_(hg.RepoError(_("push refused: %s") % d))
639
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
205 while 1:
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
206 d = cg.read(4096)
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
207 if not d: break
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
208 self.pipeo.write(d)
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
209 self.readerr()
639
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
210
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
211 self.pipeo.flush()
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
212
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
213 self.readerr()
639
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
214 l = int(self.pipei.readline())
2019
ced2d3620f95 add merge command. means same thing as "update -m".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1736
diff changeset
215 r = self.pipei.read(l)
ced2d3620f95 add merge command. means same thing as "update -m".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1736
diff changeset
216 if not r:
ced2d3620f95 add merge command. means same thing as "update -m".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1736
diff changeset
217 return 1
ced2d3620f95 add merge command. means same thing as "update -m".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1736
diff changeset
218 return int(r)
2612
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2549
diff changeset
219
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2549
diff changeset
220 def stream_out(self):
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2549
diff changeset
221 return self.do_cmd('stream_out')
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
222
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
223 instance = sshrepository