Mercurial > python-hglib
annotate hglib/client.py @ 26:b4e5c8745ef3
client: add missing options to outgoing
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Thu, 11 Aug 2011 22:58:38 +0300 |
parents | 85ae94b98324 |
children | 46908f4b87d5 |
rev | line source |
---|---|
21 | 1 import subprocess, os, struct, cStringIO, collections, re |
6
96f8c5095e2e
client: use --template instead of --style for cset display
Idan Kamara <idankk86@gmail.com>
parents:
5
diff
changeset
|
2 import hglib, error, util, templates |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
3 |
4 | 4 from util import cmdbuilder |
5 | |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 class hgclient(object): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 inputfmt = '>I' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 outputfmt = '>cI' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
9 outputfmtsize = struct.calcsize(outputfmt) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 retfmt = '>i' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
11 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 revision = collections.namedtuple('revision', 'rev, node, tags, ' |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 'branch, author, desc') |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
15 def __init__(self, path, encoding, configs): |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe'] |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 if path: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 args += ['-R', path] |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 if configs: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 args += ['--config'] + configs |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 env = dict(os.environ) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 if encoding: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
23 env['HGENCODING'] = encoding |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
24 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 self.server = subprocess.Popen(args, stdin=subprocess.PIPE, |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 stdout=subprocess.PIPE, env=env) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
27 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 self._readhello() |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
29 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 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
|
31 """ 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
|
32 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
|
33 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
|
34 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 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
|
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 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
|
38 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
|
39 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
|
40 ", 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
|
41 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
42 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
|
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 # 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
|
45 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
|
46 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 ", 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
|
51 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 else: |
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, 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
|
61 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
62 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
|
63 ''' 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
|
64 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
|
65 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
|
66 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
73 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
|
74 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
|
75 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
76 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
|
77 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
|
78 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
79 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
|
80 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
|
81 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
82 # 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
|
83 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
|
84 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
|
85 # 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
|
86 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
|
87 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
|
88 # 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
|
89 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
|
90 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
|
91 # 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
|
92 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
|
93 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
|
94 % channel) |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
95 # 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
|
96 else: |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
97 pass |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
98 |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
99 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
|
100 """ |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
101 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
|
102 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
103 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
|
104 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
|
105 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
106 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
|
107 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
|
108 received so far |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
109 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
110 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
|
111 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
|
112 """ |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
113 |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
114 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
|
115 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
|
116 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
117 inchannels = {} |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
118 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
|
119 def func(size): |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
120 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
|
121 return str(reply) |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
122 inchannels['L'] = func |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
123 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
|
124 inchannels['I'] = input |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
125 |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
126 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
|
127 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
|
128 |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
129 if ret: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
130 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
|
131 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
|
132 else: |
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
133 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
|
134 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
|
135 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 |
22
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
143 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
|
144 logfile=None, date=None, user=None): |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
145 if message and logfile: |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
146 raise ValueError("cannot specify both a message and a logfile") |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
147 |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
148 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
|
149 m=message, l=logfile, d=date, u=user) |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
150 |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
151 self.rawcommand(args) |
297df22d6091
client: add backout command
Idan Kamara <idankk86@gmail.com>
parents:
21
diff
changeset
|
152 |
23
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
153 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
|
154 rename=None): |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
155 args = cmdbuilder('bookmark', name, r=rev, f=force, d=delete, |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
156 i=inactive, m=rename) |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
157 |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
158 self.rawcommand(args) |
223e463c25e0
client: add bookmark command
Idan Kamara <idankk86@gmail.com>
parents:
22
diff
changeset
|
159 |
24
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
160 def bookmarks(self): |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
161 """ |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
162 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
|
163 index of the current one. |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
164 |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
165 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
|
166 """ |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
167 out = self.rawcommand(['bookmarks']) |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
168 |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
169 bms = [] |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
170 current = -1 |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
171 if out.rstrip() != 'no bookmarks set': |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
172 for line in out.splitlines(): |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
173 iscurrent, line = line[0:3], line[3:] |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
174 if '*' in iscurrent: |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
175 current = len(bms) |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
176 name, line = line.split(' ', 1) |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
177 rev, node = line.split(':') |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
178 bms.append((name, int(rev), node)) |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
179 return bms, current |
ca0d7e212cf8
client: add bookmarks command
Idan Kamara <idankk86@gmail.com>
parents:
23
diff
changeset
|
180 |
11
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
181 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
|
182 if name and clean: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
183 raise ValueError('cannot use both name and clean') |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
184 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
185 args = cmdbuilder('branch', name, f=force, C=clean) |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
186 out = self.rawcommand(args).rstrip() |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
187 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
188 if name: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
189 return name |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
190 elif not clean: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
191 return out |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
192 else: |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
193 # len('reset working directory to branch ') == 34 |
0549d00a617d
client: add missing options to branch()
Idan Kamara <idankk86@gmail.com>
parents:
10
diff
changeset
|
194 return out[34:] |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
195 |
12
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
196 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
|
197 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
|
198 out = self.rawcommand(args) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
199 |
12
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
200 branches = [] |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
201 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
|
202 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
|
203 rev, node = line.split(':') |
c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
Idan Kamara <idankk86@gmail.com>
parents:
11
diff
changeset
|
204 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
|
205 branches.append((name, int(rev), node)) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
206 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
|
207 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
208 def cat(self, files, rev=None, output=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
209 args = cmdbuilder('cat', *files, r=rev, o=output) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
210 out = self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
211 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
212 if not output: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
213 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
|
214 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
215 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
|
216 revrange=None): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
217 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
|
218 self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
219 |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
220 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
|
221 date=None, user=None, include=None, exclude=None): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
222 if message is None and logfile is None: |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
223 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
|
224 elif message and logfile: |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
225 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
|
226 |
14
e0d21c9db20b
client: use --debug when committing to get the new node info
Idan Kamara <idankk86@gmail.com>
parents:
13
diff
changeset
|
227 # --debug will print the committed cset |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
15
diff
changeset
|
228 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
|
229 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
|
230 I=include, X=exclude) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
231 |
14
e0d21c9db20b
client: use --debug when committing to get the new node info
Idan Kamara <idankk86@gmail.com>
parents:
13
diff
changeset
|
232 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
|
233 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
|
234 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
|
235 |
21 | 236 def config(self, names=[], untrusted=False, showsource=False): |
237 """ | |
238 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
|
239 |
21 | 240 When showsource is specified, return (source, section, key, value) where |
241 source is of the form filename:[line] | |
242 """ | |
243 def splitline(s): | |
244 k, value = s.rstrip().split('=', 1) | |
245 section, key = k.split('.', 1) | |
246 return (section, key, value) | |
247 | |
248 if not isinstance(names, list): | |
249 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
|
250 |
21 | 251 args = cmdbuilder('showconfig', *names, u=untrusted, debug=showsource) |
252 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
|
253 |
21 | 254 conf = [] |
255 if showsource: | |
256 out = util.skiplines(out, 'read config from: ') | |
257 for line in out.splitlines(): | |
258 m = re.match(r"(.+?:(?:\d+:)?) (.*)", line) | |
259 t = splitline(m.group(2)) | |
260 conf.append((m.group(1)[:-1], t[0], t[1], t[2])) | |
261 else: | |
262 for line in out.splitlines(): | |
263 conf.append(splitline(line)) | |
264 | |
265 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
|
266 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
267 @property |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
268 def encoding(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
269 """ get the servers encoding """ |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
270 if not 'getencoding' in self.capabilities: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
271 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
|
272 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
273 if not self._encoding: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
274 self.server.stdin.write('getencoding\n') |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
275 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
|
276 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
277 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
|
278 |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
279 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
|
280 bypass=False, exact=False, importbranch=False, message=None, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
281 date=None, user=None, similarity=None): |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
282 """ |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
283 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
|
284 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
|
285 """ |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
286 if hasattr(patches, 'read') and hasattr(patches, 'readline'): |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
287 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
|
288 |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
289 def readline(size, output): |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
290 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
|
291 |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
292 stdin = True |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
293 patches = () |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
294 prompt = readline |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
295 input = patch.read |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
296 else: |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
297 stdin = False |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
298 prompt = None |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
299 input = None |
5
3182303f388d
client: rawcommand, more convenient helper to run commands instead of outputruncommand
Idan Kamara <idankk86@gmail.com>
parents:
4
diff
changeset
|
300 |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
301 args = cmdbuilder('import', *patches, strip=strip, force=force, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
302 nocommit=nocommit, bypass=bypass, exact=exact, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
303 importbranch=importbranch, message=message, |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
304 date=date, user=user, similarity=similarity, _=stdin) |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
305 |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
12
diff
changeset
|
306 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
|
307 |
25
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
308 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
|
309 bundle=None, bookmarks=False, branch=None, limit=None, |
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
310 nomerges=False, subrepos=False): |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
311 args = cmdbuilder('incoming', |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
312 path, |
25
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
313 template=templates.changeset, r=revrange, |
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
314 f=force, n=newest, bundle=bundle, |
85ae94b98324
client: add missing options to incoming
Idan Kamara <idankk86@gmail.com>
parents:
24
diff
changeset
|
315 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
|
316 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
317 def eh(ret, out, err): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
318 if ret != 1: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
319 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
|
320 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
321 out = self.rawcommand(args, eh=eh) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
322 if not out: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
323 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
|
324 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
325 out = util.eatlines(out, 2).split('\0')[:-1] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
326 return self._parserevs(out) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
327 |
17
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 nomerges=False, include=None, exclude=None): |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
332 args = cmdbuilder('log', *files, template=templates.changeset, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
333 r=revrange, f=follow, follow_first=followfirst, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
334 d=date, C=copies, k=keyword, removed=removed, |
b68c444d42bb
client: add missing options to log()
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
335 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
|
336 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
|
337 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
338 out = self.rawcommand(args) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
339 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
|
340 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
341 return self._parserevs(out) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
342 |
26
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
343 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
|
344 bookmarks=False, branch=None, limit=None, nomerges=False, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
345 subrepos=False): |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
346 args = cmdbuilder('outgoing', |
26
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
347 path, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
348 template=templates.changeset, r=revrange, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
349 f=force, n=newest, B=bookmarks, |
b4e5c8745ef3
client: add missing options to outgoing
Idan Kamara <idankk86@gmail.com>
parents:
25
diff
changeset
|
350 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
|
351 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
352 def eh(ret, out, err): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
353 if ret != 1: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
354 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
|
355 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
356 out = self.rawcommand(args, eh=eh) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
357 if not out: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
358 return [] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
359 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
360 out = util.eatlines(out, 2).split('\0')[:-1] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
361 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
|
362 |
18
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
363 def parents(self, rev=None, file=None): |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
364 args = cmdbuilder('parents', file, template=templates.changeset, r=rev) |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
365 |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
366 out = self.rawcommand(args) |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
367 if not out: |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
368 return |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
369 |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
370 out = out.split('\0')[:-1] |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
371 |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
372 return self._parserevs(out) |
518149e32888
client: add parents command
Idan Kamara <idankk86@gmail.com>
parents:
17
diff
changeset
|
373 |
2
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
374 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
|
375 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
|
376 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
|
377 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
|
378 return {} |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
379 |
5fa34c3ac9a0
turn hglib into a module and expose open (previously connect) in its __init__.py
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
380 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
|
381 else: |
4 | 382 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
|
383 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
|
384 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
|
385 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
386 def root(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
387 return self.rawcommand(['root']).rstrip() |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
388 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
389 def status(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
390 out = self.rawcommand(['status', '-0']) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
391 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
392 d = dict((c, []) for c in 'MARC!?I') |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
393 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
394 for entry in out.split('\0'): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
395 if entry: |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
396 t, f = entry.split(' ', 1) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
397 d[t].append(f) |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
398 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
399 return d |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
400 |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
401 def tip(self): |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
402 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
|
403 out = self.rawcommand(args) |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
404 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
|
405 |
10
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
406 return self._parserevs(out)[0] |
fce3102c19e5
client: sort commands by name
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
407 |
20 | 408 def update(self, rev=None, clean=False, check=False, date=None): |
409 """ | |
410 Update the repository's working directory to changeset specified by rev. | |
411 If rev isn't specified, update to the tip of the current named branch. | |
412 | |
413 Return the number of files (updated, merged, removed, unresolved) | |
414 """ | |
415 if clean and check: | |
416 raise ValueError('clean and check cannot both be True') | |
417 | |
418 args = cmdbuilder('update', r=rev, C=clean, c=check, d=date) | |
419 | |
420 def eh(ret, out, err): | |
421 if ret == 1: | |
422 return out | |
423 | |
424 raise error.CommandError(args, ret, out, err) | |
425 | |
426 | |
427 out = self.rawcommand(args, eh=eh) | |
428 | |
429 # filter out 'merging ...' lines | |
430 out = util.skiplines(out, 'merging ') | |
431 | |
432 counters = out.rstrip().split(', ') | |
433 return tuple(int(s.split(' ', 1)[0]) for s in counters) |