Mercurial > python-hglib
annotate hglib/client.py @ 12:c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Wed, 10 Aug 2011 00:24:01 +0300 |
parents | 0549d00a617d |
children | 400cb1520834 |
rev | line source |
---|---|
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
1 import subprocess, os, struct, cStringIO, collections |
6
96f8c5095e2e
client: use --template instead of --style for cset display
Idan Kamara <idankk86@gmail.com>
parents:
5
diff
changeset
|
2 import hglib, error, util, templates |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
3 |
4 | 4 from util import cmdbuilder |
5 | |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 class hgclient(object): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 inputfmt = '>I' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 outputfmt = '>cI' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
9 outputfmtsize = struct.calcsize(outputfmt) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 retfmt = '>i' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
11 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 revision = collections.namedtuple('revision', 'rev, node, tags, ' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 'branch, author, desc') |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
15 def __init__(self, path, encoding, configs): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe'] |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 if path: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 args += ['-R', path] |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 if configs: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 args += ['--config'] + configs |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 env = dict(os.environ) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 if encoding: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
23 env['HGENCODING'] = encoding |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
24 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 self.server = subprocess.Popen(args, stdin=subprocess.PIPE, |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 stdout=subprocess.PIPE, env=env) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
27 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 self._readhello() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
29 self._config = {} |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
31 def _readhello(self): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
32 """ read the hello message the server sends when started """ |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 ch, msg = self._readchannel() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 assert ch == 'o' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
36 msg = msg.split('\n') |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
37 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 self.capabilities = msg[0][len('capabilities: '):] |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
39 if not self.capabilities: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
40 raise error.ResponseError("bad hello message: expected 'capabilities: '" |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
41 ", got %r" % msg[0]) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
42 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
43 self.capabilities = set(self.capabilities.split()) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
44 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
45 # at the very least the server should be able to run commands |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
46 assert 'runcommand' in self.capabilities |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
48 self._encoding = msg[1][len('encoding: '):] |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
49 if not self._encoding: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
50 raise error.ResponseError("bad hello message: expected 'encoding: '" |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
51 ", got %r" % msg[1]) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
52 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
53 def _readchannel(self): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
54 data = self.server.stdout.read(hgclient.outputfmtsize) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
55 if not data: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
56 raise error.ServerError() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
57 channel, length = struct.unpack(hgclient.outputfmt, data) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
58 if channel in 'IL': |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
59 return channel, length |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
60 else: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
61 return channel, self.server.stdout.read(length) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
62 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
63 def _parserevs(self, splitted): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
64 ''' splitted is a list of fields according to our rev.style, where each 6 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
65 fields compose one revision. ''' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
66 return [self.revision._make(rev) for rev in util.grouper(6, splitted)] |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
67 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
68 def runcommand(self, args, inchannels, outchannels): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
69 def writeblock(data): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
70 self.server.stdin.write(struct.pack(self.inputfmt, len(data))) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
71 self.server.stdin.write(data) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
72 self.server.stdin.flush() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
73 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
74 if not self.server: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
75 raise ValueError("server not connected") |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
76 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
77 self.server.stdin.write('runcommand\n') |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
78 writeblock('\0'.join(args)) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
79 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
80 while True: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
81 channel, data = self._readchannel() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
82 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
83 # input channels |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
84 if channel in inchannels: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
85 writeblock(inchannels[channel](data)) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
86 # output channels |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
87 elif channel in outchannels: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
88 outchannels[channel](data) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
89 # result channel, command finished |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
90 elif channel == 'r': |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
91 return struct.unpack(hgclient.retfmt, data)[0] |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
92 # a channel that we don't know and can't ignore |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
93 elif channel.isupper(): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
94 raise error.ResponseError("unexpected data on required channel '%s'" |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
95 % channel) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
96 # optional channel |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
97 else: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
98 pass |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
99 |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
100 def rawcommand(self, args, eh=None, prompt=None, input=None): |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
101 """ |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
102 args is the cmdline (usually built using util.cmdbuilder) |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
103 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
104 eh is an error handler that is passed the return code, stdout and stderr |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
105 If no eh is given, we raise a CommandError if ret != 0 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
106 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
107 prompt is used to reply to prompts by the server |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
108 It receives the max number of bytes to return and the contents of stdout |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
109 received so far |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
110 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
111 input is used to reply to bulk data requests by the server |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
112 It receives the max number of bytes to return |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
113 """ |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
114 |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
115 out, err = cStringIO.StringIO(), cStringIO.StringIO() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
116 outchannels = {'o' : out.write, 'e' : err.write} |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
117 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
118 inchannels = {} |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
119 if prompt is not None: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
120 def func(size): |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
121 reply = prompt(size, out.getvalue()) |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
122 return str(reply) |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
123 inchannels['L'] = func |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
124 if input is not None: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
125 inchannels['I'] = input |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
126 |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
127 ret = self.runcommand(args, inchannels, outchannels) |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
128 out, err = out.getvalue(), err.getvalue() |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
129 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
130 if ret: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
131 if eh is None: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
132 raise error.CommandError(args, ret, out, err) |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
133 else: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
134 return eh(ret, out, err) |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
135 return out |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
136 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
137 def close(self): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
138 self.server.stdin.close() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
139 self.server.wait() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
140 ret = self.server.returncode |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
141 self.server = None |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
142 return ret |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
143 |
11
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
144 def branch(self, name=None, clean=False, force=False): |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
145 if name and clean: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
146 raise ValueError('cannot use both name and clean') |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
147 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
148 args = cmdbuilder('branch', name, f=force, C=clean) |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
149 out = self.rawcommand(args).rstrip() |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
150 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
151 if name: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
152 return name |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
153 elif not clean: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
154 return out |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
155 else: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
156 # len('reset working directory to branch ') == 34 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
157 return out[34:] |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
158 |
12
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
159 def branches(self, active=False, closed=False): |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
160 args = cmdbuilder('branches', a=active, c=closed) |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
161 out = self.rawcommand(args) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
162 |
12
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
163 branches = [] |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
164 for line in out.rstrip().splitlines(): |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
165 name, line = line.split(' ', 1) |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
166 rev, node = line.split(':') |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
167 node = node.split()[0] # get rid of ' (inactive)' |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
168 branches.append((name, int(rev), node)) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
169 return branches |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
170 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
171 def cat(self, files, rev=None, output=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
172 args = cmdbuilder('cat', *files, r=rev, o=output) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
173 out = self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
174 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
175 if not output: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
176 return out |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
177 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
178 def clone(self, source='.', dest=None, branch=None, updaterev=None, |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
179 revrange=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
180 args = cmdbuilder('clone', source, dest, b=branch, u=updaterev, r=revrange) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
181 self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
182 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
183 def commit(self, message, addremove=False): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
184 args = cmdbuilder('commit', m=message, A=addremove) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
185 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
186 self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
187 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
188 # hope the tip hasn't changed since we committed |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
189 return self.tip() |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
190 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
191 def config(self, refresh=False): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
192 if not self._config or refresh: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
193 self._config.clear() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
194 |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
195 out = self.rawcommand(['showconfig']) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
196 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
197 for entry in cStringIO.StringIO(out): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
198 k, v = entry.rstrip().split('=', 1) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
199 section, name = k.split('.', 1) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
200 self._config.setdefault(section, {})[name] = v |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
201 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
202 return self._config |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
203 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
204 @property |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
205 def encoding(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
206 """ get the servers encoding """ |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
207 if not 'getencoding' in self.capabilities: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
208 raise CapabilityError('getencoding') |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
209 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
210 if not self._encoding: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
211 self.server.stdin.write('getencoding\n') |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
212 self._encoding = self._readfromchannel('r') |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
213 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
214 return self._encoding |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
215 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
216 def import_(self, patch): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
217 if isinstance(patch, str): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
218 fp = open(patch) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
219 else: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
220 assert hasattr(patch, 'read') |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
221 assert hasattr(patch, 'readline') |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
222 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
223 fp = patch |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
224 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
225 try: |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
226 def readline(size, output): |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
227 return fp.readline(size) |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
228 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
229 self.rawcommand(cmdbuilder('import', _=True), |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
230 prompt=readline, input=fp.read) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
231 finally: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
232 if fp != patch: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
233 fp.close() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
234 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
235 def incoming(self, revrange=None, path=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
236 args = cmdbuilder('incoming', |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
237 path, |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
238 template=templates.changeset, rev=revrange) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
239 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
240 def eh(ret, out, err): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
241 if ret != 1: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
242 raise error.CommandError(args, ret, out, err) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
243 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
244 out = self.rawcommand(args, eh=eh) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
245 if not out: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
246 return [] |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
247 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
248 out = util.eatlines(out, 2).split('\0')[:-1] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
249 return self._parserevs(out) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
250 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
251 def log(self, revrange=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
252 args = cmdbuilder('log', template=templates.changeset, rev=revrange) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
253 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
254 out = self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
255 out = out.split('\0')[:-1] |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
256 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
257 return self._parserevs(out) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
258 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
259 def outgoing(self, revrange=None, path=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
260 args = cmdbuilder('outgoing', |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
261 path, template=templates.changeset, rev=revrange) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
262 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
263 def eh(ret, out, err): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
264 if ret != 1: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
265 raise error.CommandError(args, ret, out, err) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
266 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
267 out = self.rawcommand(args, eh=eh) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
268 if not out: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
269 return [] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
270 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
271 out = util.eatlines(out, 2).split('\0')[:-1] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
272 return self._parserevs(out) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
273 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
274 def paths(self, name=None): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
275 if not name: |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
276 out = self.rawcommand(['paths']) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
277 if not out: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
278 return {} |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
279 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
280 return dict([s.split(' = ') for s in out.rstrip().split('\n')]) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
281 else: |
4 | 282 args = cmdbuilder('paths', name) |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
283 out = self.rawcommand(args) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
284 return out.rstrip() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
285 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
286 def root(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
287 return self.rawcommand(['root']).rstrip() |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
288 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
289 def status(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
290 out = self.rawcommand(['status', '-0']) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
291 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
292 d = dict((c, []) for c in 'MARC!?I') |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
293 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
294 for entry in out.split('\0'): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
295 if entry: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
296 t, f = entry.split(' ', 1) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
297 d[t].append(f) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
298 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
299 return d |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
300 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
301 def tip(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
302 args = cmdbuilder('tip', template=templates.changeset) |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
303 out = self.rawcommand(args) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
304 out = out.split('\0') |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
305 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
306 return self._parserevs(out)[0] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
307 |