mercurial/sshrepo.py
author Matt Mackall <mpm@selenic.com>
Sat, 19 Jun 2010 13:00:01 -0500
changeset 11405 bf5d88c466e0
parent 11369 02a4373ca5cd
child 11586 ddaaaa23bb8f
permissions -rw-r--r--
revrange: attempt to parse old-style queries as a first pass
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8210
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9878
diff changeset
     6
# GNU General Public License version 2 or any later version.
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     7
6211
f89fd07fc51d Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents: 6001
diff changeset
     8
from node import bin, hex
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
     9
from i18n import _
9861
0262bb59016f support encoding fallback in branchmap to maintain compatibility with 1.3.x
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 9467
diff changeset
    10
import repo, util, error, encoding
8563
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
    11
import re, urllib
60
e32fdbd97839 Add hg:// protocol
mpm@selenic.com
parents: 56
diff changeset
    12
6313
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    13
class remotelock(object):
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    14
    def __init__(self, repo):
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    15
        self.repo = repo
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    16
    def release(self):
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    17
        self.repo.unlock()
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    18
        self.repo = None
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    19
    def __del__(self):
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    20
        if self.repo:
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    21
            self.release()
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    22
c5580db9c3aa remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
    23
class sshrepository(repo.repository):
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
    24
    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
    25
        self._url = path
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
    26
        self.ui = ui
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
    27
3599
e00920b4f1cb sshrepo: fix the parsing of the ssh url
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3447
diff changeset
    28
        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
    29
        if not m:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    30
            self.abort(error.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
    31
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
    32
        self.user = m.group(2)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
    33
        self.host = m.group(3)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
    34
        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
    35
        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
    36
961
3e11d5038649 Add --ssh and --remotecmd to push
mpm@selenic.com
parents: 934
diff changeset
    37
        sshcmd = self.ui.config("ui", "ssh", "ssh")
3e11d5038649 Add --ssh and --remotecmd to push
mpm@selenic.com
parents: 934
diff changeset
    38
        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
    39
5644
e2e8e977a6cb win32: fix ssh://host:port when using Plink
Steve Borho <steve@borho.org>
parents: 5293
diff changeset
    40
        args = util.sshargs(sshcmd, self.host, self.user, self.port)
e2e8e977a6cb win32: fix ssh://host:port when using Plink
Steve Borho <steve@borho.org>
parents: 5293
diff changeset
    41
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
    42
        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
    43
            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
    44
            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
    45
6953
63b5f4c73c98 i18n: mark strings for translation in Mercurial
Martin Geisler <mg@daimi.au.dk>
parents: 6313
diff changeset
    46
            ui.note(_('running %s\n') % cmd)
5292
5a65d870871d sshrepo: fix Windows command quoting
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5190
diff changeset
    47
            res = util.system(cmd)
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
    48
            if res != 0:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    49
                self.abort(error.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
    50
e1831f06eef1 Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents: 2484
diff changeset
    51
        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
    52
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
    53
    def url(self):
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
    54
        return self._url
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
    55
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
    56
    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
    57
        # 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
    58
        self.cleanup()
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    59
1330
0fcde73dc3ca Give ssh a better chance of working on Windows.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1251
diff changeset
    60
        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
    61
        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
    62
5292
5a65d870871d sshrepo: fix Windows command quoting
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5190
diff changeset
    63
        cmd = util.quotecommand(cmd)
6953
63b5f4c73c98 i18n: mark strings for translation in Mercurial
Martin Geisler <mg@daimi.au.dk>
parents: 6313
diff changeset
    64
        ui.note(_('running %s\n') % cmd)
8339
f55869abb5c3 util: remove ignored mode argument in popen[23]
Martin Geisler <mg@lazybytes.net>
parents: 8312
diff changeset
    65
        self.pipeo, self.pipei, self.pipee = util.popen3(cmd)
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
    66
2028
1f1fc418a96c ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents: 2019
diff changeset
    67
        # skip any noise generated by remote shell
2421
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
    68
        self.do_cmd("hello")
2028
1f1fc418a96c ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents: 2019
diff changeset
    69
        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
    70
        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
    71
        max_noise = 500
2420
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
    72
        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
    73
            l = r.readline()
2028
1f1fc418a96c ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents: 2019
diff changeset
    74
            self.readerr()
2420
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
    75
            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
    76
                break
2420
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
    77
            if l:
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 8563
diff changeset
    78
                ui.debug("remote: ", l)
2420
144280f1578f ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents: 2230
diff changeset
    79
            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
    80
            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
    81
        else:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    82
            self.abort(error.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
    83
8150
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 7873
diff changeset
    84
        self.capabilities = set()
8210
344751cd8cb8 replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents: 8150
diff changeset
    85
        for l in reversed(lines):
2421
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
    86
            if l.startswith("capabilities:"):
5258
b534c502bfb3 Turn capabilities into a mutable set, instead of a fixed tuple.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5196
diff changeset
    87
                self.capabilities.update(l[:-1].split(":")[1].split())
2421
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
    88
                break
a1cfe679192c ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents: 2420
diff changeset
    89
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
    90
    def readerr(self):
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
    91
        while 1:
2176
9b42304d9896 fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2046
diff changeset
    92
            size = util.fstat(self.pipee).st_size
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    93
            if size == 0:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    94
                break
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
    95
            l = self.pipee.readline()
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    96
            if not l:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    97
                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
    98
            self.ui.status(_("remote: "), l)
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
    99
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   100
    def abort(self, exception):
3380
8770b4870e22 portability fix for test-ssh
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3275
diff changeset
   101
        self.cleanup()
3765
768ba23c948e Change sshrepo.repoerror() into a more flexible sshrepo.raise_().
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3764
diff changeset
   102
        raise exception
3380
8770b4870e22 portability fix for test-ssh
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3275
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
    def cleanup(self):
817
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
   105
        try:
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
   106
            self.pipeo.close()
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
   107
            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
   108
            # 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
   109
            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
   110
                self.ui.status(_("remote: "), l)
817
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
   111
            self.pipee.close()
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
   112
        except:
cf1d9a01dd92 Make ssh URL parsing more robust
mpm@selenic.com
parents: 816
diff changeset
   113
            pass
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   114
3034
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
   115
    __del__ = cleanup
2b0bc36a48d8 sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
   116
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   117
    def do_cmd(self, cmd, **args):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 8563
diff changeset
   118
        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
   119
        self.pipeo.write("%s\n" % cmd)
11366
1765897fc497 sshrepo: sort arguments
Matt Mackall <mpm@selenic.com>
parents: 11153
diff changeset
   120
        for k, v in sorted(args.iteritems()):
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   121
            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
   122
            self.pipeo.write(v)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   123
        self.pipeo.flush()
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   124
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   125
        return self.pipei
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   126
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   127
    def call(self, cmd, **args):
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   128
        self.do_cmd(cmd, **args)
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   129
        return self._recv()
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   130
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   131
    def _recv(self):
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   132
        l = self.pipei.readline()
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
   133
        self.readerr()
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
   134
        try:
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
   135
            l = int(l)
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
   136
        except:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   137
            self.abort(error.ResponseError(_("unexpected response:"), l))
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   138
        return self.pipei.read(l)
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   139
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   140
    def _send(self, data, flush=False):
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   141
        self.pipeo.write("%d\n" % len(data))
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   142
        if data:
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   143
            self.pipeo.write(data)
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   144
        if flush:
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   145
            self.pipeo.flush()
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   146
        self.readerr()
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   147
638
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
   148
    def lock(self):
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
   149
        self.call("lock")
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
   150
        return remotelock(self)
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
   151
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
   152
    def unlock(self):
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
   153
        self.call("unlock")
35f7adfefa69 Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents: 637
diff changeset
   154
3446
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
   155
    def lookup(self, key):
5259
65dc707606ed Push capability checking into protocol-level code.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5258
diff changeset
   156
        self.requirecap('lookup', _('look up remote revision'))
3446
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
   157
        d = self.call("lookup", key=key)
3447
ef1032c223e7 sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents: 3446
diff changeset
   158
        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
   159
        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
   160
            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
   161
        else:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   162
            self.abort(error.RepoError(data))
3446
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
   163
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   164
    def heads(self):
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   165
        d = self.call("heads")
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   166
        try:
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   167
            return map(bin, d[:-1].split(" "))
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   168
        except:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   169
            self.abort(error.ResponseError(_("unexpected response:"), d))
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   170
8563
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   171
    def branchmap(self):
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   172
        d = self.call("branchmap")
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   173
        try:
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   174
            branchmap = {}
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   175
            for branchpart in d.splitlines():
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   176
                branchheads = branchpart.split(' ')
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   177
                branchname = urllib.unquote(branchheads[0])
9878
7e7d56fe4833 branchmap: fix defective fallback fix 0262bb59016f
Sune Foldager <cryo@cyanite.org>
parents: 9861
diff changeset
   178
                # Earlier servers (1.3.x) send branch names in (their) local
7e7d56fe4833 branchmap: fix defective fallback fix 0262bb59016f
Sune Foldager <cryo@cyanite.org>
parents: 9861
diff changeset
   179
                # charset. The best we can do is assume it's identical to our
7e7d56fe4833 branchmap: fix defective fallback fix 0262bb59016f
Sune Foldager <cryo@cyanite.org>
parents: 9861
diff changeset
   180
                # own local charset, in case it's not utf-8.
9861
0262bb59016f support encoding fallback in branchmap to maintain compatibility with 1.3.x
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 9467
diff changeset
   181
                try:
9878
7e7d56fe4833 branchmap: fix defective fallback fix 0262bb59016f
Sune Foldager <cryo@cyanite.org>
parents: 9861
diff changeset
   182
                    branchname.decode('utf-8')
9861
0262bb59016f support encoding fallback in branchmap to maintain compatibility with 1.3.x
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 9467
diff changeset
   183
                except UnicodeDecodeError:
9878
7e7d56fe4833 branchmap: fix defective fallback fix 0262bb59016f
Sune Foldager <cryo@cyanite.org>
parents: 9861
diff changeset
   184
                    branchname = encoding.fromlocal(branchname)
8563
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   185
                branchheads = [bin(x) for x in branchheads[1:]]
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   186
                branchmap[branchname] = branchheads
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   187
            return branchmap
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   188
        except:
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   189
            raise error.ResponseError(_("unexpected response:"), d)
f8ff65a83169 named branches: client branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents: 8339
diff changeset
   190
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   191
    def branches(self, nodes):
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   192
        n = " ".join(map(hex, nodes))
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   193
        d = self.call("branches", nodes=n)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   194
        try:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   195
            br = [tuple(map(bin, b.split(" "))) for b in d.splitlines()]
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   196
            return br
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   197
        except:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   198
            self.abort(error.ResponseError(_("unexpected response:"), d))
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   199
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   200
    def between(self, pairs):
7207
fe0a4ed4634f protocol/between: the protocol expects to have ' '-separated tuples
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7106
diff changeset
   201
        n = " ".join(["-".join(map(hex, p)) for p in pairs])
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   202
        d = self.call("between", pairs=n)
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   203
        try:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   204
            p = [l and map(bin, l.split(" ")) or [] for l in d.splitlines()]
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   205
            return p
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   206
        except:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   207
            self.abort(error.ResponseError(_("unexpected response:"), d))
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   208
1736
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1402
diff changeset
   209
    def changegroup(self, nodes, kind):
624
876333a295ff Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents: 623
diff changeset
   210
        n = " ".join(map(hex, nodes))
2449
6ff30968f911 fix unused variable warning from pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2441
diff changeset
   211
        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
   212
3446
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
   213
    def changegroupsubset(self, bases, heads, kind):
5259
65dc707606ed Push capability checking into protocol-level code.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5258
diff changeset
   214
        self.requirecap('changegroupsubset', _('look up remote changes'))
3446
0b450267cf47 Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3380
diff changeset
   215
        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
   216
        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
   217
        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
   218
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
   219
    def unbundle(self, cg, heads, source):
11153
9936ed1d04f4 push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents: 10282
diff changeset
   220
        '''Send cg (a readable file-like object representing the
9936ed1d04f4 push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents: 10282
diff changeset
   221
        changegroup to push, typically a chunkbuffer object) to the
9936ed1d04f4 push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents: 10282
diff changeset
   222
        remote server as a bundle. Return an integer indicating the
9936ed1d04f4 push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents: 10282
diff changeset
   223
        result of the push (see localrepository.addchangegroup()).'''
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
   224
        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
   225
        if d:
5190
6d5ed61c508c Fix sshrepo.unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3891
diff changeset
   226
            # remote may send "unsynced changes"
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   227
            self.abort(error.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
   228
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
   229
        while 1:
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
   230
            d = cg.read(4096)
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   231
            if not d:
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   232
                break
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   233
            self._send(d)
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
   234
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   235
        self._send("", flush=True)
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
   236
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   237
        r = self._recv()
5190
6d5ed61c508c Fix sshrepo.unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3891
diff changeset
   238
        if r:
6d5ed61c508c Fix sshrepo.unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3891
diff changeset
   239
            # remote may send "unsynced changes"
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   240
            self.abort(error.RepoError(_("push failed: %s") % r))
5190
6d5ed61c508c Fix sshrepo.unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3891
diff changeset
   241
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   242
        r = self._recv()
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   243
        try:
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   244
            return int(r)
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   245
        except:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   246
            self.abort(error.ResponseError(_("unexpected response:"), r))
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2421
diff changeset
   247
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
   248
    def addchangegroup(self, cg, source, url):
11153
9936ed1d04f4 push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents: 10282
diff changeset
   249
        '''Send a changegroup to the remote server.  Return an integer
9936ed1d04f4 push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents: 10282
diff changeset
   250
        similar to unbundle(). DEPRECATED, since it requires locking the
9936ed1d04f4 push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents: 10282
diff changeset
   251
        remote.'''
639
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
   252
        d = self.call("addchangegroup")
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
   253
        if d:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   254
            self.abort(error.RepoError(_("push refused: %s") % d))
639
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
   255
        while 1:
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
   256
            d = cg.read(4096)
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   257
            if not d:
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   258
                break
639
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
   259
            self.pipeo.write(d)
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
   260
            self.readerr()
639
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
   261
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
   262
        self.pipeo.flush()
31cebba881a0 Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents: 638
diff changeset
   263
646
342927da4f4c Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents: 644
diff changeset
   264
        self.readerr()
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   265
        r = self._recv()
2019
ced2d3620f95 add merge command. means same thing as "update -m".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1736
diff changeset
   266
        if not r:
ced2d3620f95 add merge command. means same thing as "update -m".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1736
diff changeset
   267
            return 1
5978
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   268
        try:
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   269
            return int(r)
7939c71f3132 sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5293
diff changeset
   270
        except:
7642
84346894def8 sshrepo: change raise_ to abort
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
   271
            self.abort(error.ResponseError(_("unexpected response:"), r))
2612
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2549
diff changeset
   272
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2549
diff changeset
   273
    def stream_out(self):
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2549
diff changeset
   274
        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
   275
11369
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   276
    def pushkey(self, namespace, key, old, new):
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   277
        if not self.capable('pushkey'):
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   278
            return False
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   279
        d = self.call("pushkey",
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   280
                      namespace=namespace, key=key, old=old, new=new)
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   281
        return bool(int(d))
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   282
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   283
    def listkeys(self, namespace):
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   284
        if not self.capable('pushkey'):
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   285
            return {}
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   286
        d = self.call("listkeys", namespace=namespace)
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   287
        r = {}
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   288
        for l in d.splitlines():
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   289
            k, v = l.split('\t')
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   290
            r[k.decode('string-escape')] = v.decode('string-escape')
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   291
        return r
02a4373ca5cd pushkey: add ssh support
Matt Mackall <mpm@selenic.com>
parents: 11366
diff changeset
   292
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
   293
instance = sshrepository