annotate hglib/client.py @ 52:18f72b255553

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