Mercurial > hg
annotate hgext/record.py @ 6989:32e68ffccbc5
store: pathjoiner default value is os.path.join
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 05 Sep 2008 11:00:07 +0200 |
parents | 98abbcf9fbdf |
children | 6651de7176a0 |
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 # |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
6 # the GNU General Public License, incorporated herein by reference. |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
8 '''interactive change selection during commit or qrefresh''' |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
10 from mercurial.i18n import _ |
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 |
6212 | 13 import copy, cStringIO, errno, operator, 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), |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
100 sum([h.added + h.removed for h in self.hunks]))) |
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 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
189 def addrange(self, (fromstart, fromend, tostart, toend, proc)): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
190 self.fromline = int(fromstart) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
191 self.toline = int(tostart) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
192 self.proc = proc |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
193 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
194 def addcontext(self, context): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
195 if self.hunk: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
196 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
|
197 self.before, self.hunk, context) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
198 self.header.hunks.append(h) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
199 self.stream.append(h) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
200 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
|
201 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
|
202 self.before = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
203 self.hunk = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
204 self.proc = '' |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
205 self.context = context |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
206 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
207 def addhunk(self, hunk): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
208 if self.context: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
209 self.before = self.context |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
210 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
|
211 self.hunk = hunk |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
212 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
213 def newfile(self, hdr): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
214 self.addcontext([]) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
215 h = header(hdr) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
216 self.stream.append(h) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
217 self.header = h |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
218 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
219 def finished(self): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
220 self.addcontext([]) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
221 return self.stream |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
222 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
223 transitions = { |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
224 'file': {'context': addcontext, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
225 'file': newfile, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
226 'hunk': addhunk, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
227 'range': addrange}, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
228 'context': {'file': newfile, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
229 'hunk': addhunk, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
230 'range': addrange}, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
231 'hunk': {'context': addcontext, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
232 'file': newfile, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
233 'range': addrange}, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
234 'range': {'context': addcontext, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
235 'hunk': addhunk}, |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
236 } |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5129
diff
changeset
|
237 |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
238 p = parser() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
239 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
240 state = 'context' |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
241 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
|
242 try: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
243 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
|
244 except KeyError: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
245 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
|
246 (state, newstate)) |
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 return p.finished() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
249 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
250 def filterpatch(ui, chunks): |
5826 | 251 """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
|
252 chunks = list(chunks) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
253 chunks.reverse() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
254 seen = {} |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
255 def consumefile(): |
5826 | 256 """fetch next portion from chunks until a 'header' is seen |
257 NB: header == new-file mark | |
258 """ | |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
259 consumed = [] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
260 while chunks: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
261 if isinstance(chunks[-1], header): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
262 break |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
263 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
264 consumed.append(chunks.pop()) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
265 return consumed |
5826 | 266 |
267 resp_all = [None] # this two are changed from inside prompt, | |
268 resp_file = [None] # so can't be usual variables | |
269 applied = {} # 'filename' -> [] of chunks | |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
270 def prompt(query): |
5826 | 271 """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
|
272 |
5826 | 273 - y/n for the rest of file |
274 - y/n for the rest | |
275 - ? (help) | |
276 - q (quit) | |
277 | |
278 else, input is returned to the caller. | |
279 """ | |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
280 if resp_all[0] is not None: |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
281 return resp_all[0] |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
282 if resp_file[0] is not None: |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
283 return resp_file[0] |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
284 while True: |
5751 | 285 r = (ui.prompt(query + _(' [Ynsfdaq?] '), '(?i)[Ynsfdaq?]?$') |
286 or 'y').lower() | |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
287 if r == '?': |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
288 c = record.__doc__.find('y - record this change') |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
289 for l in record.__doc__[c:].splitlines(): |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
290 if l: ui.write(_(l.strip()), '\n') |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
291 continue |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
292 elif r == 's': |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
293 r = resp_file[0] = 'n' |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
294 elif r == 'f': |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
295 r = resp_file[0] = 'y' |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
296 elif r == 'd': |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
297 r = resp_all[0] = 'n' |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
298 elif r == 'a': |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
299 r = resp_all[0] = 'y' |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
300 elif r == 'q': |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
301 raise util.Abort(_('user quit')) |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
302 return r |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
303 while chunks: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
304 chunk = chunks.pop() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
305 if isinstance(chunk, header): |
5826 | 306 # new-file mark |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
307 resp_file = [None] |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
308 fixoffset = 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
309 hdr = ''.join(chunk.header) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
310 if hdr in seen: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
311 consumefile() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
312 continue |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
313 seen[hdr] = True |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
314 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
|
315 chunk.pretty(ui) |
5285
3ef190234b55
record: change wording of initial per-file prompt
Bryan O'Sullivan <bos@serpentine.com>
parents:
5154
diff
changeset
|
316 r = prompt(_('examine changes to %s?') % |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
317 _(' and ').join(map(repr, chunk.files()))) |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
318 if r == 'y': |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
319 applied[chunk.filename()] = [chunk] |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
320 if chunk.allhunks(): |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
321 applied[chunk.filename()] += consumefile() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
322 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
323 consumefile() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
324 else: |
5826 | 325 # new hunk |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
326 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
|
327 chunk.pretty(ui) |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
328 r = prompt(_('record this change to %r?') % |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
329 chunk.filename()) |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
330 if r == 'y': |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
331 if fixoffset: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
332 chunk = copy.copy(chunk) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
333 chunk.toline += fixoffset |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
334 applied[chunk.filename()].append(chunk) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
335 else: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
336 fixoffset += chunk.removed - chunk.added |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
337 return reduce(operator.add, [h for h in applied.itervalues() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
338 if h[0].special() or len(h) > 1], []) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
339 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
340 def record(ui, repo, *pats, **opts): |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
341 '''interactively select changes to commit |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
342 |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
343 If a list of files is omitted, all changes reported by "hg status" |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
344 will be candidates for recording. |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
345 |
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
|
346 See 'hg help dates' for a list of formats valid for -d/--date. |
1f733c2f0165
Document log date ranges and mention 'hg help dates' for all commands (issue998)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5932
diff
changeset
|
347 |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
348 You will be prompted for whether to record changes to each |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
349 modified file, and for files with multiple changes, for each |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
350 change to use. For each query, the following responses are |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
351 possible: |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
352 |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
353 y - record this change |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
354 n - skip this change |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
355 |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
356 s - skip remaining changes to this file |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
357 f - record remaining changes to this file |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
358 |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
359 d - done, skip remaining changes and files |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
360 a - record all changes to all remaining files |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
361 q - quit, recording no changes |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
362 |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
363 ? - display help''' |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
364 |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
365 def record_committer(ui, repo, pats, opts): |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
366 commands.commit(ui, repo, *pats, **opts) |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
367 |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
368 dorecord(ui, repo, record_committer, *pats, **opts) |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
369 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
370 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
371 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
|
372 '''interactively record a new patch |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
373 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
374 see 'hg help qnew' & 'hg help record' for more information and usage |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
375 ''' |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
376 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
377 try: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
378 mq = extensions.find('mq') |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
379 except KeyError: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
380 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
|
381 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
382 def qrecord_committer(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
|
383 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
|
384 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
385 opts = opts.copy() |
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
386 opts['force'] = True # always 'qnew -f' |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
387 dorecord(ui, repo, qrecord_committer, *pats, **opts) |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
388 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
389 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
390 def dorecord(ui, repo, committer, *pats, **opts): |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
391 if not ui.interactive: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
392 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
|
393 |
6600
b822a379860b
match: stop passing files through commitfunc
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
394 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
|
395 """This is generic record driver. |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
396 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
397 It's job is to interactively filter local changes, and accordingly |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
398 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
|
399 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
|
400 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
401 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
|
402 state is restored to original. |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
403 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
404 In the end we'll record intresting changes, and everything else will be |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
405 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
|
406 """ |
6600
b822a379860b
match: stop passing files through commitfunc
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
407 if match.files(): |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
408 changes = None |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
409 else: |
6760
4faaa0535ea7
status: clean up all users for unknown files
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
410 changes = repo.status(match=match)[:3] |
4faaa0535ea7
status: clean up all users for unknown files
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
411 modified, added, removed = changes |
6600
b822a379860b
match: stop passing files through commitfunc
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
412 match = cmdutil.matchfiles(repo, modified + added + removed) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
413 diffopts = mdiff.diffopts(git=True, nodates=True) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
414 fp = cStringIO.StringIO() |
6602
a57a27b12965
match: remove files argument from patch.diff
Matt Mackall <mpm@selenic.com>
parents:
6600
diff
changeset
|
415 patch.diff(repo, repo.dirstate.parents()[0], match=match, |
a57a27b12965
match: remove files argument from patch.diff
Matt Mackall <mpm@selenic.com>
parents:
6600
diff
changeset
|
416 changes=changes, opts=diffopts, fp=fp) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
417 fp.seek(0) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
418 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
419 # 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
|
420 chunks = filterpatch(ui, parsepatch(fp)) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
421 del fp |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
422 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
423 contenders = {} |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
424 for h in chunks: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
425 try: contenders.update(dict.fromkeys(h.files())) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
426 except AttributeError: pass |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5129
diff
changeset
|
427 |
6600
b822a379860b
match: stop passing files through commitfunc
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
428 newfiles = [f for f in match.files() if f in contenders] |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
429 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
430 if not newfiles: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
431 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
|
432 return 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
433 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
434 if changes is None: |
6600
b822a379860b
match: stop passing files through commitfunc
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
435 match = cmdutil.matchfiles(repo, newfiles) |
6760
4faaa0535ea7
status: clean up all users for unknown files
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
436 changes = repo.status(match=match) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
437 modified = dict.fromkeys(changes[0]) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
438 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
439 # 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
|
440 backups = {} |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
441 backupdir = repo.join('record-backups') |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
442 try: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
443 os.mkdir(backupdir) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
444 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
|
445 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
|
446 raise |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
447 try: |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
448 # backup continues |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
449 for f in newfiles: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
450 if f not in modified: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
451 continue |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
452 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
|
453 dir=backupdir) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
454 os.close(fd) |
6965
98abbcf9fbdf
i18n: mark strings for translation in record extension
Martin Geisler <mg@daimi.au.dk>
parents:
6951
diff
changeset
|
455 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
|
456 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
|
457 backups[f] = tmpname |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
458 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
459 fp = cStringIO.StringIO() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
460 for c in chunks: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
461 if c.filename() in backups: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
462 c.write(fp) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
463 dopatch = fp.tell() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
464 fp.seek(0) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
465 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
466 # 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
|
467 if backups: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
468 hg.revert(repo, repo.dirstate.parents()[0], backups.has_key) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
469 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
470 # 3b. (apply) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
471 if dopatch: |
6950
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
472 try: |
6965
98abbcf9fbdf
i18n: mark strings for translation in record extension
Martin Geisler <mg@daimi.au.dk>
parents:
6951
diff
changeset
|
473 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
|
474 ui.debug(fp.getvalue()) |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
475 patch.internalpatch(fp, ui, 1, repo.root) |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
476 except patch.PatchError, err: |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
477 s = str(err) |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
478 if s: |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
479 raise util.Abort(s) |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
480 else: |
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
481 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
|
482 del fp |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
483 |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
484 # 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
|
485 # 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
|
486 |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
487 # 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
|
488 # 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
|
489 cwd = os.getcwd() |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
490 os.chdir(repo.root) |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
491 try: |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
492 committer(ui, repo, newfiles, opts) |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
493 finally: |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
494 os.chdir(cwd) |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
495 |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
496 return 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
497 finally: |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
498 # 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
|
499 try: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
500 for realname, tmpname in backups.iteritems(): |
6965
98abbcf9fbdf
i18n: mark strings for translation in record extension
Martin Geisler <mg@daimi.au.dk>
parents:
6951
diff
changeset
|
501 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
|
502 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
|
503 os.unlink(tmpname) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
504 os.rmdir(backupdir) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
505 except OSError: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
506 pass |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
507 return cmdutil.commit(ui, repo, recordfunc, pats, opts) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
508 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
509 cmdtable = { |
5040
4f34d9b2568e
Update style of record's cmdtable to match mercurial/commands.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5037
diff
changeset
|
510 "record": |
4f34d9b2568e
Update style of record's cmdtable to match mercurial/commands.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5037
diff
changeset
|
511 (record, |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
512 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
513 # add commit options |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
514 commands.table['^commit|ci'][1], |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
515 |
5040
4f34d9b2568e
Update style of record's cmdtable to match mercurial/commands.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5037
diff
changeset
|
516 _('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
|
517 } |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
518 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
519 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
520 def extsetup(): |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
521 try: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
522 mq = extensions.find('mq') |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
523 except KeyError: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
524 return |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
525 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
526 qcmdtable = { |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
527 "qrecord": |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
528 (qrecord, |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
529 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
530 # add qnew options, except '--force' |
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
531 [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
|
532 |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
533 _('hg qrecord [OPTION]... PATCH [FILE]...')), |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
534 } |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
535 |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
536 cmdtable.update(qcmdtable) |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
537 |