Show More
@@ -1,476 +1,478 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # |
|
3 | 3 | # check-code - a style and portability checker for Mercurial |
|
4 | 4 | # |
|
5 | 5 | # Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
6 | 6 | # |
|
7 | 7 | # This software may be used and distributed according to the terms of the |
|
8 | 8 | # GNU General Public License version 2 or any later version. |
|
9 | 9 | |
|
10 | 10 | import re, glob, os, sys |
|
11 | 11 | import keyword |
|
12 | 12 | import optparse |
|
13 | 13 | |
|
14 | 14 | def repquote(m): |
|
15 | 15 | t = re.sub(r"\w", "x", m.group('text')) |
|
16 | 16 | t = re.sub(r"[^\s\nx]", "o", t) |
|
17 | 17 | return m.group('quote') + t + m.group('quote') |
|
18 | 18 | |
|
19 | 19 | def reppython(m): |
|
20 | 20 | comment = m.group('comment') |
|
21 | 21 | if comment: |
|
22 | 22 | l = len(comment.rstrip()) |
|
23 | 23 | return "#" * l + comment[l:] |
|
24 | 24 | return repquote(m) |
|
25 | 25 | |
|
26 | 26 | def repcomment(m): |
|
27 | 27 | return m.group(1) + "#" * len(m.group(2)) |
|
28 | 28 | |
|
29 | 29 | def repccomment(m): |
|
30 | 30 | t = re.sub(r"((?<=\n) )|\S", "x", m.group(2)) |
|
31 | 31 | return m.group(1) + t + "*/" |
|
32 | 32 | |
|
33 | 33 | def repcallspaces(m): |
|
34 | 34 | t = re.sub(r"\n\s+", "\n", m.group(2)) |
|
35 | 35 | return m.group(1) + t |
|
36 | 36 | |
|
37 | 37 | def repinclude(m): |
|
38 | 38 | return m.group(1) + "<foo>" |
|
39 | 39 | |
|
40 | 40 | def rephere(m): |
|
41 | 41 | t = re.sub(r"\S", "x", m.group(2)) |
|
42 | 42 | return m.group(1) + t |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | testpats = [ |
|
46 | 46 | [ |
|
47 | 47 | (r'pushd|popd', "don't use 'pushd' or 'popd', use 'cd'"), |
|
48 | 48 | (r'\W\$?\(\([^\)\n]*\)\)', "don't use (()) or $(()), use 'expr'"), |
|
49 | 49 | (r'grep.*-q', "don't use 'grep -q', redirect to /dev/null"), |
|
50 | 50 | (r'sed.*-i', "don't use 'sed -i', use a temporary file"), |
|
51 | 51 | (r'\becho\b.*\\n', "don't use 'echo \\n', use printf"), |
|
52 | 52 | (r'echo -n', "don't use 'echo -n', use printf"), |
|
53 | 53 | (r'(^| )wc[^|]*$\n(?!.*\(re\))', "filter wc output"), |
|
54 | 54 | (r'head -c', "don't use 'head -c', use 'dd'"), |
|
55 | 55 | (r'sha1sum', "don't use sha1sum, use $TESTDIR/md5sum.py"), |
|
56 | 56 | (r'ls.*-\w*R', "don't use 'ls -R', use 'find'"), |
|
57 | 57 | (r'printf.*\\([1-9]|0\d)', "don't use 'printf \NNN', use Python"), |
|
58 | 58 | (r'printf.*\\x', "don't use printf \\x, use Python"), |
|
59 | 59 | (r'\$\(.*\)', "don't use $(expr), use `expr`"), |
|
60 | 60 | (r'rm -rf \*', "don't use naked rm -rf, target a directory"), |
|
61 | 61 | (r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w', |
|
62 | 62 | "use egrep for extended grep syntax"), |
|
63 | 63 | (r'/bin/', "don't use explicit paths for tools"), |
|
64 | 64 | (r'[^\n]\Z', "no trailing newline"), |
|
65 | 65 | (r'export.*=', "don't export and assign at once"), |
|
66 | 66 | (r'^source\b', "don't use 'source', use '.'"), |
|
67 | 67 | (r'touch -d', "don't use 'touch -d', use 'touch -t' instead"), |
|
68 | 68 | (r'ls +[^|\n-]+ +-', "options to 'ls' must come before filenames"), |
|
69 | 69 | (r'[^>\n]>\s*\$HGRCPATH', "don't overwrite $HGRCPATH, append to it"), |
|
70 | 70 | (r'^stop\(\)', "don't use 'stop' as a shell function name"), |
|
71 | 71 | (r'(\[|\btest\b).*-e ', "don't use 'test -e', use 'test -f'"), |
|
72 | 72 | (r'^alias\b.*=', "don't use alias, use a function"), |
|
73 | 73 | (r'if\s*!', "don't use '!' to negate exit status"), |
|
74 | 74 | (r'/dev/u?random', "don't use entropy, use /dev/zero"), |
|
75 | 75 | (r'do\s*true;\s*done', "don't use true as loop body, use sleep 0"), |
|
76 | 76 | (r'^( *)\t', "don't use tabs to indent"), |
|
77 | (r'sed .*\'/[^/]*/i[^\\][^\n]', | |
|
78 | "put a backslash-escaped newline after sed 'i' command"), | |
|
77 | 79 | ], |
|
78 | 80 | # warnings |
|
79 | 81 | [ |
|
80 | 82 | (r'^function', "don't use 'function', use old style"), |
|
81 | 83 | (r'^diff.*-\w*N', "don't use 'diff -N'"), |
|
82 | 84 | (r'\$PWD|\${PWD}', "don't use $PWD, use `pwd`"), |
|
83 | 85 | (r'^([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\^', "^ must be quoted"), |
|
84 | 86 | (r'kill (`|\$\()', "don't use kill, use killdaemons.py") |
|
85 | 87 | ] |
|
86 | 88 | ] |
|
87 | 89 | |
|
88 | 90 | testfilters = [ |
|
89 | 91 | (r"( *)(#([^\n]*\S)?)", repcomment), |
|
90 | 92 | (r"<<(\S+)((.|\n)*?\n\1)", rephere), |
|
91 | 93 | ] |
|
92 | 94 | |
|
93 | 95 | winglobmsg = "use (glob) to match Windows paths too" |
|
94 | 96 | uprefix = r"^ \$ " |
|
95 | 97 | utestpats = [ |
|
96 | 98 | [ |
|
97 | 99 | (r'^(\S.*|| [$>] .*)[ \t]\n', "trailing whitespace on non-output"), |
|
98 | 100 | (uprefix + r'.*\|\s*sed[^|>\n]*\n', |
|
99 | 101 | "use regex test output patterns instead of sed"), |
|
100 | 102 | (uprefix + r'(true|exit 0)', "explicit zero exit unnecessary"), |
|
101 | 103 | (uprefix + r'.*(?<!\[)\$\?', "explicit exit code checks unnecessary"), |
|
102 | 104 | (uprefix + r'.*\|\| echo.*(fail|error)', |
|
103 | 105 | "explicit exit code checks unnecessary"), |
|
104 | 106 | (uprefix + r'set -e', "don't use set -e"), |
|
105 | 107 | (uprefix + r'\s', "don't indent commands, use > for continued lines"), |
|
106 | 108 | (r'^ saved backup bundle to \$TESTTMP.*\.hg$', winglobmsg), |
|
107 | 109 | (r'^ changeset .* references (corrupted|missing) \$TESTTMP/.*[^)]$', |
|
108 | 110 | winglobmsg), |
|
109 | 111 | (r'^ pulling from \$TESTTMP/.*[^)]$', winglobmsg, '\$TESTTMP/unix-repo$'), |
|
110 | 112 | ], |
|
111 | 113 | # warnings |
|
112 | 114 | [ |
|
113 | 115 | (r'^ [^*?/\n]* \(glob\)$', |
|
114 | 116 | "warning: glob match with no glob character (?*/)"), |
|
115 | 117 | ] |
|
116 | 118 | ] |
|
117 | 119 | |
|
118 | 120 | for i in [0, 1]: |
|
119 | 121 | for p, m in testpats[i]: |
|
120 | 122 | if p.startswith(r'^'): |
|
121 | 123 | p = r"^ [$>] (%s)" % p[1:] |
|
122 | 124 | else: |
|
123 | 125 | p = r"^ [$>] .*(%s)" % p |
|
124 | 126 | utestpats[i].append((p, m)) |
|
125 | 127 | |
|
126 | 128 | utestfilters = [ |
|
127 | 129 | (r"<<(\S+)((.|\n)*?\n > \1)", rephere), |
|
128 | 130 | (r"( *)(#([^\n]*\S)?)", repcomment), |
|
129 | 131 | ] |
|
130 | 132 | |
|
131 | 133 | pypats = [ |
|
132 | 134 | [ |
|
133 | 135 | (r'^\s*def\s*\w+\s*\(.*,\s*\(', |
|
134 | 136 | "tuple parameter unpacking not available in Python 3+"), |
|
135 | 137 | (r'lambda\s*\(.*,.*\)', |
|
136 | 138 | "tuple parameter unpacking not available in Python 3+"), |
|
137 | 139 | (r'(?<!def)\s+(cmp)\(', "cmp is not available in Python 3+"), |
|
138 | 140 | (r'\breduce\s*\(.*', "reduce is not available in Python 3+"), |
|
139 | 141 | (r'\.has_key\b', "dict.has_key is not available in Python 3+"), |
|
140 | 142 | (r'\s<>\s', '<> operator is not available in Python 3+, use !='), |
|
141 | 143 | (r'^\s*\t', "don't use tabs"), |
|
142 | 144 | (r'\S;\s*\n', "semicolon"), |
|
143 | 145 | (r'[^_]_\("[^"]+"\s*%', "don't use % inside _()"), |
|
144 | 146 | (r"[^_]_\('[^']+'\s*%", "don't use % inside _()"), |
|
145 | 147 | (r'(\w|\)),\w', "missing whitespace after ,"), |
|
146 | 148 | (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"), |
|
147 | 149 | (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"), |
|
148 | 150 | (r'(\s+)try:\n((?:\n|\1\s.*\n)+?)\1except.*?:\n' |
|
149 | 151 | r'((?:\n|\1\s.*\n)+?)\1finally:', 'no try/except/finally in Python 2.4'), |
|
150 | 152 | (r'(\s+)try:\n((?:\n|\1\s.*\n)*?)\1\s*yield\b.*?' |
|
151 | 153 | r'((?:\n|\1\s.*\n)+?)\1finally:', |
|
152 | 154 | 'no yield inside try/finally in Python 2.4'), |
|
153 | 155 | (r'.{81}', "line too long"), |
|
154 | 156 | (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'), |
|
155 | 157 | (r'[^\n]\Z', "no trailing newline"), |
|
156 | 158 | (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), |
|
157 | 159 | # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', |
|
158 | 160 | # "don't use underbars in identifiers"), |
|
159 | 161 | (r'^\s+(self\.)?[A-za-z][a-z0-9]+[A-Z]\w* = ', |
|
160 | 162 | "don't use camelcase in identifiers"), |
|
161 | 163 | (r'^\s*(if|while|def|class|except|try)\s[^[\n]*:\s*[^\\n]#\s]+', |
|
162 | 164 | "linebreak after :"), |
|
163 | 165 | (r'class\s[^( \n]+:', "old-style class, use class foo(object)"), |
|
164 | 166 | (r'class\s[^( \n]+\(\):', |
|
165 | 167 | "class foo() not available in Python 2.4, use class foo(object)"), |
|
166 | 168 | (r'\b(%s)\(' % '|'.join(keyword.kwlist), |
|
167 | 169 | "Python keyword is not a function"), |
|
168 | 170 | (r',]', "unneeded trailing ',' in list"), |
|
169 | 171 | # (r'class\s[A-Z][^\(]*\((?!Exception)', |
|
170 | 172 | # "don't capitalize non-exception classes"), |
|
171 | 173 | # (r'in range\(', "use xrange"), |
|
172 | 174 | # (r'^\s*print\s+', "avoid using print in core and extensions"), |
|
173 | 175 | (r'[\x80-\xff]', "non-ASCII character literal"), |
|
174 | 176 | (r'("\')\.format\(', "str.format() not available in Python 2.4"), |
|
175 | 177 | (r'^\s*with\s+', "with not available in Python 2.4"), |
|
176 | 178 | (r'\.isdisjoint\(', "set.isdisjoint not available in Python 2.4"), |
|
177 | 179 | (r'^\s*except.* as .*:', "except as not available in Python 2.4"), |
|
178 | 180 | (r'^\s*os\.path\.relpath', "relpath not available in Python 2.4"), |
|
179 | 181 | (r'(?<!def)\s+(any|all|format)\(', |
|
180 | 182 | "any/all/format not available in Python 2.4"), |
|
181 | 183 | (r'(?<!def)\s+(callable)\(', |
|
182 | 184 | "callable not available in Python 3, use getattr(f, '__call__', None)"), |
|
183 | 185 | (r'if\s.*\selse', "if ... else form not available in Python 2.4"), |
|
184 | 186 | (r'^\s*(%s)\s\s' % '|'.join(keyword.kwlist), |
|
185 | 187 | "gratuitous whitespace after Python keyword"), |
|
186 | 188 | (r'([\(\[][ \t]\S)|(\S[ \t][\)\]])', "gratuitous whitespace in () or []"), |
|
187 | 189 | # (r'\s\s=', "gratuitous whitespace before ="), |
|
188 | 190 | (r'[^>< ](\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\S', |
|
189 | 191 | "missing whitespace around operator"), |
|
190 | 192 | (r'[^>< ](\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\s', |
|
191 | 193 | "missing whitespace around operator"), |
|
192 | 194 | (r'\s(\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\S', |
|
193 | 195 | "missing whitespace around operator"), |
|
194 | 196 | (r'[^^+=*/!<>&| %-](\s=|=\s)[^= ]', |
|
195 | 197 | "wrong whitespace around ="), |
|
196 | 198 | (r'raise Exception', "don't raise generic exceptions"), |
|
197 | 199 | (r'raise [^,(]+, (\([^\)]+\)|[^,\(\)]+)$', |
|
198 | 200 | "don't use old-style two-argument raise, use Exception(message)"), |
|
199 | 201 | (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"), |
|
200 | 202 | (r' [=!]=\s+(True|False|None)', |
|
201 | 203 | "comparison with singleton, use 'is' or 'is not' instead"), |
|
202 | 204 | (r'^\s*(while|if) [01]:', |
|
203 | 205 | "use True/False for constant Boolean expression"), |
|
204 | 206 | (r'(?:(?<!def)\s+|\()hasattr', |
|
205 | 207 | 'hasattr(foo, bar) is broken, use util.safehasattr(foo, bar) instead'), |
|
206 | 208 | (r'opener\([^)]*\).read\(', |
|
207 | 209 | "use opener.read() instead"), |
|
208 | 210 | (r'BaseException', 'not in Python 2.4, use Exception'), |
|
209 | 211 | (r'os\.path\.relpath', 'os.path.relpath is not in Python 2.5'), |
|
210 | 212 | (r'opener\([^)]*\).write\(', |
|
211 | 213 | "use opener.write() instead"), |
|
212 | 214 | (r'[\s\(](open|file)\([^)]*\)\.read\(', |
|
213 | 215 | "use util.readfile() instead"), |
|
214 | 216 | (r'[\s\(](open|file)\([^)]*\)\.write\(', |
|
215 | 217 | "use util.readfile() instead"), |
|
216 | 218 | (r'^[\s\(]*(open(er)?|file)\([^)]*\)', |
|
217 | 219 | "always assign an opened file to a variable, and close it afterwards"), |
|
218 | 220 | (r'[\s\(](open|file)\([^)]*\)\.', |
|
219 | 221 | "always assign an opened file to a variable, and close it afterwards"), |
|
220 | 222 | (r'(?i)descendent', "the proper spelling is descendAnt"), |
|
221 | 223 | (r'\.debug\(\_', "don't mark debug messages for translation"), |
|
222 | 224 | (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"), |
|
223 | 225 | (r'^\s*except\s*:', "naked except clause", r'#.*re-raises'), |
|
224 | 226 | (r':\n( )*( ){1,3}[^ ]', "must indent 4 spaces"), |
|
225 | 227 | (r'ui\.(status|progress|write|note|warn)\([\'\"]x', |
|
226 | 228 | "missing _() in ui message (use () to hide false-positives)"), |
|
227 | 229 | (r'release\(.*wlock, .*lock\)', "wrong lock release order"), |
|
228 | 230 | ], |
|
229 | 231 | # warnings |
|
230 | 232 | [ |
|
231 | 233 | ] |
|
232 | 234 | ] |
|
233 | 235 | |
|
234 | 236 | pyfilters = [ |
|
235 | 237 | (r"""(?msx)(?P<comment>\#.*?$)| |
|
236 | 238 | ((?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!"))) |
|
237 | 239 | (?P<text>(([^\\]|\\.)*?)) |
|
238 | 240 | (?P=quote))""", reppython), |
|
239 | 241 | ] |
|
240 | 242 | |
|
241 | 243 | txtfilters = [] |
|
242 | 244 | |
|
243 | 245 | txtpats = [ |
|
244 | 246 | [ |
|
245 | 247 | ('\s$', 'trailing whitespace'), |
|
246 | 248 | ], |
|
247 | 249 | [] |
|
248 | 250 | ] |
|
249 | 251 | |
|
250 | 252 | cpats = [ |
|
251 | 253 | [ |
|
252 | 254 | (r'//', "don't use //-style comments"), |
|
253 | 255 | (r'^ ', "don't use spaces to indent"), |
|
254 | 256 | (r'\S\t', "don't use tabs except for indent"), |
|
255 | 257 | (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), |
|
256 | 258 | (r'.{81}', "line too long"), |
|
257 | 259 | (r'(while|if|do|for)\(', "use space after while/if/do/for"), |
|
258 | 260 | (r'return\(', "return is not a function"), |
|
259 | 261 | (r' ;', "no space before ;"), |
|
260 | 262 | (r'\w+\* \w+', "use int *foo, not int* foo"), |
|
261 | 263 | (r'\([^\)]+\) \w+', "use (int)foo, not (int) foo"), |
|
262 | 264 | (r'\w+ (\+\+|--)', "use foo++, not foo ++"), |
|
263 | 265 | (r'\w,\w', "missing whitespace after ,"), |
|
264 | 266 | (r'^[^#]\w[+/*]\w', "missing whitespace in expression"), |
|
265 | 267 | (r'^#\s+\w', "use #foo, not # foo"), |
|
266 | 268 | (r'[^\n]\Z', "no trailing newline"), |
|
267 | 269 | (r'^\s*#import\b', "use only #include in standard C code"), |
|
268 | 270 | ], |
|
269 | 271 | # warnings |
|
270 | 272 | [] |
|
271 | 273 | ] |
|
272 | 274 | |
|
273 | 275 | cfilters = [ |
|
274 | 276 | (r'(/\*)(((\*(?!/))|[^*])*)\*/', repccomment), |
|
275 | 277 | (r'''(?P<quote>(?<!")")(?P<text>([^"]|\\")+)"(?!")''', repquote), |
|
276 | 278 | (r'''(#\s*include\s+<)([^>]+)>''', repinclude), |
|
277 | 279 | (r'(\()([^)]+\))', repcallspaces), |
|
278 | 280 | ] |
|
279 | 281 | |
|
280 | 282 | inutilpats = [ |
|
281 | 283 | [ |
|
282 | 284 | (r'\bui\.', "don't use ui in util"), |
|
283 | 285 | ], |
|
284 | 286 | # warnings |
|
285 | 287 | [] |
|
286 | 288 | ] |
|
287 | 289 | |
|
288 | 290 | inrevlogpats = [ |
|
289 | 291 | [ |
|
290 | 292 | (r'\brepo\.', "don't use repo in revlog"), |
|
291 | 293 | ], |
|
292 | 294 | # warnings |
|
293 | 295 | [] |
|
294 | 296 | ] |
|
295 | 297 | |
|
296 | 298 | checks = [ |
|
297 | 299 | ('python', r'.*\.(py|cgi)$', pyfilters, pypats), |
|
298 | 300 | ('test script', r'(.*/)?test-[^.~]*$', testfilters, testpats), |
|
299 | 301 | ('c', r'.*\.c$', cfilters, cpats), |
|
300 | 302 | ('unified test', r'.*\.t$', utestfilters, utestpats), |
|
301 | 303 | ('layering violation repo in revlog', r'mercurial/revlog\.py', pyfilters, |
|
302 | 304 | inrevlogpats), |
|
303 | 305 | ('layering violation ui in util', r'mercurial/util\.py', pyfilters, |
|
304 | 306 | inutilpats), |
|
305 | 307 | ('txt', r'.*\.txt$', txtfilters, txtpats), |
|
306 | 308 | ] |
|
307 | 309 | |
|
308 | 310 | class norepeatlogger(object): |
|
309 | 311 | def __init__(self): |
|
310 | 312 | self._lastseen = None |
|
311 | 313 | |
|
312 | 314 | def log(self, fname, lineno, line, msg, blame): |
|
313 | 315 | """print error related a to given line of a given file. |
|
314 | 316 | |
|
315 | 317 | The faulty line will also be printed but only once in the case |
|
316 | 318 | of multiple errors. |
|
317 | 319 | |
|
318 | 320 | :fname: filename |
|
319 | 321 | :lineno: line number |
|
320 | 322 | :line: actual content of the line |
|
321 | 323 | :msg: error message |
|
322 | 324 | """ |
|
323 | 325 | msgid = fname, lineno, line |
|
324 | 326 | if msgid != self._lastseen: |
|
325 | 327 | if blame: |
|
326 | 328 | print "%s:%d (%s):" % (fname, lineno, blame) |
|
327 | 329 | else: |
|
328 | 330 | print "%s:%d:" % (fname, lineno) |
|
329 | 331 | print " > %s" % line |
|
330 | 332 | self._lastseen = msgid |
|
331 | 333 | print " " + msg |
|
332 | 334 | |
|
333 | 335 | _defaultlogger = norepeatlogger() |
|
334 | 336 | |
|
335 | 337 | def getblame(f): |
|
336 | 338 | lines = [] |
|
337 | 339 | for l in os.popen('hg annotate -un %s' % f): |
|
338 | 340 | start, line = l.split(':', 1) |
|
339 | 341 | user, rev = start.split() |
|
340 | 342 | lines.append((line[1:-1], user, rev)) |
|
341 | 343 | return lines |
|
342 | 344 | |
|
343 | 345 | def checkfile(f, logfunc=_defaultlogger.log, maxerr=None, warnings=False, |
|
344 | 346 | blame=False, debug=False, lineno=True): |
|
345 | 347 | """checks style and portability of a given file |
|
346 | 348 | |
|
347 | 349 | :f: filepath |
|
348 | 350 | :logfunc: function used to report error |
|
349 | 351 | logfunc(filename, linenumber, linecontent, errormessage) |
|
350 | 352 | :maxerr: number of error to display before aborting. |
|
351 | 353 | Set to false (default) to report all errors |
|
352 | 354 | |
|
353 | 355 | return True if no error is found, False otherwise. |
|
354 | 356 | """ |
|
355 | 357 | blamecache = None |
|
356 | 358 | result = True |
|
357 | 359 | for name, match, filters, pats in checks: |
|
358 | 360 | if debug: |
|
359 | 361 | print name, f |
|
360 | 362 | fc = 0 |
|
361 | 363 | if not re.match(match, f): |
|
362 | 364 | if debug: |
|
363 | 365 | print "Skipping %s for %s it doesn't match %s" % ( |
|
364 | 366 | name, match, f) |
|
365 | 367 | continue |
|
366 | 368 | fp = open(f) |
|
367 | 369 | pre = post = fp.read() |
|
368 | 370 | fp.close() |
|
369 | 371 | if "no-" + "check-code" in pre: |
|
370 | 372 | if debug: |
|
371 | 373 | print "Skipping %s for %s it has no- and check-code" % ( |
|
372 | 374 | name, f) |
|
373 | 375 | break |
|
374 | 376 | for p, r in filters: |
|
375 | 377 | post = re.sub(p, r, post) |
|
376 | 378 | if warnings: |
|
377 | 379 | pats = pats[0] + pats[1] |
|
378 | 380 | else: |
|
379 | 381 | pats = pats[0] |
|
380 | 382 | # print post # uncomment to show filtered version |
|
381 | 383 | |
|
382 | 384 | if debug: |
|
383 | 385 | print "Checking %s for %s" % (name, f) |
|
384 | 386 | |
|
385 | 387 | prelines = None |
|
386 | 388 | errors = [] |
|
387 | 389 | for pat in pats: |
|
388 | 390 | if len(pat) == 3: |
|
389 | 391 | p, msg, ignore = pat |
|
390 | 392 | else: |
|
391 | 393 | p, msg = pat |
|
392 | 394 | ignore = None |
|
393 | 395 | |
|
394 | 396 | # fix-up regexes for multi-line searches |
|
395 | 397 | po = p |
|
396 | 398 | # \s doesn't match \n |
|
397 | 399 | p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p) |
|
398 | 400 | # [^...] doesn't match newline |
|
399 | 401 | p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p) |
|
400 | 402 | |
|
401 | 403 | #print po, '=>', p |
|
402 | 404 | |
|
403 | 405 | pos = 0 |
|
404 | 406 | n = 0 |
|
405 | 407 | for m in re.finditer(p, post, re.MULTILINE): |
|
406 | 408 | if prelines is None: |
|
407 | 409 | prelines = pre.splitlines() |
|
408 | 410 | postlines = post.splitlines(True) |
|
409 | 411 | |
|
410 | 412 | start = m.start() |
|
411 | 413 | while n < len(postlines): |
|
412 | 414 | step = len(postlines[n]) |
|
413 | 415 | if pos + step > start: |
|
414 | 416 | break |
|
415 | 417 | pos += step |
|
416 | 418 | n += 1 |
|
417 | 419 | l = prelines[n] |
|
418 | 420 | |
|
419 | 421 | if "check-code" + "-ignore" in l: |
|
420 | 422 | if debug: |
|
421 | 423 | print "Skipping %s for %s:%s (check-code -ignore)" % ( |
|
422 | 424 | name, f, n) |
|
423 | 425 | continue |
|
424 | 426 | elif ignore and re.search(ignore, l, re.MULTILINE): |
|
425 | 427 | continue |
|
426 | 428 | bd = "" |
|
427 | 429 | if blame: |
|
428 | 430 | bd = 'working directory' |
|
429 | 431 | if not blamecache: |
|
430 | 432 | blamecache = getblame(f) |
|
431 | 433 | if n < len(blamecache): |
|
432 | 434 | bl, bu, br = blamecache[n] |
|
433 | 435 | if bl == l: |
|
434 | 436 | bd = '%s@%s' % (bu, br) |
|
435 | 437 | errors.append((f, lineno and n + 1, l, msg, bd)) |
|
436 | 438 | result = False |
|
437 | 439 | |
|
438 | 440 | errors.sort() |
|
439 | 441 | for e in errors: |
|
440 | 442 | logfunc(*e) |
|
441 | 443 | fc += 1 |
|
442 | 444 | if maxerr and fc >= maxerr: |
|
443 | 445 | print " (too many errors, giving up)" |
|
444 | 446 | break |
|
445 | 447 | |
|
446 | 448 | return result |
|
447 | 449 | |
|
448 | 450 | if __name__ == "__main__": |
|
449 | 451 | parser = optparse.OptionParser("%prog [options] [files]") |
|
450 | 452 | parser.add_option("-w", "--warnings", action="store_true", |
|
451 | 453 | help="include warning-level checks") |
|
452 | 454 | parser.add_option("-p", "--per-file", type="int", |
|
453 | 455 | help="max warnings per file") |
|
454 | 456 | parser.add_option("-b", "--blame", action="store_true", |
|
455 | 457 | help="use annotate to generate blame info") |
|
456 | 458 | parser.add_option("", "--debug", action="store_true", |
|
457 | 459 | help="show debug information") |
|
458 | 460 | parser.add_option("", "--nolineno", action="store_false", |
|
459 | 461 | dest='lineno', help="don't show line numbers") |
|
460 | 462 | |
|
461 | 463 | parser.set_defaults(per_file=15, warnings=False, blame=False, debug=False, |
|
462 | 464 | lineno=True) |
|
463 | 465 | (options, args) = parser.parse_args() |
|
464 | 466 | |
|
465 | 467 | if len(args) == 0: |
|
466 | 468 | check = glob.glob("*") |
|
467 | 469 | else: |
|
468 | 470 | check = args |
|
469 | 471 | |
|
470 | 472 | ret = 0 |
|
471 | 473 | for f in check: |
|
472 | 474 | if not checkfile(f, maxerr=options.per_file, warnings=options.warnings, |
|
473 | 475 | blame=options.blame, debug=options.debug, |
|
474 | 476 | lineno=options.lineno): |
|
475 | 477 | ret = 1 |
|
476 | 478 | sys.exit(ret) |
@@ -1,1279 +1,1281 b'' | |||
|
1 | 1 | Set up a repo |
|
2 | 2 | |
|
3 | 3 | $ echo "[ui]" >> $HGRCPATH |
|
4 | 4 | $ echo "interactive=true" >> $HGRCPATH |
|
5 | 5 | $ echo "[extensions]" >> $HGRCPATH |
|
6 | 6 | $ echo "record=" >> $HGRCPATH |
|
7 | 7 | |
|
8 | 8 | $ hg init a |
|
9 | 9 | $ cd a |
|
10 | 10 | |
|
11 | 11 | Select no files |
|
12 | 12 | |
|
13 | 13 | $ touch empty-rw |
|
14 | 14 | $ hg add empty-rw |
|
15 | 15 | |
|
16 | 16 | $ hg record empty-rw<<EOF |
|
17 | 17 | > n |
|
18 | 18 | > EOF |
|
19 | 19 | diff --git a/empty-rw b/empty-rw |
|
20 | 20 | new file mode 100644 |
|
21 | 21 | examine changes to 'empty-rw'? [Ynesfdaq?] |
|
22 | 22 | no changes to record |
|
23 | 23 | |
|
24 | 24 | $ hg tip -p |
|
25 | 25 | changeset: -1:000000000000 |
|
26 | 26 | tag: tip |
|
27 | 27 | user: |
|
28 | 28 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | Select files but no hunks |
|
33 | 33 | |
|
34 | 34 | $ hg record empty-rw<<EOF |
|
35 | 35 | > y |
|
36 | 36 | > n |
|
37 | 37 | > EOF |
|
38 | 38 | diff --git a/empty-rw b/empty-rw |
|
39 | 39 | new file mode 100644 |
|
40 | 40 | examine changes to 'empty-rw'? [Ynesfdaq?] |
|
41 | 41 | abort: empty commit message |
|
42 | 42 | [255] |
|
43 | 43 | |
|
44 | 44 | $ hg tip -p |
|
45 | 45 | changeset: -1:000000000000 |
|
46 | 46 | tag: tip |
|
47 | 47 | user: |
|
48 | 48 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 52 | Record empty file |
|
53 | 53 | |
|
54 | 54 | $ hg record -d '0 0' -m empty empty-rw<<EOF |
|
55 | 55 | > y |
|
56 | 56 | > y |
|
57 | 57 | > EOF |
|
58 | 58 | diff --git a/empty-rw b/empty-rw |
|
59 | 59 | new file mode 100644 |
|
60 | 60 | examine changes to 'empty-rw'? [Ynesfdaq?] |
|
61 | 61 | |
|
62 | 62 | $ hg tip -p |
|
63 | 63 | changeset: 0:c0708cf4e46e |
|
64 | 64 | tag: tip |
|
65 | 65 | user: test |
|
66 | 66 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
67 | 67 | summary: empty |
|
68 | 68 | |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | Summary shows we updated to the new cset |
|
72 | 72 | |
|
73 | 73 | $ hg summary |
|
74 | 74 | parent: 0:c0708cf4e46e tip |
|
75 | 75 | empty |
|
76 | 76 | branch: default |
|
77 | 77 | commit: (clean) |
|
78 | 78 | update: (current) |
|
79 | 79 | |
|
80 | 80 | Rename empty file |
|
81 | 81 | |
|
82 | 82 | $ hg mv empty-rw empty-rename |
|
83 | 83 | $ hg record -d '1 0' -m rename<<EOF |
|
84 | 84 | > y |
|
85 | 85 | > EOF |
|
86 | 86 | diff --git a/empty-rw b/empty-rename |
|
87 | 87 | rename from empty-rw |
|
88 | 88 | rename to empty-rename |
|
89 | 89 | examine changes to 'empty-rw' and 'empty-rename'? [Ynesfdaq?] |
|
90 | 90 | |
|
91 | 91 | $ hg tip -p |
|
92 | 92 | changeset: 1:d695e8dcb197 |
|
93 | 93 | tag: tip |
|
94 | 94 | user: test |
|
95 | 95 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
96 | 96 | summary: rename |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | |
|
100 | 100 | Copy empty file |
|
101 | 101 | |
|
102 | 102 | $ hg cp empty-rename empty-copy |
|
103 | 103 | $ hg record -d '2 0' -m copy<<EOF |
|
104 | 104 | > y |
|
105 | 105 | > EOF |
|
106 | 106 | diff --git a/empty-rename b/empty-copy |
|
107 | 107 | copy from empty-rename |
|
108 | 108 | copy to empty-copy |
|
109 | 109 | examine changes to 'empty-rename' and 'empty-copy'? [Ynesfdaq?] |
|
110 | 110 | |
|
111 | 111 | $ hg tip -p |
|
112 | 112 | changeset: 2:1d4b90bea524 |
|
113 | 113 | tag: tip |
|
114 | 114 | user: test |
|
115 | 115 | date: Thu Jan 01 00:00:02 1970 +0000 |
|
116 | 116 | summary: copy |
|
117 | 117 | |
|
118 | 118 | |
|
119 | 119 | |
|
120 | 120 | Delete empty file |
|
121 | 121 | |
|
122 | 122 | $ hg rm empty-copy |
|
123 | 123 | $ hg record -d '3 0' -m delete<<EOF |
|
124 | 124 | > y |
|
125 | 125 | > EOF |
|
126 | 126 | diff --git a/empty-copy b/empty-copy |
|
127 | 127 | deleted file mode 100644 |
|
128 | 128 | examine changes to 'empty-copy'? [Ynesfdaq?] |
|
129 | 129 | |
|
130 | 130 | $ hg tip -p |
|
131 | 131 | changeset: 3:b39a238f01a1 |
|
132 | 132 | tag: tip |
|
133 | 133 | user: test |
|
134 | 134 | date: Thu Jan 01 00:00:03 1970 +0000 |
|
135 | 135 | summary: delete |
|
136 | 136 | |
|
137 | 137 | |
|
138 | 138 | |
|
139 | 139 | Add binary file |
|
140 | 140 | |
|
141 | 141 | $ hg bundle --base -2 tip.bundle |
|
142 | 142 | 1 changesets found |
|
143 | 143 | $ hg add tip.bundle |
|
144 | 144 | $ hg record -d '4 0' -m binary<<EOF |
|
145 | 145 | > y |
|
146 | 146 | > EOF |
|
147 | 147 | diff --git a/tip.bundle b/tip.bundle |
|
148 | 148 | new file mode 100644 |
|
149 | 149 | this is a binary file |
|
150 | 150 | examine changes to 'tip.bundle'? [Ynesfdaq?] |
|
151 | 151 | |
|
152 | 152 | $ hg tip -p |
|
153 | 153 | changeset: 4:ad816da3711e |
|
154 | 154 | tag: tip |
|
155 | 155 | user: test |
|
156 | 156 | date: Thu Jan 01 00:00:04 1970 +0000 |
|
157 | 157 | summary: binary |
|
158 | 158 | |
|
159 | 159 | diff -r b39a238f01a1 -r ad816da3711e tip.bundle |
|
160 | 160 | Binary file tip.bundle has changed |
|
161 | 161 | |
|
162 | 162 | |
|
163 | 163 | Change binary file |
|
164 | 164 | |
|
165 | 165 | $ hg bundle --base -2 tip.bundle |
|
166 | 166 | 1 changesets found |
|
167 | 167 | $ hg record -d '5 0' -m binary-change<<EOF |
|
168 | 168 | > y |
|
169 | 169 | > EOF |
|
170 | 170 | diff --git a/tip.bundle b/tip.bundle |
|
171 | 171 | this modifies a binary file (all or nothing) |
|
172 | 172 | examine changes to 'tip.bundle'? [Ynesfdaq?] |
|
173 | 173 | |
|
174 | 174 | $ hg tip -p |
|
175 | 175 | changeset: 5:dccd6f3eb485 |
|
176 | 176 | tag: tip |
|
177 | 177 | user: test |
|
178 | 178 | date: Thu Jan 01 00:00:05 1970 +0000 |
|
179 | 179 | summary: binary-change |
|
180 | 180 | |
|
181 | 181 | diff -r ad816da3711e -r dccd6f3eb485 tip.bundle |
|
182 | 182 | Binary file tip.bundle has changed |
|
183 | 183 | |
|
184 | 184 | |
|
185 | 185 | Rename and change binary file |
|
186 | 186 | |
|
187 | 187 | $ hg mv tip.bundle top.bundle |
|
188 | 188 | $ hg bundle --base -2 top.bundle |
|
189 | 189 | 1 changesets found |
|
190 | 190 | $ hg record -d '6 0' -m binary-change-rename<<EOF |
|
191 | 191 | > y |
|
192 | 192 | > EOF |
|
193 | 193 | diff --git a/tip.bundle b/top.bundle |
|
194 | 194 | rename from tip.bundle |
|
195 | 195 | rename to top.bundle |
|
196 | 196 | this modifies a binary file (all or nothing) |
|
197 | 197 | examine changes to 'tip.bundle' and 'top.bundle'? [Ynesfdaq?] |
|
198 | 198 | |
|
199 | 199 | $ hg tip -p |
|
200 | 200 | changeset: 6:7fa44105f5b3 |
|
201 | 201 | tag: tip |
|
202 | 202 | user: test |
|
203 | 203 | date: Thu Jan 01 00:00:06 1970 +0000 |
|
204 | 204 | summary: binary-change-rename |
|
205 | 205 | |
|
206 | 206 | diff -r dccd6f3eb485 -r 7fa44105f5b3 tip.bundle |
|
207 | 207 | Binary file tip.bundle has changed |
|
208 | 208 | diff -r dccd6f3eb485 -r 7fa44105f5b3 top.bundle |
|
209 | 209 | Binary file top.bundle has changed |
|
210 | 210 | |
|
211 | 211 | |
|
212 | 212 | Add plain file |
|
213 | 213 | |
|
214 | 214 | $ for i in 1 2 3 4 5 6 7 8 9 10; do |
|
215 | 215 | > echo $i >> plain |
|
216 | 216 | > done |
|
217 | 217 | |
|
218 | 218 | $ hg add plain |
|
219 | 219 | $ hg record -d '7 0' -m plain plain<<EOF |
|
220 | 220 | > y |
|
221 | 221 | > y |
|
222 | 222 | > EOF |
|
223 | 223 | diff --git a/plain b/plain |
|
224 | 224 | new file mode 100644 |
|
225 | 225 | examine changes to 'plain'? [Ynesfdaq?] |
|
226 | 226 | |
|
227 | 227 | $ hg tip -p |
|
228 | 228 | changeset: 7:11fb457c1be4 |
|
229 | 229 | tag: tip |
|
230 | 230 | user: test |
|
231 | 231 | date: Thu Jan 01 00:00:07 1970 +0000 |
|
232 | 232 | summary: plain |
|
233 | 233 | |
|
234 | 234 | diff -r 7fa44105f5b3 -r 11fb457c1be4 plain |
|
235 | 235 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
236 | 236 | +++ b/plain Thu Jan 01 00:00:07 1970 +0000 |
|
237 | 237 | @@ -0,0 +1,10 @@ |
|
238 | 238 | +1 |
|
239 | 239 | +2 |
|
240 | 240 | +3 |
|
241 | 241 | +4 |
|
242 | 242 | +5 |
|
243 | 243 | +6 |
|
244 | 244 | +7 |
|
245 | 245 | +8 |
|
246 | 246 | +9 |
|
247 | 247 | +10 |
|
248 | 248 | |
|
249 | 249 | Modify end of plain file with username unset |
|
250 | 250 | |
|
251 | 251 | $ echo 11 >> plain |
|
252 | 252 | $ unset HGUSER |
|
253 | 253 | $ hg record --config ui.username= -d '8 0' -m end plain |
|
254 | 254 | abort: no username supplied (see "hg help config") |
|
255 | 255 | [255] |
|
256 | 256 | |
|
257 | 257 | |
|
258 | 258 | Modify end of plain file, also test that diffopts are accounted for |
|
259 | 259 | |
|
260 | 260 | $ HGUSER="test" |
|
261 | 261 | $ export HGUSER |
|
262 | 262 | $ hg record --config diff.showfunc=true -d '8 0' -m end plain <<EOF |
|
263 | 263 | > y |
|
264 | 264 | > y |
|
265 | 265 | > EOF |
|
266 | 266 | diff --git a/plain b/plain |
|
267 | 267 | 1 hunks, 1 lines changed |
|
268 | 268 | examine changes to 'plain'? [Ynesfdaq?] |
|
269 | 269 | @@ -8,3 +8,4 @@ 7 |
|
270 | 270 | 8 |
|
271 | 271 | 9 |
|
272 | 272 | 10 |
|
273 | 273 | +11 |
|
274 | 274 | record this change to 'plain'? [Ynesfdaq?] |
|
275 | 275 | |
|
276 | 276 | Modify end of plain file, no EOL |
|
277 | 277 | |
|
278 | 278 | $ hg tip --template '{node}' >> plain |
|
279 | 279 | $ hg record -d '9 0' -m noeol plain <<EOF |
|
280 | 280 | > y |
|
281 | 281 | > y |
|
282 | 282 | > EOF |
|
283 | 283 | diff --git a/plain b/plain |
|
284 | 284 | 1 hunks, 1 lines changed |
|
285 | 285 | examine changes to 'plain'? [Ynesfdaq?] |
|
286 | 286 | @@ -9,3 +9,4 @@ |
|
287 | 287 | 9 |
|
288 | 288 | 10 |
|
289 | 289 | 11 |
|
290 | 290 | +7264f99c5f5ff3261504828afa4fb4d406c3af54 |
|
291 | 291 | \ No newline at end of file |
|
292 | 292 | record this change to 'plain'? [Ynesfdaq?] |
|
293 | 293 | |
|
294 | 294 | Modify end of plain file, add EOL |
|
295 | 295 | |
|
296 | 296 | $ echo >> plain |
|
297 | 297 | $ echo 1 > plain2 |
|
298 | 298 | $ hg add plain2 |
|
299 | 299 | $ hg record -d '10 0' -m eol plain plain2 <<EOF |
|
300 | 300 | > y |
|
301 | 301 | > y |
|
302 | 302 | > y |
|
303 | 303 | > EOF |
|
304 | 304 | diff --git a/plain b/plain |
|
305 | 305 | 1 hunks, 1 lines changed |
|
306 | 306 | examine changes to 'plain'? [Ynesfdaq?] |
|
307 | 307 | @@ -9,4 +9,4 @@ |
|
308 | 308 | 9 |
|
309 | 309 | 10 |
|
310 | 310 | 11 |
|
311 | 311 | -7264f99c5f5ff3261504828afa4fb4d406c3af54 |
|
312 | 312 | \ No newline at end of file |
|
313 | 313 | +7264f99c5f5ff3261504828afa4fb4d406c3af54 |
|
314 | 314 | record change 1/2 to 'plain'? [Ynesfdaq?] |
|
315 | 315 | diff --git a/plain2 b/plain2 |
|
316 | 316 | new file mode 100644 |
|
317 | 317 | examine changes to 'plain2'? [Ynesfdaq?] |
|
318 | 318 | |
|
319 | 319 | Modify beginning, trim end, record both, add another file to test |
|
320 | 320 | changes numbering |
|
321 | 321 | |
|
322 | 322 | $ rm plain |
|
323 | 323 | $ for i in 2 2 3 4 5 6 7 8 9 10; do |
|
324 | 324 | > echo $i >> plain |
|
325 | 325 | > done |
|
326 | 326 | $ echo 2 >> plain2 |
|
327 | 327 | |
|
328 | 328 | $ hg record -d '10 0' -m begin-and-end plain plain2 <<EOF |
|
329 | 329 | > y |
|
330 | 330 | > y |
|
331 | 331 | > y |
|
332 | 332 | > y |
|
333 | 333 | > y |
|
334 | 334 | > EOF |
|
335 | 335 | diff --git a/plain b/plain |
|
336 | 336 | 2 hunks, 3 lines changed |
|
337 | 337 | examine changes to 'plain'? [Ynesfdaq?] |
|
338 | 338 | @@ -1,4 +1,4 @@ |
|
339 | 339 | -1 |
|
340 | 340 | +2 |
|
341 | 341 | 2 |
|
342 | 342 | 3 |
|
343 | 343 | 4 |
|
344 | 344 | record change 1/3 to 'plain'? [Ynesfdaq?] |
|
345 | 345 | @@ -8,5 +8,3 @@ |
|
346 | 346 | 8 |
|
347 | 347 | 9 |
|
348 | 348 | 10 |
|
349 | 349 | -11 |
|
350 | 350 | -7264f99c5f5ff3261504828afa4fb4d406c3af54 |
|
351 | 351 | record change 2/3 to 'plain'? [Ynesfdaq?] |
|
352 | 352 | diff --git a/plain2 b/plain2 |
|
353 | 353 | 1 hunks, 1 lines changed |
|
354 | 354 | examine changes to 'plain2'? [Ynesfdaq?] |
|
355 | 355 | @@ -1,1 +1,2 @@ |
|
356 | 356 | 1 |
|
357 | 357 | +2 |
|
358 | 358 | record change 3/3 to 'plain2'? [Ynesfdaq?] |
|
359 | 359 | |
|
360 | 360 | $ hg tip -p |
|
361 | 361 | changeset: 11:21df83db12b8 |
|
362 | 362 | tag: tip |
|
363 | 363 | user: test |
|
364 | 364 | date: Thu Jan 01 00:00:10 1970 +0000 |
|
365 | 365 | summary: begin-and-end |
|
366 | 366 | |
|
367 | 367 | diff -r ddb8b281c3ff -r 21df83db12b8 plain |
|
368 | 368 | --- a/plain Thu Jan 01 00:00:10 1970 +0000 |
|
369 | 369 | +++ b/plain Thu Jan 01 00:00:10 1970 +0000 |
|
370 | 370 | @@ -1,4 +1,4 @@ |
|
371 | 371 | -1 |
|
372 | 372 | +2 |
|
373 | 373 | 2 |
|
374 | 374 | 3 |
|
375 | 375 | 4 |
|
376 | 376 | @@ -8,5 +8,3 @@ |
|
377 | 377 | 8 |
|
378 | 378 | 9 |
|
379 | 379 | 10 |
|
380 | 380 | -11 |
|
381 | 381 | -7264f99c5f5ff3261504828afa4fb4d406c3af54 |
|
382 | 382 | diff -r ddb8b281c3ff -r 21df83db12b8 plain2 |
|
383 | 383 | --- a/plain2 Thu Jan 01 00:00:10 1970 +0000 |
|
384 | 384 | +++ b/plain2 Thu Jan 01 00:00:10 1970 +0000 |
|
385 | 385 | @@ -1,1 +1,2 @@ |
|
386 | 386 | 1 |
|
387 | 387 | +2 |
|
388 | 388 | |
|
389 | 389 | |
|
390 | 390 | Trim beginning, modify end |
|
391 | 391 | |
|
392 | 392 | $ rm plain |
|
393 | 393 | > for i in 4 5 6 7 8 9 10.new; do |
|
394 | 394 | > echo $i >> plain |
|
395 | 395 | > done |
|
396 | 396 | |
|
397 | 397 | Record end |
|
398 | 398 | |
|
399 | 399 | $ hg record -d '11 0' -m end-only plain <<EOF |
|
400 | 400 | > y |
|
401 | 401 | > n |
|
402 | 402 | > y |
|
403 | 403 | > EOF |
|
404 | 404 | diff --git a/plain b/plain |
|
405 | 405 | 2 hunks, 4 lines changed |
|
406 | 406 | examine changes to 'plain'? [Ynesfdaq?] |
|
407 | 407 | @@ -1,9 +1,6 @@ |
|
408 | 408 | -2 |
|
409 | 409 | -2 |
|
410 | 410 | -3 |
|
411 | 411 | 4 |
|
412 | 412 | 5 |
|
413 | 413 | 6 |
|
414 | 414 | 7 |
|
415 | 415 | 8 |
|
416 | 416 | 9 |
|
417 | 417 | record change 1/2 to 'plain'? [Ynesfdaq?] |
|
418 | 418 | @@ -4,7 +1,7 @@ |
|
419 | 419 | 4 |
|
420 | 420 | 5 |
|
421 | 421 | 6 |
|
422 | 422 | 7 |
|
423 | 423 | 8 |
|
424 | 424 | 9 |
|
425 | 425 | -10 |
|
426 | 426 | +10.new |
|
427 | 427 | record change 2/2 to 'plain'? [Ynesfdaq?] |
|
428 | 428 | |
|
429 | 429 | $ hg tip -p |
|
430 | 430 | changeset: 12:99337501826f |
|
431 | 431 | tag: tip |
|
432 | 432 | user: test |
|
433 | 433 | date: Thu Jan 01 00:00:11 1970 +0000 |
|
434 | 434 | summary: end-only |
|
435 | 435 | |
|
436 | 436 | diff -r 21df83db12b8 -r 99337501826f plain |
|
437 | 437 | --- a/plain Thu Jan 01 00:00:10 1970 +0000 |
|
438 | 438 | +++ b/plain Thu Jan 01 00:00:11 1970 +0000 |
|
439 | 439 | @@ -7,4 +7,4 @@ |
|
440 | 440 | 7 |
|
441 | 441 | 8 |
|
442 | 442 | 9 |
|
443 | 443 | -10 |
|
444 | 444 | +10.new |
|
445 | 445 | |
|
446 | 446 | |
|
447 | 447 | Record beginning |
|
448 | 448 | |
|
449 | 449 | $ hg record -d '12 0' -m begin-only plain <<EOF |
|
450 | 450 | > y |
|
451 | 451 | > y |
|
452 | 452 | > EOF |
|
453 | 453 | diff --git a/plain b/plain |
|
454 | 454 | 1 hunks, 3 lines changed |
|
455 | 455 | examine changes to 'plain'? [Ynesfdaq?] |
|
456 | 456 | @@ -1,6 +1,3 @@ |
|
457 | 457 | -2 |
|
458 | 458 | -2 |
|
459 | 459 | -3 |
|
460 | 460 | 4 |
|
461 | 461 | 5 |
|
462 | 462 | 6 |
|
463 | 463 | record this change to 'plain'? [Ynesfdaq?] |
|
464 | 464 | |
|
465 | 465 | $ hg tip -p |
|
466 | 466 | changeset: 13:bbd45465d540 |
|
467 | 467 | tag: tip |
|
468 | 468 | user: test |
|
469 | 469 | date: Thu Jan 01 00:00:12 1970 +0000 |
|
470 | 470 | summary: begin-only |
|
471 | 471 | |
|
472 | 472 | diff -r 99337501826f -r bbd45465d540 plain |
|
473 | 473 | --- a/plain Thu Jan 01 00:00:11 1970 +0000 |
|
474 | 474 | +++ b/plain Thu Jan 01 00:00:12 1970 +0000 |
|
475 | 475 | @@ -1,6 +1,3 @@ |
|
476 | 476 | -2 |
|
477 | 477 | -2 |
|
478 | 478 | -3 |
|
479 | 479 | 4 |
|
480 | 480 | 5 |
|
481 | 481 | 6 |
|
482 | 482 | |
|
483 | 483 | |
|
484 | 484 | Add to beginning, trim from end |
|
485 | 485 | |
|
486 | 486 | $ rm plain |
|
487 | 487 | $ for i in 1 2 3 4 5 6 7 8 9; do |
|
488 | 488 | > echo $i >> plain |
|
489 | 489 | > done |
|
490 | 490 | |
|
491 | 491 | Record end |
|
492 | 492 | |
|
493 | 493 | $ hg record --traceback -d '13 0' -m end-again plain<<EOF |
|
494 | 494 | > y |
|
495 | 495 | > n |
|
496 | 496 | > y |
|
497 | 497 | > EOF |
|
498 | 498 | diff --git a/plain b/plain |
|
499 | 499 | 2 hunks, 4 lines changed |
|
500 | 500 | examine changes to 'plain'? [Ynesfdaq?] |
|
501 | 501 | @@ -1,6 +1,9 @@ |
|
502 | 502 | +1 |
|
503 | 503 | +2 |
|
504 | 504 | +3 |
|
505 | 505 | 4 |
|
506 | 506 | 5 |
|
507 | 507 | 6 |
|
508 | 508 | 7 |
|
509 | 509 | 8 |
|
510 | 510 | 9 |
|
511 | 511 | record change 1/2 to 'plain'? [Ynesfdaq?] |
|
512 | 512 | @@ -1,7 +4,6 @@ |
|
513 | 513 | 4 |
|
514 | 514 | 5 |
|
515 | 515 | 6 |
|
516 | 516 | 7 |
|
517 | 517 | 8 |
|
518 | 518 | 9 |
|
519 | 519 | -10.new |
|
520 | 520 | record change 2/2 to 'plain'? [Ynesfdaq?] |
|
521 | 521 | |
|
522 | 522 | Add to beginning, middle, end |
|
523 | 523 | |
|
524 | 524 | $ rm plain |
|
525 | 525 | $ for i in 1 2 3 4 5 5.new 5.reallynew 6 7 8 9 10 11; do |
|
526 | 526 | > echo $i >> plain |
|
527 | 527 | > done |
|
528 | 528 | |
|
529 | 529 | Record beginning, middle |
|
530 | 530 | |
|
531 | 531 | $ hg record -d '14 0' -m middle-only plain <<EOF |
|
532 | 532 | > y |
|
533 | 533 | > y |
|
534 | 534 | > y |
|
535 | 535 | > n |
|
536 | 536 | > EOF |
|
537 | 537 | diff --git a/plain b/plain |
|
538 | 538 | 3 hunks, 7 lines changed |
|
539 | 539 | examine changes to 'plain'? [Ynesfdaq?] |
|
540 | 540 | @@ -1,2 +1,5 @@ |
|
541 | 541 | +1 |
|
542 | 542 | +2 |
|
543 | 543 | +3 |
|
544 | 544 | 4 |
|
545 | 545 | 5 |
|
546 | 546 | record change 1/3 to 'plain'? [Ynesfdaq?] |
|
547 | 547 | @@ -1,6 +4,8 @@ |
|
548 | 548 | 4 |
|
549 | 549 | 5 |
|
550 | 550 | +5.new |
|
551 | 551 | +5.reallynew |
|
552 | 552 | 6 |
|
553 | 553 | 7 |
|
554 | 554 | 8 |
|
555 | 555 | 9 |
|
556 | 556 | record change 2/3 to 'plain'? [Ynesfdaq?] |
|
557 | 557 | @@ -3,4 +8,6 @@ |
|
558 | 558 | 6 |
|
559 | 559 | 7 |
|
560 | 560 | 8 |
|
561 | 561 | 9 |
|
562 | 562 | +10 |
|
563 | 563 | +11 |
|
564 | 564 | record change 3/3 to 'plain'? [Ynesfdaq?] |
|
565 | 565 | |
|
566 | 566 | $ hg tip -p |
|
567 | 567 | changeset: 15:f34a7937ec33 |
|
568 | 568 | tag: tip |
|
569 | 569 | user: test |
|
570 | 570 | date: Thu Jan 01 00:00:14 1970 +0000 |
|
571 | 571 | summary: middle-only |
|
572 | 572 | |
|
573 | 573 | diff -r 82c065d0b850 -r f34a7937ec33 plain |
|
574 | 574 | --- a/plain Thu Jan 01 00:00:13 1970 +0000 |
|
575 | 575 | +++ b/plain Thu Jan 01 00:00:14 1970 +0000 |
|
576 | 576 | @@ -1,5 +1,10 @@ |
|
577 | 577 | +1 |
|
578 | 578 | +2 |
|
579 | 579 | +3 |
|
580 | 580 | 4 |
|
581 | 581 | 5 |
|
582 | 582 | +5.new |
|
583 | 583 | +5.reallynew |
|
584 | 584 | 6 |
|
585 | 585 | 7 |
|
586 | 586 | 8 |
|
587 | 587 | |
|
588 | 588 | |
|
589 | 589 | Record end |
|
590 | 590 | |
|
591 | 591 | $ hg record -d '15 0' -m end-only plain <<EOF |
|
592 | 592 | > y |
|
593 | 593 | > y |
|
594 | 594 | > EOF |
|
595 | 595 | diff --git a/plain b/plain |
|
596 | 596 | 1 hunks, 2 lines changed |
|
597 | 597 | examine changes to 'plain'? [Ynesfdaq?] |
|
598 | 598 | @@ -9,3 +9,5 @@ |
|
599 | 599 | 7 |
|
600 | 600 | 8 |
|
601 | 601 | 9 |
|
602 | 602 | +10 |
|
603 | 603 | +11 |
|
604 | 604 | record this change to 'plain'? [Ynesfdaq?] |
|
605 | 605 | |
|
606 | 606 | $ hg tip -p |
|
607 | 607 | changeset: 16:f9900b71a04c |
|
608 | 608 | tag: tip |
|
609 | 609 | user: test |
|
610 | 610 | date: Thu Jan 01 00:00:15 1970 +0000 |
|
611 | 611 | summary: end-only |
|
612 | 612 | |
|
613 | 613 | diff -r f34a7937ec33 -r f9900b71a04c plain |
|
614 | 614 | --- a/plain Thu Jan 01 00:00:14 1970 +0000 |
|
615 | 615 | +++ b/plain Thu Jan 01 00:00:15 1970 +0000 |
|
616 | 616 | @@ -9,3 +9,5 @@ |
|
617 | 617 | 7 |
|
618 | 618 | 8 |
|
619 | 619 | 9 |
|
620 | 620 | +10 |
|
621 | 621 | +11 |
|
622 | 622 | |
|
623 | 623 | |
|
624 | 624 | $ mkdir subdir |
|
625 | 625 | $ cd subdir |
|
626 | 626 | $ echo a > a |
|
627 | 627 | $ hg ci -d '16 0' -Amsubdir |
|
628 | 628 | adding subdir/a |
|
629 | 629 | |
|
630 | 630 | $ echo a >> a |
|
631 | 631 | $ hg record -d '16 0' -m subdir-change a <<EOF |
|
632 | 632 | > y |
|
633 | 633 | > y |
|
634 | 634 | > EOF |
|
635 | 635 | diff --git a/subdir/a b/subdir/a |
|
636 | 636 | 1 hunks, 1 lines changed |
|
637 | 637 | examine changes to 'subdir/a'? [Ynesfdaq?] |
|
638 | 638 | @@ -1,1 +1,2 @@ |
|
639 | 639 | a |
|
640 | 640 | +a |
|
641 | 641 | record this change to 'subdir/a'? [Ynesfdaq?] |
|
642 | 642 | |
|
643 | 643 | $ hg tip -p |
|
644 | 644 | changeset: 18:61be427a9deb |
|
645 | 645 | tag: tip |
|
646 | 646 | user: test |
|
647 | 647 | date: Thu Jan 01 00:00:16 1970 +0000 |
|
648 | 648 | summary: subdir-change |
|
649 | 649 | |
|
650 | 650 | diff -r a7ffae4d61cb -r 61be427a9deb subdir/a |
|
651 | 651 | --- a/subdir/a Thu Jan 01 00:00:16 1970 +0000 |
|
652 | 652 | +++ b/subdir/a Thu Jan 01 00:00:16 1970 +0000 |
|
653 | 653 | @@ -1,1 +1,2 @@ |
|
654 | 654 | a |
|
655 | 655 | +a |
|
656 | 656 | |
|
657 | 657 | |
|
658 | 658 | $ echo a > f1 |
|
659 | 659 | $ echo b > f2 |
|
660 | 660 | $ hg add f1 f2 |
|
661 | 661 | |
|
662 | 662 | $ hg ci -mz -d '17 0' |
|
663 | 663 | |
|
664 | 664 | $ echo a >> f1 |
|
665 | 665 | $ echo b >> f2 |
|
666 | 666 | |
|
667 | 667 | Help, quit |
|
668 | 668 | |
|
669 | 669 | $ hg record <<EOF |
|
670 | 670 | > ? |
|
671 | 671 | > q |
|
672 | 672 | > EOF |
|
673 | 673 | diff --git a/subdir/f1 b/subdir/f1 |
|
674 | 674 | 1 hunks, 1 lines changed |
|
675 | 675 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
676 | 676 | y - record this change |
|
677 | 677 | n - skip this change |
|
678 | 678 | e - edit this change manually |
|
679 | 679 | s - skip remaining changes to this file |
|
680 | 680 | f - record remaining changes to this file |
|
681 | 681 | d - done, skip remaining changes and files |
|
682 | 682 | a - record all changes to all remaining files |
|
683 | 683 | q - quit, recording no changes |
|
684 | 684 | ? - display help |
|
685 | 685 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
686 | 686 | abort: user quit |
|
687 | 687 | [255] |
|
688 | 688 | |
|
689 | 689 | Skip |
|
690 | 690 | |
|
691 | 691 | $ hg record <<EOF |
|
692 | 692 | > s |
|
693 | 693 | > EOF |
|
694 | 694 | diff --git a/subdir/f1 b/subdir/f1 |
|
695 | 695 | 1 hunks, 1 lines changed |
|
696 | 696 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
697 | 697 | diff --git a/subdir/f2 b/subdir/f2 |
|
698 | 698 | 1 hunks, 1 lines changed |
|
699 | 699 | examine changes to 'subdir/f2'? [Ynesfdaq?] abort: response expected |
|
700 | 700 | [255] |
|
701 | 701 | |
|
702 | 702 | No |
|
703 | 703 | |
|
704 | 704 | $ hg record <<EOF |
|
705 | 705 | > n |
|
706 | 706 | > EOF |
|
707 | 707 | diff --git a/subdir/f1 b/subdir/f1 |
|
708 | 708 | 1 hunks, 1 lines changed |
|
709 | 709 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
710 | 710 | diff --git a/subdir/f2 b/subdir/f2 |
|
711 | 711 | 1 hunks, 1 lines changed |
|
712 | 712 | examine changes to 'subdir/f2'? [Ynesfdaq?] abort: response expected |
|
713 | 713 | [255] |
|
714 | 714 | |
|
715 | 715 | f, quit |
|
716 | 716 | |
|
717 | 717 | $ hg record <<EOF |
|
718 | 718 | > f |
|
719 | 719 | > q |
|
720 | 720 | > EOF |
|
721 | 721 | diff --git a/subdir/f1 b/subdir/f1 |
|
722 | 722 | 1 hunks, 1 lines changed |
|
723 | 723 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
724 | 724 | diff --git a/subdir/f2 b/subdir/f2 |
|
725 | 725 | 1 hunks, 1 lines changed |
|
726 | 726 | examine changes to 'subdir/f2'? [Ynesfdaq?] |
|
727 | 727 | abort: user quit |
|
728 | 728 | [255] |
|
729 | 729 | |
|
730 | 730 | s, all |
|
731 | 731 | |
|
732 | 732 | $ hg record -d '18 0' -mx <<EOF |
|
733 | 733 | > s |
|
734 | 734 | > a |
|
735 | 735 | > EOF |
|
736 | 736 | diff --git a/subdir/f1 b/subdir/f1 |
|
737 | 737 | 1 hunks, 1 lines changed |
|
738 | 738 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
739 | 739 | diff --git a/subdir/f2 b/subdir/f2 |
|
740 | 740 | 1 hunks, 1 lines changed |
|
741 | 741 | examine changes to 'subdir/f2'? [Ynesfdaq?] |
|
742 | 742 | |
|
743 | 743 | $ hg tip -p |
|
744 | 744 | changeset: 20:b3df3dda369a |
|
745 | 745 | tag: tip |
|
746 | 746 | user: test |
|
747 | 747 | date: Thu Jan 01 00:00:18 1970 +0000 |
|
748 | 748 | summary: x |
|
749 | 749 | |
|
750 | 750 | diff -r 6e02d6c9906d -r b3df3dda369a subdir/f2 |
|
751 | 751 | --- a/subdir/f2 Thu Jan 01 00:00:17 1970 +0000 |
|
752 | 752 | +++ b/subdir/f2 Thu Jan 01 00:00:18 1970 +0000 |
|
753 | 753 | @@ -1,1 +1,2 @@ |
|
754 | 754 | b |
|
755 | 755 | +b |
|
756 | 756 | |
|
757 | 757 | |
|
758 | 758 | f |
|
759 | 759 | |
|
760 | 760 | $ hg record -d '19 0' -my <<EOF |
|
761 | 761 | > f |
|
762 | 762 | > EOF |
|
763 | 763 | diff --git a/subdir/f1 b/subdir/f1 |
|
764 | 764 | 1 hunks, 1 lines changed |
|
765 | 765 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
766 | 766 | |
|
767 | 767 | $ hg tip -p |
|
768 | 768 | changeset: 21:38ec577f126b |
|
769 | 769 | tag: tip |
|
770 | 770 | user: test |
|
771 | 771 | date: Thu Jan 01 00:00:19 1970 +0000 |
|
772 | 772 | summary: y |
|
773 | 773 | |
|
774 | 774 | diff -r b3df3dda369a -r 38ec577f126b subdir/f1 |
|
775 | 775 | --- a/subdir/f1 Thu Jan 01 00:00:18 1970 +0000 |
|
776 | 776 | +++ b/subdir/f1 Thu Jan 01 00:00:19 1970 +0000 |
|
777 | 777 | @@ -1,1 +1,2 @@ |
|
778 | 778 | a |
|
779 | 779 | +a |
|
780 | 780 | |
|
781 | 781 | |
|
782 | 782 | #if execbit |
|
783 | 783 | |
|
784 | 784 | Preserve chmod +x |
|
785 | 785 | |
|
786 | 786 | $ chmod +x f1 |
|
787 | 787 | $ echo a >> f1 |
|
788 | 788 | $ hg record -d '20 0' -mz <<EOF |
|
789 | 789 | > y |
|
790 | 790 | > y |
|
791 | 791 | > y |
|
792 | 792 | > EOF |
|
793 | 793 | diff --git a/subdir/f1 b/subdir/f1 |
|
794 | 794 | old mode 100644 |
|
795 | 795 | new mode 100755 |
|
796 | 796 | 1 hunks, 1 lines changed |
|
797 | 797 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
798 | 798 | @@ -1,2 +1,3 @@ |
|
799 | 799 | a |
|
800 | 800 | a |
|
801 | 801 | +a |
|
802 | 802 | record this change to 'subdir/f1'? [Ynesfdaq?] |
|
803 | 803 | |
|
804 | 804 | $ hg tip --config diff.git=True -p |
|
805 | 805 | changeset: 22:3261adceb075 |
|
806 | 806 | tag: tip |
|
807 | 807 | user: test |
|
808 | 808 | date: Thu Jan 01 00:00:20 1970 +0000 |
|
809 | 809 | summary: z |
|
810 | 810 | |
|
811 | 811 | diff --git a/subdir/f1 b/subdir/f1 |
|
812 | 812 | old mode 100644 |
|
813 | 813 | new mode 100755 |
|
814 | 814 | --- a/subdir/f1 |
|
815 | 815 | +++ b/subdir/f1 |
|
816 | 816 | @@ -1,2 +1,3 @@ |
|
817 | 817 | a |
|
818 | 818 | a |
|
819 | 819 | +a |
|
820 | 820 | |
|
821 | 821 | |
|
822 | 822 | Preserve execute permission on original |
|
823 | 823 | |
|
824 | 824 | $ echo b >> f1 |
|
825 | 825 | $ hg record -d '21 0' -maa <<EOF |
|
826 | 826 | > y |
|
827 | 827 | > y |
|
828 | 828 | > y |
|
829 | 829 | > EOF |
|
830 | 830 | diff --git a/subdir/f1 b/subdir/f1 |
|
831 | 831 | 1 hunks, 1 lines changed |
|
832 | 832 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
833 | 833 | @@ -1,3 +1,4 @@ |
|
834 | 834 | a |
|
835 | 835 | a |
|
836 | 836 | a |
|
837 | 837 | +b |
|
838 | 838 | record this change to 'subdir/f1'? [Ynesfdaq?] |
|
839 | 839 | |
|
840 | 840 | $ hg tip --config diff.git=True -p |
|
841 | 841 | changeset: 23:b429867550db |
|
842 | 842 | tag: tip |
|
843 | 843 | user: test |
|
844 | 844 | date: Thu Jan 01 00:00:21 1970 +0000 |
|
845 | 845 | summary: aa |
|
846 | 846 | |
|
847 | 847 | diff --git a/subdir/f1 b/subdir/f1 |
|
848 | 848 | --- a/subdir/f1 |
|
849 | 849 | +++ b/subdir/f1 |
|
850 | 850 | @@ -1,3 +1,4 @@ |
|
851 | 851 | a |
|
852 | 852 | a |
|
853 | 853 | a |
|
854 | 854 | +b |
|
855 | 855 | |
|
856 | 856 | |
|
857 | 857 | Preserve chmod -x |
|
858 | 858 | |
|
859 | 859 | $ chmod -x f1 |
|
860 | 860 | $ echo c >> f1 |
|
861 | 861 | $ hg record -d '22 0' -mab <<EOF |
|
862 | 862 | > y |
|
863 | 863 | > y |
|
864 | 864 | > y |
|
865 | 865 | > EOF |
|
866 | 866 | diff --git a/subdir/f1 b/subdir/f1 |
|
867 | 867 | old mode 100755 |
|
868 | 868 | new mode 100644 |
|
869 | 869 | 1 hunks, 1 lines changed |
|
870 | 870 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
871 | 871 | @@ -2,3 +2,4 @@ |
|
872 | 872 | a |
|
873 | 873 | a |
|
874 | 874 | b |
|
875 | 875 | +c |
|
876 | 876 | record this change to 'subdir/f1'? [Ynesfdaq?] |
|
877 | 877 | |
|
878 | 878 | $ hg tip --config diff.git=True -p |
|
879 | 879 | changeset: 24:0b082130c20a |
|
880 | 880 | tag: tip |
|
881 | 881 | user: test |
|
882 | 882 | date: Thu Jan 01 00:00:22 1970 +0000 |
|
883 | 883 | summary: ab |
|
884 | 884 | |
|
885 | 885 | diff --git a/subdir/f1 b/subdir/f1 |
|
886 | 886 | old mode 100755 |
|
887 | 887 | new mode 100644 |
|
888 | 888 | --- a/subdir/f1 |
|
889 | 889 | +++ b/subdir/f1 |
|
890 | 890 | @@ -2,3 +2,4 @@ |
|
891 | 891 | a |
|
892 | 892 | a |
|
893 | 893 | b |
|
894 | 894 | +c |
|
895 | 895 | |
|
896 | 896 | |
|
897 | 897 | #else |
|
898 | 898 | |
|
899 | 899 | Slightly bogus tests to get almost same repo structure as when x bit is used |
|
900 | 900 | - but with different hashes. |
|
901 | 901 | |
|
902 | 902 | Mock "Preserve chmod +x" |
|
903 | 903 | |
|
904 | 904 | $ echo a >> f1 |
|
905 | 905 | $ hg record -d '20 0' -mz <<EOF |
|
906 | 906 | > y |
|
907 | 907 | > y |
|
908 | 908 | > y |
|
909 | 909 | > EOF |
|
910 | 910 | diff --git a/subdir/f1 b/subdir/f1 |
|
911 | 911 | 1 hunks, 1 lines changed |
|
912 | 912 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
913 | 913 | @@ -1,2 +1,3 @@ |
|
914 | 914 | a |
|
915 | 915 | a |
|
916 | 916 | +a |
|
917 | 917 | record this change to 'subdir/f1'? [Ynesfdaq?] |
|
918 | 918 | |
|
919 | 919 | $ hg tip --config diff.git=True -p |
|
920 | 920 | changeset: 22:0d463bd428f5 |
|
921 | 921 | tag: tip |
|
922 | 922 | user: test |
|
923 | 923 | date: Thu Jan 01 00:00:20 1970 +0000 |
|
924 | 924 | summary: z |
|
925 | 925 | |
|
926 | 926 | diff --git a/subdir/f1 b/subdir/f1 |
|
927 | 927 | --- a/subdir/f1 |
|
928 | 928 | +++ b/subdir/f1 |
|
929 | 929 | @@ -1,2 +1,3 @@ |
|
930 | 930 | a |
|
931 | 931 | a |
|
932 | 932 | +a |
|
933 | 933 | |
|
934 | 934 | |
|
935 | 935 | Mock "Preserve execute permission on original" |
|
936 | 936 | |
|
937 | 937 | $ echo b >> f1 |
|
938 | 938 | $ hg record -d '21 0' -maa <<EOF |
|
939 | 939 | > y |
|
940 | 940 | > y |
|
941 | 941 | > y |
|
942 | 942 | > EOF |
|
943 | 943 | diff --git a/subdir/f1 b/subdir/f1 |
|
944 | 944 | 1 hunks, 1 lines changed |
|
945 | 945 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
946 | 946 | @@ -1,3 +1,4 @@ |
|
947 | 947 | a |
|
948 | 948 | a |
|
949 | 949 | a |
|
950 | 950 | +b |
|
951 | 951 | record this change to 'subdir/f1'? [Ynesfdaq?] |
|
952 | 952 | |
|
953 | 953 | $ hg tip --config diff.git=True -p |
|
954 | 954 | changeset: 23:0eab41a3e524 |
|
955 | 955 | tag: tip |
|
956 | 956 | user: test |
|
957 | 957 | date: Thu Jan 01 00:00:21 1970 +0000 |
|
958 | 958 | summary: aa |
|
959 | 959 | |
|
960 | 960 | diff --git a/subdir/f1 b/subdir/f1 |
|
961 | 961 | --- a/subdir/f1 |
|
962 | 962 | +++ b/subdir/f1 |
|
963 | 963 | @@ -1,3 +1,4 @@ |
|
964 | 964 | a |
|
965 | 965 | a |
|
966 | 966 | a |
|
967 | 967 | +b |
|
968 | 968 | |
|
969 | 969 | |
|
970 | 970 | Mock "Preserve chmod -x" |
|
971 | 971 | |
|
972 | 972 | $ chmod -x f1 |
|
973 | 973 | $ echo c >> f1 |
|
974 | 974 | $ hg record -d '22 0' -mab <<EOF |
|
975 | 975 | > y |
|
976 | 976 | > y |
|
977 | 977 | > y |
|
978 | 978 | > EOF |
|
979 | 979 | diff --git a/subdir/f1 b/subdir/f1 |
|
980 | 980 | 1 hunks, 1 lines changed |
|
981 | 981 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
982 | 982 | @@ -2,3 +2,4 @@ |
|
983 | 983 | a |
|
984 | 984 | a |
|
985 | 985 | b |
|
986 | 986 | +c |
|
987 | 987 | record this change to 'subdir/f1'? [Ynesfdaq?] |
|
988 | 988 | |
|
989 | 989 | $ hg tip --config diff.git=True -p |
|
990 | 990 | changeset: 24:f4f718f27b7c |
|
991 | 991 | tag: tip |
|
992 | 992 | user: test |
|
993 | 993 | date: Thu Jan 01 00:00:22 1970 +0000 |
|
994 | 994 | summary: ab |
|
995 | 995 | |
|
996 | 996 | diff --git a/subdir/f1 b/subdir/f1 |
|
997 | 997 | --- a/subdir/f1 |
|
998 | 998 | +++ b/subdir/f1 |
|
999 | 999 | @@ -2,3 +2,4 @@ |
|
1000 | 1000 | a |
|
1001 | 1001 | a |
|
1002 | 1002 | b |
|
1003 | 1003 | +c |
|
1004 | 1004 | |
|
1005 | 1005 | |
|
1006 | 1006 | #endif |
|
1007 | 1007 | |
|
1008 | 1008 | $ cd .. |
|
1009 | 1009 | |
|
1010 | 1010 | |
|
1011 | 1011 | Abort early when a merge is in progress |
|
1012 | 1012 | |
|
1013 | 1013 | $ hg up 4 |
|
1014 | 1014 | 1 files updated, 0 files merged, 6 files removed, 0 files unresolved |
|
1015 | 1015 | |
|
1016 | 1016 | $ touch iwillmergethat |
|
1017 | 1017 | $ hg add iwillmergethat |
|
1018 | 1018 | |
|
1019 | 1019 | $ hg branch thatbranch |
|
1020 | 1020 | marked working directory as branch thatbranch |
|
1021 | 1021 | (branches are permanent and global, did you want a bookmark?) |
|
1022 | 1022 | |
|
1023 | 1023 | $ hg ci -m'new head' |
|
1024 | 1024 | |
|
1025 | 1025 | $ hg up default |
|
1026 | 1026 | 6 files updated, 0 files merged, 2 files removed, 0 files unresolved |
|
1027 | 1027 | |
|
1028 | 1028 | $ hg merge thatbranch |
|
1029 | 1029 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
1030 | 1030 | (branch merge, don't forget to commit) |
|
1031 | 1031 | |
|
1032 | 1032 | $ hg record -m'will abort' |
|
1033 | 1033 | abort: cannot partially commit a merge (use "hg commit" instead) |
|
1034 | 1034 | [255] |
|
1035 | 1035 | |
|
1036 | 1036 | $ hg up -C |
|
1037 | 1037 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
1038 | 1038 | |
|
1039 | 1039 | Editing patch (and ignoring trailing text) |
|
1040 | 1040 | |
|
1041 | 1041 | $ cat > editor.sh << '__EOF__' |
|
1042 |
> sed -e 7d -e '5s/^-/ /' -e '/^# ---/i |
|
|
1042 | > sed -e 7d -e '5s/^-/ /' -e '/^# ---/i\ | |
|
1043 | > trailing\nditto' "$1" > tmp | |
|
1043 | 1044 | > mv tmp "$1" |
|
1044 | 1045 | > __EOF__ |
|
1045 | 1046 | $ cat > editedfile << '__EOF__' |
|
1046 | 1047 | > This is the first line |
|
1047 | 1048 | > This is the second line |
|
1048 | 1049 | > This is the third line |
|
1049 | 1050 | > __EOF__ |
|
1050 | 1051 | $ hg add editedfile |
|
1051 | 1052 | $ hg commit -medit-patch-1 |
|
1052 | 1053 | $ cat > editedfile << '__EOF__' |
|
1053 | 1054 | > This line has changed |
|
1054 | 1055 | > This change will be committed |
|
1055 | 1056 | > This is the third line |
|
1056 | 1057 | > __EOF__ |
|
1057 | 1058 | $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record -d '23 0' -medit-patch-2 <<EOF |
|
1058 | 1059 | > y |
|
1059 | 1060 | > e |
|
1060 | 1061 | > EOF |
|
1061 | 1062 | diff --git a/editedfile b/editedfile |
|
1062 | 1063 | 1 hunks, 2 lines changed |
|
1063 | 1064 | examine changes to 'editedfile'? [Ynesfdaq?] |
|
1064 | 1065 | @@ -1,3 +1,3 @@ |
|
1065 | 1066 | -This is the first line |
|
1066 | 1067 | -This is the second line |
|
1067 | 1068 | +This line has changed |
|
1068 | 1069 | +This change will be committed |
|
1069 | 1070 | This is the third line |
|
1070 | 1071 | record this change to 'editedfile'? [Ynesfdaq?] |
|
1071 | 1072 | $ cat editedfile |
|
1072 | 1073 | This line has changed |
|
1073 | 1074 | This change will be committed |
|
1074 | 1075 | This is the third line |
|
1075 | 1076 | $ hg cat -r tip editedfile |
|
1076 | 1077 | This is the first line |
|
1077 | 1078 | This change will be committed |
|
1078 | 1079 | This is the third line |
|
1079 | 1080 | $ hg revert editedfile |
|
1080 | 1081 | |
|
1081 | 1082 | Trying to edit patch for whole file |
|
1082 | 1083 | |
|
1083 | 1084 | $ echo "This is the fourth line" >> editedfile |
|
1084 | 1085 | $ hg record <<EOF |
|
1085 | 1086 | > e |
|
1086 | 1087 | > q |
|
1087 | 1088 | > EOF |
|
1088 | 1089 | diff --git a/editedfile b/editedfile |
|
1089 | 1090 | 1 hunks, 1 lines changed |
|
1090 | 1091 | examine changes to 'editedfile'? [Ynesfdaq?] |
|
1091 | 1092 | cannot edit patch for whole file |
|
1092 | 1093 | examine changes to 'editedfile'? [Ynesfdaq?] |
|
1093 | 1094 | abort: user quit |
|
1094 | 1095 | [255] |
|
1095 | 1096 | $ hg revert editedfile |
|
1096 | 1097 | |
|
1097 | 1098 | Removing changes from patch |
|
1098 | 1099 | |
|
1099 | 1100 | $ sed -e '3s/third/second/' -e '2s/will/will not/' -e 1d editedfile > tmp |
|
1100 | 1101 | $ mv tmp editedfile |
|
1101 | 1102 | $ echo "This line has been added" >> editedfile |
|
1102 | 1103 | $ cat > editor.sh << '__EOF__' |
|
1103 | 1104 | > sed -e 's/^[-+]/ /' "$1" > tmp |
|
1104 | 1105 | > mv tmp "$1" |
|
1105 | 1106 | > __EOF__ |
|
1106 | 1107 | $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record <<EOF |
|
1107 | 1108 | > y |
|
1108 | 1109 | > e |
|
1109 | 1110 | > EOF |
|
1110 | 1111 | diff --git a/editedfile b/editedfile |
|
1111 | 1112 | 1 hunks, 3 lines changed |
|
1112 | 1113 | examine changes to 'editedfile'? [Ynesfdaq?] |
|
1113 | 1114 | @@ -1,3 +1,3 @@ |
|
1114 | 1115 | -This is the first line |
|
1115 | 1116 | -This change will be committed |
|
1116 | 1117 | -This is the third line |
|
1117 | 1118 | +This change will not be committed |
|
1118 | 1119 | +This is the second line |
|
1119 | 1120 | +This line has been added |
|
1120 | 1121 | record this change to 'editedfile'? [Ynesfdaq?] |
|
1121 | 1122 | no changes to record |
|
1122 | 1123 | $ cat editedfile |
|
1123 | 1124 | This change will not be committed |
|
1124 | 1125 | This is the second line |
|
1125 | 1126 | This line has been added |
|
1126 | 1127 | $ hg cat -r tip editedfile |
|
1127 | 1128 | This is the first line |
|
1128 | 1129 | This change will be committed |
|
1129 | 1130 | This is the third line |
|
1130 | 1131 | $ hg revert editedfile |
|
1131 | 1132 | |
|
1132 | 1133 | Invalid patch |
|
1133 | 1134 | |
|
1134 | 1135 | $ sed -e '3s/third/second/' -e '2s/will/will not/' -e 1d editedfile > tmp |
|
1135 | 1136 | $ mv tmp editedfile |
|
1136 | 1137 | $ echo "This line has been added" >> editedfile |
|
1137 | 1138 | $ cat > editor.sh << '__EOF__' |
|
1138 | 1139 | > sed s/This/That/ "$1" > tmp |
|
1139 | 1140 | > mv tmp "$1" |
|
1140 | 1141 | > __EOF__ |
|
1141 | 1142 | $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record <<EOF |
|
1142 | 1143 | > y |
|
1143 | 1144 | > e |
|
1144 | 1145 | > EOF |
|
1145 | 1146 | diff --git a/editedfile b/editedfile |
|
1146 | 1147 | 1 hunks, 3 lines changed |
|
1147 | 1148 | examine changes to 'editedfile'? [Ynesfdaq?] |
|
1148 | 1149 | @@ -1,3 +1,3 @@ |
|
1149 | 1150 | -This is the first line |
|
1150 | 1151 | -This change will be committed |
|
1151 | 1152 | -This is the third line |
|
1152 | 1153 | +This change will not be committed |
|
1153 | 1154 | +This is the second line |
|
1154 | 1155 | +This line has been added |
|
1155 | 1156 | record this change to 'editedfile'? [Ynesfdaq?] |
|
1156 | 1157 | patching file editedfile |
|
1157 | 1158 | Hunk #1 FAILED at 0 |
|
1158 | 1159 | 1 out of 1 hunks FAILED -- saving rejects to file editedfile.rej |
|
1159 | 1160 | abort: patch failed to apply |
|
1160 | 1161 | [255] |
|
1161 | 1162 | $ cat editedfile |
|
1162 | 1163 | This change will not be committed |
|
1163 | 1164 | This is the second line |
|
1164 | 1165 | This line has been added |
|
1165 | 1166 | $ hg cat -r tip editedfile |
|
1166 | 1167 | This is the first line |
|
1167 | 1168 | This change will be committed |
|
1168 | 1169 | This is the third line |
|
1169 | 1170 | $ cat editedfile.rej |
|
1170 | 1171 | --- editedfile |
|
1171 | 1172 | +++ editedfile |
|
1172 | 1173 | @@ -1,3 +1,3 @@ |
|
1173 | 1174 | -That is the first line |
|
1174 | 1175 | -That change will be committed |
|
1175 | 1176 | -That is the third line |
|
1176 | 1177 | +That change will not be committed |
|
1177 | 1178 | +That is the second line |
|
1178 | 1179 | +That line has been added |
|
1179 | 1180 | |
|
1180 | 1181 | Malformed patch - error handling |
|
1181 | 1182 | |
|
1182 | 1183 | $ cat > editor.sh << '__EOF__' |
|
1183 | 1184 | > sed -e '/^@/p' "$1" > tmp |
|
1184 | 1185 | > mv tmp "$1" |
|
1185 | 1186 | > __EOF__ |
|
1186 | 1187 | $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record <<EOF |
|
1187 | 1188 | > y |
|
1188 | 1189 | > e |
|
1189 | 1190 | > EOF |
|
1190 | 1191 | diff --git a/editedfile b/editedfile |
|
1191 | 1192 | 1 hunks, 3 lines changed |
|
1192 | 1193 | examine changes to 'editedfile'? [Ynesfdaq?] |
|
1193 | 1194 | @@ -1,3 +1,3 @@ |
|
1194 | 1195 | -This is the first line |
|
1195 | 1196 | -This change will be committed |
|
1196 | 1197 | -This is the third line |
|
1197 | 1198 | +This change will not be committed |
|
1198 | 1199 | +This is the second line |
|
1199 | 1200 | +This line has been added |
|
1200 | 1201 | record this change to 'editedfile'? [Ynesfdaq?] |
|
1201 | 1202 | abort: error parsing patch: unhandled transition: range -> range |
|
1202 | 1203 | [255] |
|
1203 | 1204 | |
|
1204 | 1205 | random text in random positions is still an error |
|
1205 | 1206 | |
|
1206 | 1207 | $ cat > editor.sh << '__EOF__' |
|
1207 |
> sed -e '/^@/i |
|
|
1208 | > sed -e '/^@/i\ | |
|
1209 | > other' "$1" > tmp | |
|
1208 | 1210 | > mv tmp "$1" |
|
1209 | 1211 | > __EOF__ |
|
1210 | 1212 | $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record <<EOF |
|
1211 | 1213 | > y |
|
1212 | 1214 | > e |
|
1213 | 1215 | > EOF |
|
1214 | 1216 | diff --git a/editedfile b/editedfile |
|
1215 | 1217 | 1 hunks, 3 lines changed |
|
1216 | 1218 | examine changes to 'editedfile'? [Ynesfdaq?] |
|
1217 | 1219 | @@ -1,3 +1,3 @@ |
|
1218 | 1220 | -This is the first line |
|
1219 | 1221 | -This change will be committed |
|
1220 | 1222 | -This is the third line |
|
1221 | 1223 | +This change will not be committed |
|
1222 | 1224 | +This is the second line |
|
1223 | 1225 | +This line has been added |
|
1224 | 1226 | record this change to 'editedfile'? [Ynesfdaq?] |
|
1225 | 1227 | abort: error parsing patch: unhandled transition: file -> other |
|
1226 | 1228 | [255] |
|
1227 | 1229 | |
|
1228 | 1230 | $ hg up -C |
|
1229 | 1231 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
1230 | 1232 | |
|
1231 | 1233 | With win32text |
|
1232 | 1234 | |
|
1233 | 1235 | $ echo '[extensions]' >> .hg/hgrc |
|
1234 | 1236 | $ echo 'win32text = ' >> .hg/hgrc |
|
1235 | 1237 | $ echo '[decode]' >> .hg/hgrc |
|
1236 | 1238 | $ echo '** = cleverdecode:' >> .hg/hgrc |
|
1237 | 1239 | $ echo '[encode]' >> .hg/hgrc |
|
1238 | 1240 | $ echo '** = cleverencode:' >> .hg/hgrc |
|
1239 | 1241 | $ echo '[patch]' >> .hg/hgrc |
|
1240 | 1242 | $ echo 'eol = crlf' >> .hg/hgrc |
|
1241 | 1243 | |
|
1242 | 1244 | Ignore win32text deprecation warning for now: |
|
1243 | 1245 | |
|
1244 | 1246 | $ echo '[win32text]' >> .hg/hgrc |
|
1245 | 1247 | $ echo 'warn = no' >> .hg/hgrc |
|
1246 | 1248 | |
|
1247 | 1249 | $ echo d >> subdir/f1 |
|
1248 | 1250 | $ hg record -d '24 0' -mw1 <<EOF |
|
1249 | 1251 | > y |
|
1250 | 1252 | > y |
|
1251 | 1253 | > EOF |
|
1252 | 1254 | diff --git a/subdir/f1 b/subdir/f1 |
|
1253 | 1255 | 1 hunks, 1 lines changed |
|
1254 | 1256 | examine changes to 'subdir/f1'? [Ynesfdaq?] |
|
1255 | 1257 | @@ -3,3 +3,4 @@ |
|
1256 | 1258 | a |
|
1257 | 1259 | b |
|
1258 | 1260 | c |
|
1259 | 1261 | +d |
|
1260 | 1262 | record this change to 'subdir/f1'? [Ynesfdaq?] |
|
1261 | 1263 | |
|
1262 | 1264 | $ hg tip -p |
|
1263 | 1265 | changeset: 28:* (glob) |
|
1264 | 1266 | tag: tip |
|
1265 | 1267 | user: test |
|
1266 | 1268 | date: Thu Jan 01 00:00:24 1970 +0000 |
|
1267 | 1269 | summary: w1 |
|
1268 | 1270 | |
|
1269 | 1271 | diff -r ???????????? -r ???????????? subdir/f1 (glob) |
|
1270 | 1272 | --- a/subdir/f1 Thu Jan 01 00:00:23 1970 +0000 |
|
1271 | 1273 | +++ b/subdir/f1 Thu Jan 01 00:00:24 1970 +0000 |
|
1272 | 1274 | @@ -3,3 +3,4 @@ |
|
1273 | 1275 | a |
|
1274 | 1276 | b |
|
1275 | 1277 | c |
|
1276 | 1278 | +d |
|
1277 | 1279 | |
|
1278 | 1280 | |
|
1279 | 1281 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now