author | Sean Meiners <sean.meiners@linspire.com> |
Fri, 30 Jun 2006 19:24:02 -0700 | |
changeset 2549 | e1831f06eef1 |
parent 2531 | 7a90e0c77f43 |
child 2554 | 8264c2034970 |
permissions | -rw-r--r-- |
1808 | 1 |
# queue.py - patch queues for mercurial |
2 |
# |
|
3 |
# Copyright 2005 Chris Mason <mason@suse.com> |
|
4 |
# |
|
5 |
# This software may be used and distributed according to the terms |
|
6 |
# of the GNU General Public License, incorporated herein by reference. |
|
7 |
||
8 |
from mercurial.demandload import * |
|
9 |
demandload(globals(), "os sys re struct traceback errno bz2") |
|
10 |
from mercurial.i18n import gettext as _ |
|
11 |
from mercurial import ui, hg, revlog, commands, util |
|
12 |
||
13 |
versionstr = "0.45" |
|
14 |
||
15 |
repomap = {} |
|
16 |
||
2047
ebf1ecb5f4e8
Register qversion as a non repository related command
Edouard Gomez <ed.gomez@free.fr>
parents:
1863
diff
changeset
|
17 |
commands.norepo += " qversion" |
1808 | 18 |
class queue: |
19 |
def __init__(self, ui, path, patchdir=None): |
|
20 |
self.basepath = path |
|
21 |
if patchdir: |
|
22 |
self.path = patchdir |
|
23 |
else: |
|
24 |
self.path = os.path.join(path, "patches") |
|
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
25 |
self.opener = util.opener(self.path) |
1808 | 26 |
self.ui = ui |
27 |
self.applied = [] |
|
28 |
self.full_series = [] |
|
29 |
self.applied_dirty = 0 |
|
30 |
self.series_dirty = 0 |
|
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
31 |
self.series_path = "series" |
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
32 |
self.status_path = "status" |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
33 |
|
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
34 |
if os.path.exists(os.path.join(self.path, self.series_path)): |
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
35 |
self.full_series = self.opener(self.series_path).read().splitlines() |
1808 | 36 |
self.read_series(self.full_series) |
37 |
||
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
38 |
if os.path.exists(os.path.join(self.path, self.status_path)): |
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
39 |
self.applied = self.opener(self.status_path).read().splitlines() |
1808 | 40 |
|
41 |
def find_series(self, patch): |
|
42 |
pre = re.compile("(\s*)([^#]+)") |
|
43 |
index = 0 |
|
44 |
for l in self.full_series: |
|
45 |
m = pre.match(l) |
|
46 |
if m: |
|
47 |
s = m.group(2) |
|
48 |
s = s.rstrip() |
|
49 |
if s == patch: |
|
50 |
return index |
|
51 |
index += 1 |
|
52 |
return None |
|
53 |
||
54 |
def read_series(self, list): |
|
55 |
def matcher(list): |
|
56 |
pre = re.compile("(\s*)([^#]+)") |
|
57 |
for l in list: |
|
58 |
m = pre.match(l) |
|
59 |
if m: |
|
60 |
s = m.group(2) |
|
61 |
s = s.rstrip() |
|
62 |
if len(s) > 0: |
|
63 |
yield s |
|
64 |
self.series = [] |
|
65 |
self.series = [ x for x in matcher(list) ] |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
66 |
|
1808 | 67 |
def save_dirty(self): |
68 |
if self.applied_dirty: |
|
69 |
if len(self.applied) > 0: |
|
70 |
nl = "\n" |
|
71 |
else: |
|
72 |
nl = "" |
|
73 |
f = self.opener(self.status_path, "w") |
|
74 |
f.write("\n".join(self.applied) + nl) |
|
75 |
if self.series_dirty: |
|
76 |
if len(self.full_series) > 0: |
|
77 |
nl = "\n" |
|
78 |
else: |
|
79 |
nl = "" |
|
80 |
f = self.opener(self.series_path, "w") |
|
81 |
f.write("\n".join(self.full_series) + nl) |
|
82 |
||
83 |
def readheaders(self, patch): |
|
84 |
def eatdiff(lines): |
|
85 |
while lines: |
|
86 |
l = lines[-1] |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
87 |
if (l.startswith("diff -") or |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
88 |
l.startswith("Index:") or |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
89 |
l.startswith("===========")): |
1808 | 90 |
del lines[-1] |
91 |
else: |
|
92 |
break |
|
93 |
def eatempty(lines): |
|
94 |
while lines: |
|
95 |
l = lines[-1] |
|
96 |
if re.match('\s*$', l): |
|
97 |
del lines[-1] |
|
98 |
else: |
|
99 |
break |
|
100 |
||
101 |
pf = os.path.join(self.path, patch) |
|
102 |
message = [] |
|
103 |
comments = [] |
|
104 |
user = None |
|
2299
dacf718e1d48
Add timestamp field to export format. Make import and mq use it.
Danek Duvall <danek.duvall@sun.com>
parents:
2270
diff
changeset
|
105 |
date = None |
1808 | 106 |
format = None |
107 |
subject = None |
|
108 |
diffstart = 0 |
|
109 |
||
110 |
for line in file(pf): |
|
111 |
line = line.rstrip() |
|
112 |
if diffstart: |
|
113 |
if line.startswith('+++ '): |
|
114 |
diffstart = 2 |
|
115 |
break |
|
116 |
if line.startswith("--- "): |
|
117 |
diffstart = 1 |
|
118 |
continue |
|
119 |
elif format == "hgpatch": |
|
120 |
# parse values when importing the result of an hg export |
|
121 |
if line.startswith("# User "): |
|
122 |
user = line[7:] |
|
2300
52b9b6751b2c
Use "# Date" instead of "# Timestamp" for dated export/import of patches.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2299
diff
changeset
|
123 |
elif line.startswith("# Date "): |
52b9b6751b2c
Use "# Date" instead of "# Timestamp" for dated export/import of patches.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2299
diff
changeset
|
124 |
date = line[7:] |
1808 | 125 |
elif not line.startswith("# ") and line: |
126 |
message.append(line) |
|
127 |
format = None |
|
128 |
elif line == '# HG changeset patch': |
|
129 |
format = "hgpatch" |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
130 |
elif (format != "tagdone" and (line.startswith("Subject: ") or |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
131 |
line.startswith("subject: "))): |
1808 | 132 |
subject = line[9:] |
133 |
format = "tag" |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
134 |
elif (format != "tagdone" and (line.startswith("From: ") or |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
135 |
line.startswith("from: "))): |
1808 | 136 |
user = line[6:] |
137 |
format = "tag" |
|
138 |
elif format == "tag" and line == "": |
|
139 |
# when looking for tags (subject: from: etc) they |
|
140 |
# end once you find a blank line in the source |
|
141 |
format = "tagdone" |
|
2301
7c2623aedeb4
Strip empty lines and trailing spaces around commit messages.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2300
diff
changeset
|
142 |
elif message or line: |
1808 | 143 |
message.append(line) |
144 |
comments.append(line) |
|
145 |
||
146 |
eatdiff(message) |
|
147 |
eatdiff(comments) |
|
148 |
eatempty(message) |
|
149 |
eatempty(comments) |
|
150 |
||
151 |
# make sure message isn't empty |
|
152 |
if format and format.startswith("tag") and subject: |
|
153 |
message.insert(0, "") |
|
154 |
message.insert(0, subject) |
|
2299
dacf718e1d48
Add timestamp field to export format. Make import and mq use it.
Danek Duvall <danek.duvall@sun.com>
parents:
2270
diff
changeset
|
155 |
return (message, comments, user, date, diffstart > 1) |
1808 | 156 |
|
157 |
def mergeone(self, repo, mergeq, head, patch, rev, wlock): |
|
158 |
# first try just applying the patch |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
159 |
(err, n) = self.apply(repo, [ patch ], update_status=False, |
1808 | 160 |
strict=True, merge=rev, wlock=wlock) |
161 |
||
162 |
if err == 0: |
|
163 |
return (err, n) |
|
164 |
||
165 |
if n is None: |
|
166 |
self.ui.warn("apply failed for patch %s\n" % patch) |
|
167 |
sys.exit(1) |
|
168 |
||
169 |
self.ui.warn("patch didn't work out, merging %s\n" % patch) |
|
170 |
||
171 |
# apply failed, strip away that rev and merge. |
|
172 |
repo.update(head, allow=False, force=True, wlock=wlock) |
|
173 |
self.strip(repo, n, update=False, backup='strip', wlock=wlock) |
|
174 |
||
175 |
c = repo.changelog.read(rev) |
|
176 |
ret = repo.update(rev, allow=True, wlock=wlock) |
|
177 |
if ret: |
|
178 |
self.ui.warn("update returned %d\n" % ret) |
|
179 |
sys.exit(1) |
|
180 |
n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) |
|
181 |
if n == None: |
|
182 |
self.ui.warn("repo commit failed\n") |
|
183 |
sys.exit(1) |
|
184 |
try: |
|
2299
dacf718e1d48
Add timestamp field to export format. Make import and mq use it.
Danek Duvall <danek.duvall@sun.com>
parents:
2270
diff
changeset
|
185 |
message, comments, user, date, patchfound = mergeq.readheaders(patch) |
1808 | 186 |
except: |
187 |
self.ui.warn("Unable to read %s\n" % patch) |
|
188 |
sys.exit(1) |
|
189 |
||
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
190 |
patchf = self.opener(patch, "w") |
1808 | 191 |
if comments: |
192 |
comments = "\n".join(comments) + '\n\n' |
|
193 |
patchf.write(comments) |
|
194 |
commands.dodiff(patchf, self.ui, repo, head, n) |
|
195 |
patchf.close() |
|
196 |
return (0, n) |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
197 |
|
1808 | 198 |
def qparents(self, repo, rev=None): |
199 |
if rev is None: |
|
200 |
(p1, p2) = repo.dirstate.parents() |
|
201 |
if p2 == revlog.nullid: |
|
202 |
return p1 |
|
203 |
if len(self.applied) == 0: |
|
204 |
return None |
|
205 |
(top, patch) = self.applied[-1].split(':') |
|
206 |
top = revlog.bin(top) |
|
207 |
return top |
|
208 |
pp = repo.changelog.parents(rev) |
|
209 |
if pp[1] != revlog.nullid: |
|
210 |
arevs = [ x.split(':')[0] for x in self.applied ] |
|
211 |
p0 = revlog.hex(pp[0]) |
|
212 |
p1 = revlog.hex(pp[1]) |
|
213 |
if p0 in arevs: |
|
214 |
return pp[0] |
|
215 |
if p1 in arevs: |
|
216 |
return pp[1] |
|
217 |
return pp[0] |
|
218 |
||
219 |
def mergepatch(self, repo, mergeq, series, wlock): |
|
220 |
if len(self.applied) == 0: |
|
221 |
# each of the patches merged in will have two parents. This |
|
222 |
# can confuse the qrefresh, qdiff, and strip code because it |
|
223 |
# needs to know which parent is actually in the patch queue. |
|
224 |
# so, we insert a merge marker with only one parent. This way |
|
225 |
# the first patch in the queue is never a merge patch |
|
226 |
# |
|
227 |
pname = ".hg.patches.merge.marker" |
|
228 |
n = repo.commit(None, '[mq]: merge marker', user=None, force=1, |
|
229 |
wlock=wlock) |
|
230 |
self.applied.append(revlog.hex(n) + ":" + pname) |
|
231 |
self.applied_dirty = 1 |
|
232 |
||
233 |
head = self.qparents(repo) |
|
234 |
||
235 |
for patch in series: |
|
236 |
patch = mergeq.lookup(patch) |
|
237 |
if not patch: |
|
238 |
self.ui.warn("patch %s does not exist\n" % patch) |
|
239 |
return (1, None) |
|
240 |
||
241 |
info = mergeq.isapplied(patch) |
|
242 |
if not info: |
|
243 |
self.ui.warn("patch %s is not applied\n" % patch) |
|
244 |
return (1, None) |
|
245 |
rev = revlog.bin(info[1]) |
|
246 |
(err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) |
|
247 |
if head: |
|
248 |
self.applied.append(revlog.hex(head) + ":" + patch) |
|
249 |
self.applied_dirty = 1 |
|
250 |
if err: |
|
251 |
return (err, head) |
|
252 |
return (0, head) |
|
253 |
||
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
254 |
def apply(self, repo, series, list=False, update_status=True, |
1808 | 255 |
strict=False, patchdir=None, merge=None, wlock=None): |
256 |
# TODO unify with commands.py |
|
257 |
if not patchdir: |
|
258 |
patchdir = self.path |
|
259 |
pwd = os.getcwd() |
|
260 |
os.chdir(repo.root) |
|
261 |
err = 0 |
|
262 |
if not wlock: |
|
263 |
wlock = repo.wlock() |
|
264 |
lock = repo.lock() |
|
265 |
tr = repo.transaction() |
|
266 |
n = None |
|
267 |
for patch in series: |
|
268 |
self.ui.warn("applying %s\n" % patch) |
|
269 |
pf = os.path.join(patchdir, patch) |
|
270 |
||
271 |
try: |
|
2299
dacf718e1d48
Add timestamp field to export format. Make import and mq use it.
Danek Duvall <danek.duvall@sun.com>
parents:
2270
diff
changeset
|
272 |
message, comments, user, date, patchfound = self.readheaders(patch) |
1808 | 273 |
except: |
274 |
self.ui.warn("Unable to read %s\n" % pf) |
|
275 |
err = 1 |
|
276 |
break |
|
277 |
||
278 |
if not message: |
|
279 |
message = "imported patch %s\n" % patch |
|
280 |
else: |
|
281 |
if list: |
|
282 |
message.append("\nimported patch %s" % patch) |
|
283 |
message = '\n'.join(message) |
|
284 |
||
285 |
try: |
|
2270
afd7c4ec000f
Fix issue240: mq: qpush fails on Solaris
Danek Duvall <danek.duvall@sun.com>
parents:
2185
diff
changeset
|
286 |
pp = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') |
afd7c4ec000f
Fix issue240: mq: qpush fails on Solaris
Danek Duvall <danek.duvall@sun.com>
parents:
2185
diff
changeset
|
287 |
f = os.popen("%s -p1 --no-backup-if-mismatch < '%s'" % (pp, pf)) |
1808 | 288 |
except: |
289 |
self.ui.warn("patch failed, unable to continue (try -v)\n") |
|
290 |
err = 1 |
|
291 |
break |
|
292 |
files = [] |
|
293 |
fuzz = False |
|
294 |
for l in f: |
|
295 |
l = l.rstrip('\r\n'); |
|
296 |
if self.ui.verbose: |
|
297 |
self.ui.warn(l + "\n") |
|
298 |
if l[:14] == 'patching file ': |
|
299 |
pf = os.path.normpath(l[14:]) |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
300 |
# when patch finds a space in the file name, it puts |
1808 | 301 |
# single quotes around the filename. strip them off |
302 |
if pf[0] == "'" and pf[-1] == "'": |
|
303 |
pf = pf[1:-1] |
|
304 |
if pf not in files: |
|
305 |
files.append(pf) |
|
306 |
printed_file = False |
|
307 |
file_str = l |
|
308 |
elif l.find('with fuzz') >= 0: |
|
309 |
if not printed_file: |
|
310 |
self.ui.warn(file_str + '\n') |
|
311 |
printed_file = True |
|
312 |
self.ui.warn(l + '\n') |
|
313 |
fuzz = True |
|
314 |
elif l.find('saving rejects to file') >= 0: |
|
315 |
self.ui.warn(l + '\n') |
|
316 |
elif l.find('FAILED') >= 0: |
|
317 |
if not printed_file: |
|
318 |
self.ui.warn(file_str + '\n') |
|
319 |
printed_file = True |
|
320 |
self.ui.warn(l + '\n') |
|
321 |
patcherr = f.close() |
|
322 |
||
323 |
if merge and len(files) > 0: |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
324 |
# Mark as merged and update dirstate parent info |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
325 |
repo.dirstate.update(repo.dirstate.filterfiles(files), 'm') |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
326 |
p1, p2 = repo.dirstate.parents() |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
327 |
repo.dirstate.setparents(p1, merge) |
1808 | 328 |
if len(files) > 0: |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
329 |
commands.addremove_lock(self.ui, repo, files, |
1808 | 330 |
opts={}, wlock=wlock) |
2299
dacf718e1d48
Add timestamp field to export format. Make import and mq use it.
Danek Duvall <danek.duvall@sun.com>
parents:
2270
diff
changeset
|
331 |
n = repo.commit(files, message, user, date, force=1, lock=lock, |
1808 | 332 |
wlock=wlock) |
333 |
||
334 |
if n == None: |
|
335 |
self.ui.warn("repo commit failed\n") |
|
336 |
sys.exit(1) |
|
337 |
||
338 |
if update_status: |
|
339 |
self.applied.append(revlog.hex(n) + ":" + patch) |
|
340 |
||
341 |
if patcherr: |
|
342 |
if not patchfound: |
|
343 |
self.ui.warn("patch %s is empty\n" % patch) |
|
344 |
err = 0 |
|
345 |
else: |
|
346 |
self.ui.warn("patch failed, rejects left in working dir\n") |
|
347 |
err = 1 |
|
348 |
break |
|
349 |
||
350 |
if fuzz and strict: |
|
351 |
self.ui.warn("fuzz found when applying patch, stopping\n") |
|
352 |
err = 1 |
|
353 |
break |
|
354 |
tr.close() |
|
355 |
os.chdir(pwd) |
|
356 |
return (err, n) |
|
357 |
||
358 |
def delete(self, repo, patch): |
|
359 |
patch = self.lookup(patch) |
|
360 |
info = self.isapplied(patch) |
|
361 |
if info: |
|
362 |
self.ui.warn("cannot delete applied patch %s\n" % patch) |
|
363 |
sys.exit(1) |
|
364 |
if patch not in self.series: |
|
365 |
self.ui.warn("patch %s not in series file\n" % patch) |
|
366 |
sys.exit(1) |
|
367 |
i = self.find_series(patch) |
|
368 |
del self.full_series[i] |
|
369 |
self.read_series(self.full_series) |
|
370 |
self.series_dirty = 1 |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
371 |
|
1808 | 372 |
def check_toppatch(self, repo): |
373 |
if len(self.applied) > 0: |
|
374 |
(top, patch) = self.applied[-1].split(':') |
|
375 |
top = revlog.bin(top) |
|
376 |
pp = repo.dirstate.parents() |
|
377 |
if top not in pp: |
|
378 |
self.ui.warn("queue top not at dirstate parents. top %s dirstate %s %s\n" %( revlog.short(top), revlog.short(pp[0]), revlog.short(pp[1]))) |
|
379 |
sys.exit(1) |
|
380 |
return top |
|
381 |
return None |
|
382 |
def check_localchanges(self, repo): |
|
383 |
(c, a, r, d, u) = repo.changes(None, None) |
|
384 |
if c or a or d or r: |
|
385 |
self.ui.write("Local changes found, refresh first\n") |
|
386 |
sys.exit(1) |
|
387 |
def new(self, repo, patch, msg=None, force=None): |
|
2511
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
388 |
commitfiles = [] |
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
389 |
(c, a, r, d, u) = repo.changes(None, None) |
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
390 |
if c or a or d or r: |
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
391 |
if not force: |
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
392 |
raise util.Abort(_("Local changes found, refresh first")) |
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
393 |
else: |
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
394 |
commitfiles = c + a + r |
1808 | 395 |
self.check_toppatch(repo) |
396 |
wlock = repo.wlock() |
|
397 |
insert = self.series_end() |
|
398 |
if msg: |
|
2511
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
399 |
n = repo.commit(commitfiles, "[mq]: %s" % msg, force=True, |
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
400 |
wlock=wlock) |
1808 | 401 |
else: |
2511
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
402 |
n = repo.commit(commitfiles, |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
403 |
"New patch: %s" % patch, force=True, wlock=wlock) |
1808 | 404 |
if n == None: |
405 |
self.ui.warn("repo commit failed\n") |
|
406 |
sys.exit(1) |
|
407 |
self.full_series[insert:insert] = [patch] |
|
408 |
self.applied.append(revlog.hex(n) + ":" + patch) |
|
409 |
self.read_series(self.full_series) |
|
410 |
self.series_dirty = 1 |
|
411 |
self.applied_dirty = 1 |
|
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
412 |
p = self.opener(patch, "w") |
1808 | 413 |
if msg: |
414 |
msg = msg + "\n" |
|
415 |
p.write(msg) |
|
416 |
p.close() |
|
417 |
wlock = None |
|
418 |
r = self.qrepo() |
|
419 |
if r: r.add([patch]) |
|
2511
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
420 |
if commitfiles: |
041d8f0a8437
mq: hg qnew -f should refresh the new patch
Chris Mason <mason@suse.com>
parents:
2488
diff
changeset
|
421 |
self.refresh(repo, short=True) |
1808 | 422 |
|
423 |
def strip(self, repo, rev, update=True, backup="all", wlock=None): |
|
424 |
def limitheads(chlog, stop): |
|
425 |
"""return the list of all nodes that have no children""" |
|
426 |
p = {} |
|
427 |
h = [] |
|
428 |
stoprev = 0 |
|
429 |
if stop in chlog.nodemap: |
|
430 |
stoprev = chlog.rev(stop) |
|
431 |
||
432 |
for r in range(chlog.count() - 1, -1, -1): |
|
433 |
n = chlog.node(r) |
|
434 |
if n not in p: |
|
435 |
h.append(n) |
|
436 |
if n == stop: |
|
437 |
break |
|
438 |
if r < stoprev: |
|
439 |
break |
|
440 |
for pn in chlog.parents(n): |
|
441 |
p[pn] = 1 |
|
442 |
return h |
|
443 |
||
444 |
def bundle(cg): |
|
445 |
backupdir = repo.join("strip-backup") |
|
446 |
if not os.path.isdir(backupdir): |
|
447 |
os.mkdir(backupdir) |
|
448 |
name = os.path.join(backupdir, "%s" % revlog.short(rev)) |
|
449 |
name = savename(name) |
|
450 |
self.ui.warn("saving bundle to %s\n" % name) |
|
451 |
# TODO, exclusive open |
|
452 |
f = open(name, "wb") |
|
453 |
try: |
|
454 |
f.write("HG10") |
|
455 |
z = bz2.BZ2Compressor(9) |
|
456 |
while 1: |
|
457 |
chunk = cg.read(4096) |
|
458 |
if not chunk: |
|
459 |
break |
|
460 |
f.write(z.compress(chunk)) |
|
461 |
f.write(z.flush()) |
|
462 |
except: |
|
463 |
os.unlink(name) |
|
464 |
raise |
|
465 |
f.close() |
|
466 |
return name |
|
467 |
||
468 |
def stripall(rev, revnum): |
|
469 |
cl = repo.changelog |
|
470 |
c = cl.read(rev) |
|
471 |
mm = repo.manifest.read(c[0]) |
|
472 |
seen = {} |
|
473 |
||
474 |
for x in xrange(revnum, cl.count()): |
|
475 |
c = cl.read(cl.node(x)) |
|
476 |
for f in c[3]: |
|
477 |
if f in seen: |
|
478 |
continue |
|
479 |
seen[f] = 1 |
|
480 |
if f in mm: |
|
481 |
filerev = mm[f] |
|
482 |
else: |
|
483 |
filerev = 0 |
|
484 |
seen[f] = filerev |
|
485 |
# we go in two steps here so the strip loop happens in a |
|
486 |
# sensible order. When stripping many files, this helps keep |
|
487 |
# our disk access patterns under control. |
|
488 |
list = seen.keys() |
|
489 |
list.sort() |
|
490 |
for f in list: |
|
491 |
ff = repo.file(f) |
|
492 |
filerev = seen[f] |
|
493 |
if filerev != 0: |
|
494 |
if filerev in ff.nodemap: |
|
495 |
filerev = ff.rev(filerev) |
|
496 |
else: |
|
497 |
filerev = 0 |
|
498 |
ff.strip(filerev, revnum) |
|
499 |
||
500 |
if not wlock: |
|
501 |
wlock = repo.wlock() |
|
502 |
lock = repo.lock() |
|
503 |
chlog = repo.changelog |
|
504 |
# TODO delete the undo files, and handle undo of merge sets |
|
505 |
pp = chlog.parents(rev) |
|
506 |
revnum = chlog.rev(rev) |
|
507 |
||
508 |
if update: |
|
509 |
urev = self.qparents(repo, rev) |
|
510 |
repo.update(urev, allow=False, force=True, wlock=wlock) |
|
511 |
repo.dirstate.write() |
|
512 |
||
513 |
# save is a list of all the branches we are truncating away |
|
514 |
# that we actually want to keep. changegroup will be used |
|
515 |
# to preserve them and add them back after the truncate |
|
516 |
saveheads = [] |
|
517 |
savebases = {} |
|
518 |
||
519 |
tip = chlog.tip() |
|
520 |
heads = limitheads(chlog, rev) |
|
521 |
seen = {} |
|
522 |
||
523 |
# search through all the heads, finding those where the revision |
|
524 |
# we want to strip away is an ancestor. Also look for merges |
|
525 |
# that might be turned into new heads by the strip. |
|
526 |
while heads: |
|
527 |
h = heads.pop() |
|
528 |
n = h |
|
529 |
while True: |
|
530 |
seen[n] = 1 |
|
531 |
pp = chlog.parents(n) |
|
532 |
if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: |
|
533 |
if pp[1] not in seen: |
|
534 |
heads.append(pp[1]) |
|
535 |
if pp[0] == revlog.nullid: |
|
536 |
break |
|
537 |
if chlog.rev(pp[0]) < revnum: |
|
538 |
break |
|
539 |
n = pp[0] |
|
540 |
if n == rev: |
|
541 |
break |
|
542 |
r = chlog.reachable(h, rev) |
|
543 |
if rev not in r: |
|
544 |
saveheads.append(h) |
|
545 |
for x in r: |
|
546 |
if chlog.rev(x) > revnum: |
|
547 |
savebases[x] = 1 |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
548 |
|
1808 | 549 |
# create a changegroup for all the branches we need to keep |
550 |
if backup is "all": |
|
551 |
backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') |
|
552 |
bundle(backupch) |
|
553 |
if saveheads: |
|
554 |
backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') |
|
555 |
chgrpfile = bundle(backupch) |
|
556 |
||
557 |
stripall(rev, revnum) |
|
558 |
||
559 |
change = chlog.read(rev) |
|
560 |
repo.manifest.strip(repo.manifest.rev(change[0]), revnum) |
|
561 |
chlog.strip(revnum, revnum) |
|
562 |
if saveheads: |
|
563 |
self.ui.status("adding branch\n") |
|
564 |
commands.unbundle(self.ui, repo, chgrpfile, update=False) |
|
565 |
if backup is not "strip": |
|
566 |
os.unlink(chgrpfile) |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
567 |
|
1808 | 568 |
def isapplied(self, patch): |
569 |
"""returns (index, rev, patch)""" |
|
570 |
for i in xrange(len(self.applied)): |
|
571 |
p = self.applied[i] |
|
572 |
a = p.split(':') |
|
573 |
if a[1] == patch: |
|
574 |
return (i, a[0], a[1]) |
|
575 |
return None |
|
576 |
||
577 |
def lookup(self, patch): |
|
578 |
if patch == None: |
|
579 |
return None |
|
580 |
if patch in self.series: |
|
581 |
return patch |
|
582 |
if not os.path.isfile(os.path.join(self.path, patch)): |
|
583 |
try: |
|
584 |
sno = int(patch) |
|
585 |
except(ValueError, OverflowError): |
|
586 |
self.ui.warn("patch %s not in series\n" % patch) |
|
587 |
sys.exit(1) |
|
588 |
if sno >= len(self.series): |
|
589 |
self.ui.warn("patch number %d is out of range\n" % sno) |
|
590 |
sys.exit(1) |
|
591 |
patch = self.series[sno] |
|
592 |
else: |
|
593 |
self.ui.warn("patch %s not in series\n" % patch) |
|
594 |
sys.exit(1) |
|
595 |
return patch |
|
596 |
||
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
597 |
def push(self, repo, patch=None, force=False, list=False, |
1808 | 598 |
mergeq=None, wlock=None): |
599 |
if not wlock: |
|
600 |
wlock = repo.wlock() |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
601 |
patch = self.lookup(patch) |
1808 | 602 |
if patch and self.isapplied(patch): |
603 |
self.ui.warn("patch %s is already applied\n" % patch) |
|
604 |
sys.exit(1) |
|
605 |
if self.series_end() == len(self.series): |
|
606 |
self.ui.warn("File series fully applied\n") |
|
607 |
sys.exit(1) |
|
608 |
if not force: |
|
609 |
self.check_localchanges(repo) |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
610 |
|
1808 | 611 |
self.applied_dirty = 1; |
612 |
start = self.series_end() |
|
613 |
if start > 0: |
|
614 |
self.check_toppatch(repo) |
|
615 |
if not patch: |
|
616 |
patch = self.series[start] |
|
617 |
end = start + 1 |
|
618 |
else: |
|
619 |
end = self.series.index(patch, start) + 1 |
|
620 |
s = self.series[start:end] |
|
621 |
if mergeq: |
|
622 |
ret = self.mergepatch(repo, mergeq, s, wlock) |
|
623 |
else: |
|
624 |
ret = self.apply(repo, s, list, wlock=wlock) |
|
625 |
top = self.applied[-1].split(':')[1] |
|
626 |
if ret[0]: |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
627 |
self.ui.write("Errors during apply, please fix and refresh %s\n" % |
1808 | 628 |
top) |
629 |
else: |
|
630 |
self.ui.write("Now at: %s\n" % top) |
|
631 |
return ret[0] |
|
632 |
||
633 |
def pop(self, repo, patch=None, force=False, update=True, wlock=None): |
|
634 |
def getfile(f, rev): |
|
635 |
t = repo.file(f).read(rev) |
|
636 |
try: |
|
637 |
repo.wfile(f, "w").write(t) |
|
638 |
except IOError: |
|
2086
8742352db413
mq: do not fail if directory to create exists
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2047
diff
changeset
|
639 |
try: |
8742352db413
mq: do not fail if directory to create exists
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2047
diff
changeset
|
640 |
os.makedirs(os.path.dirname(repo.wjoin(f))) |
8742352db413
mq: do not fail if directory to create exists
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2047
diff
changeset
|
641 |
except OSError, err: |
8742352db413
mq: do not fail if directory to create exists
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2047
diff
changeset
|
642 |
if err.errno != errno.EEXIST: raise |
1808 | 643 |
repo.wfile(f, "w").write(t) |
644 |
||
645 |
if not wlock: |
|
646 |
wlock = repo.wlock() |
|
647 |
if patch: |
|
648 |
# index, rev, patch |
|
649 |
info = self.isapplied(patch) |
|
650 |
if not info: |
|
651 |
patch = self.lookup(patch) |
|
652 |
info = self.isapplied(patch) |
|
653 |
if not info: |
|
654 |
self.ui.warn("patch %s is not applied\n" % patch) |
|
655 |
sys.exit(1) |
|
656 |
if len(self.applied) == 0: |
|
657 |
self.ui.warn("No patches applied\n") |
|
658 |
sys.exit(1) |
|
659 |
||
660 |
if not update: |
|
661 |
parents = repo.dirstate.parents() |
|
662 |
rr = [ revlog.bin(x.split(':')[0]) for x in self.applied ] |
|
663 |
for p in parents: |
|
664 |
if p in rr: |
|
665 |
self.ui.warn("qpop: forcing dirstate update\n") |
|
666 |
update = True |
|
667 |
||
668 |
if not force and update: |
|
669 |
self.check_localchanges(repo) |
|
670 |
||
671 |
self.applied_dirty = 1; |
|
672 |
end = len(self.applied) |
|
673 |
if not patch: |
|
674 |
info = [len(self.applied) - 1] + self.applied[-1].split(':') |
|
675 |
start = info[0] |
|
676 |
rev = revlog.bin(info[1]) |
|
677 |
||
678 |
# we know there are no local changes, so we can make a simplified |
|
679 |
# form of hg.update. |
|
680 |
if update: |
|
681 |
top = self.check_toppatch(repo) |
|
682 |
qp = self.qparents(repo, rev) |
|
683 |
changes = repo.changelog.read(qp) |
|
684 |
mf1 = repo.manifest.readflags(changes[0]) |
|
685 |
mmap = repo.manifest.read(changes[0]) |
|
686 |
(c, a, r, d, u) = repo.changes(qp, top) |
|
687 |
if d: |
|
688 |
raise util.Abort("deletions found between repo revs") |
|
689 |
for f in c: |
|
690 |
getfile(f, mmap[f]) |
|
691 |
for f in r: |
|
692 |
getfile(f, mmap[f]) |
|
693 |
util.set_exec(repo.wjoin(f), mf1[f]) |
|
694 |
repo.dirstate.update(c + r, 'n') |
|
695 |
for f in a: |
|
696 |
try: os.unlink(repo.wjoin(f)) |
|
697 |
except: raise |
|
698 |
try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
|
699 |
except: pass |
|
700 |
if a: |
|
701 |
repo.dirstate.forget(a) |
|
702 |
repo.dirstate.setparents(qp, revlog.nullid) |
|
703 |
self.strip(repo, rev, update=False, backup='strip', wlock=wlock) |
|
704 |
del self.applied[start:end] |
|
705 |
if len(self.applied): |
|
706 |
self.ui.write("Now at: %s\n" % self.applied[-1].split(':')[1]) |
|
707 |
else: |
|
708 |
self.ui.write("Patch queue now empty\n") |
|
709 |
||
710 |
def diff(self, repo, files): |
|
711 |
top = self.check_toppatch(repo) |
|
712 |
if not top: |
|
713 |
self.ui.write("No patches applied\n") |
|
714 |
return |
|
715 |
qp = self.qparents(repo, top) |
|
716 |
commands.dodiff(sys.stdout, self.ui, repo, qp, None, files) |
|
717 |
||
718 |
def refresh(self, repo, short=False): |
|
719 |
if len(self.applied) == 0: |
|
720 |
self.ui.write("No patches applied\n") |
|
721 |
return |
|
722 |
wlock = repo.wlock() |
|
723 |
self.check_toppatch(repo) |
|
724 |
qp = self.qparents(repo) |
|
725 |
(top, patch) = self.applied[-1].split(':') |
|
726 |
top = revlog.bin(top) |
|
727 |
cparents = repo.changelog.parents(top) |
|
728 |
patchparent = self.qparents(repo, top) |
|
2299
dacf718e1d48
Add timestamp field to export format. Make import and mq use it.
Danek Duvall <danek.duvall@sun.com>
parents:
2270
diff
changeset
|
729 |
message, comments, user, date, patchfound = self.readheaders(patch) |
1808 | 730 |
|
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
731 |
patchf = self.opener(patch, "w") |
1808 | 732 |
if comments: |
733 |
comments = "\n".join(comments) + '\n\n' |
|
734 |
patchf.write(comments) |
|
735 |
||
736 |
tip = repo.changelog.tip() |
|
737 |
if top == tip: |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
738 |
# if the top of our patch queue is also the tip, there is an |
1808 | 739 |
# optimization here. We update the dirstate in place and strip |
740 |
# off the tip commit. Then just commit the current directory |
|
741 |
# tree. We can also send repo.commit the list of files |
|
742 |
# changed to speed up the diff |
|
743 |
# |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
744 |
# in short mode, we only diff the files included in the |
1808 | 745 |
# patch already |
746 |
# |
|
747 |
# this should really read: |
|
748 |
#(cc, dd, aa, aa2, uu) = repo.changes(tip, patchparent) |
|
749 |
# but we do it backwards to take advantage of manifest/chlog |
|
750 |
# caching against the next repo.changes call |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
751 |
# |
1808 | 752 |
(cc, aa, dd, aa2, uu) = repo.changes(patchparent, tip) |
753 |
if short: |
|
754 |
filelist = cc + aa + dd |
|
755 |
else: |
|
756 |
filelist = None |
|
757 |
(c, a, r, d, u) = repo.changes(None, None, filelist) |
|
758 |
||
759 |
# we might end up with files that were added between tip and |
|
760 |
# the dirstate parent, but then changed in the local dirstate. |
|
761 |
# in this case, we want them to only show up in the added section |
|
762 |
for x in c: |
|
763 |
if x not in aa: |
|
764 |
cc.append(x) |
|
765 |
# we might end up with files added by the local dirstate that |
|
766 |
# were deleted by the patch. In this case, they should only |
|
767 |
# show up in the changed section. |
|
768 |
for x in a: |
|
769 |
if x in dd: |
|
770 |
del dd[dd.index(x)] |
|
771 |
cc.append(x) |
|
772 |
else: |
|
773 |
aa.append(x) |
|
774 |
# make sure any files deleted in the local dirstate |
|
775 |
# are not in the add or change column of the patch |
|
776 |
forget = [] |
|
777 |
for x in d + r: |
|
778 |
if x in aa: |
|
779 |
del aa[aa.index(x)] |
|
780 |
forget.append(x) |
|
781 |
continue |
|
782 |
elif x in cc: |
|
783 |
del cc[cc.index(x)] |
|
784 |
dd.append(x) |
|
785 |
||
786 |
c = list(util.unique(cc)) |
|
787 |
r = list(util.unique(dd)) |
|
788 |
a = list(util.unique(aa)) |
|
789 |
filelist = list(util.unique(c + r + a )) |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
790 |
commands.dodiff(patchf, self.ui, repo, patchparent, None, |
1808 | 791 |
filelist, changes=(c, a, r, [], u)) |
792 |
patchf.close() |
|
793 |
||
794 |
changes = repo.changelog.read(tip) |
|
795 |
repo.dirstate.setparents(*cparents) |
|
796 |
repo.dirstate.update(a, 'a') |
|
797 |
repo.dirstate.update(r, 'r') |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
798 |
repo.dirstate.update(c, 'n') |
1808 | 799 |
repo.dirstate.forget(forget) |
800 |
||
801 |
if not message: |
|
802 |
message = "patch queue: %s\n" % patch |
|
803 |
else: |
|
804 |
message = "\n".join(message) |
|
805 |
self.strip(repo, top, update=False, backup='strip', wlock=wlock) |
|
806 |
n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) |
|
807 |
self.applied[-1] = revlog.hex(n) + ':' + patch |
|
808 |
self.applied_dirty = 1 |
|
809 |
else: |
|
810 |
commands.dodiff(patchf, self.ui, repo, patchparent, None) |
|
811 |
patchf.close() |
|
812 |
self.pop(repo, force=True, wlock=wlock) |
|
813 |
self.push(repo, force=True, wlock=wlock) |
|
814 |
||
815 |
def init(self, repo, create=False): |
|
816 |
if os.path.isdir(self.path): |
|
817 |
raise util.Abort("patch queue directory already exists") |
|
818 |
os.mkdir(self.path) |
|
819 |
if create: |
|
820 |
return self.qrepo(create=True) |
|
821 |
||
822 |
def unapplied(self, repo, patch=None): |
|
823 |
if patch and patch not in self.series: |
|
824 |
self.ui.warn("%s not in the series file\n" % patch) |
|
825 |
sys.exit(1) |
|
826 |
if not patch: |
|
827 |
start = self.series_end() |
|
828 |
else: |
|
829 |
start = self.series.index(patch) + 1 |
|
830 |
for p in self.series[start:]: |
|
831 |
self.ui.write("%s\n" % p) |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
832 |
|
1808 | 833 |
def qseries(self, repo, missing=None): |
834 |
start = self.series_end() |
|
835 |
if not missing: |
|
836 |
for p in self.series[:start]: |
|
837 |
if self.ui.verbose: |
|
838 |
self.ui.write("%d A " % self.series.index(p)) |
|
839 |
self.ui.write("%s\n" % p) |
|
840 |
for p in self.series[start:]: |
|
841 |
if self.ui.verbose: |
|
842 |
self.ui.write("%d U " % self.series.index(p)) |
|
843 |
self.ui.write("%s\n" % p) |
|
844 |
else: |
|
845 |
list = [] |
|
846 |
for root, dirs, files in os.walk(self.path): |
|
847 |
d = root[len(self.path) + 1:] |
|
848 |
for f in files: |
|
849 |
fl = os.path.join(d, f) |
|
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
850 |
if (fl not in self.series and |
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
851 |
fl not in (self.status_path, self.series_path) |
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
852 |
and not fl.startswith('.')): |
1808 | 853 |
list.append(fl) |
854 |
list.sort() |
|
855 |
if list: |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
856 |
for x in list: |
1808 | 857 |
if self.ui.verbose: |
858 |
self.ui.write("D ") |
|
859 |
self.ui.write("%s\n" % x) |
|
860 |
||
861 |
def issaveline(self, l): |
|
862 |
name = l.split(':')[1] |
|
863 |
if name == '.hg.patches.save.line': |
|
864 |
return True |
|
865 |
||
866 |
def qrepo(self, create=False): |
|
867 |
if create or os.path.isdir(os.path.join(self.path, ".hg")): |
|
1839
876e4e6ad82b
Create local ui object per repository, so .hg/hgrc don't get mixed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1810
diff
changeset
|
868 |
return hg.repository(self.ui, path=self.path, create=create) |
1808 | 869 |
|
870 |
def restore(self, repo, rev, delete=None, qupdate=None): |
|
871 |
c = repo.changelog.read(rev) |
|
872 |
desc = c[4].strip() |
|
873 |
lines = desc.splitlines() |
|
874 |
i = 0 |
|
875 |
datastart = None |
|
876 |
series = [] |
|
877 |
applied = [] |
|
878 |
qpp = None |
|
879 |
for i in xrange(0, len(lines)): |
|
880 |
if lines[i] == 'Patch Data:': |
|
881 |
datastart = i + 1 |
|
882 |
elif lines[i].startswith('Dirstate:'): |
|
883 |
l = lines[i].rstrip() |
|
884 |
l = l[10:].split(' ') |
|
885 |
qpp = [ hg.bin(x) for x in l ] |
|
886 |
elif datastart != None: |
|
887 |
l = lines[i].rstrip() |
|
888 |
index = l.index(':') |
|
889 |
id = l[:index] |
|
890 |
file = l[index + 1:] |
|
891 |
if id: |
|
892 |
applied.append(l) |
|
893 |
series.append(file) |
|
894 |
if datastart == None: |
|
895 |
self.ui.warn("No saved patch data found\n") |
|
896 |
return 1 |
|
897 |
self.ui.warn("restoring status: %s\n" % lines[0]) |
|
898 |
self.full_series = series |
|
899 |
self.applied = applied |
|
900 |
self.read_series(self.full_series) |
|
901 |
self.series_dirty = 1 |
|
902 |
self.applied_dirty = 1 |
|
903 |
heads = repo.changelog.heads() |
|
904 |
if delete: |
|
905 |
if rev not in heads: |
|
906 |
self.ui.warn("save entry has children, leaving it alone\n") |
|
907 |
else: |
|
908 |
self.ui.warn("removing save entry %s\n" % hg.short(rev)) |
|
909 |
pp = repo.dirstate.parents() |
|
910 |
if rev in pp: |
|
911 |
update = True |
|
912 |
else: |
|
913 |
update = False |
|
914 |
self.strip(repo, rev, update=update, backup='strip') |
|
915 |
if qpp: |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
916 |
self.ui.warn("saved queue repository parents: %s %s\n" % |
1808 | 917 |
(hg.short(qpp[0]), hg.short(qpp[1]))) |
918 |
if qupdate: |
|
919 |
print "queue directory updating" |
|
920 |
r = self.qrepo() |
|
921 |
if not r: |
|
922 |
self.ui.warn("Unable to load queue repository\n") |
|
923 |
return 1 |
|
924 |
r.update(qpp[0], allow=False, force=True) |
|
925 |
||
926 |
def save(self, repo, msg=None): |
|
927 |
if len(self.applied) == 0: |
|
928 |
self.ui.warn("save: no patches applied, exiting\n") |
|
929 |
return 1 |
|
930 |
if self.issaveline(self.applied[-1]): |
|
931 |
self.ui.warn("status is already saved\n") |
|
932 |
return 1 |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
933 |
|
1808 | 934 |
ar = [ ':' + x for x in self.full_series ] |
935 |
if not msg: |
|
936 |
msg = "hg patches saved state" |
|
937 |
else: |
|
938 |
msg = "hg patches: " + msg.rstrip('\r\n') |
|
939 |
r = self.qrepo() |
|
940 |
if r: |
|
941 |
pp = r.dirstate.parents() |
|
942 |
msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) |
|
943 |
msg += "\n\nPatch Data:\n" |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
944 |
text = msg + "\n".join(self.applied) + '\n' + (ar and "\n".join(ar) |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
945 |
+ '\n' or "") |
1808 | 946 |
n = repo.commit(None, text, user=None, force=1) |
947 |
if not n: |
|
948 |
self.ui.warn("repo commit failed\n") |
|
949 |
return 1 |
|
950 |
self.applied.append(revlog.hex(n) + ":" + '.hg.patches.save.line') |
|
951 |
self.applied_dirty = 1 |
|
952 |
||
953 |
def series_end(self): |
|
954 |
end = 0 |
|
955 |
if len(self.applied) > 0: |
|
956 |
(top, p) = self.applied[-1].split(':') |
|
957 |
try: |
|
958 |
end = self.series.index(p) |
|
959 |
except ValueError: |
|
960 |
return 0 |
|
961 |
return end + 1 |
|
962 |
return end |
|
963 |
||
964 |
def qapplied(self, repo, patch=None): |
|
965 |
if patch and patch not in self.series: |
|
966 |
self.ui.warn("%s not in the series file\n" % patch) |
|
967 |
sys.exit(1) |
|
968 |
if not patch: |
|
969 |
end = len(self.applied) |
|
970 |
else: |
|
971 |
end = self.series.index(patch) + 1 |
|
972 |
for x in xrange(end): |
|
973 |
p = self.appliedname(x) |
|
974 |
self.ui.write("%s\n" % p) |
|
975 |
||
976 |
def appliedname(self, index): |
|
977 |
p = self.applied[index] |
|
978 |
if not self.ui.verbose: |
|
979 |
p = p.split(':')[1] |
|
980 |
return p |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
981 |
|
1808 | 982 |
def top(self, repo): |
983 |
if len(self.applied): |
|
984 |
p = self.appliedname(-1) |
|
985 |
self.ui.write(p + '\n') |
|
986 |
else: |
|
987 |
self.ui.write("No patches applied\n") |
|
988 |
||
989 |
def next(self, repo): |
|
990 |
end = self.series_end() |
|
991 |
if end == len(self.series): |
|
992 |
self.ui.write("All patches applied\n") |
|
993 |
else: |
|
994 |
self.ui.write(self.series[end] + '\n') |
|
995 |
||
996 |
def prev(self, repo): |
|
997 |
if len(self.applied) > 1: |
|
998 |
p = self.appliedname(-2) |
|
999 |
self.ui.write(p + '\n') |
|
1000 |
elif len(self.applied) == 1: |
|
1001 |
self.ui.write("Only one patch applied\n") |
|
1002 |
else: |
|
1003 |
self.ui.write("No patches applied\n") |
|
1004 |
||
1005 |
def qimport(self, repo, files, patch=None, existing=None, force=None): |
|
1006 |
if len(files) > 1 and patch: |
|
1007 |
self.ui.warn("-n option not valid when importing multiple files\n") |
|
1008 |
sys.exit(1) |
|
1009 |
i = 0 |
|
2488
2785aeb51be4
mq: add qimported patches if patch dir is a repo
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2301
diff
changeset
|
1010 |
added = [] |
1808 | 1011 |
for filename in files: |
1012 |
if existing: |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1013 |
if not patch: |
1808 | 1014 |
patch = filename |
1015 |
if not os.path.isfile(os.path.join(self.path, patch)): |
|
1016 |
self.ui.warn("patch %s does not exist\n" % patch) |
|
1017 |
sys.exit(1) |
|
1018 |
else: |
|
1019 |
try: |
|
1020 |
text = file(filename).read() |
|
1021 |
except IOError: |
|
1022 |
self.ui.warn("Unable to read %s\n" % patch) |
|
1023 |
sys.exit(1) |
|
1024 |
if not patch: |
|
1025 |
patch = os.path.split(filename)[1] |
|
1026 |
if not force and os.path.isfile(os.path.join(self.path, patch)): |
|
1027 |
self.ui.warn("patch %s already exists\n" % patch) |
|
1028 |
sys.exit(1) |
|
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
1029 |
patchf = self.opener(patch, "w") |
1808 | 1030 |
patchf.write(text) |
1031 |
if patch in self.series: |
|
1032 |
self.ui.warn("patch %s is already in the series file\n" % patch) |
|
1033 |
sys.exit(1) |
|
1034 |
index = self.series_end() + i |
|
1035 |
self.full_series[index:index] = [patch] |
|
1036 |
self.read_series(self.full_series) |
|
1037 |
self.ui.warn("adding %s to series file\n" % patch) |
|
1038 |
i += 1 |
|
2488
2785aeb51be4
mq: add qimported patches if patch dir is a repo
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2301
diff
changeset
|
1039 |
added.append(patch) |
1808 | 1040 |
patch = None |
1041 |
self.series_dirty = 1 |
|
2488
2785aeb51be4
mq: add qimported patches if patch dir is a repo
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2301
diff
changeset
|
1042 |
qrepo = self.qrepo() |
2785aeb51be4
mq: add qimported patches if patch dir is a repo
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2301
diff
changeset
|
1043 |
if qrepo: |
2785aeb51be4
mq: add qimported patches if patch dir is a repo
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2301
diff
changeset
|
1044 |
qrepo.add(added) |
1808 | 1045 |
|
1046 |
def delete(ui, repo, patch, **opts): |
|
1047 |
"""remove a patch from the series file""" |
|
1048 |
q = repomap[repo] |
|
1049 |
q.delete(repo, patch) |
|
1050 |
q.save_dirty() |
|
1051 |
return 0 |
|
1052 |
||
1053 |
def applied(ui, repo, patch=None, **opts): |
|
1054 |
"""print the patches already applied""" |
|
1055 |
repomap[repo].qapplied(repo, patch) |
|
1056 |
return 0 |
|
1057 |
||
1058 |
def unapplied(ui, repo, patch=None, **opts): |
|
1059 |
"""print the patches not yet applied""" |
|
1060 |
repomap[repo].unapplied(repo, patch) |
|
1061 |
return 0 |
|
1062 |
||
1063 |
def qimport(ui, repo, *filename, **opts): |
|
1064 |
"""import a patch""" |
|
1065 |
q = repomap[repo] |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1066 |
q.qimport(repo, filename, patch=opts['name'], |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1067 |
existing=opts['existing'], force=opts['force']) |
1808 | 1068 |
q.save_dirty() |
1069 |
return 0 |
|
1070 |
||
1071 |
def init(ui, repo, **opts): |
|
1072 |
"""init a new queue repository""" |
|
1073 |
q = repomap[repo] |
|
1074 |
r = q.init(repo, create=opts['create_repo']) |
|
1075 |
q.save_dirty() |
|
1076 |
if r: |
|
1077 |
fp = r.wopener('.hgignore', 'w') |
|
1078 |
print >> fp, 'syntax: glob' |
|
1079 |
print >> fp, 'status' |
|
1080 |
fp.close() |
|
1081 |
r.wopener('series', 'w').close() |
|
1082 |
r.add(['.hgignore', 'series']) |
|
1083 |
return 0 |
|
1084 |
||
1085 |
def commit(ui, repo, *pats, **opts): |
|
2526
37785f986260
mq: Added help for qcommit, consistently talk about queue repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2488
diff
changeset
|
1086 |
"""commit changes in the queue repository""" |
1808 | 1087 |
q = repomap[repo] |
1088 |
r = q.qrepo() |
|
1089 |
if not r: raise util.Abort('no queue repository') |
|
1090 |
commands.commit(r.ui, r, *pats, **opts) |
|
1091 |
||
1092 |
def series(ui, repo, **opts): |
|
1093 |
"""print the entire series file""" |
|
1094 |
repomap[repo].qseries(repo, missing=opts['missing']) |
|
1095 |
return 0 |
|
1096 |
||
1097 |
def top(ui, repo, **opts): |
|
1098 |
"""print the name of the current patch""" |
|
1099 |
repomap[repo].top(repo) |
|
1100 |
return 0 |
|
1101 |
||
1102 |
def next(ui, repo, **opts): |
|
1103 |
"""print the name of the next patch""" |
|
1104 |
repomap[repo].next(repo) |
|
1105 |
return 0 |
|
1106 |
||
1107 |
def prev(ui, repo, **opts): |
|
1108 |
"""print the name of the previous patch""" |
|
1109 |
repomap[repo].prev(repo) |
|
1110 |
return 0 |
|
1111 |
||
1112 |
def new(ui, repo, patch, **opts): |
|
1113 |
"""create a new patch""" |
|
1114 |
q = repomap[repo] |
|
1115 |
q.new(repo, patch, msg=opts['message'], force=opts['force']) |
|
1116 |
q.save_dirty() |
|
1117 |
return 0 |
|
1118 |
||
1119 |
def refresh(ui, repo, **opts): |
|
1120 |
"""update the current patch""" |
|
1121 |
q = repomap[repo] |
|
1122 |
q.refresh(repo, short=opts['short']) |
|
1123 |
q.save_dirty() |
|
1124 |
return 0 |
|
1125 |
||
1126 |
def diff(ui, repo, *files, **opts): |
|
1127 |
"""diff of the current patch""" |
|
2097
4d2c2597876f
Fix hg qdiff <file>
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2086
diff
changeset
|
1128 |
# deep in the dirstate code, the walkhelper method wants a list, not a tuple |
4d2c2597876f
Fix hg qdiff <file>
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2086
diff
changeset
|
1129 |
repomap[repo].diff(repo, list(files)) |
1808 | 1130 |
return 0 |
1131 |
||
1132 |
def lastsavename(path): |
|
1133 |
(dir, base) = os.path.split(path) |
|
1134 |
names = os.listdir(dir) |
|
1135 |
namere = re.compile("%s.([0-9]+)" % base) |
|
1136 |
max = None |
|
1137 |
maxname = None |
|
1138 |
for f in names: |
|
1139 |
m = namere.match(f) |
|
1140 |
if m: |
|
1141 |
index = int(m.group(1)) |
|
1142 |
if max == None or index > max: |
|
1143 |
max = index |
|
1144 |
maxname = f |
|
1145 |
if maxname: |
|
1146 |
return (os.path.join(dir, maxname), max) |
|
1147 |
return (None, None) |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1148 |
|
1808 | 1149 |
def savename(path): |
1150 |
(last, index) = lastsavename(path) |
|
1151 |
if last is None: |
|
1152 |
index = 0 |
|
1153 |
newpath = path + ".%d" % (index + 1) |
|
1154 |
return newpath |
|
1155 |
||
1156 |
def push(ui, repo, patch=None, **opts): |
|
1157 |
"""push the next patch onto the stack""" |
|
1158 |
q = repomap[repo] |
|
1159 |
mergeq = None |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1160 |
|
1808 | 1161 |
if opts['all']: |
1162 |
patch = q.series[-1] |
|
1163 |
if opts['merge']: |
|
1164 |
if opts['name']: |
|
1165 |
newpath = opts['name'] |
|
1166 |
else: |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1167 |
newpath, i = lastsavename(q.path) |
1808 | 1168 |
if not newpath: |
1169 |
ui.warn("no saved queues found, please use -n\n") |
|
1170 |
return 1 |
|
1171 |
mergeq = queue(ui, repo.join(""), newpath) |
|
1172 |
ui.warn("merging with queue at: %s\n" % mergeq.path) |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1173 |
ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
1808 | 1174 |
mergeq=mergeq) |
1175 |
q.save_dirty() |
|
1176 |
return ret |
|
1177 |
||
1178 |
def pop(ui, repo, patch=None, **opts): |
|
1179 |
"""pop the current patch off the stack""" |
|
1180 |
localupdate = True |
|
1181 |
if opts['name']: |
|
1182 |
q = queue(ui, repo.join(""), repo.join(opts['name'])) |
|
1183 |
ui.warn('using patch queue: %s\n' % q.path) |
|
1184 |
localupdate = False |
|
1185 |
else: |
|
1186 |
q = repomap[repo] |
|
1187 |
if opts['all'] and len(q.applied) > 0: |
|
1188 |
patch = q.applied[0].split(':')[1] |
|
1189 |
q.pop(repo, patch, force=opts['force'], update=localupdate) |
|
1190 |
q.save_dirty() |
|
1191 |
return 0 |
|
1192 |
||
1193 |
def restore(ui, repo, rev, **opts): |
|
1194 |
"""restore the queue state saved by a rev""" |
|
1195 |
rev = repo.lookup(rev) |
|
1196 |
q = repomap[repo] |
|
1197 |
q.restore(repo, rev, delete=opts['delete'], |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1198 |
qupdate=opts['update']) |
1808 | 1199 |
q.save_dirty() |
1200 |
return 0 |
|
1201 |
||
1202 |
def save(ui, repo, **opts): |
|
1203 |
"""save current queue state""" |
|
1204 |
q = repomap[repo] |
|
1205 |
ret = q.save(repo, msg=opts['message']) |
|
1206 |
if ret: |
|
1207 |
return ret |
|
1208 |
q.save_dirty() |
|
1209 |
if opts['copy']: |
|
1210 |
path = q.path |
|
1211 |
if opts['name']: |
|
1212 |
newpath = os.path.join(q.basepath, opts['name']) |
|
1213 |
if os.path.exists(newpath): |
|
1214 |
if not os.path.isdir(newpath): |
|
1215 |
ui.warn("destination %s exists and is not a directory\n" % |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1216 |
newpath) |
1808 | 1217 |
sys.exit(1) |
1218 |
if not opts['force']: |
|
1219 |
ui.warn("destination %s exists, use -f to force\n" % |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1220 |
newpath) |
1808 | 1221 |
sys.exit(1) |
1222 |
else: |
|
1223 |
newpath = savename(path) |
|
1224 |
ui.warn("copy %s to %s\n" % (path, newpath)) |
|
1225 |
util.copyfiles(path, newpath) |
|
1226 |
if opts['empty']: |
|
1227 |
try: |
|
1852
fdf9cbf56ec7
Fix mq's usage of opener, which don't allow absolute paths now.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1839
diff
changeset
|
1228 |
os.unlink(os.path.join(q.path, q.status_path)) |
1808 | 1229 |
except: |
1230 |
pass |
|
1231 |
return 0 |
|
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1232 |
|
1808 | 1233 |
def strip(ui, repo, rev, **opts): |
1234 |
"""strip a revision and all later revs on the same branch""" |
|
1235 |
rev = repo.lookup(rev) |
|
1236 |
backup = 'all' |
|
1237 |
if opts['backup']: |
|
1238 |
backup = 'strip' |
|
1239 |
elif opts['nobackup']: |
|
1240 |
backup = 'none' |
|
1241 |
repomap[repo].strip(repo, rev, backup=backup) |
|
1242 |
return 0 |
|
1243 |
||
1244 |
def version(ui, q=None): |
|
1245 |
"""print the version number""" |
|
1246 |
ui.write("mq version %s\n" % versionstr) |
|
1247 |
return 0 |
|
1248 |
||
1249 |
def reposetup(ui, repo): |
|
1250 |
repomap[repo] = queue(ui, repo.join("")) |
|
1251 |
||
1252 |
cmdtable = { |
|
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1253 |
"qapplied": (applied, [], 'hg qapplied [PATCH]'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1254 |
"qcommit|qci": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1255 |
(commit, |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1256 |
commands.table["^commit|ci"][1], |
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1257 |
'hg qcommit [OPTION]... [FILE]...'), |
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1258 |
"^qdiff": (diff, [], 'hg qdiff [FILE]...'), |
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1259 |
"qdelete": (delete, [], 'hg qdelete PATCH'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1260 |
"^qimport": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1261 |
(qimport, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1262 |
[('e', 'existing', None, 'import file in patch dir'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1263 |
('n', 'name', '', 'patch file name'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1264 |
('f', 'force', None, 'overwrite existing files')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1265 |
'hg qimport [-e] [-n NAME] [-f] FILE...'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1266 |
"^qinit": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1267 |
(init, |
2526
37785f986260
mq: Added help for qcommit, consistently talk about queue repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2488
diff
changeset
|
1268 |
[('c', 'create-repo', None, 'create queue repository')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1269 |
'hg qinit [-c]'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1270 |
"qnew": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1271 |
(new, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1272 |
[('m', 'message', '', 'commit message'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1273 |
('f', 'force', None, 'force')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1274 |
'hg qnew [-m TEXT] [-f] PATCH'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1275 |
"qnext": (next, [], 'hg qnext'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1276 |
"qprev": (prev, [], 'hg qprev'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1277 |
"^qpop": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1278 |
(pop, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1279 |
[('a', 'all', None, 'pop all patches'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1280 |
('n', 'name', '', 'queue name to pop'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1281 |
('f', 'force', None, 'forget any local changes')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1282 |
'hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1283 |
"^qpush": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1284 |
(push, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1285 |
[('f', 'force', None, 'apply if the patch has rejects'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1286 |
('l', 'list', None, 'list patch name in commit text'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1287 |
('a', 'all', None, 'apply all patches'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1288 |
('m', 'merge', None, 'merge from another queue'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1289 |
('n', 'name', '', 'merge queue name')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1290 |
'hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1291 |
"^qrefresh": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1292 |
(refresh, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1293 |
[('s', 'short', None, 'short refresh')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1294 |
'hg qrefresh [-s]'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1295 |
"qrestore": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1296 |
(restore, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1297 |
[('d', 'delete', None, 'delete save entry'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1298 |
('u', 'update', None, 'update queue working dir')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1299 |
'hg qrestore [-d] [-u] REV'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1300 |
"qsave": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1301 |
(save, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1302 |
[('m', 'message', '', 'commit message'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1303 |
('c', 'copy', None, 'copy patch directory'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1304 |
('n', 'name', '', 'copy directory name'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1305 |
('e', 'empty', None, 'clear queue status file'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1306 |
('f', 'force', None, 'force copy')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1307 |
'hg qsave [-m TEXT] [-c] [-n NAME] [-e] [-f]'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1308 |
"qseries": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1309 |
(series, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1310 |
[('m', 'missing', None, 'print patches not in series')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1311 |
'hg qseries [-m]'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1312 |
"^strip": |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1313 |
(strip, |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1314 |
[('f', 'force', None, 'force multi-head removal'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1315 |
('b', 'backup', None, 'bundle unrelated changesets'), |
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1316 |
('n', 'nobackup', None, 'no backups')], |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1317 |
'hg strip [-f] [-b] [-n] REV'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1318 |
"qtop": (top, [], 'hg qtop'), |
2185
5acd648770d0
Better help for mq: Corrected synopses, get qcommit options from commands.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2097
diff
changeset
|
1319 |
"qunapplied": (unapplied, [], 'hg qunapplied [PATCH]'), |
1810
7596611ab3d5
Whitespace, tab and formatting cleanups, mainly in mq.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1808
diff
changeset
|
1320 |
"qversion": (version, [], 'hg qversion') |
1808 | 1321 |
} |
1322 |