Mercurial > hg
annotate hgext/record.py @ 12543:0788d6194a2c
l10n: churn, color, convert and eol extension done
New status: 1793 messages complete with 306 fuzzies and 799 untranslated.
Transmitted-via: Transifex (www.transifex.net).
author | Christoph <christoph@webvariants.de> |
---|---|
date | Tue, 21 Sep 2010 00:25:25 +0000 |
parents | 00658492e2aa |
children | aa2fe1f52ff4 |
rev | line source |
---|---|
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1 # record.py |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2 # |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
3 # Copyright 2007 Bryan O'Sullivan <bos@serpentine.com> |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8208
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 |
8934
9dda4c73fc3b
extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8894
diff
changeset
|
8 '''commands to interactively select changes for commit/qrefresh''' |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 |
7015
6651de7176a0
i18n, record: improve use of translated docstring in prompts
Martin Geisler <mg@daimi.au.dk>
parents:
6965
diff
changeset
|
10 from mercurial.i18n import gettext, _ |
6212 | 11 from mercurial import cmdutil, commands, extensions, hg, mdiff, patch |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
12 from mercurial import util |
11500
b782a7eb9037
record: removed 'reduce' calls (unsupported by py3k)
Renato Cunha <renatoc@gmail.com>
parents:
11499
diff
changeset
|
13 import copy, cStringIO, errno, os, re, tempfile |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
14 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
15 lines_re = re.compile(r'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
16 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
17 def scanpatch(fp): |
5826 | 18 """like patch.iterhunks, but yield different events |
19 | |
20 - ('file', [header_lines + fromfile + tofile]) | |
21 - ('context', [context_lines]) | |
22 - ('hunk', [hunk_lines]) | |
23 - ('range', (-start,len, +start,len, diffp)) | |
24 """ | |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
25 lr = patch.linereader(fp) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
26 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
27 def scanwhile(first, p): |
5826 | 28 """scan lr while predicate holds""" |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
29 lines = [first] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
30 while True: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
31 line = lr.readline() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
32 if not line: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
33 break |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
34 if p(line): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
35 lines.append(line) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
36 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
37 lr.push(line) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
38 break |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
39 return lines |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
40 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
41 while True: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
42 line = lr.readline() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
43 if not line: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
44 break |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
45 if line.startswith('diff --git a/'): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
46 def notheader(line): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
47 s = line.split(None, 1) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
48 return not s or s[0] not in ('---', 'diff') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
49 header = scanwhile(line, notheader) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
50 fromfile = lr.readline() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
51 if fromfile.startswith('---'): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
52 tofile = lr.readline() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
53 header += [fromfile, tofile] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
54 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
55 lr.push(fromfile) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
56 yield 'file', header |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
57 elif line[0] == ' ': |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
58 yield 'context', scanwhile(line, lambda l: l[0] in ' \\') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
59 elif line[0] in '-+': |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
60 yield 'hunk', scanwhile(line, lambda l: l[0] in '-+\\') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
61 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
62 m = lines_re.match(line) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
63 if m: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
64 yield 'range', m.groups() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
65 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
66 raise patch.PatchError('unknown patch content: %r' % line) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
67 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
68 class header(object): |
5826 | 69 """patch header |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6163
diff
changeset
|
70 |
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6163
diff
changeset
|
71 XXX shoudn't we move this to mercurial/patch.py ? |
5826 | 72 """ |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
73 diff_re = re.compile('diff --git a/(.*) b/(.*)$') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
74 allhunks_re = re.compile('(?:index|new file|deleted file) ') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
75 pretty_re = re.compile('(?:new file|deleted file) ') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
76 special_re = re.compile('(?:index|new|deleted|copy|rename) ') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
77 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
78 def __init__(self, header): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
79 self.header = header |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
80 self.hunks = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
81 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
82 def binary(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
83 for h in self.header: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
84 if h.startswith('index '): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
85 return True |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5129
diff
changeset
|
86 |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
87 def pretty(self, fp): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
88 for h in self.header: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
89 if h.startswith('index '): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
90 fp.write(_('this modifies a binary file (all or nothing)\n')) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
91 break |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
92 if self.pretty_re.match(h): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
93 fp.write(h) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
94 if self.binary(): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
95 fp.write(_('this is a binary file\n')) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
96 break |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
97 if h.startswith('---'): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
98 fp.write(_('%d hunks, %d lines changed\n') % |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
99 (len(self.hunks), |
11728
226a328a7ff3
record: count lines changed as the number of lines added or removed
timeless <timeless@gmail.com>
parents:
11564
diff
changeset
|
100 sum([max(h.added, h.removed) for h in self.hunks]))) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
101 break |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
102 fp.write(h) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
103 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
104 def write(self, fp): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
105 fp.write(''.join(self.header)) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
106 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
107 def allhunks(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
108 for h in self.header: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
109 if self.allhunks_re.match(h): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
110 return True |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
111 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
112 def files(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
113 fromfile, tofile = self.diff_re.match(self.header[0]).groups() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
114 if fromfile == tofile: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
115 return [fromfile] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
116 return [fromfile, tofile] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
117 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
118 def filename(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
119 return self.files()[-1] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
120 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
121 def __repr__(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
122 return '<header %s>' % (' '.join(map(repr, self.files()))) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
123 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
124 def special(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
125 for h in self.header: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
126 if self.special_re.match(h): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
127 return True |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
128 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
129 def countchanges(hunk): |
5826 | 130 """hunk -> (n+,n-)""" |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
131 add = len([h for h in hunk if h[0] == '+']) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
132 rem = len([h for h in hunk if h[0] == '-']) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
133 return add, rem |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
134 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
135 class hunk(object): |
5826 | 136 """patch hunk |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6163
diff
changeset
|
137 |
5826 | 138 XXX shouldn't we merge this with patch.hunk ? |
139 """ | |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
140 maxcontext = 3 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
141 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
142 def __init__(self, header, fromline, toline, proc, before, hunk, after): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
143 def trimcontext(number, lines): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
144 delta = len(lines) - self.maxcontext |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
145 if False and delta > 0: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
146 return number + delta, lines[:self.maxcontext] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
147 return number, lines |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
148 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
149 self.header = header |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
150 self.fromline, self.before = trimcontext(fromline, before) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
151 self.toline, self.after = trimcontext(toline, after) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
152 self.proc = proc |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
153 self.hunk = hunk |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
154 self.added, self.removed = countchanges(self.hunk) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
155 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
156 def write(self, fp): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
157 delta = len(self.before) + len(self.after) |
6949
834f7e069cae
record: take diff lines for lack of trailing newlines into account (issue1282)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6212
diff
changeset
|
158 if self.after and self.after[-1] == '\\ No newline at end of file\n': |
834f7e069cae
record: take diff lines for lack of trailing newlines into account (issue1282)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6212
diff
changeset
|
159 delta -= 1 |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
160 fromlen = delta + self.removed |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
161 tolen = delta + self.added |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
162 fp.write('@@ -%d,%d +%d,%d @@%s\n' % |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
163 (self.fromline, fromlen, self.toline, tolen, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
164 self.proc and (' ' + self.proc))) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
165 fp.write(''.join(self.before + self.hunk + self.after)) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
166 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
167 pretty = write |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
168 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
169 def filename(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
170 return self.header.filename() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
171 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
172 def __repr__(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
173 return '<hunk %r@%d>' % (self.filename(), self.fromline) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
174 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
175 def parsepatch(fp): |
5826 | 176 """patch -> [] of hunks """ |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
177 class parser(object): |
5826 | 178 """patch parsing state machine""" |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
179 def __init__(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
180 self.fromline = 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
181 self.toline = 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
182 self.proc = '' |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
183 self.header = None |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
184 self.context = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
185 self.before = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
186 self.hunk = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
187 self.stream = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
188 |
11499
324cd681fa47
record: tuple parameter unpacking is deprecated in py3k
Renato Cunha <renatoc@gmail.com>
parents:
11238
diff
changeset
|
189 def addrange(self, limits): |
324cd681fa47
record: tuple parameter unpacking is deprecated in py3k
Renato Cunha <renatoc@gmail.com>
parents:
11238
diff
changeset
|
190 fromstart, fromend, tostart, toend, proc = limits |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
191 self.fromline = int(fromstart) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
192 self.toline = int(tostart) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
193 self.proc = proc |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
194 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
195 def addcontext(self, context): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
196 if self.hunk: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
197 h = hunk(self.header, self.fromline, self.toline, self.proc, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
198 self.before, self.hunk, context) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
199 self.header.hunks.append(h) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
200 self.stream.append(h) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
201 self.fromline += len(self.before) + h.removed |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
202 self.toline += len(self.before) + h.added |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
203 self.before = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
204 self.hunk = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
205 self.proc = '' |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
206 self.context = context |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
207 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
208 def addhunk(self, hunk): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
209 if self.context: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
210 self.before = self.context |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
211 self.context = [] |
6949
834f7e069cae
record: take diff lines for lack of trailing newlines into account (issue1282)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6212
diff
changeset
|
212 self.hunk = hunk |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
213 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
214 def newfile(self, hdr): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
215 self.addcontext([]) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
216 h = header(hdr) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
217 self.stream.append(h) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
218 self.header = h |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
219 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
220 def finished(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
221 self.addcontext([]) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
222 return self.stream |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
223 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
224 transitions = { |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
225 'file': {'context': addcontext, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
226 'file': newfile, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
227 'hunk': addhunk, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
228 'range': addrange}, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
229 'context': {'file': newfile, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
230 'hunk': addhunk, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
231 'range': addrange}, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
232 'hunk': {'context': addcontext, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
233 'file': newfile, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
234 'range': addrange}, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
235 'range': {'context': addcontext, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
236 'hunk': addhunk}, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
237 } |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5129
diff
changeset
|
238 |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
239 p = parser() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
240 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
241 state = 'context' |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
242 for newstate, data in scanpatch(fp): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
243 try: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
244 p.transitions[state][newstate](p, data) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
245 except KeyError: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
246 raise patch.PatchError('unhandled transition: %s -> %s' % |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
247 (state, newstate)) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
248 state = newstate |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
249 return p.finished() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
250 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
251 def filterpatch(ui, chunks): |
5826 | 252 """Interactively filter patch chunks into applied-only chunks""" |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
253 chunks = list(chunks) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
254 chunks.reverse() |
8460
d4c545dc6f87
record: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8348
diff
changeset
|
255 seen = set() |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
256 def consumefile(): |
5826 | 257 """fetch next portion from chunks until a 'header' is seen |
258 NB: header == new-file mark | |
259 """ | |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
260 consumed = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
261 while chunks: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
262 if isinstance(chunks[-1], header): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
263 break |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
264 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
265 consumed.append(chunks.pop()) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
266 return consumed |
5826 | 267 |
268 resp_all = [None] # this two are changed from inside prompt, | |
269 resp_file = [None] # so can't be usual variables | |
270 applied = {} # 'filename' -> [] of chunks | |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
271 def prompt(query): |
5826 | 272 """prompt query, and process base inputs |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6163
diff
changeset
|
273 |
5826 | 274 - y/n for the rest of file |
275 - y/n for the rest | |
276 - ? (help) | |
277 - q (quit) | |
278 | |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
279 Returns True/False and sets reps_all and resp_file as |
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
280 appropriate. |
5826 | 281 """ |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
282 if resp_all[0] is not None: |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
283 return resp_all[0] |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
284 if resp_file[0] is not None: |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
285 return resp_file[0] |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
286 while True: |
8259
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
287 resps = _('[Ynsfdaq?]') |
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
288 choices = (_('&Yes, record this change'), |
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
289 _('&No, skip this change'), |
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
290 _('&Skip remaining changes to this file'), |
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
291 _('Record remaining changes to this &file'), |
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
292 _('&Done, skip remaining changes and files'), |
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
293 _('Record &all changes to all remaining files'), |
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
294 _('&Quit, recording no changes'), |
98acfd1d2b08
ui: replace regexp pattern with sequence of choices
Steve Borho <steve@borho.org>
parents:
8225
diff
changeset
|
295 _('&?')) |
9461 | 296 r = ui.promptchoice("%s %s" % (query, resps), choices) |
10694
d7732d2df54a
record: separate each hunk with a blank line
Martin Geisler <mg@lazybytes.net>
parents:
10323
diff
changeset
|
297 ui.write("\n") |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
298 if r == 7: # ? |
7015
6651de7176a0
i18n, record: improve use of translated docstring in prompts
Martin Geisler <mg@daimi.au.dk>
parents:
6965
diff
changeset
|
299 doc = gettext(record.__doc__) |
11236
cfa6a726ef6d
record: better way to find help in docstring
Martin Geisler <mg@aragost.com>
parents:
11235
diff
changeset
|
300 c = doc.find('::') + 2 |
7015
6651de7176a0
i18n, record: improve use of translated docstring in prompts
Martin Geisler <mg@daimi.au.dk>
parents:
6965
diff
changeset
|
301 for l in doc[c:].splitlines(): |
11236
cfa6a726ef6d
record: better way to find help in docstring
Martin Geisler <mg@aragost.com>
parents:
11235
diff
changeset
|
302 if l.startswith(' '): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
303 ui.write(l.strip(), '\n') |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
304 continue |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
305 elif r == 0: # yes |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
306 ret = True |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
307 elif r == 1: # no |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
308 ret = False |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
309 elif r == 2: # Skip |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
310 ret = resp_file[0] = False |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
311 elif r == 3: # file (Record remaining) |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
312 ret = resp_file[0] = True |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
313 elif r == 4: # done, skip remaining |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
314 ret = resp_all[0] = False |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
315 elif r == 5: # all |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
316 ret = resp_all[0] = True |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
317 elif r == 6: # quit |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
318 raise util.Abort(_('user quit')) |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8934
diff
changeset
|
319 return ret |
7910
14ec64d41dad
record: Give user a hint about chunk selection progress
Rocco Rutte <pdmef@gmx.net>
parents:
7754
diff
changeset
|
320 pos, total = 0, len(chunks) - 1 |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
321 while chunks: |
9688
dd5a16ad420e
record: get the right position (account for skipped files)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9602
diff
changeset
|
322 pos = total - len(chunks) + 1 |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
323 chunk = chunks.pop() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
324 if isinstance(chunk, header): |
5826 | 325 # new-file mark |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
326 resp_file = [None] |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
327 fixoffset = 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
328 hdr = ''.join(chunk.header) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
329 if hdr in seen: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
330 consumefile() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
331 continue |
8460
d4c545dc6f87
record: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8348
diff
changeset
|
332 seen.add(hdr) |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
333 if resp_all[0] is None: |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
334 chunk.pretty(ui) |
5285
3ef190234b55
record: change wording of initial per-file prompt
Bryan O'Sullivan <bos@serpentine.com>
parents:
5154
diff
changeset
|
335 r = prompt(_('examine changes to %s?') % |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
336 _(' and ').join(map(repr, chunk.files()))) |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
337 if r: |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
338 applied[chunk.filename()] = [chunk] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
339 if chunk.allhunks(): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
340 applied[chunk.filename()] += consumefile() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
341 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
342 consumefile() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
343 else: |
5826 | 344 # new hunk |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
345 if resp_file[0] is None and resp_all[0] is None: |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
346 chunk.pretty(ui) |
7910
14ec64d41dad
record: Give user a hint about chunk selection progress
Rocco Rutte <pdmef@gmx.net>
parents:
7754
diff
changeset
|
347 r = total == 1 and prompt(_('record this change to %r?') % |
7911
0b2561b53069
record: fix indentation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7910
diff
changeset
|
348 chunk.filename()) \ |
0b2561b53069
record: fix indentation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7910
diff
changeset
|
349 or prompt(_('record change %d/%d to %r?') % |
0b2561b53069
record: fix indentation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7910
diff
changeset
|
350 (pos, total, chunk.filename())) |
9837
b13474cd1496
record: handle translated prompt correctly
Martin Geisler <mg@lazybytes.net>
parents:
9710
diff
changeset
|
351 if r: |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
352 if fixoffset: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
353 chunk = copy.copy(chunk) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
354 chunk.toline += fixoffset |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
355 applied[chunk.filename()].append(chunk) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
356 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
357 fixoffset += chunk.removed - chunk.added |
11500
b782a7eb9037
record: removed 'reduce' calls (unsupported by py3k)
Renato Cunha <renatoc@gmail.com>
parents:
11499
diff
changeset
|
358 return sum([h for h in applied.itervalues() |
b782a7eb9037
record: removed 'reduce' calls (unsupported by py3k)
Renato Cunha <renatoc@gmail.com>
parents:
11499
diff
changeset
|
359 if h[0].special() or len(h) > 1], []) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
360 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
361 def record(ui, repo, *pats, **opts): |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
362 '''interactively select changes to commit |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
363 |
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10890
diff
changeset
|
364 If a list of files is omitted, all changes reported by :hg:`status` |
9272
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
365 will be candidates for recording. |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
366 |
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10890
diff
changeset
|
367 See :hg:`help dates` for a list of formats valid for -d/--date. |
6163
1f733c2f0165
Document log date ranges and mention 'hg help dates' for all commands (issue998)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5932
diff
changeset
|
368 |
9272
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
369 You will be prompted for whether to record changes to each |
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
370 modified file, and for files with multiple changes, for each |
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
371 change to use. For each query, the following responses are |
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
372 possible:: |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
373 |
9157
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
374 y - record this change |
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
375 n - skip this change |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
376 |
9157
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
377 s - skip remaining changes to this file |
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
378 f - record remaining changes to this file |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
379 |
9157
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
380 d - done, skip remaining changes and files |
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
381 a - record all changes to all remaining files |
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
382 q - quit, recording no changes |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
383 |
11237
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
384 ? - display help |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
385 |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
386 This command is not available when committing a merge.''' |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
387 |
10323
0aa59f532ef9
record: function variable naming & signature cleanup.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10282
diff
changeset
|
388 dorecord(ui, repo, commands.commit, *pats, **opts) |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
389 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
390 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
391 def qrecord(ui, repo, patch, *pats, **opts): |
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
392 '''interactively record a new patch |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
393 |
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10890
diff
changeset
|
394 See :hg:`help qnew` & :hg:`help record` for more information and |
9272
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
395 usage. |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
396 ''' |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
397 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
398 try: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
399 mq = extensions.find('mq') |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
400 except KeyError: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
401 raise util.Abort(_("'mq' extension not loaded")) |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
402 |
10323
0aa59f532ef9
record: function variable naming & signature cleanup.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10282
diff
changeset
|
403 def committomq(ui, repo, *pats, **opts): |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
404 mq.new(ui, repo, patch, *pats, **opts) |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
405 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
406 opts = opts.copy() |
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
407 opts['force'] = True # always 'qnew -f' |
10323
0aa59f532ef9
record: function variable naming & signature cleanup.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10282
diff
changeset
|
408 dorecord(ui, repo, committomq, *pats, **opts) |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
409 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
410 |
10323
0aa59f532ef9
record: function variable naming & signature cleanup.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10282
diff
changeset
|
411 def dorecord(ui, repo, commitfunc, *pats, **opts): |
8208
32a2a1e244f1
ui: make interactive a method
Matt Mackall <mpm@selenic.com>
parents:
8152
diff
changeset
|
412 if not ui.interactive(): |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
413 raise util.Abort(_('running non-interactively, use commit instead')) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
414 |
6600
b822a379860b
match: stop passing files through commitfunc
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
415 def recordfunc(ui, repo, message, match, opts): |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
416 """This is generic record driver. |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
417 |
9087 | 418 Its job is to interactively filter local changes, and accordingly |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
419 prepare working dir into a state, where the job can be delegated to |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
420 non-interactive commit command such as 'commit' or 'qrefresh'. |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
421 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
422 After the actual job is done by non-interactive command, working dir |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
423 state is restored to original. |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
424 |
11235
113536751190
record: docstring typo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10323
diff
changeset
|
425 In the end we'll record interesting changes, and everything else will be |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
426 left in place, so the user can continue his work. |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
427 """ |
7754
ab00d2c281a8
record: minimize number of status calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7718
diff
changeset
|
428 |
11237
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
429 merge = len(repo[None].parents()) > 1 |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
430 if merge: |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
431 raise util.Abort(_('cannot partially commit a merge ' |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
432 '(use hg commit instead)')) |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
433 |
7754
ab00d2c281a8
record: minimize number of status calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7718
diff
changeset
|
434 changes = repo.status(match=match)[:3] |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
435 diffopts = mdiff.diffopts(git=True, nodates=True) |
7754
ab00d2c281a8
record: minimize number of status calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7718
diff
changeset
|
436 chunks = patch.diff(repo, changes=changes, opts=diffopts) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
437 fp = cStringIO.StringIO() |
7308
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7015
diff
changeset
|
438 fp.write(''.join(chunks)) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
439 fp.seek(0) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
440 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
441 # 1. filter patch, so we have intending-to apply subset of it |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
442 chunks = filterpatch(ui, parsepatch(fp)) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
443 del fp |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
444 |
8152
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
7983
diff
changeset
|
445 contenders = set() |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
446 for h in chunks: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
447 try: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
448 contenders.update(set(h.files())) |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
449 except AttributeError: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
450 pass |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5129
diff
changeset
|
451 |
7754
ab00d2c281a8
record: minimize number of status calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7718
diff
changeset
|
452 changed = changes[0] + changes[1] + changes[2] |
ab00d2c281a8
record: minimize number of status calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7718
diff
changeset
|
453 newfiles = [f for f in changed if f in contenders] |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
454 if not newfiles: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
455 ui.status(_('no changes to record\n')) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
456 return 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
457 |
8152
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
7983
diff
changeset
|
458 modified = set(changes[0]) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
459 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
460 # 2. backup changed files, so we can restore them in the end |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
461 backups = {} |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
462 backupdir = repo.join('record-backups') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
463 try: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
464 os.mkdir(backupdir) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
465 except OSError, err: |
5129
eca5b31cffc7
record: raise an exception correctly if we can't create a backup directory
Bryan O'Sullivan <bos@serpentine.com>
parents:
5128
diff
changeset
|
466 if err.errno != errno.EEXIST: |
eca5b31cffc7
record: raise an exception correctly if we can't create a backup directory
Bryan O'Sullivan <bos@serpentine.com>
parents:
5128
diff
changeset
|
467 raise |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
468 try: |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
469 # backup continues |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
470 for f in newfiles: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
471 if f not in modified: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
472 continue |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
473 fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.', |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
474 dir=backupdir) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
475 os.close(fd) |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9272
diff
changeset
|
476 ui.debug('backup %r as %r\n' % (f, tmpname)) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
477 util.copyfile(repo.wjoin(f), tmpname) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
478 backups[f] = tmpname |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
479 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
480 fp = cStringIO.StringIO() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
481 for c in chunks: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
482 if c.filename() in backups: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
483 c.write(fp) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
484 dopatch = fp.tell() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
485 fp.seek(0) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
486 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
487 # 3a. apply filtered patch to clean repo (clean) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
488 if backups: |
11564
9bbfeba33aa3
record: removed 'has_key' usage
Renato Cunha <renatoc@gmail.com>
parents:
11500
diff
changeset
|
489 hg.revert(repo, repo.dirstate.parents()[0], |
9bbfeba33aa3
record: removed 'has_key' usage
Renato Cunha <renatoc@gmail.com>
parents:
11500
diff
changeset
|
490 lambda key: key in backups) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
491 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
492 # 3b. (apply) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
493 if dopatch: |
6950
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
494 try: |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9272
diff
changeset
|
495 ui.debug('applying patch\n') |
6950
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
496 ui.debug(fp.getvalue()) |
7718
6fa7b6fb90a9
record: do not lose permission changes on commit
Steve Borho <steve@borho.org>
parents:
7308
diff
changeset
|
497 pfiles = {} |
8811
8b35b08724eb
Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
8460
diff
changeset
|
498 patch.internalpatch(fp, ui, 1, repo.root, files=pfiles, |
8b35b08724eb
Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
8460
diff
changeset
|
499 eolmode=None) |
12266
00658492e2aa
patch: break import cycle with cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
11728
diff
changeset
|
500 cmdutil.updatedir(ui, repo, pfiles) |
6950
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
501 except patch.PatchError, err: |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
502 s = str(err) |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
503 if s: |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
504 raise util.Abort(s) |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
505 else: |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
506 raise util.Abort(_('patch failed to apply')) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
507 del fp |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
508 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
509 # 4. We prepared working directory according to filtered patch. |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
510 # Now is the time to delegate the job to commit/qrefresh or the like! |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
511 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
512 # it is important to first chdir to repo root -- we'll call a |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
513 # highlevel command with list of pathnames relative to repo root |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
514 cwd = os.getcwd() |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
515 os.chdir(repo.root) |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
516 try: |
10323
0aa59f532ef9
record: function variable naming & signature cleanup.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10282
diff
changeset
|
517 commitfunc(ui, repo, *newfiles, **opts) |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
518 finally: |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
519 os.chdir(cwd) |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
520 |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
521 return 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
522 finally: |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
523 # 5. finally restore backed-up files |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
524 try: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
525 for realname, tmpname in backups.iteritems(): |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9272
diff
changeset
|
526 ui.debug('restoring %r to %r\n' % (tmpname, realname)) |
5128
c9126c24e098
record: work properly if invoked in a subdirectory
Bryan O'Sullivan <bos@serpentine.com>
parents:
5040
diff
changeset
|
527 util.copyfile(tmpname, repo.wjoin(realname)) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
528 os.unlink(tmpname) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
529 os.rmdir(backupdir) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
530 except OSError: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
531 pass |
10825
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
532 |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
533 # wrap ui.write so diff output can be labeled/colorized |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
534 def wrapwrite(orig, *args, **kw): |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
535 label = kw.pop('label', '') |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
536 for chunk, l in patch.difflabel(lambda: args): |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
537 orig(chunk, label=label + l) |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
538 oldwrite = ui.write |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
539 extensions.wrapfunction(ui, 'write', wrapwrite) |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
540 try: |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
541 return cmdutil.commit(ui, repo, recordfunc, pats, opts) |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
542 finally: |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
543 ui.write = oldwrite |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
544 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
545 cmdtable = { |
5040
4f34d9b2568e
Update style of record's cmdtable to match mercurial/commands.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5037
diff
changeset
|
546 "record": |
4f34d9b2568e
Update style of record's cmdtable to match mercurial/commands.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5037
diff
changeset
|
547 (record, |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
548 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
549 # add commit options |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
550 commands.table['^commit|ci'][1], |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
551 |
5040
4f34d9b2568e
Update style of record's cmdtable to match mercurial/commands.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5037
diff
changeset
|
552 _('hg record [OPTION]... [FILE]...')), |
4f34d9b2568e
Update style of record's cmdtable to match mercurial/commands.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5037
diff
changeset
|
553 } |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
554 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
555 |
9710
1765599f4899
record: use uisetup instead of extsetup to register qrecord
Martin Geisler <mg@lazybytes.net>
parents:
9688
diff
changeset
|
556 def uisetup(ui): |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
557 try: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
558 mq = extensions.find('mq') |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
559 except KeyError: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
560 return |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
561 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
562 qcmdtable = { |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
563 "qrecord": |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
564 (qrecord, |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
565 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
566 # add qnew options, except '--force' |
10890
301633755dec
mq: promote qnew, demote qinit in short help
Matt Mackall <mpm@selenic.com>
parents:
10825
diff
changeset
|
567 [opt for opt in mq.cmdtable['^qnew'][1] if opt[1] != 'force'], |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
568 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
569 _('hg qrecord [OPTION]... PATCH [FILE]...')), |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
570 } |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
571 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
572 cmdtable.update(qcmdtable) |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
573 |