Mercurial > python-hglib
annotate hglib/client.py @ 63:939d1d763bb1
client: add resolve command
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Fri, 19 Aug 2011 22:52:59 +0300 |
parents | d1f57f162274 |
children | a7d98dc798c5 |
rev | line source |
---|---|
21 | 1 import subprocess, os, struct, cStringIO, collections, re |
46
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
2 import hglib, error, util, templates, merge |
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): |
44
3a661f63107e
client: tell the server we're interactive
Idan Kamara <idankk86@gmail.com>
parents:
43
diff
changeset
|
16 args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe', |
3a661f63107e
client: tell the server we're interactive
Idan Kamara <idankk86@gmail.com>
parents:
43
diff
changeset
|
17 '--config', 'ui.interactive=True'] |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 self.server = subprocess.Popen(args, stdin=subprocess.PIPE, |
62
d1f57f162274
closefds on posix when using subprocess
Idan Kamara <idankk86@gmail.com>
parents:
61
diff
changeset
|
27 stdout=subprocess.PIPE, env=env, |
d1f57f162274
closefds on posix when using subprocess
Idan Kamara <idankk86@gmail.com>
parents:
61
diff
changeset
|
28 close_fds=util.closefds) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
29 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 self._readhello() |
41
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
31 self._version = None |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
32 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 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
|
34 """ 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
|
35 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
|
36 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
|
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 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
|
39 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 ", 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
|
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 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
|
46 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 # 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
|
48 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
|
49 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 ", 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
|
54 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 else: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
63 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
|
64 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
65 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
|
66 ''' 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
|
67 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
|
68 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
|
69 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
76 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
|
77 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
|
78 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
79 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
|
80 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
|
81 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
82 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
|
83 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
|
84 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
85 # 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
|
86 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
|
87 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
|
88 # 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
|
89 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
|
90 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
|
91 # 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
|
92 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
|
93 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
|
94 # 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
|
95 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
|
96 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
|
97 % channel) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
98 # 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
|
99 else: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
100 pass |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
101 |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
102 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
|
103 """ |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
104 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
|
105 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
106 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
|
107 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
|
108 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
109 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
|
110 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
|
111 received so far |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
112 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
113 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
|
114 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
|
115 """ |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
116 |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
117 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
|
118 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
|
119 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
120 inchannels = {} |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
121 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
|
122 def func(size): |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
123 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
|
124 return str(reply) |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
125 inchannels['L'] = func |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
126 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
|
127 inchannels['I'] = input |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
128 |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
129 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
|
130 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
|
131 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
132 if ret: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
133 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
|
134 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
|
135 else: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
136 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
|
137 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
|
138 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 |
28 | 146 def add(self, files=[], dryrun=False, subrepos=False, include=None, |
147 exclude=None): | |
148 """ | |
149 Add the specified files on the next commit. | |
150 If no files are given, add all files to the repository. | |
151 | |
152 Return whether all given files were added. | |
153 """ | |
154 if not isinstance(files, list): | |
155 files = [files] | |
156 | |
157 args = cmdbuilder('add', *files, n=dryrun, S=subrepos, I=include, X=exclude) | |
158 | |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
159 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
160 self.rawcommand(args, eh=eh) |
28 | 161 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
162 return bool(eh) |
28 | 163 |
48
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
164 def addremove(self, files=[], similarity=None, dryrun=False, include=None, |
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
165 exclude=None): |
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
166 if not isinstance(files, list): |
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
167 files = [files] |
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
168 |
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
169 args = cmdbuilder('addremove', *files, s=similarity, n=dryrun, I=include, |
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
170 X=exclude) |
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
171 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
172 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
173 self.rawcommand(args, eh=eh) |
48
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
174 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
175 return bool(eh) |
48
82d927ac1329
client: add addremove command
Idan Kamara <idankk86@gmail.com>
parents:
47
diff
changeset
|
176 |
52
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
177 def annotate(self, files, rev=None, nofollow=False, text=False, user=False, |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
178 file=False, date=False, number=False, changeset=False, |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
179 line=False, verbose=False, include=None, exclude=None): |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
180 """ |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
181 Show changeset information by line for each file in files. |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
182 |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
183 yields a (info, contents) tuple for each line in a file |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
184 """ |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
185 if not isinstance(files, list): |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
186 files = [files] |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
187 |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
188 args = cmdbuilder('annotate', *files, r=rev, no_follow=nofollow, a=text, |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
189 u=user, f=file, d=date, n=number, c=changeset, l=line, |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
190 v=verbose, I=include, X=exclude) |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
191 |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
192 out = self.rawcommand(args) |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
193 |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
194 for line in out.splitlines(): |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
195 yield tuple(line.split(': ', 1)) |
18f72b255553
client: add annotate command
Idan Kamara <idankk86@gmail.com>
parents:
51
diff
changeset
|
196 |
53
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
197 def archive(self, dest, rev=None, nodecode=False, prefix=None, type=None, |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
198 subrepos=False, include=None, exclude=None): |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
199 """ |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
200 create an unversioned archive of a repository revision |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
201 """ |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
202 args = cmdbuilder('archive', dest, r=rev, no_decode=nodecode, p=prefix, |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
203 t=type, S=subrepos, I=include, X=exclude) |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
204 |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
205 self.rawcommand(args) |
066dfa5c0b70
client: add archive command
Idan Kamara <idankk86@gmail.com>
parents:
52
diff
changeset
|
206 |
22
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
207 def backout(self, rev, merge=False, parent=None, tool=None, message=None, |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
208 logfile=None, date=None, user=None): |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
209 if message and logfile: |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
210 raise ValueError("cannot specify both a message and a logfile") |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
211 |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
212 args = cmdbuilder('backout', r=rev, merge=merge, parent=parent, t=tool, |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
213 m=message, l=logfile, d=date, u=user) |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
214 |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
215 self.rawcommand(args) |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
216 |
23
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
217 def bookmark(self, name, rev=None, force=False, delete=False, inactive=False, |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
218 rename=None): |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
219 args = cmdbuilder('bookmark', name, r=rev, f=force, d=delete, |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
220 i=inactive, m=rename) |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
221 |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
222 self.rawcommand(args) |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
223 |
24
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
224 def bookmarks(self): |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
225 """ |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
226 Return the bookmarks as a list of (name, rev, node) and the |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
227 index of the current one. |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
228 |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
229 If there isn't a current one, -1 is returned as the index |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
230 """ |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
231 out = self.rawcommand(['bookmarks']) |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
232 |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
233 bms = [] |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
234 current = -1 |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
235 if out.rstrip() != 'no bookmarks set': |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
236 for line in out.splitlines(): |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
237 iscurrent, line = line[0:3], line[3:] |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
238 if '*' in iscurrent: |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
239 current = len(bms) |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
240 name, line = line.split(' ', 1) |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
241 rev, node = line.split(':') |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
242 bms.append((name, int(rev), node)) |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
243 return bms, current |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
244 |
11
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
245 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
|
246 if name and clean: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
247 raise ValueError('cannot use both name and clean') |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
248 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
249 args = cmdbuilder('branch', name, f=force, C=clean) |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
250 out = self.rawcommand(args).rstrip() |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
251 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
252 if name: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
253 return name |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
254 elif not clean: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
255 return out |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
256 else: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
257 # len('reset working directory to branch ') == 34 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
258 return out[34:] |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
259 |
12
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
260 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
|
261 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
|
262 out = self.rawcommand(args) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
263 |
12
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
264 branches = [] |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
265 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
|
266 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
|
267 rev, node = line.split(':') |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
268 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
|
269 branches.append((name, int(rev), node)) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
270 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
|
271 |
54 | 272 def bundle(self, file, destrepo=None, rev=[], branch=[], base=[], all=False, |
273 force=False, type=None, ssh=None, remotecmd=None, insecure=False): | |
274 """ | |
275 create a changegroup file | |
276 | |
277 Return True if a bundle was created, False if no changes were found. | |
278 """ | |
279 args = cmdbuilder('bundle', file, destrepo, f=force, r=rev, b=branch, | |
280 base=base, a=all, t=type, e=ssh, remotecmd=remotecmd, | |
281 insecure=insecure) | |
282 | |
283 eh = util.reterrorhandler(args) | |
284 self.rawcommand(args, eh=eh) | |
285 | |
286 return bool(eh) | |
287 | |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
288 def cat(self, files, rev=None, output=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
289 args = cmdbuilder('cat', *files, r=rev, o=output) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
290 out = self.rawcommand(args) |
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 if not output: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
293 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
|
294 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
295 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
|
296 revrange=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
297 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
|
298 self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
299 |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
300 def commit(self, message=None, logfile=None, addremove=False, closebranch=False, |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
301 date=None, user=None, include=None, exclude=None): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
302 if message is None and logfile is None: |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
303 raise ValueError("must provide at least a message or a logfile") |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
304 elif message and logfile: |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
305 raise ValueError("cannot specify both a message and a logfile") |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
306 |
14
e0d21c9db20b
client: use --debug when committing to get the new node info
Idan Kamara <idankk86@gmail.com>
parents:
13
diff
changeset
|
307 # --debug will print the committed cset |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
308 args = cmdbuilder('commit', debug=True, m=message, A=addremove, |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
309 close_branch=closebranch, d=date, u=user, l=logfile, |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
310 I=include, X=exclude) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
311 |
14
e0d21c9db20b
client: use --debug when committing to get the new node info
Idan Kamara <idankk86@gmail.com>
parents:
13
diff
changeset
|
312 out = self.rawcommand(args) |
e0d21c9db20b
client: use --debug when committing to get the new node info
Idan Kamara <idankk86@gmail.com>
parents:
13
diff
changeset
|
313 rev, node = out.splitlines()[-1].rsplit(':') |
15
f1af31960414
client: change return value of commit() to (rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
14
diff
changeset
|
314 return int(rev.split()[-1]), node |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
315 |
21 | 316 def config(self, names=[], untrusted=False, showsource=False): |
317 """ | |
318 Return a list of (section, key, value) config settings from all hgrc files | |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
319 |
21 | 320 When showsource is specified, return (source, section, key, value) where |
321 source is of the form filename:[line] | |
322 """ | |
323 def splitline(s): | |
324 k, value = s.rstrip().split('=', 1) | |
325 section, key = k.split('.', 1) | |
326 return (section, key, value) | |
327 | |
328 if not isinstance(names, list): | |
329 names = [names] | |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
330 |
21 | 331 args = cmdbuilder('showconfig', *names, u=untrusted, debug=showsource) |
332 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
|
333 |
21 | 334 conf = [] |
335 if showsource: | |
336 out = util.skiplines(out, 'read config from: ') | |
337 for line in out.splitlines(): | |
338 m = re.match(r"(.+?:(?:\d+:)?) (.*)", line) | |
339 t = splitline(m.group(2)) | |
340 conf.append((m.group(1)[:-1], t[0], t[1], t[2])) | |
341 else: | |
342 for line in out.splitlines(): | |
343 conf.append(splitline(line)) | |
344 | |
345 return conf | |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
346 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
347 @property |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
348 def encoding(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
349 """ get the servers encoding """ |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
350 if not 'getencoding' in self.capabilities: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
351 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
|
352 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
353 if not self._encoding: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
354 self.server.stdin.write('getencoding\n') |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
355 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
|
356 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
357 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
|
358 |
29 | 359 def copy(self, source, dest, after=False, force=False, dryrun=False, |
360 include=None, exclude=None): | |
361 if not isinstance(source, list): | |
362 source = [source] | |
363 | |
364 source.append(dest) | |
365 args = cmdbuilder('copy', *source, A=after, f=force, n=dryrun, | |
366 I=include, X=exclude) | |
367 | |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
368 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
369 self.rawcommand(args, eh=eh) |
29 | 370 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
371 return bool(eh) |
29 | 372 |
61
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
373 def diff(self, files=[], revs=[], change=None, text=False, |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
374 git=False, nodates=False, showfunction=False, reverse=False, |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
375 ignoreallspace=False, ignorespacechange=False, ignoreblanklines=False, |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
376 unified=None, stat=False, subrepos=False, include=None, exclude=None): |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
377 if change and revs: |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
378 raise ValueError('cannot specify both change and rev') |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
379 |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
380 args = cmdbuilder('diff', *files, r=revs, c=change, |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
381 a=text, g=git, nodates=nodates, |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
382 p=showfunction, reverse=reverse, |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
383 w=ignoreallspace, b=ignorespacechange, |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
384 B=ignoreblanklines, U=unified, stat=stat, |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
385 S=subrepos, I=include, X=exclude) |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
386 |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
387 return self.rawcommand(args) |
d0b9215180a4
client: fix diff indentation and position
Idan Kamara <idankk86@gmail.com>
parents:
57
diff
changeset
|
388 |
55 | 389 def export(self, revs, output=None, switchparent=False, text=False, git=False, |
390 nodates=False): | |
391 """ | |
392 Return the header and diffs for one or more changesets. When output is | |
393 given, dumps to file. | |
394 """ | |
395 if not isinstance(revs, list): | |
396 revs = [revs] | |
397 args = cmdbuilder('export', *revs, o=output, switch_parent=switchparent, | |
398 a=text, g=git, nodates=nodates) | |
399 | |
400 out = self.rawcommand(args) | |
401 | |
402 if output is None: | |
403 return out | |
404 | |
31 | 405 def forget(self, files, include=None, exclude=None): |
406 if not isinstance(files, list): | |
407 files = [files] | |
408 | |
409 args = cmdbuilder('forget', *files, I=include, X=exclude) | |
410 | |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
411 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
412 self.rawcommand(args, eh=eh) |
31 | 413 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
414 return bool(eh) |
31 | 415 |
56 | 416 def grep(self, pattern, files=[], all=False, text=False, follow=False, |
417 ignorecase=False, fileswithmatches=False, line=False, user=False, | |
418 date=False, include=None, exclude=None): | |
419 """ | |
420 search for a pattern in specified files and revisions | |
421 | |
422 yields (filename, revision, [line, [match status, [user, [date, [match]]]]]) | |
423 per match depending on the given options. | |
424 """ | |
425 if not isinstance(files, list): | |
426 files = [files] | |
427 | |
428 args = cmdbuilder('grep', *[pattern] + files, all=all, a=text, f=follow, | |
429 i=ignorecase, l=fileswithmatches, n=line, u=user, d=date, | |
430 I=include, X=exclude) | |
431 args.append('-0') | |
432 | |
433 def eh(ret, out, err): | |
434 if ret != 1: | |
435 raise error.CommandError(args, ret, out, err) | |
436 return '' | |
437 | |
438 out = self.rawcommand(args, eh=eh).split('\0') | |
439 | |
440 fieldcount = 3 | |
441 if user: | |
442 fieldcount += 1 | |
443 if date: | |
444 fieldcount += 1 | |
445 if line: | |
446 fieldcount += 1 | |
447 if all: | |
448 fieldcount += 1 | |
449 if fileswithmatches: | |
450 fieldcount -= 1 | |
451 | |
452 return util.grouper(fieldcount, out) | |
453 | |
57 | 454 def heads(self, rev=[], startrev=[], topological=False, closed=False): |
455 """ | |
456 Return a list of current repository heads or branch heads | |
457 """ | |
458 if not isinstance(rev, list): | |
459 rev = [rev] | |
460 | |
461 args = cmdbuilder('heads', *rev, r=startrev, t=topological, c=closed, | |
462 template=templates.changeset) | |
463 | |
464 def eh(ret, out, err): | |
465 if ret != 1: | |
466 raise error.CommandError(args, ret, out, err) | |
467 return '' | |
468 | |
469 out = self.rawcommand(args, eh=eh).split('\0')[:-1] | |
470 return self._parserevs(out) | |
471 | |
38
32f6a2bbf63e
client: add identify command
Idan Kamara <idankk86@gmail.com>
parents:
37
diff
changeset
|
472 def identify(self, rev=None, source=None, num=False, id=False, branch=False, |
32f6a2bbf63e
client: add identify command
Idan Kamara <idankk86@gmail.com>
parents:
37
diff
changeset
|
473 tags=False, bookmarks=False): |
32f6a2bbf63e
client: add identify command
Idan Kamara <idankk86@gmail.com>
parents:
37
diff
changeset
|
474 args = cmdbuilder('identify', source, r=rev, n=num, i=id, b=branch, t=tags, |
32f6a2bbf63e
client: add identify command
Idan Kamara <idankk86@gmail.com>
parents:
37
diff
changeset
|
475 B=bookmarks) |
32f6a2bbf63e
client: add identify command
Idan Kamara <idankk86@gmail.com>
parents:
37
diff
changeset
|
476 |
32f6a2bbf63e
client: add identify command
Idan Kamara <idankk86@gmail.com>
parents:
37
diff
changeset
|
477 return self.rawcommand(args) |
32f6a2bbf63e
client: add identify command
Idan Kamara <idankk86@gmail.com>
parents:
37
diff
changeset
|
478 |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
479 def import_(self, patches, strip=None, force=False, nocommit=False, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
480 bypass=False, exact=False, importbranch=False, message=None, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
481 date=None, user=None, similarity=None): |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
482 """ |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
483 patches can be a list of file names with patches to apply |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
484 or a file-like object that contains a patch (needs read and readline) |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
485 """ |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
486 if hasattr(patches, 'read') and hasattr(patches, 'readline'): |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
487 patch = patches |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
488 |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
489 def readline(size, output): |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
490 return patch.readline(size) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
491 |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
492 stdin = True |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
493 patches = () |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
494 prompt = readline |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
495 input = patch.read |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
496 else: |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
497 stdin = False |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
498 prompt = None |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
499 input = None |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
500 |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
501 args = cmdbuilder('import', *patches, strip=strip, force=force, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
502 nocommit=nocommit, bypass=bypass, exact=exact, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
503 importbranch=importbranch, message=message, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
504 date=date, user=user, similarity=similarity, _=stdin) |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
505 |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
506 self.rawcommand(args, prompt=prompt, input=input) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
507 |
25
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
508 def incoming(self, revrange=None, path=None, force=False, newest=False, |
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
509 bundle=None, bookmarks=False, branch=None, limit=None, |
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
510 nomerges=False, subrepos=False): |
27
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
511 """ |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
512 Return new changesets found in the specified path or the default pull |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
513 location. |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
514 |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
515 When bookmarks=True, return a list of (name, node) of incoming bookmarks. |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
516 """ |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
517 args = cmdbuilder('incoming', |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
518 path, |
25
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
519 template=templates.changeset, r=revrange, |
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
520 f=force, n=newest, bundle=bundle, |
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
521 B=bookmarks, b=branch, l=limit, M=nomerges, S=subrepos) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
522 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
523 def eh(ret, out, err): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
524 if ret != 1: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
525 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
|
526 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
527 out = self.rawcommand(args, eh=eh) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
528 if not out: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
529 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
|
530 |
27
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
531 out = util.eatlines(out, 2) |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
532 if bookmarks: |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
533 bms = [] |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
534 for line in out.splitlines(): |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
535 bms.append(tuple(line.split())) |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
536 return bms |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
537 else: |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
538 out = out.split('\0')[:-1] |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
539 return self._parserevs(out) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
540 |
17
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
541 def log(self, revrange=None, files=[], follow=False, followfirst=False, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
542 date=None, copies=False, keyword=None, removed=False, onlymerges=False, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
543 user=None, branch=None, prune=None, hidden=False, limit=None, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
544 nomerges=False, include=None, exclude=None): |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
545 args = cmdbuilder('log', *files, template=templates.changeset, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
546 r=revrange, f=follow, follow_first=followfirst, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
547 d=date, C=copies, k=keyword, removed=removed, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
548 m=onlymerges, u=user, b=branch, P=prune, h=hidden, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
549 l=limit, M=nomerges, I=include, X=exclude) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
550 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
551 out = self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
552 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
|
553 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
554 return self._parserevs(out) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
555 |
46
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
556 def merge(self, rev=None, force=False, tool=None, cb=merge.handlers.abort): |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
557 """ |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
558 merge working directory with another revision |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
559 |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
560 cb can one of merge.handlers, or a function that gets a single argument |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
561 which are the contents of stdout. It should return one of the expected |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
562 choices (a single character). |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
563 """ |
45 | 564 # we can't really use --preview since merge doesn't support --template |
565 args = cmdbuilder('merge', r=rev, f=force, t=tool) | |
566 | |
46
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
567 prompt = None |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
568 if cb is merge.handlers.abort: |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
569 prompt = cb |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
570 elif cb is merge.handlers.noninteractive: |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
571 args.append('-y') |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
572 else: |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
573 prompt = lambda size, output: cb(output) + '\n' |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
574 |
ebcc5d7dd528
client: introduce merge handlers
Idan Kamara <idankk86@gmail.com>
parents:
45
diff
changeset
|
575 self.rawcommand(args, prompt=prompt) |
45 | 576 |
32 | 577 def move(self, source, dest, after=False, force=False, dryrun=False, |
578 include=None, exclude=None): | |
579 if not isinstance(source, list): | |
580 source = [source] | |
581 | |
582 source.append(dest) | |
583 args = cmdbuilder('move', *source, A=after, f=force, n=dryrun, | |
584 I=include, X=exclude) | |
585 | |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
586 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
587 self.rawcommand(args, eh=eh) |
32 | 588 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
589 return bool(eh) |
32 | 590 |
26
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
591 def outgoing(self, revrange=None, path=None, force=False, newest=False, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
592 bookmarks=False, branch=None, limit=None, nomerges=False, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
593 subrepos=False): |
27
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
594 """ |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
595 Return changesets not found in the specified path or the default push |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
596 location. |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
597 |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
598 When bookmarks=True, return a list of (name, node) of bookmarks that will |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
599 be pushed. |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
600 """ |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
601 args = cmdbuilder('outgoing', |
26
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
602 path, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
603 template=templates.changeset, r=revrange, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
604 f=force, n=newest, B=bookmarks, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
605 b=branch, S=subrepos) |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
606 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
607 def eh(ret, out, err): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
608 if ret != 1: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
609 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
|
610 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
611 out = self.rawcommand(args, eh=eh) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
612 if not out: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
613 return [] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
614 |
27
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
615 out = util.eatlines(out, 2) |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
616 if bookmarks: |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
617 bms = [] |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
618 for line in out.splitlines(): |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
619 bms.append(tuple(line.split())) |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
620 return bms |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
621 else: |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
622 out = out.split('\0')[:-1] |
46908f4b87d5
client: add bookmarks support to incoming and outgoing
Idan Kamara <idankk86@gmail.com>
parents:
26
diff
changeset
|
623 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
|
624 |
18
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
625 def parents(self, rev=None, file=None): |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
626 args = cmdbuilder('parents', file, template=templates.changeset, r=rev) |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
627 |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
628 out = self.rawcommand(args) |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
629 if not out: |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
630 return |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
631 |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
632 out = out.split('\0')[:-1] |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
633 |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
634 return self._parserevs(out) |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
635 |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 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
|
640 return {} |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
641 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
642 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
|
643 else: |
4 | 644 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
|
645 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
|
646 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
|
647 |
40 | 648 def pull(self, source=None, rev=None, update=False, force=False, bookmark=None, |
649 branch=None, ssh=None, remotecmd=None, insecure=False, tool=None): | |
650 args = cmdbuilder('pull', source, r=rev, u=update, f=force, B=bookmark, | |
651 b=branch, e=ssh, remotecmd=remotecmd, insecure=insecure, | |
652 t=tool) | |
653 | |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
654 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
655 self.rawcommand(args, eh=eh) |
40 | 656 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
657 return bool(eh) |
40 | 658 |
39 | 659 def push(self, dest=None, rev=None, force=False, bookmark=None, branch=None, |
660 newbranch=False, ssh=None, remotecmd=None, insecure=False): | |
661 args = cmdbuilder('push', dest, r=rev, f=force, B=bookmark, b=branch, | |
662 new_branch=newbranch, e=ssh, remotecmd=remotecmd, | |
663 insecure=insecure) | |
664 | |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
665 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
666 self.rawcommand(args, eh=eh) |
39 | 667 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
668 return bool(eh) |
39 | 669 |
30 | 670 def remove(self, files, after=False, force=False, include=None, exclude=None): |
671 if not isinstance(files, list): | |
672 files = [files] | |
673 | |
674 args = cmdbuilder('remove', *files, A=after, f=force, I=include, X=exclude) | |
675 | |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
676 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
677 self.rawcommand(args, eh=eh) |
30 | 678 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
679 return bool(eh) |
30 | 680 |
63
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
681 def resolve(self, file=[], all=False, listfiles=False, mark=False, unmark=False, |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
682 tool=None, include=None, exclude=None): |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
683 """ |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
684 redo merges or set/view the merge status of files |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
685 |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
686 When listfiles is True, returns a list of (code, file path) of resolved |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
687 and unresolved files. Code will be 'R' or 'U' accordingly. |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
688 """ |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
689 if not isinstance(file, list): |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
690 file = [file] |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
691 |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
692 args = cmdbuilder('resolve', *file, a=all, l=listfiles, m=mark, u=unmark, |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
693 t=tool, I=include, X=exclude) |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
694 |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
695 out = self.rawcommand(args) |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
696 |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
697 if listfiles: |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
698 l = [] |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
699 for line in out.splitlines(): |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
700 l.append(tuple(line.split(' ', 1))) |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
701 return l |
939d1d763bb1
client: add resolve command
Idan Kamara <idankk86@gmail.com>
parents:
62
diff
changeset
|
702 |
47 | 703 def revert(self, files, rev=None, all=False, date=None, nobackup=False, |
704 dryrun=False, include=None, exclude=None): | |
705 if not isinstance(files, list): | |
706 files = [files] | |
707 | |
708 args = cmdbuilder('revert', *files, r=rev, a=all, d=date, | |
709 no_backup=nobackup, n=dryrun, I=include, X=exclude) | |
710 | |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
711 eh = util.reterrorhandler(args) |
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
712 self.rawcommand(args, eh=eh) |
47 | 713 |
50
bd7dfd94b0d9
client: use util.reterrorhandler
Idan Kamara <idankk86@gmail.com>
parents:
48
diff
changeset
|
714 return bool(eh) |
47 | 715 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
716 def root(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
717 return self.rawcommand(['root']).rstrip() |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
718 |
33
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
719 def status(self, rev=None, change=None, all=False, modified=False, added=False, |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
720 removed=False, deleted=False, clean=False, unknown=False, |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
721 ignored=False, copies=False, subrepos=False, include=None, |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
722 exclude=None): |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
723 """ |
34
f6e1d9a6e0cd
client: change return value of status() to a list of (code, file path)
Idan Kamara <idankk86@gmail.com>
parents:
33
diff
changeset
|
724 Return a list of (code, file path) where code can be: |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
725 |
33
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
726 M = modified |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
727 A = added |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
728 R = removed |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
729 C = clean |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
730 ! = missing (deleted by non-hg command, but still tracked) |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
731 ? = untracked |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
732 I = ignored |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
733 = origin of the previous file listed as A (added) |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
734 """ |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
735 if rev and change: |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
736 raise ValueError('cannot specify both rev and change') |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
737 |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
738 args = cmdbuilder('status', rev=rev, change=change, A=all, m=modified, |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
739 a=added, r=removed, d=deleted, c=clean, u=unknown, |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
740 i=ignored, C=copies, S=subrepos, I=include, X=exclude) |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
741 |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
742 args.append('-0') |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
743 |
d74a5891d9d1
client: add missing options to status
Idan Kamara <idankk86@gmail.com>
parents:
32
diff
changeset
|
744 out = self.rawcommand(args) |
34
f6e1d9a6e0cd
client: change return value of status() to a list of (code, file path)
Idan Kamara <idankk86@gmail.com>
parents:
33
diff
changeset
|
745 l = [] |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
746 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
747 for entry in out.split('\0'): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
748 if entry: |
35
1e33bbea23e5
client: handle spaces correctly in status()
Idan Kamara <idankk86@gmail.com>
parents:
34
diff
changeset
|
749 if entry[0] == ' ': |
1e33bbea23e5
client: handle spaces correctly in status()
Idan Kamara <idankk86@gmail.com>
parents:
34
diff
changeset
|
750 l.append((' ', entry[2:])) |
1e33bbea23e5
client: handle spaces correctly in status()
Idan Kamara <idankk86@gmail.com>
parents:
34
diff
changeset
|
751 else: |
1e33bbea23e5
client: handle spaces correctly in status()
Idan Kamara <idankk86@gmail.com>
parents:
34
diff
changeset
|
752 l.append(tuple(entry.split(' ', 1))) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
753 |
34
f6e1d9a6e0cd
client: change return value of status() to a list of (code, file path)
Idan Kamara <idankk86@gmail.com>
parents:
33
diff
changeset
|
754 return l |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
755 |
42 | 756 def tag(self, names, rev=None, message=None, force=False, local=False, |
757 remove=False, date=None, user=None): | |
758 if not isinstance(names, list): | |
759 names = [names] | |
760 | |
761 args = cmdbuilder('tag', *names, r=rev, m=message, f=force, l=local, | |
762 remove=remove, d=date, u=user) | |
763 | |
764 self.rawcommand(args) | |
765 | |
43 | 766 def tags(self): |
767 """ | |
768 Return a list of repository tags as: (name, rev, node, islocal) | |
769 """ | |
770 args = cmdbuilder('tags', v=True) | |
771 | |
772 out = self.rawcommand(args) | |
773 | |
774 t = [] | |
775 for line in out.splitlines(): | |
776 taglocal = line.endswith(' local') | |
777 if taglocal: | |
778 line = line[:-6] | |
779 name, rev = line.rsplit(' ', 1) | |
780 rev, node = rev.split(':') | |
781 t.append((name.rstrip(), int(rev), node, taglocal)) | |
782 return t | |
783 | |
51
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
784 def summary(self, remote=False): |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
785 """ |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
786 Return a dictionary with a brief summary of the working directory state, |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
787 including parents, branch, commit status, and available updates. |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
788 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
789 'parent' : a list of (rev, node, tags, message) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
790 'branch' : the current branch |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
791 'commit' : True if the working directory is clean, False otherwise |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
792 'update' : number of available updates, |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
793 ['remote' : (in, in bookmarks, out, out bookmarks),] |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
794 ['mq': (applied, unapplied) mq patches,] |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
795 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
796 unparsed entries will be of them form key : value |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
797 """ |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
798 args = cmdbuilder('summary', remote=remote) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
799 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
800 out = self.rawcommand(args).splitlines() |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
801 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
802 d = {} |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
803 while out: |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
804 line = out.pop(0) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
805 name, value = line.split(': ', 1) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
806 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
807 if name == 'parent': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
808 parent, tags = value.split(' ', 1) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
809 rev, node = parent.split(':') |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
810 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
811 if tags: |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
812 tags = tags.replace(' (empty repository)', '') |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
813 else: |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
814 tags = None |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
815 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
816 value = d.get(name, []) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
817 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
818 if rev == '-1': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
819 value.append((int(rev), node, tags, None)) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
820 else: |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
821 message = out.pop(0)[1:] |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
822 value.append((int(rev), node, tags, message)) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
823 elif name == 'branch': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
824 pass |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
825 elif name == 'commit': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
826 value = value == '(clean)' |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
827 elif name == 'update': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
828 if value == '(current)': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
829 value = 0 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
830 else: |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
831 value = int(value.split(' ', 1)[0]) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
832 elif remote and name == 'remote': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
833 if value == '(synced)': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
834 value = 0, 0, 0, 0 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
835 else: |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
836 inc = incb = out_ = outb = 0 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
837 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
838 for v in value.split(', '): |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
839 count, v = v.split(' ', 1) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
840 if v == 'outgoing': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
841 out_ = int(count) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
842 elif v.endswith('incoming'): |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
843 inc = int(count) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
844 elif v == 'incoming bookmarks': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
845 incb = int(count) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
846 elif v == 'outgoing bookmarks': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
847 outb = int(count) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
848 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
849 value = inc, incb, out_, outb |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
850 elif name == 'mq': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
851 applied = unapplied = 0 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
852 for v in value.split(', '): |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
853 count, v = v.split(' ', 1) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
854 if v == 'applied': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
855 applied = int(count) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
856 elif v == 'unapplied': |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
857 unapplied = int(count) |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
858 value = applied, unapplied |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
859 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
860 d[name] = value |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
861 |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
862 return d |
c52383a550fb
client: add summary command
Idan Kamara <idankk86@gmail.com>
parents:
50
diff
changeset
|
863 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
864 def tip(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
865 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
|
866 out = self.rawcommand(args) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
867 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
|
868 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
869 return self._parserevs(out)[0] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
870 |
20 | 871 def update(self, rev=None, clean=False, check=False, date=None): |
872 """ | |
873 Update the repository's working directory to changeset specified by rev. | |
874 If rev isn't specified, update to the tip of the current named branch. | |
875 | |
876 Return the number of files (updated, merged, removed, unresolved) | |
877 """ | |
878 if clean and check: | |
879 raise ValueError('clean and check cannot both be True') | |
880 | |
881 args = cmdbuilder('update', r=rev, C=clean, c=check, d=date) | |
882 | |
883 def eh(ret, out, err): | |
884 if ret == 1: | |
885 return out | |
886 | |
887 raise error.CommandError(args, ret, out, err) | |
888 | |
889 | |
890 out = self.rawcommand(args, eh=eh) | |
891 | |
892 # filter out 'merging ...' lines | |
893 out = util.skiplines(out, 'merging ') | |
894 | |
895 counters = out.rstrip().split(', ') | |
896 return tuple(int(s.split(' ', 1)[0]) for s in counters) | |
41
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
897 |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
898 @property |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
899 def version(self): |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
900 if self._version is None: |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
901 v = self.rawcommand(cmdbuilder('version', q=True)) |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
902 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?', |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
903 v).groups()) |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
904 |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
905 for i in range(3): |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
906 try: |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
907 v[i] = int(v[i]) |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
908 except TypeError: |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
909 v[i] = 0 |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
910 |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
911 self._version = tuple(v) |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
912 |
e185c3922c68
client: add version command
Idan Kamara <idankk86@gmail.com>
parents:
40
diff
changeset
|
913 return self._version |