Show More
@@ -1,263 +1,263 b'' | |||||
1 | # CVS conversion code inspired by hg-cvs-import and git-cvsimport |
|
1 | # CVS conversion code inspired by hg-cvs-import and git-cvsimport | |
2 |
|
2 | |||
3 | import os, locale, re, socket |
|
3 | import os, locale, re, socket | |
4 | from mercurial import util |
|
4 | from mercurial import util | |
5 |
|
5 | |||
6 | from common import NoRepo, commit, converter_source |
|
6 | from common import NoRepo, commit, converter_source | |
7 |
|
7 | |||
8 | class convert_cvs(converter_source): |
|
8 | class convert_cvs(converter_source): | |
9 | def __init__(self, ui, path, rev=None): |
|
9 | def __init__(self, ui, path, rev=None): | |
10 | super(convert_cvs, self).__init__(ui, path, rev=rev) |
|
10 | super(convert_cvs, self).__init__(ui, path, rev=rev) | |
11 |
|
11 | |||
12 | cvs = os.path.join(path, "CVS") |
|
12 | cvs = os.path.join(path, "CVS") | |
13 | if not os.path.exists(cvs): |
|
13 | if not os.path.exists(cvs): | |
14 | raise NoRepo("couldn't open CVS repo %s" % path) |
|
14 | raise NoRepo("couldn't open CVS repo %s" % path) | |
15 |
|
15 | |||
16 | self.changeset = {} |
|
16 | self.changeset = {} | |
17 | self.files = {} |
|
17 | self.files = {} | |
18 | self.tags = {} |
|
18 | self.tags = {} | |
19 | self.lastbranch = {} |
|
19 | self.lastbranch = {} | |
20 | self.parent = {} |
|
20 | self.parent = {} | |
21 | self.socket = None |
|
21 | self.socket = None | |
22 | self.cvsroot = file(os.path.join(cvs, "Root")).read()[:-1] |
|
22 | self.cvsroot = file(os.path.join(cvs, "Root")).read()[:-1] | |
23 | self.cvsrepo = file(os.path.join(cvs, "Repository")).read()[:-1] |
|
23 | self.cvsrepo = file(os.path.join(cvs, "Repository")).read()[:-1] | |
24 | self.encoding = locale.getpreferredencoding() |
|
24 | self.encoding = locale.getpreferredencoding() | |
25 | self._parse() |
|
25 | self._parse() | |
26 | self._connect() |
|
26 | self._connect() | |
27 |
|
27 | |||
28 | def _parse(self): |
|
28 | def _parse(self): | |
29 | if self.changeset: |
|
29 | if self.changeset: | |
30 | return |
|
30 | return | |
31 |
|
31 | |||
32 | maxrev = 0 |
|
32 | maxrev = 0 | |
33 | cmd = 'cvsps -A -u --cvs-direct -q' |
|
33 | cmd = 'cvsps -A -u --cvs-direct -q' | |
34 | if self.rev: |
|
34 | if self.rev: | |
35 | # TODO: handle tags |
|
35 | # TODO: handle tags | |
36 | try: |
|
36 | try: | |
37 | # patchset number? |
|
37 | # patchset number? | |
38 | maxrev = int(self.rev) |
|
38 | maxrev = int(self.rev) | |
39 | except ValueError: |
|
39 | except ValueError: | |
40 | try: |
|
40 | try: | |
41 | # date |
|
41 | # date | |
42 | util.parsedate(self.rev, ['%Y/%m/%d %H:%M:%S']) |
|
42 | util.parsedate(self.rev, ['%Y/%m/%d %H:%M:%S']) | |
43 | cmd = "%s -d '1970/01/01 00:00:01' -d '%s'" % (cmd, self.rev) |
|
43 | cmd = "%s -d '1970/01/01 00:00:01' -d '%s'" % (cmd, self.rev) | |
44 | except util.Abort: |
|
44 | except util.Abort: | |
45 | raise util.Abort('revision %s is not a patchset number or date' % self.rev) |
|
45 | raise util.Abort('revision %s is not a patchset number or date' % self.rev) | |
46 |
|
46 | |||
47 | d = os.getcwd() |
|
47 | d = os.getcwd() | |
48 | try: |
|
48 | try: | |
49 | os.chdir(self.path) |
|
49 | os.chdir(self.path) | |
50 | id = None |
|
50 | id = None | |
51 | state = 0 |
|
51 | state = 0 | |
52 | for l in os.popen(cmd): |
|
52 | for l in os.popen(cmd): | |
53 | if state == 0: # header |
|
53 | if state == 0: # header | |
54 | if l.startswith("PatchSet"): |
|
54 | if l.startswith("PatchSet"): | |
55 | id = l[9:-2] |
|
55 | id = l[9:-2] | |
56 | if maxrev and int(id) > maxrev: |
|
56 | if maxrev and int(id) > maxrev: | |
57 | state = 3 |
|
57 | state = 3 | |
58 | elif l.startswith("Date"): |
|
58 | elif l.startswith("Date"): | |
59 | date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"]) |
|
59 | date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"]) | |
60 | date = util.datestr(date) |
|
60 | date = util.datestr(date) | |
61 | elif l.startswith("Branch"): |
|
61 | elif l.startswith("Branch"): | |
62 | branch = l[8:-1] |
|
62 | branch = l[8:-1] | |
63 | self.parent[id] = self.lastbranch.get(branch, 'bad') |
|
63 | self.parent[id] = self.lastbranch.get(branch, 'bad') | |
64 | self.lastbranch[branch] = id |
|
64 | self.lastbranch[branch] = id | |
65 | elif l.startswith("Ancestor branch"): |
|
65 | elif l.startswith("Ancestor branch"): | |
66 | ancestor = l[17:-1] |
|
66 | ancestor = l[17:-1] | |
67 | self.parent[id] = self.lastbranch[ancestor] |
|
67 | self.parent[id] = self.lastbranch[ancestor] | |
68 | elif l.startswith("Author"): |
|
68 | elif l.startswith("Author"): | |
69 | author = self.recode(l[8:-1]) |
|
69 | author = self.recode(l[8:-1]) | |
70 | elif l.startswith("Tag:") or l.startswith("Tags:"): |
|
70 | elif l.startswith("Tag:") or l.startswith("Tags:"): | |
71 | t = l[l.index(':')+1:] |
|
71 | t = l[l.index(':')+1:] | |
72 | t = [ut.strip() for ut in t.split(',')] |
|
72 | t = [ut.strip() for ut in t.split(',')] | |
73 | if (len(t) > 1) or (t[0] and (t[0] != "(none)")): |
|
73 | if (len(t) > 1) or (t[0] and (t[0] != "(none)")): | |
74 | self.tags.update(dict.fromkeys(t, id)) |
|
74 | self.tags.update(dict.fromkeys(t, id)) | |
75 | elif l.startswith("Log:"): |
|
75 | elif l.startswith("Log:"): | |
76 | state = 1 |
|
76 | state = 1 | |
77 | log = "" |
|
77 | log = "" | |
78 | elif state == 1: # log |
|
78 | elif state == 1: # log | |
79 | if l == "Members: \n": |
|
79 | if l == "Members: \n": | |
80 | files = {} |
|
80 | files = {} | |
81 | log = self.recode(log[:-1]) |
|
81 | log = self.recode(log[:-1]) | |
82 | state = 2 |
|
82 | state = 2 | |
83 | else: |
|
83 | else: | |
84 | log += l |
|
84 | log += l | |
85 | elif state == 2: |
|
85 | elif state == 2: | |
86 | if l == "\n": # |
|
86 | if l == "\n": # | |
87 | state = 0 |
|
87 | state = 0 | |
88 | p = [self.parent[id]] |
|
88 | p = [self.parent[id]] | |
89 | if id == "1": |
|
89 | if id == "1": | |
90 | p = [] |
|
90 | p = [] | |
91 | if branch == "HEAD": |
|
91 | if branch == "HEAD": | |
92 | branch = "" |
|
92 | branch = "" | |
93 | c = commit(author=author, date=date, parents=p, |
|
93 | c = commit(author=author, date=date, parents=p, | |
94 | desc=log, branch=branch) |
|
94 | desc=log, branch=branch) | |
95 | self.changeset[id] = c |
|
95 | self.changeset[id] = c | |
96 | self.files[id] = files |
|
96 | self.files[id] = files | |
97 | else: |
|
97 | else: | |
98 | colon = l.rfind(':') |
|
98 | colon = l.rfind(':') | |
99 | file = l[1:colon] |
|
99 | file = l[1:colon] | |
100 | rev = l[colon+1:-2] |
|
100 | rev = l[colon+1:-2] | |
101 | rev = rev.split("->")[1] |
|
101 | rev = rev.split("->")[1] | |
102 | files[file] = rev |
|
102 | files[file] = rev | |
103 | elif state == 3: |
|
103 | elif state == 3: | |
104 | continue |
|
104 | continue | |
105 |
|
105 | |||
106 | self.heads = self.lastbranch.values() |
|
106 | self.heads = self.lastbranch.values() | |
107 | finally: |
|
107 | finally: | |
108 | os.chdir(d) |
|
108 | os.chdir(d) | |
109 |
|
109 | |||
110 | def _connect(self): |
|
110 | def _connect(self): | |
111 | root = self.cvsroot |
|
111 | root = self.cvsroot | |
112 | conntype = None |
|
112 | conntype = None | |
113 | user, host = None, None |
|
113 | user, host = None, None | |
114 | cmd = ['cvs', 'server'] |
|
114 | cmd = ['cvs', 'server'] | |
115 |
|
115 | |||
116 | self.ui.status("connecting to %s\n" % root) |
|
116 | self.ui.status("connecting to %s\n" % root) | |
117 |
|
117 | |||
118 | if root.startswith(":pserver:"): |
|
118 | if root.startswith(":pserver:"): | |
119 | root = root[9:] |
|
119 | root = root[9:] | |
120 | m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)', |
|
120 | m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)', | |
121 | root) |
|
121 | root) | |
122 | if m: |
|
122 | if m: | |
123 | conntype = "pserver" |
|
123 | conntype = "pserver" | |
124 | user, passw, serv, port, root = m.groups() |
|
124 | user, passw, serv, port, root = m.groups() | |
125 | if not user: |
|
125 | if not user: | |
126 | user = "anonymous" |
|
126 | user = "anonymous" | |
127 | if not port: |
|
127 | if not port: | |
128 | port = 2401 |
|
128 | port = 2401 | |
129 | else: |
|
129 | else: | |
130 | port = int(port) |
|
130 | port = int(port) | |
131 | format0 = ":pserver:%s@%s:%s" % (user, serv, root) |
|
131 | format0 = ":pserver:%s@%s:%s" % (user, serv, root) | |
132 | format1 = ":pserver:%s@%s:%d%s" % (user, serv, port, root) |
|
132 | format1 = ":pserver:%s@%s:%d%s" % (user, serv, port, root) | |
133 |
|
133 | |||
134 | if not passw: |
|
134 | if not passw: | |
135 | passw = "A" |
|
135 | passw = "A" | |
136 | pf = open(os.path.join(os.environ["HOME"], ".cvspass")) |
|
136 | pf = open(os.path.join(os.environ["HOME"], ".cvspass")) | |
137 | for line in pf.read().splitlines(): |
|
137 | for line in pf.read().splitlines(): | |
138 | part1, part2 = line.split(' ', 1) |
|
138 | part1, part2 = line.split(' ', 1) | |
139 | if part1 == '/1': |
|
139 | if part1 == '/1': | |
140 | # /1 :pserver:user@example.com:2401/cvsroot/foo Ah<Z |
|
140 | # /1 :pserver:user@example.com:2401/cvsroot/foo Ah<Z | |
141 | part1, part2 = part2.split(' ', 1) |
|
141 | part1, part2 = part2.split(' ', 1) | |
142 | format = format1 |
|
142 | format = format1 | |
143 | else: |
|
143 | else: | |
144 | # :pserver:user@example.com:/cvsroot/foo Ah<Z |
|
144 | # :pserver:user@example.com:/cvsroot/foo Ah<Z | |
145 | format = format0 |
|
145 | format = format0 | |
146 | if part1 == format: |
|
146 | if part1 == format: | |
147 | passw = part2 |
|
147 | passw = part2 | |
148 | break |
|
148 | break | |
149 | pf.close() |
|
149 | pf.close() | |
150 |
|
150 | |||
151 | sck = socket.socket() |
|
151 | sck = socket.socket() | |
152 | sck.connect((serv, port)) |
|
152 | sck.connect((serv, port)) | |
153 | sck.send("\n".join(["BEGIN AUTH REQUEST", root, user, passw, |
|
153 | sck.send("\n".join(["BEGIN AUTH REQUEST", root, user, passw, | |
154 | "END AUTH REQUEST", ""])) |
|
154 | "END AUTH REQUEST", ""])) | |
155 | if sck.recv(128) != "I LOVE YOU\n": |
|
155 | if sck.recv(128) != "I LOVE YOU\n": | |
156 |
raise |
|
156 | raise util.Abort("CVS pserver authentication failed") | |
157 |
|
157 | |||
158 | self.writep = self.readp = sck.makefile('r+') |
|
158 | self.writep = self.readp = sck.makefile('r+') | |
159 |
|
159 | |||
160 | if not conntype and root.startswith(":local:"): |
|
160 | if not conntype and root.startswith(":local:"): | |
161 | conntype = "local" |
|
161 | conntype = "local" | |
162 | root = root[7:] |
|
162 | root = root[7:] | |
163 |
|
163 | |||
164 | if not conntype: |
|
164 | if not conntype: | |
165 | # :ext:user@host/home/user/path/to/cvsroot |
|
165 | # :ext:user@host/home/user/path/to/cvsroot | |
166 | if root.startswith(":ext:"): |
|
166 | if root.startswith(":ext:"): | |
167 | root = root[5:] |
|
167 | root = root[5:] | |
168 | m = re.match(r'(?:([^@:/]+)@)?([^:/]+):?(.*)', root) |
|
168 | m = re.match(r'(?:([^@:/]+)@)?([^:/]+):?(.*)', root) | |
169 | if not m: |
|
169 | if not m: | |
170 | conntype = "local" |
|
170 | conntype = "local" | |
171 | else: |
|
171 | else: | |
172 | conntype = "rsh" |
|
172 | conntype = "rsh" | |
173 | user, host, root = m.group(1), m.group(2), m.group(3) |
|
173 | user, host, root = m.group(1), m.group(2), m.group(3) | |
174 |
|
174 | |||
175 | if conntype != "pserver": |
|
175 | if conntype != "pserver": | |
176 | if conntype == "rsh": |
|
176 | if conntype == "rsh": | |
177 | rsh = os.environ.get("CVS_RSH" or "rsh") |
|
177 | rsh = os.environ.get("CVS_RSH" or "rsh") | |
178 | if user: |
|
178 | if user: | |
179 | cmd = [rsh, '-l', user, host] + cmd |
|
179 | cmd = [rsh, '-l', user, host] + cmd | |
180 | else: |
|
180 | else: | |
181 | cmd = [rsh, host] + cmd |
|
181 | cmd = [rsh, host] + cmd | |
182 |
|
182 | |||
183 | self.writep, self.readp = os.popen2(cmd) |
|
183 | self.writep, self.readp = os.popen2(cmd) | |
184 |
|
184 | |||
185 | self.realroot = root |
|
185 | self.realroot = root | |
186 |
|
186 | |||
187 | self.writep.write("Root %s\n" % root) |
|
187 | self.writep.write("Root %s\n" % root) | |
188 | self.writep.write("Valid-responses ok error Valid-requests Mode" |
|
188 | self.writep.write("Valid-responses ok error Valid-requests Mode" | |
189 | " M Mbinary E Checked-in Created Updated" |
|
189 | " M Mbinary E Checked-in Created Updated" | |
190 | " Merged Removed\n") |
|
190 | " Merged Removed\n") | |
191 | self.writep.write("valid-requests\n") |
|
191 | self.writep.write("valid-requests\n") | |
192 | self.writep.flush() |
|
192 | self.writep.flush() | |
193 | r = self.readp.readline() |
|
193 | r = self.readp.readline() | |
194 | if not r.startswith("Valid-requests"): |
|
194 | if not r.startswith("Valid-requests"): | |
195 | raise util.Abort("server sucks") |
|
195 | raise util.Abort("server sucks") | |
196 | if "UseUnchanged" in r: |
|
196 | if "UseUnchanged" in r: | |
197 | self.writep.write("UseUnchanged\n") |
|
197 | self.writep.write("UseUnchanged\n") | |
198 | self.writep.flush() |
|
198 | self.writep.flush() | |
199 | r = self.readp.readline() |
|
199 | r = self.readp.readline() | |
200 |
|
200 | |||
201 | def getheads(self): |
|
201 | def getheads(self): | |
202 | return self.heads |
|
202 | return self.heads | |
203 |
|
203 | |||
204 | def _getfile(self, name, rev): |
|
204 | def _getfile(self, name, rev): | |
205 | if rev.endswith("(DEAD)"): |
|
205 | if rev.endswith("(DEAD)"): | |
206 | raise IOError |
|
206 | raise IOError | |
207 |
|
207 | |||
208 | args = ("-N -P -kk -r %s --" % rev).split() |
|
208 | args = ("-N -P -kk -r %s --" % rev).split() | |
209 | args.append(os.path.join(self.cvsrepo, name)) |
|
209 | args.append(os.path.join(self.cvsrepo, name)) | |
210 | for x in args: |
|
210 | for x in args: | |
211 | self.writep.write("Argument %s\n" % x) |
|
211 | self.writep.write("Argument %s\n" % x) | |
212 | self.writep.write("Directory .\n%s\nco\n" % self.realroot) |
|
212 | self.writep.write("Directory .\n%s\nco\n" % self.realroot) | |
213 | self.writep.flush() |
|
213 | self.writep.flush() | |
214 |
|
214 | |||
215 | data = "" |
|
215 | data = "" | |
216 | while 1: |
|
216 | while 1: | |
217 | line = self.readp.readline() |
|
217 | line = self.readp.readline() | |
218 | if line.startswith("Created ") or line.startswith("Updated "): |
|
218 | if line.startswith("Created ") or line.startswith("Updated "): | |
219 | self.readp.readline() # path |
|
219 | self.readp.readline() # path | |
220 | self.readp.readline() # entries |
|
220 | self.readp.readline() # entries | |
221 | mode = self.readp.readline()[:-1] |
|
221 | mode = self.readp.readline()[:-1] | |
222 | count = int(self.readp.readline()[:-1]) |
|
222 | count = int(self.readp.readline()[:-1]) | |
223 | data = self.readp.read(count) |
|
223 | data = self.readp.read(count) | |
224 | elif line.startswith(" "): |
|
224 | elif line.startswith(" "): | |
225 | data += line[1:] |
|
225 | data += line[1:] | |
226 | elif line.startswith("M "): |
|
226 | elif line.startswith("M "): | |
227 | pass |
|
227 | pass | |
228 | elif line.startswith("Mbinary "): |
|
228 | elif line.startswith("Mbinary "): | |
229 | count = int(self.readp.readline()[:-1]) |
|
229 | count = int(self.readp.readline()[:-1]) | |
230 | data = self.readp.read(count) |
|
230 | data = self.readp.read(count) | |
231 | else: |
|
231 | else: | |
232 | if line == "ok\n": |
|
232 | if line == "ok\n": | |
233 | return (data, "x" in mode and "x" or "") |
|
233 | return (data, "x" in mode and "x" or "") | |
234 | elif line.startswith("E "): |
|
234 | elif line.startswith("E "): | |
235 | self.ui.warn("cvs server: %s\n" % line[2:]) |
|
235 | self.ui.warn("cvs server: %s\n" % line[2:]) | |
236 | elif line.startswith("Remove"): |
|
236 | elif line.startswith("Remove"): | |
237 | l = self.readp.readline() |
|
237 | l = self.readp.readline() | |
238 | l = self.readp.readline() |
|
238 | l = self.readp.readline() | |
239 | if l != "ok\n": |
|
239 | if l != "ok\n": | |
240 | raise util.Abort("unknown CVS response: %s" % l) |
|
240 | raise util.Abort("unknown CVS response: %s" % l) | |
241 | else: |
|
241 | else: | |
242 | raise util.Abort("unknown CVS response: %s" % line) |
|
242 | raise util.Abort("unknown CVS response: %s" % line) | |
243 |
|
243 | |||
244 | def getfile(self, file, rev): |
|
244 | def getfile(self, file, rev): | |
245 | data, mode = self._getfile(file, rev) |
|
245 | data, mode = self._getfile(file, rev) | |
246 | self.modecache[(file, rev)] = mode |
|
246 | self.modecache[(file, rev)] = mode | |
247 | return data |
|
247 | return data | |
248 |
|
248 | |||
249 | def getmode(self, file, rev): |
|
249 | def getmode(self, file, rev): | |
250 | return self.modecache[(file, rev)] |
|
250 | return self.modecache[(file, rev)] | |
251 |
|
251 | |||
252 | def getchanges(self, rev): |
|
252 | def getchanges(self, rev): | |
253 | self.modecache = {} |
|
253 | self.modecache = {} | |
254 | files = self.files[rev] |
|
254 | files = self.files[rev] | |
255 | cl = files.items() |
|
255 | cl = files.items() | |
256 | cl.sort() |
|
256 | cl.sort() | |
257 | return (cl, {}) |
|
257 | return (cl, {}) | |
258 |
|
258 | |||
259 | def getcommit(self, rev): |
|
259 | def getcommit(self, rev): | |
260 | return self.changeset[rev] |
|
260 | return self.changeset[rev] | |
261 |
|
261 | |||
262 | def gettags(self): |
|
262 | def gettags(self): | |
263 | return self.tags |
|
263 | return self.tags |
@@ -1,2242 +1,2244 b'' | |||||
1 | # queue.py - patch queues for mercurial |
|
1 | # queue.py - patch queues for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> |
|
3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | '''patch management and development |
|
8 | '''patch management and development | |
9 |
|
9 | |||
10 | This extension lets you work with a stack of patches in a Mercurial |
|
10 | This extension lets you work with a stack of patches in a Mercurial | |
11 | repository. It manages two stacks of patches - all known patches, and |
|
11 | repository. It manages two stacks of patches - all known patches, and | |
12 | applied patches (subset of known patches). |
|
12 | applied patches (subset of known patches). | |
13 |
|
13 | |||
14 | Known patches are represented as patch files in the .hg/patches |
|
14 | Known patches are represented as patch files in the .hg/patches | |
15 | directory. Applied patches are both patch files and changesets. |
|
15 | directory. Applied patches are both patch files and changesets. | |
16 |
|
16 | |||
17 | Common tasks (use "hg help command" for more details): |
|
17 | Common tasks (use "hg help command" for more details): | |
18 |
|
18 | |||
19 | prepare repository to work with patches qinit |
|
19 | prepare repository to work with patches qinit | |
20 | create new patch qnew |
|
20 | create new patch qnew | |
21 | import existing patch qimport |
|
21 | import existing patch qimport | |
22 |
|
22 | |||
23 | print patch series qseries |
|
23 | print patch series qseries | |
24 | print applied patches qapplied |
|
24 | print applied patches qapplied | |
25 | print name of top applied patch qtop |
|
25 | print name of top applied patch qtop | |
26 |
|
26 | |||
27 | add known patch to applied stack qpush |
|
27 | add known patch to applied stack qpush | |
28 | remove patch from applied stack qpop |
|
28 | remove patch from applied stack qpop | |
29 | refresh contents of top applied patch qrefresh |
|
29 | refresh contents of top applied patch qrefresh | |
30 | ''' |
|
30 | ''' | |
31 |
|
31 | |||
32 | from mercurial.i18n import _ |
|
32 | from mercurial.i18n import _ | |
33 | from mercurial import commands, cmdutil, hg, patch, revlog, util |
|
33 | from mercurial import commands, cmdutil, hg, patch, revlog, util | |
34 | from mercurial import repair |
|
34 | from mercurial import repair | |
35 | import os, sys, re, errno |
|
35 | import os, sys, re, errno | |
36 |
|
36 | |||
37 | commands.norepo += " qclone qversion" |
|
37 | commands.norepo += " qclone qversion" | |
38 |
|
38 | |||
39 | # Patch names looks like unix-file names. |
|
39 | # Patch names looks like unix-file names. | |
40 | # They must be joinable with queue directory and result in the patch path. |
|
40 | # They must be joinable with queue directory and result in the patch path. | |
41 | normname = util.normpath |
|
41 | normname = util.normpath | |
42 |
|
42 | |||
43 | class statusentry: |
|
43 | class statusentry: | |
44 | def __init__(self, rev, name=None): |
|
44 | def __init__(self, rev, name=None): | |
45 | if not name: |
|
45 | if not name: | |
46 | fields = rev.split(':', 1) |
|
46 | fields = rev.split(':', 1) | |
47 | if len(fields) == 2: |
|
47 | if len(fields) == 2: | |
48 | self.rev, self.name = fields |
|
48 | self.rev, self.name = fields | |
49 | else: |
|
49 | else: | |
50 | self.rev, self.name = None, None |
|
50 | self.rev, self.name = None, None | |
51 | else: |
|
51 | else: | |
52 | self.rev, self.name = rev, name |
|
52 | self.rev, self.name = rev, name | |
53 |
|
53 | |||
54 | def __str__(self): |
|
54 | def __str__(self): | |
55 | return self.rev + ':' + self.name |
|
55 | return self.rev + ':' + self.name | |
56 |
|
56 | |||
57 | class queue: |
|
57 | class queue: | |
58 | def __init__(self, ui, path, patchdir=None): |
|
58 | def __init__(self, ui, path, patchdir=None): | |
59 | self.basepath = path |
|
59 | self.basepath = path | |
60 | self.path = patchdir or os.path.join(path, "patches") |
|
60 | self.path = patchdir or os.path.join(path, "patches") | |
61 | self.opener = util.opener(self.path) |
|
61 | self.opener = util.opener(self.path) | |
62 | self.ui = ui |
|
62 | self.ui = ui | |
63 | self.applied = [] |
|
63 | self.applied = [] | |
64 | self.full_series = [] |
|
64 | self.full_series = [] | |
65 | self.applied_dirty = 0 |
|
65 | self.applied_dirty = 0 | |
66 | self.series_dirty = 0 |
|
66 | self.series_dirty = 0 | |
67 | self.series_path = "series" |
|
67 | self.series_path = "series" | |
68 | self.status_path = "status" |
|
68 | self.status_path = "status" | |
69 | self.guards_path = "guards" |
|
69 | self.guards_path = "guards" | |
70 | self.active_guards = None |
|
70 | self.active_guards = None | |
71 | self.guards_dirty = False |
|
71 | self.guards_dirty = False | |
72 | self._diffopts = None |
|
72 | self._diffopts = None | |
73 |
|
73 | |||
74 | if os.path.exists(self.join(self.series_path)): |
|
74 | if os.path.exists(self.join(self.series_path)): | |
75 | self.full_series = self.opener(self.series_path).read().splitlines() |
|
75 | self.full_series = self.opener(self.series_path).read().splitlines() | |
76 | self.parse_series() |
|
76 | self.parse_series() | |
77 |
|
77 | |||
78 | if os.path.exists(self.join(self.status_path)): |
|
78 | if os.path.exists(self.join(self.status_path)): | |
79 | lines = self.opener(self.status_path).read().splitlines() |
|
79 | lines = self.opener(self.status_path).read().splitlines() | |
80 | self.applied = [statusentry(l) for l in lines] |
|
80 | self.applied = [statusentry(l) for l in lines] | |
81 |
|
81 | |||
82 | def diffopts(self): |
|
82 | def diffopts(self): | |
83 | if self._diffopts is None: |
|
83 | if self._diffopts is None: | |
84 | self._diffopts = patch.diffopts(self.ui) |
|
84 | self._diffopts = patch.diffopts(self.ui) | |
85 | return self._diffopts |
|
85 | return self._diffopts | |
86 |
|
86 | |||
87 | def join(self, *p): |
|
87 | def join(self, *p): | |
88 | return os.path.join(self.path, *p) |
|
88 | return os.path.join(self.path, *p) | |
89 |
|
89 | |||
90 | def find_series(self, patch): |
|
90 | def find_series(self, patch): | |
91 | pre = re.compile("(\s*)([^#]+)") |
|
91 | pre = re.compile("(\s*)([^#]+)") | |
92 | index = 0 |
|
92 | index = 0 | |
93 | for l in self.full_series: |
|
93 | for l in self.full_series: | |
94 | m = pre.match(l) |
|
94 | m = pre.match(l) | |
95 | if m: |
|
95 | if m: | |
96 | s = m.group(2) |
|
96 | s = m.group(2) | |
97 | s = s.rstrip() |
|
97 | s = s.rstrip() | |
98 | if s == patch: |
|
98 | if s == patch: | |
99 | return index |
|
99 | return index | |
100 | index += 1 |
|
100 | index += 1 | |
101 | return None |
|
101 | return None | |
102 |
|
102 | |||
103 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') |
|
103 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') | |
104 |
|
104 | |||
105 | def parse_series(self): |
|
105 | def parse_series(self): | |
106 | self.series = [] |
|
106 | self.series = [] | |
107 | self.series_guards = [] |
|
107 | self.series_guards = [] | |
108 | for l in self.full_series: |
|
108 | for l in self.full_series: | |
109 | h = l.find('#') |
|
109 | h = l.find('#') | |
110 | if h == -1: |
|
110 | if h == -1: | |
111 | patch = l |
|
111 | patch = l | |
112 | comment = '' |
|
112 | comment = '' | |
113 | elif h == 0: |
|
113 | elif h == 0: | |
114 | continue |
|
114 | continue | |
115 | else: |
|
115 | else: | |
116 | patch = l[:h] |
|
116 | patch = l[:h] | |
117 | comment = l[h:] |
|
117 | comment = l[h:] | |
118 | patch = patch.strip() |
|
118 | patch = patch.strip() | |
119 | if patch: |
|
119 | if patch: | |
120 | if patch in self.series: |
|
120 | if patch in self.series: | |
121 | raise util.Abort(_('%s appears more than once in %s') % |
|
121 | raise util.Abort(_('%s appears more than once in %s') % | |
122 | (patch, self.join(self.series_path))) |
|
122 | (patch, self.join(self.series_path))) | |
123 | self.series.append(patch) |
|
123 | self.series.append(patch) | |
124 | self.series_guards.append(self.guard_re.findall(comment)) |
|
124 | self.series_guards.append(self.guard_re.findall(comment)) | |
125 |
|
125 | |||
126 | def check_guard(self, guard): |
|
126 | def check_guard(self, guard): | |
127 | bad_chars = '# \t\r\n\f' |
|
127 | bad_chars = '# \t\r\n\f' | |
128 | first = guard[0] |
|
128 | first = guard[0] | |
129 | for c in '-+': |
|
129 | for c in '-+': | |
130 | if first == c: |
|
130 | if first == c: | |
131 | return (_('guard %r starts with invalid character: %r') % |
|
131 | return (_('guard %r starts with invalid character: %r') % | |
132 | (guard, c)) |
|
132 | (guard, c)) | |
133 | for c in bad_chars: |
|
133 | for c in bad_chars: | |
134 | if c in guard: |
|
134 | if c in guard: | |
135 | return _('invalid character in guard %r: %r') % (guard, c) |
|
135 | return _('invalid character in guard %r: %r') % (guard, c) | |
136 |
|
136 | |||
137 | def set_active(self, guards): |
|
137 | def set_active(self, guards): | |
138 | for guard in guards: |
|
138 | for guard in guards: | |
139 | bad = self.check_guard(guard) |
|
139 | bad = self.check_guard(guard) | |
140 | if bad: |
|
140 | if bad: | |
141 | raise util.Abort(bad) |
|
141 | raise util.Abort(bad) | |
142 | guards = dict.fromkeys(guards).keys() |
|
142 | guards = dict.fromkeys(guards).keys() | |
143 | guards.sort() |
|
143 | guards.sort() | |
144 | self.ui.debug('active guards: %s\n' % ' '.join(guards)) |
|
144 | self.ui.debug('active guards: %s\n' % ' '.join(guards)) | |
145 | self.active_guards = guards |
|
145 | self.active_guards = guards | |
146 | self.guards_dirty = True |
|
146 | self.guards_dirty = True | |
147 |
|
147 | |||
148 | def active(self): |
|
148 | def active(self): | |
149 | if self.active_guards is None: |
|
149 | if self.active_guards is None: | |
150 | self.active_guards = [] |
|
150 | self.active_guards = [] | |
151 | try: |
|
151 | try: | |
152 | guards = self.opener(self.guards_path).read().split() |
|
152 | guards = self.opener(self.guards_path).read().split() | |
153 | except IOError, err: |
|
153 | except IOError, err: | |
154 | if err.errno != errno.ENOENT: raise |
|
154 | if err.errno != errno.ENOENT: raise | |
155 | guards = [] |
|
155 | guards = [] | |
156 | for i, guard in enumerate(guards): |
|
156 | for i, guard in enumerate(guards): | |
157 | bad = self.check_guard(guard) |
|
157 | bad = self.check_guard(guard) | |
158 | if bad: |
|
158 | if bad: | |
159 | self.ui.warn('%s:%d: %s\n' % |
|
159 | self.ui.warn('%s:%d: %s\n' % | |
160 | (self.join(self.guards_path), i + 1, bad)) |
|
160 | (self.join(self.guards_path), i + 1, bad)) | |
161 | else: |
|
161 | else: | |
162 | self.active_guards.append(guard) |
|
162 | self.active_guards.append(guard) | |
163 | return self.active_guards |
|
163 | return self.active_guards | |
164 |
|
164 | |||
165 | def set_guards(self, idx, guards): |
|
165 | def set_guards(self, idx, guards): | |
166 | for g in guards: |
|
166 | for g in guards: | |
167 | if len(g) < 2: |
|
167 | if len(g) < 2: | |
168 | raise util.Abort(_('guard %r too short') % g) |
|
168 | raise util.Abort(_('guard %r too short') % g) | |
169 | if g[0] not in '-+': |
|
169 | if g[0] not in '-+': | |
170 | raise util.Abort(_('guard %r starts with invalid char') % g) |
|
170 | raise util.Abort(_('guard %r starts with invalid char') % g) | |
171 | bad = self.check_guard(g[1:]) |
|
171 | bad = self.check_guard(g[1:]) | |
172 | if bad: |
|
172 | if bad: | |
173 | raise util.Abort(bad) |
|
173 | raise util.Abort(bad) | |
174 | drop = self.guard_re.sub('', self.full_series[idx]) |
|
174 | drop = self.guard_re.sub('', self.full_series[idx]) | |
175 | self.full_series[idx] = drop + ''.join([' #' + g for g in guards]) |
|
175 | self.full_series[idx] = drop + ''.join([' #' + g for g in guards]) | |
176 | self.parse_series() |
|
176 | self.parse_series() | |
177 | self.series_dirty = True |
|
177 | self.series_dirty = True | |
178 |
|
178 | |||
179 | def pushable(self, idx): |
|
179 | def pushable(self, idx): | |
180 | if isinstance(idx, str): |
|
180 | if isinstance(idx, str): | |
181 | idx = self.series.index(idx) |
|
181 | idx = self.series.index(idx) | |
182 | patchguards = self.series_guards[idx] |
|
182 | patchguards = self.series_guards[idx] | |
183 | if not patchguards: |
|
183 | if not patchguards: | |
184 | return True, None |
|
184 | return True, None | |
185 | default = False |
|
185 | default = False | |
186 | guards = self.active() |
|
186 | guards = self.active() | |
187 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] |
|
187 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] | |
188 | if exactneg: |
|
188 | if exactneg: | |
189 | return False, exactneg[0] |
|
189 | return False, exactneg[0] | |
190 | pos = [g for g in patchguards if g[0] == '+'] |
|
190 | pos = [g for g in patchguards if g[0] == '+'] | |
191 | exactpos = [g for g in pos if g[1:] in guards] |
|
191 | exactpos = [g for g in pos if g[1:] in guards] | |
192 | if pos: |
|
192 | if pos: | |
193 | if exactpos: |
|
193 | if exactpos: | |
194 | return True, exactpos[0] |
|
194 | return True, exactpos[0] | |
195 | return False, pos |
|
195 | return False, pos | |
196 | return True, '' |
|
196 | return True, '' | |
197 |
|
197 | |||
198 | def explain_pushable(self, idx, all_patches=False): |
|
198 | def explain_pushable(self, idx, all_patches=False): | |
199 | write = all_patches and self.ui.write or self.ui.warn |
|
199 | write = all_patches and self.ui.write or self.ui.warn | |
200 | if all_patches or self.ui.verbose: |
|
200 | if all_patches or self.ui.verbose: | |
201 | if isinstance(idx, str): |
|
201 | if isinstance(idx, str): | |
202 | idx = self.series.index(idx) |
|
202 | idx = self.series.index(idx) | |
203 | pushable, why = self.pushable(idx) |
|
203 | pushable, why = self.pushable(idx) | |
204 | if all_patches and pushable: |
|
204 | if all_patches and pushable: | |
205 | if why is None: |
|
205 | if why is None: | |
206 | write(_('allowing %s - no guards in effect\n') % |
|
206 | write(_('allowing %s - no guards in effect\n') % | |
207 | self.series[idx]) |
|
207 | self.series[idx]) | |
208 | else: |
|
208 | else: | |
209 | if not why: |
|
209 | if not why: | |
210 | write(_('allowing %s - no matching negative guards\n') % |
|
210 | write(_('allowing %s - no matching negative guards\n') % | |
211 | self.series[idx]) |
|
211 | self.series[idx]) | |
212 | else: |
|
212 | else: | |
213 | write(_('allowing %s - guarded by %r\n') % |
|
213 | write(_('allowing %s - guarded by %r\n') % | |
214 | (self.series[idx], why)) |
|
214 | (self.series[idx], why)) | |
215 | if not pushable: |
|
215 | if not pushable: | |
216 | if why: |
|
216 | if why: | |
217 | write(_('skipping %s - guarded by %r\n') % |
|
217 | write(_('skipping %s - guarded by %r\n') % | |
218 | (self.series[idx], why)) |
|
218 | (self.series[idx], why)) | |
219 | else: |
|
219 | else: | |
220 | write(_('skipping %s - no matching guards\n') % |
|
220 | write(_('skipping %s - no matching guards\n') % | |
221 | self.series[idx]) |
|
221 | self.series[idx]) | |
222 |
|
222 | |||
223 | def save_dirty(self): |
|
223 | def save_dirty(self): | |
224 | def write_list(items, path): |
|
224 | def write_list(items, path): | |
225 | fp = self.opener(path, 'w') |
|
225 | fp = self.opener(path, 'w') | |
226 | for i in items: |
|
226 | for i in items: | |
227 | print >> fp, i |
|
227 | print >> fp, i | |
228 | fp.close() |
|
228 | fp.close() | |
229 | if self.applied_dirty: write_list(map(str, self.applied), self.status_path) |
|
229 | if self.applied_dirty: write_list(map(str, self.applied), self.status_path) | |
230 | if self.series_dirty: write_list(self.full_series, self.series_path) |
|
230 | if self.series_dirty: write_list(self.full_series, self.series_path) | |
231 | if self.guards_dirty: write_list(self.active_guards, self.guards_path) |
|
231 | if self.guards_dirty: write_list(self.active_guards, self.guards_path) | |
232 |
|
232 | |||
233 | def readheaders(self, patch): |
|
233 | def readheaders(self, patch): | |
234 | def eatdiff(lines): |
|
234 | def eatdiff(lines): | |
235 | while lines: |
|
235 | while lines: | |
236 | l = lines[-1] |
|
236 | l = lines[-1] | |
237 | if (l.startswith("diff -") or |
|
237 | if (l.startswith("diff -") or | |
238 | l.startswith("Index:") or |
|
238 | l.startswith("Index:") or | |
239 | l.startswith("===========")): |
|
239 | l.startswith("===========")): | |
240 | del lines[-1] |
|
240 | del lines[-1] | |
241 | else: |
|
241 | else: | |
242 | break |
|
242 | break | |
243 | def eatempty(lines): |
|
243 | def eatempty(lines): | |
244 | while lines: |
|
244 | while lines: | |
245 | l = lines[-1] |
|
245 | l = lines[-1] | |
246 | if re.match('\s*$', l): |
|
246 | if re.match('\s*$', l): | |
247 | del lines[-1] |
|
247 | del lines[-1] | |
248 | else: |
|
248 | else: | |
249 | break |
|
249 | break | |
250 |
|
250 | |||
251 | pf = self.join(patch) |
|
251 | pf = self.join(patch) | |
252 | message = [] |
|
252 | message = [] | |
253 | comments = [] |
|
253 | comments = [] | |
254 | user = None |
|
254 | user = None | |
255 | date = None |
|
255 | date = None | |
256 | format = None |
|
256 | format = None | |
257 | subject = None |
|
257 | subject = None | |
258 | diffstart = 0 |
|
258 | diffstart = 0 | |
259 |
|
259 | |||
260 | for line in file(pf): |
|
260 | for line in file(pf): | |
261 | line = line.rstrip() |
|
261 | line = line.rstrip() | |
262 | if line.startswith('diff --git'): |
|
262 | if line.startswith('diff --git'): | |
263 | diffstart = 2 |
|
263 | diffstart = 2 | |
264 | break |
|
264 | break | |
265 | if diffstart: |
|
265 | if diffstart: | |
266 | if line.startswith('+++ '): |
|
266 | if line.startswith('+++ '): | |
267 | diffstart = 2 |
|
267 | diffstart = 2 | |
268 | break |
|
268 | break | |
269 | if line.startswith("--- "): |
|
269 | if line.startswith("--- "): | |
270 | diffstart = 1 |
|
270 | diffstart = 1 | |
271 | continue |
|
271 | continue | |
272 | elif format == "hgpatch": |
|
272 | elif format == "hgpatch": | |
273 | # parse values when importing the result of an hg export |
|
273 | # parse values when importing the result of an hg export | |
274 | if line.startswith("# User "): |
|
274 | if line.startswith("# User "): | |
275 | user = line[7:] |
|
275 | user = line[7:] | |
276 | elif line.startswith("# Date "): |
|
276 | elif line.startswith("# Date "): | |
277 | date = line[7:] |
|
277 | date = line[7:] | |
278 | elif not line.startswith("# ") and line: |
|
278 | elif not line.startswith("# ") and line: | |
279 | message.append(line) |
|
279 | message.append(line) | |
280 | format = None |
|
280 | format = None | |
281 | elif line == '# HG changeset patch': |
|
281 | elif line == '# HG changeset patch': | |
282 | format = "hgpatch" |
|
282 | format = "hgpatch" | |
283 | elif (format != "tagdone" and (line.startswith("Subject: ") or |
|
283 | elif (format != "tagdone" and (line.startswith("Subject: ") or | |
284 | line.startswith("subject: "))): |
|
284 | line.startswith("subject: "))): | |
285 | subject = line[9:] |
|
285 | subject = line[9:] | |
286 | format = "tag" |
|
286 | format = "tag" | |
287 | elif (format != "tagdone" and (line.startswith("From: ") or |
|
287 | elif (format != "tagdone" and (line.startswith("From: ") or | |
288 | line.startswith("from: "))): |
|
288 | line.startswith("from: "))): | |
289 | user = line[6:] |
|
289 | user = line[6:] | |
290 | format = "tag" |
|
290 | format = "tag" | |
291 | elif format == "tag" and line == "": |
|
291 | elif format == "tag" and line == "": | |
292 | # when looking for tags (subject: from: etc) they |
|
292 | # when looking for tags (subject: from: etc) they | |
293 | # end once you find a blank line in the source |
|
293 | # end once you find a blank line in the source | |
294 | format = "tagdone" |
|
294 | format = "tagdone" | |
295 | elif message or line: |
|
295 | elif message or line: | |
296 | message.append(line) |
|
296 | message.append(line) | |
297 | comments.append(line) |
|
297 | comments.append(line) | |
298 |
|
298 | |||
299 | eatdiff(message) |
|
299 | eatdiff(message) | |
300 | eatdiff(comments) |
|
300 | eatdiff(comments) | |
301 | eatempty(message) |
|
301 | eatempty(message) | |
302 | eatempty(comments) |
|
302 | eatempty(comments) | |
303 |
|
303 | |||
304 | # make sure message isn't empty |
|
304 | # make sure message isn't empty | |
305 | if format and format.startswith("tag") and subject: |
|
305 | if format and format.startswith("tag") and subject: | |
306 | message.insert(0, "") |
|
306 | message.insert(0, "") | |
307 | message.insert(0, subject) |
|
307 | message.insert(0, subject) | |
308 | return (message, comments, user, date, diffstart > 1) |
|
308 | return (message, comments, user, date, diffstart > 1) | |
309 |
|
309 | |||
310 | def removeundo(self, repo): |
|
310 | def removeundo(self, repo): | |
311 | undo = repo.sjoin('undo') |
|
311 | undo = repo.sjoin('undo') | |
312 | if not os.path.exists(undo): |
|
312 | if not os.path.exists(undo): | |
313 | return |
|
313 | return | |
314 | try: |
|
314 | try: | |
315 | os.unlink(undo) |
|
315 | os.unlink(undo) | |
316 | except OSError, inst: |
|
316 | except OSError, inst: | |
317 | self.ui.warn('error removing undo: %s\n' % str(inst)) |
|
317 | self.ui.warn('error removing undo: %s\n' % str(inst)) | |
318 |
|
318 | |||
319 | def printdiff(self, repo, node1, node2=None, files=None, |
|
319 | def printdiff(self, repo, node1, node2=None, files=None, | |
320 | fp=None, changes=None, opts={}): |
|
320 | fp=None, changes=None, opts={}): | |
321 | fns, matchfn, anypats = cmdutil.matchpats(repo, files, opts) |
|
321 | fns, matchfn, anypats = cmdutil.matchpats(repo, files, opts) | |
322 |
|
322 | |||
323 | patch.diff(repo, node1, node2, fns, match=matchfn, |
|
323 | patch.diff(repo, node1, node2, fns, match=matchfn, | |
324 | fp=fp, changes=changes, opts=self.diffopts()) |
|
324 | fp=fp, changes=changes, opts=self.diffopts()) | |
325 |
|
325 | |||
326 | def mergeone(self, repo, mergeq, head, patch, rev): |
|
326 | def mergeone(self, repo, mergeq, head, patch, rev): | |
327 | # first try just applying the patch |
|
327 | # first try just applying the patch | |
328 | (err, n) = self.apply(repo, [ patch ], update_status=False, |
|
328 | (err, n) = self.apply(repo, [ patch ], update_status=False, | |
329 | strict=True, merge=rev) |
|
329 | strict=True, merge=rev) | |
330 |
|
330 | |||
331 | if err == 0: |
|
331 | if err == 0: | |
332 | return (err, n) |
|
332 | return (err, n) | |
333 |
|
333 | |||
334 | if n is None: |
|
334 | if n is None: | |
335 | raise util.Abort(_("apply failed for patch %s") % patch) |
|
335 | raise util.Abort(_("apply failed for patch %s") % patch) | |
336 |
|
336 | |||
337 | self.ui.warn("patch didn't work out, merging %s\n" % patch) |
|
337 | self.ui.warn("patch didn't work out, merging %s\n" % patch) | |
338 |
|
338 | |||
339 | # apply failed, strip away that rev and merge. |
|
339 | # apply failed, strip away that rev and merge. | |
340 | hg.clean(repo, head) |
|
340 | hg.clean(repo, head) | |
341 | self.strip(repo, n, update=False, backup='strip') |
|
341 | self.strip(repo, n, update=False, backup='strip') | |
342 |
|
342 | |||
343 | ctx = repo.changectx(rev) |
|
343 | ctx = repo.changectx(rev) | |
344 | ret = hg.merge(repo, rev) |
|
344 | ret = hg.merge(repo, rev) | |
345 | if ret: |
|
345 | if ret: | |
346 | raise util.Abort(_("update returned %d") % ret) |
|
346 | raise util.Abort(_("update returned %d") % ret) | |
347 | n = repo.commit(None, ctx.description(), ctx.user(), force=1) |
|
347 | n = repo.commit(None, ctx.description(), ctx.user(), force=1) | |
348 | if n == None: |
|
348 | if n == None: | |
349 | raise util.Abort(_("repo commit failed")) |
|
349 | raise util.Abort(_("repo commit failed")) | |
350 | try: |
|
350 | try: | |
351 | message, comments, user, date, patchfound = mergeq.readheaders(patch) |
|
351 | message, comments, user, date, patchfound = mergeq.readheaders(patch) | |
352 | except: |
|
352 | except: | |
353 | raise util.Abort(_("unable to read %s") % patch) |
|
353 | raise util.Abort(_("unable to read %s") % patch) | |
354 |
|
354 | |||
355 | patchf = self.opener(patch, "w") |
|
355 | patchf = self.opener(patch, "w") | |
356 | if comments: |
|
356 | if comments: | |
357 | comments = "\n".join(comments) + '\n\n' |
|
357 | comments = "\n".join(comments) + '\n\n' | |
358 | patchf.write(comments) |
|
358 | patchf.write(comments) | |
359 | self.printdiff(repo, head, n, fp=patchf) |
|
359 | self.printdiff(repo, head, n, fp=patchf) | |
360 | patchf.close() |
|
360 | patchf.close() | |
361 | self.removeundo(repo) |
|
361 | self.removeundo(repo) | |
362 | return (0, n) |
|
362 | return (0, n) | |
363 |
|
363 | |||
364 | def qparents(self, repo, rev=None): |
|
364 | def qparents(self, repo, rev=None): | |
365 | if rev is None: |
|
365 | if rev is None: | |
366 | (p1, p2) = repo.dirstate.parents() |
|
366 | (p1, p2) = repo.dirstate.parents() | |
367 | if p2 == revlog.nullid: |
|
367 | if p2 == revlog.nullid: | |
368 | return p1 |
|
368 | return p1 | |
369 | if len(self.applied) == 0: |
|
369 | if len(self.applied) == 0: | |
370 | return None |
|
370 | return None | |
371 | return revlog.bin(self.applied[-1].rev) |
|
371 | return revlog.bin(self.applied[-1].rev) | |
372 | pp = repo.changelog.parents(rev) |
|
372 | pp = repo.changelog.parents(rev) | |
373 | if pp[1] != revlog.nullid: |
|
373 | if pp[1] != revlog.nullid: | |
374 | arevs = [ x.rev for x in self.applied ] |
|
374 | arevs = [ x.rev for x in self.applied ] | |
375 | p0 = revlog.hex(pp[0]) |
|
375 | p0 = revlog.hex(pp[0]) | |
376 | p1 = revlog.hex(pp[1]) |
|
376 | p1 = revlog.hex(pp[1]) | |
377 | if p0 in arevs: |
|
377 | if p0 in arevs: | |
378 | return pp[0] |
|
378 | return pp[0] | |
379 | if p1 in arevs: |
|
379 | if p1 in arevs: | |
380 | return pp[1] |
|
380 | return pp[1] | |
381 | return pp[0] |
|
381 | return pp[0] | |
382 |
|
382 | |||
383 | def mergepatch(self, repo, mergeq, series): |
|
383 | def mergepatch(self, repo, mergeq, series): | |
384 | if len(self.applied) == 0: |
|
384 | if len(self.applied) == 0: | |
385 | # each of the patches merged in will have two parents. This |
|
385 | # each of the patches merged in will have two parents. This | |
386 | # can confuse the qrefresh, qdiff, and strip code because it |
|
386 | # can confuse the qrefresh, qdiff, and strip code because it | |
387 | # needs to know which parent is actually in the patch queue. |
|
387 | # needs to know which parent is actually in the patch queue. | |
388 | # so, we insert a merge marker with only one parent. This way |
|
388 | # so, we insert a merge marker with only one parent. This way | |
389 | # the first patch in the queue is never a merge patch |
|
389 | # the first patch in the queue is never a merge patch | |
390 | # |
|
390 | # | |
391 | pname = ".hg.patches.merge.marker" |
|
391 | pname = ".hg.patches.merge.marker" | |
392 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1) |
|
392 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1) | |
393 | self.removeundo(repo) |
|
393 | self.removeundo(repo) | |
394 | self.applied.append(statusentry(revlog.hex(n), pname)) |
|
394 | self.applied.append(statusentry(revlog.hex(n), pname)) | |
395 | self.applied_dirty = 1 |
|
395 | self.applied_dirty = 1 | |
396 |
|
396 | |||
397 | head = self.qparents(repo) |
|
397 | head = self.qparents(repo) | |
398 |
|
398 | |||
399 | for patch in series: |
|
399 | for patch in series: | |
400 | patch = mergeq.lookup(patch, strict=True) |
|
400 | patch = mergeq.lookup(patch, strict=True) | |
401 | if not patch: |
|
401 | if not patch: | |
402 | self.ui.warn("patch %s does not exist\n" % patch) |
|
402 | self.ui.warn("patch %s does not exist\n" % patch) | |
403 | return (1, None) |
|
403 | return (1, None) | |
404 | pushable, reason = self.pushable(patch) |
|
404 | pushable, reason = self.pushable(patch) | |
405 | if not pushable: |
|
405 | if not pushable: | |
406 | self.explain_pushable(patch, all_patches=True) |
|
406 | self.explain_pushable(patch, all_patches=True) | |
407 | continue |
|
407 | continue | |
408 | info = mergeq.isapplied(patch) |
|
408 | info = mergeq.isapplied(patch) | |
409 | if not info: |
|
409 | if not info: | |
410 | self.ui.warn("patch %s is not applied\n" % patch) |
|
410 | self.ui.warn("patch %s is not applied\n" % patch) | |
411 | return (1, None) |
|
411 | return (1, None) | |
412 | rev = revlog.bin(info[1]) |
|
412 | rev = revlog.bin(info[1]) | |
413 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev) |
|
413 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev) | |
414 | if head: |
|
414 | if head: | |
415 | self.applied.append(statusentry(revlog.hex(head), patch)) |
|
415 | self.applied.append(statusentry(revlog.hex(head), patch)) | |
416 | self.applied_dirty = 1 |
|
416 | self.applied_dirty = 1 | |
417 | if err: |
|
417 | if err: | |
418 | return (err, head) |
|
418 | return (err, head) | |
419 | self.save_dirty() |
|
419 | self.save_dirty() | |
420 | return (0, head) |
|
420 | return (0, head) | |
421 |
|
421 | |||
422 | def patch(self, repo, patchfile): |
|
422 | def patch(self, repo, patchfile): | |
423 | '''Apply patchfile to the working directory. |
|
423 | '''Apply patchfile to the working directory. | |
424 | patchfile: file name of patch''' |
|
424 | patchfile: file name of patch''' | |
425 | files = {} |
|
425 | files = {} | |
426 | try: |
|
426 | try: | |
427 | fuzz = patch.patch(patchfile, self.ui, strip=1, cwd=repo.root, |
|
427 | fuzz = patch.patch(patchfile, self.ui, strip=1, cwd=repo.root, | |
428 | files=files) |
|
428 | files=files) | |
429 | except Exception, inst: |
|
429 | except Exception, inst: | |
430 | self.ui.note(str(inst) + '\n') |
|
430 | self.ui.note(str(inst) + '\n') | |
431 | if not self.ui.verbose: |
|
431 | if not self.ui.verbose: | |
432 | self.ui.warn("patch failed, unable to continue (try -v)\n") |
|
432 | self.ui.warn("patch failed, unable to continue (try -v)\n") | |
433 | return (False, files, False) |
|
433 | return (False, files, False) | |
434 |
|
434 | |||
435 | return (True, files, fuzz) |
|
435 | return (True, files, fuzz) | |
436 |
|
436 | |||
437 | def apply(self, repo, series, list=False, update_status=True, |
|
437 | def apply(self, repo, series, list=False, update_status=True, | |
438 | strict=False, patchdir=None, merge=None, all_files={}): |
|
438 | strict=False, patchdir=None, merge=None, all_files={}): | |
439 | wlock = lock = tr = None |
|
439 | wlock = lock = tr = None | |
440 | try: |
|
440 | try: | |
441 | wlock = repo.wlock() |
|
441 | wlock = repo.wlock() | |
442 | lock = repo.lock() |
|
442 | lock = repo.lock() | |
443 | tr = repo.transaction() |
|
443 | tr = repo.transaction() | |
444 | try: |
|
444 | try: | |
445 | ret = self._apply(repo, series, list, update_status, |
|
445 | ret = self._apply(repo, series, list, update_status, | |
446 | strict, patchdir, merge, all_files=all_files) |
|
446 | strict, patchdir, merge, all_files=all_files) | |
447 | tr.close() |
|
447 | tr.close() | |
448 | self.save_dirty() |
|
448 | self.save_dirty() | |
449 | return ret |
|
449 | return ret | |
450 | except: |
|
450 | except: | |
451 | try: |
|
451 | try: | |
452 | tr.abort() |
|
452 | tr.abort() | |
453 | finally: |
|
453 | finally: | |
454 | repo.invalidate() |
|
454 | repo.invalidate() | |
455 | repo.dirstate.invalidate() |
|
455 | repo.dirstate.invalidate() | |
456 | raise |
|
456 | raise | |
457 | finally: |
|
457 | finally: | |
458 | del tr, lock, wlock |
|
458 | del tr, lock, wlock | |
459 |
|
459 | |||
460 | def _apply(self, repo, series, list=False, update_status=True, |
|
460 | def _apply(self, repo, series, list=False, update_status=True, | |
461 | strict=False, patchdir=None, merge=None, all_files={}): |
|
461 | strict=False, patchdir=None, merge=None, all_files={}): | |
462 | # TODO unify with commands.py |
|
462 | # TODO unify with commands.py | |
463 | if not patchdir: |
|
463 | if not patchdir: | |
464 | patchdir = self.path |
|
464 | patchdir = self.path | |
465 | err = 0 |
|
465 | err = 0 | |
466 | n = None |
|
466 | n = None | |
467 | for patchname in series: |
|
467 | for patchname in series: | |
468 | pushable, reason = self.pushable(patchname) |
|
468 | pushable, reason = self.pushable(patchname) | |
469 | if not pushable: |
|
469 | if not pushable: | |
470 | self.explain_pushable(patchname, all_patches=True) |
|
470 | self.explain_pushable(patchname, all_patches=True) | |
471 | continue |
|
471 | continue | |
472 | self.ui.warn("applying %s\n" % patchname) |
|
472 | self.ui.warn("applying %s\n" % patchname) | |
473 | pf = os.path.join(patchdir, patchname) |
|
473 | pf = os.path.join(patchdir, patchname) | |
474 |
|
474 | |||
475 | try: |
|
475 | try: | |
476 | message, comments, user, date, patchfound = self.readheaders(patchname) |
|
476 | message, comments, user, date, patchfound = self.readheaders(patchname) | |
477 | except: |
|
477 | except: | |
478 | self.ui.warn("Unable to read %s\n" % patchname) |
|
478 | self.ui.warn("Unable to read %s\n" % patchname) | |
479 | err = 1 |
|
479 | err = 1 | |
480 | break |
|
480 | break | |
481 |
|
481 | |||
482 | if not message: |
|
482 | if not message: | |
483 | message = "imported patch %s\n" % patchname |
|
483 | message = "imported patch %s\n" % patchname | |
484 | else: |
|
484 | else: | |
485 | if list: |
|
485 | if list: | |
486 | message.append("\nimported patch %s" % patchname) |
|
486 | message.append("\nimported patch %s" % patchname) | |
487 | message = '\n'.join(message) |
|
487 | message = '\n'.join(message) | |
488 |
|
488 | |||
489 | (patcherr, files, fuzz) = self.patch(repo, pf) |
|
489 | (patcherr, files, fuzz) = self.patch(repo, pf) | |
490 | all_files.update(files) |
|
490 | all_files.update(files) | |
491 | patcherr = not patcherr |
|
491 | patcherr = not patcherr | |
492 |
|
492 | |||
493 | if merge and files: |
|
493 | if merge and files: | |
494 | # Mark as removed/merged and update dirstate parent info |
|
494 | # Mark as removed/merged and update dirstate parent info | |
495 | removed = [] |
|
495 | removed = [] | |
496 | merged = [] |
|
496 | merged = [] | |
497 | for f in files: |
|
497 | for f in files: | |
498 | if os.path.exists(repo.wjoin(f)): |
|
498 | if os.path.exists(repo.wjoin(f)): | |
499 | merged.append(f) |
|
499 | merged.append(f) | |
500 | else: |
|
500 | else: | |
501 | removed.append(f) |
|
501 | removed.append(f) | |
502 | for f in removed: |
|
502 | for f in removed: | |
503 | repo.dirstate.remove(f) |
|
503 | repo.dirstate.remove(f) | |
504 | for f in merged: |
|
504 | for f in merged: | |
505 | repo.dirstate.merge(f) |
|
505 | repo.dirstate.merge(f) | |
506 | p1, p2 = repo.dirstate.parents() |
|
506 | p1, p2 = repo.dirstate.parents() | |
507 | repo.dirstate.setparents(p1, merge) |
|
507 | repo.dirstate.setparents(p1, merge) | |
508 | files = patch.updatedir(self.ui, repo, files) |
|
508 | files = patch.updatedir(self.ui, repo, files) | |
509 | n = repo.commit(files, message, user, date, force=1) |
|
509 | n = repo.commit(files, message, user, date, force=1) | |
510 |
|
510 | |||
511 | if n == None: |
|
511 | if n == None: | |
512 | raise util.Abort(_("repo commit failed")) |
|
512 | raise util.Abort(_("repo commit failed")) | |
513 |
|
513 | |||
514 | if update_status: |
|
514 | if update_status: | |
515 | self.applied.append(statusentry(revlog.hex(n), patchname)) |
|
515 | self.applied.append(statusentry(revlog.hex(n), patchname)) | |
516 |
|
516 | |||
517 | if patcherr: |
|
517 | if patcherr: | |
518 | if not patchfound: |
|
518 | if not patchfound: | |
519 | self.ui.warn("patch %s is empty\n" % patchname) |
|
519 | self.ui.warn("patch %s is empty\n" % patchname) | |
520 | err = 0 |
|
520 | err = 0 | |
521 | else: |
|
521 | else: | |
522 | self.ui.warn("patch failed, rejects left in working dir\n") |
|
522 | self.ui.warn("patch failed, rejects left in working dir\n") | |
523 | err = 1 |
|
523 | err = 1 | |
524 | break |
|
524 | break | |
525 |
|
525 | |||
526 | if fuzz and strict: |
|
526 | if fuzz and strict: | |
527 | self.ui.warn("fuzz found when applying patch, stopping\n") |
|
527 | self.ui.warn("fuzz found when applying patch, stopping\n") | |
528 | err = 1 |
|
528 | err = 1 | |
529 | break |
|
529 | break | |
530 | self.removeundo(repo) |
|
530 | self.removeundo(repo) | |
531 | return (err, n) |
|
531 | return (err, n) | |
532 |
|
532 | |||
533 | def delete(self, repo, patches, opts): |
|
533 | def delete(self, repo, patches, opts): | |
534 | if not patches and not opts.get('rev'): |
|
534 | if not patches and not opts.get('rev'): | |
535 | raise util.Abort(_('qdelete requires at least one revision or ' |
|
535 | raise util.Abort(_('qdelete requires at least one revision or ' | |
536 | 'patch name')) |
|
536 | 'patch name')) | |
537 |
|
537 | |||
538 | realpatches = [] |
|
538 | realpatches = [] | |
539 | for patch in patches: |
|
539 | for patch in patches: | |
540 | patch = self.lookup(patch, strict=True) |
|
540 | patch = self.lookup(patch, strict=True) | |
541 | info = self.isapplied(patch) |
|
541 | info = self.isapplied(patch) | |
542 | if info: |
|
542 | if info: | |
543 | raise util.Abort(_("cannot delete applied patch %s") % patch) |
|
543 | raise util.Abort(_("cannot delete applied patch %s") % patch) | |
544 | if patch not in self.series: |
|
544 | if patch not in self.series: | |
545 | raise util.Abort(_("patch %s not in series file") % patch) |
|
545 | raise util.Abort(_("patch %s not in series file") % patch) | |
546 | realpatches.append(patch) |
|
546 | realpatches.append(patch) | |
547 |
|
547 | |||
548 | appliedbase = 0 |
|
548 | appliedbase = 0 | |
549 | if opts.get('rev'): |
|
549 | if opts.get('rev'): | |
550 | if not self.applied: |
|
550 | if not self.applied: | |
551 | raise util.Abort(_('no patches applied')) |
|
551 | raise util.Abort(_('no patches applied')) | |
552 | revs = cmdutil.revrange(repo, opts['rev']) |
|
552 | revs = cmdutil.revrange(repo, opts['rev']) | |
553 | if len(revs) > 1 and revs[0] > revs[1]: |
|
553 | if len(revs) > 1 and revs[0] > revs[1]: | |
554 | revs.reverse() |
|
554 | revs.reverse() | |
555 | for rev in revs: |
|
555 | for rev in revs: | |
556 | if appliedbase >= len(self.applied): |
|
556 | if appliedbase >= len(self.applied): | |
557 | raise util.Abort(_("revision %d is not managed") % rev) |
|
557 | raise util.Abort(_("revision %d is not managed") % rev) | |
558 |
|
558 | |||
559 | base = revlog.bin(self.applied[appliedbase].rev) |
|
559 | base = revlog.bin(self.applied[appliedbase].rev) | |
560 | node = repo.changelog.node(rev) |
|
560 | node = repo.changelog.node(rev) | |
561 | if node != base: |
|
561 | if node != base: | |
562 | raise util.Abort(_("cannot delete revision %d above " |
|
562 | raise util.Abort(_("cannot delete revision %d above " | |
563 | "applied patches") % rev) |
|
563 | "applied patches") % rev) | |
564 | realpatches.append(self.applied[appliedbase].name) |
|
564 | realpatches.append(self.applied[appliedbase].name) | |
565 | appliedbase += 1 |
|
565 | appliedbase += 1 | |
566 |
|
566 | |||
567 | if not opts.get('keep'): |
|
567 | if not opts.get('keep'): | |
568 | r = self.qrepo() |
|
568 | r = self.qrepo() | |
569 | if r: |
|
569 | if r: | |
570 | r.remove(realpatches, True) |
|
570 | r.remove(realpatches, True) | |
571 | else: |
|
571 | else: | |
572 | for p in realpatches: |
|
572 | for p in realpatches: | |
573 | os.unlink(self.join(p)) |
|
573 | os.unlink(self.join(p)) | |
574 |
|
574 | |||
575 | if appliedbase: |
|
575 | if appliedbase: | |
576 | del self.applied[:appliedbase] |
|
576 | del self.applied[:appliedbase] | |
577 | self.applied_dirty = 1 |
|
577 | self.applied_dirty = 1 | |
578 | indices = [self.find_series(p) for p in realpatches] |
|
578 | indices = [self.find_series(p) for p in realpatches] | |
579 | indices.sort() |
|
579 | indices.sort() | |
580 | for i in indices[-1::-1]: |
|
580 | for i in indices[-1::-1]: | |
581 | del self.full_series[i] |
|
581 | del self.full_series[i] | |
582 | self.parse_series() |
|
582 | self.parse_series() | |
583 | self.series_dirty = 1 |
|
583 | self.series_dirty = 1 | |
584 |
|
584 | |||
585 | def check_toppatch(self, repo): |
|
585 | def check_toppatch(self, repo): | |
586 | if len(self.applied) > 0: |
|
586 | if len(self.applied) > 0: | |
587 | top = revlog.bin(self.applied[-1].rev) |
|
587 | top = revlog.bin(self.applied[-1].rev) | |
588 | pp = repo.dirstate.parents() |
|
588 | pp = repo.dirstate.parents() | |
589 | if top not in pp: |
|
589 | if top not in pp: | |
590 | raise util.Abort(_("queue top not at same revision as working directory")) |
|
590 | raise util.Abort(_("queue top not at same revision as working directory")) | |
591 | return top |
|
591 | return top | |
592 | return None |
|
592 | return None | |
593 | def check_localchanges(self, repo, force=False, refresh=True): |
|
593 | def check_localchanges(self, repo, force=False, refresh=True): | |
594 | m, a, r, d = repo.status()[:4] |
|
594 | m, a, r, d = repo.status()[:4] | |
595 | if m or a or r or d: |
|
595 | if m or a or r or d: | |
596 | if not force: |
|
596 | if not force: | |
597 | if refresh: |
|
597 | if refresh: | |
598 | raise util.Abort(_("local changes found, refresh first")) |
|
598 | raise util.Abort(_("local changes found, refresh first")) | |
599 | else: |
|
599 | else: | |
600 | raise util.Abort(_("local changes found")) |
|
600 | raise util.Abort(_("local changes found")) | |
601 | return m, a, r, d |
|
601 | return m, a, r, d | |
602 |
|
602 | |||
603 | def new(self, repo, patch, *pats, **opts): |
|
603 | def new(self, repo, patch, *pats, **opts): | |
604 | msg = opts.get('msg') |
|
604 | msg = opts.get('msg') | |
605 | force = opts.get('force') |
|
605 | force = opts.get('force') | |
606 | if os.path.exists(self.join(patch)): |
|
606 | if os.path.exists(self.join(patch)): | |
607 | raise util.Abort(_('patch "%s" already exists') % patch) |
|
607 | raise util.Abort(_('patch "%s" already exists') % patch) | |
608 | if opts.get('include') or opts.get('exclude') or pats: |
|
608 | if opts.get('include') or opts.get('exclude') or pats: | |
609 | fns, match, anypats = cmdutil.matchpats(repo, pats, opts) |
|
609 | fns, match, anypats = cmdutil.matchpats(repo, pats, opts) | |
610 | m, a, r, d = repo.status(files=fns, match=match)[:4] |
|
610 | m, a, r, d = repo.status(files=fns, match=match)[:4] | |
611 | else: |
|
611 | else: | |
612 | m, a, r, d = self.check_localchanges(repo, force) |
|
612 | m, a, r, d = self.check_localchanges(repo, force) | |
613 | commitfiles = m + a + r |
|
613 | commitfiles = m + a + r | |
614 | self.check_toppatch(repo) |
|
614 | self.check_toppatch(repo) | |
615 | wlock = repo.wlock() |
|
615 | wlock = repo.wlock() | |
616 | try: |
|
616 | try: | |
617 | insert = self.full_series_end() |
|
617 | insert = self.full_series_end() | |
618 | if msg: |
|
618 | if msg: | |
619 | n = repo.commit(commitfiles, msg, force=True) |
|
619 | n = repo.commit(commitfiles, msg, force=True) | |
620 | else: |
|
620 | else: | |
621 | n = repo.commit(commitfiles, "[mq]: %s" % patch, force=True) |
|
621 | n = repo.commit(commitfiles, "[mq]: %s" % patch, force=True) | |
622 | if n == None: |
|
622 | if n == None: | |
623 | raise util.Abort(_("repo commit failed")) |
|
623 | raise util.Abort(_("repo commit failed")) | |
624 | self.full_series[insert:insert] = [patch] |
|
624 | self.full_series[insert:insert] = [patch] | |
625 | self.applied.append(statusentry(revlog.hex(n), patch)) |
|
625 | self.applied.append(statusentry(revlog.hex(n), patch)) | |
626 | self.parse_series() |
|
626 | self.parse_series() | |
627 | self.series_dirty = 1 |
|
627 | self.series_dirty = 1 | |
628 | self.applied_dirty = 1 |
|
628 | self.applied_dirty = 1 | |
629 | p = self.opener(patch, "w") |
|
629 | p = self.opener(patch, "w") | |
630 | if msg: |
|
630 | if msg: | |
631 | msg = msg + "\n" |
|
631 | msg = msg + "\n" | |
632 | p.write(msg) |
|
632 | p.write(msg) | |
633 | p.close() |
|
633 | p.close() | |
634 | wlock = None |
|
634 | wlock = None | |
635 | r = self.qrepo() |
|
635 | r = self.qrepo() | |
636 | if r: r.add([patch]) |
|
636 | if r: r.add([patch]) | |
637 | if commitfiles: |
|
637 | if commitfiles: | |
638 | self.refresh(repo, short=True, git=opts.get('git')) |
|
638 | self.refresh(repo, short=True, git=opts.get('git')) | |
639 | self.removeundo(repo) |
|
639 | self.removeundo(repo) | |
640 | finally: |
|
640 | finally: | |
641 | del wlock |
|
641 | del wlock | |
642 |
|
642 | |||
643 | def strip(self, repo, rev, update=True, backup="all"): |
|
643 | def strip(self, repo, rev, update=True, backup="all"): | |
644 | wlock = lock = None |
|
644 | wlock = lock = None | |
645 | try: |
|
645 | try: | |
646 | wlock = repo.wlock() |
|
646 | wlock = repo.wlock() | |
647 | lock = repo.lock() |
|
647 | lock = repo.lock() | |
648 |
|
648 | |||
649 | if update: |
|
649 | if update: | |
650 | self.check_localchanges(repo, refresh=False) |
|
650 | self.check_localchanges(repo, refresh=False) | |
651 | urev = self.qparents(repo, rev) |
|
651 | urev = self.qparents(repo, rev) | |
652 | hg.clean(repo, urev) |
|
652 | hg.clean(repo, urev) | |
653 | repo.dirstate.write() |
|
653 | repo.dirstate.write() | |
654 |
|
654 | |||
655 | self.removeundo(repo) |
|
655 | self.removeundo(repo) | |
656 | repair.strip(self.ui, repo, rev, backup) |
|
656 | repair.strip(self.ui, repo, rev, backup) | |
657 | finally: |
|
657 | finally: | |
658 | del lock, wlock |
|
658 | del lock, wlock | |
659 |
|
659 | |||
660 | def isapplied(self, patch): |
|
660 | def isapplied(self, patch): | |
661 | """returns (index, rev, patch)""" |
|
661 | """returns (index, rev, patch)""" | |
662 | for i in xrange(len(self.applied)): |
|
662 | for i in xrange(len(self.applied)): | |
663 | a = self.applied[i] |
|
663 | a = self.applied[i] | |
664 | if a.name == patch: |
|
664 | if a.name == patch: | |
665 | return (i, a.rev, a.name) |
|
665 | return (i, a.rev, a.name) | |
666 | return None |
|
666 | return None | |
667 |
|
667 | |||
668 | # if the exact patch name does not exist, we try a few |
|
668 | # if the exact patch name does not exist, we try a few | |
669 | # variations. If strict is passed, we try only #1 |
|
669 | # variations. If strict is passed, we try only #1 | |
670 | # |
|
670 | # | |
671 | # 1) a number to indicate an offset in the series file |
|
671 | # 1) a number to indicate an offset in the series file | |
672 | # 2) a unique substring of the patch name was given |
|
672 | # 2) a unique substring of the patch name was given | |
673 | # 3) patchname[-+]num to indicate an offset in the series file |
|
673 | # 3) patchname[-+]num to indicate an offset in the series file | |
674 | def lookup(self, patch, strict=False): |
|
674 | def lookup(self, patch, strict=False): | |
675 | patch = patch and str(patch) |
|
675 | patch = patch and str(patch) | |
676 |
|
676 | |||
677 | def partial_name(s): |
|
677 | def partial_name(s): | |
678 | if s in self.series: |
|
678 | if s in self.series: | |
679 | return s |
|
679 | return s | |
680 | matches = [x for x in self.series if s in x] |
|
680 | matches = [x for x in self.series if s in x] | |
681 | if len(matches) > 1: |
|
681 | if len(matches) > 1: | |
682 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) |
|
682 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) | |
683 | for m in matches: |
|
683 | for m in matches: | |
684 | self.ui.warn(' %s\n' % m) |
|
684 | self.ui.warn(' %s\n' % m) | |
685 | return None |
|
685 | return None | |
686 | if matches: |
|
686 | if matches: | |
687 | return matches[0] |
|
687 | return matches[0] | |
688 | if len(self.series) > 0 and len(self.applied) > 0: |
|
688 | if len(self.series) > 0 and len(self.applied) > 0: | |
689 | if s == 'qtip': |
|
689 | if s == 'qtip': | |
690 | return self.series[self.series_end(True)-1] |
|
690 | return self.series[self.series_end(True)-1] | |
691 | if s == 'qbase': |
|
691 | if s == 'qbase': | |
692 | return self.series[0] |
|
692 | return self.series[0] | |
693 | return None |
|
693 | return None | |
694 | if patch == None: |
|
694 | if patch == None: | |
695 | return None |
|
695 | return None | |
696 |
|
696 | |||
697 | # we don't want to return a partial match until we make |
|
697 | # we don't want to return a partial match until we make | |
698 | # sure the file name passed in does not exist (checked below) |
|
698 | # sure the file name passed in does not exist (checked below) | |
699 | res = partial_name(patch) |
|
699 | res = partial_name(patch) | |
700 | if res and res == patch: |
|
700 | if res and res == patch: | |
701 | return res |
|
701 | return res | |
702 |
|
702 | |||
703 | if not os.path.isfile(self.join(patch)): |
|
703 | if not os.path.isfile(self.join(patch)): | |
704 | try: |
|
704 | try: | |
705 | sno = int(patch) |
|
705 | sno = int(patch) | |
706 | except(ValueError, OverflowError): |
|
706 | except(ValueError, OverflowError): | |
707 | pass |
|
707 | pass | |
708 | else: |
|
708 | else: | |
709 | if sno < len(self.series): |
|
709 | if sno < len(self.series): | |
710 | return self.series[sno] |
|
710 | return self.series[sno] | |
711 | if not strict: |
|
711 | if not strict: | |
712 | # return any partial match made above |
|
712 | # return any partial match made above | |
713 | if res: |
|
713 | if res: | |
714 | return res |
|
714 | return res | |
715 | minus = patch.rfind('-') |
|
715 | minus = patch.rfind('-') | |
716 | if minus >= 0: |
|
716 | if minus >= 0: | |
717 | res = partial_name(patch[:minus]) |
|
717 | res = partial_name(patch[:minus]) | |
718 | if res: |
|
718 | if res: | |
719 | i = self.series.index(res) |
|
719 | i = self.series.index(res) | |
720 | try: |
|
720 | try: | |
721 | off = int(patch[minus+1:] or 1) |
|
721 | off = int(patch[minus+1:] or 1) | |
722 | except(ValueError, OverflowError): |
|
722 | except(ValueError, OverflowError): | |
723 | pass |
|
723 | pass | |
724 | else: |
|
724 | else: | |
725 | if i - off >= 0: |
|
725 | if i - off >= 0: | |
726 | return self.series[i - off] |
|
726 | return self.series[i - off] | |
727 | plus = patch.rfind('+') |
|
727 | plus = patch.rfind('+') | |
728 | if plus >= 0: |
|
728 | if plus >= 0: | |
729 | res = partial_name(patch[:plus]) |
|
729 | res = partial_name(patch[:plus]) | |
730 | if res: |
|
730 | if res: | |
731 | i = self.series.index(res) |
|
731 | i = self.series.index(res) | |
732 | try: |
|
732 | try: | |
733 | off = int(patch[plus+1:] or 1) |
|
733 | off = int(patch[plus+1:] or 1) | |
734 | except(ValueError, OverflowError): |
|
734 | except(ValueError, OverflowError): | |
735 | pass |
|
735 | pass | |
736 | else: |
|
736 | else: | |
737 | if i + off < len(self.series): |
|
737 | if i + off < len(self.series): | |
738 | return self.series[i + off] |
|
738 | return self.series[i + off] | |
739 | raise util.Abort(_("patch %s not in series") % patch) |
|
739 | raise util.Abort(_("patch %s not in series") % patch) | |
740 |
|
740 | |||
741 | def push(self, repo, patch=None, force=False, list=False, |
|
741 | def push(self, repo, patch=None, force=False, list=False, | |
742 | mergeq=None): |
|
742 | mergeq=None): | |
743 | wlock = repo.wlock() |
|
743 | wlock = repo.wlock() | |
744 | try: |
|
744 | try: | |
745 | patch = self.lookup(patch) |
|
745 | patch = self.lookup(patch) | |
746 | # Suppose our series file is: A B C and the current 'top' |
|
746 | # Suppose our series file is: A B C and the current 'top' | |
747 | # patch is B. qpush C should be performed (moving forward) |
|
747 | # patch is B. qpush C should be performed (moving forward) | |
748 | # qpush B is a NOP (no change) qpush A is an error (can't |
|
748 | # qpush B is a NOP (no change) qpush A is an error (can't | |
749 | # go backwards with qpush) |
|
749 | # go backwards with qpush) | |
750 | if patch: |
|
750 | if patch: | |
751 | info = self.isapplied(patch) |
|
751 | info = self.isapplied(patch) | |
752 | if info: |
|
752 | if info: | |
753 | if info[0] < len(self.applied) - 1: |
|
753 | if info[0] < len(self.applied) - 1: | |
754 | raise util.Abort( |
|
754 | raise util.Abort( | |
755 | _("cannot push to a previous patch: %s") % patch) |
|
755 | _("cannot push to a previous patch: %s") % patch) | |
756 | if info[0] < len(self.series) - 1: |
|
756 | if info[0] < len(self.series) - 1: | |
757 | self.ui.warn( |
|
757 | self.ui.warn( | |
758 | _('qpush: %s is already at the top\n') % patch) |
|
758 | _('qpush: %s is already at the top\n') % patch) | |
759 | else: |
|
759 | else: | |
760 | self.ui.warn(_('all patches are currently applied\n')) |
|
760 | self.ui.warn(_('all patches are currently applied\n')) | |
761 | return |
|
761 | return | |
762 |
|
762 | |||
763 | # Following the above example, starting at 'top' of B: |
|
763 | # Following the above example, starting at 'top' of B: | |
764 | # qpush should be performed (pushes C), but a subsequent |
|
764 | # qpush should be performed (pushes C), but a subsequent | |
765 | # qpush without an argument is an error (nothing to |
|
765 | # qpush without an argument is an error (nothing to | |
766 | # apply). This allows a loop of "...while hg qpush..." to |
|
766 | # apply). This allows a loop of "...while hg qpush..." to | |
767 | # work as it detects an error when done |
|
767 | # work as it detects an error when done | |
768 | if self.series_end() == len(self.series): |
|
768 | if self.series_end() == len(self.series): | |
769 | self.ui.warn(_('patch series already fully applied\n')) |
|
769 | self.ui.warn(_('patch series already fully applied\n')) | |
770 | return 1 |
|
770 | return 1 | |
771 | if not force: |
|
771 | if not force: | |
772 | self.check_localchanges(repo) |
|
772 | self.check_localchanges(repo) | |
773 |
|
773 | |||
774 | self.applied_dirty = 1; |
|
774 | self.applied_dirty = 1; | |
775 | start = self.series_end() |
|
775 | start = self.series_end() | |
776 | if start > 0: |
|
776 | if start > 0: | |
777 | self.check_toppatch(repo) |
|
777 | self.check_toppatch(repo) | |
778 | if not patch: |
|
778 | if not patch: | |
779 | patch = self.series[start] |
|
779 | patch = self.series[start] | |
780 | end = start + 1 |
|
780 | end = start + 1 | |
781 | else: |
|
781 | else: | |
782 | end = self.series.index(patch, start) + 1 |
|
782 | end = self.series.index(patch, start) + 1 | |
783 | s = self.series[start:end] |
|
783 | s = self.series[start:end] | |
784 | all_files = {} |
|
784 | all_files = {} | |
785 | try: |
|
785 | try: | |
786 | if mergeq: |
|
786 | if mergeq: | |
787 | ret = self.mergepatch(repo, mergeq, s) |
|
787 | ret = self.mergepatch(repo, mergeq, s) | |
788 | else: |
|
788 | else: | |
789 | ret = self.apply(repo, s, list, all_files=all_files) |
|
789 | ret = self.apply(repo, s, list, all_files=all_files) | |
790 | except: |
|
790 | except: | |
791 | self.ui.warn(_('cleaning up working directory...')) |
|
791 | self.ui.warn(_('cleaning up working directory...')) | |
792 | node = repo.dirstate.parents()[0] |
|
792 | node = repo.dirstate.parents()[0] | |
793 | hg.revert(repo, node, None) |
|
793 | hg.revert(repo, node, None) | |
794 | unknown = repo.status()[4] |
|
794 | unknown = repo.status()[4] | |
795 | # only remove unknown files that we know we touched or |
|
795 | # only remove unknown files that we know we touched or | |
796 | # created while patching |
|
796 | # created while patching | |
797 | for f in unknown: |
|
797 | for f in unknown: | |
798 | if f in all_files: |
|
798 | if f in all_files: | |
799 | util.unlink(repo.wjoin(f)) |
|
799 | util.unlink(repo.wjoin(f)) | |
800 | self.ui.warn(_('done\n')) |
|
800 | self.ui.warn(_('done\n')) | |
801 | raise |
|
801 | raise | |
802 | top = self.applied[-1].name |
|
802 | top = self.applied[-1].name | |
803 | if ret[0]: |
|
803 | if ret[0]: | |
804 | self.ui.write( |
|
804 | self.ui.write( | |
805 | "Errors during apply, please fix and refresh %s\n" % top) |
|
805 | "Errors during apply, please fix and refresh %s\n" % top) | |
806 | else: |
|
806 | else: | |
807 | self.ui.write("Now at: %s\n" % top) |
|
807 | self.ui.write("Now at: %s\n" % top) | |
808 | return ret[0] |
|
808 | return ret[0] | |
809 | finally: |
|
809 | finally: | |
810 | del wlock |
|
810 | del wlock | |
811 |
|
811 | |||
812 | def pop(self, repo, patch=None, force=False, update=True, all=False): |
|
812 | def pop(self, repo, patch=None, force=False, update=True, all=False): | |
813 | def getfile(f, rev, flags): |
|
813 | def getfile(f, rev, flags): | |
814 | t = repo.file(f).read(rev) |
|
814 | t = repo.file(f).read(rev) | |
815 | repo.wwrite(f, t, flags) |
|
815 | repo.wwrite(f, t, flags) | |
816 |
|
816 | |||
817 | wlock = repo.wlock() |
|
817 | wlock = repo.wlock() | |
818 | try: |
|
818 | try: | |
819 | if patch: |
|
819 | if patch: | |
820 | # index, rev, patch |
|
820 | # index, rev, patch | |
821 | info = self.isapplied(patch) |
|
821 | info = self.isapplied(patch) | |
822 | if not info: |
|
822 | if not info: | |
823 | patch = self.lookup(patch) |
|
823 | patch = self.lookup(patch) | |
824 | info = self.isapplied(patch) |
|
824 | info = self.isapplied(patch) | |
825 | if not info: |
|
825 | if not info: | |
826 | raise util.Abort(_("patch %s is not applied") % patch) |
|
826 | raise util.Abort(_("patch %s is not applied") % patch) | |
827 |
|
827 | |||
828 | if len(self.applied) == 0: |
|
828 | if len(self.applied) == 0: | |
829 | # Allow qpop -a to work repeatedly, |
|
829 | # Allow qpop -a to work repeatedly, | |
830 | # but not qpop without an argument |
|
830 | # but not qpop without an argument | |
831 | self.ui.warn(_("no patches applied\n")) |
|
831 | self.ui.warn(_("no patches applied\n")) | |
832 | return not all |
|
832 | return not all | |
833 |
|
833 | |||
834 | if not update: |
|
834 | if not update: | |
835 | parents = repo.dirstate.parents() |
|
835 | parents = repo.dirstate.parents() | |
836 | rr = [ revlog.bin(x.rev) for x in self.applied ] |
|
836 | rr = [ revlog.bin(x.rev) for x in self.applied ] | |
837 | for p in parents: |
|
837 | for p in parents: | |
838 | if p in rr: |
|
838 | if p in rr: | |
839 | self.ui.warn("qpop: forcing dirstate update\n") |
|
839 | self.ui.warn("qpop: forcing dirstate update\n") | |
840 | update = True |
|
840 | update = True | |
841 |
|
841 | |||
842 | if not force and update: |
|
842 | if not force and update: | |
843 | self.check_localchanges(repo) |
|
843 | self.check_localchanges(repo) | |
844 |
|
844 | |||
845 | self.applied_dirty = 1; |
|
845 | self.applied_dirty = 1; | |
846 | end = len(self.applied) |
|
846 | end = len(self.applied) | |
847 | if not patch: |
|
847 | if not patch: | |
848 | if all: |
|
848 | if all: | |
849 | popi = 0 |
|
849 | popi = 0 | |
850 | else: |
|
850 | else: | |
851 | popi = len(self.applied) - 1 |
|
851 | popi = len(self.applied) - 1 | |
852 | else: |
|
852 | else: | |
853 | popi = info[0] + 1 |
|
853 | popi = info[0] + 1 | |
854 | if popi >= end: |
|
854 | if popi >= end: | |
855 | self.ui.warn("qpop: %s is already at the top\n" % patch) |
|
855 | self.ui.warn("qpop: %s is already at the top\n" % patch) | |
856 | return |
|
856 | return | |
857 | info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name] |
|
857 | info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name] | |
858 |
|
858 | |||
859 | start = info[0] |
|
859 | start = info[0] | |
860 | rev = revlog.bin(info[1]) |
|
860 | rev = revlog.bin(info[1]) | |
861 |
|
861 | |||
862 | # we know there are no local changes, so we can make a simplified |
|
862 | # we know there are no local changes, so we can make a simplified | |
863 | # form of hg.update. |
|
863 | # form of hg.update. | |
864 | if update: |
|
864 | if update: | |
865 | top = self.check_toppatch(repo) |
|
865 | top = self.check_toppatch(repo) | |
866 | qp = self.qparents(repo, rev) |
|
866 | qp = self.qparents(repo, rev) | |
867 | changes = repo.changelog.read(qp) |
|
867 | changes = repo.changelog.read(qp) | |
868 | mmap = repo.manifest.read(changes[0]) |
|
868 | mmap = repo.manifest.read(changes[0]) | |
869 | m, a, r, d, u = repo.status(qp, top)[:5] |
|
869 | m, a, r, d, u = repo.status(qp, top)[:5] | |
870 | if d: |
|
870 | if d: | |
871 | raise util.Abort("deletions found between repo revs") |
|
871 | raise util.Abort("deletions found between repo revs") | |
872 | for f in m: |
|
872 | for f in m: | |
873 | getfile(f, mmap[f], mmap.flags(f)) |
|
873 | getfile(f, mmap[f], mmap.flags(f)) | |
874 | for f in r: |
|
874 | for f in r: | |
875 | getfile(f, mmap[f], mmap.flags(f)) |
|
875 | getfile(f, mmap[f], mmap.flags(f)) | |
876 | for f in m + r: |
|
876 | for f in m + r: | |
877 | repo.dirstate.normal(f) |
|
877 | repo.dirstate.normal(f) | |
878 | for f in a: |
|
878 | for f in a: | |
879 | try: |
|
879 | try: | |
880 | os.unlink(repo.wjoin(f)) |
|
880 | os.unlink(repo.wjoin(f)) | |
881 | except OSError, e: |
|
881 | except OSError, e: | |
882 | if e.errno != errno.ENOENT: |
|
882 | if e.errno != errno.ENOENT: | |
883 | raise |
|
883 | raise | |
884 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
|
884 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) | |
885 | except: pass |
|
885 | except: pass | |
886 | repo.dirstate.forget(f) |
|
886 | repo.dirstate.forget(f) | |
887 | repo.dirstate.setparents(qp, revlog.nullid) |
|
887 | repo.dirstate.setparents(qp, revlog.nullid) | |
888 | self.strip(repo, rev, update=False, backup='strip') |
|
888 | self.strip(repo, rev, update=False, backup='strip') | |
889 | del self.applied[start:end] |
|
889 | del self.applied[start:end] | |
890 | if len(self.applied): |
|
890 | if len(self.applied): | |
891 | self.ui.write("Now at: %s\n" % self.applied[-1].name) |
|
891 | self.ui.write("Now at: %s\n" % self.applied[-1].name) | |
892 | else: |
|
892 | else: | |
893 | self.ui.write("Patch queue now empty\n") |
|
893 | self.ui.write("Patch queue now empty\n") | |
894 | finally: |
|
894 | finally: | |
895 | del wlock |
|
895 | del wlock | |
896 |
|
896 | |||
897 | def diff(self, repo, pats, opts): |
|
897 | def diff(self, repo, pats, opts): | |
898 | top = self.check_toppatch(repo) |
|
898 | top = self.check_toppatch(repo) | |
899 | if not top: |
|
899 | if not top: | |
900 | self.ui.write("No patches applied\n") |
|
900 | self.ui.write("No patches applied\n") | |
901 | return |
|
901 | return | |
902 | qp = self.qparents(repo, top) |
|
902 | qp = self.qparents(repo, top) | |
903 | if opts.get('git'): |
|
903 | if opts.get('git'): | |
904 | self.diffopts().git = True |
|
904 | self.diffopts().git = True | |
905 | self.printdiff(repo, qp, files=pats, opts=opts) |
|
905 | self.printdiff(repo, qp, files=pats, opts=opts) | |
906 |
|
906 | |||
907 | def refresh(self, repo, pats=None, **opts): |
|
907 | def refresh(self, repo, pats=None, **opts): | |
908 | if len(self.applied) == 0: |
|
908 | if len(self.applied) == 0: | |
909 | self.ui.write("No patches applied\n") |
|
909 | self.ui.write("No patches applied\n") | |
910 | return 1 |
|
910 | return 1 | |
911 | wlock = repo.wlock() |
|
911 | wlock = repo.wlock() | |
912 | try: |
|
912 | try: | |
913 | self.check_toppatch(repo) |
|
913 | self.check_toppatch(repo) | |
914 | (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name) |
|
914 | (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name) | |
915 | top = revlog.bin(top) |
|
915 | top = revlog.bin(top) | |
916 | cparents = repo.changelog.parents(top) |
|
916 | cparents = repo.changelog.parents(top) | |
917 | patchparent = self.qparents(repo, top) |
|
917 | patchparent = self.qparents(repo, top) | |
918 | message, comments, user, date, patchfound = self.readheaders(patchfn) |
|
918 | message, comments, user, date, patchfound = self.readheaders(patchfn) | |
919 |
|
919 | |||
920 | patchf = self.opener(patchfn, 'r+') |
|
920 | patchf = self.opener(patchfn, 'r+') | |
921 |
|
921 | |||
922 | # if the patch was a git patch, refresh it as a git patch |
|
922 | # if the patch was a git patch, refresh it as a git patch | |
923 | for line in patchf: |
|
923 | for line in patchf: | |
924 | if line.startswith('diff --git'): |
|
924 | if line.startswith('diff --git'): | |
925 | self.diffopts().git = True |
|
925 | self.diffopts().git = True | |
926 | break |
|
926 | break | |
927 | patchf.seek(0) |
|
|||
928 | patchf.truncate() |
|
|||
929 |
|
927 | |||
930 | msg = opts.get('msg', '').rstrip() |
|
928 | msg = opts.get('msg', '').rstrip() | |
931 | if msg: |
|
929 | if msg: | |
932 | if comments: |
|
930 | if comments: | |
933 | # Remove existing message. |
|
931 | # Remove existing message. | |
934 | ci = 0 |
|
932 | ci = 0 | |
935 | subj = None |
|
933 | subj = None | |
936 | for mi in xrange(len(message)): |
|
934 | for mi in xrange(len(message)): | |
937 | if comments[ci].lower().startswith('subject: '): |
|
935 | if comments[ci].lower().startswith('subject: '): | |
938 | subj = comments[ci][9:] |
|
936 | subj = comments[ci][9:] | |
939 | while message[mi] != comments[ci] and message[mi] != subj: |
|
937 | while message[mi] != comments[ci] and message[mi] != subj: | |
940 | ci += 1 |
|
938 | ci += 1 | |
941 | del comments[ci] |
|
939 | del comments[ci] | |
942 | comments.append(msg) |
|
940 | comments.append(msg) | |
|
941 | ||||
|
942 | patchf.seek(0) | |||
|
943 | patchf.truncate() | |||
|
944 | ||||
943 | if comments: |
|
945 | if comments: | |
944 | comments = "\n".join(comments) + '\n\n' |
|
946 | comments = "\n".join(comments) + '\n\n' | |
945 | patchf.write(comments) |
|
947 | patchf.write(comments) | |
946 |
|
948 | |||
947 | if opts.get('git'): |
|
949 | if opts.get('git'): | |
948 | self.diffopts().git = True |
|
950 | self.diffopts().git = True | |
949 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
951 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
950 | tip = repo.changelog.tip() |
|
952 | tip = repo.changelog.tip() | |
951 | if top == tip: |
|
953 | if top == tip: | |
952 | # if the top of our patch queue is also the tip, there is an |
|
954 | # if the top of our patch queue is also the tip, there is an | |
953 | # optimization here. We update the dirstate in place and strip |
|
955 | # optimization here. We update the dirstate in place and strip | |
954 | # off the tip commit. Then just commit the current directory |
|
956 | # off the tip commit. Then just commit the current directory | |
955 | # tree. We can also send repo.commit the list of files |
|
957 | # tree. We can also send repo.commit the list of files | |
956 | # changed to speed up the diff |
|
958 | # changed to speed up the diff | |
957 | # |
|
959 | # | |
958 | # in short mode, we only diff the files included in the |
|
960 | # in short mode, we only diff the files included in the | |
959 | # patch already |
|
961 | # patch already | |
960 | # |
|
962 | # | |
961 | # this should really read: |
|
963 | # this should really read: | |
962 | # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5] |
|
964 | # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5] | |
963 | # but we do it backwards to take advantage of manifest/chlog |
|
965 | # but we do it backwards to take advantage of manifest/chlog | |
964 | # caching against the next repo.status call |
|
966 | # caching against the next repo.status call | |
965 | # |
|
967 | # | |
966 | mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5] |
|
968 | mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5] | |
967 | changes = repo.changelog.read(tip) |
|
969 | changes = repo.changelog.read(tip) | |
968 | man = repo.manifest.read(changes[0]) |
|
970 | man = repo.manifest.read(changes[0]) | |
969 | aaa = aa[:] |
|
971 | aaa = aa[:] | |
970 | if opts.get('short'): |
|
972 | if opts.get('short'): | |
971 | filelist = mm + aa + dd |
|
973 | filelist = mm + aa + dd | |
972 | match = dict.fromkeys(filelist).__contains__ |
|
974 | match = dict.fromkeys(filelist).__contains__ | |
973 | else: |
|
975 | else: | |
974 | filelist = None |
|
976 | filelist = None | |
975 | match = util.always |
|
977 | match = util.always | |
976 | m, a, r, d, u = repo.status(files=filelist, match=match)[:5] |
|
978 | m, a, r, d, u = repo.status(files=filelist, match=match)[:5] | |
977 |
|
979 | |||
978 | # we might end up with files that were added between |
|
980 | # we might end up with files that were added between | |
979 | # tip and the dirstate parent, but then changed in the |
|
981 | # tip and the dirstate parent, but then changed in the | |
980 | # local dirstate. in this case, we want them to only |
|
982 | # local dirstate. in this case, we want them to only | |
981 | # show up in the added section |
|
983 | # show up in the added section | |
982 | for x in m: |
|
984 | for x in m: | |
983 | if x not in aa: |
|
985 | if x not in aa: | |
984 | mm.append(x) |
|
986 | mm.append(x) | |
985 | # we might end up with files added by the local dirstate that |
|
987 | # we might end up with files added by the local dirstate that | |
986 | # were deleted by the patch. In this case, they should only |
|
988 | # were deleted by the patch. In this case, they should only | |
987 | # show up in the changed section. |
|
989 | # show up in the changed section. | |
988 | for x in a: |
|
990 | for x in a: | |
989 | if x in dd: |
|
991 | if x in dd: | |
990 | del dd[dd.index(x)] |
|
992 | del dd[dd.index(x)] | |
991 | mm.append(x) |
|
993 | mm.append(x) | |
992 | else: |
|
994 | else: | |
993 | aa.append(x) |
|
995 | aa.append(x) | |
994 | # make sure any files deleted in the local dirstate |
|
996 | # make sure any files deleted in the local dirstate | |
995 | # are not in the add or change column of the patch |
|
997 | # are not in the add or change column of the patch | |
996 | forget = [] |
|
998 | forget = [] | |
997 | for x in d + r: |
|
999 | for x in d + r: | |
998 | if x in aa: |
|
1000 | if x in aa: | |
999 | del aa[aa.index(x)] |
|
1001 | del aa[aa.index(x)] | |
1000 | forget.append(x) |
|
1002 | forget.append(x) | |
1001 | continue |
|
1003 | continue | |
1002 | elif x in mm: |
|
1004 | elif x in mm: | |
1003 | del mm[mm.index(x)] |
|
1005 | del mm[mm.index(x)] | |
1004 | dd.append(x) |
|
1006 | dd.append(x) | |
1005 |
|
1007 | |||
1006 | m = util.unique(mm) |
|
1008 | m = util.unique(mm) | |
1007 | r = util.unique(dd) |
|
1009 | r = util.unique(dd) | |
1008 | a = util.unique(aa) |
|
1010 | a = util.unique(aa) | |
1009 | c = [filter(matchfn, l) for l in (m, a, r, [], u)] |
|
1011 | c = [filter(matchfn, l) for l in (m, a, r, [], u)] | |
1010 | filelist = util.unique(c[0] + c[1] + c[2]) |
|
1012 | filelist = util.unique(c[0] + c[1] + c[2]) | |
1011 | patch.diff(repo, patchparent, files=filelist, match=matchfn, |
|
1013 | patch.diff(repo, patchparent, files=filelist, match=matchfn, | |
1012 | fp=patchf, changes=c, opts=self.diffopts()) |
|
1014 | fp=patchf, changes=c, opts=self.diffopts()) | |
1013 | patchf.close() |
|
1015 | patchf.close() | |
1014 |
|
1016 | |||
1015 | repo.dirstate.setparents(*cparents) |
|
1017 | repo.dirstate.setparents(*cparents) | |
1016 | copies = {} |
|
1018 | copies = {} | |
1017 | for dst in a: |
|
1019 | for dst in a: | |
1018 | src = repo.dirstate.copied(dst) |
|
1020 | src = repo.dirstate.copied(dst) | |
1019 | if src is None: |
|
1021 | if src is None: | |
1020 | continue |
|
1022 | continue | |
1021 | copies.setdefault(src, []).append(dst) |
|
1023 | copies.setdefault(src, []).append(dst) | |
1022 | repo.dirstate.add(dst) |
|
1024 | repo.dirstate.add(dst) | |
1023 | # remember the copies between patchparent and tip |
|
1025 | # remember the copies between patchparent and tip | |
1024 | # this may be slow, so don't do it if we're not tracking copies |
|
1026 | # this may be slow, so don't do it if we're not tracking copies | |
1025 | if self.diffopts().git: |
|
1027 | if self.diffopts().git: | |
1026 | for dst in aaa: |
|
1028 | for dst in aaa: | |
1027 | f = repo.file(dst) |
|
1029 | f = repo.file(dst) | |
1028 | src = f.renamed(man[dst]) |
|
1030 | src = f.renamed(man[dst]) | |
1029 | if src: |
|
1031 | if src: | |
1030 | copies[src[0]] = copies.get(dst, []) |
|
1032 | copies[src[0]] = copies.get(dst, []) | |
1031 | if dst in a: |
|
1033 | if dst in a: | |
1032 | copies[src[0]].append(dst) |
|
1034 | copies[src[0]].append(dst) | |
1033 | # we can't copy a file created by the patch itself |
|
1035 | # we can't copy a file created by the patch itself | |
1034 | if dst in copies: |
|
1036 | if dst in copies: | |
1035 | del copies[dst] |
|
1037 | del copies[dst] | |
1036 | for src, dsts in copies.iteritems(): |
|
1038 | for src, dsts in copies.iteritems(): | |
1037 | for dst in dsts: |
|
1039 | for dst in dsts: | |
1038 | repo.dirstate.copy(src, dst) |
|
1040 | repo.dirstate.copy(src, dst) | |
1039 | for f in r: |
|
1041 | for f in r: | |
1040 | repo.dirstate.remove(f) |
|
1042 | repo.dirstate.remove(f) | |
1041 | # if the patch excludes a modified file, mark that |
|
1043 | # if the patch excludes a modified file, mark that | |
1042 | # file with mtime=0 so status can see it. |
|
1044 | # file with mtime=0 so status can see it. | |
1043 | mm = [] |
|
1045 | mm = [] | |
1044 | for i in xrange(len(m)-1, -1, -1): |
|
1046 | for i in xrange(len(m)-1, -1, -1): | |
1045 | if not matchfn(m[i]): |
|
1047 | if not matchfn(m[i]): | |
1046 | mm.append(m[i]) |
|
1048 | mm.append(m[i]) | |
1047 | del m[i] |
|
1049 | del m[i] | |
1048 | for f in m: |
|
1050 | for f in m: | |
1049 | repo.dirstate.normal(f) |
|
1051 | repo.dirstate.normal(f) | |
1050 | for f in mm: |
|
1052 | for f in mm: | |
1051 | repo.dirstate.normaldirty(f) |
|
1053 | repo.dirstate.normaldirty(f) | |
1052 | for f in forget: |
|
1054 | for f in forget: | |
1053 | repo.dirstate.forget(f) |
|
1055 | repo.dirstate.forget(f) | |
1054 |
|
1056 | |||
1055 | if not msg: |
|
1057 | if not msg: | |
1056 | if not message: |
|
1058 | if not message: | |
1057 | message = "[mq]: %s\n" % patchfn |
|
1059 | message = "[mq]: %s\n" % patchfn | |
1058 | else: |
|
1060 | else: | |
1059 | message = "\n".join(message) |
|
1061 | message = "\n".join(message) | |
1060 | else: |
|
1062 | else: | |
1061 | message = msg |
|
1063 | message = msg | |
1062 |
|
1064 | |||
1063 | self.strip(repo, top, update=False, |
|
1065 | self.strip(repo, top, update=False, | |
1064 | backup='strip') |
|
1066 | backup='strip') | |
1065 | n = repo.commit(filelist, message, changes[1], match=matchfn, |
|
1067 | n = repo.commit(filelist, message, changes[1], match=matchfn, | |
1066 | force=1) |
|
1068 | force=1) | |
1067 | self.applied[-1] = statusentry(revlog.hex(n), patchfn) |
|
1069 | self.applied[-1] = statusentry(revlog.hex(n), patchfn) | |
1068 | self.applied_dirty = 1 |
|
1070 | self.applied_dirty = 1 | |
1069 | self.removeundo(repo) |
|
1071 | self.removeundo(repo) | |
1070 | else: |
|
1072 | else: | |
1071 | self.printdiff(repo, patchparent, fp=patchf) |
|
1073 | self.printdiff(repo, patchparent, fp=patchf) | |
1072 | patchf.close() |
|
1074 | patchf.close() | |
1073 | added = repo.status()[1] |
|
1075 | added = repo.status()[1] | |
1074 | for a in added: |
|
1076 | for a in added: | |
1075 | f = repo.wjoin(a) |
|
1077 | f = repo.wjoin(a) | |
1076 | try: |
|
1078 | try: | |
1077 | os.unlink(f) |
|
1079 | os.unlink(f) | |
1078 | except OSError, e: |
|
1080 | except OSError, e: | |
1079 | if e.errno != errno.ENOENT: |
|
1081 | if e.errno != errno.ENOENT: | |
1080 | raise |
|
1082 | raise | |
1081 | try: os.removedirs(os.path.dirname(f)) |
|
1083 | try: os.removedirs(os.path.dirname(f)) | |
1082 | except: pass |
|
1084 | except: pass | |
1083 | # forget the file copies in the dirstate |
|
1085 | # forget the file copies in the dirstate | |
1084 | # push should readd the files later on |
|
1086 | # push should readd the files later on | |
1085 | repo.dirstate.forget(a) |
|
1087 | repo.dirstate.forget(a) | |
1086 | self.pop(repo, force=True) |
|
1088 | self.pop(repo, force=True) | |
1087 | self.push(repo, force=True) |
|
1089 | self.push(repo, force=True) | |
1088 | finally: |
|
1090 | finally: | |
1089 | del wlock |
|
1091 | del wlock | |
1090 |
|
1092 | |||
1091 | def init(self, repo, create=False): |
|
1093 | def init(self, repo, create=False): | |
1092 | if not create and os.path.isdir(self.path): |
|
1094 | if not create and os.path.isdir(self.path): | |
1093 | raise util.Abort(_("patch queue directory already exists")) |
|
1095 | raise util.Abort(_("patch queue directory already exists")) | |
1094 | try: |
|
1096 | try: | |
1095 | os.mkdir(self.path) |
|
1097 | os.mkdir(self.path) | |
1096 | except OSError, inst: |
|
1098 | except OSError, inst: | |
1097 | if inst.errno != errno.EEXIST or not create: |
|
1099 | if inst.errno != errno.EEXIST or not create: | |
1098 | raise |
|
1100 | raise | |
1099 | if create: |
|
1101 | if create: | |
1100 | return self.qrepo(create=True) |
|
1102 | return self.qrepo(create=True) | |
1101 |
|
1103 | |||
1102 | def unapplied(self, repo, patch=None): |
|
1104 | def unapplied(self, repo, patch=None): | |
1103 | if patch and patch not in self.series: |
|
1105 | if patch and patch not in self.series: | |
1104 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1106 | raise util.Abort(_("patch %s is not in series file") % patch) | |
1105 | if not patch: |
|
1107 | if not patch: | |
1106 | start = self.series_end() |
|
1108 | start = self.series_end() | |
1107 | else: |
|
1109 | else: | |
1108 | start = self.series.index(patch) + 1 |
|
1110 | start = self.series.index(patch) + 1 | |
1109 | unapplied = [] |
|
1111 | unapplied = [] | |
1110 | for i in xrange(start, len(self.series)): |
|
1112 | for i in xrange(start, len(self.series)): | |
1111 | pushable, reason = self.pushable(i) |
|
1113 | pushable, reason = self.pushable(i) | |
1112 | if pushable: |
|
1114 | if pushable: | |
1113 | unapplied.append((i, self.series[i])) |
|
1115 | unapplied.append((i, self.series[i])) | |
1114 | self.explain_pushable(i) |
|
1116 | self.explain_pushable(i) | |
1115 | return unapplied |
|
1117 | return unapplied | |
1116 |
|
1118 | |||
1117 | def qseries(self, repo, missing=None, start=0, length=None, status=None, |
|
1119 | def qseries(self, repo, missing=None, start=0, length=None, status=None, | |
1118 | summary=False): |
|
1120 | summary=False): | |
1119 | def displayname(patchname): |
|
1121 | def displayname(patchname): | |
1120 | if summary: |
|
1122 | if summary: | |
1121 | msg = self.readheaders(patchname)[0] |
|
1123 | msg = self.readheaders(patchname)[0] | |
1122 | msg = msg and ': ' + msg[0] or ': ' |
|
1124 | msg = msg and ': ' + msg[0] or ': ' | |
1123 | else: |
|
1125 | else: | |
1124 | msg = '' |
|
1126 | msg = '' | |
1125 | return '%s%s' % (patchname, msg) |
|
1127 | return '%s%s' % (patchname, msg) | |
1126 |
|
1128 | |||
1127 | applied = dict.fromkeys([p.name for p in self.applied]) |
|
1129 | applied = dict.fromkeys([p.name for p in self.applied]) | |
1128 | if length is None: |
|
1130 | if length is None: | |
1129 | length = len(self.series) - start |
|
1131 | length = len(self.series) - start | |
1130 | if not missing: |
|
1132 | if not missing: | |
1131 | for i in xrange(start, start+length): |
|
1133 | for i in xrange(start, start+length): | |
1132 | patch = self.series[i] |
|
1134 | patch = self.series[i] | |
1133 | if patch in applied: |
|
1135 | if patch in applied: | |
1134 | stat = 'A' |
|
1136 | stat = 'A' | |
1135 | elif self.pushable(i)[0]: |
|
1137 | elif self.pushable(i)[0]: | |
1136 | stat = 'U' |
|
1138 | stat = 'U' | |
1137 | else: |
|
1139 | else: | |
1138 | stat = 'G' |
|
1140 | stat = 'G' | |
1139 | pfx = '' |
|
1141 | pfx = '' | |
1140 | if self.ui.verbose: |
|
1142 | if self.ui.verbose: | |
1141 | pfx = '%d %s ' % (i, stat) |
|
1143 | pfx = '%d %s ' % (i, stat) | |
1142 | elif status and status != stat: |
|
1144 | elif status and status != stat: | |
1143 | continue |
|
1145 | continue | |
1144 | self.ui.write('%s%s\n' % (pfx, displayname(patch))) |
|
1146 | self.ui.write('%s%s\n' % (pfx, displayname(patch))) | |
1145 | else: |
|
1147 | else: | |
1146 | msng_list = [] |
|
1148 | msng_list = [] | |
1147 | for root, dirs, files in os.walk(self.path): |
|
1149 | for root, dirs, files in os.walk(self.path): | |
1148 | d = root[len(self.path) + 1:] |
|
1150 | d = root[len(self.path) + 1:] | |
1149 | for f in files: |
|
1151 | for f in files: | |
1150 | fl = os.path.join(d, f) |
|
1152 | fl = os.path.join(d, f) | |
1151 | if (fl not in self.series and |
|
1153 | if (fl not in self.series and | |
1152 | fl not in (self.status_path, self.series_path, |
|
1154 | fl not in (self.status_path, self.series_path, | |
1153 | self.guards_path) |
|
1155 | self.guards_path) | |
1154 | and not fl.startswith('.')): |
|
1156 | and not fl.startswith('.')): | |
1155 | msng_list.append(fl) |
|
1157 | msng_list.append(fl) | |
1156 | msng_list.sort() |
|
1158 | msng_list.sort() | |
1157 | for x in msng_list: |
|
1159 | for x in msng_list: | |
1158 | pfx = self.ui.verbose and ('D ') or '' |
|
1160 | pfx = self.ui.verbose and ('D ') or '' | |
1159 | self.ui.write("%s%s\n" % (pfx, displayname(x))) |
|
1161 | self.ui.write("%s%s\n" % (pfx, displayname(x))) | |
1160 |
|
1162 | |||
1161 | def issaveline(self, l): |
|
1163 | def issaveline(self, l): | |
1162 | if l.name == '.hg.patches.save.line': |
|
1164 | if l.name == '.hg.patches.save.line': | |
1163 | return True |
|
1165 | return True | |
1164 |
|
1166 | |||
1165 | def qrepo(self, create=False): |
|
1167 | def qrepo(self, create=False): | |
1166 | if create or os.path.isdir(self.join(".hg")): |
|
1168 | if create or os.path.isdir(self.join(".hg")): | |
1167 | return hg.repository(self.ui, path=self.path, create=create) |
|
1169 | return hg.repository(self.ui, path=self.path, create=create) | |
1168 |
|
1170 | |||
1169 | def restore(self, repo, rev, delete=None, qupdate=None): |
|
1171 | def restore(self, repo, rev, delete=None, qupdate=None): | |
1170 | c = repo.changelog.read(rev) |
|
1172 | c = repo.changelog.read(rev) | |
1171 | desc = c[4].strip() |
|
1173 | desc = c[4].strip() | |
1172 | lines = desc.splitlines() |
|
1174 | lines = desc.splitlines() | |
1173 | i = 0 |
|
1175 | i = 0 | |
1174 | datastart = None |
|
1176 | datastart = None | |
1175 | series = [] |
|
1177 | series = [] | |
1176 | applied = [] |
|
1178 | applied = [] | |
1177 | qpp = None |
|
1179 | qpp = None | |
1178 | for i in xrange(0, len(lines)): |
|
1180 | for i in xrange(0, len(lines)): | |
1179 | if lines[i] == 'Patch Data:': |
|
1181 | if lines[i] == 'Patch Data:': | |
1180 | datastart = i + 1 |
|
1182 | datastart = i + 1 | |
1181 | elif lines[i].startswith('Dirstate:'): |
|
1183 | elif lines[i].startswith('Dirstate:'): | |
1182 | l = lines[i].rstrip() |
|
1184 | l = lines[i].rstrip() | |
1183 | l = l[10:].split(' ') |
|
1185 | l = l[10:].split(' ') | |
1184 | qpp = [ hg.bin(x) for x in l ] |
|
1186 | qpp = [ hg.bin(x) for x in l ] | |
1185 | elif datastart != None: |
|
1187 | elif datastart != None: | |
1186 | l = lines[i].rstrip() |
|
1188 | l = lines[i].rstrip() | |
1187 | se = statusentry(l) |
|
1189 | se = statusentry(l) | |
1188 | file_ = se.name |
|
1190 | file_ = se.name | |
1189 | if se.rev: |
|
1191 | if se.rev: | |
1190 | applied.append(se) |
|
1192 | applied.append(se) | |
1191 | else: |
|
1193 | else: | |
1192 | series.append(file_) |
|
1194 | series.append(file_) | |
1193 | if datastart == None: |
|
1195 | if datastart == None: | |
1194 | self.ui.warn("No saved patch data found\n") |
|
1196 | self.ui.warn("No saved patch data found\n") | |
1195 | return 1 |
|
1197 | return 1 | |
1196 | self.ui.warn("restoring status: %s\n" % lines[0]) |
|
1198 | self.ui.warn("restoring status: %s\n" % lines[0]) | |
1197 | self.full_series = series |
|
1199 | self.full_series = series | |
1198 | self.applied = applied |
|
1200 | self.applied = applied | |
1199 | self.parse_series() |
|
1201 | self.parse_series() | |
1200 | self.series_dirty = 1 |
|
1202 | self.series_dirty = 1 | |
1201 | self.applied_dirty = 1 |
|
1203 | self.applied_dirty = 1 | |
1202 | heads = repo.changelog.heads() |
|
1204 | heads = repo.changelog.heads() | |
1203 | if delete: |
|
1205 | if delete: | |
1204 | if rev not in heads: |
|
1206 | if rev not in heads: | |
1205 | self.ui.warn("save entry has children, leaving it alone\n") |
|
1207 | self.ui.warn("save entry has children, leaving it alone\n") | |
1206 | else: |
|
1208 | else: | |
1207 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) |
|
1209 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) | |
1208 | pp = repo.dirstate.parents() |
|
1210 | pp = repo.dirstate.parents() | |
1209 | if rev in pp: |
|
1211 | if rev in pp: | |
1210 | update = True |
|
1212 | update = True | |
1211 | else: |
|
1213 | else: | |
1212 | update = False |
|
1214 | update = False | |
1213 | self.strip(repo, rev, update=update, backup='strip') |
|
1215 | self.strip(repo, rev, update=update, backup='strip') | |
1214 | if qpp: |
|
1216 | if qpp: | |
1215 | self.ui.warn("saved queue repository parents: %s %s\n" % |
|
1217 | self.ui.warn("saved queue repository parents: %s %s\n" % | |
1216 | (hg.short(qpp[0]), hg.short(qpp[1]))) |
|
1218 | (hg.short(qpp[0]), hg.short(qpp[1]))) | |
1217 | if qupdate: |
|
1219 | if qupdate: | |
1218 | print "queue directory updating" |
|
1220 | print "queue directory updating" | |
1219 | r = self.qrepo() |
|
1221 | r = self.qrepo() | |
1220 | if not r: |
|
1222 | if not r: | |
1221 | self.ui.warn("Unable to load queue repository\n") |
|
1223 | self.ui.warn("Unable to load queue repository\n") | |
1222 | return 1 |
|
1224 | return 1 | |
1223 | hg.clean(r, qpp[0]) |
|
1225 | hg.clean(r, qpp[0]) | |
1224 |
|
1226 | |||
1225 | def save(self, repo, msg=None): |
|
1227 | def save(self, repo, msg=None): | |
1226 | if len(self.applied) == 0: |
|
1228 | if len(self.applied) == 0: | |
1227 | self.ui.warn("save: no patches applied, exiting\n") |
|
1229 | self.ui.warn("save: no patches applied, exiting\n") | |
1228 | return 1 |
|
1230 | return 1 | |
1229 | if self.issaveline(self.applied[-1]): |
|
1231 | if self.issaveline(self.applied[-1]): | |
1230 | self.ui.warn("status is already saved\n") |
|
1232 | self.ui.warn("status is already saved\n") | |
1231 | return 1 |
|
1233 | return 1 | |
1232 |
|
1234 | |||
1233 | ar = [ ':' + x for x in self.full_series ] |
|
1235 | ar = [ ':' + x for x in self.full_series ] | |
1234 | if not msg: |
|
1236 | if not msg: | |
1235 | msg = "hg patches saved state" |
|
1237 | msg = "hg patches saved state" | |
1236 | else: |
|
1238 | else: | |
1237 | msg = "hg patches: " + msg.rstrip('\r\n') |
|
1239 | msg = "hg patches: " + msg.rstrip('\r\n') | |
1238 | r = self.qrepo() |
|
1240 | r = self.qrepo() | |
1239 | if r: |
|
1241 | if r: | |
1240 | pp = r.dirstate.parents() |
|
1242 | pp = r.dirstate.parents() | |
1241 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) |
|
1243 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) | |
1242 | msg += "\n\nPatch Data:\n" |
|
1244 | msg += "\n\nPatch Data:\n" | |
1243 | text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and |
|
1245 | text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and | |
1244 | "\n".join(ar) + '\n' or "") |
|
1246 | "\n".join(ar) + '\n' or "") | |
1245 | n = repo.commit(None, text, user=None, force=1) |
|
1247 | n = repo.commit(None, text, user=None, force=1) | |
1246 | if not n: |
|
1248 | if not n: | |
1247 | self.ui.warn("repo commit failed\n") |
|
1249 | self.ui.warn("repo commit failed\n") | |
1248 | return 1 |
|
1250 | return 1 | |
1249 | self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line')) |
|
1251 | self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line')) | |
1250 | self.applied_dirty = 1 |
|
1252 | self.applied_dirty = 1 | |
1251 | self.removeundo(repo) |
|
1253 | self.removeundo(repo) | |
1252 |
|
1254 | |||
1253 | def full_series_end(self): |
|
1255 | def full_series_end(self): | |
1254 | if len(self.applied) > 0: |
|
1256 | if len(self.applied) > 0: | |
1255 | p = self.applied[-1].name |
|
1257 | p = self.applied[-1].name | |
1256 | end = self.find_series(p) |
|
1258 | end = self.find_series(p) | |
1257 | if end == None: |
|
1259 | if end == None: | |
1258 | return len(self.full_series) |
|
1260 | return len(self.full_series) | |
1259 | return end + 1 |
|
1261 | return end + 1 | |
1260 | return 0 |
|
1262 | return 0 | |
1261 |
|
1263 | |||
1262 | def series_end(self, all_patches=False): |
|
1264 | def series_end(self, all_patches=False): | |
1263 | """If all_patches is False, return the index of the next pushable patch |
|
1265 | """If all_patches is False, return the index of the next pushable patch | |
1264 | in the series, or the series length. If all_patches is True, return the |
|
1266 | in the series, or the series length. If all_patches is True, return the | |
1265 | index of the first patch past the last applied one. |
|
1267 | index of the first patch past the last applied one. | |
1266 | """ |
|
1268 | """ | |
1267 | end = 0 |
|
1269 | end = 0 | |
1268 | def next(start): |
|
1270 | def next(start): | |
1269 | if all_patches: |
|
1271 | if all_patches: | |
1270 | return start |
|
1272 | return start | |
1271 | i = start |
|
1273 | i = start | |
1272 | while i < len(self.series): |
|
1274 | while i < len(self.series): | |
1273 | p, reason = self.pushable(i) |
|
1275 | p, reason = self.pushable(i) | |
1274 | if p: |
|
1276 | if p: | |
1275 | break |
|
1277 | break | |
1276 | self.explain_pushable(i) |
|
1278 | self.explain_pushable(i) | |
1277 | i += 1 |
|
1279 | i += 1 | |
1278 | return i |
|
1280 | return i | |
1279 | if len(self.applied) > 0: |
|
1281 | if len(self.applied) > 0: | |
1280 | p = self.applied[-1].name |
|
1282 | p = self.applied[-1].name | |
1281 | try: |
|
1283 | try: | |
1282 | end = self.series.index(p) |
|
1284 | end = self.series.index(p) | |
1283 | except ValueError: |
|
1285 | except ValueError: | |
1284 | return 0 |
|
1286 | return 0 | |
1285 | return next(end + 1) |
|
1287 | return next(end + 1) | |
1286 | return next(end) |
|
1288 | return next(end) | |
1287 |
|
1289 | |||
1288 | def appliedname(self, index): |
|
1290 | def appliedname(self, index): | |
1289 | pname = self.applied[index].name |
|
1291 | pname = self.applied[index].name | |
1290 | if not self.ui.verbose: |
|
1292 | if not self.ui.verbose: | |
1291 | p = pname |
|
1293 | p = pname | |
1292 | else: |
|
1294 | else: | |
1293 | p = str(self.series.index(pname)) + " " + pname |
|
1295 | p = str(self.series.index(pname)) + " " + pname | |
1294 | return p |
|
1296 | return p | |
1295 |
|
1297 | |||
1296 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, |
|
1298 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, | |
1297 | force=None, git=False): |
|
1299 | force=None, git=False): | |
1298 | def checkseries(patchname): |
|
1300 | def checkseries(patchname): | |
1299 | if patchname in self.series: |
|
1301 | if patchname in self.series: | |
1300 | raise util.Abort(_('patch %s is already in the series file') |
|
1302 | raise util.Abort(_('patch %s is already in the series file') | |
1301 | % patchname) |
|
1303 | % patchname) | |
1302 | def checkfile(patchname): |
|
1304 | def checkfile(patchname): | |
1303 | if not force and os.path.exists(self.join(patchname)): |
|
1305 | if not force and os.path.exists(self.join(patchname)): | |
1304 | raise util.Abort(_('patch "%s" already exists') |
|
1306 | raise util.Abort(_('patch "%s" already exists') | |
1305 | % patchname) |
|
1307 | % patchname) | |
1306 |
|
1308 | |||
1307 | if rev: |
|
1309 | if rev: | |
1308 | if files: |
|
1310 | if files: | |
1309 | raise util.Abort(_('option "-r" not valid when importing ' |
|
1311 | raise util.Abort(_('option "-r" not valid when importing ' | |
1310 | 'files')) |
|
1312 | 'files')) | |
1311 | rev = cmdutil.revrange(repo, rev) |
|
1313 | rev = cmdutil.revrange(repo, rev) | |
1312 | rev.sort(lambda x, y: cmp(y, x)) |
|
1314 | rev.sort(lambda x, y: cmp(y, x)) | |
1313 | if (len(files) > 1 or len(rev) > 1) and patchname: |
|
1315 | if (len(files) > 1 or len(rev) > 1) and patchname: | |
1314 | raise util.Abort(_('option "-n" not valid when importing multiple ' |
|
1316 | raise util.Abort(_('option "-n" not valid when importing multiple ' | |
1315 | 'patches')) |
|
1317 | 'patches')) | |
1316 | i = 0 |
|
1318 | i = 0 | |
1317 | added = [] |
|
1319 | added = [] | |
1318 | if rev: |
|
1320 | if rev: | |
1319 | # If mq patches are applied, we can only import revisions |
|
1321 | # If mq patches are applied, we can only import revisions | |
1320 | # that form a linear path to qbase. |
|
1322 | # that form a linear path to qbase. | |
1321 | # Otherwise, they should form a linear path to a head. |
|
1323 | # Otherwise, they should form a linear path to a head. | |
1322 | heads = repo.changelog.heads(repo.changelog.node(rev[-1])) |
|
1324 | heads = repo.changelog.heads(repo.changelog.node(rev[-1])) | |
1323 | if len(heads) > 1: |
|
1325 | if len(heads) > 1: | |
1324 | raise util.Abort(_('revision %d is the root of more than one ' |
|
1326 | raise util.Abort(_('revision %d is the root of more than one ' | |
1325 | 'branch') % rev[-1]) |
|
1327 | 'branch') % rev[-1]) | |
1326 | if self.applied: |
|
1328 | if self.applied: | |
1327 | base = revlog.hex(repo.changelog.node(rev[0])) |
|
1329 | base = revlog.hex(repo.changelog.node(rev[0])) | |
1328 | if base in [n.rev for n in self.applied]: |
|
1330 | if base in [n.rev for n in self.applied]: | |
1329 | raise util.Abort(_('revision %d is already managed') |
|
1331 | raise util.Abort(_('revision %d is already managed') | |
1330 | % rev[0]) |
|
1332 | % rev[0]) | |
1331 | if heads != [revlog.bin(self.applied[-1].rev)]: |
|
1333 | if heads != [revlog.bin(self.applied[-1].rev)]: | |
1332 | raise util.Abort(_('revision %d is not the parent of ' |
|
1334 | raise util.Abort(_('revision %d is not the parent of ' | |
1333 | 'the queue') % rev[0]) |
|
1335 | 'the queue') % rev[0]) | |
1334 | base = repo.changelog.rev(revlog.bin(self.applied[0].rev)) |
|
1336 | base = repo.changelog.rev(revlog.bin(self.applied[0].rev)) | |
1335 | lastparent = repo.changelog.parentrevs(base)[0] |
|
1337 | lastparent = repo.changelog.parentrevs(base)[0] | |
1336 | else: |
|
1338 | else: | |
1337 | if heads != [repo.changelog.node(rev[0])]: |
|
1339 | if heads != [repo.changelog.node(rev[0])]: | |
1338 | raise util.Abort(_('revision %d has unmanaged children') |
|
1340 | raise util.Abort(_('revision %d has unmanaged children') | |
1339 | % rev[0]) |
|
1341 | % rev[0]) | |
1340 | lastparent = None |
|
1342 | lastparent = None | |
1341 |
|
1343 | |||
1342 | if git: |
|
1344 | if git: | |
1343 | self.diffopts().git = True |
|
1345 | self.diffopts().git = True | |
1344 |
|
1346 | |||
1345 | for r in rev: |
|
1347 | for r in rev: | |
1346 | p1, p2 = repo.changelog.parentrevs(r) |
|
1348 | p1, p2 = repo.changelog.parentrevs(r) | |
1347 | n = repo.changelog.node(r) |
|
1349 | n = repo.changelog.node(r) | |
1348 | if p2 != revlog.nullrev: |
|
1350 | if p2 != revlog.nullrev: | |
1349 | raise util.Abort(_('cannot import merge revision %d') % r) |
|
1351 | raise util.Abort(_('cannot import merge revision %d') % r) | |
1350 | if lastparent and lastparent != r: |
|
1352 | if lastparent and lastparent != r: | |
1351 | raise util.Abort(_('revision %d is not the parent of %d') |
|
1353 | raise util.Abort(_('revision %d is not the parent of %d') | |
1352 | % (r, lastparent)) |
|
1354 | % (r, lastparent)) | |
1353 | lastparent = p1 |
|
1355 | lastparent = p1 | |
1354 |
|
1356 | |||
1355 | if not patchname: |
|
1357 | if not patchname: | |
1356 | patchname = normname('%d.diff' % r) |
|
1358 | patchname = normname('%d.diff' % r) | |
1357 | checkseries(patchname) |
|
1359 | checkseries(patchname) | |
1358 | checkfile(patchname) |
|
1360 | checkfile(patchname) | |
1359 | self.full_series.insert(0, patchname) |
|
1361 | self.full_series.insert(0, patchname) | |
1360 |
|
1362 | |||
1361 | patchf = self.opener(patchname, "w") |
|
1363 | patchf = self.opener(patchname, "w") | |
1362 | patch.export(repo, [n], fp=patchf, opts=self.diffopts()) |
|
1364 | patch.export(repo, [n], fp=patchf, opts=self.diffopts()) | |
1363 | patchf.close() |
|
1365 | patchf.close() | |
1364 |
|
1366 | |||
1365 | se = statusentry(revlog.hex(n), patchname) |
|
1367 | se = statusentry(revlog.hex(n), patchname) | |
1366 | self.applied.insert(0, se) |
|
1368 | self.applied.insert(0, se) | |
1367 |
|
1369 | |||
1368 | added.append(patchname) |
|
1370 | added.append(patchname) | |
1369 | patchname = None |
|
1371 | patchname = None | |
1370 | self.parse_series() |
|
1372 | self.parse_series() | |
1371 | self.applied_dirty = 1 |
|
1373 | self.applied_dirty = 1 | |
1372 |
|
1374 | |||
1373 | for filename in files: |
|
1375 | for filename in files: | |
1374 | if existing: |
|
1376 | if existing: | |
1375 | if filename == '-': |
|
1377 | if filename == '-': | |
1376 | raise util.Abort(_('-e is incompatible with import from -')) |
|
1378 | raise util.Abort(_('-e is incompatible with import from -')) | |
1377 | if not patchname: |
|
1379 | if not patchname: | |
1378 | patchname = normname(filename) |
|
1380 | patchname = normname(filename) | |
1379 | if not os.path.isfile(self.join(patchname)): |
|
1381 | if not os.path.isfile(self.join(patchname)): | |
1380 | raise util.Abort(_("patch %s does not exist") % patchname) |
|
1382 | raise util.Abort(_("patch %s does not exist") % patchname) | |
1381 | else: |
|
1383 | else: | |
1382 | try: |
|
1384 | try: | |
1383 | if filename == '-': |
|
1385 | if filename == '-': | |
1384 | if not patchname: |
|
1386 | if not patchname: | |
1385 | raise util.Abort(_('need --name to import a patch from -')) |
|
1387 | raise util.Abort(_('need --name to import a patch from -')) | |
1386 | text = sys.stdin.read() |
|
1388 | text = sys.stdin.read() | |
1387 | else: |
|
1389 | else: | |
1388 | text = file(filename).read() |
|
1390 | text = file(filename).read() | |
1389 | except IOError: |
|
1391 | except IOError: | |
1390 | raise util.Abort(_("unable to read %s") % patchname) |
|
1392 | raise util.Abort(_("unable to read %s") % patchname) | |
1391 | if not patchname: |
|
1393 | if not patchname: | |
1392 | patchname = normname(os.path.basename(filename)) |
|
1394 | patchname = normname(os.path.basename(filename)) | |
1393 | checkfile(patchname) |
|
1395 | checkfile(patchname) | |
1394 | patchf = self.opener(patchname, "w") |
|
1396 | patchf = self.opener(patchname, "w") | |
1395 | patchf.write(text) |
|
1397 | patchf.write(text) | |
1396 | checkseries(patchname) |
|
1398 | checkseries(patchname) | |
1397 | index = self.full_series_end() + i |
|
1399 | index = self.full_series_end() + i | |
1398 | self.full_series[index:index] = [patchname] |
|
1400 | self.full_series[index:index] = [patchname] | |
1399 | self.parse_series() |
|
1401 | self.parse_series() | |
1400 | self.ui.warn("adding %s to series file\n" % patchname) |
|
1402 | self.ui.warn("adding %s to series file\n" % patchname) | |
1401 | i += 1 |
|
1403 | i += 1 | |
1402 | added.append(patchname) |
|
1404 | added.append(patchname) | |
1403 | patchname = None |
|
1405 | patchname = None | |
1404 | self.series_dirty = 1 |
|
1406 | self.series_dirty = 1 | |
1405 | qrepo = self.qrepo() |
|
1407 | qrepo = self.qrepo() | |
1406 | if qrepo: |
|
1408 | if qrepo: | |
1407 | qrepo.add(added) |
|
1409 | qrepo.add(added) | |
1408 |
|
1410 | |||
1409 | def delete(ui, repo, *patches, **opts): |
|
1411 | def delete(ui, repo, *patches, **opts): | |
1410 | """remove patches from queue |
|
1412 | """remove patches from queue | |
1411 |
|
1413 | |||
1412 | The patches must not be applied, unless they are arguments to |
|
1414 | The patches must not be applied, unless they are arguments to | |
1413 | the --rev parameter. At least one patch or revision is required. |
|
1415 | the --rev parameter. At least one patch or revision is required. | |
1414 |
|
1416 | |||
1415 | With --rev, mq will stop managing the named revisions (converting |
|
1417 | With --rev, mq will stop managing the named revisions (converting | |
1416 | them to regular mercurial changesets). The patches must be applied |
|
1418 | them to regular mercurial changesets). The patches must be applied | |
1417 | and at the base of the stack. This option is useful when the patches |
|
1419 | and at the base of the stack. This option is useful when the patches | |
1418 | have been applied upstream. |
|
1420 | have been applied upstream. | |
1419 |
|
1421 | |||
1420 | With --keep, the patch files are preserved in the patch directory.""" |
|
1422 | With --keep, the patch files are preserved in the patch directory.""" | |
1421 | q = repo.mq |
|
1423 | q = repo.mq | |
1422 | q.delete(repo, patches, opts) |
|
1424 | q.delete(repo, patches, opts) | |
1423 | q.save_dirty() |
|
1425 | q.save_dirty() | |
1424 | return 0 |
|
1426 | return 0 | |
1425 |
|
1427 | |||
1426 | def applied(ui, repo, patch=None, **opts): |
|
1428 | def applied(ui, repo, patch=None, **opts): | |
1427 | """print the patches already applied""" |
|
1429 | """print the patches already applied""" | |
1428 | q = repo.mq |
|
1430 | q = repo.mq | |
1429 | if patch: |
|
1431 | if patch: | |
1430 | if patch not in q.series: |
|
1432 | if patch not in q.series: | |
1431 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1433 | raise util.Abort(_("patch %s is not in series file") % patch) | |
1432 | end = q.series.index(patch) + 1 |
|
1434 | end = q.series.index(patch) + 1 | |
1433 | else: |
|
1435 | else: | |
1434 | end = q.series_end(True) |
|
1436 | end = q.series_end(True) | |
1435 | return q.qseries(repo, length=end, status='A', summary=opts.get('summary')) |
|
1437 | return q.qseries(repo, length=end, status='A', summary=opts.get('summary')) | |
1436 |
|
1438 | |||
1437 | def unapplied(ui, repo, patch=None, **opts): |
|
1439 | def unapplied(ui, repo, patch=None, **opts): | |
1438 | """print the patches not yet applied""" |
|
1440 | """print the patches not yet applied""" | |
1439 | q = repo.mq |
|
1441 | q = repo.mq | |
1440 | if patch: |
|
1442 | if patch: | |
1441 | if patch not in q.series: |
|
1443 | if patch not in q.series: | |
1442 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1444 | raise util.Abort(_("patch %s is not in series file") % patch) | |
1443 | start = q.series.index(patch) + 1 |
|
1445 | start = q.series.index(patch) + 1 | |
1444 | else: |
|
1446 | else: | |
1445 | start = q.series_end(True) |
|
1447 | start = q.series_end(True) | |
1446 | q.qseries(repo, start=start, status='U', summary=opts.get('summary')) |
|
1448 | q.qseries(repo, start=start, status='U', summary=opts.get('summary')) | |
1447 |
|
1449 | |||
1448 | def qimport(ui, repo, *filename, **opts): |
|
1450 | def qimport(ui, repo, *filename, **opts): | |
1449 | """import a patch |
|
1451 | """import a patch | |
1450 |
|
1452 | |||
1451 | The patch will have the same name as its source file unless you |
|
1453 | The patch will have the same name as its source file unless you | |
1452 | give it a new one with --name. |
|
1454 | give it a new one with --name. | |
1453 |
|
1455 | |||
1454 | You can register an existing patch inside the patch directory |
|
1456 | You can register an existing patch inside the patch directory | |
1455 | with the --existing flag. |
|
1457 | with the --existing flag. | |
1456 |
|
1458 | |||
1457 | With --force, an existing patch of the same name will be overwritten. |
|
1459 | With --force, an existing patch of the same name will be overwritten. | |
1458 |
|
1460 | |||
1459 | An existing changeset may be placed under mq control with --rev |
|
1461 | An existing changeset may be placed under mq control with --rev | |
1460 | (e.g. qimport --rev tip -n patch will place tip under mq control). |
|
1462 | (e.g. qimport --rev tip -n patch will place tip under mq control). | |
1461 | With --git, patches imported with --rev will use the git diff |
|
1463 | With --git, patches imported with --rev will use the git diff | |
1462 | format. |
|
1464 | format. | |
1463 | """ |
|
1465 | """ | |
1464 | q = repo.mq |
|
1466 | q = repo.mq | |
1465 | q.qimport(repo, filename, patchname=opts['name'], |
|
1467 | q.qimport(repo, filename, patchname=opts['name'], | |
1466 | existing=opts['existing'], force=opts['force'], rev=opts['rev'], |
|
1468 | existing=opts['existing'], force=opts['force'], rev=opts['rev'], | |
1467 | git=opts['git']) |
|
1469 | git=opts['git']) | |
1468 | q.save_dirty() |
|
1470 | q.save_dirty() | |
1469 | return 0 |
|
1471 | return 0 | |
1470 |
|
1472 | |||
1471 | def init(ui, repo, **opts): |
|
1473 | def init(ui, repo, **opts): | |
1472 | """init a new queue repository |
|
1474 | """init a new queue repository | |
1473 |
|
1475 | |||
1474 | The queue repository is unversioned by default. If -c is |
|
1476 | The queue repository is unversioned by default. If -c is | |
1475 | specified, qinit will create a separate nested repository |
|
1477 | specified, qinit will create a separate nested repository | |
1476 | for patches (qinit -c may also be run later to convert |
|
1478 | for patches (qinit -c may also be run later to convert | |
1477 | an unversioned patch repository into a versioned one). |
|
1479 | an unversioned patch repository into a versioned one). | |
1478 | You can use qcommit to commit changes to this queue repository.""" |
|
1480 | You can use qcommit to commit changes to this queue repository.""" | |
1479 | q = repo.mq |
|
1481 | q = repo.mq | |
1480 | r = q.init(repo, create=opts['create_repo']) |
|
1482 | r = q.init(repo, create=opts['create_repo']) | |
1481 | q.save_dirty() |
|
1483 | q.save_dirty() | |
1482 | if r: |
|
1484 | if r: | |
1483 | if not os.path.exists(r.wjoin('.hgignore')): |
|
1485 | if not os.path.exists(r.wjoin('.hgignore')): | |
1484 | fp = r.wopener('.hgignore', 'w') |
|
1486 | fp = r.wopener('.hgignore', 'w') | |
1485 | fp.write('syntax: glob\n') |
|
1487 | fp.write('syntax: glob\n') | |
1486 | fp.write('status\n') |
|
1488 | fp.write('status\n') | |
1487 | fp.write('guards\n') |
|
1489 | fp.write('guards\n') | |
1488 | fp.close() |
|
1490 | fp.close() | |
1489 | if not os.path.exists(r.wjoin('series')): |
|
1491 | if not os.path.exists(r.wjoin('series')): | |
1490 | r.wopener('series', 'w').close() |
|
1492 | r.wopener('series', 'w').close() | |
1491 | r.add(['.hgignore', 'series']) |
|
1493 | r.add(['.hgignore', 'series']) | |
1492 | commands.add(ui, r) |
|
1494 | commands.add(ui, r) | |
1493 | return 0 |
|
1495 | return 0 | |
1494 |
|
1496 | |||
1495 | def clone(ui, source, dest=None, **opts): |
|
1497 | def clone(ui, source, dest=None, **opts): | |
1496 | '''clone main and patch repository at same time |
|
1498 | '''clone main and patch repository at same time | |
1497 |
|
1499 | |||
1498 | If source is local, destination will have no patches applied. If |
|
1500 | If source is local, destination will have no patches applied. If | |
1499 | source is remote, this command can not check if patches are |
|
1501 | source is remote, this command can not check if patches are | |
1500 | applied in source, so cannot guarantee that patches are not |
|
1502 | applied in source, so cannot guarantee that patches are not | |
1501 | applied in destination. If you clone remote repository, be sure |
|
1503 | applied in destination. If you clone remote repository, be sure | |
1502 | before that it has no patches applied. |
|
1504 | before that it has no patches applied. | |
1503 |
|
1505 | |||
1504 | Source patch repository is looked for in <src>/.hg/patches by |
|
1506 | Source patch repository is looked for in <src>/.hg/patches by | |
1505 | default. Use -p <url> to change. |
|
1507 | default. Use -p <url> to change. | |
1506 |
|
1508 | |||
1507 | The patch directory must be a nested mercurial repository, as |
|
1509 | The patch directory must be a nested mercurial repository, as | |
1508 | would be created by qinit -c. |
|
1510 | would be created by qinit -c. | |
1509 | ''' |
|
1511 | ''' | |
1510 | cmdutil.setremoteconfig(ui, opts) |
|
1512 | cmdutil.setremoteconfig(ui, opts) | |
1511 | if dest is None: |
|
1513 | if dest is None: | |
1512 | dest = hg.defaultdest(source) |
|
1514 | dest = hg.defaultdest(source) | |
1513 | sr = hg.repository(ui, ui.expandpath(source)) |
|
1515 | sr = hg.repository(ui, ui.expandpath(source)) | |
1514 | patchdir = opts['patches'] or (sr.url() + '/.hg/patches') |
|
1516 | patchdir = opts['patches'] or (sr.url() + '/.hg/patches') | |
1515 | try: |
|
1517 | try: | |
1516 | pr = hg.repository(ui, patchdir) |
|
1518 | pr = hg.repository(ui, patchdir) | |
1517 | except hg.RepoError: |
|
1519 | except hg.RepoError: | |
1518 | raise util.Abort(_('versioned patch repository not found' |
|
1520 | raise util.Abort(_('versioned patch repository not found' | |
1519 | ' (see qinit -c)')) |
|
1521 | ' (see qinit -c)')) | |
1520 | qbase, destrev = None, None |
|
1522 | qbase, destrev = None, None | |
1521 | if sr.local(): |
|
1523 | if sr.local(): | |
1522 | if sr.mq.applied: |
|
1524 | if sr.mq.applied: | |
1523 | qbase = revlog.bin(sr.mq.applied[0].rev) |
|
1525 | qbase = revlog.bin(sr.mq.applied[0].rev) | |
1524 | if not hg.islocal(dest): |
|
1526 | if not hg.islocal(dest): | |
1525 | heads = dict.fromkeys(sr.heads()) |
|
1527 | heads = dict.fromkeys(sr.heads()) | |
1526 | for h in sr.heads(qbase): |
|
1528 | for h in sr.heads(qbase): | |
1527 | del heads[h] |
|
1529 | del heads[h] | |
1528 | destrev = heads.keys() |
|
1530 | destrev = heads.keys() | |
1529 | destrev.append(sr.changelog.parents(qbase)[0]) |
|
1531 | destrev.append(sr.changelog.parents(qbase)[0]) | |
1530 | ui.note(_('cloning main repo\n')) |
|
1532 | ui.note(_('cloning main repo\n')) | |
1531 | sr, dr = hg.clone(ui, sr.url(), dest, |
|
1533 | sr, dr = hg.clone(ui, sr.url(), dest, | |
1532 | pull=opts['pull'], |
|
1534 | pull=opts['pull'], | |
1533 | rev=destrev, |
|
1535 | rev=destrev, | |
1534 | update=False, |
|
1536 | update=False, | |
1535 | stream=opts['uncompressed']) |
|
1537 | stream=opts['uncompressed']) | |
1536 | ui.note(_('cloning patch repo\n')) |
|
1538 | ui.note(_('cloning patch repo\n')) | |
1537 | spr, dpr = hg.clone(ui, opts['patches'] or (sr.url() + '/.hg/patches'), |
|
1539 | spr, dpr = hg.clone(ui, opts['patches'] or (sr.url() + '/.hg/patches'), | |
1538 | dr.url() + '/.hg/patches', |
|
1540 | dr.url() + '/.hg/patches', | |
1539 | pull=opts['pull'], |
|
1541 | pull=opts['pull'], | |
1540 | update=not opts['noupdate'], |
|
1542 | update=not opts['noupdate'], | |
1541 | stream=opts['uncompressed']) |
|
1543 | stream=opts['uncompressed']) | |
1542 | if dr.local(): |
|
1544 | if dr.local(): | |
1543 | if qbase: |
|
1545 | if qbase: | |
1544 | ui.note(_('stripping applied patches from destination repo\n')) |
|
1546 | ui.note(_('stripping applied patches from destination repo\n')) | |
1545 | dr.mq.strip(dr, qbase, update=False, backup=None) |
|
1547 | dr.mq.strip(dr, qbase, update=False, backup=None) | |
1546 | if not opts['noupdate']: |
|
1548 | if not opts['noupdate']: | |
1547 | ui.note(_('updating destination repo\n')) |
|
1549 | ui.note(_('updating destination repo\n')) | |
1548 | hg.update(dr, dr.changelog.tip()) |
|
1550 | hg.update(dr, dr.changelog.tip()) | |
1549 |
|
1551 | |||
1550 | def commit(ui, repo, *pats, **opts): |
|
1552 | def commit(ui, repo, *pats, **opts): | |
1551 | """commit changes in the queue repository""" |
|
1553 | """commit changes in the queue repository""" | |
1552 | q = repo.mq |
|
1554 | q = repo.mq | |
1553 | r = q.qrepo() |
|
1555 | r = q.qrepo() | |
1554 | if not r: raise util.Abort('no queue repository') |
|
1556 | if not r: raise util.Abort('no queue repository') | |
1555 | commands.commit(r.ui, r, *pats, **opts) |
|
1557 | commands.commit(r.ui, r, *pats, **opts) | |
1556 |
|
1558 | |||
1557 | def series(ui, repo, **opts): |
|
1559 | def series(ui, repo, **opts): | |
1558 | """print the entire series file""" |
|
1560 | """print the entire series file""" | |
1559 | repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) |
|
1561 | repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) | |
1560 | return 0 |
|
1562 | return 0 | |
1561 |
|
1563 | |||
1562 | def top(ui, repo, **opts): |
|
1564 | def top(ui, repo, **opts): | |
1563 | """print the name of the current patch""" |
|
1565 | """print the name of the current patch""" | |
1564 | q = repo.mq |
|
1566 | q = repo.mq | |
1565 | t = q.applied and q.series_end(True) or 0 |
|
1567 | t = q.applied and q.series_end(True) or 0 | |
1566 | if t: |
|
1568 | if t: | |
1567 | return q.qseries(repo, start=t-1, length=1, status='A', |
|
1569 | return q.qseries(repo, start=t-1, length=1, status='A', | |
1568 | summary=opts.get('summary')) |
|
1570 | summary=opts.get('summary')) | |
1569 | else: |
|
1571 | else: | |
1570 | ui.write("No patches applied\n") |
|
1572 | ui.write("No patches applied\n") | |
1571 | return 1 |
|
1573 | return 1 | |
1572 |
|
1574 | |||
1573 | def next(ui, repo, **opts): |
|
1575 | def next(ui, repo, **opts): | |
1574 | """print the name of the next patch""" |
|
1576 | """print the name of the next patch""" | |
1575 | q = repo.mq |
|
1577 | q = repo.mq | |
1576 | end = q.series_end() |
|
1578 | end = q.series_end() | |
1577 | if end == len(q.series): |
|
1579 | if end == len(q.series): | |
1578 | ui.write("All patches applied\n") |
|
1580 | ui.write("All patches applied\n") | |
1579 | return 1 |
|
1581 | return 1 | |
1580 | return q.qseries(repo, start=end, length=1, summary=opts.get('summary')) |
|
1582 | return q.qseries(repo, start=end, length=1, summary=opts.get('summary')) | |
1581 |
|
1583 | |||
1582 | def prev(ui, repo, **opts): |
|
1584 | def prev(ui, repo, **opts): | |
1583 | """print the name of the previous patch""" |
|
1585 | """print the name of the previous patch""" | |
1584 | q = repo.mq |
|
1586 | q = repo.mq | |
1585 | l = len(q.applied) |
|
1587 | l = len(q.applied) | |
1586 | if l == 1: |
|
1588 | if l == 1: | |
1587 | ui.write("Only one patch applied\n") |
|
1589 | ui.write("Only one patch applied\n") | |
1588 | return 1 |
|
1590 | return 1 | |
1589 | if not l: |
|
1591 | if not l: | |
1590 | ui.write("No patches applied\n") |
|
1592 | ui.write("No patches applied\n") | |
1591 | return 1 |
|
1593 | return 1 | |
1592 | return q.qseries(repo, start=l-2, length=1, status='A', |
|
1594 | return q.qseries(repo, start=l-2, length=1, status='A', | |
1593 | summary=opts.get('summary')) |
|
1595 | summary=opts.get('summary')) | |
1594 |
|
1596 | |||
1595 | def new(ui, repo, patch, *args, **opts): |
|
1597 | def new(ui, repo, patch, *args, **opts): | |
1596 | """create a new patch |
|
1598 | """create a new patch | |
1597 |
|
1599 | |||
1598 | qnew creates a new patch on top of the currently-applied patch |
|
1600 | qnew creates a new patch on top of the currently-applied patch | |
1599 | (if any). It will refuse to run if there are any outstanding |
|
1601 | (if any). It will refuse to run if there are any outstanding | |
1600 | changes unless -f is specified, in which case the patch will |
|
1602 | changes unless -f is specified, in which case the patch will | |
1601 | be initialised with them. You may also use -I, -X, and/or a list of |
|
1603 | be initialised with them. You may also use -I, -X, and/or a list of | |
1602 | files after the patch name to add only changes to matching files |
|
1604 | files after the patch name to add only changes to matching files | |
1603 | to the new patch, leaving the rest as uncommitted modifications. |
|
1605 | to the new patch, leaving the rest as uncommitted modifications. | |
1604 |
|
1606 | |||
1605 | -e, -m or -l set the patch header as well as the commit message. |
|
1607 | -e, -m or -l set the patch header as well as the commit message. | |
1606 | If none is specified, the patch header is empty and the |
|
1608 | If none is specified, the patch header is empty and the | |
1607 | commit message is '[mq]: PATCH'""" |
|
1609 | commit message is '[mq]: PATCH'""" | |
1608 | q = repo.mq |
|
1610 | q = repo.mq | |
1609 | message = cmdutil.logmessage(opts) |
|
1611 | message = cmdutil.logmessage(opts) | |
1610 | if opts['edit']: |
|
1612 | if opts['edit']: | |
1611 | message = ui.edit(message, ui.username()) |
|
1613 | message = ui.edit(message, ui.username()) | |
1612 | opts['msg'] = message |
|
1614 | opts['msg'] = message | |
1613 | q.new(repo, patch, *args, **opts) |
|
1615 | q.new(repo, patch, *args, **opts) | |
1614 | q.save_dirty() |
|
1616 | q.save_dirty() | |
1615 | return 0 |
|
1617 | return 0 | |
1616 |
|
1618 | |||
1617 | def refresh(ui, repo, *pats, **opts): |
|
1619 | def refresh(ui, repo, *pats, **opts): | |
1618 | """update the current patch |
|
1620 | """update the current patch | |
1619 |
|
1621 | |||
1620 | If any file patterns are provided, the refreshed patch will contain only |
|
1622 | If any file patterns are provided, the refreshed patch will contain only | |
1621 | the modifications that match those patterns; the remaining modifications |
|
1623 | the modifications that match those patterns; the remaining modifications | |
1622 | will remain in the working directory. |
|
1624 | will remain in the working directory. | |
1623 |
|
1625 | |||
1624 | hg add/remove/copy/rename work as usual, though you might want to use |
|
1626 | hg add/remove/copy/rename work as usual, though you might want to use | |
1625 | git-style patches (--git or [diff] git=1) to track copies and renames. |
|
1627 | git-style patches (--git or [diff] git=1) to track copies and renames. | |
1626 | """ |
|
1628 | """ | |
1627 | q = repo.mq |
|
1629 | q = repo.mq | |
1628 | message = cmdutil.logmessage(opts) |
|
1630 | message = cmdutil.logmessage(opts) | |
1629 | if opts['edit']: |
|
1631 | if opts['edit']: | |
1630 | if message: |
|
1632 | if message: | |
1631 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1633 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) | |
1632 | patch = q.applied[-1].name |
|
1634 | patch = q.applied[-1].name | |
1633 | (message, comment, user, date, hasdiff) = q.readheaders(patch) |
|
1635 | (message, comment, user, date, hasdiff) = q.readheaders(patch) | |
1634 | message = ui.edit('\n'.join(message), user or ui.username()) |
|
1636 | message = ui.edit('\n'.join(message), user or ui.username()) | |
1635 | ret = q.refresh(repo, pats, msg=message, **opts) |
|
1637 | ret = q.refresh(repo, pats, msg=message, **opts) | |
1636 | q.save_dirty() |
|
1638 | q.save_dirty() | |
1637 | return ret |
|
1639 | return ret | |
1638 |
|
1640 | |||
1639 | def diff(ui, repo, *pats, **opts): |
|
1641 | def diff(ui, repo, *pats, **opts): | |
1640 | """diff of the current patch""" |
|
1642 | """diff of the current patch""" | |
1641 | repo.mq.diff(repo, pats, opts) |
|
1643 | repo.mq.diff(repo, pats, opts) | |
1642 | return 0 |
|
1644 | return 0 | |
1643 |
|
1645 | |||
1644 | def fold(ui, repo, *files, **opts): |
|
1646 | def fold(ui, repo, *files, **opts): | |
1645 | """fold the named patches into the current patch |
|
1647 | """fold the named patches into the current patch | |
1646 |
|
1648 | |||
1647 | Patches must not yet be applied. Each patch will be successively |
|
1649 | Patches must not yet be applied. Each patch will be successively | |
1648 | applied to the current patch in the order given. If all the |
|
1650 | applied to the current patch in the order given. If all the | |
1649 | patches apply successfully, the current patch will be refreshed |
|
1651 | patches apply successfully, the current patch will be refreshed | |
1650 | with the new cumulative patch, and the folded patches will |
|
1652 | with the new cumulative patch, and the folded patches will | |
1651 | be deleted. With -k/--keep, the folded patch files will not |
|
1653 | be deleted. With -k/--keep, the folded patch files will not | |
1652 | be removed afterwards. |
|
1654 | be removed afterwards. | |
1653 |
|
1655 | |||
1654 | The header for each folded patch will be concatenated with |
|
1656 | The header for each folded patch will be concatenated with | |
1655 | the current patch header, separated by a line of '* * *'.""" |
|
1657 | the current patch header, separated by a line of '* * *'.""" | |
1656 |
|
1658 | |||
1657 | q = repo.mq |
|
1659 | q = repo.mq | |
1658 |
|
1660 | |||
1659 | if not files: |
|
1661 | if not files: | |
1660 | raise util.Abort(_('qfold requires at least one patch name')) |
|
1662 | raise util.Abort(_('qfold requires at least one patch name')) | |
1661 | if not q.check_toppatch(repo): |
|
1663 | if not q.check_toppatch(repo): | |
1662 | raise util.Abort(_('No patches applied')) |
|
1664 | raise util.Abort(_('No patches applied')) | |
1663 |
|
1665 | |||
1664 | message = cmdutil.logmessage(opts) |
|
1666 | message = cmdutil.logmessage(opts) | |
1665 | if opts['edit']: |
|
1667 | if opts['edit']: | |
1666 | if message: |
|
1668 | if message: | |
1667 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1669 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) | |
1668 |
|
1670 | |||
1669 | parent = q.lookup('qtip') |
|
1671 | parent = q.lookup('qtip') | |
1670 | patches = [] |
|
1672 | patches = [] | |
1671 | messages = [] |
|
1673 | messages = [] | |
1672 | for f in files: |
|
1674 | for f in files: | |
1673 | p = q.lookup(f) |
|
1675 | p = q.lookup(f) | |
1674 | if p in patches or p == parent: |
|
1676 | if p in patches or p == parent: | |
1675 | ui.warn(_('Skipping already folded patch %s') % p) |
|
1677 | ui.warn(_('Skipping already folded patch %s') % p) | |
1676 | if q.isapplied(p): |
|
1678 | if q.isapplied(p): | |
1677 | raise util.Abort(_('qfold cannot fold already applied patch %s') % p) |
|
1679 | raise util.Abort(_('qfold cannot fold already applied patch %s') % p) | |
1678 | patches.append(p) |
|
1680 | patches.append(p) | |
1679 |
|
1681 | |||
1680 | for p in patches: |
|
1682 | for p in patches: | |
1681 | if not message: |
|
1683 | if not message: | |
1682 | messages.append(q.readheaders(p)[0]) |
|
1684 | messages.append(q.readheaders(p)[0]) | |
1683 | pf = q.join(p) |
|
1685 | pf = q.join(p) | |
1684 | (patchsuccess, files, fuzz) = q.patch(repo, pf) |
|
1686 | (patchsuccess, files, fuzz) = q.patch(repo, pf) | |
1685 | if not patchsuccess: |
|
1687 | if not patchsuccess: | |
1686 | raise util.Abort(_('Error folding patch %s') % p) |
|
1688 | raise util.Abort(_('Error folding patch %s') % p) | |
1687 | patch.updatedir(ui, repo, files) |
|
1689 | patch.updatedir(ui, repo, files) | |
1688 |
|
1690 | |||
1689 | if not message: |
|
1691 | if not message: | |
1690 | message, comments, user = q.readheaders(parent)[0:3] |
|
1692 | message, comments, user = q.readheaders(parent)[0:3] | |
1691 | for msg in messages: |
|
1693 | for msg in messages: | |
1692 | message.append('* * *') |
|
1694 | message.append('* * *') | |
1693 | message.extend(msg) |
|
1695 | message.extend(msg) | |
1694 | message = '\n'.join(message) |
|
1696 | message = '\n'.join(message) | |
1695 |
|
1697 | |||
1696 | if opts['edit']: |
|
1698 | if opts['edit']: | |
1697 | message = ui.edit(message, user or ui.username()) |
|
1699 | message = ui.edit(message, user or ui.username()) | |
1698 |
|
1700 | |||
1699 | q.refresh(repo, msg=message) |
|
1701 | q.refresh(repo, msg=message) | |
1700 | q.delete(repo, patches, opts) |
|
1702 | q.delete(repo, patches, opts) | |
1701 | q.save_dirty() |
|
1703 | q.save_dirty() | |
1702 |
|
1704 | |||
1703 | def goto(ui, repo, patch, **opts): |
|
1705 | def goto(ui, repo, patch, **opts): | |
1704 | '''push or pop patches until named patch is at top of stack''' |
|
1706 | '''push or pop patches until named patch is at top of stack''' | |
1705 | q = repo.mq |
|
1707 | q = repo.mq | |
1706 | patch = q.lookup(patch) |
|
1708 | patch = q.lookup(patch) | |
1707 | if q.isapplied(patch): |
|
1709 | if q.isapplied(patch): | |
1708 | ret = q.pop(repo, patch, force=opts['force']) |
|
1710 | ret = q.pop(repo, patch, force=opts['force']) | |
1709 | else: |
|
1711 | else: | |
1710 | ret = q.push(repo, patch, force=opts['force']) |
|
1712 | ret = q.push(repo, patch, force=opts['force']) | |
1711 | q.save_dirty() |
|
1713 | q.save_dirty() | |
1712 | return ret |
|
1714 | return ret | |
1713 |
|
1715 | |||
1714 | def guard(ui, repo, *args, **opts): |
|
1716 | def guard(ui, repo, *args, **opts): | |
1715 | '''set or print guards for a patch |
|
1717 | '''set or print guards for a patch | |
1716 |
|
1718 | |||
1717 | Guards control whether a patch can be pushed. A patch with no |
|
1719 | Guards control whether a patch can be pushed. A patch with no | |
1718 | guards is always pushed. A patch with a positive guard ("+foo") is |
|
1720 | guards is always pushed. A patch with a positive guard ("+foo") is | |
1719 | pushed only if the qselect command has activated it. A patch with |
|
1721 | pushed only if the qselect command has activated it. A patch with | |
1720 | a negative guard ("-foo") is never pushed if the qselect command |
|
1722 | a negative guard ("-foo") is never pushed if the qselect command | |
1721 | has activated it. |
|
1723 | has activated it. | |
1722 |
|
1724 | |||
1723 | With no arguments, print the currently active guards. |
|
1725 | With no arguments, print the currently active guards. | |
1724 | With arguments, set guards for the named patch. |
|
1726 | With arguments, set guards for the named patch. | |
1725 |
|
1727 | |||
1726 | To set a negative guard "-foo" on topmost patch ("--" is needed so |
|
1728 | To set a negative guard "-foo" on topmost patch ("--" is needed so | |
1727 | hg will not interpret "-foo" as an option): |
|
1729 | hg will not interpret "-foo" as an option): | |
1728 | hg qguard -- -foo |
|
1730 | hg qguard -- -foo | |
1729 |
|
1731 | |||
1730 | To set guards on another patch: |
|
1732 | To set guards on another patch: | |
1731 | hg qguard other.patch +2.6.17 -stable |
|
1733 | hg qguard other.patch +2.6.17 -stable | |
1732 | ''' |
|
1734 | ''' | |
1733 | def status(idx): |
|
1735 | def status(idx): | |
1734 | guards = q.series_guards[idx] or ['unguarded'] |
|
1736 | guards = q.series_guards[idx] or ['unguarded'] | |
1735 | ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards))) |
|
1737 | ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards))) | |
1736 | q = repo.mq |
|
1738 | q = repo.mq | |
1737 | patch = None |
|
1739 | patch = None | |
1738 | args = list(args) |
|
1740 | args = list(args) | |
1739 | if opts['list']: |
|
1741 | if opts['list']: | |
1740 | if args or opts['none']: |
|
1742 | if args or opts['none']: | |
1741 | raise util.Abort(_('cannot mix -l/--list with options or arguments')) |
|
1743 | raise util.Abort(_('cannot mix -l/--list with options or arguments')) | |
1742 | for i in xrange(len(q.series)): |
|
1744 | for i in xrange(len(q.series)): | |
1743 | status(i) |
|
1745 | status(i) | |
1744 | return |
|
1746 | return | |
1745 | if not args or args[0][0:1] in '-+': |
|
1747 | if not args or args[0][0:1] in '-+': | |
1746 | if not q.applied: |
|
1748 | if not q.applied: | |
1747 | raise util.Abort(_('no patches applied')) |
|
1749 | raise util.Abort(_('no patches applied')) | |
1748 | patch = q.applied[-1].name |
|
1750 | patch = q.applied[-1].name | |
1749 | if patch is None and args[0][0:1] not in '-+': |
|
1751 | if patch is None and args[0][0:1] not in '-+': | |
1750 | patch = args.pop(0) |
|
1752 | patch = args.pop(0) | |
1751 | if patch is None: |
|
1753 | if patch is None: | |
1752 | raise util.Abort(_('no patch to work with')) |
|
1754 | raise util.Abort(_('no patch to work with')) | |
1753 | if args or opts['none']: |
|
1755 | if args or opts['none']: | |
1754 | idx = q.find_series(patch) |
|
1756 | idx = q.find_series(patch) | |
1755 | if idx is None: |
|
1757 | if idx is None: | |
1756 | raise util.Abort(_('no patch named %s') % patch) |
|
1758 | raise util.Abort(_('no patch named %s') % patch) | |
1757 | q.set_guards(idx, args) |
|
1759 | q.set_guards(idx, args) | |
1758 | q.save_dirty() |
|
1760 | q.save_dirty() | |
1759 | else: |
|
1761 | else: | |
1760 | status(q.series.index(q.lookup(patch))) |
|
1762 | status(q.series.index(q.lookup(patch))) | |
1761 |
|
1763 | |||
1762 | def header(ui, repo, patch=None): |
|
1764 | def header(ui, repo, patch=None): | |
1763 | """Print the header of the topmost or specified patch""" |
|
1765 | """Print the header of the topmost or specified patch""" | |
1764 | q = repo.mq |
|
1766 | q = repo.mq | |
1765 |
|
1767 | |||
1766 | if patch: |
|
1768 | if patch: | |
1767 | patch = q.lookup(patch) |
|
1769 | patch = q.lookup(patch) | |
1768 | else: |
|
1770 | else: | |
1769 | if not q.applied: |
|
1771 | if not q.applied: | |
1770 | ui.write('No patches applied\n') |
|
1772 | ui.write('No patches applied\n') | |
1771 | return 1 |
|
1773 | return 1 | |
1772 | patch = q.lookup('qtip') |
|
1774 | patch = q.lookup('qtip') | |
1773 | message = repo.mq.readheaders(patch)[0] |
|
1775 | message = repo.mq.readheaders(patch)[0] | |
1774 |
|
1776 | |||
1775 | ui.write('\n'.join(message) + '\n') |
|
1777 | ui.write('\n'.join(message) + '\n') | |
1776 |
|
1778 | |||
1777 | def lastsavename(path): |
|
1779 | def lastsavename(path): | |
1778 | (directory, base) = os.path.split(path) |
|
1780 | (directory, base) = os.path.split(path) | |
1779 | names = os.listdir(directory) |
|
1781 | names = os.listdir(directory) | |
1780 | namere = re.compile("%s.([0-9]+)" % base) |
|
1782 | namere = re.compile("%s.([0-9]+)" % base) | |
1781 | maxindex = None |
|
1783 | maxindex = None | |
1782 | maxname = None |
|
1784 | maxname = None | |
1783 | for f in names: |
|
1785 | for f in names: | |
1784 | m = namere.match(f) |
|
1786 | m = namere.match(f) | |
1785 | if m: |
|
1787 | if m: | |
1786 | index = int(m.group(1)) |
|
1788 | index = int(m.group(1)) | |
1787 | if maxindex == None or index > maxindex: |
|
1789 | if maxindex == None or index > maxindex: | |
1788 | maxindex = index |
|
1790 | maxindex = index | |
1789 | maxname = f |
|
1791 | maxname = f | |
1790 | if maxname: |
|
1792 | if maxname: | |
1791 | return (os.path.join(directory, maxname), maxindex) |
|
1793 | return (os.path.join(directory, maxname), maxindex) | |
1792 | return (None, None) |
|
1794 | return (None, None) | |
1793 |
|
1795 | |||
1794 | def savename(path): |
|
1796 | def savename(path): | |
1795 | (last, index) = lastsavename(path) |
|
1797 | (last, index) = lastsavename(path) | |
1796 | if last is None: |
|
1798 | if last is None: | |
1797 | index = 0 |
|
1799 | index = 0 | |
1798 | newpath = path + ".%d" % (index + 1) |
|
1800 | newpath = path + ".%d" % (index + 1) | |
1799 | return newpath |
|
1801 | return newpath | |
1800 |
|
1802 | |||
1801 | def push(ui, repo, patch=None, **opts): |
|
1803 | def push(ui, repo, patch=None, **opts): | |
1802 | """push the next patch onto the stack""" |
|
1804 | """push the next patch onto the stack""" | |
1803 | q = repo.mq |
|
1805 | q = repo.mq | |
1804 | mergeq = None |
|
1806 | mergeq = None | |
1805 |
|
1807 | |||
1806 | if opts['all']: |
|
1808 | if opts['all']: | |
1807 | if not q.series: |
|
1809 | if not q.series: | |
1808 | ui.warn(_('no patches in series\n')) |
|
1810 | ui.warn(_('no patches in series\n')) | |
1809 | return 0 |
|
1811 | return 0 | |
1810 | patch = q.series[-1] |
|
1812 | patch = q.series[-1] | |
1811 | if opts['merge']: |
|
1813 | if opts['merge']: | |
1812 | if opts['name']: |
|
1814 | if opts['name']: | |
1813 | newpath = opts['name'] |
|
1815 | newpath = opts['name'] | |
1814 | else: |
|
1816 | else: | |
1815 | newpath, i = lastsavename(q.path) |
|
1817 | newpath, i = lastsavename(q.path) | |
1816 | if not newpath: |
|
1818 | if not newpath: | |
1817 | ui.warn("no saved queues found, please use -n\n") |
|
1819 | ui.warn("no saved queues found, please use -n\n") | |
1818 | return 1 |
|
1820 | return 1 | |
1819 | mergeq = queue(ui, repo.join(""), newpath) |
|
1821 | mergeq = queue(ui, repo.join(""), newpath) | |
1820 | ui.warn("merging with queue at: %s\n" % mergeq.path) |
|
1822 | ui.warn("merging with queue at: %s\n" % mergeq.path) | |
1821 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
|
1823 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], | |
1822 | mergeq=mergeq) |
|
1824 | mergeq=mergeq) | |
1823 | return ret |
|
1825 | return ret | |
1824 |
|
1826 | |||
1825 | def pop(ui, repo, patch=None, **opts): |
|
1827 | def pop(ui, repo, patch=None, **opts): | |
1826 | """pop the current patch off the stack""" |
|
1828 | """pop the current patch off the stack""" | |
1827 | localupdate = True |
|
1829 | localupdate = True | |
1828 | if opts['name']: |
|
1830 | if opts['name']: | |
1829 | q = queue(ui, repo.join(""), repo.join(opts['name'])) |
|
1831 | q = queue(ui, repo.join(""), repo.join(opts['name'])) | |
1830 | ui.warn('using patch queue: %s\n' % q.path) |
|
1832 | ui.warn('using patch queue: %s\n' % q.path) | |
1831 | localupdate = False |
|
1833 | localupdate = False | |
1832 | else: |
|
1834 | else: | |
1833 | q = repo.mq |
|
1835 | q = repo.mq | |
1834 | ret = q.pop(repo, patch, force=opts['force'], update=localupdate, |
|
1836 | ret = q.pop(repo, patch, force=opts['force'], update=localupdate, | |
1835 | all=opts['all']) |
|
1837 | all=opts['all']) | |
1836 | q.save_dirty() |
|
1838 | q.save_dirty() | |
1837 | return ret |
|
1839 | return ret | |
1838 |
|
1840 | |||
1839 | def rename(ui, repo, patch, name=None, **opts): |
|
1841 | def rename(ui, repo, patch, name=None, **opts): | |
1840 | """rename a patch |
|
1842 | """rename a patch | |
1841 |
|
1843 | |||
1842 | With one argument, renames the current patch to PATCH1. |
|
1844 | With one argument, renames the current patch to PATCH1. | |
1843 | With two arguments, renames PATCH1 to PATCH2.""" |
|
1845 | With two arguments, renames PATCH1 to PATCH2.""" | |
1844 |
|
1846 | |||
1845 | q = repo.mq |
|
1847 | q = repo.mq | |
1846 |
|
1848 | |||
1847 | if not name: |
|
1849 | if not name: | |
1848 | name = patch |
|
1850 | name = patch | |
1849 | patch = None |
|
1851 | patch = None | |
1850 |
|
1852 | |||
1851 | if patch: |
|
1853 | if patch: | |
1852 | patch = q.lookup(patch) |
|
1854 | patch = q.lookup(patch) | |
1853 | else: |
|
1855 | else: | |
1854 | if not q.applied: |
|
1856 | if not q.applied: | |
1855 | ui.write(_('No patches applied\n')) |
|
1857 | ui.write(_('No patches applied\n')) | |
1856 | return |
|
1858 | return | |
1857 | patch = q.lookup('qtip') |
|
1859 | patch = q.lookup('qtip') | |
1858 | absdest = q.join(name) |
|
1860 | absdest = q.join(name) | |
1859 | if os.path.isdir(absdest): |
|
1861 | if os.path.isdir(absdest): | |
1860 | name = normname(os.path.join(name, os.path.basename(patch))) |
|
1862 | name = normname(os.path.join(name, os.path.basename(patch))) | |
1861 | absdest = q.join(name) |
|
1863 | absdest = q.join(name) | |
1862 | if os.path.exists(absdest): |
|
1864 | if os.path.exists(absdest): | |
1863 | raise util.Abort(_('%s already exists') % absdest) |
|
1865 | raise util.Abort(_('%s already exists') % absdest) | |
1864 |
|
1866 | |||
1865 | if name in q.series: |
|
1867 | if name in q.series: | |
1866 | raise util.Abort(_('A patch named %s already exists in the series file') % name) |
|
1868 | raise util.Abort(_('A patch named %s already exists in the series file') % name) | |
1867 |
|
1869 | |||
1868 | if ui.verbose: |
|
1870 | if ui.verbose: | |
1869 | ui.write('Renaming %s to %s\n' % (patch, name)) |
|
1871 | ui.write('Renaming %s to %s\n' % (patch, name)) | |
1870 | i = q.find_series(patch) |
|
1872 | i = q.find_series(patch) | |
1871 | guards = q.guard_re.findall(q.full_series[i]) |
|
1873 | guards = q.guard_re.findall(q.full_series[i]) | |
1872 | q.full_series[i] = name + ''.join([' #' + g for g in guards]) |
|
1874 | q.full_series[i] = name + ''.join([' #' + g for g in guards]) | |
1873 | q.parse_series() |
|
1875 | q.parse_series() | |
1874 | q.series_dirty = 1 |
|
1876 | q.series_dirty = 1 | |
1875 |
|
1877 | |||
1876 | info = q.isapplied(patch) |
|
1878 | info = q.isapplied(patch) | |
1877 | if info: |
|
1879 | if info: | |
1878 | q.applied[info[0]] = statusentry(info[1], name) |
|
1880 | q.applied[info[0]] = statusentry(info[1], name) | |
1879 | q.applied_dirty = 1 |
|
1881 | q.applied_dirty = 1 | |
1880 |
|
1882 | |||
1881 | util.rename(q.join(patch), absdest) |
|
1883 | util.rename(q.join(patch), absdest) | |
1882 | r = q.qrepo() |
|
1884 | r = q.qrepo() | |
1883 | if r: |
|
1885 | if r: | |
1884 | wlock = r.wlock() |
|
1886 | wlock = r.wlock() | |
1885 | try: |
|
1887 | try: | |
1886 | if r.dirstate[name] == 'r': |
|
1888 | if r.dirstate[name] == 'r': | |
1887 | r.undelete([name]) |
|
1889 | r.undelete([name]) | |
1888 | r.copy(patch, name) |
|
1890 | r.copy(patch, name) | |
1889 | r.remove([patch], False) |
|
1891 | r.remove([patch], False) | |
1890 | finally: |
|
1892 | finally: | |
1891 | del wlock |
|
1893 | del wlock | |
1892 |
|
1894 | |||
1893 | q.save_dirty() |
|
1895 | q.save_dirty() | |
1894 |
|
1896 | |||
1895 | def restore(ui, repo, rev, **opts): |
|
1897 | def restore(ui, repo, rev, **opts): | |
1896 | """restore the queue state saved by a rev""" |
|
1898 | """restore the queue state saved by a rev""" | |
1897 | rev = repo.lookup(rev) |
|
1899 | rev = repo.lookup(rev) | |
1898 | q = repo.mq |
|
1900 | q = repo.mq | |
1899 | q.restore(repo, rev, delete=opts['delete'], |
|
1901 | q.restore(repo, rev, delete=opts['delete'], | |
1900 | qupdate=opts['update']) |
|
1902 | qupdate=opts['update']) | |
1901 | q.save_dirty() |
|
1903 | q.save_dirty() | |
1902 | return 0 |
|
1904 | return 0 | |
1903 |
|
1905 | |||
1904 | def save(ui, repo, **opts): |
|
1906 | def save(ui, repo, **opts): | |
1905 | """save current queue state""" |
|
1907 | """save current queue state""" | |
1906 | q = repo.mq |
|
1908 | q = repo.mq | |
1907 | message = cmdutil.logmessage(opts) |
|
1909 | message = cmdutil.logmessage(opts) | |
1908 | ret = q.save(repo, msg=message) |
|
1910 | ret = q.save(repo, msg=message) | |
1909 | if ret: |
|
1911 | if ret: | |
1910 | return ret |
|
1912 | return ret | |
1911 | q.save_dirty() |
|
1913 | q.save_dirty() | |
1912 | if opts['copy']: |
|
1914 | if opts['copy']: | |
1913 | path = q.path |
|
1915 | path = q.path | |
1914 | if opts['name']: |
|
1916 | if opts['name']: | |
1915 | newpath = os.path.join(q.basepath, opts['name']) |
|
1917 | newpath = os.path.join(q.basepath, opts['name']) | |
1916 | if os.path.exists(newpath): |
|
1918 | if os.path.exists(newpath): | |
1917 | if not os.path.isdir(newpath): |
|
1919 | if not os.path.isdir(newpath): | |
1918 | raise util.Abort(_('destination %s exists and is not ' |
|
1920 | raise util.Abort(_('destination %s exists and is not ' | |
1919 | 'a directory') % newpath) |
|
1921 | 'a directory') % newpath) | |
1920 | if not opts['force']: |
|
1922 | if not opts['force']: | |
1921 | raise util.Abort(_('destination %s exists, ' |
|
1923 | raise util.Abort(_('destination %s exists, ' | |
1922 | 'use -f to force') % newpath) |
|
1924 | 'use -f to force') % newpath) | |
1923 | else: |
|
1925 | else: | |
1924 | newpath = savename(path) |
|
1926 | newpath = savename(path) | |
1925 | ui.warn("copy %s to %s\n" % (path, newpath)) |
|
1927 | ui.warn("copy %s to %s\n" % (path, newpath)) | |
1926 | util.copyfiles(path, newpath) |
|
1928 | util.copyfiles(path, newpath) | |
1927 | if opts['empty']: |
|
1929 | if opts['empty']: | |
1928 | try: |
|
1930 | try: | |
1929 | os.unlink(q.join(q.status_path)) |
|
1931 | os.unlink(q.join(q.status_path)) | |
1930 | except: |
|
1932 | except: | |
1931 | pass |
|
1933 | pass | |
1932 | return 0 |
|
1934 | return 0 | |
1933 |
|
1935 | |||
1934 | def strip(ui, repo, rev, **opts): |
|
1936 | def strip(ui, repo, rev, **opts): | |
1935 | """strip a revision and all later revs on the same branch""" |
|
1937 | """strip a revision and all later revs on the same branch""" | |
1936 | rev = repo.lookup(rev) |
|
1938 | rev = repo.lookup(rev) | |
1937 | backup = 'all' |
|
1939 | backup = 'all' | |
1938 | if opts['backup']: |
|
1940 | if opts['backup']: | |
1939 | backup = 'strip' |
|
1941 | backup = 'strip' | |
1940 | elif opts['nobackup']: |
|
1942 | elif opts['nobackup']: | |
1941 | backup = 'none' |
|
1943 | backup = 'none' | |
1942 | update = repo.dirstate.parents()[0] != revlog.nullid |
|
1944 | update = repo.dirstate.parents()[0] != revlog.nullid | |
1943 | repo.mq.strip(repo, rev, backup=backup, update=update) |
|
1945 | repo.mq.strip(repo, rev, backup=backup, update=update) | |
1944 | return 0 |
|
1946 | return 0 | |
1945 |
|
1947 | |||
1946 | def select(ui, repo, *args, **opts): |
|
1948 | def select(ui, repo, *args, **opts): | |
1947 | '''set or print guarded patches to push |
|
1949 | '''set or print guarded patches to push | |
1948 |
|
1950 | |||
1949 | Use the qguard command to set or print guards on patch, then use |
|
1951 | Use the qguard command to set or print guards on patch, then use | |
1950 | qselect to tell mq which guards to use. A patch will be pushed if it |
|
1952 | qselect to tell mq which guards to use. A patch will be pushed if it | |
1951 | has no guards or any positive guards match the currently selected guard, |
|
1953 | has no guards or any positive guards match the currently selected guard, | |
1952 | but will not be pushed if any negative guards match the current guard. |
|
1954 | but will not be pushed if any negative guards match the current guard. | |
1953 | For example: |
|
1955 | For example: | |
1954 |
|
1956 | |||
1955 | qguard foo.patch -stable (negative guard) |
|
1957 | qguard foo.patch -stable (negative guard) | |
1956 | qguard bar.patch +stable (positive guard) |
|
1958 | qguard bar.patch +stable (positive guard) | |
1957 | qselect stable |
|
1959 | qselect stable | |
1958 |
|
1960 | |||
1959 | This activates the "stable" guard. mq will skip foo.patch (because |
|
1961 | This activates the "stable" guard. mq will skip foo.patch (because | |
1960 | it has a negative match) but push bar.patch (because it |
|
1962 | it has a negative match) but push bar.patch (because it | |
1961 | has a positive match). |
|
1963 | has a positive match). | |
1962 |
|
1964 | |||
1963 | With no arguments, prints the currently active guards. |
|
1965 | With no arguments, prints the currently active guards. | |
1964 | With one argument, sets the active guard. |
|
1966 | With one argument, sets the active guard. | |
1965 |
|
1967 | |||
1966 | Use -n/--none to deactivate guards (no other arguments needed). |
|
1968 | Use -n/--none to deactivate guards (no other arguments needed). | |
1967 | When no guards are active, patches with positive guards are skipped |
|
1969 | When no guards are active, patches with positive guards are skipped | |
1968 | and patches with negative guards are pushed. |
|
1970 | and patches with negative guards are pushed. | |
1969 |
|
1971 | |||
1970 | qselect can change the guards on applied patches. It does not pop |
|
1972 | qselect can change the guards on applied patches. It does not pop | |
1971 | guarded patches by default. Use --pop to pop back to the last applied |
|
1973 | guarded patches by default. Use --pop to pop back to the last applied | |
1972 | patch that is not guarded. Use --reapply (which implies --pop) to push |
|
1974 | patch that is not guarded. Use --reapply (which implies --pop) to push | |
1973 | back to the current patch afterwards, but skip guarded patches. |
|
1975 | back to the current patch afterwards, but skip guarded patches. | |
1974 |
|
1976 | |||
1975 | Use -s/--series to print a list of all guards in the series file (no |
|
1977 | Use -s/--series to print a list of all guards in the series file (no | |
1976 | other arguments needed). Use -v for more information.''' |
|
1978 | other arguments needed). Use -v for more information.''' | |
1977 |
|
1979 | |||
1978 | q = repo.mq |
|
1980 | q = repo.mq | |
1979 | guards = q.active() |
|
1981 | guards = q.active() | |
1980 | if args or opts['none']: |
|
1982 | if args or opts['none']: | |
1981 | old_unapplied = q.unapplied(repo) |
|
1983 | old_unapplied = q.unapplied(repo) | |
1982 | old_guarded = [i for i in xrange(len(q.applied)) if |
|
1984 | old_guarded = [i for i in xrange(len(q.applied)) if | |
1983 | not q.pushable(i)[0]] |
|
1985 | not q.pushable(i)[0]] | |
1984 | q.set_active(args) |
|
1986 | q.set_active(args) | |
1985 | q.save_dirty() |
|
1987 | q.save_dirty() | |
1986 | if not args: |
|
1988 | if not args: | |
1987 | ui.status(_('guards deactivated\n')) |
|
1989 | ui.status(_('guards deactivated\n')) | |
1988 | if not opts['pop'] and not opts['reapply']: |
|
1990 | if not opts['pop'] and not opts['reapply']: | |
1989 | unapplied = q.unapplied(repo) |
|
1991 | unapplied = q.unapplied(repo) | |
1990 | guarded = [i for i in xrange(len(q.applied)) |
|
1992 | guarded = [i for i in xrange(len(q.applied)) | |
1991 | if not q.pushable(i)[0]] |
|
1993 | if not q.pushable(i)[0]] | |
1992 | if len(unapplied) != len(old_unapplied): |
|
1994 | if len(unapplied) != len(old_unapplied): | |
1993 | ui.status(_('number of unguarded, unapplied patches has ' |
|
1995 | ui.status(_('number of unguarded, unapplied patches has ' | |
1994 | 'changed from %d to %d\n') % |
|
1996 | 'changed from %d to %d\n') % | |
1995 | (len(old_unapplied), len(unapplied))) |
|
1997 | (len(old_unapplied), len(unapplied))) | |
1996 | if len(guarded) != len(old_guarded): |
|
1998 | if len(guarded) != len(old_guarded): | |
1997 | ui.status(_('number of guarded, applied patches has changed ' |
|
1999 | ui.status(_('number of guarded, applied patches has changed ' | |
1998 | 'from %d to %d\n') % |
|
2000 | 'from %d to %d\n') % | |
1999 | (len(old_guarded), len(guarded))) |
|
2001 | (len(old_guarded), len(guarded))) | |
2000 | elif opts['series']: |
|
2002 | elif opts['series']: | |
2001 | guards = {} |
|
2003 | guards = {} | |
2002 | noguards = 0 |
|
2004 | noguards = 0 | |
2003 | for gs in q.series_guards: |
|
2005 | for gs in q.series_guards: | |
2004 | if not gs: |
|
2006 | if not gs: | |
2005 | noguards += 1 |
|
2007 | noguards += 1 | |
2006 | for g in gs: |
|
2008 | for g in gs: | |
2007 | guards.setdefault(g, 0) |
|
2009 | guards.setdefault(g, 0) | |
2008 | guards[g] += 1 |
|
2010 | guards[g] += 1 | |
2009 | if ui.verbose: |
|
2011 | if ui.verbose: | |
2010 | guards['NONE'] = noguards |
|
2012 | guards['NONE'] = noguards | |
2011 | guards = guards.items() |
|
2013 | guards = guards.items() | |
2012 | guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:])) |
|
2014 | guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:])) | |
2013 | if guards: |
|
2015 | if guards: | |
2014 | ui.note(_('guards in series file:\n')) |
|
2016 | ui.note(_('guards in series file:\n')) | |
2015 | for guard, count in guards: |
|
2017 | for guard, count in guards: | |
2016 | ui.note('%2d ' % count) |
|
2018 | ui.note('%2d ' % count) | |
2017 | ui.write(guard, '\n') |
|
2019 | ui.write(guard, '\n') | |
2018 | else: |
|
2020 | else: | |
2019 | ui.note(_('no guards in series file\n')) |
|
2021 | ui.note(_('no guards in series file\n')) | |
2020 | else: |
|
2022 | else: | |
2021 | if guards: |
|
2023 | if guards: | |
2022 | ui.note(_('active guards:\n')) |
|
2024 | ui.note(_('active guards:\n')) | |
2023 | for g in guards: |
|
2025 | for g in guards: | |
2024 | ui.write(g, '\n') |
|
2026 | ui.write(g, '\n') | |
2025 | else: |
|
2027 | else: | |
2026 | ui.write(_('no active guards\n')) |
|
2028 | ui.write(_('no active guards\n')) | |
2027 | reapply = opts['reapply'] and q.applied and q.appliedname(-1) |
|
2029 | reapply = opts['reapply'] and q.applied and q.appliedname(-1) | |
2028 | popped = False |
|
2030 | popped = False | |
2029 | if opts['pop'] or opts['reapply']: |
|
2031 | if opts['pop'] or opts['reapply']: | |
2030 | for i in xrange(len(q.applied)): |
|
2032 | for i in xrange(len(q.applied)): | |
2031 | pushable, reason = q.pushable(i) |
|
2033 | pushable, reason = q.pushable(i) | |
2032 | if not pushable: |
|
2034 | if not pushable: | |
2033 | ui.status(_('popping guarded patches\n')) |
|
2035 | ui.status(_('popping guarded patches\n')) | |
2034 | popped = True |
|
2036 | popped = True | |
2035 | if i == 0: |
|
2037 | if i == 0: | |
2036 | q.pop(repo, all=True) |
|
2038 | q.pop(repo, all=True) | |
2037 | else: |
|
2039 | else: | |
2038 | q.pop(repo, i-1) |
|
2040 | q.pop(repo, i-1) | |
2039 | break |
|
2041 | break | |
2040 | if popped: |
|
2042 | if popped: | |
2041 | try: |
|
2043 | try: | |
2042 | if reapply: |
|
2044 | if reapply: | |
2043 | ui.status(_('reapplying unguarded patches\n')) |
|
2045 | ui.status(_('reapplying unguarded patches\n')) | |
2044 | q.push(repo, reapply) |
|
2046 | q.push(repo, reapply) | |
2045 | finally: |
|
2047 | finally: | |
2046 | q.save_dirty() |
|
2048 | q.save_dirty() | |
2047 |
|
2049 | |||
2048 | def reposetup(ui, repo): |
|
2050 | def reposetup(ui, repo): | |
2049 | class mqrepo(repo.__class__): |
|
2051 | class mqrepo(repo.__class__): | |
2050 | def abort_if_wdir_patched(self, errmsg, force=False): |
|
2052 | def abort_if_wdir_patched(self, errmsg, force=False): | |
2051 | if self.mq.applied and not force: |
|
2053 | if self.mq.applied and not force: | |
2052 | parent = revlog.hex(self.dirstate.parents()[0]) |
|
2054 | parent = revlog.hex(self.dirstate.parents()[0]) | |
2053 | if parent in [s.rev for s in self.mq.applied]: |
|
2055 | if parent in [s.rev for s in self.mq.applied]: | |
2054 | raise util.Abort(errmsg) |
|
2056 | raise util.Abort(errmsg) | |
2055 |
|
2057 | |||
2056 | def commit(self, *args, **opts): |
|
2058 | def commit(self, *args, **opts): | |
2057 | if len(args) >= 6: |
|
2059 | if len(args) >= 6: | |
2058 | force = args[5] |
|
2060 | force = args[5] | |
2059 | else: |
|
2061 | else: | |
2060 | force = opts.get('force') |
|
2062 | force = opts.get('force') | |
2061 | self.abort_if_wdir_patched( |
|
2063 | self.abort_if_wdir_patched( | |
2062 | _('cannot commit over an applied mq patch'), |
|
2064 | _('cannot commit over an applied mq patch'), | |
2063 | force) |
|
2065 | force) | |
2064 |
|
2066 | |||
2065 | return super(mqrepo, self).commit(*args, **opts) |
|
2067 | return super(mqrepo, self).commit(*args, **opts) | |
2066 |
|
2068 | |||
2067 | def push(self, remote, force=False, revs=None): |
|
2069 | def push(self, remote, force=False, revs=None): | |
2068 | if self.mq.applied and not force and not revs: |
|
2070 | if self.mq.applied and not force and not revs: | |
2069 | raise util.Abort(_('source has mq patches applied')) |
|
2071 | raise util.Abort(_('source has mq patches applied')) | |
2070 | return super(mqrepo, self).push(remote, force, revs) |
|
2072 | return super(mqrepo, self).push(remote, force, revs) | |
2071 |
|
2073 | |||
2072 | def tags(self): |
|
2074 | def tags(self): | |
2073 | if self.tagscache: |
|
2075 | if self.tagscache: | |
2074 | return self.tagscache |
|
2076 | return self.tagscache | |
2075 |
|
2077 | |||
2076 | tagscache = super(mqrepo, self).tags() |
|
2078 | tagscache = super(mqrepo, self).tags() | |
2077 |
|
2079 | |||
2078 | q = self.mq |
|
2080 | q = self.mq | |
2079 | if not q.applied: |
|
2081 | if not q.applied: | |
2080 | return tagscache |
|
2082 | return tagscache | |
2081 |
|
2083 | |||
2082 | mqtags = [(revlog.bin(patch.rev), patch.name) for patch in q.applied] |
|
2084 | mqtags = [(revlog.bin(patch.rev), patch.name) for patch in q.applied] | |
2083 | mqtags.append((mqtags[-1][0], 'qtip')) |
|
2085 | mqtags.append((mqtags[-1][0], 'qtip')) | |
2084 | mqtags.append((mqtags[0][0], 'qbase')) |
|
2086 | mqtags.append((mqtags[0][0], 'qbase')) | |
2085 | mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) |
|
2087 | mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) | |
2086 | for patch in mqtags: |
|
2088 | for patch in mqtags: | |
2087 | if patch[1] in tagscache: |
|
2089 | if patch[1] in tagscache: | |
2088 | self.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1]) |
|
2090 | self.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1]) | |
2089 | else: |
|
2091 | else: | |
2090 | tagscache[patch[1]] = patch[0] |
|
2092 | tagscache[patch[1]] = patch[0] | |
2091 |
|
2093 | |||
2092 | return tagscache |
|
2094 | return tagscache | |
2093 |
|
2095 | |||
2094 | def _branchtags(self): |
|
2096 | def _branchtags(self): | |
2095 | q = self.mq |
|
2097 | q = self.mq | |
2096 | if not q.applied: |
|
2098 | if not q.applied: | |
2097 | return super(mqrepo, self)._branchtags() |
|
2099 | return super(mqrepo, self)._branchtags() | |
2098 |
|
2100 | |||
2099 | self.branchcache = {} # avoid recursion in changectx |
|
2101 | self.branchcache = {} # avoid recursion in changectx | |
2100 | cl = self.changelog |
|
2102 | cl = self.changelog | |
2101 | partial, last, lrev = self._readbranchcache() |
|
2103 | partial, last, lrev = self._readbranchcache() | |
2102 |
|
2104 | |||
2103 | qbase = cl.rev(revlog.bin(q.applied[0].rev)) |
|
2105 | qbase = cl.rev(revlog.bin(q.applied[0].rev)) | |
2104 | start = lrev + 1 |
|
2106 | start = lrev + 1 | |
2105 | if start < qbase: |
|
2107 | if start < qbase: | |
2106 | # update the cache (excluding the patches) and save it |
|
2108 | # update the cache (excluding the patches) and save it | |
2107 | self._updatebranchcache(partial, lrev+1, qbase) |
|
2109 | self._updatebranchcache(partial, lrev+1, qbase) | |
2108 | self._writebranchcache(partial, cl.node(qbase-1), qbase-1) |
|
2110 | self._writebranchcache(partial, cl.node(qbase-1), qbase-1) | |
2109 | start = qbase |
|
2111 | start = qbase | |
2110 | # if start = qbase, the cache is as updated as it should be. |
|
2112 | # if start = qbase, the cache is as updated as it should be. | |
2111 | # if start > qbase, the cache includes (part of) the patches. |
|
2113 | # if start > qbase, the cache includes (part of) the patches. | |
2112 | # we might as well use it, but we won't save it. |
|
2114 | # we might as well use it, but we won't save it. | |
2113 |
|
2115 | |||
2114 | # update the cache up to the tip |
|
2116 | # update the cache up to the tip | |
2115 | self._updatebranchcache(partial, start, cl.count()) |
|
2117 | self._updatebranchcache(partial, start, cl.count()) | |
2116 |
|
2118 | |||
2117 | return partial |
|
2119 | return partial | |
2118 |
|
2120 | |||
2119 | if repo.local(): |
|
2121 | if repo.local(): | |
2120 | repo.__class__ = mqrepo |
|
2122 | repo.__class__ = mqrepo | |
2121 | repo.mq = queue(ui, repo.join("")) |
|
2123 | repo.mq = queue(ui, repo.join("")) | |
2122 |
|
2124 | |||
2123 | seriesopts = [('s', 'summary', None, _('print first line of patch header'))] |
|
2125 | seriesopts = [('s', 'summary', None, _('print first line of patch header'))] | |
2124 |
|
2126 | |||
2125 | cmdtable = { |
|
2127 | cmdtable = { | |
2126 | "qapplied": (applied, [] + seriesopts, _('hg qapplied [-s] [PATCH]')), |
|
2128 | "qapplied": (applied, [] + seriesopts, _('hg qapplied [-s] [PATCH]')), | |
2127 | "qclone": |
|
2129 | "qclone": | |
2128 | (clone, |
|
2130 | (clone, | |
2129 | [('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2131 | [('', 'pull', None, _('use pull protocol to copy metadata')), | |
2130 | ('U', 'noupdate', None, _('do not update the new working directories')), |
|
2132 | ('U', 'noupdate', None, _('do not update the new working directories')), | |
2131 | ('', 'uncompressed', None, |
|
2133 | ('', 'uncompressed', None, | |
2132 | _('use uncompressed transfer (fast over LAN)')), |
|
2134 | _('use uncompressed transfer (fast over LAN)')), | |
2133 | ('p', 'patches', '', _('location of source patch repo')), |
|
2135 | ('p', 'patches', '', _('location of source patch repo')), | |
2134 | ] + commands.remoteopts, |
|
2136 | ] + commands.remoteopts, | |
2135 | _('hg qclone [OPTION]... SOURCE [DEST]')), |
|
2137 | _('hg qclone [OPTION]... SOURCE [DEST]')), | |
2136 | "qcommit|qci": |
|
2138 | "qcommit|qci": | |
2137 | (commit, |
|
2139 | (commit, | |
2138 | commands.table["^commit|ci"][1], |
|
2140 | commands.table["^commit|ci"][1], | |
2139 | _('hg qcommit [OPTION]... [FILE]...')), |
|
2141 | _('hg qcommit [OPTION]... [FILE]...')), | |
2140 | "^qdiff": |
|
2142 | "^qdiff": | |
2141 | (diff, |
|
2143 | (diff, | |
2142 | [('g', 'git', None, _('use git extended diff format')), |
|
2144 | [('g', 'git', None, _('use git extended diff format')), | |
2143 | ] + commands.walkopts, |
|
2145 | ] + commands.walkopts, | |
2144 | _('hg qdiff [-I] [-X] [-g] [FILE]...')), |
|
2146 | _('hg qdiff [-I] [-X] [-g] [FILE]...')), | |
2145 | "qdelete|qremove|qrm": |
|
2147 | "qdelete|qremove|qrm": | |
2146 | (delete, |
|
2148 | (delete, | |
2147 | [('k', 'keep', None, _('keep patch file')), |
|
2149 | [('k', 'keep', None, _('keep patch file')), | |
2148 | ('r', 'rev', [], _('stop managing a revision'))], |
|
2150 | ('r', 'rev', [], _('stop managing a revision'))], | |
2149 | _('hg qdelete [-k] [-r REV]... [PATCH]...')), |
|
2151 | _('hg qdelete [-k] [-r REV]... [PATCH]...')), | |
2150 | 'qfold': |
|
2152 | 'qfold': | |
2151 | (fold, |
|
2153 | (fold, | |
2152 | [('e', 'edit', None, _('edit patch header')), |
|
2154 | [('e', 'edit', None, _('edit patch header')), | |
2153 | ('k', 'keep', None, _('keep folded patch files')), |
|
2155 | ('k', 'keep', None, _('keep folded patch files')), | |
2154 | ] + commands.commitopts, |
|
2156 | ] + commands.commitopts, | |
2155 | _('hg qfold [-e] [-k] [-m TEXT] [-l FILE] PATCH...')), |
|
2157 | _('hg qfold [-e] [-k] [-m TEXT] [-l FILE] PATCH...')), | |
2156 | 'qgoto': |
|
2158 | 'qgoto': | |
2157 | (goto, |
|
2159 | (goto, | |
2158 | [('f', 'force', None, _('overwrite any local changes'))], |
|
2160 | [('f', 'force', None, _('overwrite any local changes'))], | |
2159 | _('hg qgoto [OPTION]... PATCH')), |
|
2161 | _('hg qgoto [OPTION]... PATCH')), | |
2160 | 'qguard': |
|
2162 | 'qguard': | |
2161 | (guard, |
|
2163 | (guard, | |
2162 | [('l', 'list', None, _('list all patches and guards')), |
|
2164 | [('l', 'list', None, _('list all patches and guards')), | |
2163 | ('n', 'none', None, _('drop all guards'))], |
|
2165 | ('n', 'none', None, _('drop all guards'))], | |
2164 | _('hg qguard [-l] [-n] [PATCH] [+GUARD]... [-GUARD]...')), |
|
2166 | _('hg qguard [-l] [-n] [PATCH] [+GUARD]... [-GUARD]...')), | |
2165 | 'qheader': (header, [], _('hg qheader [PATCH]')), |
|
2167 | 'qheader': (header, [], _('hg qheader [PATCH]')), | |
2166 | "^qimport": |
|
2168 | "^qimport": | |
2167 | (qimport, |
|
2169 | (qimport, | |
2168 | [('e', 'existing', None, 'import file in patch dir'), |
|
2170 | [('e', 'existing', None, 'import file in patch dir'), | |
2169 | ('n', 'name', '', 'patch file name'), |
|
2171 | ('n', 'name', '', 'patch file name'), | |
2170 | ('f', 'force', None, 'overwrite existing files'), |
|
2172 | ('f', 'force', None, 'overwrite existing files'), | |
2171 | ('r', 'rev', [], 'place existing revisions under mq control'), |
|
2173 | ('r', 'rev', [], 'place existing revisions under mq control'), | |
2172 | ('g', 'git', None, _('use git extended diff format'))], |
|
2174 | ('g', 'git', None, _('use git extended diff format'))], | |
2173 | _('hg qimport [-e] [-n NAME] [-f] [-g] [-r REV]... FILE...')), |
|
2175 | _('hg qimport [-e] [-n NAME] [-f] [-g] [-r REV]... FILE...')), | |
2174 | "^qinit": |
|
2176 | "^qinit": | |
2175 | (init, |
|
2177 | (init, | |
2176 | [('c', 'create-repo', None, 'create queue repository')], |
|
2178 | [('c', 'create-repo', None, 'create queue repository')], | |
2177 | _('hg qinit [-c]')), |
|
2179 | _('hg qinit [-c]')), | |
2178 | "qnew": |
|
2180 | "qnew": | |
2179 | (new, |
|
2181 | (new, | |
2180 | [('e', 'edit', None, _('edit commit message')), |
|
2182 | [('e', 'edit', None, _('edit commit message')), | |
2181 | ('f', 'force', None, _('import uncommitted changes into patch')), |
|
2183 | ('f', 'force', None, _('import uncommitted changes into patch')), | |
2182 | ('g', 'git', None, _('use git extended diff format')), |
|
2184 | ('g', 'git', None, _('use git extended diff format')), | |
2183 | ] + commands.walkopts + commands.commitopts, |
|
2185 | ] + commands.walkopts + commands.commitopts, | |
2184 | _('hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH [FILE]...')), |
|
2186 | _('hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH [FILE]...')), | |
2185 | "qnext": (next, [] + seriesopts, _('hg qnext [-s]')), |
|
2187 | "qnext": (next, [] + seriesopts, _('hg qnext [-s]')), | |
2186 | "qprev": (prev, [] + seriesopts, _('hg qprev [-s]')), |
|
2188 | "qprev": (prev, [] + seriesopts, _('hg qprev [-s]')), | |
2187 | "^qpop": |
|
2189 | "^qpop": | |
2188 | (pop, |
|
2190 | (pop, | |
2189 | [('a', 'all', None, _('pop all patches')), |
|
2191 | [('a', 'all', None, _('pop all patches')), | |
2190 | ('n', 'name', '', _('queue name to pop')), |
|
2192 | ('n', 'name', '', _('queue name to pop')), | |
2191 | ('f', 'force', None, _('forget any local changes'))], |
|
2193 | ('f', 'force', None, _('forget any local changes'))], | |
2192 | _('hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]')), |
|
2194 | _('hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]')), | |
2193 | "^qpush": |
|
2195 | "^qpush": | |
2194 | (push, |
|
2196 | (push, | |
2195 | [('f', 'force', None, _('apply if the patch has rejects')), |
|
2197 | [('f', 'force', None, _('apply if the patch has rejects')), | |
2196 | ('l', 'list', None, _('list patch name in commit text')), |
|
2198 | ('l', 'list', None, _('list patch name in commit text')), | |
2197 | ('a', 'all', None, _('apply all patches')), |
|
2199 | ('a', 'all', None, _('apply all patches')), | |
2198 | ('m', 'merge', None, _('merge from another queue')), |
|
2200 | ('m', 'merge', None, _('merge from another queue')), | |
2199 | ('n', 'name', '', _('merge queue name'))], |
|
2201 | ('n', 'name', '', _('merge queue name'))], | |
2200 | _('hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]')), |
|
2202 | _('hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]')), | |
2201 | "^qrefresh": |
|
2203 | "^qrefresh": | |
2202 | (refresh, |
|
2204 | (refresh, | |
2203 | [('e', 'edit', None, _('edit commit message')), |
|
2205 | [('e', 'edit', None, _('edit commit message')), | |
2204 | ('g', 'git', None, _('use git extended diff format')), |
|
2206 | ('g', 'git', None, _('use git extended diff format')), | |
2205 | ('s', 'short', None, _('refresh only files already in the patch')), |
|
2207 | ('s', 'short', None, _('refresh only files already in the patch')), | |
2206 | ] + commands.walkopts + commands.commitopts, |
|
2208 | ] + commands.walkopts + commands.commitopts, | |
2207 | _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')), |
|
2209 | _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')), | |
2208 | 'qrename|qmv': |
|
2210 | 'qrename|qmv': | |
2209 | (rename, [], _('hg qrename PATCH1 [PATCH2]')), |
|
2211 | (rename, [], _('hg qrename PATCH1 [PATCH2]')), | |
2210 | "qrestore": |
|
2212 | "qrestore": | |
2211 | (restore, |
|
2213 | (restore, | |
2212 | [('d', 'delete', None, _('delete save entry')), |
|
2214 | [('d', 'delete', None, _('delete save entry')), | |
2213 | ('u', 'update', None, _('update queue working dir'))], |
|
2215 | ('u', 'update', None, _('update queue working dir'))], | |
2214 | _('hg qrestore [-d] [-u] REV')), |
|
2216 | _('hg qrestore [-d] [-u] REV')), | |
2215 | "qsave": |
|
2217 | "qsave": | |
2216 | (save, |
|
2218 | (save, | |
2217 | [('c', 'copy', None, _('copy patch directory')), |
|
2219 | [('c', 'copy', None, _('copy patch directory')), | |
2218 | ('n', 'name', '', _('copy directory name')), |
|
2220 | ('n', 'name', '', _('copy directory name')), | |
2219 | ('e', 'empty', None, _('clear queue status file')), |
|
2221 | ('e', 'empty', None, _('clear queue status file')), | |
2220 | ('f', 'force', None, _('force copy'))] + commands.commitopts, |
|
2222 | ('f', 'force', None, _('force copy'))] + commands.commitopts, | |
2221 | _('hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]')), |
|
2223 | _('hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]')), | |
2222 | "qselect": |
|
2224 | "qselect": | |
2223 | (select, |
|
2225 | (select, | |
2224 | [('n', 'none', None, _('disable all guards')), |
|
2226 | [('n', 'none', None, _('disable all guards')), | |
2225 | ('s', 'series', None, _('list all guards in series file')), |
|
2227 | ('s', 'series', None, _('list all guards in series file')), | |
2226 | ('', 'pop', None, _('pop to before first guarded applied patch')), |
|
2228 | ('', 'pop', None, _('pop to before first guarded applied patch')), | |
2227 | ('', 'reapply', None, _('pop, then reapply patches'))], |
|
2229 | ('', 'reapply', None, _('pop, then reapply patches'))], | |
2228 | _('hg qselect [OPTION]... [GUARD]...')), |
|
2230 | _('hg qselect [OPTION]... [GUARD]...')), | |
2229 | "qseries": |
|
2231 | "qseries": | |
2230 | (series, |
|
2232 | (series, | |
2231 | [('m', 'missing', None, _('print patches not in series')), |
|
2233 | [('m', 'missing', None, _('print patches not in series')), | |
2232 | ] + seriesopts, |
|
2234 | ] + seriesopts, | |
2233 | _('hg qseries [-ms]')), |
|
2235 | _('hg qseries [-ms]')), | |
2234 | "^strip": |
|
2236 | "^strip": | |
2235 | (strip, |
|
2237 | (strip, | |
2236 | [('f', 'force', None, _('force multi-head removal')), |
|
2238 | [('f', 'force', None, _('force multi-head removal')), | |
2237 | ('b', 'backup', None, _('bundle unrelated changesets')), |
|
2239 | ('b', 'backup', None, _('bundle unrelated changesets')), | |
2238 | ('n', 'nobackup', None, _('no backups'))], |
|
2240 | ('n', 'nobackup', None, _('no backups'))], | |
2239 | _('hg strip [-f] [-b] [-n] REV')), |
|
2241 | _('hg strip [-f] [-b] [-n] REV')), | |
2240 | "qtop": (top, [] + seriesopts, _('hg qtop [-s]')), |
|
2242 | "qtop": (top, [] + seriesopts, _('hg qtop [-s]')), | |
2241 | "qunapplied": (unapplied, [] + seriesopts, _('hg qunapplied [-s] [PATCH]')), |
|
2243 | "qunapplied": (unapplied, [] + seriesopts, _('hg qunapplied [-s] [PATCH]')), | |
2242 | } |
|
2244 | } |
@@ -1,290 +1,291 b'' | |||||
1 | # hg.py - repository classes for mercurial |
|
1 | # hg.py - repository classes for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
|
4 | # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms |
|
6 | # This software may be used and distributed according to the terms | |
7 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | # of the GNU General Public License, incorporated herein by reference. | |
8 |
|
8 | |||
9 | from node import * |
|
9 | from node import * | |
10 | from repo import * |
|
10 | from repo import * | |
11 | from i18n import _ |
|
11 | from i18n import _ | |
12 | import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo |
|
12 | import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo | |
13 | import errno, lock, os, shutil, util, extensions |
|
13 | import errno, lock, os, shutil, util, extensions | |
14 | import merge as _merge |
|
14 | import merge as _merge | |
15 | import verify as _verify |
|
15 | import verify as _verify | |
16 |
|
16 | |||
17 | def _local(path): |
|
17 | def _local(path): | |
18 | return (os.path.isfile(util.drop_scheme('file', path)) and |
|
18 | return (os.path.isfile(util.drop_scheme('file', path)) and | |
19 | bundlerepo or localrepo) |
|
19 | bundlerepo or localrepo) | |
20 |
|
20 | |||
21 | def parseurl(url, revs): |
|
21 | def parseurl(url, revs): | |
22 | '''parse url#branch, returning url, branch + revs''' |
|
22 | '''parse url#branch, returning url, branch + revs''' | |
23 |
|
23 | |||
24 | if '#' not in url: |
|
24 | if '#' not in url: | |
25 | return url, (revs or None) |
|
25 | return url, (revs or None) | |
26 |
|
26 | |||
27 | url, rev = url.split('#', 1) |
|
27 | url, rev = url.split('#', 1) | |
28 | return url, revs + [rev] |
|
28 | return url, revs + [rev] | |
29 |
|
29 | |||
30 | schemes = { |
|
30 | schemes = { | |
31 | 'bundle': bundlerepo, |
|
31 | 'bundle': bundlerepo, | |
32 | 'file': _local, |
|
32 | 'file': _local, | |
33 | 'http': httprepo, |
|
33 | 'http': httprepo, | |
34 | 'https': httprepo, |
|
34 | 'https': httprepo, | |
35 | 'ssh': sshrepo, |
|
35 | 'ssh': sshrepo, | |
36 | 'static-http': statichttprepo, |
|
36 | 'static-http': statichttprepo, | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | def _lookup(path): |
|
39 | def _lookup(path): | |
40 | scheme = 'file' |
|
40 | scheme = 'file' | |
41 | if path: |
|
41 | if path: | |
42 | c = path.find(':') |
|
42 | c = path.find(':') | |
43 | if c > 0: |
|
43 | if c > 0: | |
44 | scheme = path[:c] |
|
44 | scheme = path[:c] | |
45 | thing = schemes.get(scheme) or schemes['file'] |
|
45 | thing = schemes.get(scheme) or schemes['file'] | |
46 | try: |
|
46 | try: | |
47 | return thing(path) |
|
47 | return thing(path) | |
48 | except TypeError: |
|
48 | except TypeError: | |
49 | return thing |
|
49 | return thing | |
50 |
|
50 | |||
51 | def islocal(repo): |
|
51 | def islocal(repo): | |
52 | '''return true if repo or path is local''' |
|
52 | '''return true if repo or path is local''' | |
53 | if isinstance(repo, str): |
|
53 | if isinstance(repo, str): | |
54 | try: |
|
54 | try: | |
55 | return _lookup(repo).islocal(repo) |
|
55 | return _lookup(repo).islocal(repo) | |
56 | except AttributeError: |
|
56 | except AttributeError: | |
57 | return False |
|
57 | return False | |
58 | return repo.local() |
|
58 | return repo.local() | |
59 |
|
59 | |||
60 | def repository(ui, path='', create=False): |
|
60 | def repository(ui, path='', create=False): | |
61 | """return a repository object for the specified path""" |
|
61 | """return a repository object for the specified path""" | |
62 | repo = _lookup(path).instance(ui, path, create) |
|
62 | repo = _lookup(path).instance(ui, path, create) | |
63 | ui = getattr(repo, "ui", ui) |
|
63 | ui = getattr(repo, "ui", ui) | |
64 | for hook in extensions.setuphooks: |
|
64 | for hook in extensions.setuphooks: | |
65 | hook(ui, repo) |
|
65 | hook(ui, repo) | |
66 | return repo |
|
66 | return repo | |
67 |
|
67 | |||
68 | def defaultdest(source): |
|
68 | def defaultdest(source): | |
69 | '''return default destination of clone if none is given''' |
|
69 | '''return default destination of clone if none is given''' | |
70 | return os.path.basename(os.path.normpath(source)) |
|
70 | return os.path.basename(os.path.normpath(source)) | |
71 |
|
71 | |||
72 | def clone(ui, source, dest=None, pull=False, rev=None, update=True, |
|
72 | def clone(ui, source, dest=None, pull=False, rev=None, update=True, | |
73 | stream=False): |
|
73 | stream=False): | |
74 | """Make a copy of an existing repository. |
|
74 | """Make a copy of an existing repository. | |
75 |
|
75 | |||
76 | Create a copy of an existing repository in a new directory. The |
|
76 | Create a copy of an existing repository in a new directory. The | |
77 | source and destination are URLs, as passed to the repository |
|
77 | source and destination are URLs, as passed to the repository | |
78 | function. Returns a pair of repository objects, the source and |
|
78 | function. Returns a pair of repository objects, the source and | |
79 | newly created destination. |
|
79 | newly created destination. | |
80 |
|
80 | |||
81 | The location of the source is added to the new repository's |
|
81 | The location of the source is added to the new repository's | |
82 | .hg/hgrc file, as the default to be used for future pulls and |
|
82 | .hg/hgrc file, as the default to be used for future pulls and | |
83 | pushes. |
|
83 | pushes. | |
84 |
|
84 | |||
85 | If an exception is raised, the partly cloned/updated destination |
|
85 | If an exception is raised, the partly cloned/updated destination | |
86 | repository will be deleted. |
|
86 | repository will be deleted. | |
87 |
|
87 | |||
88 | Arguments: |
|
88 | Arguments: | |
89 |
|
89 | |||
90 | source: repository object or URL |
|
90 | source: repository object or URL | |
91 |
|
91 | |||
92 | dest: URL of destination repository to create (defaults to base |
|
92 | dest: URL of destination repository to create (defaults to base | |
93 | name of source repository) |
|
93 | name of source repository) | |
94 |
|
94 | |||
95 | pull: always pull from source repository, even in local case |
|
95 | pull: always pull from source repository, even in local case | |
96 |
|
96 | |||
97 | stream: stream raw data uncompressed from repository (fast over |
|
97 | stream: stream raw data uncompressed from repository (fast over | |
98 | LAN, slow over WAN) |
|
98 | LAN, slow over WAN) | |
99 |
|
99 | |||
100 | rev: revision to clone up to (implies pull=True) |
|
100 | rev: revision to clone up to (implies pull=True) | |
101 |
|
101 | |||
102 | update: update working directory after clone completes, if |
|
102 | update: update working directory after clone completes, if | |
103 | destination is local repository |
|
103 | destination is local repository | |
104 | """ |
|
104 | """ | |
105 |
|
105 | |||
106 | origsource = source |
|
106 | origsource = source | |
107 | source, rev = parseurl(ui.expandpath(source), rev) |
|
107 | source, rev = parseurl(ui.expandpath(source), rev) | |
108 |
|
108 | |||
109 | if isinstance(source, str): |
|
109 | if isinstance(source, str): | |
110 | src_repo = repository(ui, source) |
|
110 | src_repo = repository(ui, source) | |
111 | else: |
|
111 | else: | |
112 | src_repo = source |
|
112 | src_repo = source | |
113 | source = src_repo.url() |
|
113 | source = src_repo.url() | |
114 |
|
114 | |||
115 | if dest is None: |
|
115 | if dest is None: | |
116 | dest = defaultdest(source) |
|
116 | dest = defaultdest(source) | |
117 | ui.status(_("destination directory: %s\n") % dest) |
|
117 | ui.status(_("destination directory: %s\n") % dest) | |
118 |
|
118 | |||
119 | def localpath(path): |
|
119 | def localpath(path): | |
120 | if path.startswith('file://'): |
|
120 | if path.startswith('file://'): | |
121 | return path[7:] |
|
121 | return path[7:] | |
122 | if path.startswith('file:'): |
|
122 | if path.startswith('file:'): | |
123 | return path[5:] |
|
123 | return path[5:] | |
124 | return path |
|
124 | return path | |
125 |
|
125 | |||
126 | dest = localpath(dest) |
|
126 | dest = localpath(dest) | |
127 | source = localpath(source) |
|
127 | source = localpath(source) | |
128 |
|
128 | |||
129 | if os.path.exists(dest): |
|
129 | if os.path.exists(dest): | |
130 | raise util.Abort(_("destination '%s' already exists") % dest) |
|
130 | raise util.Abort(_("destination '%s' already exists") % dest) | |
131 |
|
131 | |||
132 | class DirCleanup(object): |
|
132 | class DirCleanup(object): | |
133 | def __init__(self, dir_): |
|
133 | def __init__(self, dir_): | |
134 | self.rmtree = shutil.rmtree |
|
134 | self.rmtree = shutil.rmtree | |
135 | self.dir_ = dir_ |
|
135 | self.dir_ = dir_ | |
136 | def close(self): |
|
136 | def close(self): | |
137 | self.dir_ = None |
|
137 | self.dir_ = None | |
138 | def __del__(self): |
|
138 | def __del__(self): | |
139 | if self.dir_: |
|
139 | if self.dir_: | |
140 | self.rmtree(self.dir_, True) |
|
140 | self.rmtree(self.dir_, True) | |
141 |
|
141 | |||
142 | src_lock = dest_lock = dir_cleanup = None |
|
142 | src_lock = dest_lock = dir_cleanup = None | |
143 | try: |
|
143 | try: | |
144 | if islocal(dest): |
|
144 | if islocal(dest): | |
145 | dir_cleanup = DirCleanup(dest) |
|
145 | dir_cleanup = DirCleanup(dest) | |
146 |
|
146 | |||
147 | abspath = origsource |
|
147 | abspath = origsource | |
148 | copy = False |
|
148 | copy = False | |
149 | if src_repo.local() and islocal(dest): |
|
149 | if src_repo.local() and islocal(dest): | |
150 | abspath = os.path.abspath(origsource) |
|
150 | abspath = os.path.abspath(origsource) | |
151 | copy = not pull and not rev |
|
151 | copy = not pull and not rev | |
152 |
|
152 | |||
153 | if copy: |
|
153 | if copy: | |
154 | try: |
|
154 | try: | |
155 | # we use a lock here because if we race with commit, we |
|
155 | # we use a lock here because if we race with commit, we | |
156 | # can end up with extra data in the cloned revlogs that's |
|
156 | # can end up with extra data in the cloned revlogs that's | |
157 | # not pointed to by changesets, thus causing verify to |
|
157 | # not pointed to by changesets, thus causing verify to | |
158 | # fail |
|
158 | # fail | |
159 | src_lock = src_repo.lock() |
|
159 | src_lock = src_repo.lock() | |
160 | except lock.LockException: |
|
160 | except lock.LockException: | |
161 | copy = False |
|
161 | copy = False | |
162 |
|
162 | |||
163 | if copy: |
|
163 | if copy: | |
164 | def force_copy(src, dst): |
|
164 | def force_copy(src, dst): | |
165 | try: |
|
165 | try: | |
166 | util.copyfiles(src, dst) |
|
166 | util.copyfiles(src, dst) | |
167 | except OSError, inst: |
|
167 | except OSError, inst: | |
168 | if inst.errno != errno.ENOENT: |
|
168 | if inst.errno != errno.ENOENT: | |
169 | raise |
|
169 | raise | |
170 |
|
170 | |||
171 | src_store = os.path.realpath(src_repo.spath) |
|
171 | src_store = os.path.realpath(src_repo.spath) | |
172 | if not os.path.exists(dest): |
|
172 | if not os.path.exists(dest): | |
173 | os.mkdir(dest) |
|
173 | os.mkdir(dest) | |
174 | dest_path = os.path.realpath(os.path.join(dest, ".hg")) |
|
174 | dest_path = os.path.realpath(os.path.join(dest, ".hg")) | |
175 | os.mkdir(dest_path) |
|
175 | os.mkdir(dest_path) | |
176 | if src_repo.spath != src_repo.path: |
|
176 | if src_repo.spath != src_repo.path: | |
177 | dest_store = os.path.join(dest_path, "store") |
|
177 | dest_store = os.path.join(dest_path, "store") | |
178 | os.mkdir(dest_store) |
|
178 | os.mkdir(dest_store) | |
179 | else: |
|
179 | else: | |
180 | dest_store = dest_path |
|
180 | dest_store = dest_path | |
181 | # copy the requires file |
|
181 | # copy the requires file | |
182 | force_copy(src_repo.join("requires"), |
|
182 | force_copy(src_repo.join("requires"), | |
183 | os.path.join(dest_path, "requires")) |
|
183 | os.path.join(dest_path, "requires")) | |
184 | # we lock here to avoid premature writing to the target |
|
184 | # we lock here to avoid premature writing to the target | |
185 | dest_lock = lock.lock(os.path.join(dest_store, "lock")) |
|
185 | dest_lock = lock.lock(os.path.join(dest_store, "lock")) | |
186 |
|
186 | |||
187 | files = ("data", |
|
187 | files = ("data", | |
188 | "00manifest.d", "00manifest.i", |
|
188 | "00manifest.d", "00manifest.i", | |
189 | "00changelog.d", "00changelog.i") |
|
189 | "00changelog.d", "00changelog.i") | |
190 | for f in files: |
|
190 | for f in files: | |
191 | src = os.path.join(src_store, f) |
|
191 | src = os.path.join(src_store, f) | |
192 | dst = os.path.join(dest_store, f) |
|
192 | dst = os.path.join(dest_store, f) | |
193 | force_copy(src, dst) |
|
193 | force_copy(src, dst) | |
194 |
|
194 | |||
195 | # we need to re-init the repo after manually copying the data |
|
195 | # we need to re-init the repo after manually copying the data | |
196 | # into it |
|
196 | # into it | |
197 | dest_repo = repository(ui, dest) |
|
197 | dest_repo = repository(ui, dest) | |
198 |
|
198 | |||
199 | else: |
|
199 | else: | |
200 | dest_repo = repository(ui, dest, create=True) |
|
200 | dest_repo = repository(ui, dest, create=True) | |
201 |
|
201 | |||
202 | revs = None |
|
202 | revs = None | |
203 | if rev: |
|
203 | if rev: | |
204 | if 'lookup' not in src_repo.capabilities: |
|
204 | if 'lookup' not in src_repo.capabilities: | |
205 | raise util.Abort(_("src repository does not support revision " |
|
205 | raise util.Abort(_("src repository does not support revision " | |
206 | "lookup and so doesn't support clone by " |
|
206 | "lookup and so doesn't support clone by " | |
207 | "revision")) |
|
207 | "revision")) | |
208 | revs = [src_repo.lookup(r) for r in rev] |
|
208 | revs = [src_repo.lookup(r) for r in rev] | |
209 |
|
209 | |||
210 | if dest_repo.local(): |
|
210 | if dest_repo.local(): | |
211 | dest_repo.clone(src_repo, heads=revs, stream=stream) |
|
211 | dest_repo.clone(src_repo, heads=revs, stream=stream) | |
212 | elif src_repo.local(): |
|
212 | elif src_repo.local(): | |
213 | src_repo.push(dest_repo, revs=revs) |
|
213 | src_repo.push(dest_repo, revs=revs) | |
214 | else: |
|
214 | else: | |
215 | raise util.Abort(_("clone from remote to remote not supported")) |
|
215 | raise util.Abort(_("clone from remote to remote not supported")) | |
216 |
|
216 | |||
|
217 | if dir_cleanup: | |||
|
218 | dir_cleanup.close() | |||
|
219 | ||||
217 | if dest_repo.local(): |
|
220 | if dest_repo.local(): | |
218 | fp = dest_repo.opener("hgrc", "w", text=True) |
|
221 | fp = dest_repo.opener("hgrc", "w", text=True) | |
219 | fp.write("[paths]\n") |
|
222 | fp.write("[paths]\n") | |
220 | fp.write("default = %s\n" % abspath) |
|
223 | fp.write("default = %s\n" % abspath) | |
221 | fp.close() |
|
224 | fp.close() | |
222 |
|
225 | |||
223 | if update: |
|
226 | if update: | |
224 | try: |
|
227 | try: | |
225 | checkout = dest_repo.lookup("default") |
|
228 | checkout = dest_repo.lookup("default") | |
226 | except: |
|
229 | except: | |
227 | checkout = dest_repo.changelog.tip() |
|
230 | checkout = dest_repo.changelog.tip() | |
228 | _update(dest_repo, checkout) |
|
231 | _update(dest_repo, checkout) | |
229 | if dir_cleanup: |
|
|||
230 | dir_cleanup.close() |
|
|||
231 |
|
232 | |||
232 | return src_repo, dest_repo |
|
233 | return src_repo, dest_repo | |
233 | finally: |
|
234 | finally: | |
234 | del src_lock, dest_lock, dir_cleanup |
|
235 | del src_lock, dest_lock, dir_cleanup | |
235 |
|
236 | |||
236 | def _showstats(repo, stats): |
|
237 | def _showstats(repo, stats): | |
237 | stats = ((stats[0], _("updated")), |
|
238 | stats = ((stats[0], _("updated")), | |
238 | (stats[1], _("merged")), |
|
239 | (stats[1], _("merged")), | |
239 | (stats[2], _("removed")), |
|
240 | (stats[2], _("removed")), | |
240 | (stats[3], _("unresolved"))) |
|
241 | (stats[3], _("unresolved"))) | |
241 | note = ", ".join([_("%d files %s") % s for s in stats]) |
|
242 | note = ", ".join([_("%d files %s") % s for s in stats]) | |
242 | repo.ui.status("%s\n" % note) |
|
243 | repo.ui.status("%s\n" % note) | |
243 |
|
244 | |||
244 | def _update(repo, node): return update(repo, node) |
|
245 | def _update(repo, node): return update(repo, node) | |
245 |
|
246 | |||
246 | def update(repo, node): |
|
247 | def update(repo, node): | |
247 | """update the working directory to node, merging linear changes""" |
|
248 | """update the working directory to node, merging linear changes""" | |
248 | pl = repo.parents() |
|
249 | pl = repo.parents() | |
249 | stats = _merge.update(repo, node, False, False, None) |
|
250 | stats = _merge.update(repo, node, False, False, None) | |
250 | _showstats(repo, stats) |
|
251 | _showstats(repo, stats) | |
251 | if stats[3]: |
|
252 | if stats[3]: | |
252 | repo.ui.status(_("There are unresolved merges with" |
|
253 | repo.ui.status(_("There are unresolved merges with" | |
253 | " locally modified files.\n")) |
|
254 | " locally modified files.\n")) | |
254 | if stats[1]: |
|
255 | if stats[1]: | |
255 | repo.ui.status(_("You can finish the partial merge using:\n")) |
|
256 | repo.ui.status(_("You can finish the partial merge using:\n")) | |
256 | else: |
|
257 | else: | |
257 | repo.ui.status(_("You can redo the full merge using:\n")) |
|
258 | repo.ui.status(_("You can redo the full merge using:\n")) | |
258 | # len(pl)==1, otherwise _merge.update() would have raised util.Abort: |
|
259 | # len(pl)==1, otherwise _merge.update() would have raised util.Abort: | |
259 | repo.ui.status(_(" hg update %s\n hg update %s\n") |
|
260 | repo.ui.status(_(" hg update %s\n hg update %s\n") | |
260 | % (pl[0].rev(), repo.changectx(node).rev())) |
|
261 | % (pl[0].rev(), repo.changectx(node).rev())) | |
261 | return stats[3] |
|
262 | return stats[3] | |
262 |
|
263 | |||
263 | def clean(repo, node, show_stats=True): |
|
264 | def clean(repo, node, show_stats=True): | |
264 | """forcibly switch the working directory to node, clobbering changes""" |
|
265 | """forcibly switch the working directory to node, clobbering changes""" | |
265 | stats = _merge.update(repo, node, False, True, None) |
|
266 | stats = _merge.update(repo, node, False, True, None) | |
266 | if show_stats: _showstats(repo, stats) |
|
267 | if show_stats: _showstats(repo, stats) | |
267 | return stats[3] |
|
268 | return stats[3] | |
268 |
|
269 | |||
269 | def merge(repo, node, force=None, remind=True): |
|
270 | def merge(repo, node, force=None, remind=True): | |
270 | """branch merge with node, resolving changes""" |
|
271 | """branch merge with node, resolving changes""" | |
271 | stats = _merge.update(repo, node, True, force, False) |
|
272 | stats = _merge.update(repo, node, True, force, False) | |
272 | _showstats(repo, stats) |
|
273 | _showstats(repo, stats) | |
273 | if stats[3]: |
|
274 | if stats[3]: | |
274 | pl = repo.parents() |
|
275 | pl = repo.parents() | |
275 | repo.ui.status(_("There are unresolved merges," |
|
276 | repo.ui.status(_("There are unresolved merges," | |
276 | " you can redo the full merge using:\n" |
|
277 | " you can redo the full merge using:\n" | |
277 | " hg update -C %s\n" |
|
278 | " hg update -C %s\n" | |
278 | " hg merge %s\n") |
|
279 | " hg merge %s\n") | |
279 | % (pl[0].rev(), pl[1].rev())) |
|
280 | % (pl[0].rev(), pl[1].rev())) | |
280 | elif remind: |
|
281 | elif remind: | |
281 | repo.ui.status(_("(branch merge, don't forget to commit)\n")) |
|
282 | repo.ui.status(_("(branch merge, don't forget to commit)\n")) | |
282 | return stats[3] |
|
283 | return stats[3] | |
283 |
|
284 | |||
284 | def revert(repo, node, choose): |
|
285 | def revert(repo, node, choose): | |
285 | """revert changes to revision in node without updating dirstate""" |
|
286 | """revert changes to revision in node without updating dirstate""" | |
286 | return _merge.update(repo, node, False, True, choose)[3] |
|
287 | return _merge.update(repo, node, False, True, choose)[3] | |
287 |
|
288 | |||
288 | def verify(repo): |
|
289 | def verify(repo): | |
289 | """verify the consistency of a repository""" |
|
290 | """verify the consistency of a repository""" | |
290 | return _verify.verify(repo) |
|
291 | return _verify.verify(repo) |
General Comments 0
You need to be logged in to leave comments.
Login now