Show More
@@ -1,433 +1,435 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 | return "#" * len(comment) |
|
23 | 23 | return repquote(m) |
|
24 | 24 | |
|
25 | 25 | def repcomment(m): |
|
26 | 26 | return m.group(1) + "#" * len(m.group(2)) |
|
27 | 27 | |
|
28 | 28 | def repccomment(m): |
|
29 | 29 | t = re.sub(r"((?<=\n) )|\S", "x", m.group(2)) |
|
30 | 30 | return m.group(1) + t + "*/" |
|
31 | 31 | |
|
32 | 32 | def repcallspaces(m): |
|
33 | 33 | t = re.sub(r"\n\s+", "\n", m.group(2)) |
|
34 | 34 | return m.group(1) + t |
|
35 | 35 | |
|
36 | 36 | def repinclude(m): |
|
37 | 37 | return m.group(1) + "<foo>" |
|
38 | 38 | |
|
39 | 39 | def rephere(m): |
|
40 | 40 | t = re.sub(r"\S", "x", m.group(2)) |
|
41 | 41 | return m.group(1) + t |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | testpats = [ |
|
45 | 45 | [ |
|
46 | 46 | (r'(pushd|popd)', "don't use 'pushd' or 'popd', use 'cd'"), |
|
47 | 47 | (r'\W\$?\(\([^\)\n]*\)\)', "don't use (()) or $(()), use 'expr'"), |
|
48 | 48 | (r'^function', "don't use 'function', use old style"), |
|
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'echo.*\\n', "don't use 'echo \\n', use printf"), |
|
52 | 52 | (r'echo -n', "don't use 'echo -n', use printf"), |
|
53 | 53 | (r'^diff.*-\w*N', "don't use 'diff -N'"), |
|
54 | 54 | (r'(^| )wc[^|]*$\n(?!.*\(re\))', "filter wc output"), |
|
55 | 55 | (r'head -c', "don't use 'head -c', use 'dd'"), |
|
56 | 56 | (r'sha1sum', "don't use sha1sum, use $TESTDIR/md5sum.py"), |
|
57 | 57 | (r'ls.*-\w*R', "don't use 'ls -R', use 'find'"), |
|
58 | 58 | (r'printf.*\\\d{1,3}', "don't use 'printf \NNN', use Python"), |
|
59 | 59 | (r'printf.*\\x', "don't use printf \\x, use Python"), |
|
60 | 60 | (r'\$\(.*\)', "don't use $(expr), use `expr`"), |
|
61 | 61 | (r'rm -rf \*', "don't use naked rm -rf, target a directory"), |
|
62 | 62 | (r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w', |
|
63 | 63 | "use egrep for extended grep syntax"), |
|
64 | 64 | (r'/bin/', "don't use explicit paths for tools"), |
|
65 | 65 | (r'\$PWD', "don't use $PWD, use `pwd`"), |
|
66 | 66 | (r'[^\n]\Z', "no trailing newline"), |
|
67 | 67 | (r'export.*=', "don't export and assign at once"), |
|
68 | 68 | (r'^([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\\^', "^ must be quoted"), |
|
69 | 69 | (r'^source\b', "don't use 'source', use '.'"), |
|
70 | 70 | (r'touch -d', "don't use 'touch -d', use 'touch -t' instead"), |
|
71 | 71 | (r'ls +[^|\n-]+ +-', "options to 'ls' must come before filenames"), |
|
72 | 72 | (r'[^>\n]>\s*\$HGRCPATH', "don't overwrite $HGRCPATH, append to it"), |
|
73 | 73 | (r'^stop\(\)', "don't use 'stop' as a shell function name"), |
|
74 | 74 | (r'(\[|\btest\b).*-e ', "don't use 'test -e', use 'test -f'"), |
|
75 | 75 | (r'^alias\b.*=', "don't use alias, use a function"), |
|
76 | 76 | ], |
|
77 | 77 | # warnings |
|
78 | 78 | [] |
|
79 | 79 | ] |
|
80 | 80 | |
|
81 | 81 | testfilters = [ |
|
82 | 82 | (r"( *)(#([^\n]*\S)?)", repcomment), |
|
83 | 83 | (r"<<(\S+)((.|\n)*?\n\1)", rephere), |
|
84 | 84 | ] |
|
85 | 85 | |
|
86 | 86 | uprefix = r"^ \$ " |
|
87 | 87 | uprefixc = r"^ > " |
|
88 | 88 | utestpats = [ |
|
89 | 89 | [ |
|
90 | 90 | (r'^(\S| $ ).*(\S[ \t]+|^[ \t]+)\n', "trailing whitespace on non-output"), |
|
91 | 91 | (uprefix + r'.*\|\s*sed', "use regex test output patterns instead of sed"), |
|
92 | 92 | (uprefix + r'(true|exit 0)', "explicit zero exit unnecessary"), |
|
93 | 93 | (uprefix + r'.*(?<!\[)\$\?', "explicit exit code checks unnecessary"), |
|
94 | 94 | (uprefix + r'.*\|\| echo.*(fail|error)', |
|
95 | 95 | "explicit exit code checks unnecessary"), |
|
96 | 96 | (uprefix + r'set -e', "don't use set -e"), |
|
97 | 97 | (uprefixc + r'( *)\t', "don't use tabs to indent"), |
|
98 | (uprefixc + r'.*do\s*true;\s*done', | |
|
99 | "don't use true as loop body, use sleep 0"), | |
|
98 | 100 | ], |
|
99 | 101 | # warnings |
|
100 | 102 | [] |
|
101 | 103 | ] |
|
102 | 104 | |
|
103 | 105 | for i in [0, 1]: |
|
104 | 106 | for p, m in testpats[i]: |
|
105 | 107 | if p.startswith(r'^'): |
|
106 | 108 | p = uprefix + p[1:] |
|
107 | 109 | else: |
|
108 | 110 | p = uprefix + ".*" + p |
|
109 | 111 | utestpats[i].append((p, m)) |
|
110 | 112 | |
|
111 | 113 | utestfilters = [ |
|
112 | 114 | (r"( *)(#([^\n]*\S)?)", repcomment), |
|
113 | 115 | ] |
|
114 | 116 | |
|
115 | 117 | pypats = [ |
|
116 | 118 | [ |
|
117 | 119 | (r'^\s*def\s*\w+\s*\(.*,\s*\(', |
|
118 | 120 | "tuple parameter unpacking not available in Python 3+"), |
|
119 | 121 | (r'lambda\s*\(.*,.*\)', |
|
120 | 122 | "tuple parameter unpacking not available in Python 3+"), |
|
121 | 123 | (r'(?<!def)\s+(cmp)\(', "cmp is not available in Python 3+"), |
|
122 | 124 | (r'\breduce\s*\(.*', "reduce is not available in Python 3+"), |
|
123 | 125 | (r'\.has_key\b', "dict.has_key is not available in Python 3+"), |
|
124 | 126 | (r'^\s*\t', "don't use tabs"), |
|
125 | 127 | (r'\S;\s*\n', "semicolon"), |
|
126 | 128 | (r'[^_]_\("[^"]+"\s*%', "don't use % inside _()"), |
|
127 | 129 | (r"[^_]_\('[^']+'\s*%", "don't use % inside _()"), |
|
128 | 130 | (r'\w,\w', "missing whitespace after ,"), |
|
129 | 131 | (r'\w[+/*\-<>]\w', "missing whitespace in expression"), |
|
130 | 132 | (r'^\s+\w+=\w+[^,)\n]$', "missing whitespace in assignment"), |
|
131 | 133 | (r'(\s+)try:\n((?:\n|\1\s.*\n)+?)\1except.*?:\n' |
|
132 | 134 | r'((?:\n|\1\s.*\n)+?)\1finally:', 'no try/except/finally in Py2.4'), |
|
133 | 135 | (r'.{85}', "line too long"), |
|
134 | 136 | (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'), |
|
135 | 137 | (r'[^\n]\Z', "no trailing newline"), |
|
136 | 138 | (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), |
|
137 | 139 | # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', "don't use underbars in identifiers"), |
|
138 | 140 | (r'^\s+(self\.)?[A-za-z][a-z0-9]+[A-Z]\w* = ', |
|
139 | 141 | "don't use camelcase in identifiers"), |
|
140 | 142 | (r'^\s*(if|while|def|class|except|try)\s[^[\n]*:\s*[^\\n]#\s]+', |
|
141 | 143 | "linebreak after :"), |
|
142 | 144 | (r'class\s[^( \n]+:', "old-style class, use class foo(object)"), |
|
143 | 145 | (r'class\s[^( \n]+\(\):', |
|
144 | 146 | "class foo() not available in Python 2.4, use class foo(object)"), |
|
145 | 147 | (r'\b(%s)\(' % '|'.join(keyword.kwlist), |
|
146 | 148 | "Python keyword is not a function"), |
|
147 | 149 | (r',]', "unneeded trailing ',' in list"), |
|
148 | 150 | # (r'class\s[A-Z][^\(]*\((?!Exception)', |
|
149 | 151 | # "don't capitalize non-exception classes"), |
|
150 | 152 | # (r'in range\(', "use xrange"), |
|
151 | 153 | # (r'^\s*print\s+', "avoid using print in core and extensions"), |
|
152 | 154 | (r'[\x80-\xff]', "non-ASCII character literal"), |
|
153 | 155 | (r'("\')\.format\(', "str.format() not available in Python 2.4"), |
|
154 | 156 | (r'^\s*with\s+', "with not available in Python 2.4"), |
|
155 | 157 | (r'\.isdisjoint\(', "set.isdisjoint not available in Python 2.4"), |
|
156 | 158 | (r'^\s*except.* as .*:', "except as not available in Python 2.4"), |
|
157 | 159 | (r'^\s*os\.path\.relpath', "relpath not available in Python 2.4"), |
|
158 | 160 | (r'(?<!def)\s+(any|all|format)\(', |
|
159 | 161 | "any/all/format not available in Python 2.4"), |
|
160 | 162 | (r'(?<!def)\s+(callable)\(', |
|
161 | 163 | "callable not available in Python 3, use getattr(f, '__call__', None)"), |
|
162 | 164 | (r'if\s.*\selse', "if ... else form not available in Python 2.4"), |
|
163 | 165 | (r'^\s*(%s)\s\s' % '|'.join(keyword.kwlist), |
|
164 | 166 | "gratuitous whitespace after Python keyword"), |
|
165 | 167 | (r'([\(\[][ \t]\S)|(\S[ \t][\)\]])', "gratuitous whitespace in () or []"), |
|
166 | 168 | # (r'\s\s=', "gratuitous whitespace before ="), |
|
167 | 169 | (r'[^>< ](\+=|-=|!=|<>|<=|>=|<<=|>>=)\S', |
|
168 | 170 | "missing whitespace around operator"), |
|
169 | 171 | (r'[^>< ](\+=|-=|!=|<>|<=|>=|<<=|>>=)\s', |
|
170 | 172 | "missing whitespace around operator"), |
|
171 | 173 | (r'\s(\+=|-=|!=|<>|<=|>=|<<=|>>=)\S', |
|
172 | 174 | "missing whitespace around operator"), |
|
173 | 175 | (r'[^^+=*/!<>&| -](\s=|=\s)[^= ]', |
|
174 | 176 | "wrong whitespace around ="), |
|
175 | 177 | (r'raise Exception', "don't raise generic exceptions"), |
|
176 | 178 | (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"), |
|
177 | 179 | (r' [=!]=\s+(True|False|None)', |
|
178 | 180 | "comparison with singleton, use 'is' or 'is not' instead"), |
|
179 | 181 | (r'^\s*(while|if) [01]:', |
|
180 | 182 | "use True/False for constant Boolean expression"), |
|
181 | 183 | (r'(?<!def)\s+hasattr', |
|
182 | 184 | 'hasattr(foo, bar) is broken, use util.safehasattr(foo, bar) instead'), |
|
183 | 185 | (r'opener\([^)]*\).read\(', |
|
184 | 186 | "use opener.read() instead"), |
|
185 | 187 | (r'BaseException', 'not in Py2.4, use Exception'), |
|
186 | 188 | (r'os\.path\.relpath', 'os.path.relpath is not in Py2.5'), |
|
187 | 189 | (r'opener\([^)]*\).write\(', |
|
188 | 190 | "use opener.write() instead"), |
|
189 | 191 | (r'[\s\(](open|file)\([^)]*\)\.read\(', |
|
190 | 192 | "use util.readfile() instead"), |
|
191 | 193 | (r'[\s\(](open|file)\([^)]*\)\.write\(', |
|
192 | 194 | "use util.readfile() instead"), |
|
193 | 195 | (r'^[\s\(]*(open(er)?|file)\([^)]*\)', |
|
194 | 196 | "always assign an opened file to a variable, and close it afterwards"), |
|
195 | 197 | (r'[\s\(](open|file)\([^)]*\)\.', |
|
196 | 198 | "always assign an opened file to a variable, and close it afterwards"), |
|
197 | 199 | (r'(?i)descendent', "the proper spelling is descendAnt"), |
|
198 | 200 | (r'\.debug\(\_', "don't mark debug messages for translation"), |
|
199 | 201 | ], |
|
200 | 202 | # warnings |
|
201 | 203 | [ |
|
202 | 204 | (r'.{81}', "warning: line over 80 characters"), |
|
203 | 205 | (r'^\s*except:$', "warning: naked except clause"), |
|
204 | 206 | (r'ui\.(status|progress|write|note|warn)\([\'\"]x', |
|
205 | 207 | "warning: unwrapped ui message"), |
|
206 | 208 | ] |
|
207 | 209 | ] |
|
208 | 210 | |
|
209 | 211 | pyfilters = [ |
|
210 | 212 | (r"""(?msx)(?P<comment>\#.*?$)| |
|
211 | 213 | ((?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!"))) |
|
212 | 214 | (?P<text>(([^\\]|\\.)*?)) |
|
213 | 215 | (?P=quote))""", reppython), |
|
214 | 216 | ] |
|
215 | 217 | |
|
216 | 218 | cpats = [ |
|
217 | 219 | [ |
|
218 | 220 | (r'//', "don't use //-style comments"), |
|
219 | 221 | (r'^ ', "don't use spaces to indent"), |
|
220 | 222 | (r'\S\t', "don't use tabs except for indent"), |
|
221 | 223 | (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), |
|
222 | 224 | (r'.{85}', "line too long"), |
|
223 | 225 | (r'(while|if|do|for)\(', "use space after while/if/do/for"), |
|
224 | 226 | (r'return\(', "return is not a function"), |
|
225 | 227 | (r' ;', "no space before ;"), |
|
226 | 228 | (r'\w+\* \w+', "use int *foo, not int* foo"), |
|
227 | 229 | (r'\([^\)]+\) \w+', "use (int)foo, not (int) foo"), |
|
228 | 230 | (r'\S+ (\+\+|--)', "use foo++, not foo ++"), |
|
229 | 231 | (r'\w,\w', "missing whitespace after ,"), |
|
230 | 232 | (r'^[^#]\w[+/*]\w', "missing whitespace in expression"), |
|
231 | 233 | (r'^#\s+\w', "use #foo, not # foo"), |
|
232 | 234 | (r'[^\n]\Z', "no trailing newline"), |
|
233 | 235 | (r'^\s*#import\b', "use only #include in standard C code"), |
|
234 | 236 | ], |
|
235 | 237 | # warnings |
|
236 | 238 | [] |
|
237 | 239 | ] |
|
238 | 240 | |
|
239 | 241 | cfilters = [ |
|
240 | 242 | (r'(/\*)(((\*(?!/))|[^*])*)\*/', repccomment), |
|
241 | 243 | (r'''(?P<quote>(?<!")")(?P<text>([^"]|\\")+)"(?!")''', repquote), |
|
242 | 244 | (r'''(#\s*include\s+<)([^>]+)>''', repinclude), |
|
243 | 245 | (r'(\()([^)]+\))', repcallspaces), |
|
244 | 246 | ] |
|
245 | 247 | |
|
246 | 248 | inutilpats = [ |
|
247 | 249 | [ |
|
248 | 250 | (r'\bui\.', "don't use ui in util"), |
|
249 | 251 | ], |
|
250 | 252 | # warnings |
|
251 | 253 | [] |
|
252 | 254 | ] |
|
253 | 255 | |
|
254 | 256 | inrevlogpats = [ |
|
255 | 257 | [ |
|
256 | 258 | (r'\brepo\.', "don't use repo in revlog"), |
|
257 | 259 | ], |
|
258 | 260 | # warnings |
|
259 | 261 | [] |
|
260 | 262 | ] |
|
261 | 263 | |
|
262 | 264 | checks = [ |
|
263 | 265 | ('python', r'.*\.(py|cgi)$', pyfilters, pypats), |
|
264 | 266 | ('test script', r'(.*/)?test-[^.~]*$', testfilters, testpats), |
|
265 | 267 | ('c', r'.*\.c$', cfilters, cpats), |
|
266 | 268 | ('unified test', r'.*\.t$', utestfilters, utestpats), |
|
267 | 269 | ('layering violation repo in revlog', r'mercurial/revlog\.py', pyfilters, |
|
268 | 270 | inrevlogpats), |
|
269 | 271 | ('layering violation ui in util', r'mercurial/util\.py', pyfilters, |
|
270 | 272 | inutilpats), |
|
271 | 273 | ] |
|
272 | 274 | |
|
273 | 275 | class norepeatlogger(object): |
|
274 | 276 | def __init__(self): |
|
275 | 277 | self._lastseen = None |
|
276 | 278 | |
|
277 | 279 | def log(self, fname, lineno, line, msg, blame): |
|
278 | 280 | """print error related a to given line of a given file. |
|
279 | 281 | |
|
280 | 282 | The faulty line will also be printed but only once in the case |
|
281 | 283 | of multiple errors. |
|
282 | 284 | |
|
283 | 285 | :fname: filename |
|
284 | 286 | :lineno: line number |
|
285 | 287 | :line: actual content of the line |
|
286 | 288 | :msg: error message |
|
287 | 289 | """ |
|
288 | 290 | msgid = fname, lineno, line |
|
289 | 291 | if msgid != self._lastseen: |
|
290 | 292 | if blame: |
|
291 | 293 | print "%s:%d (%s):" % (fname, lineno, blame) |
|
292 | 294 | else: |
|
293 | 295 | print "%s:%d:" % (fname, lineno) |
|
294 | 296 | print " > %s" % line |
|
295 | 297 | self._lastseen = msgid |
|
296 | 298 | print " " + msg |
|
297 | 299 | |
|
298 | 300 | _defaultlogger = norepeatlogger() |
|
299 | 301 | |
|
300 | 302 | def getblame(f): |
|
301 | 303 | lines = [] |
|
302 | 304 | for l in os.popen('hg annotate -un %s' % f): |
|
303 | 305 | start, line = l.split(':', 1) |
|
304 | 306 | user, rev = start.split() |
|
305 | 307 | lines.append((line[1:-1], user, rev)) |
|
306 | 308 | return lines |
|
307 | 309 | |
|
308 | 310 | def checkfile(f, logfunc=_defaultlogger.log, maxerr=None, warnings=False, |
|
309 | 311 | blame=False, debug=False, lineno=True): |
|
310 | 312 | """checks style and portability of a given file |
|
311 | 313 | |
|
312 | 314 | :f: filepath |
|
313 | 315 | :logfunc: function used to report error |
|
314 | 316 | logfunc(filename, linenumber, linecontent, errormessage) |
|
315 | 317 | :maxerr: number of error to display before arborting. |
|
316 | 318 | Set to false (default) to report all errors |
|
317 | 319 | |
|
318 | 320 | return True if no error is found, False otherwise. |
|
319 | 321 | """ |
|
320 | 322 | blamecache = None |
|
321 | 323 | result = True |
|
322 | 324 | for name, match, filters, pats in checks: |
|
323 | 325 | if debug: |
|
324 | 326 | print name, f |
|
325 | 327 | fc = 0 |
|
326 | 328 | if not re.match(match, f): |
|
327 | 329 | if debug: |
|
328 | 330 | print "Skipping %s for %s it doesn't match %s" % ( |
|
329 | 331 | name, match, f) |
|
330 | 332 | continue |
|
331 | 333 | fp = open(f) |
|
332 | 334 | pre = post = fp.read() |
|
333 | 335 | fp.close() |
|
334 | 336 | if "no-" + "check-code" in pre: |
|
335 | 337 | if debug: |
|
336 | 338 | print "Skipping %s for %s it has no- and check-code" % ( |
|
337 | 339 | name, f) |
|
338 | 340 | break |
|
339 | 341 | for p, r in filters: |
|
340 | 342 | post = re.sub(p, r, post) |
|
341 | 343 | if warnings: |
|
342 | 344 | pats = pats[0] + pats[1] |
|
343 | 345 | else: |
|
344 | 346 | pats = pats[0] |
|
345 | 347 | # print post # uncomment to show filtered version |
|
346 | 348 | |
|
347 | 349 | if debug: |
|
348 | 350 | print "Checking %s for %s" % (name, f) |
|
349 | 351 | |
|
350 | 352 | prelines = None |
|
351 | 353 | errors = [] |
|
352 | 354 | for p, msg in pats: |
|
353 | 355 | # fix-up regexes for multiline searches |
|
354 | 356 | po = p |
|
355 | 357 | # \s doesn't match \n |
|
356 | 358 | p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p) |
|
357 | 359 | # [^...] doesn't match newline |
|
358 | 360 | p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p) |
|
359 | 361 | |
|
360 | 362 | #print po, '=>', p |
|
361 | 363 | |
|
362 | 364 | pos = 0 |
|
363 | 365 | n = 0 |
|
364 | 366 | for m in re.finditer(p, post, re.MULTILINE): |
|
365 | 367 | if prelines is None: |
|
366 | 368 | prelines = pre.splitlines() |
|
367 | 369 | postlines = post.splitlines(True) |
|
368 | 370 | |
|
369 | 371 | start = m.start() |
|
370 | 372 | while n < len(postlines): |
|
371 | 373 | step = len(postlines[n]) |
|
372 | 374 | if pos + step > start: |
|
373 | 375 | break |
|
374 | 376 | pos += step |
|
375 | 377 | n += 1 |
|
376 | 378 | l = prelines[n] |
|
377 | 379 | |
|
378 | 380 | if "check-code" + "-ignore" in l: |
|
379 | 381 | if debug: |
|
380 | 382 | print "Skipping %s for %s:%s (check-code -ignore)" % ( |
|
381 | 383 | name, f, n) |
|
382 | 384 | continue |
|
383 | 385 | bd = "" |
|
384 | 386 | if blame: |
|
385 | 387 | bd = 'working directory' |
|
386 | 388 | if not blamecache: |
|
387 | 389 | blamecache = getblame(f) |
|
388 | 390 | if n < len(blamecache): |
|
389 | 391 | bl, bu, br = blamecache[n] |
|
390 | 392 | if bl == l: |
|
391 | 393 | bd = '%s@%s' % (bu, br) |
|
392 | 394 | errors.append((f, lineno and n + 1, l, msg, bd)) |
|
393 | 395 | result = False |
|
394 | 396 | |
|
395 | 397 | errors.sort() |
|
396 | 398 | for e in errors: |
|
397 | 399 | logfunc(*e) |
|
398 | 400 | fc += 1 |
|
399 | 401 | if maxerr and fc >= maxerr: |
|
400 | 402 | print " (too many errors, giving up)" |
|
401 | 403 | break |
|
402 | 404 | |
|
403 | 405 | return result |
|
404 | 406 | |
|
405 | 407 | if __name__ == "__main__": |
|
406 | 408 | parser = optparse.OptionParser("%prog [options] [files]") |
|
407 | 409 | parser.add_option("-w", "--warnings", action="store_true", |
|
408 | 410 | help="include warning-level checks") |
|
409 | 411 | parser.add_option("-p", "--per-file", type="int", |
|
410 | 412 | help="max warnings per file") |
|
411 | 413 | parser.add_option("-b", "--blame", action="store_true", |
|
412 | 414 | help="use annotate to generate blame info") |
|
413 | 415 | parser.add_option("", "--debug", action="store_true", |
|
414 | 416 | help="show debug information") |
|
415 | 417 | parser.add_option("", "--nolineno", action="store_false", |
|
416 | 418 | dest='lineno', help="don't show line numbers") |
|
417 | 419 | |
|
418 | 420 | parser.set_defaults(per_file=15, warnings=False, blame=False, debug=False, |
|
419 | 421 | lineno=True) |
|
420 | 422 | (options, args) = parser.parse_args() |
|
421 | 423 | |
|
422 | 424 | if len(args) == 0: |
|
423 | 425 | check = glob.glob("*") |
|
424 | 426 | else: |
|
425 | 427 | check = args |
|
426 | 428 | |
|
427 | 429 | ret = 0 |
|
428 | 430 | for f in check: |
|
429 | 431 | if not checkfile(f, maxerr=options.per_file, warnings=options.warnings, |
|
430 | 432 | blame=options.blame, debug=options.debug, |
|
431 | 433 | lineno=options.lineno): |
|
432 | 434 | ret = 1 |
|
433 | 435 | sys.exit(ret) |
@@ -1,5647 +1,5647 b'' | |||
|
1 | 1 | # commands.py - command processing for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from node import hex, bin, nullid, nullrev, short |
|
9 | 9 | from lock import release |
|
10 | 10 | from i18n import _, gettext |
|
11 | 11 | import os, re, difflib, time, tempfile, errno |
|
12 | 12 | import hg, scmutil, util, revlog, extensions, copies, error, bookmarks |
|
13 | 13 | import patch, help, url, encoding, templatekw, discovery |
|
14 | 14 | import archival, changegroup, cmdutil, hbisect |
|
15 | 15 | import sshserver, hgweb, hgweb.server, commandserver |
|
16 | 16 | import merge as mergemod |
|
17 | 17 | import minirst, revset, fileset |
|
18 | 18 | import dagparser, context, simplemerge |
|
19 | 19 | import random, setdiscovery, treediscovery, dagutil, pvec |
|
20 | 20 | import phases |
|
21 | 21 | |
|
22 | 22 | table = {} |
|
23 | 23 | |
|
24 | 24 | command = cmdutil.command(table) |
|
25 | 25 | |
|
26 | 26 | # common command options |
|
27 | 27 | |
|
28 | 28 | globalopts = [ |
|
29 | 29 | ('R', 'repository', '', |
|
30 | 30 | _('repository root directory or name of overlay bundle file'), |
|
31 | 31 | _('REPO')), |
|
32 | 32 | ('', 'cwd', '', |
|
33 | 33 | _('change working directory'), _('DIR')), |
|
34 | 34 | ('y', 'noninteractive', None, |
|
35 | 35 | _('do not prompt, automatically pick the first choice for all prompts')), |
|
36 | 36 | ('q', 'quiet', None, _('suppress output')), |
|
37 | 37 | ('v', 'verbose', None, _('enable additional output')), |
|
38 | 38 | ('', 'config', [], |
|
39 | 39 | _('set/override config option (use \'section.name=value\')'), |
|
40 | 40 | _('CONFIG')), |
|
41 | 41 | ('', 'debug', None, _('enable debugging output')), |
|
42 | 42 | ('', 'debugger', None, _('start debugger')), |
|
43 | 43 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), |
|
44 | 44 | _('ENCODE')), |
|
45 | 45 | ('', 'encodingmode', encoding.encodingmode, |
|
46 | 46 | _('set the charset encoding mode'), _('MODE')), |
|
47 | 47 | ('', 'traceback', None, _('always print a traceback on exception')), |
|
48 | 48 | ('', 'time', None, _('time how long the command takes')), |
|
49 | 49 | ('', 'profile', None, _('print command execution profile')), |
|
50 | 50 | ('', 'version', None, _('output version information and exit')), |
|
51 | 51 | ('h', 'help', None, _('display help and exit')), |
|
52 | 52 | ] |
|
53 | 53 | |
|
54 | 54 | dryrunopts = [('n', 'dry-run', None, |
|
55 | 55 | _('do not perform actions, just print output'))] |
|
56 | 56 | |
|
57 | 57 | remoteopts = [ |
|
58 | 58 | ('e', 'ssh', '', |
|
59 | 59 | _('specify ssh command to use'), _('CMD')), |
|
60 | 60 | ('', 'remotecmd', '', |
|
61 | 61 | _('specify hg command to run on the remote side'), _('CMD')), |
|
62 | 62 | ('', 'insecure', None, |
|
63 | 63 | _('do not verify server certificate (ignoring web.cacerts config)')), |
|
64 | 64 | ] |
|
65 | 65 | |
|
66 | 66 | walkopts = [ |
|
67 | 67 | ('I', 'include', [], |
|
68 | 68 | _('include names matching the given patterns'), _('PATTERN')), |
|
69 | 69 | ('X', 'exclude', [], |
|
70 | 70 | _('exclude names matching the given patterns'), _('PATTERN')), |
|
71 | 71 | ] |
|
72 | 72 | |
|
73 | 73 | commitopts = [ |
|
74 | 74 | ('m', 'message', '', |
|
75 | 75 | _('use text as commit message'), _('TEXT')), |
|
76 | 76 | ('l', 'logfile', '', |
|
77 | 77 | _('read commit message from file'), _('FILE')), |
|
78 | 78 | ] |
|
79 | 79 | |
|
80 | 80 | commitopts2 = [ |
|
81 | 81 | ('d', 'date', '', |
|
82 | 82 | _('record the specified date as commit date'), _('DATE')), |
|
83 | 83 | ('u', 'user', '', |
|
84 | 84 | _('record the specified user as committer'), _('USER')), |
|
85 | 85 | ] |
|
86 | 86 | |
|
87 | 87 | templateopts = [ |
|
88 | 88 | ('', 'style', '', |
|
89 | 89 | _('display using template map file'), _('STYLE')), |
|
90 | 90 | ('', 'template', '', |
|
91 | 91 | _('display with template'), _('TEMPLATE')), |
|
92 | 92 | ] |
|
93 | 93 | |
|
94 | 94 | logopts = [ |
|
95 | 95 | ('p', 'patch', None, _('show patch')), |
|
96 | 96 | ('g', 'git', None, _('use git extended diff format')), |
|
97 | 97 | ('l', 'limit', '', |
|
98 | 98 | _('limit number of changes displayed'), _('NUM')), |
|
99 | 99 | ('M', 'no-merges', None, _('do not show merges')), |
|
100 | 100 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
101 | 101 | ] + templateopts |
|
102 | 102 | |
|
103 | 103 | diffopts = [ |
|
104 | 104 | ('a', 'text', None, _('treat all files as text')), |
|
105 | 105 | ('g', 'git', None, _('use git extended diff format')), |
|
106 | 106 | ('', 'nodates', None, _('omit dates from diff headers')) |
|
107 | 107 | ] |
|
108 | 108 | |
|
109 | 109 | diffwsopts = [ |
|
110 | 110 | ('w', 'ignore-all-space', None, |
|
111 | 111 | _('ignore white space when comparing lines')), |
|
112 | 112 | ('b', 'ignore-space-change', None, |
|
113 | 113 | _('ignore changes in the amount of white space')), |
|
114 | 114 | ('B', 'ignore-blank-lines', None, |
|
115 | 115 | _('ignore changes whose lines are all blank')), |
|
116 | 116 | ] |
|
117 | 117 | |
|
118 | 118 | diffopts2 = [ |
|
119 | 119 | ('p', 'show-function', None, _('show which function each change is in')), |
|
120 | 120 | ('', 'reverse', None, _('produce a diff that undoes the changes')), |
|
121 | 121 | ] + diffwsopts + [ |
|
122 | 122 | ('U', 'unified', '', |
|
123 | 123 | _('number of lines of context to show'), _('NUM')), |
|
124 | 124 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
125 | 125 | ] |
|
126 | 126 | |
|
127 | 127 | mergetoolopts = [ |
|
128 | 128 | ('t', 'tool', '', _('specify merge tool')), |
|
129 | 129 | ] |
|
130 | 130 | |
|
131 | 131 | similarityopts = [ |
|
132 | 132 | ('s', 'similarity', '', |
|
133 | 133 | _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY')) |
|
134 | 134 | ] |
|
135 | 135 | |
|
136 | 136 | subrepoopts = [ |
|
137 | 137 | ('S', 'subrepos', None, |
|
138 | 138 | _('recurse into subrepositories')) |
|
139 | 139 | ] |
|
140 | 140 | |
|
141 | 141 | # Commands start here, listed alphabetically |
|
142 | 142 | |
|
143 | 143 | @command('^add', |
|
144 | 144 | walkopts + subrepoopts + dryrunopts, |
|
145 | 145 | _('[OPTION]... [FILE]...')) |
|
146 | 146 | def add(ui, repo, *pats, **opts): |
|
147 | 147 | """add the specified files on the next commit |
|
148 | 148 | |
|
149 | 149 | Schedule files to be version controlled and added to the |
|
150 | 150 | repository. |
|
151 | 151 | |
|
152 | 152 | The files will be added to the repository at the next commit. To |
|
153 | 153 | undo an add before that, see :hg:`forget`. |
|
154 | 154 | |
|
155 | 155 | If no names are given, add all files to the repository. |
|
156 | 156 | |
|
157 | 157 | .. container:: verbose |
|
158 | 158 | |
|
159 | 159 | An example showing how new (unknown) files are added |
|
160 | 160 | automatically by :hg:`add`:: |
|
161 | 161 | |
|
162 | 162 | $ ls |
|
163 | 163 | foo.c |
|
164 | 164 | $ hg status |
|
165 | 165 | ? foo.c |
|
166 | 166 | $ hg add |
|
167 | 167 | adding foo.c |
|
168 | 168 | $ hg status |
|
169 | 169 | A foo.c |
|
170 | 170 | |
|
171 | 171 | Returns 0 if all files are successfully added. |
|
172 | 172 | """ |
|
173 | 173 | |
|
174 | 174 | m = scmutil.match(repo[None], pats, opts) |
|
175 | 175 | rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), |
|
176 | 176 | opts.get('subrepos'), prefix="", explicitonly=False) |
|
177 | 177 | return rejected and 1 or 0 |
|
178 | 178 | |
|
179 | 179 | @command('addremove', |
|
180 | 180 | similarityopts + walkopts + dryrunopts, |
|
181 | 181 | _('[OPTION]... [FILE]...')) |
|
182 | 182 | def addremove(ui, repo, *pats, **opts): |
|
183 | 183 | """add all new files, delete all missing files |
|
184 | 184 | |
|
185 | 185 | Add all new files and remove all missing files from the |
|
186 | 186 | repository. |
|
187 | 187 | |
|
188 | 188 | New files are ignored if they match any of the patterns in |
|
189 | 189 | ``.hgignore``. As with add, these changes take effect at the next |
|
190 | 190 | commit. |
|
191 | 191 | |
|
192 | 192 | Use the -s/--similarity option to detect renamed files. With a |
|
193 | 193 | parameter greater than 0, this compares every removed file with |
|
194 | 194 | every added file and records those similar enough as renames. This |
|
195 | 195 | option takes a percentage between 0 (disabled) and 100 (files must |
|
196 | 196 | be identical) as its parameter. Detecting renamed files this way |
|
197 | 197 | can be expensive. After using this option, :hg:`status -C` can be |
|
198 | 198 | used to check which files were identified as moved or renamed. |
|
199 | 199 | |
|
200 | 200 | Returns 0 if all files are successfully added. |
|
201 | 201 | """ |
|
202 | 202 | try: |
|
203 | 203 | sim = float(opts.get('similarity') or 100) |
|
204 | 204 | except ValueError: |
|
205 | 205 | raise util.Abort(_('similarity must be a number')) |
|
206 | 206 | if sim < 0 or sim > 100: |
|
207 | 207 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
208 | 208 | return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0) |
|
209 | 209 | |
|
210 | 210 | @command('^annotate|blame', |
|
211 | 211 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), |
|
212 | 212 | ('', 'follow', None, |
|
213 | 213 | _('follow copies/renames and list the filename (DEPRECATED)')), |
|
214 | 214 | ('', 'no-follow', None, _("don't follow copies and renames")), |
|
215 | 215 | ('a', 'text', None, _('treat all files as text')), |
|
216 | 216 | ('u', 'user', None, _('list the author (long with -v)')), |
|
217 | 217 | ('f', 'file', None, _('list the filename')), |
|
218 | 218 | ('d', 'date', None, _('list the date (short with -q)')), |
|
219 | 219 | ('n', 'number', None, _('list the revision number (default)')), |
|
220 | 220 | ('c', 'changeset', None, _('list the changeset')), |
|
221 | 221 | ('l', 'line-number', None, _('show line number at the first appearance')) |
|
222 | 222 | ] + diffwsopts + walkopts, |
|
223 | 223 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')) |
|
224 | 224 | def annotate(ui, repo, *pats, **opts): |
|
225 | 225 | """show changeset information by line for each file |
|
226 | 226 | |
|
227 | 227 | List changes in files, showing the revision id responsible for |
|
228 | 228 | each line |
|
229 | 229 | |
|
230 | 230 | This command is useful for discovering when a change was made and |
|
231 | 231 | by whom. |
|
232 | 232 | |
|
233 | 233 | Without the -a/--text option, annotate will avoid processing files |
|
234 | 234 | it detects as binary. With -a, annotate will annotate the file |
|
235 | 235 | anyway, although the results will probably be neither useful |
|
236 | 236 | nor desirable. |
|
237 | 237 | |
|
238 | 238 | Returns 0 on success. |
|
239 | 239 | """ |
|
240 | 240 | if opts.get('follow'): |
|
241 | 241 | # --follow is deprecated and now just an alias for -f/--file |
|
242 | 242 | # to mimic the behavior of Mercurial before version 1.5 |
|
243 | 243 | opts['file'] = True |
|
244 | 244 | |
|
245 | 245 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
246 | 246 | getdate = util.cachefunc(lambda x: datefunc(x[0].date())) |
|
247 | 247 | |
|
248 | 248 | if not pats: |
|
249 | 249 | raise util.Abort(_('at least one filename or pattern is required')) |
|
250 | 250 | |
|
251 | 251 | hexfn = ui.debugflag and hex or short |
|
252 | 252 | |
|
253 | 253 | opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())), |
|
254 | 254 | ('number', ' ', lambda x: str(x[0].rev())), |
|
255 | 255 | ('changeset', ' ', lambda x: hexfn(x[0].node())), |
|
256 | 256 | ('date', ' ', getdate), |
|
257 | 257 | ('file', ' ', lambda x: x[0].path()), |
|
258 | 258 | ('line_number', ':', lambda x: str(x[1])), |
|
259 | 259 | ] |
|
260 | 260 | |
|
261 | 261 | if (not opts.get('user') and not opts.get('changeset') |
|
262 | 262 | and not opts.get('date') and not opts.get('file')): |
|
263 | 263 | opts['number'] = True |
|
264 | 264 | |
|
265 | 265 | linenumber = opts.get('line_number') is not None |
|
266 | 266 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): |
|
267 | 267 | raise util.Abort(_('at least one of -n/-c is required for -l')) |
|
268 | 268 | |
|
269 | 269 | funcmap = [(func, sep) for op, sep, func in opmap if opts.get(op)] |
|
270 | 270 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column |
|
271 | 271 | |
|
272 | 272 | def bad(x, y): |
|
273 | 273 | raise util.Abort("%s: %s" % (x, y)) |
|
274 | 274 | |
|
275 | 275 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
276 | 276 | m = scmutil.match(ctx, pats, opts) |
|
277 | 277 | m.bad = bad |
|
278 | 278 | follow = not opts.get('no_follow') |
|
279 | 279 | diffopts = patch.diffopts(ui, opts, section='annotate') |
|
280 | 280 | for abs in ctx.walk(m): |
|
281 | 281 | fctx = ctx[abs] |
|
282 | 282 | if not opts.get('text') and util.binary(fctx.data()): |
|
283 | 283 | ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
|
284 | 284 | continue |
|
285 | 285 | |
|
286 | 286 | lines = fctx.annotate(follow=follow, linenumber=linenumber, |
|
287 | 287 | diffopts=diffopts) |
|
288 | 288 | pieces = [] |
|
289 | 289 | |
|
290 | 290 | for f, sep in funcmap: |
|
291 | 291 | l = [f(n) for n, dummy in lines] |
|
292 | 292 | if l: |
|
293 | 293 | sized = [(x, encoding.colwidth(x)) for x in l] |
|
294 | 294 | ml = max([w for x, w in sized]) |
|
295 | 295 | pieces.append(["%s%s%s" % (sep, ' ' * (ml - w), x) |
|
296 | 296 | for x, w in sized]) |
|
297 | 297 | |
|
298 | 298 | if pieces: |
|
299 | 299 | for p, l in zip(zip(*pieces), lines): |
|
300 | 300 | ui.write("%s: %s" % ("".join(p), l[1])) |
|
301 | 301 | |
|
302 | 302 | if lines and not lines[-1][1].endswith('\n'): |
|
303 | 303 | ui.write('\n') |
|
304 | 304 | |
|
305 | 305 | @command('archive', |
|
306 | 306 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
307 | 307 | ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
308 | 308 | _('PREFIX')), |
|
309 | 309 | ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
310 | 310 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
311 | 311 | ] + subrepoopts + walkopts, |
|
312 | 312 | _('[OPTION]... DEST')) |
|
313 | 313 | def archive(ui, repo, dest, **opts): |
|
314 | 314 | '''create an unversioned archive of a repository revision |
|
315 | 315 | |
|
316 | 316 | By default, the revision used is the parent of the working |
|
317 | 317 | directory; use -r/--rev to specify a different revision. |
|
318 | 318 | |
|
319 | 319 | The archive type is automatically detected based on file |
|
320 | 320 | extension (or override using -t/--type). |
|
321 | 321 | |
|
322 | 322 | .. container:: verbose |
|
323 | 323 | |
|
324 | 324 | Examples: |
|
325 | 325 | |
|
326 | 326 | - create a zip file containing the 1.0 release:: |
|
327 | 327 | |
|
328 | 328 | hg archive -r 1.0 project-1.0.zip |
|
329 | 329 | |
|
330 | 330 | - create a tarball excluding .hg files:: |
|
331 | 331 | |
|
332 | 332 | hg archive project.tar.gz -X ".hg*" |
|
333 | 333 | |
|
334 | 334 | Valid types are: |
|
335 | 335 | |
|
336 | 336 | :``files``: a directory full of files (default) |
|
337 | 337 | :``tar``: tar archive, uncompressed |
|
338 | 338 | :``tbz2``: tar archive, compressed using bzip2 |
|
339 | 339 | :``tgz``: tar archive, compressed using gzip |
|
340 | 340 | :``uzip``: zip archive, uncompressed |
|
341 | 341 | :``zip``: zip archive, compressed using deflate |
|
342 | 342 | |
|
343 | 343 | The exact name of the destination archive or directory is given |
|
344 | 344 | using a format string; see :hg:`help export` for details. |
|
345 | 345 | |
|
346 | 346 | Each member added to an archive file has a directory prefix |
|
347 | 347 | prepended. Use -p/--prefix to specify a format string for the |
|
348 | 348 | prefix. The default is the basename of the archive, with suffixes |
|
349 | 349 | removed. |
|
350 | 350 | |
|
351 | 351 | Returns 0 on success. |
|
352 | 352 | ''' |
|
353 | 353 | |
|
354 | 354 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
355 | 355 | if not ctx: |
|
356 | 356 | raise util.Abort(_('no working directory: please specify a revision')) |
|
357 | 357 | node = ctx.node() |
|
358 | 358 | dest = cmdutil.makefilename(repo, dest, node) |
|
359 | 359 | if os.path.realpath(dest) == repo.root: |
|
360 | 360 | raise util.Abort(_('repository root cannot be destination')) |
|
361 | 361 | |
|
362 | 362 | kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
363 | 363 | prefix = opts.get('prefix') |
|
364 | 364 | |
|
365 | 365 | if dest == '-': |
|
366 | 366 | if kind == 'files': |
|
367 | 367 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
368 | 368 | dest = cmdutil.makefileobj(repo, dest) |
|
369 | 369 | if not prefix: |
|
370 | 370 | prefix = os.path.basename(repo.root) + '-%h' |
|
371 | 371 | |
|
372 | 372 | prefix = cmdutil.makefilename(repo, prefix, node) |
|
373 | 373 | matchfn = scmutil.match(ctx, [], opts) |
|
374 | 374 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
375 | 375 | matchfn, prefix, subrepos=opts.get('subrepos')) |
|
376 | 376 | |
|
377 | 377 | @command('backout', |
|
378 | 378 | [('', 'merge', None, _('merge with old dirstate parent after backout')), |
|
379 | 379 | ('', 'parent', '', |
|
380 | 380 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), |
|
381 | 381 | ('r', 'rev', '', _('revision to backout'), _('REV')), |
|
382 | 382 | ] + mergetoolopts + walkopts + commitopts + commitopts2, |
|
383 | 383 | _('[OPTION]... [-r] REV')) |
|
384 | 384 | def backout(ui, repo, node=None, rev=None, **opts): |
|
385 | 385 | '''reverse effect of earlier changeset |
|
386 | 386 | |
|
387 | 387 | Prepare a new changeset with the effect of REV undone in the |
|
388 | 388 | current working directory. |
|
389 | 389 | |
|
390 | 390 | If REV is the parent of the working directory, then this new changeset |
|
391 | 391 | is committed automatically. Otherwise, hg needs to merge the |
|
392 | 392 | changes and the merged result is left uncommitted. |
|
393 | 393 | |
|
394 | 394 | .. note:: |
|
395 | 395 | backout cannot be used to fix either an unwanted or |
|
396 | 396 | incorrect merge. |
|
397 | 397 | |
|
398 | 398 | .. container:: verbose |
|
399 | 399 | |
|
400 | 400 | By default, the pending changeset will have one parent, |
|
401 | 401 | maintaining a linear history. With --merge, the pending |
|
402 | 402 | changeset will instead have two parents: the old parent of the |
|
403 | 403 | working directory and a new child of REV that simply undoes REV. |
|
404 | 404 | |
|
405 | 405 | Before version 1.7, the behavior without --merge was equivalent |
|
406 | 406 | to specifying --merge followed by :hg:`update --clean .` to |
|
407 | 407 | cancel the merge and leave the child of REV as a head to be |
|
408 | 408 | merged separately. |
|
409 | 409 | |
|
410 | 410 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
411 | 411 | |
|
412 | 412 | Returns 0 on success. |
|
413 | 413 | ''' |
|
414 | 414 | if rev and node: |
|
415 | 415 | raise util.Abort(_("please specify just one revision")) |
|
416 | 416 | |
|
417 | 417 | if not rev: |
|
418 | 418 | rev = node |
|
419 | 419 | |
|
420 | 420 | if not rev: |
|
421 | 421 | raise util.Abort(_("please specify a revision to backout")) |
|
422 | 422 | |
|
423 | 423 | date = opts.get('date') |
|
424 | 424 | if date: |
|
425 | 425 | opts['date'] = util.parsedate(date) |
|
426 | 426 | |
|
427 | 427 | cmdutil.bailifchanged(repo) |
|
428 | 428 | node = scmutil.revsingle(repo, rev).node() |
|
429 | 429 | |
|
430 | 430 | op1, op2 = repo.dirstate.parents() |
|
431 | 431 | a = repo.changelog.ancestor(op1, node) |
|
432 | 432 | if a != node: |
|
433 | 433 | raise util.Abort(_('cannot backout change on a different branch')) |
|
434 | 434 | |
|
435 | 435 | p1, p2 = repo.changelog.parents(node) |
|
436 | 436 | if p1 == nullid: |
|
437 | 437 | raise util.Abort(_('cannot backout a change with no parents')) |
|
438 | 438 | if p2 != nullid: |
|
439 | 439 | if not opts.get('parent'): |
|
440 | 440 | raise util.Abort(_('cannot backout a merge changeset')) |
|
441 | 441 | p = repo.lookup(opts['parent']) |
|
442 | 442 | if p not in (p1, p2): |
|
443 | 443 | raise util.Abort(_('%s is not a parent of %s') % |
|
444 | 444 | (short(p), short(node))) |
|
445 | 445 | parent = p |
|
446 | 446 | else: |
|
447 | 447 | if opts.get('parent'): |
|
448 | 448 | raise util.Abort(_('cannot use --parent on non-merge changeset')) |
|
449 | 449 | parent = p1 |
|
450 | 450 | |
|
451 | 451 | # the backout should appear on the same branch |
|
452 | 452 | branch = repo.dirstate.branch() |
|
453 | 453 | hg.clean(repo, node, show_stats=False) |
|
454 | 454 | repo.dirstate.setbranch(branch) |
|
455 | 455 | revert_opts = opts.copy() |
|
456 | 456 | revert_opts['date'] = None |
|
457 | 457 | revert_opts['all'] = True |
|
458 | 458 | revert_opts['rev'] = hex(parent) |
|
459 | 459 | revert_opts['no_backup'] = None |
|
460 | 460 | revert(ui, repo, **revert_opts) |
|
461 | 461 | if not opts.get('merge') and op1 != node: |
|
462 | 462 | try: |
|
463 | 463 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
464 | 464 | return hg.update(repo, op1) |
|
465 | 465 | finally: |
|
466 | 466 | ui.setconfig('ui', 'forcemerge', '') |
|
467 | 467 | |
|
468 | 468 | commit_opts = opts.copy() |
|
469 | 469 | commit_opts['addremove'] = False |
|
470 | 470 | if not commit_opts['message'] and not commit_opts['logfile']: |
|
471 | 471 | # we don't translate commit messages |
|
472 | 472 | commit_opts['message'] = "Backed out changeset %s" % short(node) |
|
473 | 473 | commit_opts['force_editor'] = True |
|
474 | 474 | commit(ui, repo, **commit_opts) |
|
475 | 475 | def nice(node): |
|
476 | 476 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
477 | 477 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
478 | 478 | (nice(repo.changelog.tip()), nice(node))) |
|
479 | 479 | if opts.get('merge') and op1 != node: |
|
480 | 480 | hg.clean(repo, op1, show_stats=False) |
|
481 | 481 | ui.status(_('merging with changeset %s\n') |
|
482 | 482 | % nice(repo.changelog.tip())) |
|
483 | 483 | try: |
|
484 | 484 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
485 | 485 | return hg.merge(repo, hex(repo.changelog.tip())) |
|
486 | 486 | finally: |
|
487 | 487 | ui.setconfig('ui', 'forcemerge', '') |
|
488 | 488 | return 0 |
|
489 | 489 | |
|
490 | 490 | @command('bisect', |
|
491 | 491 | [('r', 'reset', False, _('reset bisect state')), |
|
492 | 492 | ('g', 'good', False, _('mark changeset good')), |
|
493 | 493 | ('b', 'bad', False, _('mark changeset bad')), |
|
494 | 494 | ('s', 'skip', False, _('skip testing changeset')), |
|
495 | 495 | ('e', 'extend', False, _('extend the bisect range')), |
|
496 | 496 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), |
|
497 | 497 | ('U', 'noupdate', False, _('do not update to target'))], |
|
498 | 498 | _("[-gbsr] [-U] [-c CMD] [REV]")) |
|
499 | 499 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
500 | 500 | reset=None, good=None, bad=None, skip=None, extend=None, |
|
501 | 501 | noupdate=None): |
|
502 | 502 | """subdivision search of changesets |
|
503 | 503 | |
|
504 | 504 | This command helps to find changesets which introduce problems. To |
|
505 | 505 | use, mark the earliest changeset you know exhibits the problem as |
|
506 | 506 | bad, then mark the latest changeset which is free from the problem |
|
507 | 507 | as good. Bisect will update your working directory to a revision |
|
508 | 508 | for testing (unless the -U/--noupdate option is specified). Once |
|
509 | 509 | you have performed tests, mark the working directory as good or |
|
510 | 510 | bad, and bisect will either update to another candidate changeset |
|
511 | 511 | or announce that it has found the bad revision. |
|
512 | 512 | |
|
513 | 513 | As a shortcut, you can also use the revision argument to mark a |
|
514 | 514 | revision as good or bad without checking it out first. |
|
515 | 515 | |
|
516 | 516 | If you supply a command, it will be used for automatic bisection. |
|
517 | 517 | Its exit status will be used to mark revisions as good or bad: |
|
518 | 518 | status 0 means good, 125 means to skip the revision, 127 |
|
519 | 519 | (command not found) will abort the bisection, and any other |
|
520 | 520 | non-zero exit status means the revision is bad. |
|
521 | 521 | |
|
522 | 522 | .. container:: verbose |
|
523 | 523 | |
|
524 | 524 | Some examples: |
|
525 | 525 | |
|
526 | 526 | - start a bisection with known bad revision 12, and good revision 34:: |
|
527 | 527 | |
|
528 | 528 | hg bisect --bad 34 |
|
529 | 529 | hg bisect --good 12 |
|
530 | 530 | |
|
531 | 531 | - advance the current bisection by marking current revision as good or |
|
532 | 532 | bad:: |
|
533 | 533 | |
|
534 | 534 | hg bisect --good |
|
535 | 535 | hg bisect --bad |
|
536 | 536 | |
|
537 | 537 | - mark the current revision, or a known revision, to be skipped (eg. if |
|
538 | 538 | that revision is not usable because of another issue):: |
|
539 | 539 | |
|
540 | 540 | hg bisect --skip |
|
541 | 541 | hg bisect --skip 23 |
|
542 | 542 | |
|
543 | 543 | - forget the current bisection:: |
|
544 | 544 | |
|
545 | 545 | hg bisect --reset |
|
546 | 546 | |
|
547 | 547 | - use 'make && make tests' to automatically find the first broken |
|
548 | 548 | revision:: |
|
549 | 549 | |
|
550 | 550 | hg bisect --reset |
|
551 | 551 | hg bisect --bad 34 |
|
552 | 552 | hg bisect --good 12 |
|
553 | 553 | hg bisect --command 'make && make tests' |
|
554 | 554 | |
|
555 | 555 | - see all changesets whose states are already known in the current |
|
556 | 556 | bisection:: |
|
557 | 557 | |
|
558 | 558 | hg log -r "bisect(pruned)" |
|
559 | 559 | |
|
560 | 560 | - see all changesets that took part in the current bisection:: |
|
561 | 561 | |
|
562 | 562 | hg log -r "bisect(range)" |
|
563 | 563 | |
|
564 | 564 | - with the graphlog extension, you can even get a nice graph:: |
|
565 | 565 | |
|
566 | 566 | hg log --graph -r "bisect(range)" |
|
567 | 567 | |
|
568 | 568 | See :hg:`help revsets` for more about the `bisect()` keyword. |
|
569 | 569 | |
|
570 | 570 | Returns 0 on success. |
|
571 | 571 | """ |
|
572 | 572 | def extendbisectrange(nodes, good): |
|
573 | 573 | # bisect is incomplete when it ends on a merge node and |
|
574 | 574 | # one of the parent was not checked. |
|
575 | 575 | parents = repo[nodes[0]].parents() |
|
576 | 576 | if len(parents) > 1: |
|
577 | 577 | side = good and state['bad'] or state['good'] |
|
578 | 578 | num = len(set(i.node() for i in parents) & set(side)) |
|
579 | 579 | if num == 1: |
|
580 | 580 | return parents[0].ancestor(parents[1]) |
|
581 | 581 | return None |
|
582 | 582 | |
|
583 | 583 | def print_result(nodes, good): |
|
584 | 584 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
585 | 585 | if len(nodes) == 1: |
|
586 | 586 | # narrowed it down to a single revision |
|
587 | 587 | if good: |
|
588 | 588 | ui.write(_("The first good revision is:\n")) |
|
589 | 589 | else: |
|
590 | 590 | ui.write(_("The first bad revision is:\n")) |
|
591 | 591 | displayer.show(repo[nodes[0]]) |
|
592 | 592 | extendnode = extendbisectrange(nodes, good) |
|
593 | 593 | if extendnode is not None: |
|
594 | 594 | ui.write(_('Not all ancestors of this changeset have been' |
|
595 | 595 | ' checked.\nUse bisect --extend to continue the ' |
|
596 | 596 | 'bisection from\nthe common ancestor, %s.\n') |
|
597 | 597 | % extendnode) |
|
598 | 598 | else: |
|
599 | 599 | # multiple possible revisions |
|
600 | 600 | if good: |
|
601 | 601 | ui.write(_("Due to skipped revisions, the first " |
|
602 | 602 | "good revision could be any of:\n")) |
|
603 | 603 | else: |
|
604 | 604 | ui.write(_("Due to skipped revisions, the first " |
|
605 | 605 | "bad revision could be any of:\n")) |
|
606 | 606 | for n in nodes: |
|
607 | 607 | displayer.show(repo[n]) |
|
608 | 608 | displayer.close() |
|
609 | 609 | |
|
610 | 610 | def check_state(state, interactive=True): |
|
611 | 611 | if not state['good'] or not state['bad']: |
|
612 | 612 | if (good or bad or skip or reset) and interactive: |
|
613 | 613 | return |
|
614 | 614 | if not state['good']: |
|
615 | 615 | raise util.Abort(_('cannot bisect (no known good revisions)')) |
|
616 | 616 | else: |
|
617 | 617 | raise util.Abort(_('cannot bisect (no known bad revisions)')) |
|
618 | 618 | return True |
|
619 | 619 | |
|
620 | 620 | # backward compatibility |
|
621 | 621 | if rev in "good bad reset init".split(): |
|
622 | 622 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
623 | 623 | cmd, rev, extra = rev, extra, None |
|
624 | 624 | if cmd == "good": |
|
625 | 625 | good = True |
|
626 | 626 | elif cmd == "bad": |
|
627 | 627 | bad = True |
|
628 | 628 | else: |
|
629 | 629 | reset = True |
|
630 | 630 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: |
|
631 | 631 | raise util.Abort(_('incompatible arguments')) |
|
632 | 632 | |
|
633 | 633 | if reset: |
|
634 | 634 | p = repo.join("bisect.state") |
|
635 | 635 | if os.path.exists(p): |
|
636 | 636 | os.unlink(p) |
|
637 | 637 | return |
|
638 | 638 | |
|
639 | 639 | state = hbisect.load_state(repo) |
|
640 | 640 | |
|
641 | 641 | if command: |
|
642 | 642 | changesets = 1 |
|
643 | 643 | try: |
|
644 | 644 | while changesets: |
|
645 | 645 | # update state |
|
646 | 646 | status = util.system(command, out=ui.fout) |
|
647 | 647 | if status == 125: |
|
648 | 648 | transition = "skip" |
|
649 | 649 | elif status == 0: |
|
650 | 650 | transition = "good" |
|
651 | 651 | # status < 0 means process was killed |
|
652 | 652 | elif status == 127: |
|
653 | 653 | raise util.Abort(_("failed to execute %s") % command) |
|
654 | 654 | elif status < 0: |
|
655 | 655 | raise util.Abort(_("%s killed") % command) |
|
656 | 656 | else: |
|
657 | 657 | transition = "bad" |
|
658 | 658 | ctx = scmutil.revsingle(repo, rev) |
|
659 | 659 | rev = None # clear for future iterations |
|
660 | 660 | state[transition].append(ctx.node()) |
|
661 | 661 | ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
662 | 662 | check_state(state, interactive=False) |
|
663 | 663 | # bisect |
|
664 | 664 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
665 | 665 | # update to next check |
|
666 | 666 | cmdutil.bailifchanged(repo) |
|
667 | 667 | hg.clean(repo, nodes[0], show_stats=False) |
|
668 | 668 | finally: |
|
669 | 669 | hbisect.save_state(repo, state) |
|
670 | 670 | print_result(nodes, good) |
|
671 | 671 | return |
|
672 | 672 | |
|
673 | 673 | # update state |
|
674 | 674 | |
|
675 | 675 | if rev: |
|
676 | 676 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] |
|
677 | 677 | else: |
|
678 | 678 | nodes = [repo.lookup('.')] |
|
679 | 679 | |
|
680 | 680 | if good or bad or skip: |
|
681 | 681 | if good: |
|
682 | 682 | state['good'] += nodes |
|
683 | 683 | elif bad: |
|
684 | 684 | state['bad'] += nodes |
|
685 | 685 | elif skip: |
|
686 | 686 | state['skip'] += nodes |
|
687 | 687 | hbisect.save_state(repo, state) |
|
688 | 688 | |
|
689 | 689 | if not check_state(state): |
|
690 | 690 | return |
|
691 | 691 | |
|
692 | 692 | # actually bisect |
|
693 | 693 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
694 | 694 | if extend: |
|
695 | 695 | if not changesets: |
|
696 | 696 | extendnode = extendbisectrange(nodes, good) |
|
697 | 697 | if extendnode is not None: |
|
698 | 698 | ui.write(_("Extending search to changeset %d:%s\n" |
|
699 | 699 | % (extendnode.rev(), extendnode))) |
|
700 | 700 | if noupdate: |
|
701 | 701 | return |
|
702 | 702 | cmdutil.bailifchanged(repo) |
|
703 | 703 | return hg.clean(repo, extendnode.node()) |
|
704 | 704 | raise util.Abort(_("nothing to extend")) |
|
705 | 705 | |
|
706 | 706 | if changesets == 0: |
|
707 | 707 | print_result(nodes, good) |
|
708 | 708 | else: |
|
709 | 709 | assert len(nodes) == 1 # only a single node can be tested next |
|
710 | 710 | node = nodes[0] |
|
711 | 711 | # compute the approximate number of remaining tests |
|
712 | 712 | tests, size = 0, 2 |
|
713 | 713 | while size <= changesets: |
|
714 | 714 | tests, size = tests + 1, size * 2 |
|
715 | 715 | rev = repo.changelog.rev(node) |
|
716 | 716 | ui.write(_("Testing changeset %d:%s " |
|
717 | 717 | "(%d changesets remaining, ~%d tests)\n") |
|
718 | 718 | % (rev, short(node), changesets, tests)) |
|
719 | 719 | if not noupdate: |
|
720 | 720 | cmdutil.bailifchanged(repo) |
|
721 | 721 | return hg.clean(repo, node) |
|
722 | 722 | |
|
723 | 723 | @command('bookmarks', |
|
724 | 724 | [('f', 'force', False, _('force')), |
|
725 | 725 | ('r', 'rev', '', _('revision'), _('REV')), |
|
726 | 726 | ('d', 'delete', False, _('delete a given bookmark')), |
|
727 | 727 | ('m', 'rename', '', _('rename a given bookmark'), _('NAME')), |
|
728 | 728 | ('i', 'inactive', False, _('mark a bookmark inactive'))], |
|
729 | 729 | _('hg bookmarks [-f] [-d] [-i] [-m NAME] [-r REV] [NAME]')) |
|
730 | 730 | def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, |
|
731 | 731 | rename=None, inactive=False): |
|
732 | 732 | '''track a line of development with movable markers |
|
733 | 733 | |
|
734 | 734 | Bookmarks are pointers to certain commits that move when committing. |
|
735 | 735 | Bookmarks are local. They can be renamed, copied and deleted. It is |
|
736 | 736 | possible to use :hg:`merge NAME` to merge from a given bookmark, and |
|
737 | 737 | :hg:`update NAME` to update to a given bookmark. |
|
738 | 738 | |
|
739 | 739 | You can use :hg:`bookmark NAME` to set a bookmark on the working |
|
740 | 740 | directory's parent revision with the given name. If you specify |
|
741 | 741 | a revision using -r REV (where REV may be an existing bookmark), |
|
742 | 742 | the bookmark is assigned to that revision. |
|
743 | 743 | |
|
744 | 744 | Bookmarks can be pushed and pulled between repositories (see :hg:`help |
|
745 | 745 | push` and :hg:`help pull`). This requires both the local and remote |
|
746 | 746 | repositories to support bookmarks. For versions prior to 1.8, this means |
|
747 | 747 | the bookmarks extension must be enabled. |
|
748 | 748 | |
|
749 | 749 | With -i/--inactive, the new bookmark will not be made the active |
|
750 | 750 | bookmark. If -r/--rev is given, the new bookmark will not be made |
|
751 | 751 | active even if -i/--inactive is not given. If no NAME is given, the |
|
752 | 752 | current active bookmark will be marked inactive. |
|
753 | 753 | ''' |
|
754 | 754 | hexfn = ui.debugflag and hex or short |
|
755 | 755 | marks = repo._bookmarks |
|
756 | 756 | cur = repo.changectx('.').node() |
|
757 | 757 | |
|
758 | 758 | if delete: |
|
759 | 759 | if mark is None: |
|
760 | 760 | raise util.Abort(_("bookmark name required")) |
|
761 | 761 | if mark not in marks: |
|
762 | 762 | raise util.Abort(_("bookmark '%s' does not exist") % mark) |
|
763 | 763 | if mark == repo._bookmarkcurrent: |
|
764 | 764 | bookmarks.setcurrent(repo, None) |
|
765 | 765 | del marks[mark] |
|
766 | 766 | bookmarks.write(repo) |
|
767 | 767 | return |
|
768 | 768 | |
|
769 | 769 | if rename: |
|
770 | 770 | if rename not in marks: |
|
771 | 771 | raise util.Abort(_("bookmark '%s' does not exist") % rename) |
|
772 | 772 | if mark in marks and not force: |
|
773 | 773 | raise util.Abort(_("bookmark '%s' already exists " |
|
774 | 774 | "(use -f to force)") % mark) |
|
775 | 775 | if mark is None: |
|
776 | 776 | raise util.Abort(_("new bookmark name required")) |
|
777 | 777 | marks[mark] = marks[rename] |
|
778 | 778 | if repo._bookmarkcurrent == rename and not inactive: |
|
779 | 779 | bookmarks.setcurrent(repo, mark) |
|
780 | 780 | del marks[rename] |
|
781 | 781 | bookmarks.write(repo) |
|
782 | 782 | return |
|
783 | 783 | |
|
784 | 784 | if mark is not None: |
|
785 | 785 | if "\n" in mark: |
|
786 | 786 | raise util.Abort(_("bookmark name cannot contain newlines")) |
|
787 | 787 | mark = mark.strip() |
|
788 | 788 | if not mark: |
|
789 | 789 | raise util.Abort(_("bookmark names cannot consist entirely of " |
|
790 | 790 | "whitespace")) |
|
791 | 791 | if inactive and mark == repo._bookmarkcurrent: |
|
792 | 792 | bookmarks.setcurrent(repo, None) |
|
793 | 793 | return |
|
794 | 794 | if mark in marks and not force: |
|
795 | 795 | raise util.Abort(_("bookmark '%s' already exists " |
|
796 | 796 | "(use -f to force)") % mark) |
|
797 | 797 | if ((mark in repo.branchtags() or mark == repo.dirstate.branch()) |
|
798 | 798 | and not force): |
|
799 | 799 | raise util.Abort( |
|
800 | 800 | _("a bookmark cannot have the name of an existing branch")) |
|
801 | 801 | if rev: |
|
802 | 802 | marks[mark] = repo.lookup(rev) |
|
803 | 803 | else: |
|
804 | 804 | marks[mark] = cur |
|
805 | 805 | if not inactive and cur == marks[mark]: |
|
806 | 806 | bookmarks.setcurrent(repo, mark) |
|
807 | 807 | bookmarks.write(repo) |
|
808 | 808 | return |
|
809 | 809 | |
|
810 | 810 | if mark is None: |
|
811 | 811 | if rev: |
|
812 | 812 | raise util.Abort(_("bookmark name required")) |
|
813 | 813 | if len(marks) == 0: |
|
814 | 814 | ui.status(_("no bookmarks set\n")) |
|
815 | 815 | else: |
|
816 | 816 | for bmark, n in sorted(marks.iteritems()): |
|
817 | 817 | current = repo._bookmarkcurrent |
|
818 | 818 | if bmark == current and n == cur: |
|
819 | 819 | prefix, label = '*', 'bookmarks.current' |
|
820 | 820 | else: |
|
821 | 821 | prefix, label = ' ', '' |
|
822 | 822 | |
|
823 | 823 | if ui.quiet: |
|
824 | 824 | ui.write("%s\n" % bmark, label=label) |
|
825 | 825 | else: |
|
826 | 826 | ui.write(" %s %-25s %d:%s\n" % ( |
|
827 | 827 | prefix, bmark, repo.changelog.rev(n), hexfn(n)), |
|
828 | 828 | label=label) |
|
829 | 829 | return |
|
830 | 830 | |
|
831 | 831 | @command('branch', |
|
832 | 832 | [('f', 'force', None, |
|
833 | 833 | _('set branch name even if it shadows an existing branch')), |
|
834 | 834 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
835 | 835 | _('[-fC] [NAME]')) |
|
836 | 836 | def branch(ui, repo, label=None, **opts): |
|
837 | 837 | """set or show the current branch name |
|
838 | 838 | |
|
839 | 839 | .. note:: |
|
840 | 840 | Branch names are permanent and global. Use :hg:`bookmark` to create a |
|
841 | 841 | light-weight bookmark instead. See :hg:`help glossary` for more |
|
842 | 842 | information about named branches and bookmarks. |
|
843 | 843 | |
|
844 | 844 | With no argument, show the current branch name. With one argument, |
|
845 | 845 | set the working directory branch name (the branch will not exist |
|
846 | 846 | in the repository until the next commit). Standard practice |
|
847 | 847 | recommends that primary development take place on the 'default' |
|
848 | 848 | branch. |
|
849 | 849 | |
|
850 | 850 | Unless -f/--force is specified, branch will not let you set a |
|
851 | 851 | branch name that already exists, even if it's inactive. |
|
852 | 852 | |
|
853 | 853 | Use -C/--clean to reset the working directory branch to that of |
|
854 | 854 | the parent of the working directory, negating a previous branch |
|
855 | 855 | change. |
|
856 | 856 | |
|
857 | 857 | Use the command :hg:`update` to switch to an existing branch. Use |
|
858 | 858 | :hg:`commit --close-branch` to mark this branch as closed. |
|
859 | 859 | |
|
860 | 860 | Returns 0 on success. |
|
861 | 861 | """ |
|
862 | 862 | |
|
863 | 863 | if opts.get('clean'): |
|
864 | 864 | label = repo[None].p1().branch() |
|
865 | 865 | repo.dirstate.setbranch(label) |
|
866 | 866 | ui.status(_('reset working directory to branch %s\n') % label) |
|
867 | 867 | elif label: |
|
868 | 868 | if not opts.get('force') and label in repo.branchtags(): |
|
869 | 869 | if label not in [p.branch() for p in repo.parents()]: |
|
870 | 870 | raise util.Abort(_('a branch of the same name already exists'), |
|
871 | 871 | # i18n: "it" refers to an existing branch |
|
872 | 872 | hint=_("use 'hg update' to switch to it")) |
|
873 | 873 | repo.dirstate.setbranch(label) |
|
874 | 874 | ui.status(_('marked working directory as branch %s\n') % label) |
|
875 | 875 | ui.status(_('(branches are permanent and global, ' |
|
876 | 876 | 'did you want a bookmark?)\n')) |
|
877 | 877 | else: |
|
878 | 878 | ui.write("%s\n" % repo.dirstate.branch()) |
|
879 | 879 | |
|
880 | 880 | @command('branches', |
|
881 | 881 | [('a', 'active', False, _('show only branches that have unmerged heads')), |
|
882 | 882 | ('c', 'closed', False, _('show normal and closed branches'))], |
|
883 | 883 | _('[-ac]')) |
|
884 | 884 | def branches(ui, repo, active=False, closed=False): |
|
885 | 885 | """list repository named branches |
|
886 | 886 | |
|
887 | 887 | List the repository's named branches, indicating which ones are |
|
888 | 888 | inactive. If -c/--closed is specified, also list branches which have |
|
889 | 889 | been marked closed (see :hg:`commit --close-branch`). |
|
890 | 890 | |
|
891 | 891 | If -a/--active is specified, only show active branches. A branch |
|
892 | 892 | is considered active if it contains repository heads. |
|
893 | 893 | |
|
894 | 894 | Use the command :hg:`update` to switch to an existing branch. |
|
895 | 895 | |
|
896 | 896 | Returns 0. |
|
897 | 897 | """ |
|
898 | 898 | |
|
899 | 899 | hexfunc = ui.debugflag and hex or short |
|
900 | 900 | activebranches = [repo[n].branch() for n in repo.heads()] |
|
901 | 901 | def testactive(tag, node): |
|
902 | 902 | realhead = tag in activebranches |
|
903 | 903 | open = node in repo.branchheads(tag, closed=False) |
|
904 | 904 | return realhead and open |
|
905 | 905 | branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag) |
|
906 | 906 | for tag, node in repo.branchtags().items()], |
|
907 | 907 | reverse=True) |
|
908 | 908 | |
|
909 | 909 | for isactive, node, tag in branches: |
|
910 | 910 | if (not active) or isactive: |
|
911 | 911 | if ui.quiet: |
|
912 | 912 | ui.write("%s\n" % tag) |
|
913 | 913 | else: |
|
914 | 914 | hn = repo.lookup(node) |
|
915 | 915 | if isactive: |
|
916 | 916 | label = 'branches.active' |
|
917 | 917 | notice = '' |
|
918 | 918 | elif hn not in repo.branchheads(tag, closed=False): |
|
919 | 919 | if not closed: |
|
920 | 920 | continue |
|
921 | 921 | label = 'branches.closed' |
|
922 | 922 | notice = _(' (closed)') |
|
923 | 923 | else: |
|
924 | 924 | label = 'branches.inactive' |
|
925 | 925 | notice = _(' (inactive)') |
|
926 | 926 | if tag == repo.dirstate.branch(): |
|
927 | 927 | label = 'branches.current' |
|
928 | 928 | rev = str(node).rjust(31 - encoding.colwidth(tag)) |
|
929 | 929 | rev = ui.label('%s:%s' % (rev, hexfunc(hn)), 'log.changeset') |
|
930 | 930 | tag = ui.label(tag, label) |
|
931 | 931 | ui.write("%s %s%s\n" % (tag, rev, notice)) |
|
932 | 932 | |
|
933 | 933 | @command('bundle', |
|
934 | 934 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
935 | 935 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), |
|
936 | 936 | _('REV')), |
|
937 | 937 | ('b', 'branch', [], _('a specific branch you would like to bundle'), |
|
938 | 938 | _('BRANCH')), |
|
939 | 939 | ('', 'base', [], |
|
940 | 940 | _('a base changeset assumed to be available at the destination'), |
|
941 | 941 | _('REV')), |
|
942 | 942 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
943 | 943 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), |
|
944 | 944 | ] + remoteopts, |
|
945 | 945 | _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]')) |
|
946 | 946 | def bundle(ui, repo, fname, dest=None, **opts): |
|
947 | 947 | """create a changegroup file |
|
948 | 948 | |
|
949 | 949 | Generate a compressed changegroup file collecting changesets not |
|
950 | 950 | known to be in another repository. |
|
951 | 951 | |
|
952 | 952 | If you omit the destination repository, then hg assumes the |
|
953 | 953 | destination will have all the nodes you specify with --base |
|
954 | 954 | parameters. To create a bundle containing all changesets, use |
|
955 | 955 | -a/--all (or --base null). |
|
956 | 956 | |
|
957 | 957 | You can change compression method with the -t/--type option. |
|
958 | 958 | The available compression methods are: none, bzip2, and |
|
959 | 959 | gzip (by default, bundles are compressed using bzip2). |
|
960 | 960 | |
|
961 | 961 | The bundle file can then be transferred using conventional means |
|
962 | 962 | and applied to another repository with the unbundle or pull |
|
963 | 963 | command. This is useful when direct push and pull are not |
|
964 | 964 | available or when exporting an entire repository is undesirable. |
|
965 | 965 | |
|
966 | 966 | Applying bundles preserves all changeset contents including |
|
967 | 967 | permissions, copy/rename information, and revision history. |
|
968 | 968 | |
|
969 | 969 | Returns 0 on success, 1 if no changes found. |
|
970 | 970 | """ |
|
971 | 971 | revs = None |
|
972 | 972 | if 'rev' in opts: |
|
973 | 973 | revs = scmutil.revrange(repo, opts['rev']) |
|
974 | 974 | |
|
975 | 975 | if opts.get('all'): |
|
976 | 976 | base = ['null'] |
|
977 | 977 | else: |
|
978 | 978 | base = scmutil.revrange(repo, opts.get('base')) |
|
979 | 979 | if base: |
|
980 | 980 | if dest: |
|
981 | 981 | raise util.Abort(_("--base is incompatible with specifying " |
|
982 | 982 | "a destination")) |
|
983 | 983 | common = [repo.lookup(rev) for rev in base] |
|
984 | 984 | heads = revs and map(repo.lookup, revs) or revs |
|
985 | 985 | cg = repo.getbundle('bundle', heads=heads, common=common) |
|
986 | 986 | outgoing = None |
|
987 | 987 | else: |
|
988 | 988 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
989 | 989 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
990 | 990 | other = hg.peer(repo, opts, dest) |
|
991 | 991 | revs, checkout = hg.addbranchrevs(repo, other, branches, revs) |
|
992 | 992 | heads = revs and map(repo.lookup, revs) or revs |
|
993 | 993 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
994 | 994 | onlyheads=heads, |
|
995 | 995 | force=opts.get('force')) |
|
996 | 996 | cg = repo.getlocalbundle('bundle', outgoing) |
|
997 | 997 | if not cg: |
|
998 | 998 | scmutil.nochangesfound(ui, outgoing and outgoing.excluded) |
|
999 | 999 | return 1 |
|
1000 | 1000 | |
|
1001 | 1001 | bundletype = opts.get('type', 'bzip2').lower() |
|
1002 | 1002 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} |
|
1003 | 1003 | bundletype = btypes.get(bundletype) |
|
1004 | 1004 | if bundletype not in changegroup.bundletypes: |
|
1005 | 1005 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
1006 | 1006 | |
|
1007 | 1007 | changegroup.writebundle(cg, fname, bundletype) |
|
1008 | 1008 | |
|
1009 | 1009 | @command('cat', |
|
1010 | 1010 | [('o', 'output', '', |
|
1011 | 1011 | _('print output to file with formatted name'), _('FORMAT')), |
|
1012 | 1012 | ('r', 'rev', '', _('print the given revision'), _('REV')), |
|
1013 | 1013 | ('', 'decode', None, _('apply any matching decode filter')), |
|
1014 | 1014 | ] + walkopts, |
|
1015 | 1015 | _('[OPTION]... FILE...')) |
|
1016 | 1016 | def cat(ui, repo, file1, *pats, **opts): |
|
1017 | 1017 | """output the current or given revision of files |
|
1018 | 1018 | |
|
1019 | 1019 | Print the specified files as they were at the given revision. If |
|
1020 | 1020 | no revision is given, the parent of the working directory is used, |
|
1021 | 1021 | or tip if no revision is checked out. |
|
1022 | 1022 | |
|
1023 | 1023 | Output may be to a file, in which case the name of the file is |
|
1024 | 1024 | given using a format string. The formatting rules are the same as |
|
1025 | 1025 | for the export command, with the following additions: |
|
1026 | 1026 | |
|
1027 | 1027 | :``%s``: basename of file being printed |
|
1028 | 1028 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
1029 | 1029 | :``%p``: root-relative path name of file being printed |
|
1030 | 1030 | |
|
1031 | 1031 | Returns 0 on success. |
|
1032 | 1032 | """ |
|
1033 | 1033 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1034 | 1034 | err = 1 |
|
1035 | 1035 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1036 | 1036 | for abs in ctx.walk(m): |
|
1037 | 1037 | fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), |
|
1038 | 1038 | pathname=abs) |
|
1039 | 1039 | data = ctx[abs].data() |
|
1040 | 1040 | if opts.get('decode'): |
|
1041 | 1041 | data = repo.wwritedata(abs, data) |
|
1042 | 1042 | fp.write(data) |
|
1043 | 1043 | fp.close() |
|
1044 | 1044 | err = 0 |
|
1045 | 1045 | return err |
|
1046 | 1046 | |
|
1047 | 1047 | @command('^clone', |
|
1048 | 1048 | [('U', 'noupdate', None, |
|
1049 | 1049 | _('the clone will include an empty working copy (only a repository)')), |
|
1050 | 1050 | ('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')), |
|
1051 | 1051 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), |
|
1052 | 1052 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), |
|
1053 | 1053 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
1054 | 1054 | ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')), |
|
1055 | 1055 | ] + remoteopts, |
|
1056 | 1056 | _('[OPTION]... SOURCE [DEST]')) |
|
1057 | 1057 | def clone(ui, source, dest=None, **opts): |
|
1058 | 1058 | """make a copy of an existing repository |
|
1059 | 1059 | |
|
1060 | 1060 | Create a copy of an existing repository in a new directory. |
|
1061 | 1061 | |
|
1062 | 1062 | If no destination directory name is specified, it defaults to the |
|
1063 | 1063 | basename of the source. |
|
1064 | 1064 | |
|
1065 | 1065 | The location of the source is added to the new repository's |
|
1066 | 1066 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
1067 | 1067 | |
|
1068 | 1068 | Only local paths and ``ssh://`` URLs are supported as |
|
1069 | 1069 | destinations. For ``ssh://`` destinations, no working directory or |
|
1070 | 1070 | ``.hg/hgrc`` will be created on the remote side. |
|
1071 | 1071 | |
|
1072 | 1072 | To pull only a subset of changesets, specify one or more revisions |
|
1073 | 1073 | identifiers with -r/--rev or branches with -b/--branch. The |
|
1074 | 1074 | resulting clone will contain only the specified changesets and |
|
1075 | 1075 | their ancestors. These options (or 'clone src#rev dest') imply |
|
1076 | 1076 | --pull, even for local source repositories. Note that specifying a |
|
1077 | 1077 | tag will include the tagged changeset but not the changeset |
|
1078 | 1078 | containing the tag. |
|
1079 | 1079 | |
|
1080 | 1080 | To check out a particular version, use -u/--update, or |
|
1081 | 1081 | -U/--noupdate to create a clone with no working directory. |
|
1082 | 1082 | |
|
1083 | 1083 | .. container:: verbose |
|
1084 | 1084 | |
|
1085 | 1085 | For efficiency, hardlinks are used for cloning whenever the |
|
1086 | 1086 | source and destination are on the same filesystem (note this |
|
1087 | 1087 | applies only to the repository data, not to the working |
|
1088 | 1088 | directory). Some filesystems, such as AFS, implement hardlinking |
|
1089 | 1089 | incorrectly, but do not report errors. In these cases, use the |
|
1090 | 1090 | --pull option to avoid hardlinking. |
|
1091 | 1091 | |
|
1092 | 1092 | In some cases, you can clone repositories and the working |
|
1093 | 1093 | directory using full hardlinks with :: |
|
1094 | 1094 | |
|
1095 | 1095 | $ cp -al REPO REPOCLONE |
|
1096 | 1096 | |
|
1097 | 1097 | This is the fastest way to clone, but it is not always safe. The |
|
1098 | 1098 | operation is not atomic (making sure REPO is not modified during |
|
1099 | 1099 | the operation is up to you) and you have to make sure your |
|
1100 | 1100 | editor breaks hardlinks (Emacs and most Linux Kernel tools do |
|
1101 | 1101 | so). Also, this is not compatible with certain extensions that |
|
1102 | 1102 | place their metadata under the .hg directory, such as mq. |
|
1103 | 1103 | |
|
1104 | 1104 | Mercurial will update the working directory to the first applicable |
|
1105 | 1105 | revision from this list: |
|
1106 | 1106 | |
|
1107 | 1107 | a) null if -U or the source repository has no changesets |
|
1108 | 1108 | b) if -u . and the source repository is local, the first parent of |
|
1109 | 1109 | the source repository's working directory |
|
1110 | 1110 | c) the changeset specified with -u (if a branch name, this means the |
|
1111 | 1111 | latest head of that branch) |
|
1112 | 1112 | d) the changeset specified with -r |
|
1113 | 1113 | e) the tipmost head specified with -b |
|
1114 | 1114 | f) the tipmost head specified with the url#branch source syntax |
|
1115 | 1115 | g) the tipmost head of the default branch |
|
1116 | 1116 | h) tip |
|
1117 | 1117 | |
|
1118 | 1118 | Examples: |
|
1119 | 1119 | |
|
1120 | 1120 | - clone a remote repository to a new directory named hg/:: |
|
1121 | 1121 | |
|
1122 | 1122 | hg clone http://selenic.com/hg |
|
1123 | 1123 | |
|
1124 | 1124 | - create a lightweight local clone:: |
|
1125 | 1125 | |
|
1126 | 1126 | hg clone project/ project-feature/ |
|
1127 | 1127 | |
|
1128 | 1128 | - clone from an absolute path on an ssh server (note double-slash):: |
|
1129 | 1129 | |
|
1130 | 1130 | hg clone ssh://user@server//home/projects/alpha/ |
|
1131 | 1131 | |
|
1132 | 1132 | - do a high-speed clone over a LAN while checking out a |
|
1133 | 1133 | specified version:: |
|
1134 | 1134 | |
|
1135 | 1135 | hg clone --uncompressed http://server/repo -u 1.5 |
|
1136 | 1136 | |
|
1137 | 1137 | - create a repository without changesets after a particular revision:: |
|
1138 | 1138 | |
|
1139 | 1139 | hg clone -r 04e544 experimental/ good/ |
|
1140 | 1140 | |
|
1141 | 1141 | - clone (and track) a particular named branch:: |
|
1142 | 1142 | |
|
1143 | 1143 | hg clone http://selenic.com/hg#stable |
|
1144 | 1144 | |
|
1145 | 1145 | See :hg:`help urls` for details on specifying URLs. |
|
1146 | 1146 | |
|
1147 | 1147 | Returns 0 on success. |
|
1148 | 1148 | """ |
|
1149 | 1149 | if opts.get('noupdate') and opts.get('updaterev'): |
|
1150 | 1150 | raise util.Abort(_("cannot specify both --noupdate and --updaterev")) |
|
1151 | 1151 | |
|
1152 | 1152 | r = hg.clone(ui, opts, source, dest, |
|
1153 | 1153 | pull=opts.get('pull'), |
|
1154 | 1154 | stream=opts.get('uncompressed'), |
|
1155 | 1155 | rev=opts.get('rev'), |
|
1156 | 1156 | update=opts.get('updaterev') or not opts.get('noupdate'), |
|
1157 | 1157 | branch=opts.get('branch')) |
|
1158 | 1158 | |
|
1159 | 1159 | return r is None |
|
1160 | 1160 | |
|
1161 | 1161 | @command('^commit|ci', |
|
1162 | 1162 | [('A', 'addremove', None, |
|
1163 | 1163 | _('mark new/missing files as added/removed before committing')), |
|
1164 | 1164 | ('', 'close-branch', None, |
|
1165 | 1165 | _('mark a branch as closed, hiding it from the branch list')), |
|
1166 | 1166 | ] + walkopts + commitopts + commitopts2 + subrepoopts, |
|
1167 | 1167 | _('[OPTION]... [FILE]...')) |
|
1168 | 1168 | def commit(ui, repo, *pats, **opts): |
|
1169 | 1169 | """commit the specified files or all outstanding changes |
|
1170 | 1170 | |
|
1171 | 1171 | Commit changes to the given files into the repository. Unlike a |
|
1172 | 1172 | centralized SCM, this operation is a local operation. See |
|
1173 | 1173 | :hg:`push` for a way to actively distribute your changes. |
|
1174 | 1174 | |
|
1175 | 1175 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1176 | 1176 | will be committed. |
|
1177 | 1177 | |
|
1178 | 1178 | If you are committing the result of a merge, do not provide any |
|
1179 | 1179 | filenames or -I/-X filters. |
|
1180 | 1180 | |
|
1181 | 1181 | If no commit message is specified, Mercurial starts your |
|
1182 | 1182 | configured editor where you can enter a message. In case your |
|
1183 | 1183 | commit fails, you will find a backup of your message in |
|
1184 | 1184 | ``.hg/last-message.txt``. |
|
1185 | 1185 | |
|
1186 | 1186 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1187 | 1187 | |
|
1188 | 1188 | Returns 0 on success, 1 if nothing changed. |
|
1189 | 1189 | """ |
|
1190 | 1190 | if opts.get('subrepos'): |
|
1191 | 1191 | # Let --subrepos on the command line overide config setting. |
|
1192 | 1192 | ui.setconfig('ui', 'commitsubrepos', True) |
|
1193 | 1193 | |
|
1194 | 1194 | extra = {} |
|
1195 | 1195 | if opts.get('close_branch'): |
|
1196 | 1196 | if repo['.'].node() not in repo.branchheads(): |
|
1197 | 1197 | # The topo heads set is included in the branch heads set of the |
|
1198 | 1198 | # current branch, so it's sufficient to test branchheads |
|
1199 | 1199 | raise util.Abort(_('can only close branch heads')) |
|
1200 | 1200 | extra['close'] = 1 |
|
1201 | 1201 | e = cmdutil.commiteditor |
|
1202 | 1202 | if opts.get('force_editor'): |
|
1203 | 1203 | e = cmdutil.commitforceeditor |
|
1204 | 1204 | |
|
1205 | 1205 | def commitfunc(ui, repo, message, match, opts): |
|
1206 | 1206 | return repo.commit(message, opts.get('user'), opts.get('date'), match, |
|
1207 | 1207 | editor=e, extra=extra) |
|
1208 | 1208 | |
|
1209 | 1209 | branch = repo[None].branch() |
|
1210 | 1210 | bheads = repo.branchheads(branch) |
|
1211 | 1211 | |
|
1212 | 1212 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
1213 | 1213 | if not node: |
|
1214 | 1214 | stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |
|
1215 | 1215 | if stat[3]: |
|
1216 | 1216 | ui.status(_("nothing changed (%d missing files, see 'hg status')\n") |
|
1217 | 1217 | % len(stat[3])) |
|
1218 | 1218 | else: |
|
1219 | 1219 | ui.status(_("nothing changed\n")) |
|
1220 | 1220 | return 1 |
|
1221 | 1221 | |
|
1222 | 1222 | ctx = repo[node] |
|
1223 | 1223 | parents = ctx.parents() |
|
1224 | 1224 | |
|
1225 | 1225 | if (bheads and node not in bheads and not |
|
1226 | 1226 | [x for x in parents if x.node() in bheads and x.branch() == branch]): |
|
1227 | 1227 | ui.status(_('created new head\n')) |
|
1228 | 1228 | # The message is not printed for initial roots. For the other |
|
1229 | 1229 | # changesets, it is printed in the following situations: |
|
1230 | 1230 | # |
|
1231 | 1231 | # Par column: for the 2 parents with ... |
|
1232 | 1232 | # N: null or no parent |
|
1233 | 1233 | # B: parent is on another named branch |
|
1234 | 1234 | # C: parent is a regular non head changeset |
|
1235 | 1235 | # H: parent was a branch head of the current branch |
|
1236 | 1236 | # Msg column: whether we print "created new head" message |
|
1237 | 1237 | # In the following, it is assumed that there already exists some |
|
1238 | 1238 | # initial branch heads of the current branch, otherwise nothing is |
|
1239 | 1239 | # printed anyway. |
|
1240 | 1240 | # |
|
1241 | 1241 | # Par Msg Comment |
|
1242 | 1242 | # NN y additional topo root |
|
1243 | 1243 | # |
|
1244 | 1244 | # BN y additional branch root |
|
1245 | 1245 | # CN y additional topo head |
|
1246 | 1246 | # HN n usual case |
|
1247 | 1247 | # |
|
1248 | 1248 | # BB y weird additional branch root |
|
1249 | 1249 | # CB y branch merge |
|
1250 | 1250 | # HB n merge with named branch |
|
1251 | 1251 | # |
|
1252 | 1252 | # CC y additional head from merge |
|
1253 | 1253 | # CH n merge with a head |
|
1254 | 1254 | # |
|
1255 | 1255 | # HH n head merge: head count decreases |
|
1256 | 1256 | |
|
1257 | 1257 | if not opts.get('close_branch'): |
|
1258 | 1258 | for r in parents: |
|
1259 | 1259 | if r.extra().get('close') and r.branch() == branch: |
|
1260 | 1260 | ui.status(_('reopening closed branch head %d\n') % r) |
|
1261 | 1261 | |
|
1262 | 1262 | if ui.debugflag: |
|
1263 | 1263 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex())) |
|
1264 | 1264 | elif ui.verbose: |
|
1265 | 1265 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx)) |
|
1266 | 1266 | |
|
1267 | 1267 | @command('copy|cp', |
|
1268 | 1268 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
1269 | 1269 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
1270 | 1270 | ] + walkopts + dryrunopts, |
|
1271 | 1271 | _('[OPTION]... [SOURCE]... DEST')) |
|
1272 | 1272 | def copy(ui, repo, *pats, **opts): |
|
1273 | 1273 | """mark files as copied for the next commit |
|
1274 | 1274 | |
|
1275 | 1275 | Mark dest as having copies of source files. If dest is a |
|
1276 | 1276 | directory, copies are put in that directory. If dest is a file, |
|
1277 | 1277 | the source must be a single file. |
|
1278 | 1278 | |
|
1279 | 1279 | By default, this command copies the contents of files as they |
|
1280 | 1280 | exist in the working directory. If invoked with -A/--after, the |
|
1281 | 1281 | operation is recorded, but no copying is performed. |
|
1282 | 1282 | |
|
1283 | 1283 | This command takes effect with the next commit. To undo a copy |
|
1284 | 1284 | before that, see :hg:`revert`. |
|
1285 | 1285 | |
|
1286 | 1286 | Returns 0 on success, 1 if errors are encountered. |
|
1287 | 1287 | """ |
|
1288 | 1288 | wlock = repo.wlock(False) |
|
1289 | 1289 | try: |
|
1290 | 1290 | return cmdutil.copy(ui, repo, pats, opts) |
|
1291 | 1291 | finally: |
|
1292 | 1292 | wlock.release() |
|
1293 | 1293 | |
|
1294 | 1294 | @command('debugancestor', [], _('[INDEX] REV1 REV2')) |
|
1295 | 1295 | def debugancestor(ui, repo, *args): |
|
1296 | 1296 | """find the ancestor revision of two revisions in a given index""" |
|
1297 | 1297 | if len(args) == 3: |
|
1298 | 1298 | index, rev1, rev2 = args |
|
1299 | 1299 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) |
|
1300 | 1300 | lookup = r.lookup |
|
1301 | 1301 | elif len(args) == 2: |
|
1302 | 1302 | if not repo: |
|
1303 | 1303 | raise util.Abort(_("there is no Mercurial repository here " |
|
1304 | 1304 | "(.hg not found)")) |
|
1305 | 1305 | rev1, rev2 = args |
|
1306 | 1306 | r = repo.changelog |
|
1307 | 1307 | lookup = repo.lookup |
|
1308 | 1308 | else: |
|
1309 | 1309 | raise util.Abort(_('either two or three arguments required')) |
|
1310 | 1310 | a = r.ancestor(lookup(rev1), lookup(rev2)) |
|
1311 | 1311 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1312 | 1312 | |
|
1313 | 1313 | @command('debugbuilddag', |
|
1314 | 1314 | [('m', 'mergeable-file', None, _('add single file mergeable changes')), |
|
1315 | 1315 | ('o', 'overwritten-file', None, _('add single file all revs overwrite')), |
|
1316 | 1316 | ('n', 'new-file', None, _('add new file at each rev'))], |
|
1317 | 1317 | _('[OPTION]... [TEXT]')) |
|
1318 | 1318 | def debugbuilddag(ui, repo, text=None, |
|
1319 | 1319 | mergeable_file=False, |
|
1320 | 1320 | overwritten_file=False, |
|
1321 | 1321 | new_file=False): |
|
1322 | 1322 | """builds a repo with a given DAG from scratch in the current empty repo |
|
1323 | 1323 | |
|
1324 | 1324 | The description of the DAG is read from stdin if not given on the |
|
1325 | 1325 | command line. |
|
1326 | 1326 | |
|
1327 | 1327 | Elements: |
|
1328 | 1328 | |
|
1329 | 1329 | - "+n" is a linear run of n nodes based on the current default parent |
|
1330 | 1330 | - "." is a single node based on the current default parent |
|
1331 | 1331 | - "$" resets the default parent to null (implied at the start); |
|
1332 | 1332 | otherwise the default parent is always the last node created |
|
1333 | 1333 | - "<p" sets the default parent to the backref p |
|
1334 | 1334 | - "*p" is a fork at parent p, which is a backref |
|
1335 | 1335 | - "*p1/p2" is a merge of parents p1 and p2, which are backrefs |
|
1336 | 1336 | - "/p2" is a merge of the preceding node and p2 |
|
1337 | 1337 | - ":tag" defines a local tag for the preceding node |
|
1338 | 1338 | - "@branch" sets the named branch for subsequent nodes |
|
1339 | 1339 | - "#...\\n" is a comment up to the end of the line |
|
1340 | 1340 | |
|
1341 | 1341 | Whitespace between the above elements is ignored. |
|
1342 | 1342 | |
|
1343 | 1343 | A backref is either |
|
1344 | 1344 | |
|
1345 | 1345 | - a number n, which references the node curr-n, where curr is the current |
|
1346 | 1346 | node, or |
|
1347 | 1347 | - the name of a local tag you placed earlier using ":tag", or |
|
1348 | 1348 | - empty to denote the default parent. |
|
1349 | 1349 | |
|
1350 | 1350 | All string valued-elements are either strictly alphanumeric, or must |
|
1351 | 1351 | be enclosed in double quotes ("..."), with "\\" as escape character. |
|
1352 | 1352 | """ |
|
1353 | 1353 | |
|
1354 | 1354 | if text is None: |
|
1355 | 1355 | ui.status(_("reading DAG from stdin\n")) |
|
1356 | 1356 | text = ui.fin.read() |
|
1357 | 1357 | |
|
1358 | 1358 | cl = repo.changelog |
|
1359 | 1359 | if len(cl) > 0: |
|
1360 | 1360 | raise util.Abort(_('repository is not empty')) |
|
1361 | 1361 | |
|
1362 | 1362 | # determine number of revs in DAG |
|
1363 | 1363 | total = 0 |
|
1364 | 1364 | for type, data in dagparser.parsedag(text): |
|
1365 | 1365 | if type == 'n': |
|
1366 | 1366 | total += 1 |
|
1367 | 1367 | |
|
1368 | 1368 | if mergeable_file: |
|
1369 | 1369 | linesperrev = 2 |
|
1370 | 1370 | # make a file with k lines per rev |
|
1371 | 1371 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] |
|
1372 | 1372 | initialmergedlines.append("") |
|
1373 | 1373 | |
|
1374 | 1374 | tags = [] |
|
1375 | 1375 | |
|
1376 | 1376 | lock = tr = None |
|
1377 | 1377 | try: |
|
1378 | 1378 | lock = repo.lock() |
|
1379 | 1379 | tr = repo.transaction("builddag") |
|
1380 | 1380 | |
|
1381 | 1381 | at = -1 |
|
1382 | 1382 | atbranch = 'default' |
|
1383 | 1383 | nodeids = [] |
|
1384 | 1384 | id = 0 |
|
1385 | 1385 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
1386 | 1386 | for type, data in dagparser.parsedag(text): |
|
1387 | 1387 | if type == 'n': |
|
1388 | 1388 | ui.note('node %s\n' % str(data)) |
|
1389 | 1389 | id, ps = data |
|
1390 | 1390 | |
|
1391 | 1391 | files = [] |
|
1392 | 1392 | fctxs = {} |
|
1393 | 1393 | |
|
1394 | 1394 | p2 = None |
|
1395 | 1395 | if mergeable_file: |
|
1396 | 1396 | fn = "mf" |
|
1397 | 1397 | p1 = repo[ps[0]] |
|
1398 | 1398 | if len(ps) > 1: |
|
1399 | 1399 | p2 = repo[ps[1]] |
|
1400 | 1400 | pa = p1.ancestor(p2) |
|
1401 | 1401 | base, local, other = [x[fn].data() for x in pa, p1, p2] |
|
1402 | 1402 | m3 = simplemerge.Merge3Text(base, local, other) |
|
1403 | 1403 | ml = [l.strip() for l in m3.merge_lines()] |
|
1404 | 1404 | ml.append("") |
|
1405 | 1405 | elif at > 0: |
|
1406 | 1406 | ml = p1[fn].data().split("\n") |
|
1407 | 1407 | else: |
|
1408 | 1408 | ml = initialmergedlines |
|
1409 | 1409 | ml[id * linesperrev] += " r%i" % id |
|
1410 | 1410 | mergedtext = "\n".join(ml) |
|
1411 | 1411 | files.append(fn) |
|
1412 | 1412 | fctxs[fn] = context.memfilectx(fn, mergedtext) |
|
1413 | 1413 | |
|
1414 | 1414 | if overwritten_file: |
|
1415 | 1415 | fn = "of" |
|
1416 | 1416 | files.append(fn) |
|
1417 | 1417 | fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) |
|
1418 | 1418 | |
|
1419 | 1419 | if new_file: |
|
1420 | 1420 | fn = "nf%i" % id |
|
1421 | 1421 | files.append(fn) |
|
1422 | 1422 | fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) |
|
1423 | 1423 | if len(ps) > 1: |
|
1424 | 1424 | if not p2: |
|
1425 | 1425 | p2 = repo[ps[1]] |
|
1426 | 1426 | for fn in p2: |
|
1427 | 1427 | if fn.startswith("nf"): |
|
1428 | 1428 | files.append(fn) |
|
1429 | 1429 | fctxs[fn] = p2[fn] |
|
1430 | 1430 | |
|
1431 | 1431 | def fctxfn(repo, cx, path): |
|
1432 | 1432 | return fctxs.get(path) |
|
1433 | 1433 | |
|
1434 | 1434 | if len(ps) == 0 or ps[0] < 0: |
|
1435 | 1435 | pars = [None, None] |
|
1436 | 1436 | elif len(ps) == 1: |
|
1437 | 1437 | pars = [nodeids[ps[0]], None] |
|
1438 | 1438 | else: |
|
1439 | 1439 | pars = [nodeids[p] for p in ps] |
|
1440 | 1440 | cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn, |
|
1441 | 1441 | date=(id, 0), |
|
1442 | 1442 | user="debugbuilddag", |
|
1443 | 1443 | extra={'branch': atbranch}) |
|
1444 | 1444 | nodeid = repo.commitctx(cx) |
|
1445 | 1445 | nodeids.append(nodeid) |
|
1446 | 1446 | at = id |
|
1447 | 1447 | elif type == 'l': |
|
1448 | 1448 | id, name = data |
|
1449 | 1449 | ui.note('tag %s\n' % name) |
|
1450 | 1450 | tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) |
|
1451 | 1451 | elif type == 'a': |
|
1452 | 1452 | ui.note('branch %s\n' % data) |
|
1453 | 1453 | atbranch = data |
|
1454 | 1454 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
1455 | 1455 | tr.close() |
|
1456 | 1456 | |
|
1457 | 1457 | if tags: |
|
1458 | 1458 | repo.opener.write("localtags", "".join(tags)) |
|
1459 | 1459 | finally: |
|
1460 | 1460 | ui.progress(_('building'), None) |
|
1461 | 1461 | release(tr, lock) |
|
1462 | 1462 | |
|
1463 | 1463 | @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE')) |
|
1464 | 1464 | def debugbundle(ui, bundlepath, all=None, **opts): |
|
1465 | 1465 | """lists the contents of a bundle""" |
|
1466 | 1466 | f = url.open(ui, bundlepath) |
|
1467 | 1467 | try: |
|
1468 | 1468 | gen = changegroup.readbundle(f, bundlepath) |
|
1469 | 1469 | if all: |
|
1470 | 1470 | ui.write("format: id, p1, p2, cset, delta base, len(delta)\n") |
|
1471 | 1471 | |
|
1472 | 1472 | def showchunks(named): |
|
1473 | 1473 | ui.write("\n%s\n" % named) |
|
1474 | 1474 | chain = None |
|
1475 | 1475 | while True: |
|
1476 | 1476 | chunkdata = gen.deltachunk(chain) |
|
1477 | 1477 | if not chunkdata: |
|
1478 | 1478 | break |
|
1479 | 1479 | node = chunkdata['node'] |
|
1480 | 1480 | p1 = chunkdata['p1'] |
|
1481 | 1481 | p2 = chunkdata['p2'] |
|
1482 | 1482 | cs = chunkdata['cs'] |
|
1483 | 1483 | deltabase = chunkdata['deltabase'] |
|
1484 | 1484 | delta = chunkdata['delta'] |
|
1485 | 1485 | ui.write("%s %s %s %s %s %s\n" % |
|
1486 | 1486 | (hex(node), hex(p1), hex(p2), |
|
1487 | 1487 | hex(cs), hex(deltabase), len(delta))) |
|
1488 | 1488 | chain = node |
|
1489 | 1489 | |
|
1490 | 1490 | chunkdata = gen.changelogheader() |
|
1491 | 1491 | showchunks("changelog") |
|
1492 | 1492 | chunkdata = gen.manifestheader() |
|
1493 | 1493 | showchunks("manifest") |
|
1494 | 1494 | while True: |
|
1495 | 1495 | chunkdata = gen.filelogheader() |
|
1496 | 1496 | if not chunkdata: |
|
1497 | 1497 | break |
|
1498 | 1498 | fname = chunkdata['filename'] |
|
1499 | 1499 | showchunks(fname) |
|
1500 | 1500 | else: |
|
1501 | 1501 | chunkdata = gen.changelogheader() |
|
1502 | 1502 | chain = None |
|
1503 | 1503 | while True: |
|
1504 | 1504 | chunkdata = gen.deltachunk(chain) |
|
1505 | 1505 | if not chunkdata: |
|
1506 | 1506 | break |
|
1507 | 1507 | node = chunkdata['node'] |
|
1508 | 1508 | ui.write("%s\n" % hex(node)) |
|
1509 | 1509 | chain = node |
|
1510 | 1510 | finally: |
|
1511 | 1511 | f.close() |
|
1512 | 1512 | |
|
1513 | 1513 | @command('debugcheckstate', [], '') |
|
1514 | 1514 | def debugcheckstate(ui, repo): |
|
1515 | 1515 | """validate the correctness of the current dirstate""" |
|
1516 | 1516 | parent1, parent2 = repo.dirstate.parents() |
|
1517 | 1517 | m1 = repo[parent1].manifest() |
|
1518 | 1518 | m2 = repo[parent2].manifest() |
|
1519 | 1519 | errors = 0 |
|
1520 | 1520 | for f in repo.dirstate: |
|
1521 | 1521 | state = repo.dirstate[f] |
|
1522 | 1522 | if state in "nr" and f not in m1: |
|
1523 | 1523 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1524 | 1524 | errors += 1 |
|
1525 | 1525 | if state in "a" and f in m1: |
|
1526 | 1526 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1527 | 1527 | errors += 1 |
|
1528 | 1528 | if state in "m" and f not in m1 and f not in m2: |
|
1529 | 1529 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1530 | 1530 | (f, state)) |
|
1531 | 1531 | errors += 1 |
|
1532 | 1532 | for f in m1: |
|
1533 | 1533 | state = repo.dirstate[f] |
|
1534 | 1534 | if state not in "nrm": |
|
1535 | 1535 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1536 | 1536 | errors += 1 |
|
1537 | 1537 | if errors: |
|
1538 | 1538 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1539 | 1539 | raise util.Abort(error) |
|
1540 | 1540 | |
|
1541 | 1541 | @command('debugcommands', [], _('[COMMAND]')) |
|
1542 | 1542 | def debugcommands(ui, cmd='', *args): |
|
1543 | 1543 | """list all available commands and options""" |
|
1544 | 1544 | for cmd, vals in sorted(table.iteritems()): |
|
1545 | 1545 | cmd = cmd.split('|')[0].strip('^') |
|
1546 | 1546 | opts = ', '.join([i[1] for i in vals[1]]) |
|
1547 | 1547 | ui.write('%s: %s\n' % (cmd, opts)) |
|
1548 | 1548 | |
|
1549 | 1549 | @command('debugcomplete', |
|
1550 | 1550 | [('o', 'options', None, _('show the command options'))], |
|
1551 | 1551 | _('[-o] CMD')) |
|
1552 | 1552 | def debugcomplete(ui, cmd='', **opts): |
|
1553 | 1553 | """returns the completion list associated with the given command""" |
|
1554 | 1554 | |
|
1555 | 1555 | if opts.get('options'): |
|
1556 | 1556 | options = [] |
|
1557 | 1557 | otables = [globalopts] |
|
1558 | 1558 | if cmd: |
|
1559 | 1559 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
1560 | 1560 | otables.append(entry[1]) |
|
1561 | 1561 | for t in otables: |
|
1562 | 1562 | for o in t: |
|
1563 | 1563 | if "(DEPRECATED)" in o[3]: |
|
1564 | 1564 | continue |
|
1565 | 1565 | if o[0]: |
|
1566 | 1566 | options.append('-%s' % o[0]) |
|
1567 | 1567 | options.append('--%s' % o[1]) |
|
1568 | 1568 | ui.write("%s\n" % "\n".join(options)) |
|
1569 | 1569 | return |
|
1570 | 1570 | |
|
1571 | 1571 | cmdlist = cmdutil.findpossible(cmd, table) |
|
1572 | 1572 | if ui.verbose: |
|
1573 | 1573 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
1574 | 1574 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
1575 | 1575 | |
|
1576 | 1576 | @command('debugdag', |
|
1577 | 1577 | [('t', 'tags', None, _('use tags as labels')), |
|
1578 | 1578 | ('b', 'branches', None, _('annotate with branch names')), |
|
1579 | 1579 | ('', 'dots', None, _('use dots for runs')), |
|
1580 | 1580 | ('s', 'spaces', None, _('separate elements by spaces'))], |
|
1581 | 1581 | _('[OPTION]... [FILE [REV]...]')) |
|
1582 | 1582 | def debugdag(ui, repo, file_=None, *revs, **opts): |
|
1583 | 1583 | """format the changelog or an index DAG as a concise textual description |
|
1584 | 1584 | |
|
1585 | 1585 | If you pass a revlog index, the revlog's DAG is emitted. If you list |
|
1586 | 1586 | revision numbers, they get labelled in the output as rN. |
|
1587 | 1587 | |
|
1588 | 1588 | Otherwise, the changelog DAG of the current repo is emitted. |
|
1589 | 1589 | """ |
|
1590 | 1590 | spaces = opts.get('spaces') |
|
1591 | 1591 | dots = opts.get('dots') |
|
1592 | 1592 | if file_: |
|
1593 | 1593 | rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
1594 | 1594 | revs = set((int(r) for r in revs)) |
|
1595 | 1595 | def events(): |
|
1596 | 1596 | for r in rlog: |
|
1597 | 1597 | yield 'n', (r, list(set(p for p in rlog.parentrevs(r) if p != -1))) |
|
1598 | 1598 | if r in revs: |
|
1599 | 1599 | yield 'l', (r, "r%i" % r) |
|
1600 | 1600 | elif repo: |
|
1601 | 1601 | cl = repo.changelog |
|
1602 | 1602 | tags = opts.get('tags') |
|
1603 | 1603 | branches = opts.get('branches') |
|
1604 | 1604 | if tags: |
|
1605 | 1605 | labels = {} |
|
1606 | 1606 | for l, n in repo.tags().items(): |
|
1607 | 1607 | labels.setdefault(cl.rev(n), []).append(l) |
|
1608 | 1608 | def events(): |
|
1609 | 1609 | b = "default" |
|
1610 | 1610 | for r in cl: |
|
1611 | 1611 | if branches: |
|
1612 | 1612 | newb = cl.read(cl.node(r))[5]['branch'] |
|
1613 | 1613 | if newb != b: |
|
1614 | 1614 | yield 'a', newb |
|
1615 | 1615 | b = newb |
|
1616 | 1616 | yield 'n', (r, list(set(p for p in cl.parentrevs(r) if p != -1))) |
|
1617 | 1617 | if tags: |
|
1618 | 1618 | ls = labels.get(r) |
|
1619 | 1619 | if ls: |
|
1620 | 1620 | for l in ls: |
|
1621 | 1621 | yield 'l', (r, l) |
|
1622 | 1622 | else: |
|
1623 | 1623 | raise util.Abort(_('need repo for changelog dag')) |
|
1624 | 1624 | |
|
1625 | 1625 | for line in dagparser.dagtextlines(events(), |
|
1626 | 1626 | addspaces=spaces, |
|
1627 | 1627 | wraplabels=True, |
|
1628 | 1628 | wrapannotations=True, |
|
1629 | 1629 | wrapnonlinear=dots, |
|
1630 | 1630 | usedots=dots, |
|
1631 | 1631 | maxlinewidth=70): |
|
1632 | 1632 | ui.write(line) |
|
1633 | 1633 | ui.write("\n") |
|
1634 | 1634 | |
|
1635 | 1635 | @command('debugdata', |
|
1636 | 1636 | [('c', 'changelog', False, _('open changelog')), |
|
1637 | 1637 | ('m', 'manifest', False, _('open manifest'))], |
|
1638 | 1638 | _('-c|-m|FILE REV')) |
|
1639 | 1639 | def debugdata(ui, repo, file_, rev = None, **opts): |
|
1640 | 1640 | """dump the contents of a data file revision""" |
|
1641 | 1641 | if opts.get('changelog') or opts.get('manifest'): |
|
1642 | 1642 | file_, rev = None, file_ |
|
1643 | 1643 | elif rev is None: |
|
1644 | 1644 | raise error.CommandError('debugdata', _('invalid arguments')) |
|
1645 | 1645 | r = cmdutil.openrevlog(repo, 'debugdata', file_, opts) |
|
1646 | 1646 | try: |
|
1647 | 1647 | ui.write(r.revision(r.lookup(rev))) |
|
1648 | 1648 | except KeyError: |
|
1649 | 1649 | raise util.Abort(_('invalid revision identifier %s') % rev) |
|
1650 | 1650 | |
|
1651 | 1651 | @command('debugdate', |
|
1652 | 1652 | [('e', 'extended', None, _('try extended date formats'))], |
|
1653 | 1653 | _('[-e] DATE [RANGE]')) |
|
1654 | 1654 | def debugdate(ui, date, range=None, **opts): |
|
1655 | 1655 | """parse and display a date""" |
|
1656 | 1656 | if opts["extended"]: |
|
1657 | 1657 | d = util.parsedate(date, util.extendeddateformats) |
|
1658 | 1658 | else: |
|
1659 | 1659 | d = util.parsedate(date) |
|
1660 | 1660 | ui.write("internal: %s %s\n" % d) |
|
1661 | 1661 | ui.write("standard: %s\n" % util.datestr(d)) |
|
1662 | 1662 | if range: |
|
1663 | 1663 | m = util.matchdate(range) |
|
1664 | 1664 | ui.write("match: %s\n" % m(d[0])) |
|
1665 | 1665 | |
|
1666 | 1666 | @command('debugdiscovery', |
|
1667 | 1667 | [('', 'old', None, _('use old-style discovery')), |
|
1668 | 1668 | ('', 'nonheads', None, |
|
1669 | 1669 | _('use old-style discovery with non-heads included')), |
|
1670 | 1670 | ] + remoteopts, |
|
1671 | 1671 | _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) |
|
1672 | 1672 | def debugdiscovery(ui, repo, remoteurl="default", **opts): |
|
1673 | 1673 | """runs the changeset discovery protocol in isolation""" |
|
1674 | 1674 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), opts.get('branch')) |
|
1675 | 1675 | remote = hg.peer(repo, opts, remoteurl) |
|
1676 | 1676 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) |
|
1677 | 1677 | |
|
1678 | 1678 | # make sure tests are repeatable |
|
1679 | 1679 | random.seed(12323) |
|
1680 | 1680 | |
|
1681 | 1681 | def doit(localheads, remoteheads): |
|
1682 | 1682 | if opts.get('old'): |
|
1683 | 1683 | if localheads: |
|
1684 | 1684 | raise util.Abort('cannot use localheads with old style discovery') |
|
1685 | 1685 | common, _in, hds = treediscovery.findcommonincoming(repo, remote, |
|
1686 | 1686 | force=True) |
|
1687 | 1687 | common = set(common) |
|
1688 | 1688 | if not opts.get('nonheads'): |
|
1689 | 1689 | ui.write("unpruned common: %s\n" % " ".join([short(n) |
|
1690 | 1690 | for n in common])) |
|
1691 | 1691 | dag = dagutil.revlogdag(repo.changelog) |
|
1692 | 1692 | all = dag.ancestorset(dag.internalizeall(common)) |
|
1693 | 1693 | common = dag.externalizeall(dag.headsetofconnecteds(all)) |
|
1694 | 1694 | else: |
|
1695 | 1695 | common, any, hds = setdiscovery.findcommonheads(ui, repo, remote) |
|
1696 | 1696 | common = set(common) |
|
1697 | 1697 | rheads = set(hds) |
|
1698 | 1698 | lheads = set(repo.heads()) |
|
1699 | 1699 | ui.write("common heads: %s\n" % " ".join([short(n) for n in common])) |
|
1700 | 1700 | if lheads <= common: |
|
1701 | 1701 | ui.write("local is subset\n") |
|
1702 | 1702 | elif rheads <= common: |
|
1703 | 1703 | ui.write("remote is subset\n") |
|
1704 | 1704 | |
|
1705 | 1705 | serverlogs = opts.get('serverlog') |
|
1706 | 1706 | if serverlogs: |
|
1707 | 1707 | for filename in serverlogs: |
|
1708 | 1708 | logfile = open(filename, 'r') |
|
1709 | 1709 | try: |
|
1710 | 1710 | line = logfile.readline() |
|
1711 | 1711 | while line: |
|
1712 | 1712 | parts = line.strip().split(';') |
|
1713 | 1713 | op = parts[1] |
|
1714 | 1714 | if op == 'cg': |
|
1715 | 1715 | pass |
|
1716 | 1716 | elif op == 'cgss': |
|
1717 | 1717 | doit(parts[2].split(' '), parts[3].split(' ')) |
|
1718 | 1718 | elif op == 'unb': |
|
1719 | 1719 | doit(parts[3].split(' '), parts[2].split(' ')) |
|
1720 | 1720 | line = logfile.readline() |
|
1721 | 1721 | finally: |
|
1722 | 1722 | logfile.close() |
|
1723 | 1723 | |
|
1724 | 1724 | else: |
|
1725 | 1725 | remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, |
|
1726 | 1726 | opts.get('remote_head')) |
|
1727 | 1727 | localrevs = opts.get('local_head') |
|
1728 | 1728 | doit(localrevs, remoterevs) |
|
1729 | 1729 | |
|
1730 | 1730 | @command('debugfileset', [], ('REVSPEC')) |
|
1731 | 1731 | def debugfileset(ui, repo, expr): |
|
1732 | 1732 | '''parse and apply a fileset specification''' |
|
1733 | 1733 | if ui.verbose: |
|
1734 | 1734 | tree = fileset.parse(expr)[0] |
|
1735 | 1735 | ui.note(tree, "\n") |
|
1736 | 1736 | |
|
1737 | 1737 | for f in fileset.getfileset(repo[None], expr): |
|
1738 | 1738 | ui.write("%s\n" % f) |
|
1739 | 1739 | |
|
1740 | 1740 | @command('debugfsinfo', [], _('[PATH]')) |
|
1741 | 1741 | def debugfsinfo(ui, path = "."): |
|
1742 | 1742 | """show information detected about current filesystem""" |
|
1743 | 1743 | util.writefile('.debugfsinfo', '') |
|
1744 | 1744 | ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) |
|
1745 | 1745 | ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) |
|
1746 | 1746 | ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') |
|
1747 | 1747 | and 'yes' or 'no')) |
|
1748 | 1748 | os.unlink('.debugfsinfo') |
|
1749 | 1749 | |
|
1750 | 1750 | @command('debuggetbundle', |
|
1751 | 1751 | [('H', 'head', [], _('id of head node'), _('ID')), |
|
1752 | 1752 | ('C', 'common', [], _('id of common node'), _('ID')), |
|
1753 | 1753 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))], |
|
1754 | 1754 | _('REPO FILE [-H|-C ID]...')) |
|
1755 | 1755 | def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts): |
|
1756 | 1756 | """retrieves a bundle from a repo |
|
1757 | 1757 | |
|
1758 | 1758 | Every ID must be a full-length hex node id string. Saves the bundle to the |
|
1759 | 1759 | given file. |
|
1760 | 1760 | """ |
|
1761 | 1761 | repo = hg.peer(ui, opts, repopath) |
|
1762 | 1762 | if not repo.capable('getbundle'): |
|
1763 | 1763 | raise util.Abort("getbundle() not supported by target repository") |
|
1764 | 1764 | args = {} |
|
1765 | 1765 | if common: |
|
1766 | 1766 | args['common'] = [bin(s) for s in common] |
|
1767 | 1767 | if head: |
|
1768 | 1768 | args['heads'] = [bin(s) for s in head] |
|
1769 | 1769 | bundle = repo.getbundle('debug', **args) |
|
1770 | 1770 | |
|
1771 | 1771 | bundletype = opts.get('type', 'bzip2').lower() |
|
1772 | 1772 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} |
|
1773 | 1773 | bundletype = btypes.get(bundletype) |
|
1774 | 1774 | if bundletype not in changegroup.bundletypes: |
|
1775 | 1775 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
1776 | 1776 | changegroup.writebundle(bundle, bundlepath, bundletype) |
|
1777 | 1777 | |
|
1778 | 1778 | @command('debugignore', [], '') |
|
1779 | 1779 | def debugignore(ui, repo, *values, **opts): |
|
1780 | 1780 | """display the combined ignore pattern""" |
|
1781 | 1781 | ignore = repo.dirstate._ignore |
|
1782 | 1782 | includepat = getattr(ignore, 'includepat', None) |
|
1783 | 1783 | if includepat is not None: |
|
1784 | 1784 | ui.write("%s\n" % includepat) |
|
1785 | 1785 | else: |
|
1786 | 1786 | raise util.Abort(_("no ignore patterns found")) |
|
1787 | 1787 | |
|
1788 | 1788 | @command('debugindex', |
|
1789 | 1789 | [('c', 'changelog', False, _('open changelog')), |
|
1790 | 1790 | ('m', 'manifest', False, _('open manifest')), |
|
1791 | 1791 | ('f', 'format', 0, _('revlog format'), _('FORMAT'))], |
|
1792 | 1792 | _('[-f FORMAT] -c|-m|FILE')) |
|
1793 | 1793 | def debugindex(ui, repo, file_ = None, **opts): |
|
1794 | 1794 | """dump the contents of an index file""" |
|
1795 | 1795 | r = cmdutil.openrevlog(repo, 'debugindex', file_, opts) |
|
1796 | 1796 | format = opts.get('format', 0) |
|
1797 | 1797 | if format not in (0, 1): |
|
1798 | 1798 | raise util.Abort(_("unknown format %d") % format) |
|
1799 | 1799 | |
|
1800 | 1800 | generaldelta = r.version & revlog.REVLOGGENERALDELTA |
|
1801 | 1801 | if generaldelta: |
|
1802 | 1802 | basehdr = ' delta' |
|
1803 | 1803 | else: |
|
1804 | 1804 | basehdr = ' base' |
|
1805 | 1805 | |
|
1806 | 1806 | if format == 0: |
|
1807 | 1807 | ui.write(" rev offset length " + basehdr + " linkrev" |
|
1808 | 1808 | " nodeid p1 p2\n") |
|
1809 | 1809 | elif format == 1: |
|
1810 | 1810 | ui.write(" rev flag offset length" |
|
1811 | 1811 | " size " + basehdr + " link p1 p2 nodeid\n") |
|
1812 | 1812 | |
|
1813 | 1813 | for i in r: |
|
1814 | 1814 | node = r.node(i) |
|
1815 | 1815 | if generaldelta: |
|
1816 | 1816 | base = r.deltaparent(i) |
|
1817 | 1817 | else: |
|
1818 | 1818 | base = r.chainbase(i) |
|
1819 | 1819 | if format == 0: |
|
1820 | 1820 | try: |
|
1821 | 1821 | pp = r.parents(node) |
|
1822 | 1822 | except: |
|
1823 | 1823 | pp = [nullid, nullid] |
|
1824 | 1824 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1825 | 1825 | i, r.start(i), r.length(i), base, r.linkrev(i), |
|
1826 | 1826 | short(node), short(pp[0]), short(pp[1]))) |
|
1827 | 1827 | elif format == 1: |
|
1828 | 1828 | pr = r.parentrevs(i) |
|
1829 | 1829 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( |
|
1830 | 1830 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), |
|
1831 | 1831 | base, r.linkrev(i), pr[0], pr[1], short(node))) |
|
1832 | 1832 | |
|
1833 | 1833 | @command('debugindexdot', [], _('FILE')) |
|
1834 | 1834 | def debugindexdot(ui, repo, file_): |
|
1835 | 1835 | """dump an index DAG as a graphviz dot file""" |
|
1836 | 1836 | r = None |
|
1837 | 1837 | if repo: |
|
1838 | 1838 | filelog = repo.file(file_) |
|
1839 | 1839 | if len(filelog): |
|
1840 | 1840 | r = filelog |
|
1841 | 1841 | if not r: |
|
1842 | 1842 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
1843 | 1843 | ui.write("digraph G {\n") |
|
1844 | 1844 | for i in r: |
|
1845 | 1845 | node = r.node(i) |
|
1846 | 1846 | pp = r.parents(node) |
|
1847 | 1847 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
1848 | 1848 | if pp[1] != nullid: |
|
1849 | 1849 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
1850 | 1850 | ui.write("}\n") |
|
1851 | 1851 | |
|
1852 | 1852 | @command('debuginstall', [], '') |
|
1853 | 1853 | def debuginstall(ui): |
|
1854 | 1854 | '''test Mercurial installation |
|
1855 | 1855 | |
|
1856 | 1856 | Returns 0 on success. |
|
1857 | 1857 | ''' |
|
1858 | 1858 | |
|
1859 | 1859 | def writetemp(contents): |
|
1860 | 1860 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") |
|
1861 | 1861 | f = os.fdopen(fd, "wb") |
|
1862 | 1862 | f.write(contents) |
|
1863 | 1863 | f.close() |
|
1864 | 1864 | return name |
|
1865 | 1865 | |
|
1866 | 1866 | problems = 0 |
|
1867 | 1867 | |
|
1868 | 1868 | # encoding |
|
1869 | 1869 | ui.status(_("Checking encoding (%s)...\n") % encoding.encoding) |
|
1870 | 1870 | try: |
|
1871 | 1871 | encoding.fromlocal("test") |
|
1872 | 1872 | except util.Abort, inst: |
|
1873 | 1873 | ui.write(" %s\n" % inst) |
|
1874 | 1874 | ui.write(_(" (check that your locale is properly set)\n")) |
|
1875 | 1875 | problems += 1 |
|
1876 | 1876 | |
|
1877 | 1877 | # compiled modules |
|
1878 | 1878 | ui.status(_("Checking installed modules (%s)...\n") |
|
1879 | 1879 | % os.path.dirname(__file__)) |
|
1880 | 1880 | try: |
|
1881 | 1881 | import bdiff, mpatch, base85, osutil |
|
1882 | 1882 | dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes |
|
1883 | 1883 | except Exception, inst: |
|
1884 | 1884 | ui.write(" %s\n" % inst) |
|
1885 | 1885 | ui.write(_(" One or more extensions could not be found")) |
|
1886 | 1886 | ui.write(_(" (check that you compiled the extensions)\n")) |
|
1887 | 1887 | problems += 1 |
|
1888 | 1888 | |
|
1889 | 1889 | # templates |
|
1890 | 1890 | import templater |
|
1891 | 1891 | p = templater.templatepath() |
|
1892 | 1892 | ui.status(_("Checking templates (%s)...\n") % ' '.join(p)) |
|
1893 | 1893 | try: |
|
1894 | 1894 | templater.templater(templater.templatepath("map-cmdline.default")) |
|
1895 | 1895 | except Exception, inst: |
|
1896 | 1896 | ui.write(" %s\n" % inst) |
|
1897 | 1897 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) |
|
1898 | 1898 | problems += 1 |
|
1899 | 1899 | |
|
1900 | 1900 | # editor |
|
1901 | 1901 | ui.status(_("Checking commit editor...\n")) |
|
1902 | 1902 | editor = ui.geteditor() |
|
1903 | 1903 | cmdpath = util.findexe(editor) or util.findexe(editor.split()[0]) |
|
1904 | 1904 | if not cmdpath: |
|
1905 | 1905 | if editor == 'vi': |
|
1906 | 1906 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) |
|
1907 | 1907 | ui.write(_(" (specify a commit editor in your configuration" |
|
1908 | 1908 | " file)\n")) |
|
1909 | 1909 | else: |
|
1910 | 1910 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) |
|
1911 | 1911 | ui.write(_(" (specify a commit editor in your configuration" |
|
1912 | 1912 | " file)\n")) |
|
1913 | 1913 | problems += 1 |
|
1914 | 1914 | |
|
1915 | 1915 | # check username |
|
1916 | 1916 | ui.status(_("Checking username...\n")) |
|
1917 | 1917 | try: |
|
1918 | 1918 | ui.username() |
|
1919 | 1919 | except util.Abort, e: |
|
1920 | 1920 | ui.write(" %s\n" % e) |
|
1921 | 1921 | ui.write(_(" (specify a username in your configuration file)\n")) |
|
1922 | 1922 | problems += 1 |
|
1923 | 1923 | |
|
1924 | 1924 | if not problems: |
|
1925 | 1925 | ui.status(_("No problems detected\n")) |
|
1926 | 1926 | else: |
|
1927 | 1927 | ui.write(_("%s problems detected," |
|
1928 | 1928 | " please check your install!\n") % problems) |
|
1929 | 1929 | |
|
1930 | 1930 | return problems |
|
1931 | 1931 | |
|
1932 | 1932 | @command('debugknown', [], _('REPO ID...')) |
|
1933 | 1933 | def debugknown(ui, repopath, *ids, **opts): |
|
1934 | 1934 | """test whether node ids are known to a repo |
|
1935 | 1935 | |
|
1936 | 1936 | Every ID must be a full-length hex node id string. Returns a list of 0s and 1s |
|
1937 | 1937 | indicating unknown/known. |
|
1938 | 1938 | """ |
|
1939 | 1939 | repo = hg.peer(ui, opts, repopath) |
|
1940 | 1940 | if not repo.capable('known'): |
|
1941 | 1941 | raise util.Abort("known() not supported by target repository") |
|
1942 | 1942 | flags = repo.known([bin(s) for s in ids]) |
|
1943 | 1943 | ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) |
|
1944 | 1944 | |
|
1945 | 1945 | @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]')) |
|
1946 | 1946 | def debugpushkey(ui, repopath, namespace, *keyinfo, **opts): |
|
1947 | 1947 | '''access the pushkey key/value protocol |
|
1948 | 1948 | |
|
1949 | 1949 | With two args, list the keys in the given namespace. |
|
1950 | 1950 | |
|
1951 | 1951 | With five args, set a key to new if it currently is set to old. |
|
1952 | 1952 | Reports success or failure. |
|
1953 | 1953 | ''' |
|
1954 | 1954 | |
|
1955 | 1955 | target = hg.peer(ui, {}, repopath) |
|
1956 | 1956 | if keyinfo: |
|
1957 | 1957 | key, old, new = keyinfo |
|
1958 | 1958 | r = target.pushkey(namespace, key, old, new) |
|
1959 | 1959 | ui.status(str(r) + '\n') |
|
1960 | 1960 | return not r |
|
1961 | 1961 | else: |
|
1962 | 1962 | for k, v in target.listkeys(namespace).iteritems(): |
|
1963 | 1963 | ui.write("%s\t%s\n" % (k.encode('string-escape'), |
|
1964 | 1964 | v.encode('string-escape'))) |
|
1965 | 1965 | |
|
1966 | 1966 | @command('debugpvec', [], _('A B')) |
|
1967 | 1967 | def debugpvec(ui, repo, a, b=None): |
|
1968 | 1968 | ca = scmutil.revsingle(repo, a) |
|
1969 | 1969 | cb = scmutil.revsingle(repo, b) |
|
1970 | 1970 | pa = pvec.ctxpvec(ca) |
|
1971 | 1971 | pb = pvec.ctxpvec(cb) |
|
1972 | 1972 | if pa == pb: |
|
1973 | 1973 | rel = "=" |
|
1974 | 1974 | elif pa > pb: |
|
1975 | 1975 | rel = ">" |
|
1976 | 1976 | elif pa < pb: |
|
1977 | 1977 | rel = "<" |
|
1978 | 1978 | elif pa | pb: |
|
1979 | 1979 | rel = "|" |
|
1980 | 1980 | ui.write(_("a: %s\n") % pa) |
|
1981 | 1981 | ui.write(_("b: %s\n") % pb) |
|
1982 | 1982 | ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth)) |
|
1983 | 1983 | ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") % |
|
1984 | 1984 | (abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec), |
|
1985 | 1985 | pa.distance(pb), rel)) |
|
1986 | 1986 | |
|
1987 | 1987 | @command('debugrebuildstate', |
|
1988 | 1988 | [('r', 'rev', '', _('revision to rebuild to'), _('REV'))], |
|
1989 | 1989 | _('[-r REV] [REV]')) |
|
1990 | 1990 | def debugrebuildstate(ui, repo, rev="tip"): |
|
1991 | 1991 | """rebuild the dirstate as it would look like for the given revision""" |
|
1992 | 1992 | ctx = scmutil.revsingle(repo, rev) |
|
1993 | 1993 | wlock = repo.wlock() |
|
1994 | 1994 | try: |
|
1995 | 1995 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
1996 | 1996 | finally: |
|
1997 | 1997 | wlock.release() |
|
1998 | 1998 | |
|
1999 | 1999 | @command('debugrename', |
|
2000 | 2000 | [('r', 'rev', '', _('revision to debug'), _('REV'))], |
|
2001 | 2001 | _('[-r REV] FILE')) |
|
2002 | 2002 | def debugrename(ui, repo, file1, *pats, **opts): |
|
2003 | 2003 | """dump rename information""" |
|
2004 | 2004 | |
|
2005 | 2005 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
2006 | 2006 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
2007 | 2007 | for abs in ctx.walk(m): |
|
2008 | 2008 | fctx = ctx[abs] |
|
2009 | 2009 | o = fctx.filelog().renamed(fctx.filenode()) |
|
2010 | 2010 | rel = m.rel(abs) |
|
2011 | 2011 | if o: |
|
2012 | 2012 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) |
|
2013 | 2013 | else: |
|
2014 | 2014 | ui.write(_("%s not renamed\n") % rel) |
|
2015 | 2015 | |
|
2016 | 2016 | @command('debugrevlog', |
|
2017 | 2017 | [('c', 'changelog', False, _('open changelog')), |
|
2018 | 2018 | ('m', 'manifest', False, _('open manifest')), |
|
2019 | 2019 | ('d', 'dump', False, _('dump index data'))], |
|
2020 | 2020 | _('-c|-m|FILE')) |
|
2021 | 2021 | def debugrevlog(ui, repo, file_ = None, **opts): |
|
2022 | 2022 | """show data and statistics about a revlog""" |
|
2023 | 2023 | r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts) |
|
2024 | 2024 | |
|
2025 | 2025 | if opts.get("dump"): |
|
2026 | 2026 | numrevs = len(r) |
|
2027 | 2027 | ui.write("# rev p1rev p2rev start end deltastart base p1 p2" |
|
2028 | 2028 | " rawsize totalsize compression heads\n") |
|
2029 | 2029 | ts = 0 |
|
2030 | 2030 | heads = set() |
|
2031 | 2031 | for rev in xrange(numrevs): |
|
2032 | 2032 | dbase = r.deltaparent(rev) |
|
2033 | 2033 | if dbase == -1: |
|
2034 | 2034 | dbase = rev |
|
2035 | 2035 | cbase = r.chainbase(rev) |
|
2036 | 2036 | p1, p2 = r.parentrevs(rev) |
|
2037 | 2037 | rs = r.rawsize(rev) |
|
2038 | 2038 | ts = ts + rs |
|
2039 | 2039 | heads -= set(r.parentrevs(rev)) |
|
2040 | 2040 | heads.add(rev) |
|
2041 | 2041 | ui.write("%d %d %d %d %d %d %d %d %d %d %d %d %d\n" % |
|
2042 | 2042 | (rev, p1, p2, r.start(rev), r.end(rev), |
|
2043 | 2043 | r.start(dbase), r.start(cbase), |
|
2044 | 2044 | r.start(p1), r.start(p2), |
|
2045 | 2045 | rs, ts, ts / r.end(rev), len(heads))) |
|
2046 | 2046 | return 0 |
|
2047 | 2047 | |
|
2048 | 2048 | v = r.version |
|
2049 | 2049 | format = v & 0xFFFF |
|
2050 | 2050 | flags = [] |
|
2051 | 2051 | gdelta = False |
|
2052 | 2052 | if v & revlog.REVLOGNGINLINEDATA: |
|
2053 | 2053 | flags.append('inline') |
|
2054 | 2054 | if v & revlog.REVLOGGENERALDELTA: |
|
2055 | 2055 | gdelta = True |
|
2056 | 2056 | flags.append('generaldelta') |
|
2057 | 2057 | if not flags: |
|
2058 | 2058 | flags = ['(none)'] |
|
2059 | 2059 | |
|
2060 | 2060 | nummerges = 0 |
|
2061 | 2061 | numfull = 0 |
|
2062 | 2062 | numprev = 0 |
|
2063 | 2063 | nump1 = 0 |
|
2064 | 2064 | nump2 = 0 |
|
2065 | 2065 | numother = 0 |
|
2066 | 2066 | nump1prev = 0 |
|
2067 | 2067 | nump2prev = 0 |
|
2068 | 2068 | chainlengths = [] |
|
2069 | 2069 | |
|
2070 | 2070 | datasize = [None, 0, 0L] |
|
2071 | 2071 | fullsize = [None, 0, 0L] |
|
2072 | 2072 | deltasize = [None, 0, 0L] |
|
2073 | 2073 | |
|
2074 | 2074 | def addsize(size, l): |
|
2075 | 2075 | if l[0] is None or size < l[0]: |
|
2076 | 2076 | l[0] = size |
|
2077 | 2077 | if size > l[1]: |
|
2078 | 2078 | l[1] = size |
|
2079 | 2079 | l[2] += size |
|
2080 | 2080 | |
|
2081 | 2081 | numrevs = len(r) |
|
2082 | 2082 | for rev in xrange(numrevs): |
|
2083 | 2083 | p1, p2 = r.parentrevs(rev) |
|
2084 | 2084 | delta = r.deltaparent(rev) |
|
2085 | 2085 | if format > 0: |
|
2086 | 2086 | addsize(r.rawsize(rev), datasize) |
|
2087 | 2087 | if p2 != nullrev: |
|
2088 | 2088 | nummerges += 1 |
|
2089 | 2089 | size = r.length(rev) |
|
2090 | 2090 | if delta == nullrev: |
|
2091 | 2091 | chainlengths.append(0) |
|
2092 | 2092 | numfull += 1 |
|
2093 | 2093 | addsize(size, fullsize) |
|
2094 | 2094 | else: |
|
2095 | 2095 | chainlengths.append(chainlengths[delta] + 1) |
|
2096 | 2096 | addsize(size, deltasize) |
|
2097 | 2097 | if delta == rev - 1: |
|
2098 | 2098 | numprev += 1 |
|
2099 | 2099 | if delta == p1: |
|
2100 | 2100 | nump1prev += 1 |
|
2101 | 2101 | elif delta == p2: |
|
2102 | 2102 | nump2prev += 1 |
|
2103 | 2103 | elif delta == p1: |
|
2104 | 2104 | nump1 += 1 |
|
2105 | 2105 | elif delta == p2: |
|
2106 | 2106 | nump2 += 1 |
|
2107 | 2107 | elif delta != nullrev: |
|
2108 | 2108 | numother += 1 |
|
2109 | 2109 | |
|
2110 | 2110 | numdeltas = numrevs - numfull |
|
2111 | 2111 | numoprev = numprev - nump1prev - nump2prev |
|
2112 | 2112 | totalrawsize = datasize[2] |
|
2113 | 2113 | datasize[2] /= numrevs |
|
2114 | 2114 | fulltotal = fullsize[2] |
|
2115 | 2115 | fullsize[2] /= numfull |
|
2116 | 2116 | deltatotal = deltasize[2] |
|
2117 | 2117 | deltasize[2] /= numrevs - numfull |
|
2118 | 2118 | totalsize = fulltotal + deltatotal |
|
2119 | 2119 | avgchainlen = sum(chainlengths) / numrevs |
|
2120 | 2120 | compratio = totalrawsize / totalsize |
|
2121 | 2121 | |
|
2122 | 2122 | basedfmtstr = '%%%dd\n' |
|
2123 | 2123 | basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n' |
|
2124 | 2124 | |
|
2125 | 2125 | def dfmtstr(max): |
|
2126 | 2126 | return basedfmtstr % len(str(max)) |
|
2127 | 2127 | def pcfmtstr(max, padding=0): |
|
2128 | 2128 | return basepcfmtstr % (len(str(max)), ' ' * padding) |
|
2129 | 2129 | |
|
2130 | 2130 | def pcfmt(value, total): |
|
2131 | 2131 | return (value, 100 * float(value) / total) |
|
2132 | 2132 | |
|
2133 | 2133 | ui.write('format : %d\n' % format) |
|
2134 | 2134 | ui.write('flags : %s\n' % ', '.join(flags)) |
|
2135 | 2135 | |
|
2136 | 2136 | ui.write('\n') |
|
2137 | 2137 | fmt = pcfmtstr(totalsize) |
|
2138 | 2138 | fmt2 = dfmtstr(totalsize) |
|
2139 | 2139 | ui.write('revisions : ' + fmt2 % numrevs) |
|
2140 | 2140 | ui.write(' merges : ' + fmt % pcfmt(nummerges, numrevs)) |
|
2141 | 2141 | ui.write(' normal : ' + fmt % pcfmt(numrevs - nummerges, numrevs)) |
|
2142 | 2142 | ui.write('revisions : ' + fmt2 % numrevs) |
|
2143 | 2143 | ui.write(' full : ' + fmt % pcfmt(numfull, numrevs)) |
|
2144 | 2144 | ui.write(' deltas : ' + fmt % pcfmt(numdeltas, numrevs)) |
|
2145 | 2145 | ui.write('revision size : ' + fmt2 % totalsize) |
|
2146 | 2146 | ui.write(' full : ' + fmt % pcfmt(fulltotal, totalsize)) |
|
2147 | 2147 | ui.write(' deltas : ' + fmt % pcfmt(deltatotal, totalsize)) |
|
2148 | 2148 | |
|
2149 | 2149 | ui.write('\n') |
|
2150 | 2150 | fmt = dfmtstr(max(avgchainlen, compratio)) |
|
2151 | 2151 | ui.write('avg chain length : ' + fmt % avgchainlen) |
|
2152 | 2152 | ui.write('compression ratio : ' + fmt % compratio) |
|
2153 | 2153 | |
|
2154 | 2154 | if format > 0: |
|
2155 | 2155 | ui.write('\n') |
|
2156 | 2156 | ui.write('uncompressed data size (min/max/avg) : %d / %d / %d\n' |
|
2157 | 2157 | % tuple(datasize)) |
|
2158 | 2158 | ui.write('full revision size (min/max/avg) : %d / %d / %d\n' |
|
2159 | 2159 | % tuple(fullsize)) |
|
2160 | 2160 | ui.write('delta size (min/max/avg) : %d / %d / %d\n' |
|
2161 | 2161 | % tuple(deltasize)) |
|
2162 | 2162 | |
|
2163 | 2163 | if numdeltas > 0: |
|
2164 | 2164 | ui.write('\n') |
|
2165 | 2165 | fmt = pcfmtstr(numdeltas) |
|
2166 | 2166 | fmt2 = pcfmtstr(numdeltas, 4) |
|
2167 | 2167 | ui.write('deltas against prev : ' + fmt % pcfmt(numprev, numdeltas)) |
|
2168 | 2168 | if numprev > 0: |
|
2169 | 2169 | ui.write(' where prev = p1 : ' + fmt2 % pcfmt(nump1prev, numprev)) |
|
2170 | 2170 | ui.write(' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, numprev)) |
|
2171 | 2171 | ui.write(' other : ' + fmt2 % pcfmt(numoprev, numprev)) |
|
2172 | 2172 | if gdelta: |
|
2173 | 2173 | ui.write('deltas against p1 : ' + fmt % pcfmt(nump1, numdeltas)) |
|
2174 | 2174 | ui.write('deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas)) |
|
2175 | 2175 | ui.write('deltas against other : ' + fmt % pcfmt(numother, numdeltas)) |
|
2176 | 2176 | |
|
2177 | 2177 | @command('debugrevspec', [], ('REVSPEC')) |
|
2178 | 2178 | def debugrevspec(ui, repo, expr): |
|
2179 | 2179 | """parse and apply a revision specification |
|
2180 | 2180 | |
|
2181 | 2181 | Use --verbose to print the parsed tree before and after aliases |
|
2182 | 2182 | expansion. |
|
2183 | 2183 | """ |
|
2184 | 2184 | if ui.verbose: |
|
2185 | 2185 | tree = revset.parse(expr)[0] |
|
2186 | 2186 | ui.note(revset.prettyformat(tree), "\n") |
|
2187 | 2187 | newtree = revset.findaliases(ui, tree) |
|
2188 | 2188 | if newtree != tree: |
|
2189 | 2189 | ui.note(revset.prettyformat(newtree), "\n") |
|
2190 | 2190 | func = revset.match(ui, expr) |
|
2191 | 2191 | for c in func(repo, range(len(repo))): |
|
2192 | 2192 | ui.write("%s\n" % c) |
|
2193 | 2193 | |
|
2194 | 2194 | @command('debugsetparents', [], _('REV1 [REV2]')) |
|
2195 | 2195 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
2196 | 2196 | """manually set the parents of the current working directory |
|
2197 | 2197 | |
|
2198 | 2198 | This is useful for writing repository conversion tools, but should |
|
2199 | 2199 | be used with care. |
|
2200 | 2200 | |
|
2201 | 2201 | Returns 0 on success. |
|
2202 | 2202 | """ |
|
2203 | 2203 | |
|
2204 | 2204 | r1 = scmutil.revsingle(repo, rev1).node() |
|
2205 | 2205 | r2 = scmutil.revsingle(repo, rev2, 'null').node() |
|
2206 | 2206 | |
|
2207 | 2207 | wlock = repo.wlock() |
|
2208 | 2208 | try: |
|
2209 | 2209 | repo.dirstate.setparents(r1, r2) |
|
2210 | 2210 | finally: |
|
2211 | 2211 | wlock.release() |
|
2212 | 2212 | |
|
2213 | 2213 | @command('debugstate', |
|
2214 | 2214 | [('', 'nodates', None, _('do not display the saved mtime')), |
|
2215 | 2215 | ('', 'datesort', None, _('sort by saved mtime'))], |
|
2216 | 2216 | _('[OPTION]...')) |
|
2217 | 2217 | def debugstate(ui, repo, nodates=None, datesort=None): |
|
2218 | 2218 | """show the contents of the current dirstate""" |
|
2219 | 2219 | timestr = "" |
|
2220 | 2220 | showdate = not nodates |
|
2221 | 2221 | if datesort: |
|
2222 | 2222 | keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename |
|
2223 | 2223 | else: |
|
2224 | 2224 | keyfunc = None # sort by filename |
|
2225 | 2225 | for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc): |
|
2226 | 2226 | if showdate: |
|
2227 | 2227 | if ent[3] == -1: |
|
2228 | 2228 | # Pad or slice to locale representation |
|
2229 | 2229 | locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", |
|
2230 | 2230 | time.localtime(0))) |
|
2231 | 2231 | timestr = 'unset' |
|
2232 | 2232 | timestr = (timestr[:locale_len] + |
|
2233 | 2233 | ' ' * (locale_len - len(timestr))) |
|
2234 | 2234 | else: |
|
2235 | 2235 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", |
|
2236 | 2236 | time.localtime(ent[3])) |
|
2237 | 2237 | if ent[1] & 020000: |
|
2238 | 2238 | mode = 'lnk' |
|
2239 | 2239 | else: |
|
2240 | 2240 | mode = '%3o' % (ent[1] & 0777 & ~util.umask) |
|
2241 | 2241 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
|
2242 | 2242 | for f in repo.dirstate.copies(): |
|
2243 | 2243 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
2244 | 2244 | |
|
2245 | 2245 | @command('debugsub', |
|
2246 | 2246 | [('r', 'rev', '', |
|
2247 | 2247 | _('revision to check'), _('REV'))], |
|
2248 | 2248 | _('[-r REV] [REV]')) |
|
2249 | 2249 | def debugsub(ui, repo, rev=None): |
|
2250 | 2250 | ctx = scmutil.revsingle(repo, rev, None) |
|
2251 | 2251 | for k, v in sorted(ctx.substate.items()): |
|
2252 | 2252 | ui.write('path %s\n' % k) |
|
2253 | 2253 | ui.write(' source %s\n' % v[0]) |
|
2254 | 2254 | ui.write(' revision %s\n' % v[1]) |
|
2255 | 2255 | |
|
2256 | 2256 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...')) |
|
2257 | 2257 | def debugwalk(ui, repo, *pats, **opts): |
|
2258 | 2258 | """show how files match on given patterns""" |
|
2259 | 2259 | m = scmutil.match(repo[None], pats, opts) |
|
2260 | 2260 | items = list(repo.walk(m)) |
|
2261 | 2261 | if not items: |
|
2262 | 2262 | return |
|
2263 | 2263 | fmt = 'f %%-%ds %%-%ds %%s' % ( |
|
2264 | 2264 | max([len(abs) for abs in items]), |
|
2265 | 2265 | max([len(m.rel(abs)) for abs in items])) |
|
2266 | 2266 | for abs in items: |
|
2267 | 2267 | line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '') |
|
2268 | 2268 | ui.write("%s\n" % line.rstrip()) |
|
2269 | 2269 | |
|
2270 | 2270 | @command('debugwireargs', |
|
2271 | 2271 | [('', 'three', '', 'three'), |
|
2272 | 2272 | ('', 'four', '', 'four'), |
|
2273 | 2273 | ('', 'five', '', 'five'), |
|
2274 | 2274 | ] + remoteopts, |
|
2275 | 2275 | _('REPO [OPTIONS]... [ONE [TWO]]')) |
|
2276 | 2276 | def debugwireargs(ui, repopath, *vals, **opts): |
|
2277 | 2277 | repo = hg.peer(ui, opts, repopath) |
|
2278 | 2278 | for opt in remoteopts: |
|
2279 | 2279 | del opts[opt[1]] |
|
2280 | 2280 | args = {} |
|
2281 | 2281 | for k, v in opts.iteritems(): |
|
2282 | 2282 | if v: |
|
2283 | 2283 | args[k] = v |
|
2284 | 2284 | # run twice to check that we don't mess up the stream for the next command |
|
2285 | 2285 | res1 = repo.debugwireargs(*vals, **args) |
|
2286 | 2286 | res2 = repo.debugwireargs(*vals, **args) |
|
2287 | 2287 | ui.write("%s\n" % res1) |
|
2288 | 2288 | if res1 != res2: |
|
2289 | 2289 | ui.warn("%s\n" % res2) |
|
2290 | 2290 | |
|
2291 | 2291 | @command('^diff', |
|
2292 | 2292 | [('r', 'rev', [], _('revision'), _('REV')), |
|
2293 | 2293 | ('c', 'change', '', _('change made by revision'), _('REV')) |
|
2294 | 2294 | ] + diffopts + diffopts2 + walkopts + subrepoopts, |
|
2295 | 2295 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...')) |
|
2296 | 2296 | def diff(ui, repo, *pats, **opts): |
|
2297 | 2297 | """diff repository (or selected files) |
|
2298 | 2298 | |
|
2299 | 2299 | Show differences between revisions for the specified files. |
|
2300 | 2300 | |
|
2301 | 2301 | Differences between files are shown using the unified diff format. |
|
2302 | 2302 | |
|
2303 | 2303 | .. note:: |
|
2304 | 2304 | diff may generate unexpected results for merges, as it will |
|
2305 | 2305 | default to comparing against the working directory's first |
|
2306 | 2306 | parent changeset if no revisions are specified. |
|
2307 | 2307 | |
|
2308 | 2308 | When two revision arguments are given, then changes are shown |
|
2309 | 2309 | between those revisions. If only one revision is specified then |
|
2310 | 2310 | that revision is compared to the working directory, and, when no |
|
2311 | 2311 | revisions are specified, the working directory files are compared |
|
2312 | 2312 | to its parent. |
|
2313 | 2313 | |
|
2314 | 2314 | Alternatively you can specify -c/--change with a revision to see |
|
2315 | 2315 | the changes in that changeset relative to its first parent. |
|
2316 | 2316 | |
|
2317 | 2317 | Without the -a/--text option, diff will avoid generating diffs of |
|
2318 | 2318 | files it detects as binary. With -a, diff will generate a diff |
|
2319 | 2319 | anyway, probably with undesirable results. |
|
2320 | 2320 | |
|
2321 | 2321 | Use the -g/--git option to generate diffs in the git extended diff |
|
2322 | 2322 | format. For more information, read :hg:`help diffs`. |
|
2323 | 2323 | |
|
2324 | 2324 | .. container:: verbose |
|
2325 | 2325 | |
|
2326 | 2326 | Examples: |
|
2327 | 2327 | |
|
2328 | 2328 | - compare a file in the current working directory to its parent:: |
|
2329 | 2329 | |
|
2330 | 2330 | hg diff foo.c |
|
2331 | 2331 | |
|
2332 | 2332 | - compare two historical versions of a directory, with rename info:: |
|
2333 | 2333 | |
|
2334 | 2334 | hg diff --git -r 1.0:1.2 lib/ |
|
2335 | 2335 | |
|
2336 | 2336 | - get change stats relative to the last change on some date:: |
|
2337 | 2337 | |
|
2338 | 2338 | hg diff --stat -r "date('may 2')" |
|
2339 | 2339 | |
|
2340 | 2340 | - diff all newly-added files that contain a keyword:: |
|
2341 | 2341 | |
|
2342 | 2342 | hg diff "set:added() and grep(GNU)" |
|
2343 | 2343 | |
|
2344 | 2344 | - compare a revision and its parents:: |
|
2345 | 2345 | |
|
2346 | 2346 | hg diff -c 9353 # compare against first parent |
|
2347 | 2347 | hg diff -r 9353^:9353 # same using revset syntax |
|
2348 | 2348 | hg diff -r 9353^2:9353 # compare against the second parent |
|
2349 | 2349 | |
|
2350 | 2350 | Returns 0 on success. |
|
2351 | 2351 | """ |
|
2352 | 2352 | |
|
2353 | 2353 | revs = opts.get('rev') |
|
2354 | 2354 | change = opts.get('change') |
|
2355 | 2355 | stat = opts.get('stat') |
|
2356 | 2356 | reverse = opts.get('reverse') |
|
2357 | 2357 | |
|
2358 | 2358 | if revs and change: |
|
2359 | 2359 | msg = _('cannot specify --rev and --change at the same time') |
|
2360 | 2360 | raise util.Abort(msg) |
|
2361 | 2361 | elif change: |
|
2362 | 2362 | node2 = scmutil.revsingle(repo, change, None).node() |
|
2363 | 2363 | node1 = repo[node2].p1().node() |
|
2364 | 2364 | else: |
|
2365 | 2365 | node1, node2 = scmutil.revpair(repo, revs) |
|
2366 | 2366 | |
|
2367 | 2367 | if reverse: |
|
2368 | 2368 | node1, node2 = node2, node1 |
|
2369 | 2369 | |
|
2370 | 2370 | diffopts = patch.diffopts(ui, opts) |
|
2371 | 2371 | m = scmutil.match(repo[node2], pats, opts) |
|
2372 | 2372 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, |
|
2373 | 2373 | listsubrepos=opts.get('subrepos')) |
|
2374 | 2374 | |
|
2375 | 2375 | @command('^export', |
|
2376 | 2376 | [('o', 'output', '', |
|
2377 | 2377 | _('print output to file with formatted name'), _('FORMAT')), |
|
2378 | 2378 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
2379 | 2379 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
2380 | 2380 | ] + diffopts, |
|
2381 | 2381 | _('[OPTION]... [-o OUTFILESPEC] REV...')) |
|
2382 | 2382 | def export(ui, repo, *changesets, **opts): |
|
2383 | 2383 | """dump the header and diffs for one or more changesets |
|
2384 | 2384 | |
|
2385 | 2385 | Print the changeset header and diffs for one or more revisions. |
|
2386 | 2386 | |
|
2387 | 2387 | The information shown in the changeset header is: author, date, |
|
2388 | 2388 | branch name (if non-default), changeset hash, parent(s) and commit |
|
2389 | 2389 | comment. |
|
2390 | 2390 | |
|
2391 | 2391 | .. note:: |
|
2392 | 2392 | export may generate unexpected diff output for merge |
|
2393 | 2393 | changesets, as it will compare the merge changeset against its |
|
2394 | 2394 | first parent only. |
|
2395 | 2395 | |
|
2396 | 2396 | Output may be to a file, in which case the name of the file is |
|
2397 | 2397 | given using a format string. The formatting rules are as follows: |
|
2398 | 2398 | |
|
2399 | 2399 | :``%%``: literal "%" character |
|
2400 | 2400 | :``%H``: changeset hash (40 hexadecimal digits) |
|
2401 | 2401 | :``%N``: number of patches being generated |
|
2402 | 2402 | :``%R``: changeset revision number |
|
2403 | 2403 | :``%b``: basename of the exporting repository |
|
2404 | 2404 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
2405 | 2405 | :``%m``: first line of the commit message (only alphanumeric characters) |
|
2406 | 2406 | :``%n``: zero-padded sequence number, starting at 1 |
|
2407 | 2407 | :``%r``: zero-padded changeset revision number |
|
2408 | 2408 | |
|
2409 | 2409 | Without the -a/--text option, export will avoid generating diffs |
|
2410 | 2410 | of files it detects as binary. With -a, export will generate a |
|
2411 | 2411 | diff anyway, probably with undesirable results. |
|
2412 | 2412 | |
|
2413 | 2413 | Use the -g/--git option to generate diffs in the git extended diff |
|
2414 | 2414 | format. See :hg:`help diffs` for more information. |
|
2415 | 2415 | |
|
2416 | 2416 | With the --switch-parent option, the diff will be against the |
|
2417 | 2417 | second parent. It can be useful to review a merge. |
|
2418 | 2418 | |
|
2419 | 2419 | .. container:: verbose |
|
2420 | 2420 | |
|
2421 | 2421 | Examples: |
|
2422 | 2422 | |
|
2423 | 2423 | - use export and import to transplant a bugfix to the current |
|
2424 | 2424 | branch:: |
|
2425 | 2425 | |
|
2426 | 2426 | hg export -r 9353 | hg import - |
|
2427 | 2427 | |
|
2428 | 2428 | - export all the changesets between two revisions to a file with |
|
2429 | 2429 | rename information:: |
|
2430 | 2430 | |
|
2431 | 2431 | hg export --git -r 123:150 > changes.txt |
|
2432 | 2432 | |
|
2433 | 2433 | - split outgoing changes into a series of patches with |
|
2434 | 2434 | descriptive names:: |
|
2435 | 2435 | |
|
2436 | 2436 | hg export -r "outgoing()" -o "%n-%m.patch" |
|
2437 | 2437 | |
|
2438 | 2438 | Returns 0 on success. |
|
2439 | 2439 | """ |
|
2440 | 2440 | changesets += tuple(opts.get('rev', [])) |
|
2441 | if not changesets: | |
|
2441 | revs = scmutil.revrange(repo, changesets) | |
|
2442 | if not revs: | |
|
2442 | 2443 | raise util.Abort(_("export requires at least one changeset")) |
|
2443 | revs = scmutil.revrange(repo, changesets) | |
|
2444 | 2444 | if len(revs) > 1: |
|
2445 | 2445 | ui.note(_('exporting patches:\n')) |
|
2446 | 2446 | else: |
|
2447 | 2447 | ui.note(_('exporting patch:\n')) |
|
2448 | 2448 | cmdutil.export(repo, revs, template=opts.get('output'), |
|
2449 | 2449 | switch_parent=opts.get('switch_parent'), |
|
2450 | 2450 | opts=patch.diffopts(ui, opts)) |
|
2451 | 2451 | |
|
2452 | 2452 | @command('^forget', walkopts, _('[OPTION]... FILE...')) |
|
2453 | 2453 | def forget(ui, repo, *pats, **opts): |
|
2454 | 2454 | """forget the specified files on the next commit |
|
2455 | 2455 | |
|
2456 | 2456 | Mark the specified files so they will no longer be tracked |
|
2457 | 2457 | after the next commit. |
|
2458 | 2458 | |
|
2459 | 2459 | This only removes files from the current branch, not from the |
|
2460 | 2460 | entire project history, and it does not delete them from the |
|
2461 | 2461 | working directory. |
|
2462 | 2462 | |
|
2463 | 2463 | To undo a forget before the next commit, see :hg:`add`. |
|
2464 | 2464 | |
|
2465 | 2465 | .. container:: verbose |
|
2466 | 2466 | |
|
2467 | 2467 | Examples: |
|
2468 | 2468 | |
|
2469 | 2469 | - forget newly-added binary files:: |
|
2470 | 2470 | |
|
2471 | 2471 | hg forget "set:added() and binary()" |
|
2472 | 2472 | |
|
2473 | 2473 | - forget files that would be excluded by .hgignore:: |
|
2474 | 2474 | |
|
2475 | 2475 | hg forget "set:hgignore()" |
|
2476 | 2476 | |
|
2477 | 2477 | Returns 0 on success. |
|
2478 | 2478 | """ |
|
2479 | 2479 | |
|
2480 | 2480 | if not pats: |
|
2481 | 2481 | raise util.Abort(_('no files specified')) |
|
2482 | 2482 | |
|
2483 | 2483 | m = scmutil.match(repo[None], pats, opts) |
|
2484 | 2484 | rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] |
|
2485 | 2485 | return rejected and 1 or 0 |
|
2486 | 2486 | |
|
2487 | 2487 | @command( |
|
2488 | 2488 | 'graft', |
|
2489 | 2489 | [('c', 'continue', False, _('resume interrupted graft')), |
|
2490 | 2490 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
2491 | 2491 | ('D', 'currentdate', False, |
|
2492 | 2492 | _('record the current date as commit date')), |
|
2493 | 2493 | ('U', 'currentuser', False, |
|
2494 | 2494 | _('record the current user as committer'), _('DATE'))] |
|
2495 | 2495 | + commitopts2 + mergetoolopts, |
|
2496 | 2496 | _('[OPTION]... REVISION...')) |
|
2497 | 2497 | def graft(ui, repo, *revs, **opts): |
|
2498 | 2498 | '''copy changes from other branches onto the current branch |
|
2499 | 2499 | |
|
2500 | 2500 | This command uses Mercurial's merge logic to copy individual |
|
2501 | 2501 | changes from other branches without merging branches in the |
|
2502 | 2502 | history graph. This is sometimes known as 'backporting' or |
|
2503 | 2503 | 'cherry-picking'. By default, graft will copy user, date, and |
|
2504 | 2504 | description from the source changesets. |
|
2505 | 2505 | |
|
2506 | 2506 | Changesets that are ancestors of the current revision, that have |
|
2507 | 2507 | already been grafted, or that are merges will be skipped. |
|
2508 | 2508 | |
|
2509 | 2509 | If a graft merge results in conflicts, the graft process is |
|
2510 | 2510 | interrupted so that the current merge can be manually resolved. |
|
2511 | 2511 | Once all conflicts are addressed, the graft process can be |
|
2512 | 2512 | continued with the -c/--continue option. |
|
2513 | 2513 | |
|
2514 | 2514 | .. note:: |
|
2515 | 2515 | The -c/--continue option does not reapply earlier options. |
|
2516 | 2516 | |
|
2517 | 2517 | .. container:: verbose |
|
2518 | 2518 | |
|
2519 | 2519 | Examples: |
|
2520 | 2520 | |
|
2521 | 2521 | - copy a single change to the stable branch and edit its description:: |
|
2522 | 2522 | |
|
2523 | 2523 | hg update stable |
|
2524 | 2524 | hg graft --edit 9393 |
|
2525 | 2525 | |
|
2526 | 2526 | - graft a range of changesets with one exception, updating dates:: |
|
2527 | 2527 | |
|
2528 | 2528 | hg graft -D "2085::2093 and not 2091" |
|
2529 | 2529 | |
|
2530 | 2530 | - continue a graft after resolving conflicts:: |
|
2531 | 2531 | |
|
2532 | 2532 | hg graft -c |
|
2533 | 2533 | |
|
2534 | 2534 | - show the source of a grafted changeset:: |
|
2535 | 2535 | |
|
2536 | 2536 | hg log --debug -r tip |
|
2537 | 2537 | |
|
2538 | 2538 | Returns 0 on successful completion. |
|
2539 | 2539 | ''' |
|
2540 | 2540 | |
|
2541 | 2541 | if not opts.get('user') and opts.get('currentuser'): |
|
2542 | 2542 | opts['user'] = ui.username() |
|
2543 | 2543 | if not opts.get('date') and opts.get('currentdate'): |
|
2544 | 2544 | opts['date'] = "%d %d" % util.makedate() |
|
2545 | 2545 | |
|
2546 | 2546 | editor = None |
|
2547 | 2547 | if opts.get('edit'): |
|
2548 | 2548 | editor = cmdutil.commitforceeditor |
|
2549 | 2549 | |
|
2550 | 2550 | cont = False |
|
2551 | 2551 | if opts['continue']: |
|
2552 | 2552 | cont = True |
|
2553 | 2553 | if revs: |
|
2554 | 2554 | raise util.Abort(_("can't specify --continue and revisions")) |
|
2555 | 2555 | # read in unfinished revisions |
|
2556 | 2556 | try: |
|
2557 | 2557 | nodes = repo.opener.read('graftstate').splitlines() |
|
2558 | 2558 | revs = [repo[node].rev() for node in nodes] |
|
2559 | 2559 | except IOError, inst: |
|
2560 | 2560 | if inst.errno != errno.ENOENT: |
|
2561 | 2561 | raise |
|
2562 | 2562 | raise util.Abort(_("no graft state found, can't continue")) |
|
2563 | 2563 | else: |
|
2564 | 2564 | cmdutil.bailifchanged(repo) |
|
2565 | 2565 | if not revs: |
|
2566 | 2566 | raise util.Abort(_('no revisions specified')) |
|
2567 | 2567 | revs = scmutil.revrange(repo, revs) |
|
2568 | 2568 | |
|
2569 | 2569 | # check for merges |
|
2570 | 2570 | for rev in repo.revs('%ld and merge()', revs): |
|
2571 | 2571 | ui.warn(_('skipping ungraftable merge revision %s\n') % rev) |
|
2572 | 2572 | revs.remove(rev) |
|
2573 | 2573 | if not revs: |
|
2574 | 2574 | return -1 |
|
2575 | 2575 | |
|
2576 | 2576 | # check for ancestors of dest branch |
|
2577 | 2577 | for rev in repo.revs('::. and %ld', revs): |
|
2578 | 2578 | ui.warn(_('skipping ancestor revision %s\n') % rev) |
|
2579 | 2579 | revs.remove(rev) |
|
2580 | 2580 | if not revs: |
|
2581 | 2581 | return -1 |
|
2582 | 2582 | |
|
2583 | 2583 | # analyze revs for earlier grafts |
|
2584 | 2584 | ids = {} |
|
2585 | 2585 | for ctx in repo.set("%ld", revs): |
|
2586 | 2586 | ids[ctx.hex()] = ctx.rev() |
|
2587 | 2587 | n = ctx.extra().get('source') |
|
2588 | 2588 | if n: |
|
2589 | 2589 | ids[n] = ctx.rev() |
|
2590 | 2590 | |
|
2591 | 2591 | # check ancestors for earlier grafts |
|
2592 | 2592 | ui.debug('scanning for duplicate grafts\n') |
|
2593 | 2593 | for ctx in repo.set("::. - ::%ld", revs): |
|
2594 | 2594 | n = ctx.extra().get('source') |
|
2595 | 2595 | if n in ids: |
|
2596 | 2596 | r = repo[n].rev() |
|
2597 | 2597 | if r in revs: |
|
2598 | 2598 | ui.warn(_('skipping already grafted revision %s\n') % r) |
|
2599 | 2599 | revs.remove(r) |
|
2600 | 2600 | elif ids[n] in revs: |
|
2601 | 2601 | ui.warn(_('skipping already grafted revision %s ' |
|
2602 | 2602 | '(same origin %d)\n') % (ids[n], r)) |
|
2603 | 2603 | revs.remove(ids[n]) |
|
2604 | 2604 | elif ctx.hex() in ids: |
|
2605 | 2605 | r = ids[ctx.hex()] |
|
2606 | 2606 | ui.warn(_('skipping already grafted revision %s ' |
|
2607 | 2607 | '(was grafted from %d)\n') % (r, ctx.rev())) |
|
2608 | 2608 | revs.remove(r) |
|
2609 | 2609 | if not revs: |
|
2610 | 2610 | return -1 |
|
2611 | 2611 | |
|
2612 | 2612 | for pos, ctx in enumerate(repo.set("%ld", revs)): |
|
2613 | 2613 | current = repo['.'] |
|
2614 | 2614 | ui.status(_('grafting revision %s\n') % ctx.rev()) |
|
2615 | 2615 | |
|
2616 | 2616 | # we don't merge the first commit when continuing |
|
2617 | 2617 | if not cont: |
|
2618 | 2618 | # perform the graft merge with p1(rev) as 'ancestor' |
|
2619 | 2619 | try: |
|
2620 | 2620 | # ui.forcemerge is an internal variable, do not document |
|
2621 | 2621 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
2622 | 2622 | stats = mergemod.update(repo, ctx.node(), True, True, False, |
|
2623 | 2623 | ctx.p1().node()) |
|
2624 | 2624 | finally: |
|
2625 | 2625 | ui.setconfig('ui', 'forcemerge', '') |
|
2626 | 2626 | # drop the second merge parent |
|
2627 | 2627 | repo.dirstate.setparents(current.node(), nullid) |
|
2628 | 2628 | repo.dirstate.write() |
|
2629 | 2629 | # fix up dirstate for copies and renames |
|
2630 | 2630 | cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev()) |
|
2631 | 2631 | # report any conflicts |
|
2632 | 2632 | if stats and stats[3] > 0: |
|
2633 | 2633 | # write out state for --continue |
|
2634 | 2634 | nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] |
|
2635 | 2635 | repo.opener.write('graftstate', ''.join(nodelines)) |
|
2636 | 2636 | raise util.Abort( |
|
2637 | 2637 | _("unresolved conflicts, can't continue"), |
|
2638 | 2638 | hint=_('use hg resolve and hg graft --continue')) |
|
2639 | 2639 | else: |
|
2640 | 2640 | cont = False |
|
2641 | 2641 | |
|
2642 | 2642 | # commit |
|
2643 | 2643 | source = ctx.extra().get('source') |
|
2644 | 2644 | if not source: |
|
2645 | 2645 | source = ctx.hex() |
|
2646 | 2646 | extra = {'source': source} |
|
2647 | 2647 | user = ctx.user() |
|
2648 | 2648 | if opts.get('user'): |
|
2649 | 2649 | user = opts['user'] |
|
2650 | 2650 | date = ctx.date() |
|
2651 | 2651 | if opts.get('date'): |
|
2652 | 2652 | date = opts['date'] |
|
2653 | 2653 | repo.commit(text=ctx.description(), user=user, |
|
2654 | 2654 | date=date, extra=extra, editor=editor) |
|
2655 | 2655 | |
|
2656 | 2656 | # remove state when we complete successfully |
|
2657 | 2657 | if os.path.exists(repo.join('graftstate')): |
|
2658 | 2658 | util.unlinkpath(repo.join('graftstate')) |
|
2659 | 2659 | |
|
2660 | 2660 | return 0 |
|
2661 | 2661 | |
|
2662 | 2662 | @command('grep', |
|
2663 | 2663 | [('0', 'print0', None, _('end fields with NUL')), |
|
2664 | 2664 | ('', 'all', None, _('print all revisions that match')), |
|
2665 | 2665 | ('a', 'text', None, _('treat all files as text')), |
|
2666 | 2666 | ('f', 'follow', None, |
|
2667 | 2667 | _('follow changeset history,' |
|
2668 | 2668 | ' or file history across copies and renames')), |
|
2669 | 2669 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2670 | 2670 | ('l', 'files-with-matches', None, |
|
2671 | 2671 | _('print only filenames and revisions that match')), |
|
2672 | 2672 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2673 | 2673 | ('r', 'rev', [], |
|
2674 | 2674 | _('only search files changed within revision range'), _('REV')), |
|
2675 | 2675 | ('u', 'user', None, _('list the author (long with -v)')), |
|
2676 | 2676 | ('d', 'date', None, _('list the date (short with -q)')), |
|
2677 | 2677 | ] + walkopts, |
|
2678 | 2678 | _('[OPTION]... PATTERN [FILE]...')) |
|
2679 | 2679 | def grep(ui, repo, pattern, *pats, **opts): |
|
2680 | 2680 | """search for a pattern in specified files and revisions |
|
2681 | 2681 | |
|
2682 | 2682 | Search revisions of files for a regular expression. |
|
2683 | 2683 | |
|
2684 | 2684 | This command behaves differently than Unix grep. It only accepts |
|
2685 | 2685 | Python/Perl regexps. It searches repository history, not the |
|
2686 | 2686 | working directory. It always prints the revision number in which a |
|
2687 | 2687 | match appears. |
|
2688 | 2688 | |
|
2689 | 2689 | By default, grep only prints output for the first revision of a |
|
2690 | 2690 | file in which it finds a match. To get it to print every revision |
|
2691 | 2691 | that contains a change in match status ("-" for a match that |
|
2692 | 2692 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
2693 | 2693 | use the --all flag. |
|
2694 | 2694 | |
|
2695 | 2695 | Returns 0 if a match is found, 1 otherwise. |
|
2696 | 2696 | """ |
|
2697 | 2697 | reflags = re.M |
|
2698 | 2698 | if opts.get('ignore_case'): |
|
2699 | 2699 | reflags |= re.I |
|
2700 | 2700 | try: |
|
2701 | 2701 | regexp = re.compile(pattern, reflags) |
|
2702 | 2702 | except re.error, inst: |
|
2703 | 2703 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
2704 | 2704 | return 1 |
|
2705 | 2705 | sep, eol = ':', '\n' |
|
2706 | 2706 | if opts.get('print0'): |
|
2707 | 2707 | sep = eol = '\0' |
|
2708 | 2708 | |
|
2709 | 2709 | getfile = util.lrucachefunc(repo.file) |
|
2710 | 2710 | |
|
2711 | 2711 | def matchlines(body): |
|
2712 | 2712 | begin = 0 |
|
2713 | 2713 | linenum = 0 |
|
2714 | 2714 | while True: |
|
2715 | 2715 | match = regexp.search(body, begin) |
|
2716 | 2716 | if not match: |
|
2717 | 2717 | break |
|
2718 | 2718 | mstart, mend = match.span() |
|
2719 | 2719 | linenum += body.count('\n', begin, mstart) + 1 |
|
2720 | 2720 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
2721 | 2721 | begin = body.find('\n', mend) + 1 or len(body) + 1 |
|
2722 | 2722 | lend = begin - 1 |
|
2723 | 2723 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
2724 | 2724 | |
|
2725 | 2725 | class linestate(object): |
|
2726 | 2726 | def __init__(self, line, linenum, colstart, colend): |
|
2727 | 2727 | self.line = line |
|
2728 | 2728 | self.linenum = linenum |
|
2729 | 2729 | self.colstart = colstart |
|
2730 | 2730 | self.colend = colend |
|
2731 | 2731 | |
|
2732 | 2732 | def __hash__(self): |
|
2733 | 2733 | return hash((self.linenum, self.line)) |
|
2734 | 2734 | |
|
2735 | 2735 | def __eq__(self, other): |
|
2736 | 2736 | return self.line == other.line |
|
2737 | 2737 | |
|
2738 | 2738 | matches = {} |
|
2739 | 2739 | copies = {} |
|
2740 | 2740 | def grepbody(fn, rev, body): |
|
2741 | 2741 | matches[rev].setdefault(fn, []) |
|
2742 | 2742 | m = matches[rev][fn] |
|
2743 | 2743 | for lnum, cstart, cend, line in matchlines(body): |
|
2744 | 2744 | s = linestate(line, lnum, cstart, cend) |
|
2745 | 2745 | m.append(s) |
|
2746 | 2746 | |
|
2747 | 2747 | def difflinestates(a, b): |
|
2748 | 2748 | sm = difflib.SequenceMatcher(None, a, b) |
|
2749 | 2749 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
2750 | 2750 | if tag == 'insert': |
|
2751 | 2751 | for i in xrange(blo, bhi): |
|
2752 | 2752 | yield ('+', b[i]) |
|
2753 | 2753 | elif tag == 'delete': |
|
2754 | 2754 | for i in xrange(alo, ahi): |
|
2755 | 2755 | yield ('-', a[i]) |
|
2756 | 2756 | elif tag == 'replace': |
|
2757 | 2757 | for i in xrange(alo, ahi): |
|
2758 | 2758 | yield ('-', a[i]) |
|
2759 | 2759 | for i in xrange(blo, bhi): |
|
2760 | 2760 | yield ('+', b[i]) |
|
2761 | 2761 | |
|
2762 | 2762 | def display(fn, ctx, pstates, states): |
|
2763 | 2763 | rev = ctx.rev() |
|
2764 | 2764 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
2765 | 2765 | found = False |
|
2766 | 2766 | filerevmatches = {} |
|
2767 | 2767 | def binary(): |
|
2768 | 2768 | flog = getfile(fn) |
|
2769 | 2769 | return util.binary(flog.read(ctx.filenode(fn))) |
|
2770 | 2770 | |
|
2771 | 2771 | if opts.get('all'): |
|
2772 | 2772 | iter = difflinestates(pstates, states) |
|
2773 | 2773 | else: |
|
2774 | 2774 | iter = [('', l) for l in states] |
|
2775 | 2775 | for change, l in iter: |
|
2776 | 2776 | cols = [fn, str(rev)] |
|
2777 | 2777 | before, match, after = None, None, None |
|
2778 | 2778 | if opts.get('line_number'): |
|
2779 | 2779 | cols.append(str(l.linenum)) |
|
2780 | 2780 | if opts.get('all'): |
|
2781 | 2781 | cols.append(change) |
|
2782 | 2782 | if opts.get('user'): |
|
2783 | 2783 | cols.append(ui.shortuser(ctx.user())) |
|
2784 | 2784 | if opts.get('date'): |
|
2785 | 2785 | cols.append(datefunc(ctx.date())) |
|
2786 | 2786 | if opts.get('files_with_matches'): |
|
2787 | 2787 | c = (fn, rev) |
|
2788 | 2788 | if c in filerevmatches: |
|
2789 | 2789 | continue |
|
2790 | 2790 | filerevmatches[c] = 1 |
|
2791 | 2791 | else: |
|
2792 | 2792 | before = l.line[:l.colstart] |
|
2793 | 2793 | match = l.line[l.colstart:l.colend] |
|
2794 | 2794 | after = l.line[l.colend:] |
|
2795 | 2795 | ui.write(sep.join(cols)) |
|
2796 | 2796 | if before is not None: |
|
2797 | 2797 | if not opts.get('text') and binary(): |
|
2798 | 2798 | ui.write(sep + " Binary file matches") |
|
2799 | 2799 | else: |
|
2800 | 2800 | ui.write(sep + before) |
|
2801 | 2801 | ui.write(match, label='grep.match') |
|
2802 | 2802 | ui.write(after) |
|
2803 | 2803 | ui.write(eol) |
|
2804 | 2804 | found = True |
|
2805 | 2805 | return found |
|
2806 | 2806 | |
|
2807 | 2807 | skip = {} |
|
2808 | 2808 | revfiles = {} |
|
2809 | 2809 | matchfn = scmutil.match(repo[None], pats, opts) |
|
2810 | 2810 | found = False |
|
2811 | 2811 | follow = opts.get('follow') |
|
2812 | 2812 | |
|
2813 | 2813 | def prep(ctx, fns): |
|
2814 | 2814 | rev = ctx.rev() |
|
2815 | 2815 | pctx = ctx.p1() |
|
2816 | 2816 | parent = pctx.rev() |
|
2817 | 2817 | matches.setdefault(rev, {}) |
|
2818 | 2818 | matches.setdefault(parent, {}) |
|
2819 | 2819 | files = revfiles.setdefault(rev, []) |
|
2820 | 2820 | for fn in fns: |
|
2821 | 2821 | flog = getfile(fn) |
|
2822 | 2822 | try: |
|
2823 | 2823 | fnode = ctx.filenode(fn) |
|
2824 | 2824 | except error.LookupError: |
|
2825 | 2825 | continue |
|
2826 | 2826 | |
|
2827 | 2827 | copied = flog.renamed(fnode) |
|
2828 | 2828 | copy = follow and copied and copied[0] |
|
2829 | 2829 | if copy: |
|
2830 | 2830 | copies.setdefault(rev, {})[fn] = copy |
|
2831 | 2831 | if fn in skip: |
|
2832 | 2832 | if copy: |
|
2833 | 2833 | skip[copy] = True |
|
2834 | 2834 | continue |
|
2835 | 2835 | files.append(fn) |
|
2836 | 2836 | |
|
2837 | 2837 | if fn not in matches[rev]: |
|
2838 | 2838 | grepbody(fn, rev, flog.read(fnode)) |
|
2839 | 2839 | |
|
2840 | 2840 | pfn = copy or fn |
|
2841 | 2841 | if pfn not in matches[parent]: |
|
2842 | 2842 | try: |
|
2843 | 2843 | fnode = pctx.filenode(pfn) |
|
2844 | 2844 | grepbody(pfn, parent, flog.read(fnode)) |
|
2845 | 2845 | except error.LookupError: |
|
2846 | 2846 | pass |
|
2847 | 2847 | |
|
2848 | 2848 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
2849 | 2849 | rev = ctx.rev() |
|
2850 | 2850 | parent = ctx.p1().rev() |
|
2851 | 2851 | for fn in sorted(revfiles.get(rev, [])): |
|
2852 | 2852 | states = matches[rev][fn] |
|
2853 | 2853 | copy = copies.get(rev, {}).get(fn) |
|
2854 | 2854 | if fn in skip: |
|
2855 | 2855 | if copy: |
|
2856 | 2856 | skip[copy] = True |
|
2857 | 2857 | continue |
|
2858 | 2858 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
2859 | 2859 | if pstates or states: |
|
2860 | 2860 | r = display(fn, ctx, pstates, states) |
|
2861 | 2861 | found = found or r |
|
2862 | 2862 | if r and not opts.get('all'): |
|
2863 | 2863 | skip[fn] = True |
|
2864 | 2864 | if copy: |
|
2865 | 2865 | skip[copy] = True |
|
2866 | 2866 | del matches[rev] |
|
2867 | 2867 | del revfiles[rev] |
|
2868 | 2868 | |
|
2869 | 2869 | return not found |
|
2870 | 2870 | |
|
2871 | 2871 | @command('heads', |
|
2872 | 2872 | [('r', 'rev', '', |
|
2873 | 2873 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), |
|
2874 | 2874 | ('t', 'topo', False, _('show topological heads only')), |
|
2875 | 2875 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), |
|
2876 | 2876 | ('c', 'closed', False, _('show normal and closed branch heads')), |
|
2877 | 2877 | ] + templateopts, |
|
2878 | 2878 | _('[-ac] [-r STARTREV] [REV]...')) |
|
2879 | 2879 | def heads(ui, repo, *branchrevs, **opts): |
|
2880 | 2880 | """show current repository heads or show branch heads |
|
2881 | 2881 | |
|
2882 | 2882 | With no arguments, show all repository branch heads. |
|
2883 | 2883 | |
|
2884 | 2884 | Repository "heads" are changesets with no child changesets. They are |
|
2885 | 2885 | where development generally takes place and are the usual targets |
|
2886 | 2886 | for update and merge operations. Branch heads are changesets that have |
|
2887 | 2887 | no child changeset on the same branch. |
|
2888 | 2888 | |
|
2889 | 2889 | If one or more REVs are given, only branch heads on the branches |
|
2890 | 2890 | associated with the specified changesets are shown. This means |
|
2891 | 2891 | that you can use :hg:`heads foo` to see the heads on a branch |
|
2892 | 2892 | named ``foo``. |
|
2893 | 2893 | |
|
2894 | 2894 | If -c/--closed is specified, also show branch heads marked closed |
|
2895 | 2895 | (see :hg:`commit --close-branch`). |
|
2896 | 2896 | |
|
2897 | 2897 | If STARTREV is specified, only those heads that are descendants of |
|
2898 | 2898 | STARTREV will be displayed. |
|
2899 | 2899 | |
|
2900 | 2900 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
2901 | 2901 | changesets without children will be shown. |
|
2902 | 2902 | |
|
2903 | 2903 | Returns 0 if matching heads are found, 1 if not. |
|
2904 | 2904 | """ |
|
2905 | 2905 | |
|
2906 | 2906 | start = None |
|
2907 | 2907 | if 'rev' in opts: |
|
2908 | 2908 | start = scmutil.revsingle(repo, opts['rev'], None).node() |
|
2909 | 2909 | |
|
2910 | 2910 | if opts.get('topo'): |
|
2911 | 2911 | heads = [repo[h] for h in repo.heads(start)] |
|
2912 | 2912 | else: |
|
2913 | 2913 | heads = [] |
|
2914 | 2914 | for branch in repo.branchmap(): |
|
2915 | 2915 | heads += repo.branchheads(branch, start, opts.get('closed')) |
|
2916 | 2916 | heads = [repo[h] for h in heads] |
|
2917 | 2917 | |
|
2918 | 2918 | if branchrevs: |
|
2919 | 2919 | branches = set(repo[br].branch() for br in branchrevs) |
|
2920 | 2920 | heads = [h for h in heads if h.branch() in branches] |
|
2921 | 2921 | |
|
2922 | 2922 | if opts.get('active') and branchrevs: |
|
2923 | 2923 | dagheads = repo.heads(start) |
|
2924 | 2924 | heads = [h for h in heads if h.node() in dagheads] |
|
2925 | 2925 | |
|
2926 | 2926 | if branchrevs: |
|
2927 | 2927 | haveheads = set(h.branch() for h in heads) |
|
2928 | 2928 | if branches - haveheads: |
|
2929 | 2929 | headless = ', '.join(b for b in branches - haveheads) |
|
2930 | 2930 | msg = _('no open branch heads found on branches %s') |
|
2931 | 2931 | if opts.get('rev'): |
|
2932 | 2932 | msg += _(' (started at %s)') % opts['rev'] |
|
2933 | 2933 | ui.warn((msg + '\n') % headless) |
|
2934 | 2934 | |
|
2935 | 2935 | if not heads: |
|
2936 | 2936 | return 1 |
|
2937 | 2937 | |
|
2938 | 2938 | heads = sorted(heads, key=lambda x: -x.rev()) |
|
2939 | 2939 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2940 | 2940 | for ctx in heads: |
|
2941 | 2941 | displayer.show(ctx) |
|
2942 | 2942 | displayer.close() |
|
2943 | 2943 | |
|
2944 | 2944 | @command('help', |
|
2945 | 2945 | [('e', 'extension', None, _('show only help for extensions')), |
|
2946 | 2946 | ('c', 'command', None, _('show only help for commands'))], |
|
2947 | 2947 | _('[-ec] [TOPIC]')) |
|
2948 | 2948 | def help_(ui, name=None, unknowncmd=False, full=True, **opts): |
|
2949 | 2949 | """show help for a given topic or a help overview |
|
2950 | 2950 | |
|
2951 | 2951 | With no arguments, print a list of commands with short help messages. |
|
2952 | 2952 | |
|
2953 | 2953 | Given a topic, extension, or command name, print help for that |
|
2954 | 2954 | topic. |
|
2955 | 2955 | |
|
2956 | 2956 | Returns 0 if successful. |
|
2957 | 2957 | """ |
|
2958 | 2958 | |
|
2959 | 2959 | textwidth = min(ui.termwidth(), 80) - 2 |
|
2960 | 2960 | |
|
2961 | 2961 | def optrst(options): |
|
2962 | 2962 | data = [] |
|
2963 | 2963 | multioccur = False |
|
2964 | 2964 | for option in options: |
|
2965 | 2965 | if len(option) == 5: |
|
2966 | 2966 | shortopt, longopt, default, desc, optlabel = option |
|
2967 | 2967 | else: |
|
2968 | 2968 | shortopt, longopt, default, desc = option |
|
2969 | 2969 | optlabel = _("VALUE") # default label |
|
2970 | 2970 | |
|
2971 | 2971 | if _("DEPRECATED") in desc and not ui.verbose: |
|
2972 | 2972 | continue |
|
2973 | 2973 | |
|
2974 | 2974 | so = '' |
|
2975 | 2975 | if shortopt: |
|
2976 | 2976 | so = '-' + shortopt |
|
2977 | 2977 | lo = '--' + longopt |
|
2978 | 2978 | if default: |
|
2979 | 2979 | desc += _(" (default: %s)") % default |
|
2980 | 2980 | |
|
2981 | 2981 | if isinstance(default, list): |
|
2982 | 2982 | lo += " %s [+]" % optlabel |
|
2983 | 2983 | multioccur = True |
|
2984 | 2984 | elif (default is not None) and not isinstance(default, bool): |
|
2985 | 2985 | lo += " %s" % optlabel |
|
2986 | 2986 | |
|
2987 | 2987 | data.append((so, lo, desc)) |
|
2988 | 2988 | |
|
2989 | 2989 | rst = minirst.maketable(data, 1) |
|
2990 | 2990 | |
|
2991 | 2991 | if multioccur: |
|
2992 | 2992 | rst += _("\n[+] marked option can be specified multiple times\n") |
|
2993 | 2993 | |
|
2994 | 2994 | return rst |
|
2995 | 2995 | |
|
2996 | 2996 | # list all option lists |
|
2997 | 2997 | def opttext(optlist, width): |
|
2998 | 2998 | rst = '' |
|
2999 | 2999 | if not optlist: |
|
3000 | 3000 | return '' |
|
3001 | 3001 | |
|
3002 | 3002 | for title, options in optlist: |
|
3003 | 3003 | rst += '\n%s\n' % title |
|
3004 | 3004 | if options: |
|
3005 | 3005 | rst += "\n" |
|
3006 | 3006 | rst += optrst(options) |
|
3007 | 3007 | rst += '\n' |
|
3008 | 3008 | |
|
3009 | 3009 | return '\n' + minirst.format(rst, width) |
|
3010 | 3010 | |
|
3011 | 3011 | def addglobalopts(optlist, aliases): |
|
3012 | 3012 | if ui.quiet: |
|
3013 | 3013 | return [] |
|
3014 | 3014 | |
|
3015 | 3015 | if ui.verbose: |
|
3016 | 3016 | optlist.append((_("global options:"), globalopts)) |
|
3017 | 3017 | if name == 'shortlist': |
|
3018 | 3018 | optlist.append((_('use "hg help" for the full list ' |
|
3019 | 3019 | 'of commands'), ())) |
|
3020 | 3020 | else: |
|
3021 | 3021 | if name == 'shortlist': |
|
3022 | 3022 | msg = _('use "hg help" for the full list of commands ' |
|
3023 | 3023 | 'or "hg -v" for details') |
|
3024 | 3024 | elif name and not full: |
|
3025 | 3025 | msg = _('use "hg help %s" to show the full help text') % name |
|
3026 | 3026 | elif aliases: |
|
3027 | 3027 | msg = _('use "hg -v help%s" to show builtin aliases and ' |
|
3028 | 3028 | 'global options') % (name and " " + name or "") |
|
3029 | 3029 | else: |
|
3030 | 3030 | msg = _('use "hg -v help %s" to show more info') % name |
|
3031 | 3031 | optlist.append((msg, ())) |
|
3032 | 3032 | |
|
3033 | 3033 | def helpcmd(name): |
|
3034 | 3034 | try: |
|
3035 | 3035 | aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd) |
|
3036 | 3036 | except error.AmbiguousCommand, inst: |
|
3037 | 3037 | # py3k fix: except vars can't be used outside the scope of the |
|
3038 | 3038 | # except block, nor can be used inside a lambda. python issue4617 |
|
3039 | 3039 | prefix = inst.args[0] |
|
3040 | 3040 | select = lambda c: c.lstrip('^').startswith(prefix) |
|
3041 | 3041 | helplist(select) |
|
3042 | 3042 | return |
|
3043 | 3043 | |
|
3044 | 3044 | # check if it's an invalid alias and display its error if it is |
|
3045 | 3045 | if getattr(entry[0], 'badalias', False): |
|
3046 | 3046 | if not unknowncmd: |
|
3047 | 3047 | entry[0](ui) |
|
3048 | 3048 | return |
|
3049 | 3049 | |
|
3050 | 3050 | rst = "" |
|
3051 | 3051 | |
|
3052 | 3052 | # synopsis |
|
3053 | 3053 | if len(entry) > 2: |
|
3054 | 3054 | if entry[2].startswith('hg'): |
|
3055 | 3055 | rst += "%s\n" % entry[2] |
|
3056 | 3056 | else: |
|
3057 | 3057 | rst += 'hg %s %s\n' % (aliases[0], entry[2]) |
|
3058 | 3058 | else: |
|
3059 | 3059 | rst += 'hg %s\n' % aliases[0] |
|
3060 | 3060 | |
|
3061 | 3061 | # aliases |
|
3062 | 3062 | if full and not ui.quiet and len(aliases) > 1: |
|
3063 | 3063 | rst += _("\naliases: %s\n") % ', '.join(aliases[1:]) |
|
3064 | 3064 | |
|
3065 | 3065 | # description |
|
3066 | 3066 | doc = gettext(entry[0].__doc__) |
|
3067 | 3067 | if not doc: |
|
3068 | 3068 | doc = _("(no help text available)") |
|
3069 | 3069 | if util.safehasattr(entry[0], 'definition'): # aliased command |
|
3070 | 3070 | if entry[0].definition.startswith('!'): # shell alias |
|
3071 | 3071 | doc = _('shell alias for::\n\n %s') % entry[0].definition[1:] |
|
3072 | 3072 | else: |
|
3073 | 3073 | doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc) |
|
3074 | 3074 | if ui.quiet or not full: |
|
3075 | 3075 | doc = doc.splitlines()[0] |
|
3076 | 3076 | rst += "\n" + doc + "\n" |
|
3077 | 3077 | |
|
3078 | 3078 | # check if this command shadows a non-trivial (multi-line) |
|
3079 | 3079 | # extension help text |
|
3080 | 3080 | try: |
|
3081 | 3081 | mod = extensions.find(name) |
|
3082 | 3082 | doc = gettext(mod.__doc__) or '' |
|
3083 | 3083 | if '\n' in doc.strip(): |
|
3084 | 3084 | msg = _('use "hg help -e %s" to show help for ' |
|
3085 | 3085 | 'the %s extension') % (name, name) |
|
3086 | 3086 | rst += '\n%s\n' % msg |
|
3087 | 3087 | except KeyError: |
|
3088 | 3088 | pass |
|
3089 | 3089 | |
|
3090 | 3090 | # options |
|
3091 | 3091 | if not ui.quiet and entry[1]: |
|
3092 | 3092 | rst += '\n' |
|
3093 | 3093 | rst += _("options:") |
|
3094 | 3094 | rst += '\n\n' |
|
3095 | 3095 | rst += optrst(entry[1]) |
|
3096 | 3096 | |
|
3097 | 3097 | if ui.verbose: |
|
3098 | 3098 | rst += '\n' |
|
3099 | 3099 | rst += _("global options:") |
|
3100 | 3100 | rst += '\n\n' |
|
3101 | 3101 | rst += optrst(globalopts) |
|
3102 | 3102 | |
|
3103 | 3103 | keep = ui.verbose and ['verbose'] or [] |
|
3104 | 3104 | formatted, pruned = minirst.format(rst, textwidth, keep=keep) |
|
3105 | 3105 | ui.write(formatted) |
|
3106 | 3106 | |
|
3107 | 3107 | if not ui.verbose: |
|
3108 | 3108 | if not full: |
|
3109 | 3109 | ui.write(_('\nuse "hg help %s" to show the full help text\n') |
|
3110 | 3110 | % name) |
|
3111 | 3111 | elif not ui.quiet: |
|
3112 | 3112 | ui.write(_('\nuse "hg -v help %s" to show more info\n') % name) |
|
3113 | 3113 | |
|
3114 | 3114 | |
|
3115 | 3115 | def helplist(select=None): |
|
3116 | 3116 | # list of commands |
|
3117 | 3117 | if name == "shortlist": |
|
3118 | 3118 | header = _('basic commands:\n\n') |
|
3119 | 3119 | else: |
|
3120 | 3120 | header = _('list of commands:\n\n') |
|
3121 | 3121 | |
|
3122 | 3122 | h = {} |
|
3123 | 3123 | cmds = {} |
|
3124 | 3124 | for c, e in table.iteritems(): |
|
3125 | 3125 | f = c.split("|", 1)[0] |
|
3126 | 3126 | if select and not select(f): |
|
3127 | 3127 | continue |
|
3128 | 3128 | if (not select and name != 'shortlist' and |
|
3129 | 3129 | e[0].__module__ != __name__): |
|
3130 | 3130 | continue |
|
3131 | 3131 | if name == "shortlist" and not f.startswith("^"): |
|
3132 | 3132 | continue |
|
3133 | 3133 | f = f.lstrip("^") |
|
3134 | 3134 | if not ui.debugflag and f.startswith("debug"): |
|
3135 | 3135 | continue |
|
3136 | 3136 | doc = e[0].__doc__ |
|
3137 | 3137 | if doc and 'DEPRECATED' in doc and not ui.verbose: |
|
3138 | 3138 | continue |
|
3139 | 3139 | doc = gettext(doc) |
|
3140 | 3140 | if not doc: |
|
3141 | 3141 | doc = _("(no help text available)") |
|
3142 | 3142 | h[f] = doc.splitlines()[0].rstrip() |
|
3143 | 3143 | cmds[f] = c.lstrip("^") |
|
3144 | 3144 | |
|
3145 | 3145 | if not h: |
|
3146 | 3146 | ui.status(_('no commands defined\n')) |
|
3147 | 3147 | return |
|
3148 | 3148 | |
|
3149 | 3149 | ui.status(header) |
|
3150 | 3150 | fns = sorted(h) |
|
3151 | 3151 | m = max(map(len, fns)) |
|
3152 | 3152 | for f in fns: |
|
3153 | 3153 | if ui.verbose: |
|
3154 | 3154 | commands = cmds[f].replace("|",", ") |
|
3155 | 3155 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
3156 | 3156 | else: |
|
3157 | 3157 | ui.write('%s\n' % (util.wrap(h[f], textwidth, |
|
3158 | 3158 | initindent=' %-*s ' % (m, f), |
|
3159 | 3159 | hangindent=' ' * (m + 4)))) |
|
3160 | 3160 | |
|
3161 | 3161 | if not name: |
|
3162 | 3162 | text = help.listexts(_('enabled extensions:'), extensions.enabled()) |
|
3163 | 3163 | if text: |
|
3164 | 3164 | ui.write("\n%s" % minirst.format(text, textwidth)) |
|
3165 | 3165 | |
|
3166 | 3166 | ui.write(_("\nadditional help topics:\n\n")) |
|
3167 | 3167 | topics = [] |
|
3168 | 3168 | for names, header, doc in help.helptable: |
|
3169 | 3169 | topics.append((sorted(names, key=len, reverse=True)[0], header)) |
|
3170 | 3170 | topics_len = max([len(s[0]) for s in topics]) |
|
3171 | 3171 | for t, desc in topics: |
|
3172 | 3172 | ui.write(" %-*s %s\n" % (topics_len, t, desc)) |
|
3173 | 3173 | |
|
3174 | 3174 | optlist = [] |
|
3175 | 3175 | addglobalopts(optlist, True) |
|
3176 | 3176 | ui.write(opttext(optlist, textwidth)) |
|
3177 | 3177 | |
|
3178 | 3178 | def helptopic(name): |
|
3179 | 3179 | for names, header, doc in help.helptable: |
|
3180 | 3180 | if name in names: |
|
3181 | 3181 | break |
|
3182 | 3182 | else: |
|
3183 | 3183 | raise error.UnknownCommand(name) |
|
3184 | 3184 | |
|
3185 | 3185 | # description |
|
3186 | 3186 | if not doc: |
|
3187 | 3187 | doc = _("(no help text available)") |
|
3188 | 3188 | if util.safehasattr(doc, '__call__'): |
|
3189 | 3189 | doc = doc() |
|
3190 | 3190 | |
|
3191 | 3191 | ui.write("%s\n\n" % header) |
|
3192 | 3192 | ui.write("%s" % minirst.format(doc, textwidth, indent=4)) |
|
3193 | 3193 | try: |
|
3194 | 3194 | cmdutil.findcmd(name, table) |
|
3195 | 3195 | ui.write(_('\nuse "hg help -c %s" to see help for ' |
|
3196 | 3196 | 'the %s command\n') % (name, name)) |
|
3197 | 3197 | except error.UnknownCommand: |
|
3198 | 3198 | pass |
|
3199 | 3199 | |
|
3200 | 3200 | def helpext(name): |
|
3201 | 3201 | try: |
|
3202 | 3202 | mod = extensions.find(name) |
|
3203 | 3203 | doc = gettext(mod.__doc__) or _('no help text available') |
|
3204 | 3204 | except KeyError: |
|
3205 | 3205 | mod = None |
|
3206 | 3206 | doc = extensions.disabledext(name) |
|
3207 | 3207 | if not doc: |
|
3208 | 3208 | raise error.UnknownCommand(name) |
|
3209 | 3209 | |
|
3210 | 3210 | if '\n' not in doc: |
|
3211 | 3211 | head, tail = doc, "" |
|
3212 | 3212 | else: |
|
3213 | 3213 | head, tail = doc.split('\n', 1) |
|
3214 | 3214 | ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head)) |
|
3215 | 3215 | if tail: |
|
3216 | 3216 | ui.write(minirst.format(tail, textwidth)) |
|
3217 | 3217 | ui.status('\n') |
|
3218 | 3218 | |
|
3219 | 3219 | if mod: |
|
3220 | 3220 | try: |
|
3221 | 3221 | ct = mod.cmdtable |
|
3222 | 3222 | except AttributeError: |
|
3223 | 3223 | ct = {} |
|
3224 | 3224 | modcmds = set([c.split('|', 1)[0] for c in ct]) |
|
3225 | 3225 | helplist(modcmds.__contains__) |
|
3226 | 3226 | else: |
|
3227 | 3227 | ui.write(_('use "hg help extensions" for information on enabling ' |
|
3228 | 3228 | 'extensions\n')) |
|
3229 | 3229 | |
|
3230 | 3230 | def helpextcmd(name): |
|
3231 | 3231 | cmd, ext, mod = extensions.disabledcmd(ui, name, ui.config('ui', 'strict')) |
|
3232 | 3232 | doc = gettext(mod.__doc__).splitlines()[0] |
|
3233 | 3233 | |
|
3234 | 3234 | msg = help.listexts(_("'%s' is provided by the following " |
|
3235 | 3235 | "extension:") % cmd, {ext: doc}, indent=4) |
|
3236 | 3236 | ui.write(minirst.format(msg, textwidth)) |
|
3237 | 3237 | ui.write('\n') |
|
3238 | 3238 | ui.write(_('use "hg help extensions" for information on enabling ' |
|
3239 | 3239 | 'extensions\n')) |
|
3240 | 3240 | |
|
3241 | 3241 | if name and name != 'shortlist': |
|
3242 | 3242 | i = None |
|
3243 | 3243 | if unknowncmd: |
|
3244 | 3244 | queries = (helpextcmd,) |
|
3245 | 3245 | elif opts.get('extension'): |
|
3246 | 3246 | queries = (helpext,) |
|
3247 | 3247 | elif opts.get('command'): |
|
3248 | 3248 | queries = (helpcmd,) |
|
3249 | 3249 | else: |
|
3250 | 3250 | queries = (helptopic, helpcmd, helpext, helpextcmd) |
|
3251 | 3251 | for f in queries: |
|
3252 | 3252 | try: |
|
3253 | 3253 | f(name) |
|
3254 | 3254 | i = None |
|
3255 | 3255 | break |
|
3256 | 3256 | except error.UnknownCommand, inst: |
|
3257 | 3257 | i = inst |
|
3258 | 3258 | if i: |
|
3259 | 3259 | raise i |
|
3260 | 3260 | else: |
|
3261 | 3261 | # program name |
|
3262 | 3262 | ui.status(_("Mercurial Distributed SCM\n")) |
|
3263 | 3263 | ui.status('\n') |
|
3264 | 3264 | helplist() |
|
3265 | 3265 | |
|
3266 | 3266 | |
|
3267 | 3267 | @command('identify|id', |
|
3268 | 3268 | [('r', 'rev', '', |
|
3269 | 3269 | _('identify the specified revision'), _('REV')), |
|
3270 | 3270 | ('n', 'num', None, _('show local revision number')), |
|
3271 | 3271 | ('i', 'id', None, _('show global revision id')), |
|
3272 | 3272 | ('b', 'branch', None, _('show branch')), |
|
3273 | 3273 | ('t', 'tags', None, _('show tags')), |
|
3274 | 3274 | ('B', 'bookmarks', None, _('show bookmarks')), |
|
3275 | 3275 | ] + remoteopts, |
|
3276 | 3276 | _('[-nibtB] [-r REV] [SOURCE]')) |
|
3277 | 3277 | def identify(ui, repo, source=None, rev=None, |
|
3278 | 3278 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): |
|
3279 | 3279 | """identify the working copy or specified revision |
|
3280 | 3280 | |
|
3281 | 3281 | Print a summary identifying the repository state at REV using one or |
|
3282 | 3282 | two parent hash identifiers, followed by a "+" if the working |
|
3283 | 3283 | directory has uncommitted changes, the branch name (if not default), |
|
3284 | 3284 | a list of tags, and a list of bookmarks. |
|
3285 | 3285 | |
|
3286 | 3286 | When REV is not given, print a summary of the current state of the |
|
3287 | 3287 | repository. |
|
3288 | 3288 | |
|
3289 | 3289 | Specifying a path to a repository root or Mercurial bundle will |
|
3290 | 3290 | cause lookup to operate on that repository/bundle. |
|
3291 | 3291 | |
|
3292 | 3292 | .. container:: verbose |
|
3293 | 3293 | |
|
3294 | 3294 | Examples: |
|
3295 | 3295 | |
|
3296 | 3296 | - generate a build identifier for the working directory:: |
|
3297 | 3297 | |
|
3298 | 3298 | hg id --id > build-id.dat |
|
3299 | 3299 | |
|
3300 | 3300 | - find the revision corresponding to a tag:: |
|
3301 | 3301 | |
|
3302 | 3302 | hg id -n -r 1.3 |
|
3303 | 3303 | |
|
3304 | 3304 | - check the most recent revision of a remote repository:: |
|
3305 | 3305 | |
|
3306 | 3306 | hg id -r tip http://selenic.com/hg/ |
|
3307 | 3307 | |
|
3308 | 3308 | Returns 0 if successful. |
|
3309 | 3309 | """ |
|
3310 | 3310 | |
|
3311 | 3311 | if not repo and not source: |
|
3312 | 3312 | raise util.Abort(_("there is no Mercurial repository here " |
|
3313 | 3313 | "(.hg not found)")) |
|
3314 | 3314 | |
|
3315 | 3315 | hexfunc = ui.debugflag and hex or short |
|
3316 | 3316 | default = not (num or id or branch or tags or bookmarks) |
|
3317 | 3317 | output = [] |
|
3318 | 3318 | revs = [] |
|
3319 | 3319 | |
|
3320 | 3320 | if source: |
|
3321 | 3321 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
3322 | 3322 | repo = hg.peer(ui, opts, source) |
|
3323 | 3323 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
3324 | 3324 | |
|
3325 | 3325 | if not repo.local(): |
|
3326 | 3326 | if num or branch or tags: |
|
3327 | 3327 | raise util.Abort( |
|
3328 | 3328 | _("can't query remote revision number, branch, or tags")) |
|
3329 | 3329 | if not rev and revs: |
|
3330 | 3330 | rev = revs[0] |
|
3331 | 3331 | if not rev: |
|
3332 | 3332 | rev = "tip" |
|
3333 | 3333 | |
|
3334 | 3334 | remoterev = repo.lookup(rev) |
|
3335 | 3335 | if default or id: |
|
3336 | 3336 | output = [hexfunc(remoterev)] |
|
3337 | 3337 | |
|
3338 | 3338 | def getbms(): |
|
3339 | 3339 | bms = [] |
|
3340 | 3340 | |
|
3341 | 3341 | if 'bookmarks' in repo.listkeys('namespaces'): |
|
3342 | 3342 | hexremoterev = hex(remoterev) |
|
3343 | 3343 | bms = [bm for bm, bmr in repo.listkeys('bookmarks').iteritems() |
|
3344 | 3344 | if bmr == hexremoterev] |
|
3345 | 3345 | |
|
3346 | 3346 | return bms |
|
3347 | 3347 | |
|
3348 | 3348 | if bookmarks: |
|
3349 | 3349 | output.extend(getbms()) |
|
3350 | 3350 | elif default and not ui.quiet: |
|
3351 | 3351 | # multiple bookmarks for a single parent separated by '/' |
|
3352 | 3352 | bm = '/'.join(getbms()) |
|
3353 | 3353 | if bm: |
|
3354 | 3354 | output.append(bm) |
|
3355 | 3355 | else: |
|
3356 | 3356 | if not rev: |
|
3357 | 3357 | ctx = repo[None] |
|
3358 | 3358 | parents = ctx.parents() |
|
3359 | 3359 | changed = "" |
|
3360 | 3360 | if default or id or num: |
|
3361 | 3361 | changed = util.any(repo.status()) and "+" or "" |
|
3362 | 3362 | if default or id: |
|
3363 | 3363 | output = ["%s%s" % |
|
3364 | 3364 | ('+'.join([hexfunc(p.node()) for p in parents]), changed)] |
|
3365 | 3365 | if num: |
|
3366 | 3366 | output.append("%s%s" % |
|
3367 | 3367 | ('+'.join([str(p.rev()) for p in parents]), changed)) |
|
3368 | 3368 | else: |
|
3369 | 3369 | ctx = scmutil.revsingle(repo, rev) |
|
3370 | 3370 | if default or id: |
|
3371 | 3371 | output = [hexfunc(ctx.node())] |
|
3372 | 3372 | if num: |
|
3373 | 3373 | output.append(str(ctx.rev())) |
|
3374 | 3374 | |
|
3375 | 3375 | if default and not ui.quiet: |
|
3376 | 3376 | b = ctx.branch() |
|
3377 | 3377 | if b != 'default': |
|
3378 | 3378 | output.append("(%s)" % b) |
|
3379 | 3379 | |
|
3380 | 3380 | # multiple tags for a single parent separated by '/' |
|
3381 | 3381 | t = '/'.join(ctx.tags()) |
|
3382 | 3382 | if t: |
|
3383 | 3383 | output.append(t) |
|
3384 | 3384 | |
|
3385 | 3385 | # multiple bookmarks for a single parent separated by '/' |
|
3386 | 3386 | bm = '/'.join(ctx.bookmarks()) |
|
3387 | 3387 | if bm: |
|
3388 | 3388 | output.append(bm) |
|
3389 | 3389 | else: |
|
3390 | 3390 | if branch: |
|
3391 | 3391 | output.append(ctx.branch()) |
|
3392 | 3392 | |
|
3393 | 3393 | if tags: |
|
3394 | 3394 | output.extend(ctx.tags()) |
|
3395 | 3395 | |
|
3396 | 3396 | if bookmarks: |
|
3397 | 3397 | output.extend(ctx.bookmarks()) |
|
3398 | 3398 | |
|
3399 | 3399 | ui.write("%s\n" % ' '.join(output)) |
|
3400 | 3400 | |
|
3401 | 3401 | @command('import|patch', |
|
3402 | 3402 | [('p', 'strip', 1, |
|
3403 | 3403 | _('directory strip option for patch. This has the same ' |
|
3404 | 3404 | 'meaning as the corresponding patch option'), _('NUM')), |
|
3405 | 3405 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), |
|
3406 | 3406 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
3407 | 3407 | ('f', 'force', None, _('skip check for outstanding uncommitted changes')), |
|
3408 | 3408 | ('', 'no-commit', None, |
|
3409 | 3409 | _("don't commit, just update the working directory")), |
|
3410 | 3410 | ('', 'bypass', None, |
|
3411 | 3411 | _("apply patch without touching the working directory")), |
|
3412 | 3412 | ('', 'exact', None, |
|
3413 | 3413 | _('apply patch to the nodes from which it was generated')), |
|
3414 | 3414 | ('', 'import-branch', None, |
|
3415 | 3415 | _('use any branch information in patch (implied by --exact)'))] + |
|
3416 | 3416 | commitopts + commitopts2 + similarityopts, |
|
3417 | 3417 | _('[OPTION]... PATCH...')) |
|
3418 | 3418 | def import_(ui, repo, patch1=None, *patches, **opts): |
|
3419 | 3419 | """import an ordered set of patches |
|
3420 | 3420 | |
|
3421 | 3421 | Import a list of patches and commit them individually (unless |
|
3422 | 3422 | --no-commit is specified). |
|
3423 | 3423 | |
|
3424 | 3424 | If there are outstanding changes in the working directory, import |
|
3425 | 3425 | will abort unless given the -f/--force flag. |
|
3426 | 3426 | |
|
3427 | 3427 | You can import a patch straight from a mail message. Even patches |
|
3428 | 3428 | as attachments work (to use the body part, it must have type |
|
3429 | 3429 | text/plain or text/x-patch). From and Subject headers of email |
|
3430 | 3430 | message are used as default committer and commit message. All |
|
3431 | 3431 | text/plain body parts before first diff are added to commit |
|
3432 | 3432 | message. |
|
3433 | 3433 | |
|
3434 | 3434 | If the imported patch was generated by :hg:`export`, user and |
|
3435 | 3435 | description from patch override values from message headers and |
|
3436 | 3436 | body. Values given on command line with -m/--message and -u/--user |
|
3437 | 3437 | override these. |
|
3438 | 3438 | |
|
3439 | 3439 | If --exact is specified, import will set the working directory to |
|
3440 | 3440 | the parent of each patch before applying it, and will abort if the |
|
3441 | 3441 | resulting changeset has a different ID than the one recorded in |
|
3442 | 3442 | the patch. This may happen due to character set problems or other |
|
3443 | 3443 | deficiencies in the text patch format. |
|
3444 | 3444 | |
|
3445 | 3445 | Use --bypass to apply and commit patches directly to the |
|
3446 | 3446 | repository, not touching the working directory. Without --exact, |
|
3447 | 3447 | patches will be applied on top of the working directory parent |
|
3448 | 3448 | revision. |
|
3449 | 3449 | |
|
3450 | 3450 | With -s/--similarity, hg will attempt to discover renames and |
|
3451 | 3451 | copies in the patch in the same way as :hg:`addremove`. |
|
3452 | 3452 | |
|
3453 | 3453 | To read a patch from standard input, use "-" as the patch name. If |
|
3454 | 3454 | a URL is specified, the patch will be downloaded from it. |
|
3455 | 3455 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3456 | 3456 | |
|
3457 | 3457 | .. container:: verbose |
|
3458 | 3458 | |
|
3459 | 3459 | Examples: |
|
3460 | 3460 | |
|
3461 | 3461 | - import a traditional patch from a website and detect renames:: |
|
3462 | 3462 | |
|
3463 | 3463 | hg import -s 80 http://example.com/bugfix.patch |
|
3464 | 3464 | |
|
3465 | 3465 | - import a changeset from an hgweb server:: |
|
3466 | 3466 | |
|
3467 | 3467 | hg import http://www.selenic.com/hg/rev/5ca8c111e9aa |
|
3468 | 3468 | |
|
3469 | 3469 | - import all the patches in an Unix-style mbox:: |
|
3470 | 3470 | |
|
3471 | 3471 | hg import incoming-patches.mbox |
|
3472 | 3472 | |
|
3473 | 3473 | - attempt to exactly restore an exported changeset (not always |
|
3474 | 3474 | possible):: |
|
3475 | 3475 | |
|
3476 | 3476 | hg import --exact proposed-fix.patch |
|
3477 | 3477 | |
|
3478 | 3478 | Returns 0 on success. |
|
3479 | 3479 | """ |
|
3480 | 3480 | |
|
3481 | 3481 | if not patch1: |
|
3482 | 3482 | raise util.Abort(_('need at least one patch to import')) |
|
3483 | 3483 | |
|
3484 | 3484 | patches = (patch1,) + patches |
|
3485 | 3485 | |
|
3486 | 3486 | date = opts.get('date') |
|
3487 | 3487 | if date: |
|
3488 | 3488 | opts['date'] = util.parsedate(date) |
|
3489 | 3489 | |
|
3490 | 3490 | editor = cmdutil.commiteditor |
|
3491 | 3491 | if opts.get('edit'): |
|
3492 | 3492 | editor = cmdutil.commitforceeditor |
|
3493 | 3493 | |
|
3494 | 3494 | update = not opts.get('bypass') |
|
3495 | 3495 | if not update and opts.get('no_commit'): |
|
3496 | 3496 | raise util.Abort(_('cannot use --no-commit with --bypass')) |
|
3497 | 3497 | try: |
|
3498 | 3498 | sim = float(opts.get('similarity') or 0) |
|
3499 | 3499 | except ValueError: |
|
3500 | 3500 | raise util.Abort(_('similarity must be a number')) |
|
3501 | 3501 | if sim < 0 or sim > 100: |
|
3502 | 3502 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
3503 | 3503 | if sim and not update: |
|
3504 | 3504 | raise util.Abort(_('cannot use --similarity with --bypass')) |
|
3505 | 3505 | |
|
3506 | 3506 | if (opts.get('exact') or not opts.get('force')) and update: |
|
3507 | 3507 | cmdutil.bailifchanged(repo) |
|
3508 | 3508 | |
|
3509 | 3509 | base = opts["base"] |
|
3510 | 3510 | strip = opts["strip"] |
|
3511 | 3511 | wlock = lock = tr = None |
|
3512 | 3512 | msgs = [] |
|
3513 | 3513 | |
|
3514 | 3514 | def checkexact(repo, n, nodeid): |
|
3515 | 3515 | if opts.get('exact') and hex(n) != nodeid: |
|
3516 | 3516 | repo.rollback() |
|
3517 | 3517 | raise util.Abort(_('patch is damaged or loses information')) |
|
3518 | 3518 | |
|
3519 | 3519 | def tryone(ui, hunk, parents): |
|
3520 | 3520 | tmpname, message, user, date, branch, nodeid, p1, p2 = \ |
|
3521 | 3521 | patch.extract(ui, hunk) |
|
3522 | 3522 | |
|
3523 | 3523 | if not tmpname: |
|
3524 | 3524 | return (None, None) |
|
3525 | 3525 | msg = _('applied to working directory') |
|
3526 | 3526 | |
|
3527 | 3527 | try: |
|
3528 | 3528 | cmdline_message = cmdutil.logmessage(ui, opts) |
|
3529 | 3529 | if cmdline_message: |
|
3530 | 3530 | # pickup the cmdline msg |
|
3531 | 3531 | message = cmdline_message |
|
3532 | 3532 | elif message: |
|
3533 | 3533 | # pickup the patch msg |
|
3534 | 3534 | message = message.strip() |
|
3535 | 3535 | else: |
|
3536 | 3536 | # launch the editor |
|
3537 | 3537 | message = None |
|
3538 | 3538 | ui.debug('message:\n%s\n' % message) |
|
3539 | 3539 | |
|
3540 | 3540 | if len(parents) == 1: |
|
3541 | 3541 | parents.append(repo[nullid]) |
|
3542 | 3542 | if opts.get('exact'): |
|
3543 | 3543 | if not nodeid or not p1: |
|
3544 | 3544 | raise util.Abort(_('not a Mercurial patch')) |
|
3545 | 3545 | p1 = repo[p1] |
|
3546 | 3546 | p2 = repo[p2 or nullid] |
|
3547 | 3547 | elif p2: |
|
3548 | 3548 | try: |
|
3549 | 3549 | p1 = repo[p1] |
|
3550 | 3550 | p2 = repo[p2] |
|
3551 | 3551 | # Without any options, consider p2 only if the |
|
3552 | 3552 | # patch is being applied on top of the recorded |
|
3553 | 3553 | # first parent. |
|
3554 | 3554 | if p1 != parents[0]: |
|
3555 | 3555 | p1 = parents[0] |
|
3556 | 3556 | p2 = repo[nullid] |
|
3557 | 3557 | except error.RepoError: |
|
3558 | 3558 | p1, p2 = parents |
|
3559 | 3559 | else: |
|
3560 | 3560 | p1, p2 = parents |
|
3561 | 3561 | |
|
3562 | 3562 | n = None |
|
3563 | 3563 | if update: |
|
3564 | 3564 | if p1 != parents[0]: |
|
3565 | 3565 | hg.clean(repo, p1.node()) |
|
3566 | 3566 | if p2 != parents[1]: |
|
3567 | 3567 | repo.dirstate.setparents(p1.node(), p2.node()) |
|
3568 | 3568 | |
|
3569 | 3569 | if opts.get('exact') or opts.get('import_branch'): |
|
3570 | 3570 | repo.dirstate.setbranch(branch or 'default') |
|
3571 | 3571 | |
|
3572 | 3572 | files = set() |
|
3573 | 3573 | patch.patch(ui, repo, tmpname, strip=strip, files=files, |
|
3574 | 3574 | eolmode=None, similarity=sim / 100.0) |
|
3575 | 3575 | files = list(files) |
|
3576 | 3576 | if opts.get('no_commit'): |
|
3577 | 3577 | if message: |
|
3578 | 3578 | msgs.append(message) |
|
3579 | 3579 | else: |
|
3580 | 3580 | if opts.get('exact') or p2: |
|
3581 | 3581 | # If you got here, you either use --force and know what |
|
3582 | 3582 | # you are doing or used --exact or a merge patch while |
|
3583 | 3583 | # being updated to its first parent. |
|
3584 | 3584 | m = None |
|
3585 | 3585 | else: |
|
3586 | 3586 | m = scmutil.matchfiles(repo, files or []) |
|
3587 | 3587 | n = repo.commit(message, opts.get('user') or user, |
|
3588 | 3588 | opts.get('date') or date, match=m, |
|
3589 | 3589 | editor=editor) |
|
3590 | 3590 | checkexact(repo, n, nodeid) |
|
3591 | 3591 | else: |
|
3592 | 3592 | if opts.get('exact') or opts.get('import_branch'): |
|
3593 | 3593 | branch = branch or 'default' |
|
3594 | 3594 | else: |
|
3595 | 3595 | branch = p1.branch() |
|
3596 | 3596 | store = patch.filestore() |
|
3597 | 3597 | try: |
|
3598 | 3598 | files = set() |
|
3599 | 3599 | try: |
|
3600 | 3600 | patch.patchrepo(ui, repo, p1, store, tmpname, strip, |
|
3601 | 3601 | files, eolmode=None) |
|
3602 | 3602 | except patch.PatchError, e: |
|
3603 | 3603 | raise util.Abort(str(e)) |
|
3604 | 3604 | memctx = patch.makememctx(repo, (p1.node(), p2.node()), |
|
3605 | 3605 | message, |
|
3606 | 3606 | opts.get('user') or user, |
|
3607 | 3607 | opts.get('date') or date, |
|
3608 | 3608 | branch, files, store, |
|
3609 | 3609 | editor=cmdutil.commiteditor) |
|
3610 | 3610 | repo.savecommitmessage(memctx.description()) |
|
3611 | 3611 | n = memctx.commit() |
|
3612 | 3612 | checkexact(repo, n, nodeid) |
|
3613 | 3613 | finally: |
|
3614 | 3614 | store.close() |
|
3615 | 3615 | if n: |
|
3616 | 3616 | # i18n: refers to a short changeset id |
|
3617 | 3617 | msg = _('created %s') % short(n) |
|
3618 | 3618 | return (msg, n) |
|
3619 | 3619 | finally: |
|
3620 | 3620 | os.unlink(tmpname) |
|
3621 | 3621 | |
|
3622 | 3622 | try: |
|
3623 | 3623 | try: |
|
3624 | 3624 | wlock = repo.wlock() |
|
3625 | 3625 | if not opts.get('no_commit'): |
|
3626 | 3626 | lock = repo.lock() |
|
3627 | 3627 | tr = repo.transaction('import') |
|
3628 | 3628 | parents = repo.parents() |
|
3629 | 3629 | for patchurl in patches: |
|
3630 | 3630 | if patchurl == '-': |
|
3631 | 3631 | ui.status(_('applying patch from stdin\n')) |
|
3632 | 3632 | patchfile = ui.fin |
|
3633 | 3633 | patchurl = 'stdin' # for error message |
|
3634 | 3634 | else: |
|
3635 | 3635 | patchurl = os.path.join(base, patchurl) |
|
3636 | 3636 | ui.status(_('applying %s\n') % patchurl) |
|
3637 | 3637 | patchfile = url.open(ui, patchurl) |
|
3638 | 3638 | |
|
3639 | 3639 | haspatch = False |
|
3640 | 3640 | for hunk in patch.split(patchfile): |
|
3641 | 3641 | (msg, node) = tryone(ui, hunk, parents) |
|
3642 | 3642 | if msg: |
|
3643 | 3643 | haspatch = True |
|
3644 | 3644 | ui.note(msg + '\n') |
|
3645 | 3645 | if update or opts.get('exact'): |
|
3646 | 3646 | parents = repo.parents() |
|
3647 | 3647 | else: |
|
3648 | 3648 | parents = [repo[node]] |
|
3649 | 3649 | |
|
3650 | 3650 | if not haspatch: |
|
3651 | 3651 | raise util.Abort(_('%s: no diffs found') % patchurl) |
|
3652 | 3652 | |
|
3653 | 3653 | if tr: |
|
3654 | 3654 | tr.close() |
|
3655 | 3655 | if msgs: |
|
3656 | 3656 | repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
3657 | 3657 | except: |
|
3658 | 3658 | # wlock.release() indirectly calls dirstate.write(): since |
|
3659 | 3659 | # we're crashing, we do not want to change the working dir |
|
3660 | 3660 | # parent after all, so make sure it writes nothing |
|
3661 | 3661 | repo.dirstate.invalidate() |
|
3662 | 3662 | raise |
|
3663 | 3663 | finally: |
|
3664 | 3664 | if tr: |
|
3665 | 3665 | tr.release() |
|
3666 | 3666 | release(lock, wlock) |
|
3667 | 3667 | |
|
3668 | 3668 | @command('incoming|in', |
|
3669 | 3669 | [('f', 'force', None, |
|
3670 | 3670 | _('run even if remote repository is unrelated')), |
|
3671 | 3671 | ('n', 'newest-first', None, _('show newest record first')), |
|
3672 | 3672 | ('', 'bundle', '', |
|
3673 | 3673 | _('file to store the bundles into'), _('FILE')), |
|
3674 | 3674 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3675 | 3675 | ('B', 'bookmarks', False, _("compare bookmarks")), |
|
3676 | 3676 | ('b', 'branch', [], |
|
3677 | 3677 | _('a specific branch you would like to pull'), _('BRANCH')), |
|
3678 | 3678 | ] + logopts + remoteopts + subrepoopts, |
|
3679 | 3679 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) |
|
3680 | 3680 | def incoming(ui, repo, source="default", **opts): |
|
3681 | 3681 | """show new changesets found in source |
|
3682 | 3682 | |
|
3683 | 3683 | Show new changesets found in the specified path/URL or the default |
|
3684 | 3684 | pull location. These are the changesets that would have been pulled |
|
3685 | 3685 | if a pull at the time you issued this command. |
|
3686 | 3686 | |
|
3687 | 3687 | For remote repository, using --bundle avoids downloading the |
|
3688 | 3688 | changesets twice if the incoming is followed by a pull. |
|
3689 | 3689 | |
|
3690 | 3690 | See pull for valid source format details. |
|
3691 | 3691 | |
|
3692 | 3692 | Returns 0 if there are incoming changes, 1 otherwise. |
|
3693 | 3693 | """ |
|
3694 | 3694 | if opts.get('bundle') and opts.get('subrepos'): |
|
3695 | 3695 | raise util.Abort(_('cannot combine --bundle and --subrepos')) |
|
3696 | 3696 | |
|
3697 | 3697 | if opts.get('bookmarks'): |
|
3698 | 3698 | source, branches = hg.parseurl(ui.expandpath(source), |
|
3699 | 3699 | opts.get('branch')) |
|
3700 | 3700 | other = hg.peer(repo, opts, source) |
|
3701 | 3701 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3702 | 3702 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3703 | 3703 | return 0 |
|
3704 | 3704 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
3705 | 3705 | return bookmarks.diff(ui, repo, other) |
|
3706 | 3706 | |
|
3707 | 3707 | repo._subtoppath = ui.expandpath(source) |
|
3708 | 3708 | try: |
|
3709 | 3709 | return hg.incoming(ui, repo, source, opts) |
|
3710 | 3710 | finally: |
|
3711 | 3711 | del repo._subtoppath |
|
3712 | 3712 | |
|
3713 | 3713 | |
|
3714 | 3714 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]')) |
|
3715 | 3715 | def init(ui, dest=".", **opts): |
|
3716 | 3716 | """create a new repository in the given directory |
|
3717 | 3717 | |
|
3718 | 3718 | Initialize a new repository in the given directory. If the given |
|
3719 | 3719 | directory does not exist, it will be created. |
|
3720 | 3720 | |
|
3721 | 3721 | If no directory is given, the current directory is used. |
|
3722 | 3722 | |
|
3723 | 3723 | It is possible to specify an ``ssh://`` URL as the destination. |
|
3724 | 3724 | See :hg:`help urls` for more information. |
|
3725 | 3725 | |
|
3726 | 3726 | Returns 0 on success. |
|
3727 | 3727 | """ |
|
3728 | 3728 | hg.peer(ui, opts, ui.expandpath(dest), create=True) |
|
3729 | 3729 | |
|
3730 | 3730 | @command('locate', |
|
3731 | 3731 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
3732 | 3732 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
3733 | 3733 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), |
|
3734 | 3734 | ] + walkopts, |
|
3735 | 3735 | _('[OPTION]... [PATTERN]...')) |
|
3736 | 3736 | def locate(ui, repo, *pats, **opts): |
|
3737 | 3737 | """locate files matching specific patterns |
|
3738 | 3738 | |
|
3739 | 3739 | Print files under Mercurial control in the working directory whose |
|
3740 | 3740 | names match the given patterns. |
|
3741 | 3741 | |
|
3742 | 3742 | By default, this command searches all directories in the working |
|
3743 | 3743 | directory. To search just the current directory and its |
|
3744 | 3744 | subdirectories, use "--include .". |
|
3745 | 3745 | |
|
3746 | 3746 | If no patterns are given to match, this command prints the names |
|
3747 | 3747 | of all files under Mercurial control in the working directory. |
|
3748 | 3748 | |
|
3749 | 3749 | If you want to feed the output of this command into the "xargs" |
|
3750 | 3750 | command, use the -0 option to both this command and "xargs". This |
|
3751 | 3751 | will avoid the problem of "xargs" treating single filenames that |
|
3752 | 3752 | contain whitespace as multiple filenames. |
|
3753 | 3753 | |
|
3754 | 3754 | Returns 0 if a match is found, 1 otherwise. |
|
3755 | 3755 | """ |
|
3756 | 3756 | end = opts.get('print0') and '\0' or '\n' |
|
3757 | 3757 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() |
|
3758 | 3758 | |
|
3759 | 3759 | ret = 1 |
|
3760 | 3760 | m = scmutil.match(repo[rev], pats, opts, default='relglob') |
|
3761 | 3761 | m.bad = lambda x, y: False |
|
3762 | 3762 | for abs in repo[rev].walk(m): |
|
3763 | 3763 | if not rev and abs not in repo.dirstate: |
|
3764 | 3764 | continue |
|
3765 | 3765 | if opts.get('fullpath'): |
|
3766 | 3766 | ui.write(repo.wjoin(abs), end) |
|
3767 | 3767 | else: |
|
3768 | 3768 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
3769 | 3769 | ret = 0 |
|
3770 | 3770 | |
|
3771 | 3771 | return ret |
|
3772 | 3772 | |
|
3773 | 3773 | @command('^log|history', |
|
3774 | 3774 | [('f', 'follow', None, |
|
3775 | 3775 | _('follow changeset history, or file history across copies and renames')), |
|
3776 | 3776 | ('', 'follow-first', None, |
|
3777 | 3777 | _('only follow the first parent of merge changesets (DEPRECATED)')), |
|
3778 | 3778 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), |
|
3779 | 3779 | ('C', 'copies', None, _('show copied files')), |
|
3780 | 3780 | ('k', 'keyword', [], |
|
3781 | 3781 | _('do case-insensitive search for a given text'), _('TEXT')), |
|
3782 | 3782 | ('r', 'rev', [], _('show the specified revision or range'), _('REV')), |
|
3783 | 3783 | ('', 'removed', None, _('include revisions where files were removed')), |
|
3784 | 3784 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), |
|
3785 | 3785 | ('u', 'user', [], _('revisions committed by user'), _('USER')), |
|
3786 | 3786 | ('', 'only-branch', [], |
|
3787 | 3787 | _('show only changesets within the given named branch (DEPRECATED)'), |
|
3788 | 3788 | _('BRANCH')), |
|
3789 | 3789 | ('b', 'branch', [], |
|
3790 | 3790 | _('show changesets within the given named branch'), _('BRANCH')), |
|
3791 | 3791 | ('P', 'prune', [], |
|
3792 | 3792 | _('do not display revision or any of its ancestors'), _('REV')), |
|
3793 | 3793 | ('', 'hidden', False, _('show hidden changesets (DEPRECATED)')), |
|
3794 | 3794 | ] + logopts + walkopts, |
|
3795 | 3795 | _('[OPTION]... [FILE]')) |
|
3796 | 3796 | def log(ui, repo, *pats, **opts): |
|
3797 | 3797 | """show revision history of entire repository or files |
|
3798 | 3798 | |
|
3799 | 3799 | Print the revision history of the specified files or the entire |
|
3800 | 3800 | project. |
|
3801 | 3801 | |
|
3802 | 3802 | If no revision range is specified, the default is ``tip:0`` unless |
|
3803 | 3803 | --follow is set, in which case the working directory parent is |
|
3804 | 3804 | used as the starting revision. |
|
3805 | 3805 | |
|
3806 | 3806 | File history is shown without following rename or copy history of |
|
3807 | 3807 | files. Use -f/--follow with a filename to follow history across |
|
3808 | 3808 | renames and copies. --follow without a filename will only show |
|
3809 | 3809 | ancestors or descendants of the starting revision. |
|
3810 | 3810 | |
|
3811 | 3811 | By default this command prints revision number and changeset id, |
|
3812 | 3812 | tags, non-trivial parents, user, date and time, and a summary for |
|
3813 | 3813 | each commit. When the -v/--verbose switch is used, the list of |
|
3814 | 3814 | changed files and full commit message are shown. |
|
3815 | 3815 | |
|
3816 | 3816 | .. note:: |
|
3817 | 3817 | log -p/--patch may generate unexpected diff output for merge |
|
3818 | 3818 | changesets, as it will only compare the merge changeset against |
|
3819 | 3819 | its first parent. Also, only files different from BOTH parents |
|
3820 | 3820 | will appear in files:. |
|
3821 | 3821 | |
|
3822 | 3822 | .. note:: |
|
3823 | 3823 | for performance reasons, log FILE may omit duplicate changes |
|
3824 | 3824 | made on branches and will not show deletions. To see all |
|
3825 | 3825 | changes including duplicates and deletions, use the --removed |
|
3826 | 3826 | switch. |
|
3827 | 3827 | |
|
3828 | 3828 | .. container:: verbose |
|
3829 | 3829 | |
|
3830 | 3830 | Some examples: |
|
3831 | 3831 | |
|
3832 | 3832 | - changesets with full descriptions and file lists:: |
|
3833 | 3833 | |
|
3834 | 3834 | hg log -v |
|
3835 | 3835 | |
|
3836 | 3836 | - changesets ancestral to the working directory:: |
|
3837 | 3837 | |
|
3838 | 3838 | hg log -f |
|
3839 | 3839 | |
|
3840 | 3840 | - last 10 commits on the current branch:: |
|
3841 | 3841 | |
|
3842 | 3842 | hg log -l 10 -b . |
|
3843 | 3843 | |
|
3844 | 3844 | - changesets showing all modifications of a file, including removals:: |
|
3845 | 3845 | |
|
3846 | 3846 | hg log --removed file.c |
|
3847 | 3847 | |
|
3848 | 3848 | - all changesets that touch a directory, with diffs, excluding merges:: |
|
3849 | 3849 | |
|
3850 | 3850 | hg log -Mp lib/ |
|
3851 | 3851 | |
|
3852 | 3852 | - all revision numbers that match a keyword:: |
|
3853 | 3853 | |
|
3854 | 3854 | hg log -k bug --template "{rev}\\n" |
|
3855 | 3855 | |
|
3856 | 3856 | - check if a given changeset is included is a tagged release:: |
|
3857 | 3857 | |
|
3858 | 3858 | hg log -r "a21ccf and ancestor(1.9)" |
|
3859 | 3859 | |
|
3860 | 3860 | - find all changesets by some user in a date range:: |
|
3861 | 3861 | |
|
3862 | 3862 | hg log -k alice -d "may 2008 to jul 2008" |
|
3863 | 3863 | |
|
3864 | 3864 | - summary of all changesets after the last tag:: |
|
3865 | 3865 | |
|
3866 | 3866 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" |
|
3867 | 3867 | |
|
3868 | 3868 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3869 | 3869 | |
|
3870 | 3870 | See :hg:`help revisions` and :hg:`help revsets` for more about |
|
3871 | 3871 | specifying revisions. |
|
3872 | 3872 | |
|
3873 | 3873 | Returns 0 on success. |
|
3874 | 3874 | """ |
|
3875 | 3875 | |
|
3876 | 3876 | matchfn = scmutil.match(repo[None], pats, opts) |
|
3877 | 3877 | limit = cmdutil.loglimit(opts) |
|
3878 | 3878 | count = 0 |
|
3879 | 3879 | |
|
3880 | 3880 | getrenamed, endrev = None, None |
|
3881 | 3881 | if opts.get('copies'): |
|
3882 | 3882 | if opts.get('rev'): |
|
3883 | 3883 | endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1 |
|
3884 | 3884 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
3885 | 3885 | |
|
3886 | 3886 | df = False |
|
3887 | 3887 | if opts["date"]: |
|
3888 | 3888 | df = util.matchdate(opts["date"]) |
|
3889 | 3889 | |
|
3890 | 3890 | branches = opts.get('branch', []) + opts.get('only_branch', []) |
|
3891 | 3891 | opts['branch'] = [repo.lookupbranch(b) for b in branches] |
|
3892 | 3892 | |
|
3893 | 3893 | displayer = cmdutil.show_changeset(ui, repo, opts, True) |
|
3894 | 3894 | def prep(ctx, fns): |
|
3895 | 3895 | rev = ctx.rev() |
|
3896 | 3896 | parents = [p for p in repo.changelog.parentrevs(rev) |
|
3897 | 3897 | if p != nullrev] |
|
3898 | 3898 | if opts.get('no_merges') and len(parents) == 2: |
|
3899 | 3899 | return |
|
3900 | 3900 | if opts.get('only_merges') and len(parents) != 2: |
|
3901 | 3901 | return |
|
3902 | 3902 | if opts.get('branch') and ctx.branch() not in opts['branch']: |
|
3903 | 3903 | return |
|
3904 | 3904 | if not opts.get('hidden') and ctx.hidden(): |
|
3905 | 3905 | return |
|
3906 | 3906 | if df and not df(ctx.date()[0]): |
|
3907 | 3907 | return |
|
3908 | 3908 | |
|
3909 | 3909 | lower = encoding.lower |
|
3910 | 3910 | if opts.get('user'): |
|
3911 | 3911 | luser = lower(ctx.user()) |
|
3912 | 3912 | for k in [lower(x) for x in opts['user']]: |
|
3913 | 3913 | if (k in luser): |
|
3914 | 3914 | break |
|
3915 | 3915 | else: |
|
3916 | 3916 | return |
|
3917 | 3917 | if opts.get('keyword'): |
|
3918 | 3918 | luser = lower(ctx.user()) |
|
3919 | 3919 | ldesc = lower(ctx.description()) |
|
3920 | 3920 | lfiles = lower(" ".join(ctx.files())) |
|
3921 | 3921 | for k in [lower(x) for x in opts['keyword']]: |
|
3922 | 3922 | if (k in luser or k in ldesc or k in lfiles): |
|
3923 | 3923 | break |
|
3924 | 3924 | else: |
|
3925 | 3925 | return |
|
3926 | 3926 | |
|
3927 | 3927 | copies = None |
|
3928 | 3928 | if getrenamed is not None and rev: |
|
3929 | 3929 | copies = [] |
|
3930 | 3930 | for fn in ctx.files(): |
|
3931 | 3931 | rename = getrenamed(fn, rev) |
|
3932 | 3932 | if rename: |
|
3933 | 3933 | copies.append((fn, rename[0])) |
|
3934 | 3934 | |
|
3935 | 3935 | revmatchfn = None |
|
3936 | 3936 | if opts.get('patch') or opts.get('stat'): |
|
3937 | 3937 | if opts.get('follow') or opts.get('follow_first'): |
|
3938 | 3938 | # note: this might be wrong when following through merges |
|
3939 | 3939 | revmatchfn = scmutil.match(repo[None], fns, default='path') |
|
3940 | 3940 | else: |
|
3941 | 3941 | revmatchfn = matchfn |
|
3942 | 3942 | |
|
3943 | 3943 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
3944 | 3944 | |
|
3945 | 3945 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
3946 | 3946 | if count == limit: |
|
3947 | 3947 | break |
|
3948 | 3948 | if displayer.flush(ctx.rev()): |
|
3949 | 3949 | count += 1 |
|
3950 | 3950 | displayer.close() |
|
3951 | 3951 | |
|
3952 | 3952 | @command('manifest', |
|
3953 | 3953 | [('r', 'rev', '', _('revision to display'), _('REV')), |
|
3954 | 3954 | ('', 'all', False, _("list files from all revisions"))], |
|
3955 | 3955 | _('[-r REV]')) |
|
3956 | 3956 | def manifest(ui, repo, node=None, rev=None, **opts): |
|
3957 | 3957 | """output the current or given revision of the project manifest |
|
3958 | 3958 | |
|
3959 | 3959 | Print a list of version controlled files for the given revision. |
|
3960 | 3960 | If no revision is given, the first parent of the working directory |
|
3961 | 3961 | is used, or the null revision if no revision is checked out. |
|
3962 | 3962 | |
|
3963 | 3963 | With -v, print file permissions, symlink and executable bits. |
|
3964 | 3964 | With --debug, print file revision hashes. |
|
3965 | 3965 | |
|
3966 | 3966 | If option --all is specified, the list of all files from all revisions |
|
3967 | 3967 | is printed. This includes deleted and renamed files. |
|
3968 | 3968 | |
|
3969 | 3969 | Returns 0 on success. |
|
3970 | 3970 | """ |
|
3971 | 3971 | if opts.get('all'): |
|
3972 | 3972 | if rev or node: |
|
3973 | 3973 | raise util.Abort(_("can't specify a revision with --all")) |
|
3974 | 3974 | |
|
3975 | 3975 | res = [] |
|
3976 | 3976 | prefix = "data/" |
|
3977 | 3977 | suffix = ".i" |
|
3978 | 3978 | plen = len(prefix) |
|
3979 | 3979 | slen = len(suffix) |
|
3980 | 3980 | lock = repo.lock() |
|
3981 | 3981 | try: |
|
3982 | 3982 | for fn, b, size in repo.store.datafiles(): |
|
3983 | 3983 | if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: |
|
3984 | 3984 | res.append(fn[plen:-slen]) |
|
3985 | 3985 | finally: |
|
3986 | 3986 | lock.release() |
|
3987 | 3987 | for f in sorted(res): |
|
3988 | 3988 | ui.write("%s\n" % f) |
|
3989 | 3989 | return |
|
3990 | 3990 | |
|
3991 | 3991 | if rev and node: |
|
3992 | 3992 | raise util.Abort(_("please specify just one revision")) |
|
3993 | 3993 | |
|
3994 | 3994 | if not node: |
|
3995 | 3995 | node = rev |
|
3996 | 3996 | |
|
3997 | 3997 | decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} |
|
3998 | 3998 | ctx = scmutil.revsingle(repo, node) |
|
3999 | 3999 | for f in ctx: |
|
4000 | 4000 | if ui.debugflag: |
|
4001 | 4001 | ui.write("%40s " % hex(ctx.manifest()[f])) |
|
4002 | 4002 | if ui.verbose: |
|
4003 | 4003 | ui.write(decor[ctx.flags(f)]) |
|
4004 | 4004 | ui.write("%s\n" % f) |
|
4005 | 4005 | |
|
4006 | 4006 | @command('^merge', |
|
4007 | 4007 | [('f', 'force', None, _('force a merge with outstanding changes')), |
|
4008 | 4008 | ('r', 'rev', '', _('revision to merge'), _('REV')), |
|
4009 | 4009 | ('P', 'preview', None, |
|
4010 | 4010 | _('review revisions to merge (no merge is performed)')) |
|
4011 | 4011 | ] + mergetoolopts, |
|
4012 | 4012 | _('[-P] [-f] [[-r] REV]')) |
|
4013 | 4013 | def merge(ui, repo, node=None, **opts): |
|
4014 | 4014 | """merge working directory with another revision |
|
4015 | 4015 | |
|
4016 | 4016 | The current working directory is updated with all changes made in |
|
4017 | 4017 | the requested revision since the last common predecessor revision. |
|
4018 | 4018 | |
|
4019 | 4019 | Files that changed between either parent are marked as changed for |
|
4020 | 4020 | the next commit and a commit must be performed before any further |
|
4021 | 4021 | updates to the repository are allowed. The next commit will have |
|
4022 | 4022 | two parents. |
|
4023 | 4023 | |
|
4024 | 4024 | ``--tool`` can be used to specify the merge tool used for file |
|
4025 | 4025 | merges. It overrides the HGMERGE environment variable and your |
|
4026 | 4026 | configuration files. See :hg:`help merge-tools` for options. |
|
4027 | 4027 | |
|
4028 | 4028 | If no revision is specified, the working directory's parent is a |
|
4029 | 4029 | head revision, and the current branch contains exactly one other |
|
4030 | 4030 | head, the other head is merged with by default. Otherwise, an |
|
4031 | 4031 | explicit revision with which to merge with must be provided. |
|
4032 | 4032 | |
|
4033 | 4033 | :hg:`resolve` must be used to resolve unresolved files. |
|
4034 | 4034 | |
|
4035 | 4035 | To undo an uncommitted merge, use :hg:`update --clean .` which |
|
4036 | 4036 | will check out a clean copy of the original merge parent, losing |
|
4037 | 4037 | all changes. |
|
4038 | 4038 | |
|
4039 | 4039 | Returns 0 on success, 1 if there are unresolved files. |
|
4040 | 4040 | """ |
|
4041 | 4041 | |
|
4042 | 4042 | if opts.get('rev') and node: |
|
4043 | 4043 | raise util.Abort(_("please specify just one revision")) |
|
4044 | 4044 | if not node: |
|
4045 | 4045 | node = opts.get('rev') |
|
4046 | 4046 | |
|
4047 | 4047 | if not node: |
|
4048 | 4048 | branch = repo[None].branch() |
|
4049 | 4049 | bheads = repo.branchheads(branch) |
|
4050 | 4050 | if len(bheads) > 2: |
|
4051 | 4051 | raise util.Abort(_("branch '%s' has %d heads - " |
|
4052 | 4052 | "please merge with an explicit rev") |
|
4053 | 4053 | % (branch, len(bheads)), |
|
4054 | 4054 | hint=_("run 'hg heads .' to see heads")) |
|
4055 | 4055 | |
|
4056 | 4056 | parent = repo.dirstate.p1() |
|
4057 | 4057 | if len(bheads) == 1: |
|
4058 | 4058 | if len(repo.heads()) > 1: |
|
4059 | 4059 | raise util.Abort(_("branch '%s' has one head - " |
|
4060 | 4060 | "please merge with an explicit rev") |
|
4061 | 4061 | % branch, |
|
4062 | 4062 | hint=_("run 'hg heads' to see all heads")) |
|
4063 | 4063 | msg, hint = _('nothing to merge'), None |
|
4064 | 4064 | if parent != repo.lookup(branch): |
|
4065 | 4065 | hint = _("use 'hg update' instead") |
|
4066 | 4066 | raise util.Abort(msg, hint=hint) |
|
4067 | 4067 | |
|
4068 | 4068 | if parent not in bheads: |
|
4069 | 4069 | raise util.Abort(_('working directory not at a head revision'), |
|
4070 | 4070 | hint=_("use 'hg update' or merge with an " |
|
4071 | 4071 | "explicit revision")) |
|
4072 | 4072 | node = parent == bheads[0] and bheads[-1] or bheads[0] |
|
4073 | 4073 | else: |
|
4074 | 4074 | node = scmutil.revsingle(repo, node).node() |
|
4075 | 4075 | |
|
4076 | 4076 | if opts.get('preview'): |
|
4077 | 4077 | # find nodes that are ancestors of p2 but not of p1 |
|
4078 | 4078 | p1 = repo.lookup('.') |
|
4079 | 4079 | p2 = repo.lookup(node) |
|
4080 | 4080 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
4081 | 4081 | |
|
4082 | 4082 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
4083 | 4083 | for node in nodes: |
|
4084 | 4084 | displayer.show(repo[node]) |
|
4085 | 4085 | displayer.close() |
|
4086 | 4086 | return 0 |
|
4087 | 4087 | |
|
4088 | 4088 | try: |
|
4089 | 4089 | # ui.forcemerge is an internal variable, do not document |
|
4090 | 4090 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
4091 | 4091 | return hg.merge(repo, node, force=opts.get('force')) |
|
4092 | 4092 | finally: |
|
4093 | 4093 | ui.setconfig('ui', 'forcemerge', '') |
|
4094 | 4094 | |
|
4095 | 4095 | @command('outgoing|out', |
|
4096 | 4096 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
4097 | 4097 | ('r', 'rev', [], |
|
4098 | 4098 | _('a changeset intended to be included in the destination'), _('REV')), |
|
4099 | 4099 | ('n', 'newest-first', None, _('show newest record first')), |
|
4100 | 4100 | ('B', 'bookmarks', False, _('compare bookmarks')), |
|
4101 | 4101 | ('b', 'branch', [], _('a specific branch you would like to push'), |
|
4102 | 4102 | _('BRANCH')), |
|
4103 | 4103 | ] + logopts + remoteopts + subrepoopts, |
|
4104 | 4104 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) |
|
4105 | 4105 | def outgoing(ui, repo, dest=None, **opts): |
|
4106 | 4106 | """show changesets not found in the destination |
|
4107 | 4107 | |
|
4108 | 4108 | Show changesets not found in the specified destination repository |
|
4109 | 4109 | or the default push location. These are the changesets that would |
|
4110 | 4110 | be pushed if a push was requested. |
|
4111 | 4111 | |
|
4112 | 4112 | See pull for details of valid destination formats. |
|
4113 | 4113 | |
|
4114 | 4114 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
4115 | 4115 | """ |
|
4116 | 4116 | |
|
4117 | 4117 | if opts.get('bookmarks'): |
|
4118 | 4118 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
4119 | 4119 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
4120 | 4120 | other = hg.peer(repo, opts, dest) |
|
4121 | 4121 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
4122 | 4122 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
4123 | 4123 | return 0 |
|
4124 | 4124 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
4125 | 4125 | return bookmarks.diff(ui, other, repo) |
|
4126 | 4126 | |
|
4127 | 4127 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') |
|
4128 | 4128 | try: |
|
4129 | 4129 | return hg.outgoing(ui, repo, dest, opts) |
|
4130 | 4130 | finally: |
|
4131 | 4131 | del repo._subtoppath |
|
4132 | 4132 | |
|
4133 | 4133 | @command('parents', |
|
4134 | 4134 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), |
|
4135 | 4135 | ] + templateopts, |
|
4136 | 4136 | _('[-r REV] [FILE]')) |
|
4137 | 4137 | def parents(ui, repo, file_=None, **opts): |
|
4138 | 4138 | """show the parents of the working directory or revision |
|
4139 | 4139 | |
|
4140 | 4140 | Print the working directory's parent revisions. If a revision is |
|
4141 | 4141 | given via -r/--rev, the parent of that revision will be printed. |
|
4142 | 4142 | If a file argument is given, the revision in which the file was |
|
4143 | 4143 | last changed (before the working directory revision or the |
|
4144 | 4144 | argument to --rev if given) is printed. |
|
4145 | 4145 | |
|
4146 | 4146 | Returns 0 on success. |
|
4147 | 4147 | """ |
|
4148 | 4148 | |
|
4149 | 4149 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
4150 | 4150 | |
|
4151 | 4151 | if file_: |
|
4152 | 4152 | m = scmutil.match(ctx, (file_,), opts) |
|
4153 | 4153 | if m.anypats() or len(m.files()) != 1: |
|
4154 | 4154 | raise util.Abort(_('can only specify an explicit filename')) |
|
4155 | 4155 | file_ = m.files()[0] |
|
4156 | 4156 | filenodes = [] |
|
4157 | 4157 | for cp in ctx.parents(): |
|
4158 | 4158 | if not cp: |
|
4159 | 4159 | continue |
|
4160 | 4160 | try: |
|
4161 | 4161 | filenodes.append(cp.filenode(file_)) |
|
4162 | 4162 | except error.LookupError: |
|
4163 | 4163 | pass |
|
4164 | 4164 | if not filenodes: |
|
4165 | 4165 | raise util.Abort(_("'%s' not found in manifest!") % file_) |
|
4166 | 4166 | fl = repo.file(file_) |
|
4167 | 4167 | p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes] |
|
4168 | 4168 | else: |
|
4169 | 4169 | p = [cp.node() for cp in ctx.parents()] |
|
4170 | 4170 | |
|
4171 | 4171 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
4172 | 4172 | for n in p: |
|
4173 | 4173 | if n != nullid: |
|
4174 | 4174 | displayer.show(repo[n]) |
|
4175 | 4175 | displayer.close() |
|
4176 | 4176 | |
|
4177 | 4177 | @command('paths', [], _('[NAME]')) |
|
4178 | 4178 | def paths(ui, repo, search=None): |
|
4179 | 4179 | """show aliases for remote repositories |
|
4180 | 4180 | |
|
4181 | 4181 | Show definition of symbolic path name NAME. If no name is given, |
|
4182 | 4182 | show definition of all available names. |
|
4183 | 4183 | |
|
4184 | 4184 | Option -q/--quiet suppresses all output when searching for NAME |
|
4185 | 4185 | and shows only the path names when listing all definitions. |
|
4186 | 4186 | |
|
4187 | 4187 | Path names are defined in the [paths] section of your |
|
4188 | 4188 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
4189 | 4189 | repository, ``.hg/hgrc`` is used, too. |
|
4190 | 4190 | |
|
4191 | 4191 | The path names ``default`` and ``default-push`` have a special |
|
4192 | 4192 | meaning. When performing a push or pull operation, they are used |
|
4193 | 4193 | as fallbacks if no location is specified on the command-line. |
|
4194 | 4194 | When ``default-push`` is set, it will be used for push and |
|
4195 | 4195 | ``default`` will be used for pull; otherwise ``default`` is used |
|
4196 | 4196 | as the fallback for both. When cloning a repository, the clone |
|
4197 | 4197 | source is written as ``default`` in ``.hg/hgrc``. Note that |
|
4198 | 4198 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
4199 | 4199 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` and |
|
4200 | 4200 | :hg:`bundle`) operations. |
|
4201 | 4201 | |
|
4202 | 4202 | See :hg:`help urls` for more information. |
|
4203 | 4203 | |
|
4204 | 4204 | Returns 0 on success. |
|
4205 | 4205 | """ |
|
4206 | 4206 | if search: |
|
4207 | 4207 | for name, path in ui.configitems("paths"): |
|
4208 | 4208 | if name == search: |
|
4209 | 4209 | ui.status("%s\n" % util.hidepassword(path)) |
|
4210 | 4210 | return |
|
4211 | 4211 | if not ui.quiet: |
|
4212 | 4212 | ui.warn(_("not found!\n")) |
|
4213 | 4213 | return 1 |
|
4214 | 4214 | else: |
|
4215 | 4215 | for name, path in ui.configitems("paths"): |
|
4216 | 4216 | if ui.quiet: |
|
4217 | 4217 | ui.write("%s\n" % name) |
|
4218 | 4218 | else: |
|
4219 | 4219 | ui.write("%s = %s\n" % (name, util.hidepassword(path))) |
|
4220 | 4220 | |
|
4221 | 4221 | @command('^phase', |
|
4222 | 4222 | [('p', 'public', False, _('set changeset phase to public')), |
|
4223 | 4223 | ('d', 'draft', False, _('set changeset phase to draft')), |
|
4224 | 4224 | ('s', 'secret', False, _('set changeset phase to secret')), |
|
4225 | 4225 | ('f', 'force', False, _('allow to move boundary backward')), |
|
4226 | 4226 | ('r', 'rev', [], _('target revision'), _('REV')), |
|
4227 | 4227 | ], |
|
4228 | 4228 | _('[-p|-d|-s] [-f] [-r] REV...')) |
|
4229 | 4229 | def phase(ui, repo, *revs, **opts): |
|
4230 | 4230 | """set or show the current phase name |
|
4231 | 4231 | |
|
4232 | 4232 | With no argument, show the phase name of specified revisions. |
|
4233 | 4233 | |
|
4234 | 4234 | With one of -p/--public, -d/--draft or -s/--secret, change the |
|
4235 | 4235 | phase value of the specified revisions. |
|
4236 | 4236 | |
|
4237 | 4237 | Unless -f/--force is specified, :hg:`phase` won't move changeset from a |
|
4238 | 4238 | lower phase to an higher phase. Phases are ordered as follows:: |
|
4239 | 4239 | |
|
4240 | 4240 | public < draft < secret |
|
4241 | 4241 | |
|
4242 | 4242 | Return 0 on success, 1 if no phases were changed or some could not |
|
4243 | 4243 | be changed. |
|
4244 | 4244 | """ |
|
4245 | 4245 | # search for a unique phase argument |
|
4246 | 4246 | targetphase = None |
|
4247 | 4247 | for idx, name in enumerate(phases.phasenames): |
|
4248 | 4248 | if opts[name]: |
|
4249 | 4249 | if targetphase is not None: |
|
4250 | 4250 | raise util.Abort(_('only one phase can be specified')) |
|
4251 | 4251 | targetphase = idx |
|
4252 | 4252 | |
|
4253 | 4253 | # look for specified revision |
|
4254 | 4254 | revs = list(revs) |
|
4255 | 4255 | revs.extend(opts['rev']) |
|
4256 | 4256 | if not revs: |
|
4257 | 4257 | raise util.Abort(_('no revisions specified')) |
|
4258 | 4258 | |
|
4259 | 4259 | revs = scmutil.revrange(repo, revs) |
|
4260 | 4260 | |
|
4261 | 4261 | lock = None |
|
4262 | 4262 | ret = 0 |
|
4263 | 4263 | if targetphase is None: |
|
4264 | 4264 | # display |
|
4265 | 4265 | for r in revs: |
|
4266 | 4266 | ctx = repo[r] |
|
4267 | 4267 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) |
|
4268 | 4268 | else: |
|
4269 | 4269 | lock = repo.lock() |
|
4270 | 4270 | try: |
|
4271 | 4271 | # set phase |
|
4272 | 4272 | nodes = [ctx.node() for ctx in repo.set('%ld', revs)] |
|
4273 | 4273 | if not nodes: |
|
4274 | 4274 | raise util.Abort(_('empty revision set')) |
|
4275 | 4275 | olddata = repo._phaserev[:] |
|
4276 | 4276 | phases.advanceboundary(repo, targetphase, nodes) |
|
4277 | 4277 | if opts['force']: |
|
4278 | 4278 | phases.retractboundary(repo, targetphase, nodes) |
|
4279 | 4279 | finally: |
|
4280 | 4280 | lock.release() |
|
4281 | 4281 | if olddata is not None: |
|
4282 | 4282 | changes = 0 |
|
4283 | 4283 | newdata = repo._phaserev |
|
4284 | 4284 | changes = sum(o != newdata[i] for i, o in enumerate(olddata)) |
|
4285 | 4285 | rejected = [n for n in nodes |
|
4286 | 4286 | if newdata[repo[n].rev()] < targetphase] |
|
4287 | 4287 | if rejected: |
|
4288 | 4288 | ui.warn(_('cannot move %i changesets to a more permissive ' |
|
4289 | 4289 | 'phase, use --force\n') % len(rejected)) |
|
4290 | 4290 | ret = 1 |
|
4291 | 4291 | if changes: |
|
4292 | 4292 | msg = _('phase changed for %i changesets\n') % changes |
|
4293 | 4293 | if ret: |
|
4294 | 4294 | ui.status(msg) |
|
4295 | 4295 | else: |
|
4296 | 4296 | ui.note(msg) |
|
4297 | 4297 | else: |
|
4298 | 4298 | ui.warn(_('no phases changed\n')) |
|
4299 | 4299 | ret = 1 |
|
4300 | 4300 | return ret |
|
4301 | 4301 | |
|
4302 | 4302 | def postincoming(ui, repo, modheads, optupdate, checkout): |
|
4303 | 4303 | if modheads == 0: |
|
4304 | 4304 | return |
|
4305 | 4305 | if optupdate: |
|
4306 | 4306 | movemarkfrom = repo['.'].node() |
|
4307 | 4307 | try: |
|
4308 | 4308 | ret = hg.update(repo, checkout) |
|
4309 | 4309 | except util.Abort, inst: |
|
4310 | 4310 | ui.warn(_("not updating: %s\n") % str(inst)) |
|
4311 | 4311 | return 0 |
|
4312 | 4312 | if not ret and not checkout: |
|
4313 | 4313 | if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
|
4314 | 4314 | ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent) |
|
4315 | 4315 | return ret |
|
4316 | 4316 | if modheads > 1: |
|
4317 | 4317 | currentbranchheads = len(repo.branchheads()) |
|
4318 | 4318 | if currentbranchheads == modheads: |
|
4319 | 4319 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
4320 | 4320 | elif currentbranchheads > 1: |
|
4321 | 4321 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to merge)\n")) |
|
4322 | 4322 | else: |
|
4323 | 4323 | ui.status(_("(run 'hg heads' to see heads)\n")) |
|
4324 | 4324 | else: |
|
4325 | 4325 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
4326 | 4326 | |
|
4327 | 4327 | @command('^pull', |
|
4328 | 4328 | [('u', 'update', None, |
|
4329 | 4329 | _('update to new branch head if changesets were pulled')), |
|
4330 | 4330 | ('f', 'force', None, _('run even when remote repository is unrelated')), |
|
4331 | 4331 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
4332 | 4332 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), |
|
4333 | 4333 | ('b', 'branch', [], _('a specific branch you would like to pull'), |
|
4334 | 4334 | _('BRANCH')), |
|
4335 | 4335 | ] + remoteopts, |
|
4336 | 4336 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
|
4337 | 4337 | def pull(ui, repo, source="default", **opts): |
|
4338 | 4338 | """pull changes from the specified source |
|
4339 | 4339 | |
|
4340 | 4340 | Pull changes from a remote repository to a local one. |
|
4341 | 4341 | |
|
4342 | 4342 | This finds all changes from the repository at the specified path |
|
4343 | 4343 | or URL and adds them to a local repository (the current one unless |
|
4344 | 4344 | -R is specified). By default, this does not update the copy of the |
|
4345 | 4345 | project in the working directory. |
|
4346 | 4346 | |
|
4347 | 4347 | Use :hg:`incoming` if you want to see what would have been added |
|
4348 | 4348 | by a pull at the time you issued this command. If you then decide |
|
4349 | 4349 | to add those changes to the repository, you should use :hg:`pull |
|
4350 | 4350 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
4351 | 4351 | |
|
4352 | 4352 | If SOURCE is omitted, the 'default' path will be used. |
|
4353 | 4353 | See :hg:`help urls` for more information. |
|
4354 | 4354 | |
|
4355 | 4355 | Returns 0 on success, 1 if an update had unresolved files. |
|
4356 | 4356 | """ |
|
4357 | 4357 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
|
4358 | 4358 | other = hg.peer(repo, opts, source) |
|
4359 | 4359 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) |
|
4360 | 4360 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) |
|
4361 | 4361 | |
|
4362 | 4362 | if opts.get('bookmark'): |
|
4363 | 4363 | if not revs: |
|
4364 | 4364 | revs = [] |
|
4365 | 4365 | rb = other.listkeys('bookmarks') |
|
4366 | 4366 | for b in opts['bookmark']: |
|
4367 | 4367 | if b not in rb: |
|
4368 | 4368 | raise util.Abort(_('remote bookmark %s not found!') % b) |
|
4369 | 4369 | revs.append(rb[b]) |
|
4370 | 4370 | |
|
4371 | 4371 | if revs: |
|
4372 | 4372 | try: |
|
4373 | 4373 | revs = [other.lookup(rev) for rev in revs] |
|
4374 | 4374 | except error.CapabilityError: |
|
4375 | 4375 | err = _("other repository doesn't support revision lookup, " |
|
4376 | 4376 | "so a rev cannot be specified.") |
|
4377 | 4377 | raise util.Abort(err) |
|
4378 | 4378 | |
|
4379 | 4379 | modheads = repo.pull(other, heads=revs, force=opts.get('force')) |
|
4380 | 4380 | bookmarks.updatefromremote(ui, repo, other, source) |
|
4381 | 4381 | if checkout: |
|
4382 | 4382 | checkout = str(repo.changelog.rev(other.lookup(checkout))) |
|
4383 | 4383 | repo._subtoppath = source |
|
4384 | 4384 | try: |
|
4385 | 4385 | ret = postincoming(ui, repo, modheads, opts.get('update'), checkout) |
|
4386 | 4386 | |
|
4387 | 4387 | finally: |
|
4388 | 4388 | del repo._subtoppath |
|
4389 | 4389 | |
|
4390 | 4390 | # update specified bookmarks |
|
4391 | 4391 | if opts.get('bookmark'): |
|
4392 | 4392 | for b in opts['bookmark']: |
|
4393 | 4393 | # explicit pull overrides local bookmark if any |
|
4394 | 4394 | ui.status(_("importing bookmark %s\n") % b) |
|
4395 | 4395 | repo._bookmarks[b] = repo[rb[b]].node() |
|
4396 | 4396 | bookmarks.write(repo) |
|
4397 | 4397 | |
|
4398 | 4398 | return ret |
|
4399 | 4399 | |
|
4400 | 4400 | @command('^push', |
|
4401 | 4401 | [('f', 'force', None, _('force push')), |
|
4402 | 4402 | ('r', 'rev', [], |
|
4403 | 4403 | _('a changeset intended to be included in the destination'), |
|
4404 | 4404 | _('REV')), |
|
4405 | 4405 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), |
|
4406 | 4406 | ('b', 'branch', [], |
|
4407 | 4407 | _('a specific branch you would like to push'), _('BRANCH')), |
|
4408 | 4408 | ('', 'new-branch', False, _('allow pushing a new branch')), |
|
4409 | 4409 | ] + remoteopts, |
|
4410 | 4410 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) |
|
4411 | 4411 | def push(ui, repo, dest=None, **opts): |
|
4412 | 4412 | """push changes to the specified destination |
|
4413 | 4413 | |
|
4414 | 4414 | Push changesets from the local repository to the specified |
|
4415 | 4415 | destination. |
|
4416 | 4416 | |
|
4417 | 4417 | This operation is symmetrical to pull: it is identical to a pull |
|
4418 | 4418 | in the destination repository from the current one. |
|
4419 | 4419 | |
|
4420 | 4420 | By default, push will not allow creation of new heads at the |
|
4421 | 4421 | destination, since multiple heads would make it unclear which head |
|
4422 | 4422 | to use. In this situation, it is recommended to pull and merge |
|
4423 | 4423 | before pushing. |
|
4424 | 4424 | |
|
4425 | 4425 | Use --new-branch if you want to allow push to create a new named |
|
4426 | 4426 | branch that is not present at the destination. This allows you to |
|
4427 | 4427 | only create a new branch without forcing other changes. |
|
4428 | 4428 | |
|
4429 | 4429 | Use -f/--force to override the default behavior and push all |
|
4430 | 4430 | changesets on all branches. |
|
4431 | 4431 | |
|
4432 | 4432 | If -r/--rev is used, the specified revision and all its ancestors |
|
4433 | 4433 | will be pushed to the remote repository. |
|
4434 | 4434 | |
|
4435 | 4435 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
4436 | 4436 | URLs. If DESTINATION is omitted, a default path will be used. |
|
4437 | 4437 | |
|
4438 | 4438 | Returns 0 if push was successful, 1 if nothing to push. |
|
4439 | 4439 | """ |
|
4440 | 4440 | |
|
4441 | 4441 | if opts.get('bookmark'): |
|
4442 | 4442 | for b in opts['bookmark']: |
|
4443 | 4443 | # translate -B options to -r so changesets get pushed |
|
4444 | 4444 | if b in repo._bookmarks: |
|
4445 | 4445 | opts.setdefault('rev', []).append(b) |
|
4446 | 4446 | else: |
|
4447 | 4447 | # if we try to push a deleted bookmark, translate it to null |
|
4448 | 4448 | # this lets simultaneous -r, -b options continue working |
|
4449 | 4449 | opts.setdefault('rev', []).append("null") |
|
4450 | 4450 | |
|
4451 | 4451 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
4452 | 4452 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
4453 | 4453 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) |
|
4454 | 4454 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
4455 | 4455 | other = hg.peer(repo, opts, dest) |
|
4456 | 4456 | if revs: |
|
4457 | 4457 | revs = [repo.lookup(rev) for rev in revs] |
|
4458 | 4458 | |
|
4459 | 4459 | repo._subtoppath = dest |
|
4460 | 4460 | try: |
|
4461 | 4461 | # push subrepos depth-first for coherent ordering |
|
4462 | 4462 | c = repo[''] |
|
4463 | 4463 | subs = c.substate # only repos that are committed |
|
4464 | 4464 | for s in sorted(subs): |
|
4465 | 4465 | if c.sub(s).push(opts) == 0: |
|
4466 | 4466 | return False |
|
4467 | 4467 | finally: |
|
4468 | 4468 | del repo._subtoppath |
|
4469 | 4469 | result = repo.push(other, opts.get('force'), revs=revs, |
|
4470 | 4470 | newbranch=opts.get('new_branch')) |
|
4471 | 4471 | |
|
4472 | 4472 | result = not result |
|
4473 | 4473 | |
|
4474 | 4474 | if opts.get('bookmark'): |
|
4475 | 4475 | rb = other.listkeys('bookmarks') |
|
4476 | 4476 | for b in opts['bookmark']: |
|
4477 | 4477 | # explicit push overrides remote bookmark if any |
|
4478 | 4478 | if b in repo._bookmarks: |
|
4479 | 4479 | ui.status(_("exporting bookmark %s\n") % b) |
|
4480 | 4480 | new = repo[b].hex() |
|
4481 | 4481 | elif b in rb: |
|
4482 | 4482 | ui.status(_("deleting remote bookmark %s\n") % b) |
|
4483 | 4483 | new = '' # delete |
|
4484 | 4484 | else: |
|
4485 | 4485 | ui.warn(_('bookmark %s does not exist on the local ' |
|
4486 | 4486 | 'or remote repository!\n') % b) |
|
4487 | 4487 | return 2 |
|
4488 | 4488 | old = rb.get(b, '') |
|
4489 | 4489 | r = other.pushkey('bookmarks', b, old, new) |
|
4490 | 4490 | if not r: |
|
4491 | 4491 | ui.warn(_('updating bookmark %s failed!\n') % b) |
|
4492 | 4492 | if not result: |
|
4493 | 4493 | result = 2 |
|
4494 | 4494 | |
|
4495 | 4495 | return result |
|
4496 | 4496 | |
|
4497 | 4497 | @command('recover', []) |
|
4498 | 4498 | def recover(ui, repo): |
|
4499 | 4499 | """roll back an interrupted transaction |
|
4500 | 4500 | |
|
4501 | 4501 | Recover from an interrupted commit or pull. |
|
4502 | 4502 | |
|
4503 | 4503 | This command tries to fix the repository status after an |
|
4504 | 4504 | interrupted operation. It should only be necessary when Mercurial |
|
4505 | 4505 | suggests it. |
|
4506 | 4506 | |
|
4507 | 4507 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
4508 | 4508 | """ |
|
4509 | 4509 | if repo.recover(): |
|
4510 | 4510 | return hg.verify(repo) |
|
4511 | 4511 | return 1 |
|
4512 | 4512 | |
|
4513 | 4513 | @command('^remove|rm', |
|
4514 | 4514 | [('A', 'after', None, _('record delete for missing files')), |
|
4515 | 4515 | ('f', 'force', None, |
|
4516 | 4516 | _('remove (and delete) file even if added or modified')), |
|
4517 | 4517 | ] + walkopts, |
|
4518 | 4518 | _('[OPTION]... FILE...')) |
|
4519 | 4519 | def remove(ui, repo, *pats, **opts): |
|
4520 | 4520 | """remove the specified files on the next commit |
|
4521 | 4521 | |
|
4522 | 4522 | Schedule the indicated files for removal from the current branch. |
|
4523 | 4523 | |
|
4524 | 4524 | This command schedules the files to be removed at the next commit. |
|
4525 | 4525 | To undo a remove before that, see :hg:`revert`. To undo added |
|
4526 | 4526 | files, see :hg:`forget`. |
|
4527 | 4527 | |
|
4528 | 4528 | .. container:: verbose |
|
4529 | 4529 | |
|
4530 | 4530 | -A/--after can be used to remove only files that have already |
|
4531 | 4531 | been deleted, -f/--force can be used to force deletion, and -Af |
|
4532 | 4532 | can be used to remove files from the next revision without |
|
4533 | 4533 | deleting them from the working directory. |
|
4534 | 4534 | |
|
4535 | 4535 | The following table details the behavior of remove for different |
|
4536 | 4536 | file states (columns) and option combinations (rows). The file |
|
4537 | 4537 | states are Added [A], Clean [C], Modified [M] and Missing [!] |
|
4538 | 4538 | (as reported by :hg:`status`). The actions are Warn, Remove |
|
4539 | 4539 | (from branch) and Delete (from disk): |
|
4540 | 4540 | |
|
4541 | 4541 | ======= == == == == |
|
4542 | 4542 | A C M ! |
|
4543 | 4543 | ======= == == == == |
|
4544 | 4544 | none W RD W R |
|
4545 | 4545 | -f R RD RD R |
|
4546 | 4546 | -A W W W R |
|
4547 | 4547 | -Af R R R R |
|
4548 | 4548 | ======= == == == == |
|
4549 | 4549 | |
|
4550 | 4550 | Note that remove never deletes files in Added [A] state from the |
|
4551 | 4551 | working directory, not even if option --force is specified. |
|
4552 | 4552 | |
|
4553 | 4553 | Returns 0 on success, 1 if any warnings encountered. |
|
4554 | 4554 | """ |
|
4555 | 4555 | |
|
4556 | 4556 | ret = 0 |
|
4557 | 4557 | after, force = opts.get('after'), opts.get('force') |
|
4558 | 4558 | if not pats and not after: |
|
4559 | 4559 | raise util.Abort(_('no files specified')) |
|
4560 | 4560 | |
|
4561 | 4561 | m = scmutil.match(repo[None], pats, opts) |
|
4562 | 4562 | s = repo.status(match=m, clean=True) |
|
4563 | 4563 | modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
|
4564 | 4564 | |
|
4565 | 4565 | for f in m.files(): |
|
4566 | 4566 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
|
4567 | 4567 | if os.path.exists(m.rel(f)): |
|
4568 | 4568 | ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) |
|
4569 | 4569 | ret = 1 |
|
4570 | 4570 | |
|
4571 | 4571 | if force: |
|
4572 | 4572 | list = modified + deleted + clean + added |
|
4573 | 4573 | elif after: |
|
4574 | 4574 | list = deleted |
|
4575 | 4575 | for f in modified + added + clean: |
|
4576 | 4576 | ui.warn(_('not removing %s: file still exists (use -f' |
|
4577 | 4577 | ' to force removal)\n') % m.rel(f)) |
|
4578 | 4578 | ret = 1 |
|
4579 | 4579 | else: |
|
4580 | 4580 | list = deleted + clean |
|
4581 | 4581 | for f in modified: |
|
4582 | 4582 | ui.warn(_('not removing %s: file is modified (use -f' |
|
4583 | 4583 | ' to force removal)\n') % m.rel(f)) |
|
4584 | 4584 | ret = 1 |
|
4585 | 4585 | for f in added: |
|
4586 | 4586 | ui.warn(_('not removing %s: file has been marked for add' |
|
4587 | 4587 | ' (use forget to undo)\n') % m.rel(f)) |
|
4588 | 4588 | ret = 1 |
|
4589 | 4589 | |
|
4590 | 4590 | for f in sorted(list): |
|
4591 | 4591 | if ui.verbose or not m.exact(f): |
|
4592 | 4592 | ui.status(_('removing %s\n') % m.rel(f)) |
|
4593 | 4593 | |
|
4594 | 4594 | wlock = repo.wlock() |
|
4595 | 4595 | try: |
|
4596 | 4596 | if not after: |
|
4597 | 4597 | for f in list: |
|
4598 | 4598 | if f in added: |
|
4599 | 4599 | continue # we never unlink added files on remove |
|
4600 | 4600 | try: |
|
4601 | 4601 | util.unlinkpath(repo.wjoin(f)) |
|
4602 | 4602 | except OSError, inst: |
|
4603 | 4603 | if inst.errno != errno.ENOENT: |
|
4604 | 4604 | raise |
|
4605 | 4605 | repo[None].forget(list) |
|
4606 | 4606 | finally: |
|
4607 | 4607 | wlock.release() |
|
4608 | 4608 | |
|
4609 | 4609 | return ret |
|
4610 | 4610 | |
|
4611 | 4611 | @command('rename|move|mv', |
|
4612 | 4612 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
4613 | 4613 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
4614 | 4614 | ] + walkopts + dryrunopts, |
|
4615 | 4615 | _('[OPTION]... SOURCE... DEST')) |
|
4616 | 4616 | def rename(ui, repo, *pats, **opts): |
|
4617 | 4617 | """rename files; equivalent of copy + remove |
|
4618 | 4618 | |
|
4619 | 4619 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
4620 | 4620 | is a directory, copies are put in that directory. If dest is a |
|
4621 | 4621 | file, there can only be one source. |
|
4622 | 4622 | |
|
4623 | 4623 | By default, this command copies the contents of files as they |
|
4624 | 4624 | exist in the working directory. If invoked with -A/--after, the |
|
4625 | 4625 | operation is recorded, but no copying is performed. |
|
4626 | 4626 | |
|
4627 | 4627 | This command takes effect at the next commit. To undo a rename |
|
4628 | 4628 | before that, see :hg:`revert`. |
|
4629 | 4629 | |
|
4630 | 4630 | Returns 0 on success, 1 if errors are encountered. |
|
4631 | 4631 | """ |
|
4632 | 4632 | wlock = repo.wlock(False) |
|
4633 | 4633 | try: |
|
4634 | 4634 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
4635 | 4635 | finally: |
|
4636 | 4636 | wlock.release() |
|
4637 | 4637 | |
|
4638 | 4638 | @command('resolve', |
|
4639 | 4639 | [('a', 'all', None, _('select all unresolved files')), |
|
4640 | 4640 | ('l', 'list', None, _('list state of files needing merge')), |
|
4641 | 4641 | ('m', 'mark', None, _('mark files as resolved')), |
|
4642 | 4642 | ('u', 'unmark', None, _('mark files as unresolved')), |
|
4643 | 4643 | ('n', 'no-status', None, _('hide status prefix'))] |
|
4644 | 4644 | + mergetoolopts + walkopts, |
|
4645 | 4645 | _('[OPTION]... [FILE]...')) |
|
4646 | 4646 | def resolve(ui, repo, *pats, **opts): |
|
4647 | 4647 | """redo merges or set/view the merge status of files |
|
4648 | 4648 | |
|
4649 | 4649 | Merges with unresolved conflicts are often the result of |
|
4650 | 4650 | non-interactive merging using the ``internal:merge`` configuration |
|
4651 | 4651 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
4652 | 4652 | command is used to manage the files involved in a merge, after |
|
4653 | 4653 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
4654 | 4654 | working directory must have two parents). See :hg:`help |
|
4655 | 4655 | merge-tools` for information on configuring merge tools. |
|
4656 | 4656 | |
|
4657 | 4657 | The resolve command can be used in the following ways: |
|
4658 | 4658 | |
|
4659 | 4659 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified |
|
4660 | 4660 | files, discarding any previous merge attempts. Re-merging is not |
|
4661 | 4661 | performed for files already marked as resolved. Use ``--all/-a`` |
|
4662 | 4662 | to select all unresolved files. ``--tool`` can be used to specify |
|
4663 | 4663 | the merge tool used for the given files. It overrides the HGMERGE |
|
4664 | 4664 | environment variable and your configuration files. Previous file |
|
4665 | 4665 | contents are saved with a ``.orig`` suffix. |
|
4666 | 4666 | |
|
4667 | 4667 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
4668 | 4668 | (e.g. after having manually fixed-up the files). The default is |
|
4669 | 4669 | to mark all unresolved files. |
|
4670 | 4670 | |
|
4671 | 4671 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
4672 | 4672 | default is to mark all resolved files. |
|
4673 | 4673 | |
|
4674 | 4674 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
4675 | 4675 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
4676 | 4676 | |
|
4677 | 4677 | Note that Mercurial will not let you commit files with unresolved |
|
4678 | 4678 | merge conflicts. You must use :hg:`resolve -m ...` before you can |
|
4679 | 4679 | commit after a conflicting merge. |
|
4680 | 4680 | |
|
4681 | 4681 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
4682 | 4682 | """ |
|
4683 | 4683 | |
|
4684 | 4684 | all, mark, unmark, show, nostatus = \ |
|
4685 | 4685 | [opts.get(o) for o in 'all mark unmark list no_status'.split()] |
|
4686 | 4686 | |
|
4687 | 4687 | if (show and (mark or unmark)) or (mark and unmark): |
|
4688 | 4688 | raise util.Abort(_("too many options specified")) |
|
4689 | 4689 | if pats and all: |
|
4690 | 4690 | raise util.Abort(_("can't specify --all and patterns")) |
|
4691 | 4691 | if not (all or pats or show or mark or unmark): |
|
4692 | 4692 | raise util.Abort(_('no files or directories specified; ' |
|
4693 | 4693 | 'use --all to remerge all files')) |
|
4694 | 4694 | |
|
4695 | 4695 | ms = mergemod.mergestate(repo) |
|
4696 | 4696 | m = scmutil.match(repo[None], pats, opts) |
|
4697 | 4697 | ret = 0 |
|
4698 | 4698 | |
|
4699 | 4699 | for f in ms: |
|
4700 | 4700 | if m(f): |
|
4701 | 4701 | if show: |
|
4702 | 4702 | if nostatus: |
|
4703 | 4703 | ui.write("%s\n" % f) |
|
4704 | 4704 | else: |
|
4705 | 4705 | ui.write("%s %s\n" % (ms[f].upper(), f), |
|
4706 | 4706 | label='resolve.' + |
|
4707 | 4707 | {'u': 'unresolved', 'r': 'resolved'}[ms[f]]) |
|
4708 | 4708 | elif mark: |
|
4709 | 4709 | ms.mark(f, "r") |
|
4710 | 4710 | elif unmark: |
|
4711 | 4711 | ms.mark(f, "u") |
|
4712 | 4712 | else: |
|
4713 | 4713 | wctx = repo[None] |
|
4714 | 4714 | mctx = wctx.parents()[-1] |
|
4715 | 4715 | |
|
4716 | 4716 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
4717 | 4717 | a = repo.wjoin(f) |
|
4718 | 4718 | util.copyfile(a, a + ".resolve") |
|
4719 | 4719 | |
|
4720 | 4720 | try: |
|
4721 | 4721 | # resolve file |
|
4722 | 4722 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
4723 | 4723 | if ms.resolve(f, wctx, mctx): |
|
4724 | 4724 | ret = 1 |
|
4725 | 4725 | finally: |
|
4726 | 4726 | ui.setconfig('ui', 'forcemerge', '') |
|
4727 | 4727 | |
|
4728 | 4728 | # replace filemerge's .orig file with our resolve file |
|
4729 | 4729 | util.rename(a + ".resolve", a + ".orig") |
|
4730 | 4730 | |
|
4731 | 4731 | ms.commit() |
|
4732 | 4732 | return ret |
|
4733 | 4733 | |
|
4734 | 4734 | @command('revert', |
|
4735 | 4735 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
4736 | 4736 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
4737 | 4737 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), |
|
4738 | 4738 | ('C', 'no-backup', None, _('do not save backup copies of files')), |
|
4739 | 4739 | ] + walkopts + dryrunopts, |
|
4740 | 4740 | _('[OPTION]... [-r REV] [NAME]...')) |
|
4741 | 4741 | def revert(ui, repo, *pats, **opts): |
|
4742 | 4742 | """restore files to their checkout state |
|
4743 | 4743 | |
|
4744 | 4744 | .. note:: |
|
4745 | 4745 | To check out earlier revisions, you should use :hg:`update REV`. |
|
4746 | 4746 | To cancel a merge (and lose your changes), use :hg:`update --clean .`. |
|
4747 | 4747 | |
|
4748 | 4748 | With no revision specified, revert the specified files or directories |
|
4749 | 4749 | to the contents they had in the parent of the working directory. |
|
4750 | 4750 | This restores the contents of files to an unmodified |
|
4751 | 4751 | state and unschedules adds, removes, copies, and renames. If the |
|
4752 | 4752 | working directory has two parents, you must explicitly specify a |
|
4753 | 4753 | revision. |
|
4754 | 4754 | |
|
4755 | 4755 | Using the -r/--rev or -d/--date options, revert the given files or |
|
4756 | 4756 | directories to their states as of a specific revision. Because |
|
4757 | 4757 | revert does not change the working directory parents, this will |
|
4758 | 4758 | cause these files to appear modified. This can be helpful to "back |
|
4759 | 4759 | out" some or all of an earlier change. See :hg:`backout` for a |
|
4760 | 4760 | related method. |
|
4761 | 4761 | |
|
4762 | 4762 | Modified files are saved with a .orig suffix before reverting. |
|
4763 | 4763 | To disable these backups, use --no-backup. |
|
4764 | 4764 | |
|
4765 | 4765 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4766 | 4766 | |
|
4767 | 4767 | Returns 0 on success. |
|
4768 | 4768 | """ |
|
4769 | 4769 | |
|
4770 | 4770 | if opts.get("date"): |
|
4771 | 4771 | if opts.get("rev"): |
|
4772 | 4772 | raise util.Abort(_("you can't specify a revision and a date")) |
|
4773 | 4773 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
4774 | 4774 | |
|
4775 | 4775 | parent, p2 = repo.dirstate.parents() |
|
4776 | 4776 | if not opts.get('rev') and p2 != nullid: |
|
4777 | 4777 | # revert after merge is a trap for new users (issue2915) |
|
4778 | 4778 | raise util.Abort(_('uncommitted merge with no revision specified'), |
|
4779 | 4779 | hint=_('use "hg update" or see "hg help revert"')) |
|
4780 | 4780 | |
|
4781 | 4781 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
4782 | 4782 | |
|
4783 | 4783 | if not pats and not opts.get('all'): |
|
4784 | 4784 | msg = _("no files or directories specified") |
|
4785 | 4785 | if p2 != nullid: |
|
4786 | 4786 | hint = _("uncommitted merge, use --all to discard all changes," |
|
4787 | 4787 | " or 'hg update -C .' to abort the merge") |
|
4788 | 4788 | raise util.Abort(msg, hint=hint) |
|
4789 | 4789 | dirty = util.any(repo.status()) |
|
4790 | 4790 | node = ctx.node() |
|
4791 | 4791 | if node != parent: |
|
4792 | 4792 | if dirty: |
|
4793 | 4793 | hint = _("uncommitted changes, use --all to discard all" |
|
4794 | 4794 | " changes, or 'hg update %s' to update") % ctx.rev() |
|
4795 | 4795 | else: |
|
4796 | 4796 | hint = _("use --all to revert all files," |
|
4797 | 4797 | " or 'hg update %s' to update") % ctx.rev() |
|
4798 | 4798 | elif dirty: |
|
4799 | 4799 | hint = _("uncommitted changes, use --all to discard all changes") |
|
4800 | 4800 | else: |
|
4801 | 4801 | hint = _("use --all to revert all files") |
|
4802 | 4802 | raise util.Abort(msg, hint=hint) |
|
4803 | 4803 | |
|
4804 | 4804 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) |
|
4805 | 4805 | |
|
4806 | 4806 | @command('rollback', dryrunopts + |
|
4807 | 4807 | [('f', 'force', False, _('ignore safety measures'))]) |
|
4808 | 4808 | def rollback(ui, repo, **opts): |
|
4809 | 4809 | """roll back the last transaction (dangerous) |
|
4810 | 4810 | |
|
4811 | 4811 | This command should be used with care. There is only one level of |
|
4812 | 4812 | rollback, and there is no way to undo a rollback. It will also |
|
4813 | 4813 | restore the dirstate at the time of the last transaction, losing |
|
4814 | 4814 | any dirstate changes since that time. This command does not alter |
|
4815 | 4815 | the working directory. |
|
4816 | 4816 | |
|
4817 | 4817 | Transactions are used to encapsulate the effects of all commands |
|
4818 | 4818 | that create new changesets or propagate existing changesets into a |
|
4819 | 4819 | repository. For example, the following commands are transactional, |
|
4820 | 4820 | and their effects can be rolled back: |
|
4821 | 4821 | |
|
4822 | 4822 | - commit |
|
4823 | 4823 | - import |
|
4824 | 4824 | - pull |
|
4825 | 4825 | - push (with this repository as the destination) |
|
4826 | 4826 | - unbundle |
|
4827 | 4827 | |
|
4828 | 4828 | To avoid permanent data loss, rollback will refuse to rollback a |
|
4829 | 4829 | commit transaction if it isn't checked out. Use --force to |
|
4830 | 4830 | override this protection. |
|
4831 | 4831 | |
|
4832 | 4832 | This command is not intended for use on public repositories. Once |
|
4833 | 4833 | changes are visible for pull by other users, rolling a transaction |
|
4834 | 4834 | back locally is ineffective (someone else may already have pulled |
|
4835 | 4835 | the changes). Furthermore, a race is possible with readers of the |
|
4836 | 4836 | repository; for example an in-progress pull from the repository |
|
4837 | 4837 | may fail if a rollback is performed. |
|
4838 | 4838 | |
|
4839 | 4839 | Returns 0 on success, 1 if no rollback data is available. |
|
4840 | 4840 | """ |
|
4841 | 4841 | return repo.rollback(dryrun=opts.get('dry_run'), |
|
4842 | 4842 | force=opts.get('force')) |
|
4843 | 4843 | |
|
4844 | 4844 | @command('root', []) |
|
4845 | 4845 | def root(ui, repo): |
|
4846 | 4846 | """print the root (top) of the current working directory |
|
4847 | 4847 | |
|
4848 | 4848 | Print the root directory of the current repository. |
|
4849 | 4849 | |
|
4850 | 4850 | Returns 0 on success. |
|
4851 | 4851 | """ |
|
4852 | 4852 | ui.write(repo.root + "\n") |
|
4853 | 4853 | |
|
4854 | 4854 | @command('^serve', |
|
4855 | 4855 | [('A', 'accesslog', '', _('name of access log file to write to'), |
|
4856 | 4856 | _('FILE')), |
|
4857 | 4857 | ('d', 'daemon', None, _('run server in background')), |
|
4858 | 4858 | ('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('NUM')), |
|
4859 | 4859 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), |
|
4860 | 4860 | # use string type, then we can check if something was passed |
|
4861 | 4861 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), |
|
4862 | 4862 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), |
|
4863 | 4863 | _('ADDR')), |
|
4864 | 4864 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), |
|
4865 | 4865 | _('PREFIX')), |
|
4866 | 4866 | ('n', 'name', '', |
|
4867 | 4867 | _('name to show in web pages (default: working directory)'), _('NAME')), |
|
4868 | 4868 | ('', 'web-conf', '', |
|
4869 | 4869 | _('name of the hgweb config file (see "hg help hgweb")'), _('FILE')), |
|
4870 | 4870 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), |
|
4871 | 4871 | _('FILE')), |
|
4872 | 4872 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), |
|
4873 | 4873 | ('', 'stdio', None, _('for remote clients')), |
|
4874 | 4874 | ('', 'cmdserver', '', _('for remote clients'), _('MODE')), |
|
4875 | 4875 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), |
|
4876 | 4876 | ('', 'style', '', _('template style to use'), _('STYLE')), |
|
4877 | 4877 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
4878 | 4878 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))], |
|
4879 | 4879 | _('[OPTION]...')) |
|
4880 | 4880 | def serve(ui, repo, **opts): |
|
4881 | 4881 | """start stand-alone webserver |
|
4882 | 4882 | |
|
4883 | 4883 | Start a local HTTP repository browser and pull server. You can use |
|
4884 | 4884 | this for ad-hoc sharing and browsing of repositories. It is |
|
4885 | 4885 | recommended to use a real web server to serve a repository for |
|
4886 | 4886 | longer periods of time. |
|
4887 | 4887 | |
|
4888 | 4888 | Please note that the server does not implement access control. |
|
4889 | 4889 | This means that, by default, anybody can read from the server and |
|
4890 | 4890 | nobody can write to it by default. Set the ``web.allow_push`` |
|
4891 | 4891 | option to ``*`` to allow everybody to push to the server. You |
|
4892 | 4892 | should use a real web server if you need to authenticate users. |
|
4893 | 4893 | |
|
4894 | 4894 | By default, the server logs accesses to stdout and errors to |
|
4895 | 4895 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
4896 | 4896 | files. |
|
4897 | 4897 | |
|
4898 | 4898 | To have the server choose a free port number to listen on, specify |
|
4899 | 4899 | a port number of 0; in this case, the server will print the port |
|
4900 | 4900 | number it uses. |
|
4901 | 4901 | |
|
4902 | 4902 | Returns 0 on success. |
|
4903 | 4903 | """ |
|
4904 | 4904 | |
|
4905 | 4905 | if opts["stdio"] and opts["cmdserver"]: |
|
4906 | 4906 | raise util.Abort(_("cannot use --stdio with --cmdserver")) |
|
4907 | 4907 | |
|
4908 | 4908 | def checkrepo(): |
|
4909 | 4909 | if repo is None: |
|
4910 | 4910 | raise error.RepoError(_("There is no Mercurial repository here" |
|
4911 | 4911 | " (.hg not found)")) |
|
4912 | 4912 | |
|
4913 | 4913 | if opts["stdio"]: |
|
4914 | 4914 | checkrepo() |
|
4915 | 4915 | s = sshserver.sshserver(ui, repo) |
|
4916 | 4916 | s.serve_forever() |
|
4917 | 4917 | |
|
4918 | 4918 | if opts["cmdserver"]: |
|
4919 | 4919 | checkrepo() |
|
4920 | 4920 | s = commandserver.server(ui, repo, opts["cmdserver"]) |
|
4921 | 4921 | return s.serve() |
|
4922 | 4922 | |
|
4923 | 4923 | # this way we can check if something was given in the command-line |
|
4924 | 4924 | if opts.get('port'): |
|
4925 | 4925 | opts['port'] = util.getport(opts.get('port')) |
|
4926 | 4926 | |
|
4927 | 4927 | baseui = repo and repo.baseui or ui |
|
4928 | 4928 | optlist = ("name templates style address port prefix ipv6" |
|
4929 | 4929 | " accesslog errorlog certificate encoding") |
|
4930 | 4930 | for o in optlist.split(): |
|
4931 | 4931 | val = opts.get(o, '') |
|
4932 | 4932 | if val in (None, ''): # should check against default options instead |
|
4933 | 4933 | continue |
|
4934 | 4934 | baseui.setconfig("web", o, val) |
|
4935 | 4935 | if repo and repo.ui != baseui: |
|
4936 | 4936 | repo.ui.setconfig("web", o, val) |
|
4937 | 4937 | |
|
4938 | 4938 | o = opts.get('web_conf') or opts.get('webdir_conf') |
|
4939 | 4939 | if not o: |
|
4940 | 4940 | if not repo: |
|
4941 | 4941 | raise error.RepoError(_("There is no Mercurial repository" |
|
4942 | 4942 | " here (.hg not found)")) |
|
4943 | 4943 | o = repo.root |
|
4944 | 4944 | |
|
4945 | 4945 | app = hgweb.hgweb(o, baseui=ui) |
|
4946 | 4946 | |
|
4947 | 4947 | class service(object): |
|
4948 | 4948 | def init(self): |
|
4949 | 4949 | util.setsignalhandler() |
|
4950 | 4950 | self.httpd = hgweb.server.create_server(ui, app) |
|
4951 | 4951 | |
|
4952 | 4952 | if opts['port'] and not ui.verbose: |
|
4953 | 4953 | return |
|
4954 | 4954 | |
|
4955 | 4955 | if self.httpd.prefix: |
|
4956 | 4956 | prefix = self.httpd.prefix.strip('/') + '/' |
|
4957 | 4957 | else: |
|
4958 | 4958 | prefix = '' |
|
4959 | 4959 | |
|
4960 | 4960 | port = ':%d' % self.httpd.port |
|
4961 | 4961 | if port == ':80': |
|
4962 | 4962 | port = '' |
|
4963 | 4963 | |
|
4964 | 4964 | bindaddr = self.httpd.addr |
|
4965 | 4965 | if bindaddr == '0.0.0.0': |
|
4966 | 4966 | bindaddr = '*' |
|
4967 | 4967 | elif ':' in bindaddr: # IPv6 |
|
4968 | 4968 | bindaddr = '[%s]' % bindaddr |
|
4969 | 4969 | |
|
4970 | 4970 | fqaddr = self.httpd.fqaddr |
|
4971 | 4971 | if ':' in fqaddr: |
|
4972 | 4972 | fqaddr = '[%s]' % fqaddr |
|
4973 | 4973 | if opts['port']: |
|
4974 | 4974 | write = ui.status |
|
4975 | 4975 | else: |
|
4976 | 4976 | write = ui.write |
|
4977 | 4977 | write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % |
|
4978 | 4978 | (fqaddr, port, prefix, bindaddr, self.httpd.port)) |
|
4979 | 4979 | |
|
4980 | 4980 | def run(self): |
|
4981 | 4981 | self.httpd.serve_forever() |
|
4982 | 4982 | |
|
4983 | 4983 | service = service() |
|
4984 | 4984 | |
|
4985 | 4985 | cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
4986 | 4986 | |
|
4987 | 4987 | @command('showconfig|debugconfig', |
|
4988 | 4988 | [('u', 'untrusted', None, _('show untrusted configuration options'))], |
|
4989 | 4989 | _('[-u] [NAME]...')) |
|
4990 | 4990 | def showconfig(ui, repo, *values, **opts): |
|
4991 | 4991 | """show combined config settings from all hgrc files |
|
4992 | 4992 | |
|
4993 | 4993 | With no arguments, print names and values of all config items. |
|
4994 | 4994 | |
|
4995 | 4995 | With one argument of the form section.name, print just the value |
|
4996 | 4996 | of that config item. |
|
4997 | 4997 | |
|
4998 | 4998 | With multiple arguments, print names and values of all config |
|
4999 | 4999 | items with matching section names. |
|
5000 | 5000 | |
|
5001 | 5001 | With --debug, the source (filename and line number) is printed |
|
5002 | 5002 | for each config item. |
|
5003 | 5003 | |
|
5004 | 5004 | Returns 0 on success. |
|
5005 | 5005 | """ |
|
5006 | 5006 | |
|
5007 | 5007 | for f in scmutil.rcpath(): |
|
5008 | 5008 | ui.debug('read config from: %s\n' % f) |
|
5009 | 5009 | untrusted = bool(opts.get('untrusted')) |
|
5010 | 5010 | if values: |
|
5011 | 5011 | sections = [v for v in values if '.' not in v] |
|
5012 | 5012 | items = [v for v in values if '.' in v] |
|
5013 | 5013 | if len(items) > 1 or items and sections: |
|
5014 | 5014 | raise util.Abort(_('only one config item permitted')) |
|
5015 | 5015 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
5016 | 5016 | value = str(value).replace('\n', '\\n') |
|
5017 | 5017 | sectname = section + '.' + name |
|
5018 | 5018 | if values: |
|
5019 | 5019 | for v in values: |
|
5020 | 5020 | if v == section: |
|
5021 | 5021 | ui.debug('%s: ' % |
|
5022 | 5022 | ui.configsource(section, name, untrusted)) |
|
5023 | 5023 | ui.write('%s=%s\n' % (sectname, value)) |
|
5024 | 5024 | elif v == sectname: |
|
5025 | 5025 | ui.debug('%s: ' % |
|
5026 | 5026 | ui.configsource(section, name, untrusted)) |
|
5027 | 5027 | ui.write(value, '\n') |
|
5028 | 5028 | else: |
|
5029 | 5029 | ui.debug('%s: ' % |
|
5030 | 5030 | ui.configsource(section, name, untrusted)) |
|
5031 | 5031 | ui.write('%s=%s\n' % (sectname, value)) |
|
5032 | 5032 | |
|
5033 | 5033 | @command('^status|st', |
|
5034 | 5034 | [('A', 'all', None, _('show status of all files')), |
|
5035 | 5035 | ('m', 'modified', None, _('show only modified files')), |
|
5036 | 5036 | ('a', 'added', None, _('show only added files')), |
|
5037 | 5037 | ('r', 'removed', None, _('show only removed files')), |
|
5038 | 5038 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
5039 | 5039 | ('c', 'clean', None, _('show only files without changes')), |
|
5040 | 5040 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
5041 | 5041 | ('i', 'ignored', None, _('show only ignored files')), |
|
5042 | 5042 | ('n', 'no-status', None, _('hide status prefix')), |
|
5043 | 5043 | ('C', 'copies', None, _('show source of copied files')), |
|
5044 | 5044 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
5045 | 5045 | ('', 'rev', [], _('show difference from revision'), _('REV')), |
|
5046 | 5046 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), |
|
5047 | 5047 | ] + walkopts + subrepoopts, |
|
5048 | 5048 | _('[OPTION]... [FILE]...')) |
|
5049 | 5049 | def status(ui, repo, *pats, **opts): |
|
5050 | 5050 | """show changed files in the working directory |
|
5051 | 5051 | |
|
5052 | 5052 | Show status of files in the repository. If names are given, only |
|
5053 | 5053 | files that match are shown. Files that are clean or ignored or |
|
5054 | 5054 | the source of a copy/move operation, are not listed unless |
|
5055 | 5055 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
5056 | 5056 | Unless options described with "show only ..." are given, the |
|
5057 | 5057 | options -mardu are used. |
|
5058 | 5058 | |
|
5059 | 5059 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
5060 | 5060 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
5061 | 5061 | |
|
5062 | 5062 | .. note:: |
|
5063 | 5063 | status may appear to disagree with diff if permissions have |
|
5064 | 5064 | changed or a merge has occurred. The standard diff format does |
|
5065 | 5065 | not report permission changes and diff only reports changes |
|
5066 | 5066 | relative to one merge parent. |
|
5067 | 5067 | |
|
5068 | 5068 | If one revision is given, it is used as the base revision. |
|
5069 | 5069 | If two revisions are given, the differences between them are |
|
5070 | 5070 | shown. The --change option can also be used as a shortcut to list |
|
5071 | 5071 | the changed files of a revision from its first parent. |
|
5072 | 5072 | |
|
5073 | 5073 | The codes used to show the status of files are:: |
|
5074 | 5074 | |
|
5075 | 5075 | M = modified |
|
5076 | 5076 | A = added |
|
5077 | 5077 | R = removed |
|
5078 | 5078 | C = clean |
|
5079 | 5079 | ! = missing (deleted by non-hg command, but still tracked) |
|
5080 | 5080 | ? = not tracked |
|
5081 | 5081 | I = ignored |
|
5082 | 5082 | = origin of the previous file listed as A (added) |
|
5083 | 5083 | |
|
5084 | 5084 | .. container:: verbose |
|
5085 | 5085 | |
|
5086 | 5086 | Examples: |
|
5087 | 5087 | |
|
5088 | 5088 | - show changes in the working directory relative to a |
|
5089 | 5089 | changeset:: |
|
5090 | 5090 | |
|
5091 | 5091 | hg status --rev 9353 |
|
5092 | 5092 | |
|
5093 | 5093 | - show all changes including copies in an existing changeset:: |
|
5094 | 5094 | |
|
5095 | 5095 | hg status --copies --change 9353 |
|
5096 | 5096 | |
|
5097 | 5097 | - get a NUL separated list of added files, suitable for xargs:: |
|
5098 | 5098 | |
|
5099 | 5099 | hg status -an0 |
|
5100 | 5100 | |
|
5101 | 5101 | Returns 0 on success. |
|
5102 | 5102 | """ |
|
5103 | 5103 | |
|
5104 | 5104 | revs = opts.get('rev') |
|
5105 | 5105 | change = opts.get('change') |
|
5106 | 5106 | |
|
5107 | 5107 | if revs and change: |
|
5108 | 5108 | msg = _('cannot specify --rev and --change at the same time') |
|
5109 | 5109 | raise util.Abort(msg) |
|
5110 | 5110 | elif change: |
|
5111 | 5111 | node2 = scmutil.revsingle(repo, change, None).node() |
|
5112 | 5112 | node1 = repo[node2].p1().node() |
|
5113 | 5113 | else: |
|
5114 | 5114 | node1, node2 = scmutil.revpair(repo, revs) |
|
5115 | 5115 | |
|
5116 | 5116 | cwd = (pats and repo.getcwd()) or '' |
|
5117 | 5117 | end = opts.get('print0') and '\0' or '\n' |
|
5118 | 5118 | copy = {} |
|
5119 | 5119 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
5120 | 5120 | show = [k for k in states if opts.get(k)] |
|
5121 | 5121 | if opts.get('all'): |
|
5122 | 5122 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
5123 | 5123 | if not show: |
|
5124 | 5124 | show = ui.quiet and states[:4] or states[:5] |
|
5125 | 5125 | |
|
5126 | 5126 | stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts), |
|
5127 | 5127 | 'ignored' in show, 'clean' in show, 'unknown' in show, |
|
5128 | 5128 | opts.get('subrepos')) |
|
5129 | 5129 | changestates = zip(states, 'MAR!?IC', stat) |
|
5130 | 5130 | |
|
5131 | 5131 | if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): |
|
5132 | 5132 | copy = copies.pathcopies(repo[node1], repo[node2]) |
|
5133 | 5133 | |
|
5134 | 5134 | fm = ui.formatter('status', opts) |
|
5135 | 5135 | format = '%s %s' + end |
|
5136 | 5136 | if opts.get('no_status'): |
|
5137 | 5137 | format = '%.0s%s' + end |
|
5138 | 5138 | |
|
5139 | 5139 | for state, char, files in changestates: |
|
5140 | 5140 | if state in show: |
|
5141 | 5141 | label = 'status.' + state |
|
5142 | 5142 | for f in files: |
|
5143 | 5143 | fm.startitem() |
|
5144 | 5144 | fm.write("status path", format, char, |
|
5145 | 5145 | repo.pathto(f, cwd), label=label) |
|
5146 | 5146 | if f in copy: |
|
5147 | 5147 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), |
|
5148 | 5148 | label='status.copied') |
|
5149 | 5149 | fm.end() |
|
5150 | 5150 | |
|
5151 | 5151 | @command('^summary|sum', |
|
5152 | 5152 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') |
|
5153 | 5153 | def summary(ui, repo, **opts): |
|
5154 | 5154 | """summarize working directory state |
|
5155 | 5155 | |
|
5156 | 5156 | This generates a brief summary of the working directory state, |
|
5157 | 5157 | including parents, branch, commit status, and available updates. |
|
5158 | 5158 | |
|
5159 | 5159 | With the --remote option, this will check the default paths for |
|
5160 | 5160 | incoming and outgoing changes. This can be time-consuming. |
|
5161 | 5161 | |
|
5162 | 5162 | Returns 0 on success. |
|
5163 | 5163 | """ |
|
5164 | 5164 | |
|
5165 | 5165 | ctx = repo[None] |
|
5166 | 5166 | parents = ctx.parents() |
|
5167 | 5167 | pnode = parents[0].node() |
|
5168 | 5168 | marks = [] |
|
5169 | 5169 | |
|
5170 | 5170 | for p in parents: |
|
5171 | 5171 | # label with log.changeset (instead of log.parent) since this |
|
5172 | 5172 | # shows a working directory parent *changeset*: |
|
5173 | 5173 | ui.write(_('parent: %d:%s ') % (p.rev(), str(p)), |
|
5174 | 5174 | label='log.changeset') |
|
5175 | 5175 | ui.write(' '.join(p.tags()), label='log.tag') |
|
5176 | 5176 | if p.bookmarks(): |
|
5177 | 5177 | marks.extend(p.bookmarks()) |
|
5178 | 5178 | if p.rev() == -1: |
|
5179 | 5179 | if not len(repo): |
|
5180 | 5180 | ui.write(_(' (empty repository)')) |
|
5181 | 5181 | else: |
|
5182 | 5182 | ui.write(_(' (no revision checked out)')) |
|
5183 | 5183 | ui.write('\n') |
|
5184 | 5184 | if p.description(): |
|
5185 | 5185 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', |
|
5186 | 5186 | label='log.summary') |
|
5187 | 5187 | |
|
5188 | 5188 | branch = ctx.branch() |
|
5189 | 5189 | bheads = repo.branchheads(branch) |
|
5190 | 5190 | m = _('branch: %s\n') % branch |
|
5191 | 5191 | if branch != 'default': |
|
5192 | 5192 | ui.write(m, label='log.branch') |
|
5193 | 5193 | else: |
|
5194 | 5194 | ui.status(m, label='log.branch') |
|
5195 | 5195 | |
|
5196 | 5196 | if marks: |
|
5197 | 5197 | current = repo._bookmarkcurrent |
|
5198 | 5198 | ui.write(_('bookmarks:'), label='log.bookmark') |
|
5199 | 5199 | if current is not None: |
|
5200 | 5200 | try: |
|
5201 | 5201 | marks.remove(current) |
|
5202 | 5202 | ui.write(' *' + current, label='bookmarks.current') |
|
5203 | 5203 | except ValueError: |
|
5204 | 5204 | # current bookmark not in parent ctx marks |
|
5205 | 5205 | pass |
|
5206 | 5206 | for m in marks: |
|
5207 | 5207 | ui.write(' ' + m, label='log.bookmark') |
|
5208 | 5208 | ui.write('\n', label='log.bookmark') |
|
5209 | 5209 | |
|
5210 | 5210 | st = list(repo.status(unknown=True))[:6] |
|
5211 | 5211 | |
|
5212 | 5212 | c = repo.dirstate.copies() |
|
5213 | 5213 | copied, renamed = [], [] |
|
5214 | 5214 | for d, s in c.iteritems(): |
|
5215 | 5215 | if s in st[2]: |
|
5216 | 5216 | st[2].remove(s) |
|
5217 | 5217 | renamed.append(d) |
|
5218 | 5218 | else: |
|
5219 | 5219 | copied.append(d) |
|
5220 | 5220 | if d in st[1]: |
|
5221 | 5221 | st[1].remove(d) |
|
5222 | 5222 | st.insert(3, renamed) |
|
5223 | 5223 | st.insert(4, copied) |
|
5224 | 5224 | |
|
5225 | 5225 | ms = mergemod.mergestate(repo) |
|
5226 | 5226 | st.append([f for f in ms if ms[f] == 'u']) |
|
5227 | 5227 | |
|
5228 | 5228 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
5229 | 5229 | st.append(subs) |
|
5230 | 5230 | |
|
5231 | 5231 | labels = [ui.label(_('%d modified'), 'status.modified'), |
|
5232 | 5232 | ui.label(_('%d added'), 'status.added'), |
|
5233 | 5233 | ui.label(_('%d removed'), 'status.removed'), |
|
5234 | 5234 | ui.label(_('%d renamed'), 'status.copied'), |
|
5235 | 5235 | ui.label(_('%d copied'), 'status.copied'), |
|
5236 | 5236 | ui.label(_('%d deleted'), 'status.deleted'), |
|
5237 | 5237 | ui.label(_('%d unknown'), 'status.unknown'), |
|
5238 | 5238 | ui.label(_('%d ignored'), 'status.ignored'), |
|
5239 | 5239 | ui.label(_('%d unresolved'), 'resolve.unresolved'), |
|
5240 | 5240 | ui.label(_('%d subrepos'), 'status.modified')] |
|
5241 | 5241 | t = [] |
|
5242 | 5242 | for s, l in zip(st, labels): |
|
5243 | 5243 | if s: |
|
5244 | 5244 | t.append(l % len(s)) |
|
5245 | 5245 | |
|
5246 | 5246 | t = ', '.join(t) |
|
5247 | 5247 | cleanworkdir = False |
|
5248 | 5248 | |
|
5249 | 5249 | if len(parents) > 1: |
|
5250 | 5250 | t += _(' (merge)') |
|
5251 | 5251 | elif branch != parents[0].branch(): |
|
5252 | 5252 | t += _(' (new branch)') |
|
5253 | 5253 | elif (parents[0].extra().get('close') and |
|
5254 | 5254 | pnode in repo.branchheads(branch, closed=True)): |
|
5255 | 5255 | t += _(' (head closed)') |
|
5256 | 5256 | elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]): |
|
5257 | 5257 | t += _(' (clean)') |
|
5258 | 5258 | cleanworkdir = True |
|
5259 | 5259 | elif pnode not in bheads: |
|
5260 | 5260 | t += _(' (new branch head)') |
|
5261 | 5261 | |
|
5262 | 5262 | if cleanworkdir: |
|
5263 | 5263 | ui.status(_('commit: %s\n') % t.strip()) |
|
5264 | 5264 | else: |
|
5265 | 5265 | ui.write(_('commit: %s\n') % t.strip()) |
|
5266 | 5266 | |
|
5267 | 5267 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
5268 | 5268 | new = [0] * len(repo) |
|
5269 | 5269 | cl = repo.changelog |
|
5270 | 5270 | for a in [cl.rev(n) for n in bheads]: |
|
5271 | 5271 | new[a] = 1 |
|
5272 | 5272 | for a in cl.ancestors(*[cl.rev(n) for n in bheads]): |
|
5273 | 5273 | new[a] = 1 |
|
5274 | 5274 | for a in [p.rev() for p in parents]: |
|
5275 | 5275 | if a >= 0: |
|
5276 | 5276 | new[a] = 0 |
|
5277 | 5277 | for a in cl.ancestors(*[p.rev() for p in parents]): |
|
5278 | 5278 | new[a] = 0 |
|
5279 | 5279 | new = sum(new) |
|
5280 | 5280 | |
|
5281 | 5281 | if new == 0: |
|
5282 | 5282 | ui.status(_('update: (current)\n')) |
|
5283 | 5283 | elif pnode not in bheads: |
|
5284 | 5284 | ui.write(_('update: %d new changesets (update)\n') % new) |
|
5285 | 5285 | else: |
|
5286 | 5286 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % |
|
5287 | 5287 | (new, len(bheads))) |
|
5288 | 5288 | |
|
5289 | 5289 | if opts.get('remote'): |
|
5290 | 5290 | t = [] |
|
5291 | 5291 | source, branches = hg.parseurl(ui.expandpath('default')) |
|
5292 | 5292 | other = hg.peer(repo, {}, source) |
|
5293 | 5293 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) |
|
5294 | 5294 | ui.debug('comparing with %s\n' % util.hidepassword(source)) |
|
5295 | 5295 | repo.ui.pushbuffer() |
|
5296 | 5296 | commoninc = discovery.findcommonincoming(repo, other) |
|
5297 | 5297 | _common, incoming, _rheads = commoninc |
|
5298 | 5298 | repo.ui.popbuffer() |
|
5299 | 5299 | if incoming: |
|
5300 | 5300 | t.append(_('1 or more incoming')) |
|
5301 | 5301 | |
|
5302 | 5302 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) |
|
5303 | 5303 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
5304 | 5304 | if source != dest: |
|
5305 | 5305 | other = hg.peer(repo, {}, dest) |
|
5306 | 5306 | commoninc = None |
|
5307 | 5307 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) |
|
5308 | 5308 | repo.ui.pushbuffer() |
|
5309 | 5309 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
5310 | 5310 | commoninc=commoninc) |
|
5311 | 5311 | repo.ui.popbuffer() |
|
5312 | 5312 | o = outgoing.missing |
|
5313 | 5313 | if o: |
|
5314 | 5314 | t.append(_('%d outgoing') % len(o)) |
|
5315 | 5315 | if 'bookmarks' in other.listkeys('namespaces'): |
|
5316 | 5316 | lmarks = repo.listkeys('bookmarks') |
|
5317 | 5317 | rmarks = other.listkeys('bookmarks') |
|
5318 | 5318 | diff = set(rmarks) - set(lmarks) |
|
5319 | 5319 | if len(diff) > 0: |
|
5320 | 5320 | t.append(_('%d incoming bookmarks') % len(diff)) |
|
5321 | 5321 | diff = set(lmarks) - set(rmarks) |
|
5322 | 5322 | if len(diff) > 0: |
|
5323 | 5323 | t.append(_('%d outgoing bookmarks') % len(diff)) |
|
5324 | 5324 | |
|
5325 | 5325 | if t: |
|
5326 | 5326 | ui.write(_('remote: %s\n') % (', '.join(t))) |
|
5327 | 5327 | else: |
|
5328 | 5328 | ui.status(_('remote: (synced)\n')) |
|
5329 | 5329 | |
|
5330 | 5330 | @command('tag', |
|
5331 | 5331 | [('f', 'force', None, _('force tag')), |
|
5332 | 5332 | ('l', 'local', None, _('make the tag local')), |
|
5333 | 5333 | ('r', 'rev', '', _('revision to tag'), _('REV')), |
|
5334 | 5334 | ('', 'remove', None, _('remove a tag')), |
|
5335 | 5335 | # -l/--local is already there, commitopts cannot be used |
|
5336 | 5336 | ('e', 'edit', None, _('edit commit message')), |
|
5337 | 5337 | ('m', 'message', '', _('use <text> as commit message'), _('TEXT')), |
|
5338 | 5338 | ] + commitopts2, |
|
5339 | 5339 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) |
|
5340 | 5340 | def tag(ui, repo, name1, *names, **opts): |
|
5341 | 5341 | """add one or more tags for the current or given revision |
|
5342 | 5342 | |
|
5343 | 5343 | Name a particular revision using <name>. |
|
5344 | 5344 | |
|
5345 | 5345 | Tags are used to name particular revisions of the repository and are |
|
5346 | 5346 | very useful to compare different revisions, to go back to significant |
|
5347 | 5347 | earlier versions or to mark branch points as releases, etc. Changing |
|
5348 | 5348 | an existing tag is normally disallowed; use -f/--force to override. |
|
5349 | 5349 | |
|
5350 | 5350 | If no revision is given, the parent of the working directory is |
|
5351 | 5351 | used, or tip if no revision is checked out. |
|
5352 | 5352 | |
|
5353 | 5353 | To facilitate version control, distribution, and merging of tags, |
|
5354 | 5354 | they are stored as a file named ".hgtags" which is managed similarly |
|
5355 | 5355 | to other project files and can be hand-edited if necessary. This |
|
5356 | 5356 | also means that tagging creates a new commit. The file |
|
5357 | 5357 | ".hg/localtags" is used for local tags (not shared among |
|
5358 | 5358 | repositories). |
|
5359 | 5359 | |
|
5360 | 5360 | Tag commits are usually made at the head of a branch. If the parent |
|
5361 | 5361 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
5362 | 5362 | -f/--force to force the tag commit to be based on a non-head |
|
5363 | 5363 | changeset. |
|
5364 | 5364 | |
|
5365 | 5365 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5366 | 5366 | |
|
5367 | 5367 | Since tag names have priority over branch names during revision |
|
5368 | 5368 | lookup, using an existing branch name as a tag name is discouraged. |
|
5369 | 5369 | |
|
5370 | 5370 | Returns 0 on success. |
|
5371 | 5371 | """ |
|
5372 | 5372 | wlock = lock = None |
|
5373 | 5373 | try: |
|
5374 | 5374 | wlock = repo.wlock() |
|
5375 | 5375 | lock = repo.lock() |
|
5376 | 5376 | rev_ = "." |
|
5377 | 5377 | names = [t.strip() for t in (name1,) + names] |
|
5378 | 5378 | if len(names) != len(set(names)): |
|
5379 | 5379 | raise util.Abort(_('tag names must be unique')) |
|
5380 | 5380 | for n in names: |
|
5381 | 5381 | if n in ['tip', '.', 'null']: |
|
5382 | 5382 | raise util.Abort(_("the name '%s' is reserved") % n) |
|
5383 | 5383 | if not n: |
|
5384 | 5384 | raise util.Abort(_('tag names cannot consist entirely of ' |
|
5385 | 5385 | 'whitespace')) |
|
5386 | 5386 | if opts.get('rev') and opts.get('remove'): |
|
5387 | 5387 | raise util.Abort(_("--rev and --remove are incompatible")) |
|
5388 | 5388 | if opts.get('rev'): |
|
5389 | 5389 | rev_ = opts['rev'] |
|
5390 | 5390 | message = opts.get('message') |
|
5391 | 5391 | if opts.get('remove'): |
|
5392 | 5392 | expectedtype = opts.get('local') and 'local' or 'global' |
|
5393 | 5393 | for n in names: |
|
5394 | 5394 | if not repo.tagtype(n): |
|
5395 | 5395 | raise util.Abort(_("tag '%s' does not exist") % n) |
|
5396 | 5396 | if repo.tagtype(n) != expectedtype: |
|
5397 | 5397 | if expectedtype == 'global': |
|
5398 | 5398 | raise util.Abort(_("tag '%s' is not a global tag") % n) |
|
5399 | 5399 | else: |
|
5400 | 5400 | raise util.Abort(_("tag '%s' is not a local tag") % n) |
|
5401 | 5401 | rev_ = nullid |
|
5402 | 5402 | if not message: |
|
5403 | 5403 | # we don't translate commit messages |
|
5404 | 5404 | message = 'Removed tag %s' % ', '.join(names) |
|
5405 | 5405 | elif not opts.get('force'): |
|
5406 | 5406 | for n in names: |
|
5407 | 5407 | if n in repo.tags(): |
|
5408 | 5408 | raise util.Abort(_("tag '%s' already exists " |
|
5409 | 5409 | "(use -f to force)") % n) |
|
5410 | 5410 | if not opts.get('local'): |
|
5411 | 5411 | p1, p2 = repo.dirstate.parents() |
|
5412 | 5412 | if p2 != nullid: |
|
5413 | 5413 | raise util.Abort(_('uncommitted merge')) |
|
5414 | 5414 | bheads = repo.branchheads() |
|
5415 | 5415 | if not opts.get('force') and bheads and p1 not in bheads: |
|
5416 | 5416 | raise util.Abort(_('not at a branch head (use -f to force)')) |
|
5417 | 5417 | r = scmutil.revsingle(repo, rev_).node() |
|
5418 | 5418 | |
|
5419 | 5419 | if not message: |
|
5420 | 5420 | # we don't translate commit messages |
|
5421 | 5421 | message = ('Added tag %s for changeset %s' % |
|
5422 | 5422 | (', '.join(names), short(r))) |
|
5423 | 5423 | |
|
5424 | 5424 | date = opts.get('date') |
|
5425 | 5425 | if date: |
|
5426 | 5426 | date = util.parsedate(date) |
|
5427 | 5427 | |
|
5428 | 5428 | if opts.get('edit'): |
|
5429 | 5429 | message = ui.edit(message, ui.username()) |
|
5430 | 5430 | |
|
5431 | 5431 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date) |
|
5432 | 5432 | finally: |
|
5433 | 5433 | release(lock, wlock) |
|
5434 | 5434 | |
|
5435 | 5435 | @command('tags', [], '') |
|
5436 | 5436 | def tags(ui, repo): |
|
5437 | 5437 | """list repository tags |
|
5438 | 5438 | |
|
5439 | 5439 | This lists both regular and local tags. When the -v/--verbose |
|
5440 | 5440 | switch is used, a third column "local" is printed for local tags. |
|
5441 | 5441 | |
|
5442 | 5442 | Returns 0 on success. |
|
5443 | 5443 | """ |
|
5444 | 5444 | |
|
5445 | 5445 | hexfunc = ui.debugflag and hex or short |
|
5446 | 5446 | tagtype = "" |
|
5447 | 5447 | |
|
5448 | 5448 | for t, n in reversed(repo.tagslist()): |
|
5449 | 5449 | if ui.quiet: |
|
5450 | 5450 | ui.write("%s\n" % t, label='tags.normal') |
|
5451 | 5451 | continue |
|
5452 | 5452 | |
|
5453 | 5453 | hn = hexfunc(n) |
|
5454 | 5454 | r = "%5d:%s" % (repo.changelog.rev(n), hn) |
|
5455 | 5455 | rev = ui.label(r, 'log.changeset') |
|
5456 | 5456 | spaces = " " * (30 - encoding.colwidth(t)) |
|
5457 | 5457 | |
|
5458 | 5458 | tag = ui.label(t, 'tags.normal') |
|
5459 | 5459 | if ui.verbose: |
|
5460 | 5460 | if repo.tagtype(t) == 'local': |
|
5461 | 5461 | tagtype = " local" |
|
5462 | 5462 | tag = ui.label(t, 'tags.local') |
|
5463 | 5463 | else: |
|
5464 | 5464 | tagtype = "" |
|
5465 | 5465 | ui.write("%s%s %s%s\n" % (tag, spaces, rev, tagtype)) |
|
5466 | 5466 | |
|
5467 | 5467 | @command('tip', |
|
5468 | 5468 | [('p', 'patch', None, _('show patch')), |
|
5469 | 5469 | ('g', 'git', None, _('use git extended diff format')), |
|
5470 | 5470 | ] + templateopts, |
|
5471 | 5471 | _('[-p] [-g]')) |
|
5472 | 5472 | def tip(ui, repo, **opts): |
|
5473 | 5473 | """show the tip revision |
|
5474 | 5474 | |
|
5475 | 5475 | The tip revision (usually just called the tip) is the changeset |
|
5476 | 5476 | most recently added to the repository (and therefore the most |
|
5477 | 5477 | recently changed head). |
|
5478 | 5478 | |
|
5479 | 5479 | If you have just made a commit, that commit will be the tip. If |
|
5480 | 5480 | you have just pulled changes from another repository, the tip of |
|
5481 | 5481 | that repository becomes the current tip. The "tip" tag is special |
|
5482 | 5482 | and cannot be renamed or assigned to a different changeset. |
|
5483 | 5483 | |
|
5484 | 5484 | Returns 0 on success. |
|
5485 | 5485 | """ |
|
5486 | 5486 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
5487 | 5487 | displayer.show(repo[len(repo) - 1]) |
|
5488 | 5488 | displayer.close() |
|
5489 | 5489 | |
|
5490 | 5490 | @command('unbundle', |
|
5491 | 5491 | [('u', 'update', None, |
|
5492 | 5492 | _('update to new branch head if changesets were unbundled'))], |
|
5493 | 5493 | _('[-u] FILE...')) |
|
5494 | 5494 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
5495 | 5495 | """apply one or more changegroup files |
|
5496 | 5496 | |
|
5497 | 5497 | Apply one or more compressed changegroup files generated by the |
|
5498 | 5498 | bundle command. |
|
5499 | 5499 | |
|
5500 | 5500 | Returns 0 on success, 1 if an update has unresolved files. |
|
5501 | 5501 | """ |
|
5502 | 5502 | fnames = (fname1,) + fnames |
|
5503 | 5503 | |
|
5504 | 5504 | lock = repo.lock() |
|
5505 | 5505 | wc = repo['.'] |
|
5506 | 5506 | try: |
|
5507 | 5507 | for fname in fnames: |
|
5508 | 5508 | f = url.open(ui, fname) |
|
5509 | 5509 | gen = changegroup.readbundle(f, fname) |
|
5510 | 5510 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) |
|
5511 | 5511 | bookmarks.updatecurrentbookmark(repo, wc.node(), wc.branch()) |
|
5512 | 5512 | finally: |
|
5513 | 5513 | lock.release() |
|
5514 | 5514 | return postincoming(ui, repo, modheads, opts.get('update'), None) |
|
5515 | 5515 | |
|
5516 | 5516 | @command('^update|up|checkout|co', |
|
5517 | 5517 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
|
5518 | 5518 | ('c', 'check', None, |
|
5519 | 5519 | _('update across branches if no uncommitted changes')), |
|
5520 | 5520 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
5521 | 5521 | ('r', 'rev', '', _('revision'), _('REV'))], |
|
5522 | 5522 | _('[-c] [-C] [-d DATE] [[-r] REV]')) |
|
5523 | 5523 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False): |
|
5524 | 5524 | """update working directory (or switch revisions) |
|
5525 | 5525 | |
|
5526 | 5526 | Update the repository's working directory to the specified |
|
5527 | 5527 | changeset. If no changeset is specified, update to the tip of the |
|
5528 | 5528 | current named branch and move the current bookmark (see :hg:`help |
|
5529 | 5529 | bookmarks`). |
|
5530 | 5530 | |
|
5531 | 5531 | If the changeset is not a descendant of the working directory's |
|
5532 | 5532 | parent, the update is aborted. With the -c/--check option, the |
|
5533 | 5533 | working directory is checked for uncommitted changes; if none are |
|
5534 | 5534 | found, the working directory is updated to the specified |
|
5535 | 5535 | changeset. |
|
5536 | 5536 | |
|
5537 | 5537 | Update sets the working directory's parent revison to the specified |
|
5538 | 5538 | changeset (see :hg:`help parents`). |
|
5539 | 5539 | |
|
5540 | 5540 | The following rules apply when the working directory contains |
|
5541 | 5541 | uncommitted changes: |
|
5542 | 5542 | |
|
5543 | 5543 | 1. If neither -c/--check nor -C/--clean is specified, and if |
|
5544 | 5544 | the requested changeset is an ancestor or descendant of |
|
5545 | 5545 | the working directory's parent, the uncommitted changes |
|
5546 | 5546 | are merged into the requested changeset and the merged |
|
5547 | 5547 | result is left uncommitted. If the requested changeset is |
|
5548 | 5548 | not an ancestor or descendant (that is, it is on another |
|
5549 | 5549 | branch), the update is aborted and the uncommitted changes |
|
5550 | 5550 | are preserved. |
|
5551 | 5551 | |
|
5552 | 5552 | 2. With the -c/--check option, the update is aborted and the |
|
5553 | 5553 | uncommitted changes are preserved. |
|
5554 | 5554 | |
|
5555 | 5555 | 3. With the -C/--clean option, uncommitted changes are discarded and |
|
5556 | 5556 | the working directory is updated to the requested changeset. |
|
5557 | 5557 | |
|
5558 | 5558 | Use null as the changeset to remove the working directory (like |
|
5559 | 5559 | :hg:`clone -U`). |
|
5560 | 5560 | |
|
5561 | 5561 | If you want to revert just one file to an older revision, use |
|
5562 | 5562 | :hg:`revert [-r REV] NAME`. |
|
5563 | 5563 | |
|
5564 | 5564 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5565 | 5565 | |
|
5566 | 5566 | Returns 0 on success, 1 if there are unresolved files. |
|
5567 | 5567 | """ |
|
5568 | 5568 | if rev and node: |
|
5569 | 5569 | raise util.Abort(_("please specify just one revision")) |
|
5570 | 5570 | |
|
5571 | 5571 | if rev is None or rev == '': |
|
5572 | 5572 | rev = node |
|
5573 | 5573 | |
|
5574 | 5574 | # with no argument, we also move the current bookmark, if any |
|
5575 | 5575 | movemarkfrom = None |
|
5576 | 5576 | if rev is None or node == '': |
|
5577 | 5577 | movemarkfrom = repo['.'].node() |
|
5578 | 5578 | |
|
5579 | 5579 | # if we defined a bookmark, we have to remember the original bookmark name |
|
5580 | 5580 | brev = rev |
|
5581 | 5581 | rev = scmutil.revsingle(repo, rev, rev).rev() |
|
5582 | 5582 | |
|
5583 | 5583 | if check and clean: |
|
5584 | 5584 | raise util.Abort(_("cannot specify both -c/--check and -C/--clean")) |
|
5585 | 5585 | |
|
5586 | 5586 | if date: |
|
5587 | 5587 | if rev is not None: |
|
5588 | 5588 | raise util.Abort(_("you can't specify a revision and a date")) |
|
5589 | 5589 | rev = cmdutil.finddate(ui, repo, date) |
|
5590 | 5590 | |
|
5591 | 5591 | if check: |
|
5592 | 5592 | # we could use dirty() but we can ignore merge and branch trivia |
|
5593 | 5593 | c = repo[None] |
|
5594 | 5594 | if c.modified() or c.added() or c.removed(): |
|
5595 | 5595 | raise util.Abort(_("uncommitted local changes")) |
|
5596 | 5596 | if not rev: |
|
5597 | 5597 | rev = repo[repo[None].branch()].rev() |
|
5598 | 5598 | mergemod._checkunknown(repo, repo[None], repo[rev]) |
|
5599 | 5599 | |
|
5600 | 5600 | if clean: |
|
5601 | 5601 | ret = hg.clean(repo, rev) |
|
5602 | 5602 | else: |
|
5603 | 5603 | ret = hg.update(repo, rev) |
|
5604 | 5604 | |
|
5605 | 5605 | if not ret and movemarkfrom: |
|
5606 | 5606 | if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
|
5607 | 5607 | ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent) |
|
5608 | 5608 | elif brev in repo._bookmarks: |
|
5609 | 5609 | bookmarks.setcurrent(repo, brev) |
|
5610 | 5610 | elif brev: |
|
5611 | 5611 | bookmarks.unsetcurrent(repo) |
|
5612 | 5612 | |
|
5613 | 5613 | return ret |
|
5614 | 5614 | |
|
5615 | 5615 | @command('verify', []) |
|
5616 | 5616 | def verify(ui, repo): |
|
5617 | 5617 | """verify the integrity of the repository |
|
5618 | 5618 | |
|
5619 | 5619 | Verify the integrity of the current repository. |
|
5620 | 5620 | |
|
5621 | 5621 | This will perform an extensive check of the repository's |
|
5622 | 5622 | integrity, validating the hashes and checksums of each entry in |
|
5623 | 5623 | the changelog, manifest, and tracked files, as well as the |
|
5624 | 5624 | integrity of their crosslinks and indices. |
|
5625 | 5625 | |
|
5626 | 5626 | Returns 0 on success, 1 if errors are encountered. |
|
5627 | 5627 | """ |
|
5628 | 5628 | return hg.verify(repo) |
|
5629 | 5629 | |
|
5630 | 5630 | @command('version', []) |
|
5631 | 5631 | def version_(ui): |
|
5632 | 5632 | """output version and copyright information""" |
|
5633 | 5633 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
5634 | 5634 | % util.version()) |
|
5635 | 5635 | ui.status(_( |
|
5636 | 5636 | "(see http://mercurial.selenic.com for more information)\n" |
|
5637 | 5637 | "\nCopyright (C) 2005-2012 Matt Mackall and others\n" |
|
5638 | 5638 | "This is free software; see the source for copying conditions. " |
|
5639 | 5639 | "There is NO\nwarranty; " |
|
5640 | 5640 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
5641 | 5641 | )) |
|
5642 | 5642 | |
|
5643 | 5643 | norepo = ("clone init version help debugcommands debugcomplete" |
|
5644 | 5644 | " debugdate debuginstall debugfsinfo debugpushkey debugwireargs" |
|
5645 | 5645 | " debugknown debuggetbundle debugbundle") |
|
5646 | 5646 | optionalrepo = ("identify paths serve showconfig debugancestor debugdag" |
|
5647 | 5647 | " debugdata debugindex debugindexdot debugrevlog") |
@@ -1,1194 +1,1194 b'' | |||
|
1 | 1 | # context.py - changeset and file context objects for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from node import nullid, nullrev, short, hex |
|
9 | 9 | from i18n import _ |
|
10 | 10 | import ancestor, mdiff, error, util, scmutil, subrepo, patch, encoding, phases |
|
11 | 11 | import match as matchmod |
|
12 | 12 | import os, errno, stat |
|
13 | 13 | |
|
14 | 14 | propertycache = util.propertycache |
|
15 | 15 | |
|
16 | 16 | class changectx(object): |
|
17 | 17 | """A changecontext object makes access to data related to a particular |
|
18 | 18 | changeset convenient.""" |
|
19 | 19 | def __init__(self, repo, changeid=''): |
|
20 | 20 | """changeid is a revision number, node, or tag""" |
|
21 | 21 | if changeid == '': |
|
22 | 22 | changeid = '.' |
|
23 | 23 | self._repo = repo |
|
24 | 24 | if isinstance(changeid, (long, int)): |
|
25 | 25 | self._rev = changeid |
|
26 | 26 | self._node = self._repo.changelog.node(changeid) |
|
27 | 27 | else: |
|
28 | 28 | self._node = self._repo.lookup(changeid) |
|
29 | 29 | self._rev = self._repo.changelog.rev(self._node) |
|
30 | 30 | |
|
31 | 31 | def __str__(self): |
|
32 | 32 | return short(self.node()) |
|
33 | 33 | |
|
34 | 34 | def __int__(self): |
|
35 | 35 | return self.rev() |
|
36 | 36 | |
|
37 | 37 | def __repr__(self): |
|
38 | 38 | return "<changectx %s>" % str(self) |
|
39 | 39 | |
|
40 | 40 | def __hash__(self): |
|
41 | 41 | try: |
|
42 | 42 | return hash(self._rev) |
|
43 | 43 | except AttributeError: |
|
44 | 44 | return id(self) |
|
45 | 45 | |
|
46 | 46 | def __eq__(self, other): |
|
47 | 47 | try: |
|
48 | 48 | return self._rev == other._rev |
|
49 | 49 | except AttributeError: |
|
50 | 50 | return False |
|
51 | 51 | |
|
52 | 52 | def __ne__(self, other): |
|
53 | 53 | return not (self == other) |
|
54 | 54 | |
|
55 | 55 | def __nonzero__(self): |
|
56 | 56 | return self._rev != nullrev |
|
57 | 57 | |
|
58 | 58 | @propertycache |
|
59 | 59 | def _changeset(self): |
|
60 | 60 | return self._repo.changelog.read(self.node()) |
|
61 | 61 | |
|
62 | 62 | @propertycache |
|
63 | 63 | def _manifest(self): |
|
64 | 64 | return self._repo.manifest.read(self._changeset[0]) |
|
65 | 65 | |
|
66 | 66 | @propertycache |
|
67 | 67 | def _manifestdelta(self): |
|
68 | 68 | return self._repo.manifest.readdelta(self._changeset[0]) |
|
69 | 69 | |
|
70 | 70 | @propertycache |
|
71 | 71 | def _parents(self): |
|
72 | 72 | p = self._repo.changelog.parentrevs(self._rev) |
|
73 | 73 | if p[1] == nullrev: |
|
74 | 74 | p = p[:-1] |
|
75 | 75 | return [changectx(self._repo, x) for x in p] |
|
76 | 76 | |
|
77 | 77 | @propertycache |
|
78 | 78 | def substate(self): |
|
79 | 79 | return subrepo.state(self, self._repo.ui) |
|
80 | 80 | |
|
81 | 81 | def __contains__(self, key): |
|
82 | 82 | return key in self._manifest |
|
83 | 83 | |
|
84 | 84 | def __getitem__(self, key): |
|
85 | 85 | return self.filectx(key) |
|
86 | 86 | |
|
87 | 87 | def __iter__(self): |
|
88 | 88 | for f in sorted(self._manifest): |
|
89 | 89 | yield f |
|
90 | 90 | |
|
91 | 91 | def changeset(self): |
|
92 | 92 | return self._changeset |
|
93 | 93 | def manifest(self): |
|
94 | 94 | return self._manifest |
|
95 | 95 | def manifestnode(self): |
|
96 | 96 | return self._changeset[0] |
|
97 | 97 | |
|
98 | 98 | def rev(self): |
|
99 | 99 | return self._rev |
|
100 | 100 | def node(self): |
|
101 | 101 | return self._node |
|
102 | 102 | def hex(self): |
|
103 | 103 | return hex(self._node) |
|
104 | 104 | def user(self): |
|
105 | 105 | return self._changeset[1] |
|
106 | 106 | def date(self): |
|
107 | 107 | return self._changeset[2] |
|
108 | 108 | def files(self): |
|
109 | 109 | return self._changeset[3] |
|
110 | 110 | def description(self): |
|
111 | 111 | return self._changeset[4] |
|
112 | 112 | def branch(self): |
|
113 | 113 | return encoding.tolocal(self._changeset[5].get("branch")) |
|
114 | 114 | def extra(self): |
|
115 | 115 | return self._changeset[5] |
|
116 | 116 | def tags(self): |
|
117 | 117 | return self._repo.nodetags(self._node) |
|
118 | 118 | def bookmarks(self): |
|
119 | 119 | return self._repo.nodebookmarks(self._node) |
|
120 | 120 | def phase(self): |
|
121 | 121 | if self._rev == -1: |
|
122 | 122 | return phases.public |
|
123 | 123 | if self._rev >= len(self._repo._phaserev): |
|
124 | 124 | # outdated cache |
|
125 | 125 | del self._repo._phaserev |
|
126 | 126 | return self._repo._phaserev[self._rev] |
|
127 | 127 | def phasestr(self): |
|
128 | 128 | return phases.phasenames[self.phase()] |
|
129 | 129 | def mutable(self): |
|
130 |
return self. |
|
|
130 | return self.phase() > phases.public | |
|
131 | 131 | def hidden(self): |
|
132 | 132 | return self._rev in self._repo.changelog.hiddenrevs |
|
133 | 133 | |
|
134 | 134 | def parents(self): |
|
135 | 135 | """return contexts for each parent changeset""" |
|
136 | 136 | return self._parents |
|
137 | 137 | |
|
138 | 138 | def p1(self): |
|
139 | 139 | return self._parents[0] |
|
140 | 140 | |
|
141 | 141 | def p2(self): |
|
142 | 142 | if len(self._parents) == 2: |
|
143 | 143 | return self._parents[1] |
|
144 | 144 | return changectx(self._repo, -1) |
|
145 | 145 | |
|
146 | 146 | def children(self): |
|
147 | 147 | """return contexts for each child changeset""" |
|
148 | 148 | c = self._repo.changelog.children(self._node) |
|
149 | 149 | return [changectx(self._repo, x) for x in c] |
|
150 | 150 | |
|
151 | 151 | def ancestors(self): |
|
152 | 152 | for a in self._repo.changelog.ancestors(self._rev): |
|
153 | 153 | yield changectx(self._repo, a) |
|
154 | 154 | |
|
155 | 155 | def descendants(self): |
|
156 | 156 | for d in self._repo.changelog.descendants(self._rev): |
|
157 | 157 | yield changectx(self._repo, d) |
|
158 | 158 | |
|
159 | 159 | def _fileinfo(self, path): |
|
160 | 160 | if '_manifest' in self.__dict__: |
|
161 | 161 | try: |
|
162 | 162 | return self._manifest[path], self._manifest.flags(path) |
|
163 | 163 | except KeyError: |
|
164 | 164 | raise error.LookupError(self._node, path, |
|
165 | 165 | _('not found in manifest')) |
|
166 | 166 | if '_manifestdelta' in self.__dict__ or path in self.files(): |
|
167 | 167 | if path in self._manifestdelta: |
|
168 | 168 | return self._manifestdelta[path], self._manifestdelta.flags(path) |
|
169 | 169 | node, flag = self._repo.manifest.find(self._changeset[0], path) |
|
170 | 170 | if not node: |
|
171 | 171 | raise error.LookupError(self._node, path, |
|
172 | 172 | _('not found in manifest')) |
|
173 | 173 | |
|
174 | 174 | return node, flag |
|
175 | 175 | |
|
176 | 176 | def filenode(self, path): |
|
177 | 177 | return self._fileinfo(path)[0] |
|
178 | 178 | |
|
179 | 179 | def flags(self, path): |
|
180 | 180 | try: |
|
181 | 181 | return self._fileinfo(path)[1] |
|
182 | 182 | except error.LookupError: |
|
183 | 183 | return '' |
|
184 | 184 | |
|
185 | 185 | def filectx(self, path, fileid=None, filelog=None): |
|
186 | 186 | """get a file context from this changeset""" |
|
187 | 187 | if fileid is None: |
|
188 | 188 | fileid = self.filenode(path) |
|
189 | 189 | return filectx(self._repo, path, fileid=fileid, |
|
190 | 190 | changectx=self, filelog=filelog) |
|
191 | 191 | |
|
192 | 192 | def ancestor(self, c2): |
|
193 | 193 | """ |
|
194 | 194 | return the ancestor context of self and c2 |
|
195 | 195 | """ |
|
196 | 196 | # deal with workingctxs |
|
197 | 197 | n2 = c2._node |
|
198 | 198 | if n2 is None: |
|
199 | 199 | n2 = c2._parents[0]._node |
|
200 | 200 | n = self._repo.changelog.ancestor(self._node, n2) |
|
201 | 201 | return changectx(self._repo, n) |
|
202 | 202 | |
|
203 | 203 | def walk(self, match): |
|
204 | 204 | fset = set(match.files()) |
|
205 | 205 | # for dirstate.walk, files=['.'] means "walk the whole tree". |
|
206 | 206 | # follow that here, too |
|
207 | 207 | fset.discard('.') |
|
208 | 208 | for fn in self: |
|
209 | 209 | if fn in fset: |
|
210 | 210 | # specified pattern is the exact name |
|
211 | 211 | fset.remove(fn) |
|
212 | 212 | if match(fn): |
|
213 | 213 | yield fn |
|
214 | 214 | for fn in sorted(fset): |
|
215 | 215 | if fn in self._dirs: |
|
216 | 216 | # specified pattern is a directory |
|
217 | 217 | continue |
|
218 | 218 | if match.bad(fn, _('no such file in rev %s') % self) and match(fn): |
|
219 | 219 | yield fn |
|
220 | 220 | |
|
221 | 221 | def sub(self, path): |
|
222 | 222 | return subrepo.subrepo(self, path) |
|
223 | 223 | |
|
224 | 224 | def match(self, pats=[], include=None, exclude=None, default='glob'): |
|
225 | 225 | r = self._repo |
|
226 | 226 | return matchmod.match(r.root, r.getcwd(), pats, |
|
227 | 227 | include, exclude, default, |
|
228 | 228 | auditor=r.auditor, ctx=self) |
|
229 | 229 | |
|
230 | 230 | def diff(self, ctx2=None, match=None, **opts): |
|
231 | 231 | """Returns a diff generator for the given contexts and matcher""" |
|
232 | 232 | if ctx2 is None: |
|
233 | 233 | ctx2 = self.p1() |
|
234 | 234 | if ctx2 is not None and not isinstance(ctx2, changectx): |
|
235 | 235 | ctx2 = self._repo[ctx2] |
|
236 | 236 | diffopts = patch.diffopts(self._repo.ui, opts) |
|
237 | 237 | return patch.diff(self._repo, ctx2.node(), self.node(), |
|
238 | 238 | match=match, opts=diffopts) |
|
239 | 239 | |
|
240 | 240 | @propertycache |
|
241 | 241 | def _dirs(self): |
|
242 | 242 | dirs = set() |
|
243 | 243 | for f in self._manifest: |
|
244 | 244 | pos = f.rfind('/') |
|
245 | 245 | while pos != -1: |
|
246 | 246 | f = f[:pos] |
|
247 | 247 | if f in dirs: |
|
248 | 248 | break # dirs already contains this and above |
|
249 | 249 | dirs.add(f) |
|
250 | 250 | pos = f.rfind('/') |
|
251 | 251 | return dirs |
|
252 | 252 | |
|
253 | 253 | def dirs(self): |
|
254 | 254 | return self._dirs |
|
255 | 255 | |
|
256 | 256 | class filectx(object): |
|
257 | 257 | """A filecontext object makes access to data related to a particular |
|
258 | 258 | filerevision convenient.""" |
|
259 | 259 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
260 | 260 | filelog=None, changectx=None): |
|
261 | 261 | """changeid can be a changeset revision, node, or tag. |
|
262 | 262 | fileid can be a file revision or node.""" |
|
263 | 263 | self._repo = repo |
|
264 | 264 | self._path = path |
|
265 | 265 | |
|
266 | 266 | assert (changeid is not None |
|
267 | 267 | or fileid is not None |
|
268 | 268 | or changectx is not None), \ |
|
269 | 269 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
270 | 270 | % (changeid, fileid, changectx)) |
|
271 | 271 | |
|
272 | 272 | if filelog: |
|
273 | 273 | self._filelog = filelog |
|
274 | 274 | |
|
275 | 275 | if changeid is not None: |
|
276 | 276 | self._changeid = changeid |
|
277 | 277 | if changectx is not None: |
|
278 | 278 | self._changectx = changectx |
|
279 | 279 | if fileid is not None: |
|
280 | 280 | self._fileid = fileid |
|
281 | 281 | |
|
282 | 282 | @propertycache |
|
283 | 283 | def _changectx(self): |
|
284 | 284 | return changectx(self._repo, self._changeid) |
|
285 | 285 | |
|
286 | 286 | @propertycache |
|
287 | 287 | def _filelog(self): |
|
288 | 288 | return self._repo.file(self._path) |
|
289 | 289 | |
|
290 | 290 | @propertycache |
|
291 | 291 | def _changeid(self): |
|
292 | 292 | if '_changectx' in self.__dict__: |
|
293 | 293 | return self._changectx.rev() |
|
294 | 294 | else: |
|
295 | 295 | return self._filelog.linkrev(self._filerev) |
|
296 | 296 | |
|
297 | 297 | @propertycache |
|
298 | 298 | def _filenode(self): |
|
299 | 299 | if '_fileid' in self.__dict__: |
|
300 | 300 | return self._filelog.lookup(self._fileid) |
|
301 | 301 | else: |
|
302 | 302 | return self._changectx.filenode(self._path) |
|
303 | 303 | |
|
304 | 304 | @propertycache |
|
305 | 305 | def _filerev(self): |
|
306 | 306 | return self._filelog.rev(self._filenode) |
|
307 | 307 | |
|
308 | 308 | @propertycache |
|
309 | 309 | def _repopath(self): |
|
310 | 310 | return self._path |
|
311 | 311 | |
|
312 | 312 | def __nonzero__(self): |
|
313 | 313 | try: |
|
314 | 314 | self._filenode |
|
315 | 315 | return True |
|
316 | 316 | except error.LookupError: |
|
317 | 317 | # file is missing |
|
318 | 318 | return False |
|
319 | 319 | |
|
320 | 320 | def __str__(self): |
|
321 | 321 | return "%s@%s" % (self.path(), short(self.node())) |
|
322 | 322 | |
|
323 | 323 | def __repr__(self): |
|
324 | 324 | return "<filectx %s>" % str(self) |
|
325 | 325 | |
|
326 | 326 | def __hash__(self): |
|
327 | 327 | try: |
|
328 | 328 | return hash((self._path, self._filenode)) |
|
329 | 329 | except AttributeError: |
|
330 | 330 | return id(self) |
|
331 | 331 | |
|
332 | 332 | def __eq__(self, other): |
|
333 | 333 | try: |
|
334 | 334 | return (self._path == other._path |
|
335 | 335 | and self._filenode == other._filenode) |
|
336 | 336 | except AttributeError: |
|
337 | 337 | return False |
|
338 | 338 | |
|
339 | 339 | def __ne__(self, other): |
|
340 | 340 | return not (self == other) |
|
341 | 341 | |
|
342 | 342 | def filectx(self, fileid): |
|
343 | 343 | '''opens an arbitrary revision of the file without |
|
344 | 344 | opening a new filelog''' |
|
345 | 345 | return filectx(self._repo, self._path, fileid=fileid, |
|
346 | 346 | filelog=self._filelog) |
|
347 | 347 | |
|
348 | 348 | def filerev(self): |
|
349 | 349 | return self._filerev |
|
350 | 350 | def filenode(self): |
|
351 | 351 | return self._filenode |
|
352 | 352 | def flags(self): |
|
353 | 353 | return self._changectx.flags(self._path) |
|
354 | 354 | def filelog(self): |
|
355 | 355 | return self._filelog |
|
356 | 356 | |
|
357 | 357 | def rev(self): |
|
358 | 358 | if '_changectx' in self.__dict__: |
|
359 | 359 | return self._changectx.rev() |
|
360 | 360 | if '_changeid' in self.__dict__: |
|
361 | 361 | return self._changectx.rev() |
|
362 | 362 | return self._filelog.linkrev(self._filerev) |
|
363 | 363 | |
|
364 | 364 | def linkrev(self): |
|
365 | 365 | return self._filelog.linkrev(self._filerev) |
|
366 | 366 | def node(self): |
|
367 | 367 | return self._changectx.node() |
|
368 | 368 | def hex(self): |
|
369 | 369 | return hex(self.node()) |
|
370 | 370 | def user(self): |
|
371 | 371 | return self._changectx.user() |
|
372 | 372 | def date(self): |
|
373 | 373 | return self._changectx.date() |
|
374 | 374 | def files(self): |
|
375 | 375 | return self._changectx.files() |
|
376 | 376 | def description(self): |
|
377 | 377 | return self._changectx.description() |
|
378 | 378 | def branch(self): |
|
379 | 379 | return self._changectx.branch() |
|
380 | 380 | def extra(self): |
|
381 | 381 | return self._changectx.extra() |
|
382 | 382 | def manifest(self): |
|
383 | 383 | return self._changectx.manifest() |
|
384 | 384 | def changectx(self): |
|
385 | 385 | return self._changectx |
|
386 | 386 | |
|
387 | 387 | def data(self): |
|
388 | 388 | return self._filelog.read(self._filenode) |
|
389 | 389 | def path(self): |
|
390 | 390 | return self._path |
|
391 | 391 | def size(self): |
|
392 | 392 | return self._filelog.size(self._filerev) |
|
393 | 393 | |
|
394 | 394 | def isbinary(self): |
|
395 | 395 | try: |
|
396 | 396 | return util.binary(self.data()) |
|
397 | 397 | except IOError: |
|
398 | 398 | return False |
|
399 | 399 | |
|
400 | 400 | def cmp(self, fctx): |
|
401 | 401 | """compare with other file context |
|
402 | 402 | |
|
403 | 403 | returns True if different than fctx. |
|
404 | 404 | """ |
|
405 | 405 | if (fctx._filerev is None |
|
406 | 406 | and (self._repo._encodefilterpats |
|
407 | 407 | # if file data starts with '\1\n', empty metadata block is |
|
408 | 408 | # prepended, which adds 4 bytes to filelog.size(). |
|
409 | 409 | or self.size() - 4 == fctx.size()) |
|
410 | 410 | or self.size() == fctx.size()): |
|
411 | 411 | return self._filelog.cmp(self._filenode, fctx.data()) |
|
412 | 412 | |
|
413 | 413 | return True |
|
414 | 414 | |
|
415 | 415 | def renamed(self): |
|
416 | 416 | """check if file was actually renamed in this changeset revision |
|
417 | 417 | |
|
418 | 418 | If rename logged in file revision, we report copy for changeset only |
|
419 | 419 | if file revisions linkrev points back to the changeset in question |
|
420 | 420 | or both changeset parents contain different file revisions. |
|
421 | 421 | """ |
|
422 | 422 | |
|
423 | 423 | renamed = self._filelog.renamed(self._filenode) |
|
424 | 424 | if not renamed: |
|
425 | 425 | return renamed |
|
426 | 426 | |
|
427 | 427 | if self.rev() == self.linkrev(): |
|
428 | 428 | return renamed |
|
429 | 429 | |
|
430 | 430 | name = self.path() |
|
431 | 431 | fnode = self._filenode |
|
432 | 432 | for p in self._changectx.parents(): |
|
433 | 433 | try: |
|
434 | 434 | if fnode == p.filenode(name): |
|
435 | 435 | return None |
|
436 | 436 | except error.LookupError: |
|
437 | 437 | pass |
|
438 | 438 | return renamed |
|
439 | 439 | |
|
440 | 440 | def parents(self): |
|
441 | 441 | p = self._path |
|
442 | 442 | fl = self._filelog |
|
443 | 443 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] |
|
444 | 444 | |
|
445 | 445 | r = self._filelog.renamed(self._filenode) |
|
446 | 446 | if r: |
|
447 | 447 | pl[0] = (r[0], r[1], None) |
|
448 | 448 | |
|
449 | 449 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
450 | 450 | for p, n, l in pl if n != nullid] |
|
451 | 451 | |
|
452 | 452 | def p1(self): |
|
453 | 453 | return self.parents()[0] |
|
454 | 454 | |
|
455 | 455 | def p2(self): |
|
456 | 456 | p = self.parents() |
|
457 | 457 | if len(p) == 2: |
|
458 | 458 | return p[1] |
|
459 | 459 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) |
|
460 | 460 | |
|
461 | 461 | def children(self): |
|
462 | 462 | # hard for renames |
|
463 | 463 | c = self._filelog.children(self._filenode) |
|
464 | 464 | return [filectx(self._repo, self._path, fileid=x, |
|
465 | 465 | filelog=self._filelog) for x in c] |
|
466 | 466 | |
|
467 | 467 | def annotate(self, follow=False, linenumber=None, diffopts=None): |
|
468 | 468 | '''returns a list of tuples of (ctx, line) for each line |
|
469 | 469 | in the file, where ctx is the filectx of the node where |
|
470 | 470 | that line was last changed. |
|
471 | 471 | This returns tuples of ((ctx, linenumber), line) for each line, |
|
472 | 472 | if "linenumber" parameter is NOT "None". |
|
473 | 473 | In such tuples, linenumber means one at the first appearance |
|
474 | 474 | in the managed file. |
|
475 | 475 | To reduce annotation cost, |
|
476 | 476 | this returns fixed value(False is used) as linenumber, |
|
477 | 477 | if "linenumber" parameter is "False".''' |
|
478 | 478 | |
|
479 | 479 | def decorate_compat(text, rev): |
|
480 | 480 | return ([rev] * len(text.splitlines()), text) |
|
481 | 481 | |
|
482 | 482 | def without_linenumber(text, rev): |
|
483 | 483 | return ([(rev, False)] * len(text.splitlines()), text) |
|
484 | 484 | |
|
485 | 485 | def with_linenumber(text, rev): |
|
486 | 486 | size = len(text.splitlines()) |
|
487 | 487 | return ([(rev, i) for i in xrange(1, size + 1)], text) |
|
488 | 488 | |
|
489 | 489 | decorate = (((linenumber is None) and decorate_compat) or |
|
490 | 490 | (linenumber and with_linenumber) or |
|
491 | 491 | without_linenumber) |
|
492 | 492 | |
|
493 | 493 | def pair(parent, child): |
|
494 | 494 | blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts, |
|
495 | 495 | refine=True) |
|
496 | 496 | for (a1, a2, b1, b2), t in blocks: |
|
497 | 497 | # Changed blocks ('!') or blocks made only of blank lines ('~') |
|
498 | 498 | # belong to the child. |
|
499 | 499 | if t == '=': |
|
500 | 500 | child[0][b1:b2] = parent[0][a1:a2] |
|
501 | 501 | return child |
|
502 | 502 | |
|
503 | 503 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
504 | 504 | def getctx(path, fileid): |
|
505 | 505 | log = path == self._path and self._filelog or getlog(path) |
|
506 | 506 | return filectx(self._repo, path, fileid=fileid, filelog=log) |
|
507 | 507 | getctx = util.lrucachefunc(getctx) |
|
508 | 508 | |
|
509 | 509 | def parents(f): |
|
510 | 510 | # we want to reuse filectx objects as much as possible |
|
511 | 511 | p = f._path |
|
512 | 512 | if f._filerev is None: # working dir |
|
513 | 513 | pl = [(n.path(), n.filerev()) for n in f.parents()] |
|
514 | 514 | else: |
|
515 | 515 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] |
|
516 | 516 | |
|
517 | 517 | if follow: |
|
518 | 518 | r = f.renamed() |
|
519 | 519 | if r: |
|
520 | 520 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) |
|
521 | 521 | |
|
522 | 522 | return [getctx(p, n) for p, n in pl if n != nullrev] |
|
523 | 523 | |
|
524 | 524 | # use linkrev to find the first changeset where self appeared |
|
525 | 525 | if self.rev() != self.linkrev(): |
|
526 | 526 | base = self.filectx(self.filerev()) |
|
527 | 527 | else: |
|
528 | 528 | base = self |
|
529 | 529 | |
|
530 | 530 | # This algorithm would prefer to be recursive, but Python is a |
|
531 | 531 | # bit recursion-hostile. Instead we do an iterative |
|
532 | 532 | # depth-first search. |
|
533 | 533 | |
|
534 | 534 | visit = [base] |
|
535 | 535 | hist = {} |
|
536 | 536 | pcache = {} |
|
537 | 537 | needed = {base: 1} |
|
538 | 538 | while visit: |
|
539 | 539 | f = visit[-1] |
|
540 | 540 | if f not in pcache: |
|
541 | 541 | pcache[f] = parents(f) |
|
542 | 542 | |
|
543 | 543 | ready = True |
|
544 | 544 | pl = pcache[f] |
|
545 | 545 | for p in pl: |
|
546 | 546 | if p not in hist: |
|
547 | 547 | ready = False |
|
548 | 548 | visit.append(p) |
|
549 | 549 | needed[p] = needed.get(p, 0) + 1 |
|
550 | 550 | if ready: |
|
551 | 551 | visit.pop() |
|
552 | 552 | curr = decorate(f.data(), f) |
|
553 | 553 | for p in pl: |
|
554 | 554 | curr = pair(hist[p], curr) |
|
555 | 555 | if needed[p] == 1: |
|
556 | 556 | del hist[p] |
|
557 | 557 | else: |
|
558 | 558 | needed[p] -= 1 |
|
559 | 559 | |
|
560 | 560 | hist[f] = curr |
|
561 | 561 | pcache[f] = [] |
|
562 | 562 | |
|
563 | 563 | return zip(hist[base][0], hist[base][1].splitlines(True)) |
|
564 | 564 | |
|
565 | 565 | def ancestor(self, fc2, actx=None): |
|
566 | 566 | """ |
|
567 | 567 | find the common ancestor file context, if any, of self, and fc2 |
|
568 | 568 | |
|
569 | 569 | If actx is given, it must be the changectx of the common ancestor |
|
570 | 570 | of self's and fc2's respective changesets. |
|
571 | 571 | """ |
|
572 | 572 | |
|
573 | 573 | if actx is None: |
|
574 | 574 | actx = self.changectx().ancestor(fc2.changectx()) |
|
575 | 575 | |
|
576 | 576 | # the trivial case: changesets are unrelated, files must be too |
|
577 | 577 | if not actx: |
|
578 | 578 | return None |
|
579 | 579 | |
|
580 | 580 | # the easy case: no (relevant) renames |
|
581 | 581 | if fc2.path() == self.path() and self.path() in actx: |
|
582 | 582 | return actx[self.path()] |
|
583 | 583 | acache = {} |
|
584 | 584 | |
|
585 | 585 | # prime the ancestor cache for the working directory |
|
586 | 586 | for c in (self, fc2): |
|
587 | 587 | if c._filerev is None: |
|
588 | 588 | pl = [(n.path(), n.filenode()) for n in c.parents()] |
|
589 | 589 | acache[(c._path, None)] = pl |
|
590 | 590 | |
|
591 | 591 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} |
|
592 | 592 | def parents(vertex): |
|
593 | 593 | if vertex in acache: |
|
594 | 594 | return acache[vertex] |
|
595 | 595 | f, n = vertex |
|
596 | 596 | if f not in flcache: |
|
597 | 597 | flcache[f] = self._repo.file(f) |
|
598 | 598 | fl = flcache[f] |
|
599 | 599 | pl = [(f, p) for p in fl.parents(n) if p != nullid] |
|
600 | 600 | re = fl.renamed(n) |
|
601 | 601 | if re: |
|
602 | 602 | pl.append(re) |
|
603 | 603 | acache[vertex] = pl |
|
604 | 604 | return pl |
|
605 | 605 | |
|
606 | 606 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
|
607 | 607 | v = ancestor.ancestor(a, b, parents) |
|
608 | 608 | if v: |
|
609 | 609 | f, n = v |
|
610 | 610 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
|
611 | 611 | |
|
612 | 612 | return None |
|
613 | 613 | |
|
614 | 614 | def ancestors(self, followfirst=False): |
|
615 | 615 | visit = {} |
|
616 | 616 | c = self |
|
617 | 617 | cut = followfirst and 1 or None |
|
618 | 618 | while True: |
|
619 | 619 | for parent in c.parents()[:cut]: |
|
620 | 620 | visit[(parent.rev(), parent.node())] = parent |
|
621 | 621 | if not visit: |
|
622 | 622 | break |
|
623 | 623 | c = visit.pop(max(visit)) |
|
624 | 624 | yield c |
|
625 | 625 | |
|
626 | 626 | class workingctx(changectx): |
|
627 | 627 | """A workingctx object makes access to data related to |
|
628 | 628 | the current working directory convenient. |
|
629 | 629 | date - any valid date string or (unixtime, offset), or None. |
|
630 | 630 | user - username string, or None. |
|
631 | 631 | extra - a dictionary of extra values, or None. |
|
632 | 632 | changes - a list of file lists as returned by localrepo.status() |
|
633 | 633 | or None to use the repository status. |
|
634 | 634 | """ |
|
635 | 635 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
636 | 636 | changes=None): |
|
637 | 637 | self._repo = repo |
|
638 | 638 | self._rev = None |
|
639 | 639 | self._node = None |
|
640 | 640 | self._text = text |
|
641 | 641 | if date: |
|
642 | 642 | self._date = util.parsedate(date) |
|
643 | 643 | if user: |
|
644 | 644 | self._user = user |
|
645 | 645 | if changes: |
|
646 | 646 | self._status = list(changes[:4]) |
|
647 | 647 | self._unknown = changes[4] |
|
648 | 648 | self._ignored = changes[5] |
|
649 | 649 | self._clean = changes[6] |
|
650 | 650 | else: |
|
651 | 651 | self._unknown = None |
|
652 | 652 | self._ignored = None |
|
653 | 653 | self._clean = None |
|
654 | 654 | |
|
655 | 655 | self._extra = {} |
|
656 | 656 | if extra: |
|
657 | 657 | self._extra = extra.copy() |
|
658 | 658 | if 'branch' not in self._extra: |
|
659 | 659 | try: |
|
660 | 660 | branch = encoding.fromlocal(self._repo.dirstate.branch()) |
|
661 | 661 | except UnicodeDecodeError: |
|
662 | 662 | raise util.Abort(_('branch name not in UTF-8!')) |
|
663 | 663 | self._extra['branch'] = branch |
|
664 | 664 | if self._extra['branch'] == '': |
|
665 | 665 | self._extra['branch'] = 'default' |
|
666 | 666 | |
|
667 | 667 | def __str__(self): |
|
668 | 668 | return str(self._parents[0]) + "+" |
|
669 | 669 | |
|
670 | 670 | def __repr__(self): |
|
671 | 671 | return "<workingctx %s>" % str(self) |
|
672 | 672 | |
|
673 | 673 | def __nonzero__(self): |
|
674 | 674 | return True |
|
675 | 675 | |
|
676 | 676 | def __contains__(self, key): |
|
677 | 677 | return self._repo.dirstate[key] not in "?r" |
|
678 | 678 | |
|
679 | 679 | def _buildflagfunc(self): |
|
680 | 680 | # Create a fallback function for getting file flags when the |
|
681 | 681 | # filesystem doesn't support them |
|
682 | 682 | |
|
683 | 683 | copiesget = self._repo.dirstate.copies().get |
|
684 | 684 | |
|
685 | 685 | if len(self._parents) < 2: |
|
686 | 686 | # when we have one parent, it's easy: copy from parent |
|
687 | 687 | man = self._parents[0].manifest() |
|
688 | 688 | def func(f): |
|
689 | 689 | f = copiesget(f, f) |
|
690 | 690 | return man.flags(f) |
|
691 | 691 | else: |
|
692 | 692 | # merges are tricky: we try to reconstruct the unstored |
|
693 | 693 | # result from the merge (issue1802) |
|
694 | 694 | p1, p2 = self._parents |
|
695 | 695 | pa = p1.ancestor(p2) |
|
696 | 696 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() |
|
697 | 697 | |
|
698 | 698 | def func(f): |
|
699 | 699 | f = copiesget(f, f) # may be wrong for merges with copies |
|
700 | 700 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) |
|
701 | 701 | if fl1 == fl2: |
|
702 | 702 | return fl1 |
|
703 | 703 | if fl1 == fla: |
|
704 | 704 | return fl2 |
|
705 | 705 | if fl2 == fla: |
|
706 | 706 | return fl1 |
|
707 | 707 | return '' # punt for conflicts |
|
708 | 708 | |
|
709 | 709 | return func |
|
710 | 710 | |
|
711 | 711 | @propertycache |
|
712 | 712 | def _flagfunc(self): |
|
713 | 713 | return self._repo.dirstate.flagfunc(self._buildflagfunc) |
|
714 | 714 | |
|
715 | 715 | @propertycache |
|
716 | 716 | def _manifest(self): |
|
717 | 717 | """generate a manifest corresponding to the working directory""" |
|
718 | 718 | |
|
719 | 719 | man = self._parents[0].manifest().copy() |
|
720 | 720 | if len(self._parents) > 1: |
|
721 | 721 | man2 = self.p2().manifest() |
|
722 | 722 | def getman(f): |
|
723 | 723 | if f in man: |
|
724 | 724 | return man |
|
725 | 725 | return man2 |
|
726 | 726 | else: |
|
727 | 727 | getman = lambda f: man |
|
728 | 728 | |
|
729 | 729 | copied = self._repo.dirstate.copies() |
|
730 | 730 | ff = self._flagfunc |
|
731 | 731 | modified, added, removed, deleted = self._status |
|
732 | 732 | for i, l in (("a", added), ("m", modified)): |
|
733 | 733 | for f in l: |
|
734 | 734 | orig = copied.get(f, f) |
|
735 | 735 | man[f] = getman(orig).get(orig, nullid) + i |
|
736 | 736 | try: |
|
737 | 737 | man.set(f, ff(f)) |
|
738 | 738 | except OSError: |
|
739 | 739 | pass |
|
740 | 740 | |
|
741 | 741 | for f in deleted + removed: |
|
742 | 742 | if f in man: |
|
743 | 743 | del man[f] |
|
744 | 744 | |
|
745 | 745 | return man |
|
746 | 746 | |
|
747 | 747 | def __iter__(self): |
|
748 | 748 | d = self._repo.dirstate |
|
749 | 749 | for f in d: |
|
750 | 750 | if d[f] != 'r': |
|
751 | 751 | yield f |
|
752 | 752 | |
|
753 | 753 | @propertycache |
|
754 | 754 | def _status(self): |
|
755 | 755 | return self._repo.status()[:4] |
|
756 | 756 | |
|
757 | 757 | @propertycache |
|
758 | 758 | def _user(self): |
|
759 | 759 | return self._repo.ui.username() |
|
760 | 760 | |
|
761 | 761 | @propertycache |
|
762 | 762 | def _date(self): |
|
763 | 763 | return util.makedate() |
|
764 | 764 | |
|
765 | 765 | @propertycache |
|
766 | 766 | def _parents(self): |
|
767 | 767 | p = self._repo.dirstate.parents() |
|
768 | 768 | if p[1] == nullid: |
|
769 | 769 | p = p[:-1] |
|
770 | 770 | self._parents = [changectx(self._repo, x) for x in p] |
|
771 | 771 | return self._parents |
|
772 | 772 | |
|
773 | 773 | def status(self, ignored=False, clean=False, unknown=False): |
|
774 | 774 | """Explicit status query |
|
775 | 775 | Unless this method is used to query the working copy status, the |
|
776 | 776 | _status property will implicitly read the status using its default |
|
777 | 777 | arguments.""" |
|
778 | 778 | stat = self._repo.status(ignored=ignored, clean=clean, unknown=unknown) |
|
779 | 779 | self._unknown = self._ignored = self._clean = None |
|
780 | 780 | if unknown: |
|
781 | 781 | self._unknown = stat[4] |
|
782 | 782 | if ignored: |
|
783 | 783 | self._ignored = stat[5] |
|
784 | 784 | if clean: |
|
785 | 785 | self._clean = stat[6] |
|
786 | 786 | self._status = stat[:4] |
|
787 | 787 | return stat |
|
788 | 788 | |
|
789 | 789 | def manifest(self): |
|
790 | 790 | return self._manifest |
|
791 | 791 | def user(self): |
|
792 | 792 | return self._user or self._repo.ui.username() |
|
793 | 793 | def date(self): |
|
794 | 794 | return self._date |
|
795 | 795 | def description(self): |
|
796 | 796 | return self._text |
|
797 | 797 | def files(self): |
|
798 | 798 | return sorted(self._status[0] + self._status[1] + self._status[2]) |
|
799 | 799 | |
|
800 | 800 | def modified(self): |
|
801 | 801 | return self._status[0] |
|
802 | 802 | def added(self): |
|
803 | 803 | return self._status[1] |
|
804 | 804 | def removed(self): |
|
805 | 805 | return self._status[2] |
|
806 | 806 | def deleted(self): |
|
807 | 807 | return self._status[3] |
|
808 | 808 | def unknown(self): |
|
809 | 809 | assert self._unknown is not None # must call status first |
|
810 | 810 | return self._unknown |
|
811 | 811 | def ignored(self): |
|
812 | 812 | assert self._ignored is not None # must call status first |
|
813 | 813 | return self._ignored |
|
814 | 814 | def clean(self): |
|
815 | 815 | assert self._clean is not None # must call status first |
|
816 | 816 | return self._clean |
|
817 | 817 | def branch(self): |
|
818 | 818 | return encoding.tolocal(self._extra['branch']) |
|
819 | 819 | def extra(self): |
|
820 | 820 | return self._extra |
|
821 | 821 | |
|
822 | 822 | def tags(self): |
|
823 | 823 | t = [] |
|
824 | 824 | for p in self.parents(): |
|
825 | 825 | t.extend(p.tags()) |
|
826 | 826 | return t |
|
827 | 827 | |
|
828 | 828 | def bookmarks(self): |
|
829 | 829 | b = [] |
|
830 | 830 | for p in self.parents(): |
|
831 | 831 | b.extend(p.bookmarks()) |
|
832 | 832 | return b |
|
833 | 833 | |
|
834 | 834 | def phase(self): |
|
835 | 835 | phase = phases.draft # default phase to draft |
|
836 | 836 | for p in self.parents(): |
|
837 | 837 | phase = max(phase, p.phase()) |
|
838 | 838 | return phase |
|
839 | 839 | |
|
840 | 840 | def hidden(self): |
|
841 | 841 | return False |
|
842 | 842 | |
|
843 | 843 | def children(self): |
|
844 | 844 | return [] |
|
845 | 845 | |
|
846 | 846 | def flags(self, path): |
|
847 | 847 | if '_manifest' in self.__dict__: |
|
848 | 848 | try: |
|
849 | 849 | return self._manifest.flags(path) |
|
850 | 850 | except KeyError: |
|
851 | 851 | return '' |
|
852 | 852 | |
|
853 | 853 | try: |
|
854 | 854 | return self._flagfunc(path) |
|
855 | 855 | except OSError: |
|
856 | 856 | return '' |
|
857 | 857 | |
|
858 | 858 | def filectx(self, path, filelog=None): |
|
859 | 859 | """get a file context from the working directory""" |
|
860 | 860 | return workingfilectx(self._repo, path, workingctx=self, |
|
861 | 861 | filelog=filelog) |
|
862 | 862 | |
|
863 | 863 | def ancestor(self, c2): |
|
864 | 864 | """return the ancestor context of self and c2""" |
|
865 | 865 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
866 | 866 | |
|
867 | 867 | def walk(self, match): |
|
868 | 868 | return sorted(self._repo.dirstate.walk(match, self.substate.keys(), |
|
869 | 869 | True, False)) |
|
870 | 870 | |
|
871 | 871 | def dirty(self, missing=False): |
|
872 | 872 | "check whether a working directory is modified" |
|
873 | 873 | # check subrepos first |
|
874 | 874 | for s in self.substate: |
|
875 | 875 | if self.sub(s).dirty(): |
|
876 | 876 | return True |
|
877 | 877 | # check current working dir |
|
878 | 878 | return (self.p2() or self.branch() != self.p1().branch() or |
|
879 | 879 | self.modified() or self.added() or self.removed() or |
|
880 | 880 | (missing and self.deleted())) |
|
881 | 881 | |
|
882 | 882 | def add(self, list, prefix=""): |
|
883 | 883 | join = lambda f: os.path.join(prefix, f) |
|
884 | 884 | wlock = self._repo.wlock() |
|
885 | 885 | ui, ds = self._repo.ui, self._repo.dirstate |
|
886 | 886 | try: |
|
887 | 887 | rejected = [] |
|
888 | 888 | for f in list: |
|
889 | 889 | scmutil.checkportable(ui, join(f)) |
|
890 | 890 | p = self._repo.wjoin(f) |
|
891 | 891 | try: |
|
892 | 892 | st = os.lstat(p) |
|
893 | 893 | except OSError: |
|
894 | 894 | ui.warn(_("%s does not exist!\n") % join(f)) |
|
895 | 895 | rejected.append(f) |
|
896 | 896 | continue |
|
897 | 897 | if st.st_size > 10000000: |
|
898 | 898 | ui.warn(_("%s: up to %d MB of RAM may be required " |
|
899 | 899 | "to manage this file\n" |
|
900 | 900 | "(use 'hg revert %s' to cancel the " |
|
901 | 901 | "pending addition)\n") |
|
902 | 902 | % (f, 3 * st.st_size // 1000000, join(f))) |
|
903 | 903 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
904 | 904 | ui.warn(_("%s not added: only files and symlinks " |
|
905 | 905 | "supported currently\n") % join(f)) |
|
906 | 906 | rejected.append(p) |
|
907 | 907 | elif ds[f] in 'amn': |
|
908 | 908 | ui.warn(_("%s already tracked!\n") % join(f)) |
|
909 | 909 | elif ds[f] == 'r': |
|
910 | 910 | ds.normallookup(f) |
|
911 | 911 | else: |
|
912 | 912 | ds.add(f) |
|
913 | 913 | return rejected |
|
914 | 914 | finally: |
|
915 | 915 | wlock.release() |
|
916 | 916 | |
|
917 | 917 | def forget(self, files, prefix=""): |
|
918 | 918 | join = lambda f: os.path.join(prefix, f) |
|
919 | 919 | wlock = self._repo.wlock() |
|
920 | 920 | try: |
|
921 | 921 | rejected = [] |
|
922 | 922 | for f in files: |
|
923 | 923 | if f not in self._repo.dirstate: |
|
924 | 924 | self._repo.ui.warn(_("%s not tracked!\n") % join(f)) |
|
925 | 925 | rejected.append(f) |
|
926 | 926 | elif self._repo.dirstate[f] != 'a': |
|
927 | 927 | self._repo.dirstate.remove(f) |
|
928 | 928 | else: |
|
929 | 929 | self._repo.dirstate.drop(f) |
|
930 | 930 | return rejected |
|
931 | 931 | finally: |
|
932 | 932 | wlock.release() |
|
933 | 933 | |
|
934 | 934 | def ancestors(self, followfirst=False): |
|
935 | 935 | cut = followfirst and 1 or None |
|
936 | 936 | for a in self._repo.changelog.ancestors( |
|
937 | 937 | *[p.rev() for p in self._parents[:cut]]): |
|
938 | 938 | yield changectx(self._repo, a) |
|
939 | 939 | |
|
940 | 940 | def undelete(self, list): |
|
941 | 941 | pctxs = self.parents() |
|
942 | 942 | wlock = self._repo.wlock() |
|
943 | 943 | try: |
|
944 | 944 | for f in list: |
|
945 | 945 | if self._repo.dirstate[f] != 'r': |
|
946 | 946 | self._repo.ui.warn(_("%s not removed!\n") % f) |
|
947 | 947 | else: |
|
948 | 948 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] |
|
949 | 949 | t = fctx.data() |
|
950 | 950 | self._repo.wwrite(f, t, fctx.flags()) |
|
951 | 951 | self._repo.dirstate.normal(f) |
|
952 | 952 | finally: |
|
953 | 953 | wlock.release() |
|
954 | 954 | |
|
955 | 955 | def copy(self, source, dest): |
|
956 | 956 | p = self._repo.wjoin(dest) |
|
957 | 957 | if not os.path.lexists(p): |
|
958 | 958 | self._repo.ui.warn(_("%s does not exist!\n") % dest) |
|
959 | 959 | elif not (os.path.isfile(p) or os.path.islink(p)): |
|
960 | 960 | self._repo.ui.warn(_("copy failed: %s is not a file or a " |
|
961 | 961 | "symbolic link\n") % dest) |
|
962 | 962 | else: |
|
963 | 963 | wlock = self._repo.wlock() |
|
964 | 964 | try: |
|
965 | 965 | if self._repo.dirstate[dest] in '?r': |
|
966 | 966 | self._repo.dirstate.add(dest) |
|
967 | 967 | self._repo.dirstate.copy(source, dest) |
|
968 | 968 | finally: |
|
969 | 969 | wlock.release() |
|
970 | 970 | |
|
971 | 971 | def dirs(self): |
|
972 | 972 | return self._repo.dirstate.dirs() |
|
973 | 973 | |
|
974 | 974 | class workingfilectx(filectx): |
|
975 | 975 | """A workingfilectx object makes access to data related to a particular |
|
976 | 976 | file in the working directory convenient.""" |
|
977 | 977 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
978 | 978 | """changeid can be a changeset revision, node, or tag. |
|
979 | 979 | fileid can be a file revision or node.""" |
|
980 | 980 | self._repo = repo |
|
981 | 981 | self._path = path |
|
982 | 982 | self._changeid = None |
|
983 | 983 | self._filerev = self._filenode = None |
|
984 | 984 | |
|
985 | 985 | if filelog: |
|
986 | 986 | self._filelog = filelog |
|
987 | 987 | if workingctx: |
|
988 | 988 | self._changectx = workingctx |
|
989 | 989 | |
|
990 | 990 | @propertycache |
|
991 | 991 | def _changectx(self): |
|
992 | 992 | return workingctx(self._repo) |
|
993 | 993 | |
|
994 | 994 | def __nonzero__(self): |
|
995 | 995 | return True |
|
996 | 996 | |
|
997 | 997 | def __str__(self): |
|
998 | 998 | return "%s@%s" % (self.path(), self._changectx) |
|
999 | 999 | |
|
1000 | 1000 | def __repr__(self): |
|
1001 | 1001 | return "<workingfilectx %s>" % str(self) |
|
1002 | 1002 | |
|
1003 | 1003 | def data(self): |
|
1004 | 1004 | return self._repo.wread(self._path) |
|
1005 | 1005 | def renamed(self): |
|
1006 | 1006 | rp = self._repo.dirstate.copied(self._path) |
|
1007 | 1007 | if not rp: |
|
1008 | 1008 | return None |
|
1009 | 1009 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
1010 | 1010 | |
|
1011 | 1011 | def parents(self): |
|
1012 | 1012 | '''return parent filectxs, following copies if necessary''' |
|
1013 | 1013 | def filenode(ctx, path): |
|
1014 | 1014 | return ctx._manifest.get(path, nullid) |
|
1015 | 1015 | |
|
1016 | 1016 | path = self._path |
|
1017 | 1017 | fl = self._filelog |
|
1018 | 1018 | pcl = self._changectx._parents |
|
1019 | 1019 | renamed = self.renamed() |
|
1020 | 1020 | |
|
1021 | 1021 | if renamed: |
|
1022 | 1022 | pl = [renamed + (None,)] |
|
1023 | 1023 | else: |
|
1024 | 1024 | pl = [(path, filenode(pcl[0], path), fl)] |
|
1025 | 1025 | |
|
1026 | 1026 | for pc in pcl[1:]: |
|
1027 | 1027 | pl.append((path, filenode(pc, path), fl)) |
|
1028 | 1028 | |
|
1029 | 1029 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
1030 | 1030 | for p, n, l in pl if n != nullid] |
|
1031 | 1031 | |
|
1032 | 1032 | def children(self): |
|
1033 | 1033 | return [] |
|
1034 | 1034 | |
|
1035 | 1035 | def size(self): |
|
1036 | 1036 | return os.lstat(self._repo.wjoin(self._path)).st_size |
|
1037 | 1037 | def date(self): |
|
1038 | 1038 | t, tz = self._changectx.date() |
|
1039 | 1039 | try: |
|
1040 | 1040 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) |
|
1041 | 1041 | except OSError, err: |
|
1042 | 1042 | if err.errno != errno.ENOENT: |
|
1043 | 1043 | raise |
|
1044 | 1044 | return (t, tz) |
|
1045 | 1045 | |
|
1046 | 1046 | def cmp(self, fctx): |
|
1047 | 1047 | """compare with other file context |
|
1048 | 1048 | |
|
1049 | 1049 | returns True if different than fctx. |
|
1050 | 1050 | """ |
|
1051 | 1051 | # fctx should be a filectx (not a wfctx) |
|
1052 | 1052 | # invert comparison to reuse the same code path |
|
1053 | 1053 | return fctx.cmp(self) |
|
1054 | 1054 | |
|
1055 | 1055 | class memctx(object): |
|
1056 | 1056 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
1057 | 1057 | |
|
1058 | 1058 | Revision information is supplied at initialization time while |
|
1059 | 1059 | related files data and is made available through a callback |
|
1060 | 1060 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
1061 | 1061 | sequence of two parent revisions identifiers (pass None for every |
|
1062 | 1062 | missing parent), 'text' is the commit message and 'files' lists |
|
1063 | 1063 | names of files touched by the revision (normalized and relative to |
|
1064 | 1064 | repository root). |
|
1065 | 1065 | |
|
1066 | 1066 | filectxfn(repo, memctx, path) is a callable receiving the |
|
1067 | 1067 | repository, the current memctx object and the normalized path of |
|
1068 | 1068 | requested file, relative to repository root. It is fired by the |
|
1069 | 1069 | commit function for every file in 'files', but calls order is |
|
1070 | 1070 | undefined. If the file is available in the revision being |
|
1071 | 1071 | committed (updated or added), filectxfn returns a memfilectx |
|
1072 | 1072 | object. If the file was removed, filectxfn raises an |
|
1073 | 1073 | IOError. Moved files are represented by marking the source file |
|
1074 | 1074 | removed and the new file added with copy information (see |
|
1075 | 1075 | memfilectx). |
|
1076 | 1076 | |
|
1077 | 1077 | user receives the committer name and defaults to current |
|
1078 | 1078 | repository username, date is the commit date in any format |
|
1079 | 1079 | supported by util.parsedate() and defaults to current date, extra |
|
1080 | 1080 | is a dictionary of metadata or is left empty. |
|
1081 | 1081 | """ |
|
1082 | 1082 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
1083 | 1083 | date=None, extra=None): |
|
1084 | 1084 | self._repo = repo |
|
1085 | 1085 | self._rev = None |
|
1086 | 1086 | self._node = None |
|
1087 | 1087 | self._text = text |
|
1088 | 1088 | self._date = date and util.parsedate(date) or util.makedate() |
|
1089 | 1089 | self._user = user |
|
1090 | 1090 | parents = [(p or nullid) for p in parents] |
|
1091 | 1091 | p1, p2 = parents |
|
1092 | 1092 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
|
1093 | 1093 | files = sorted(set(files)) |
|
1094 | 1094 | self._status = [files, [], [], [], []] |
|
1095 | 1095 | self._filectxfn = filectxfn |
|
1096 | 1096 | |
|
1097 | 1097 | self._extra = extra and extra.copy() or {} |
|
1098 | 1098 | if self._extra.get('branch', '') == '': |
|
1099 | 1099 | self._extra['branch'] = 'default' |
|
1100 | 1100 | |
|
1101 | 1101 | def __str__(self): |
|
1102 | 1102 | return str(self._parents[0]) + "+" |
|
1103 | 1103 | |
|
1104 | 1104 | def __int__(self): |
|
1105 | 1105 | return self._rev |
|
1106 | 1106 | |
|
1107 | 1107 | def __nonzero__(self): |
|
1108 | 1108 | return True |
|
1109 | 1109 | |
|
1110 | 1110 | def __getitem__(self, key): |
|
1111 | 1111 | return self.filectx(key) |
|
1112 | 1112 | |
|
1113 | 1113 | def p1(self): |
|
1114 | 1114 | return self._parents[0] |
|
1115 | 1115 | def p2(self): |
|
1116 | 1116 | return self._parents[1] |
|
1117 | 1117 | |
|
1118 | 1118 | def user(self): |
|
1119 | 1119 | return self._user or self._repo.ui.username() |
|
1120 | 1120 | def date(self): |
|
1121 | 1121 | return self._date |
|
1122 | 1122 | def description(self): |
|
1123 | 1123 | return self._text |
|
1124 | 1124 | def files(self): |
|
1125 | 1125 | return self.modified() |
|
1126 | 1126 | def modified(self): |
|
1127 | 1127 | return self._status[0] |
|
1128 | 1128 | def added(self): |
|
1129 | 1129 | return self._status[1] |
|
1130 | 1130 | def removed(self): |
|
1131 | 1131 | return self._status[2] |
|
1132 | 1132 | def deleted(self): |
|
1133 | 1133 | return self._status[3] |
|
1134 | 1134 | def unknown(self): |
|
1135 | 1135 | return self._status[4] |
|
1136 | 1136 | def ignored(self): |
|
1137 | 1137 | return self._status[5] |
|
1138 | 1138 | def clean(self): |
|
1139 | 1139 | return self._status[6] |
|
1140 | 1140 | def branch(self): |
|
1141 | 1141 | return encoding.tolocal(self._extra['branch']) |
|
1142 | 1142 | def extra(self): |
|
1143 | 1143 | return self._extra |
|
1144 | 1144 | def flags(self, f): |
|
1145 | 1145 | return self[f].flags() |
|
1146 | 1146 | |
|
1147 | 1147 | def parents(self): |
|
1148 | 1148 | """return contexts for each parent changeset""" |
|
1149 | 1149 | return self._parents |
|
1150 | 1150 | |
|
1151 | 1151 | def filectx(self, path, filelog=None): |
|
1152 | 1152 | """get a file context from the working directory""" |
|
1153 | 1153 | return self._filectxfn(self._repo, self, path) |
|
1154 | 1154 | |
|
1155 | 1155 | def commit(self): |
|
1156 | 1156 | """commit context to the repo""" |
|
1157 | 1157 | return self._repo.commitctx(self) |
|
1158 | 1158 | |
|
1159 | 1159 | class memfilectx(object): |
|
1160 | 1160 | """memfilectx represents an in-memory file to commit. |
|
1161 | 1161 | |
|
1162 | 1162 | See memctx for more details. |
|
1163 | 1163 | """ |
|
1164 | 1164 | def __init__(self, path, data, islink=False, isexec=False, copied=None): |
|
1165 | 1165 | """ |
|
1166 | 1166 | path is the normalized file path relative to repository root. |
|
1167 | 1167 | data is the file content as a string. |
|
1168 | 1168 | islink is True if the file is a symbolic link. |
|
1169 | 1169 | isexec is True if the file is executable. |
|
1170 | 1170 | copied is the source file path if current file was copied in the |
|
1171 | 1171 | revision being committed, or None.""" |
|
1172 | 1172 | self._path = path |
|
1173 | 1173 | self._data = data |
|
1174 | 1174 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
1175 | 1175 | self._copied = None |
|
1176 | 1176 | if copied: |
|
1177 | 1177 | self._copied = (copied, nullid) |
|
1178 | 1178 | |
|
1179 | 1179 | def __nonzero__(self): |
|
1180 | 1180 | return True |
|
1181 | 1181 | def __str__(self): |
|
1182 | 1182 | return "%s@%s" % (self.path(), self._changectx) |
|
1183 | 1183 | def path(self): |
|
1184 | 1184 | return self._path |
|
1185 | 1185 | def data(self): |
|
1186 | 1186 | return self._data |
|
1187 | 1187 | def flags(self): |
|
1188 | 1188 | return self._flags |
|
1189 | 1189 | def isexec(self): |
|
1190 | 1190 | return 'x' in self._flags |
|
1191 | 1191 | def islink(self): |
|
1192 | 1192 | return 'l' in self._flags |
|
1193 | 1193 | def renamed(self): |
|
1194 | 1194 | return self._copied |
@@ -1,342 +1,342 b'' | |||
|
1 | 1 | # mdiff.py - diff and patch routines for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from i18n import _ |
|
9 | 9 | import bdiff, mpatch, util |
|
10 | 10 | import re, struct |
|
11 | 11 | |
|
12 | 12 | def splitnewlines(text): |
|
13 | 13 | '''like str.splitlines, but only split on newlines.''' |
|
14 | 14 | lines = [l + '\n' for l in text.split('\n')] |
|
15 | 15 | if lines: |
|
16 | 16 | if lines[-1] == '\n': |
|
17 | 17 | lines.pop() |
|
18 | 18 | else: |
|
19 | 19 | lines[-1] = lines[-1][:-1] |
|
20 | 20 | return lines |
|
21 | 21 | |
|
22 | 22 | class diffopts(object): |
|
23 | 23 | '''context is the number of context lines |
|
24 | 24 | text treats all files as text |
|
25 | 25 | showfunc enables diff -p output |
|
26 | 26 | git enables the git extended patch format |
|
27 | 27 | nodates removes dates from diff headers |
|
28 | 28 | ignorews ignores all whitespace changes in the diff |
|
29 | 29 | ignorewsamount ignores changes in the amount of whitespace |
|
30 | 30 | ignoreblanklines ignores changes whose lines are all blank |
|
31 | 31 | upgrade generates git diffs to avoid data loss |
|
32 | 32 | ''' |
|
33 | 33 | |
|
34 | 34 | defaults = { |
|
35 | 35 | 'context': 3, |
|
36 | 36 | 'text': False, |
|
37 | 37 | 'showfunc': False, |
|
38 | 38 | 'git': False, |
|
39 | 39 | 'nodates': False, |
|
40 | 40 | 'ignorews': False, |
|
41 | 41 | 'ignorewsamount': False, |
|
42 | 42 | 'ignoreblanklines': False, |
|
43 | 43 | 'upgrade': False, |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | __slots__ = defaults.keys() |
|
47 | 47 | |
|
48 | 48 | def __init__(self, **opts): |
|
49 | 49 | for k in self.__slots__: |
|
50 | 50 | v = opts.get(k) |
|
51 | 51 | if v is None: |
|
52 | 52 | v = self.defaults[k] |
|
53 | 53 | setattr(self, k, v) |
|
54 | 54 | |
|
55 | 55 | try: |
|
56 | 56 | self.context = int(self.context) |
|
57 | 57 | except ValueError: |
|
58 | 58 | raise util.Abort(_('diff context lines count must be ' |
|
59 | 59 | 'an integer, not %r') % self.context) |
|
60 | 60 | |
|
61 | 61 | def copy(self, **kwargs): |
|
62 | 62 | opts = dict((k, getattr(self, k)) for k in self.defaults) |
|
63 | 63 | opts.update(kwargs) |
|
64 | 64 | return diffopts(**opts) |
|
65 | 65 | |
|
66 | 66 | defaultopts = diffopts() |
|
67 | 67 | |
|
68 | 68 | def wsclean(opts, text, blank=True): |
|
69 | 69 | if opts.ignorews: |
|
70 | 70 | text = bdiff.fixws(text, 1) |
|
71 | 71 | elif opts.ignorewsamount: |
|
72 | 72 | text = bdiff.fixws(text, 0) |
|
73 | 73 | if blank and opts.ignoreblanklines: |
|
74 | 74 | text = re.sub('\n+', '\n', text).strip('\n') |
|
75 | 75 | return text |
|
76 | 76 | |
|
77 | 77 | def splitblock(base1, lines1, base2, lines2, opts): |
|
78 | 78 | # The input lines matches except for interwoven blank lines. We |
|
79 | 79 | # transform it into a sequence of matching blocks and blank blocks. |
|
80 | 80 | lines1 = [(wsclean(opts, l) and 1 or 0) for l in lines1] |
|
81 | 81 | lines2 = [(wsclean(opts, l) and 1 or 0) for l in lines2] |
|
82 | 82 | s1, e1 = 0, len(lines1) |
|
83 | 83 | s2, e2 = 0, len(lines2) |
|
84 | 84 | while s1 < e1 or s2 < e2: |
|
85 | 85 | i1, i2, btype = s1, s2, '=' |
|
86 | 86 | if (i1 >= e1 or lines1[i1] == 0 |
|
87 | 87 | or i2 >= e2 or lines2[i2] == 0): |
|
88 | 88 | # Consume the block of blank lines |
|
89 | 89 | btype = '~' |
|
90 | 90 | while i1 < e1 and lines1[i1] == 0: |
|
91 | 91 | i1 += 1 |
|
92 | 92 | while i2 < e2 and lines2[i2] == 0: |
|
93 | 93 | i2 += 1 |
|
94 | 94 | else: |
|
95 | 95 | # Consume the matching lines |
|
96 | 96 | while i1 < e1 and lines1[i1] == 1 and lines2[i2] == 1: |
|
97 | 97 | i1 += 1 |
|
98 | 98 | i2 += 1 |
|
99 | 99 | yield [base1 + s1, base1 + i1, base2 + s2, base2 + i2], btype |
|
100 | 100 | s1 = i1 |
|
101 | 101 | s2 = i2 |
|
102 | 102 | |
|
103 | 103 | def allblocks(text1, text2, opts=None, lines1=None, lines2=None, refine=False): |
|
104 | 104 | """Return (block, type) tuples, where block is an mdiff.blocks |
|
105 | 105 | line entry. type is '=' for blocks matching exactly one another |
|
106 | 106 | (bdiff blocks), '!' for non-matching blocks and '~' for blocks |
|
107 | 107 | matching only after having filtered blank lines. If refine is True, |
|
108 | 108 | then '~' blocks are refined and are only made of blank lines. |
|
109 | 109 | line1 and line2 are text1 and text2 split with splitnewlines() if |
|
110 | 110 | they are already available. |
|
111 | 111 | """ |
|
112 | 112 | if opts is None: |
|
113 | 113 | opts = defaultopts |
|
114 | 114 | if opts.ignorews or opts.ignorewsamount: |
|
115 | 115 | text1 = wsclean(opts, text1, False) |
|
116 | 116 | text2 = wsclean(opts, text2, False) |
|
117 | 117 | diff = bdiff.blocks(text1, text2) |
|
118 | 118 | for i, s1 in enumerate(diff): |
|
119 | 119 | # The first match is special. |
|
120 | 120 | # we've either found a match starting at line 0 or a match later |
|
121 | 121 | # in the file. If it starts later, old and new below will both be |
|
122 | 122 | # empty and we'll continue to the next match. |
|
123 | 123 | if i > 0: |
|
124 | 124 | s = diff[i - 1] |
|
125 | 125 | else: |
|
126 | 126 | s = [0, 0, 0, 0] |
|
127 | 127 | s = [s[1], s1[0], s[3], s1[2]] |
|
128 | 128 | |
|
129 | 129 | # bdiff sometimes gives huge matches past eof, this check eats them, |
|
130 | 130 | # and deals with the special first match case described above |
|
131 | 131 | if s[0] != s[1] or s[2] != s[3]: |
|
132 | 132 | type = '!' |
|
133 | 133 | if opts.ignoreblanklines: |
|
134 | 134 | if lines1 is None: |
|
135 | 135 | lines1 = splitnewlines(text1) |
|
136 | 136 | if lines2 is None: |
|
137 | 137 | lines2 = splitnewlines(text2) |
|
138 | 138 | old = wsclean(opts, "".join(lines1[s[0]:s[1]])) |
|
139 | 139 | new = wsclean(opts, "".join(lines2[s[2]:s[3]])) |
|
140 | 140 | if old == new: |
|
141 | 141 | type = '~' |
|
142 | 142 | yield s, type |
|
143 | 143 | yield s1, '=' |
|
144 | 144 | |
|
145 | 145 | def diffline(revs, a, b, opts): |
|
146 | 146 | parts = ['diff'] |
|
147 | 147 | if opts.git: |
|
148 | 148 | parts.append('--git') |
|
149 | 149 | if revs and not opts.git: |
|
150 | 150 | parts.append(' '.join(["-r %s" % rev for rev in revs])) |
|
151 | 151 | if opts.git: |
|
152 | 152 | parts.append('a/%s' % a) |
|
153 | 153 | parts.append('b/%s' % b) |
|
154 | 154 | else: |
|
155 | 155 | parts.append(a) |
|
156 | 156 | return ' '.join(parts) + '\n' |
|
157 | 157 | |
|
158 | 158 | def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts): |
|
159 |
def datetag(date, |
|
|
159 | def datetag(date, fn=None): | |
|
160 | 160 | if not opts.git and not opts.nodates: |
|
161 | 161 | return '\t%s\n' % date |
|
162 |
if |
|
|
162 | if fn and ' ' in fn: | |
|
163 | 163 | return '\t\n' |
|
164 | 164 | return '\n' |
|
165 | 165 | |
|
166 | 166 | if not a and not b: |
|
167 | 167 | return "" |
|
168 | 168 | epoch = util.datestr((0, 0)) |
|
169 | 169 | |
|
170 | 170 | fn1 = util.pconvert(fn1) |
|
171 | 171 | fn2 = util.pconvert(fn2) |
|
172 | 172 | |
|
173 | 173 | if not opts.text and (util.binary(a) or util.binary(b)): |
|
174 | 174 | if a and b and len(a) == len(b) and a == b: |
|
175 | 175 | return "" |
|
176 | 176 | l = ['Binary file %s has changed\n' % fn1] |
|
177 | 177 | elif not a: |
|
178 | 178 | b = splitnewlines(b) |
|
179 | 179 | if a is None: |
|
180 |
l1 = '--- /dev/null%s' % datetag(epoch |
|
|
180 | l1 = '--- /dev/null%s' % datetag(epoch) | |
|
181 | 181 | else: |
|
182 | l1 = "--- %s%s" % ("a/" + fn1, datetag(ad)) | |
|
183 | l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd)) | |
|
182 | l1 = "--- %s%s" % ("a/" + fn1, datetag(ad, fn1)) | |
|
183 | l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd, fn2)) | |
|
184 | 184 | l3 = "@@ -0,0 +1,%d @@\n" % len(b) |
|
185 | 185 | l = [l1, l2, l3] + ["+" + e for e in b] |
|
186 | 186 | elif not b: |
|
187 | 187 | a = splitnewlines(a) |
|
188 | l1 = "--- %s%s" % ("a/" + fn1, datetag(ad)) | |
|
188 | l1 = "--- %s%s" % ("a/" + fn1, datetag(ad, fn1)) | |
|
189 | 189 | if b is None: |
|
190 |
l2 = '+++ /dev/null%s' % datetag(epoch |
|
|
190 | l2 = '+++ /dev/null%s' % datetag(epoch) | |
|
191 | 191 | else: |
|
192 | l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd)) | |
|
192 | l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd, fn2)) | |
|
193 | 193 | l3 = "@@ -1,%d +0,0 @@\n" % len(a) |
|
194 | 194 | l = [l1, l2, l3] + ["-" + e for e in a] |
|
195 | 195 | else: |
|
196 | 196 | al = splitnewlines(a) |
|
197 | 197 | bl = splitnewlines(b) |
|
198 | 198 | l = list(_unidiff(a, b, al, bl, opts=opts)) |
|
199 | 199 | if not l: |
|
200 | 200 | return "" |
|
201 | 201 | |
|
202 | l.insert(0, "--- a/%s%s" % (fn1, datetag(ad))) | |
|
203 | l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd))) | |
|
202 | l.insert(0, "--- a/%s%s" % (fn1, datetag(ad, fn1))) | |
|
203 | l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd, fn2))) | |
|
204 | 204 | |
|
205 | 205 | for ln in xrange(len(l)): |
|
206 | 206 | if l[ln][-1] != '\n': |
|
207 | 207 | l[ln] += "\n\ No newline at end of file\n" |
|
208 | 208 | |
|
209 | 209 | if r: |
|
210 | 210 | l.insert(0, diffline(r, fn1, fn2, opts)) |
|
211 | 211 | |
|
212 | 212 | return "".join(l) |
|
213 | 213 | |
|
214 | 214 | # creates a headerless unified diff |
|
215 | 215 | # t1 and t2 are the text to be diffed |
|
216 | 216 | # l1 and l2 are the text broken up into lines |
|
217 | 217 | def _unidiff(t1, t2, l1, l2, opts=defaultopts): |
|
218 | 218 | def contextend(l, len): |
|
219 | 219 | ret = l + opts.context |
|
220 | 220 | if ret > len: |
|
221 | 221 | ret = len |
|
222 | 222 | return ret |
|
223 | 223 | |
|
224 | 224 | def contextstart(l): |
|
225 | 225 | ret = l - opts.context |
|
226 | 226 | if ret < 0: |
|
227 | 227 | return 0 |
|
228 | 228 | return ret |
|
229 | 229 | |
|
230 | 230 | lastfunc = [0, ''] |
|
231 | 231 | def yieldhunk(hunk): |
|
232 | 232 | (astart, a2, bstart, b2, delta) = hunk |
|
233 | 233 | aend = contextend(a2, len(l1)) |
|
234 | 234 | alen = aend - astart |
|
235 | 235 | blen = b2 - bstart + aend - a2 |
|
236 | 236 | |
|
237 | 237 | func = "" |
|
238 | 238 | if opts.showfunc: |
|
239 | 239 | lastpos, func = lastfunc |
|
240 | 240 | # walk backwards from the start of the context up to the start of |
|
241 | 241 | # the previous hunk context until we find a line starting with an |
|
242 | 242 | # alphanumeric char. |
|
243 | 243 | for i in xrange(astart - 1, lastpos - 1, -1): |
|
244 | 244 | if l1[i][0].isalnum(): |
|
245 | 245 | func = ' ' + l1[i].rstrip()[:40] |
|
246 | 246 | lastfunc[1] = func |
|
247 | 247 | break |
|
248 | 248 | # by recording this hunk's starting point as the next place to |
|
249 | 249 | # start looking for function lines, we avoid reading any line in |
|
250 | 250 | # the file more than once. |
|
251 | 251 | lastfunc[0] = astart |
|
252 | 252 | |
|
253 | 253 | # zero-length hunk ranges report their start line as one less |
|
254 | 254 | if alen: |
|
255 | 255 | astart += 1 |
|
256 | 256 | if blen: |
|
257 | 257 | bstart += 1 |
|
258 | 258 | |
|
259 | 259 | yield "@@ -%d,%d +%d,%d @@%s\n" % (astart, alen, |
|
260 | 260 | bstart, blen, func) |
|
261 | 261 | for x in delta: |
|
262 | 262 | yield x |
|
263 | 263 | for x in xrange(a2, aend): |
|
264 | 264 | yield ' ' + l1[x] |
|
265 | 265 | |
|
266 | 266 | # bdiff.blocks gives us the matching sequences in the files. The loop |
|
267 | 267 | # below finds the spaces between those matching sequences and translates |
|
268 | 268 | # them into diff output. |
|
269 | 269 | # |
|
270 | 270 | hunk = None |
|
271 | 271 | ignoredlines = 0 |
|
272 | 272 | for s, stype in allblocks(t1, t2, opts, l1, l2): |
|
273 | 273 | a1, a2, b1, b2 = s |
|
274 | 274 | if stype != '!': |
|
275 | 275 | if stype == '~': |
|
276 | 276 | # The diff context lines are based on t1 content. When |
|
277 | 277 | # blank lines are ignored, the new lines offsets must |
|
278 | 278 | # be adjusted as if equivalent blocks ('~') had the |
|
279 | 279 | # same sizes on both sides. |
|
280 | 280 | ignoredlines += (b2 - b1) - (a2 - a1) |
|
281 | 281 | continue |
|
282 | 282 | delta = [] |
|
283 | 283 | old = l1[a1:a2] |
|
284 | 284 | new = l2[b1:b2] |
|
285 | 285 | |
|
286 | 286 | b1 -= ignoredlines |
|
287 | 287 | b2 -= ignoredlines |
|
288 | 288 | astart = contextstart(a1) |
|
289 | 289 | bstart = contextstart(b1) |
|
290 | 290 | prev = None |
|
291 | 291 | if hunk: |
|
292 | 292 | # join with the previous hunk if it falls inside the context |
|
293 | 293 | if astart < hunk[1] + opts.context + 1: |
|
294 | 294 | prev = hunk |
|
295 | 295 | astart = hunk[1] |
|
296 | 296 | bstart = hunk[3] |
|
297 | 297 | else: |
|
298 | 298 | for x in yieldhunk(hunk): |
|
299 | 299 | yield x |
|
300 | 300 | if prev: |
|
301 | 301 | # we've joined the previous hunk, record the new ending points. |
|
302 | 302 | hunk[1] = a2 |
|
303 | 303 | hunk[3] = b2 |
|
304 | 304 | delta = hunk[4] |
|
305 | 305 | else: |
|
306 | 306 | # create a new hunk |
|
307 | 307 | hunk = [astart, a2, bstart, b2, delta] |
|
308 | 308 | |
|
309 | 309 | delta[len(delta):] = [' ' + x for x in l1[astart:a1]] |
|
310 | 310 | delta[len(delta):] = ['-' + x for x in old] |
|
311 | 311 | delta[len(delta):] = ['+' + x for x in new] |
|
312 | 312 | |
|
313 | 313 | if hunk: |
|
314 | 314 | for x in yieldhunk(hunk): |
|
315 | 315 | yield x |
|
316 | 316 | |
|
317 | 317 | def patchtext(bin): |
|
318 | 318 | pos = 0 |
|
319 | 319 | t = [] |
|
320 | 320 | while pos < len(bin): |
|
321 | 321 | p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) |
|
322 | 322 | pos += 12 |
|
323 | 323 | t.append(bin[pos:pos + l]) |
|
324 | 324 | pos += l |
|
325 | 325 | return "".join(t) |
|
326 | 326 | |
|
327 | 327 | def patch(a, bin): |
|
328 | 328 | if len(a) == 0: |
|
329 | 329 | # skip over trivial delta header |
|
330 | 330 | return util.buffer(bin, 12) |
|
331 | 331 | return mpatch.patches(a, [bin]) |
|
332 | 332 | |
|
333 | 333 | # similar to difflib.SequenceMatcher.get_matching_blocks |
|
334 | 334 | def get_matching_blocks(a, b): |
|
335 | 335 | return [(d[0], d[2], d[1] - d[0]) for d in bdiff.blocks(a, b)] |
|
336 | 336 | |
|
337 | 337 | def trivialdiffheader(length): |
|
338 | 338 | return struct.pack(">lll", 0, 0, length) |
|
339 | 339 | |
|
340 | 340 | patches = mpatch.patches |
|
341 | 341 | patchedsize = mpatch.patchedsize |
|
342 | 342 | textdiff = bdiff.bdiff |
@@ -1,746 +1,746 b'' | |||
|
1 | 1 | # ui.py - user interface bits for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from i18n import _ |
|
9 | 9 | import errno, getpass, os, socket, sys, tempfile, traceback |
|
10 | 10 | import config, scmutil, util, error, formatter |
|
11 | 11 | |
|
12 | 12 | class ui(object): |
|
13 | 13 | def __init__(self, src=None): |
|
14 | 14 | self._buffers = [] |
|
15 | 15 | self.quiet = self.verbose = self.debugflag = self.tracebackflag = False |
|
16 | 16 | self._reportuntrusted = True |
|
17 | 17 | self._ocfg = config.config() # overlay |
|
18 | 18 | self._tcfg = config.config() # trusted |
|
19 | 19 | self._ucfg = config.config() # untrusted |
|
20 | 20 | self._trustusers = set() |
|
21 | 21 | self._trustgroups = set() |
|
22 | 22 | |
|
23 | 23 | if src: |
|
24 | 24 | self.fout = src.fout |
|
25 | 25 | self.ferr = src.ferr |
|
26 | 26 | self.fin = src.fin |
|
27 | 27 | |
|
28 | 28 | self._tcfg = src._tcfg.copy() |
|
29 | 29 | self._ucfg = src._ucfg.copy() |
|
30 | 30 | self._ocfg = src._ocfg.copy() |
|
31 | 31 | self._trustusers = src._trustusers.copy() |
|
32 | 32 | self._trustgroups = src._trustgroups.copy() |
|
33 | 33 | self.environ = src.environ |
|
34 | 34 | self.fixconfig() |
|
35 | 35 | else: |
|
36 | 36 | self.fout = sys.stdout |
|
37 | 37 | self.ferr = sys.stderr |
|
38 | 38 | self.fin = sys.stdin |
|
39 | 39 | |
|
40 | 40 | # shared read-only environment |
|
41 | 41 | self.environ = os.environ |
|
42 | 42 | # we always trust global config files |
|
43 | 43 | for f in scmutil.rcpath(): |
|
44 | 44 | self.readconfig(f, trust=True) |
|
45 | 45 | |
|
46 | 46 | def copy(self): |
|
47 | 47 | return self.__class__(self) |
|
48 | 48 | |
|
49 | 49 | def formatter(self, topic, opts): |
|
50 | 50 | return formatter.formatter(self, topic, opts) |
|
51 | 51 | |
|
52 | 52 | def _trusted(self, fp, f): |
|
53 | 53 | st = util.fstat(fp) |
|
54 | 54 | if util.isowner(st): |
|
55 | 55 | return True |
|
56 | 56 | |
|
57 | 57 | tusers, tgroups = self._trustusers, self._trustgroups |
|
58 | 58 | if '*' in tusers or '*' in tgroups: |
|
59 | 59 | return True |
|
60 | 60 | |
|
61 | 61 | user = util.username(st.st_uid) |
|
62 | 62 | group = util.groupname(st.st_gid) |
|
63 | 63 | if user in tusers or group in tgroups or user == util.username(): |
|
64 | 64 | return True |
|
65 | 65 | |
|
66 | 66 | if self._reportuntrusted: |
|
67 | 67 | self.warn(_('Not trusting file %s from untrusted ' |
|
68 | 68 | 'user %s, group %s\n') % (f, user, group)) |
|
69 | 69 | return False |
|
70 | 70 | |
|
71 | 71 | def readconfig(self, filename, root=None, trust=False, |
|
72 | 72 | sections=None, remap=None): |
|
73 | 73 | try: |
|
74 | 74 | fp = open(filename) |
|
75 | 75 | except IOError: |
|
76 | 76 | if not sections: # ignore unless we were looking for something |
|
77 | 77 | return |
|
78 | 78 | raise |
|
79 | 79 | |
|
80 | 80 | cfg = config.config() |
|
81 | 81 | trusted = sections or trust or self._trusted(fp, filename) |
|
82 | 82 | |
|
83 | 83 | try: |
|
84 | 84 | cfg.read(filename, fp, sections=sections, remap=remap) |
|
85 | 85 | fp.close() |
|
86 | 86 | except error.ConfigError, inst: |
|
87 | 87 | if trusted: |
|
88 | 88 | raise |
|
89 | 89 | self.warn(_("Ignored: %s\n") % str(inst)) |
|
90 | 90 | |
|
91 | 91 | if self.plain(): |
|
92 | 92 | for k in ('debug', 'fallbackencoding', 'quiet', 'slash', |
|
93 | 93 | 'logtemplate', 'style', |
|
94 | 94 | 'traceback', 'verbose'): |
|
95 | 95 | if k in cfg['ui']: |
|
96 | 96 | del cfg['ui'][k] |
|
97 | 97 | for k, v in cfg.items('defaults'): |
|
98 | 98 | del cfg['defaults'][k] |
|
99 | 99 | # Don't remove aliases from the configuration if in the exceptionlist |
|
100 | 100 | if self.plain('alias'): |
|
101 | 101 | for k, v in cfg.items('alias'): |
|
102 | 102 | del cfg['alias'][k] |
|
103 | 103 | |
|
104 | 104 | if trusted: |
|
105 | 105 | self._tcfg.update(cfg) |
|
106 | 106 | self._tcfg.update(self._ocfg) |
|
107 | 107 | self._ucfg.update(cfg) |
|
108 | 108 | self._ucfg.update(self._ocfg) |
|
109 | 109 | |
|
110 | 110 | if root is None: |
|
111 | 111 | root = os.path.expanduser('~') |
|
112 | 112 | self.fixconfig(root=root) |
|
113 | 113 | |
|
114 | 114 | def fixconfig(self, root=None, section=None): |
|
115 | 115 | if section in (None, 'paths'): |
|
116 | 116 | # expand vars and ~ |
|
117 | 117 | # translate paths relative to root (or home) into absolute paths |
|
118 | 118 | root = root or os.getcwd() |
|
119 | 119 | for c in self._tcfg, self._ucfg, self._ocfg: |
|
120 | 120 | for n, p in c.items('paths'): |
|
121 | 121 | if not p: |
|
122 | 122 | continue |
|
123 | 123 | if '%%' in p: |
|
124 | 124 | self.warn(_("(deprecated '%%' in path %s=%s from %s)\n") |
|
125 | 125 | % (n, p, self.configsource('paths', n))) |
|
126 | 126 | p = p.replace('%%', '%') |
|
127 | 127 | p = util.expandpath(p) |
|
128 | 128 | if not util.hasscheme(p) and not os.path.isabs(p): |
|
129 | 129 | p = os.path.normpath(os.path.join(root, p)) |
|
130 | 130 | c.set("paths", n, p) |
|
131 | 131 | |
|
132 | 132 | if section in (None, 'ui'): |
|
133 | 133 | # update ui options |
|
134 | 134 | self.debugflag = self.configbool('ui', 'debug') |
|
135 | 135 | self.verbose = self.debugflag or self.configbool('ui', 'verbose') |
|
136 | 136 | self.quiet = not self.debugflag and self.configbool('ui', 'quiet') |
|
137 | 137 | if self.verbose and self.quiet: |
|
138 | 138 | self.quiet = self.verbose = False |
|
139 | 139 | self._reportuntrusted = self.debugflag or self.configbool("ui", |
|
140 | 140 | "report_untrusted", True) |
|
141 | 141 | self.tracebackflag = self.configbool('ui', 'traceback', False) |
|
142 | 142 | |
|
143 | 143 | if section in (None, 'trusted'): |
|
144 | 144 | # update trust information |
|
145 | 145 | self._trustusers.update(self.configlist('trusted', 'users')) |
|
146 | 146 | self._trustgroups.update(self.configlist('trusted', 'groups')) |
|
147 | 147 | |
|
148 | 148 | def backupconfig(self, section, item): |
|
149 | 149 | return (self._ocfg.backup(section, item), |
|
150 | 150 | self._tcfg.backup(section, item), |
|
151 | 151 | self._ucfg.backup(section, item),) |
|
152 | 152 | def restoreconfig(self, data): |
|
153 | 153 | self._ocfg.restore(data[0]) |
|
154 | 154 | self._tcfg.restore(data[1]) |
|
155 | 155 | self._ucfg.restore(data[2]) |
|
156 | 156 | |
|
157 | 157 | def setconfig(self, section, name, value, overlay=True): |
|
158 | 158 | if overlay: |
|
159 | 159 | self._ocfg.set(section, name, value) |
|
160 | 160 | self._tcfg.set(section, name, value) |
|
161 | 161 | self._ucfg.set(section, name, value) |
|
162 | 162 | self.fixconfig(section=section) |
|
163 | 163 | |
|
164 | 164 | def _data(self, untrusted): |
|
165 | 165 | return untrusted and self._ucfg or self._tcfg |
|
166 | 166 | |
|
167 | 167 | def configsource(self, section, name, untrusted=False): |
|
168 | 168 | return self._data(untrusted).source(section, name) or 'none' |
|
169 | 169 | |
|
170 | 170 | def config(self, section, name, default=None, untrusted=False): |
|
171 | 171 | if isinstance(name, list): |
|
172 | 172 | alternates = name |
|
173 | 173 | else: |
|
174 | 174 | alternates = [name] |
|
175 | 175 | |
|
176 | 176 | for n in alternates: |
|
177 | 177 | value = self._data(untrusted).get(section, name, None) |
|
178 | 178 | if value is not None: |
|
179 | 179 | name = n |
|
180 | 180 | break |
|
181 | 181 | else: |
|
182 | 182 | value = default |
|
183 | 183 | |
|
184 | 184 | if self.debugflag and not untrusted and self._reportuntrusted: |
|
185 | 185 | uvalue = self._ucfg.get(section, name) |
|
186 | 186 | if uvalue is not None and uvalue != value: |
|
187 | 187 | self.debug("ignoring untrusted configuration option " |
|
188 | 188 | "%s.%s = %s\n" % (section, name, uvalue)) |
|
189 | 189 | return value |
|
190 | 190 | |
|
191 | 191 | def configpath(self, section, name, default=None, untrusted=False): |
|
192 | 192 | 'get a path config item, expanded relative to repo root or config file' |
|
193 | 193 | v = self.config(section, name, default, untrusted) |
|
194 | 194 | if v is None: |
|
195 | 195 | return None |
|
196 | 196 | if not os.path.isabs(v) or "://" not in v: |
|
197 | 197 | src = self.configsource(section, name, untrusted) |
|
198 | 198 | if ':' in src: |
|
199 | 199 | base = os.path.dirname(src.rsplit(':')[0]) |
|
200 | 200 | v = os.path.join(base, os.path.expanduser(v)) |
|
201 | 201 | return v |
|
202 | 202 | |
|
203 | 203 | def configbool(self, section, name, default=False, untrusted=False): |
|
204 | 204 | """parse a configuration element as a boolean |
|
205 | 205 | |
|
206 | 206 | >>> u = ui(); s = 'foo' |
|
207 | 207 | >>> u.setconfig(s, 'true', 'yes') |
|
208 | 208 | >>> u.configbool(s, 'true') |
|
209 | 209 | True |
|
210 | 210 | >>> u.setconfig(s, 'false', 'no') |
|
211 | 211 | >>> u.configbool(s, 'false') |
|
212 | 212 | False |
|
213 | 213 | >>> u.configbool(s, 'unknown') |
|
214 | 214 | False |
|
215 | 215 | >>> u.configbool(s, 'unknown', True) |
|
216 | 216 | True |
|
217 | 217 | >>> u.setconfig(s, 'invalid', 'somevalue') |
|
218 | 218 | >>> u.configbool(s, 'invalid') |
|
219 | 219 | Traceback (most recent call last): |
|
220 | 220 | ... |
|
221 | 221 | ConfigError: foo.invalid is not a boolean ('somevalue') |
|
222 | 222 | """ |
|
223 | 223 | |
|
224 | 224 | v = self.config(section, name, None, untrusted) |
|
225 | 225 | if v is None: |
|
226 | 226 | return default |
|
227 | 227 | if isinstance(v, bool): |
|
228 | 228 | return v |
|
229 | 229 | b = util.parsebool(v) |
|
230 | 230 | if b is None: |
|
231 | 231 | raise error.ConfigError(_("%s.%s is not a boolean ('%s')") |
|
232 | 232 | % (section, name, v)) |
|
233 | 233 | return b |
|
234 | 234 | |
|
235 | 235 | def configint(self, section, name, default=None, untrusted=False): |
|
236 | 236 | """parse a configuration element as an integer |
|
237 | 237 | |
|
238 | 238 | >>> u = ui(); s = 'foo' |
|
239 | 239 | >>> u.setconfig(s, 'int1', '42') |
|
240 | 240 | >>> u.configint(s, 'int1') |
|
241 | 241 | 42 |
|
242 | 242 | >>> u.setconfig(s, 'int2', '-42') |
|
243 | 243 | >>> u.configint(s, 'int2') |
|
244 | 244 | -42 |
|
245 | 245 | >>> u.configint(s, 'unknown', 7) |
|
246 | 246 | 7 |
|
247 | 247 | >>> u.setconfig(s, 'invalid', 'somevalue') |
|
248 | 248 | >>> u.configint(s, 'invalid') |
|
249 | 249 | Traceback (most recent call last): |
|
250 | 250 | ... |
|
251 | 251 | ConfigError: foo.invalid is not an integer ('somevalue') |
|
252 | 252 | """ |
|
253 | 253 | |
|
254 | 254 | v = self.config(section, name, None, untrusted) |
|
255 | 255 | if v is None: |
|
256 | 256 | return default |
|
257 | 257 | try: |
|
258 | 258 | return int(v) |
|
259 | 259 | except ValueError: |
|
260 | 260 | raise error.ConfigError(_("%s.%s is not an integer ('%s')") |
|
261 | 261 | % (section, name, v)) |
|
262 | 262 | |
|
263 | 263 | def configlist(self, section, name, default=None, untrusted=False): |
|
264 | 264 | """parse a configuration element as a list of comma/space separated |
|
265 | 265 | strings |
|
266 | 266 | |
|
267 | 267 | >>> u = ui(); s = 'foo' |
|
268 | 268 | >>> u.setconfig(s, 'list1', 'this,is "a small" ,test') |
|
269 | 269 | >>> u.configlist(s, 'list1') |
|
270 | 270 | ['this', 'is', 'a small', 'test'] |
|
271 | 271 | """ |
|
272 | 272 | |
|
273 | 273 | def _parse_plain(parts, s, offset): |
|
274 | 274 | whitespace = False |
|
275 | 275 | while offset < len(s) and (s[offset].isspace() or s[offset] == ','): |
|
276 | 276 | whitespace = True |
|
277 | 277 | offset += 1 |
|
278 | 278 | if offset >= len(s): |
|
279 | 279 | return None, parts, offset |
|
280 | 280 | if whitespace: |
|
281 | 281 | parts.append('') |
|
282 | 282 | if s[offset] == '"' and not parts[-1]: |
|
283 | 283 | return _parse_quote, parts, offset + 1 |
|
284 | 284 | elif s[offset] == '"' and parts[-1][-1] == '\\': |
|
285 | 285 | parts[-1] = parts[-1][:-1] + s[offset] |
|
286 | 286 | return _parse_plain, parts, offset + 1 |
|
287 | 287 | parts[-1] += s[offset] |
|
288 | 288 | return _parse_plain, parts, offset + 1 |
|
289 | 289 | |
|
290 | 290 | def _parse_quote(parts, s, offset): |
|
291 | 291 | if offset < len(s) and s[offset] == '"': # "" |
|
292 | 292 | parts.append('') |
|
293 | 293 | offset += 1 |
|
294 | 294 | while offset < len(s) and (s[offset].isspace() or |
|
295 | 295 | s[offset] == ','): |
|
296 | 296 | offset += 1 |
|
297 | 297 | return _parse_plain, parts, offset |
|
298 | 298 | |
|
299 | 299 | while offset < len(s) and s[offset] != '"': |
|
300 | 300 | if (s[offset] == '\\' and offset + 1 < len(s) |
|
301 | 301 | and s[offset + 1] == '"'): |
|
302 | 302 | offset += 1 |
|
303 | 303 | parts[-1] += '"' |
|
304 | 304 | else: |
|
305 | 305 | parts[-1] += s[offset] |
|
306 | 306 | offset += 1 |
|
307 | 307 | |
|
308 | 308 | if offset >= len(s): |
|
309 | 309 | real_parts = _configlist(parts[-1]) |
|
310 | 310 | if not real_parts: |
|
311 | 311 | parts[-1] = '"' |
|
312 | 312 | else: |
|
313 | 313 | real_parts[0] = '"' + real_parts[0] |
|
314 | 314 | parts = parts[:-1] |
|
315 | 315 | parts.extend(real_parts) |
|
316 | 316 | return None, parts, offset |
|
317 | 317 | |
|
318 | 318 | offset += 1 |
|
319 | 319 | while offset < len(s) and s[offset] in [' ', ',']: |
|
320 | 320 | offset += 1 |
|
321 | 321 | |
|
322 | 322 | if offset < len(s): |
|
323 | 323 | if offset + 1 == len(s) and s[offset] == '"': |
|
324 | 324 | parts[-1] += '"' |
|
325 | 325 | offset += 1 |
|
326 | 326 | else: |
|
327 | 327 | parts.append('') |
|
328 | 328 | else: |
|
329 | 329 | return None, parts, offset |
|
330 | 330 | |
|
331 | 331 | return _parse_plain, parts, offset |
|
332 | 332 | |
|
333 | 333 | def _configlist(s): |
|
334 | 334 | s = s.rstrip(' ,') |
|
335 | 335 | if not s: |
|
336 | 336 | return [] |
|
337 | 337 | parser, parts, offset = _parse_plain, [''], 0 |
|
338 | 338 | while parser: |
|
339 | 339 | parser, parts, offset = parser(parts, s, offset) |
|
340 | 340 | return parts |
|
341 | 341 | |
|
342 | 342 | result = self.config(section, name, untrusted=untrusted) |
|
343 | 343 | if result is None: |
|
344 | 344 | result = default or [] |
|
345 | 345 | if isinstance(result, basestring): |
|
346 | 346 | result = _configlist(result.lstrip(' ,\n')) |
|
347 | 347 | if result is None: |
|
348 | 348 | result = default or [] |
|
349 | 349 | return result |
|
350 | 350 | |
|
351 | 351 | def has_section(self, section, untrusted=False): |
|
352 | 352 | '''tell whether section exists in config.''' |
|
353 | 353 | return section in self._data(untrusted) |
|
354 | 354 | |
|
355 | 355 | def configitems(self, section, untrusted=False): |
|
356 | 356 | items = self._data(untrusted).items(section) |
|
357 | 357 | if self.debugflag and not untrusted and self._reportuntrusted: |
|
358 | 358 | for k, v in self._ucfg.items(section): |
|
359 | 359 | if self._tcfg.get(section, k) != v: |
|
360 | 360 | self.debug("ignoring untrusted configuration option " |
|
361 | 361 | "%s.%s = %s\n" % (section, k, v)) |
|
362 | 362 | return items |
|
363 | 363 | |
|
364 | 364 | def walkconfig(self, untrusted=False): |
|
365 | 365 | cfg = self._data(untrusted) |
|
366 | 366 | for section in cfg.sections(): |
|
367 | 367 | for name, value in self.configitems(section, untrusted): |
|
368 | 368 | yield section, name, value |
|
369 | 369 | |
|
370 | 370 | def plain(self, feature=None): |
|
371 | 371 | '''is plain mode active? |
|
372 | 372 | |
|
373 | 373 | Plain mode means that all configuration variables which affect |
|
374 | 374 | the behavior and output of Mercurial should be |
|
375 | 375 | ignored. Additionally, the output should be stable, |
|
376 | 376 | reproducible and suitable for use in scripts or applications. |
|
377 | 377 | |
|
378 | 378 | The only way to trigger plain mode is by setting either the |
|
379 | 379 | `HGPLAIN' or `HGPLAINEXCEPT' environment variables. |
|
380 | 380 | |
|
381 | 381 | The return value can either be |
|
382 | 382 | - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT |
|
383 | 383 | - True otherwise |
|
384 | 384 | ''' |
|
385 | 385 | if 'HGPLAIN' not in os.environ and 'HGPLAINEXCEPT' not in os.environ: |
|
386 | 386 | return False |
|
387 | 387 | exceptions = os.environ.get('HGPLAINEXCEPT', '').strip().split(',') |
|
388 | 388 | if feature and exceptions: |
|
389 | 389 | return feature not in exceptions |
|
390 | 390 | return True |
|
391 | 391 | |
|
392 | 392 | def username(self): |
|
393 | 393 | """Return default username to be used in commits. |
|
394 | 394 | |
|
395 | 395 | Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL |
|
396 | 396 | and stop searching if one of these is set. |
|
397 | 397 | If not found and ui.askusername is True, ask the user, else use |
|
398 | 398 | ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname". |
|
399 | 399 | """ |
|
400 | 400 | user = os.environ.get("HGUSER") |
|
401 | 401 | if user is None: |
|
402 | 402 | user = self.config("ui", "username") |
|
403 | 403 | if user is not None: |
|
404 | 404 | user = os.path.expandvars(user) |
|
405 | 405 | if user is None: |
|
406 | 406 | user = os.environ.get("EMAIL") |
|
407 | 407 | if user is None and self.configbool("ui", "askusername"): |
|
408 | 408 | user = self.prompt(_("enter a commit username:"), default=None) |
|
409 | 409 | if user is None and not self.interactive(): |
|
410 | 410 | try: |
|
411 | 411 | user = '%s@%s' % (util.getuser(), socket.getfqdn()) |
|
412 | 412 | self.warn(_("No username found, using '%s' instead\n") % user) |
|
413 | 413 | except KeyError: |
|
414 | 414 | pass |
|
415 | 415 | if not user: |
|
416 | 416 | raise util.Abort(_('no username supplied (see "hg help config")')) |
|
417 | 417 | if "\n" in user: |
|
418 | 418 | raise util.Abort(_("username %s contains a newline\n") % repr(user)) |
|
419 | 419 | return user |
|
420 | 420 | |
|
421 | 421 | def shortuser(self, user): |
|
422 | 422 | """Return a short representation of a user name or email address.""" |
|
423 | 423 | if not self.verbose: |
|
424 | 424 | user = util.shortuser(user) |
|
425 | 425 | return user |
|
426 | 426 | |
|
427 | 427 | def expandpath(self, loc, default=None): |
|
428 | 428 | """Return repository location relative to cwd or from [paths]""" |
|
429 | 429 | if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')): |
|
430 | 430 | return loc |
|
431 | 431 | |
|
432 | 432 | path = self.config('paths', loc) |
|
433 | 433 | if not path and default is not None: |
|
434 | 434 | path = self.config('paths', default) |
|
435 | 435 | return path or loc |
|
436 | 436 | |
|
437 | 437 | def pushbuffer(self): |
|
438 | 438 | self._buffers.append([]) |
|
439 | 439 | |
|
440 | 440 | def popbuffer(self, labeled=False): |
|
441 | 441 | '''pop the last buffer and return the buffered output |
|
442 | 442 | |
|
443 | 443 | If labeled is True, any labels associated with buffered |
|
444 | 444 | output will be handled. By default, this has no effect |
|
445 | 445 | on the output returned, but extensions and GUI tools may |
|
446 | 446 | handle this argument and returned styled output. If output |
|
447 | 447 | is being buffered so it can be captured and parsed or |
|
448 | 448 | processed, labeled should not be set to True. |
|
449 | 449 | ''' |
|
450 | 450 | return "".join(self._buffers.pop()) |
|
451 | 451 | |
|
452 | 452 | def write(self, *args, **opts): |
|
453 | 453 | '''write args to output |
|
454 | 454 | |
|
455 | 455 | By default, this method simply writes to the buffer or stdout, |
|
456 | 456 | but extensions or GUI tools may override this method, |
|
457 | 457 | write_err(), popbuffer(), and label() to style output from |
|
458 | 458 | various parts of hg. |
|
459 | 459 | |
|
460 | 460 | An optional keyword argument, "label", can be passed in. |
|
461 | 461 | This should be a string containing label names separated by |
|
462 | 462 | space. Label names take the form of "topic.type". For example, |
|
463 | 463 | ui.debug() issues a label of "ui.debug". |
|
464 | 464 | |
|
465 | 465 | When labeling output for a specific command, a label of |
|
466 | 466 | "cmdname.type" is recommended. For example, status issues |
|
467 | 467 | a label of "status.modified" for modified files. |
|
468 | 468 | ''' |
|
469 | 469 | if self._buffers: |
|
470 | 470 | self._buffers[-1].extend([str(a) for a in args]) |
|
471 | 471 | else: |
|
472 | 472 | for a in args: |
|
473 | 473 | self.fout.write(str(a)) |
|
474 | 474 | |
|
475 | 475 | def write_err(self, *args, **opts): |
|
476 | 476 | try: |
|
477 | 477 | if not getattr(self.fout, 'closed', False): |
|
478 | 478 | self.fout.flush() |
|
479 | 479 | for a in args: |
|
480 | 480 | self.ferr.write(str(a)) |
|
481 | 481 | # stderr may be buffered under win32 when redirected to files, |
|
482 | 482 | # including stdout. |
|
483 | 483 | if not getattr(self.ferr, 'closed', False): |
|
484 | 484 | self.ferr.flush() |
|
485 | 485 | except IOError, inst: |
|
486 | if inst.errno not in (errno.EPIPE, errno.EIO): | |
|
486 | if inst.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): | |
|
487 | 487 | raise |
|
488 | 488 | |
|
489 | 489 | def flush(self): |
|
490 | 490 | try: self.fout.flush() |
|
491 | 491 | except: pass |
|
492 | 492 | try: self.ferr.flush() |
|
493 | 493 | except: pass |
|
494 | 494 | |
|
495 | 495 | def interactive(self): |
|
496 | 496 | '''is interactive input allowed? |
|
497 | 497 | |
|
498 | 498 | An interactive session is a session where input can be reasonably read |
|
499 | 499 | from `sys.stdin'. If this function returns false, any attempt to read |
|
500 | 500 | from stdin should fail with an error, unless a sensible default has been |
|
501 | 501 | specified. |
|
502 | 502 | |
|
503 | 503 | Interactiveness is triggered by the value of the `ui.interactive' |
|
504 | 504 | configuration variable or - if it is unset - when `sys.stdin' points |
|
505 | 505 | to a terminal device. |
|
506 | 506 | |
|
507 | 507 | This function refers to input only; for output, see `ui.formatted()'. |
|
508 | 508 | ''' |
|
509 | 509 | i = self.configbool("ui", "interactive", None) |
|
510 | 510 | if i is None: |
|
511 | 511 | # some environments replace stdin without implementing isatty |
|
512 | 512 | # usually those are non-interactive |
|
513 | 513 | return util.isatty(self.fin) |
|
514 | 514 | |
|
515 | 515 | return i |
|
516 | 516 | |
|
517 | 517 | def termwidth(self): |
|
518 | 518 | '''how wide is the terminal in columns? |
|
519 | 519 | ''' |
|
520 | 520 | if 'COLUMNS' in os.environ: |
|
521 | 521 | try: |
|
522 | 522 | return int(os.environ['COLUMNS']) |
|
523 | 523 | except ValueError: |
|
524 | 524 | pass |
|
525 | 525 | return util.termwidth() |
|
526 | 526 | |
|
527 | 527 | def formatted(self): |
|
528 | 528 | '''should formatted output be used? |
|
529 | 529 | |
|
530 | 530 | It is often desirable to format the output to suite the output medium. |
|
531 | 531 | Examples of this are truncating long lines or colorizing messages. |
|
532 | 532 | However, this is not often not desirable when piping output into other |
|
533 | 533 | utilities, e.g. `grep'. |
|
534 | 534 | |
|
535 | 535 | Formatted output is triggered by the value of the `ui.formatted' |
|
536 | 536 | configuration variable or - if it is unset - when `sys.stdout' points |
|
537 | 537 | to a terminal device. Please note that `ui.formatted' should be |
|
538 | 538 | considered an implementation detail; it is not intended for use outside |
|
539 | 539 | Mercurial or its extensions. |
|
540 | 540 | |
|
541 | 541 | This function refers to output only; for input, see `ui.interactive()'. |
|
542 | 542 | This function always returns false when in plain mode, see `ui.plain()'. |
|
543 | 543 | ''' |
|
544 | 544 | if self.plain(): |
|
545 | 545 | return False |
|
546 | 546 | |
|
547 | 547 | i = self.configbool("ui", "formatted", None) |
|
548 | 548 | if i is None: |
|
549 | 549 | # some environments replace stdout without implementing isatty |
|
550 | 550 | # usually those are non-interactive |
|
551 | 551 | return util.isatty(self.fout) |
|
552 | 552 | |
|
553 | 553 | return i |
|
554 | 554 | |
|
555 | 555 | def _readline(self, prompt=''): |
|
556 | 556 | if util.isatty(self.fin): |
|
557 | 557 | try: |
|
558 | 558 | # magically add command line editing support, where |
|
559 | 559 | # available |
|
560 | 560 | import readline |
|
561 | 561 | # force demandimport to really load the module |
|
562 | 562 | readline.read_history_file |
|
563 | 563 | # windows sometimes raises something other than ImportError |
|
564 | 564 | except Exception: |
|
565 | 565 | pass |
|
566 | 566 | |
|
567 | 567 | # call write() so output goes through subclassed implementation |
|
568 | 568 | # e.g. color extension on Windows |
|
569 | 569 | self.write(prompt) |
|
570 | 570 | |
|
571 | 571 | # instead of trying to emulate raw_input, swap (self.fin, |
|
572 | 572 | # self.fout) with (sys.stdin, sys.stdout) |
|
573 | 573 | oldin = sys.stdin |
|
574 | 574 | oldout = sys.stdout |
|
575 | 575 | sys.stdin = self.fin |
|
576 | 576 | sys.stdout = self.fout |
|
577 | 577 | line = raw_input(' ') |
|
578 | 578 | sys.stdin = oldin |
|
579 | 579 | sys.stdout = oldout |
|
580 | 580 | |
|
581 | 581 | # When stdin is in binary mode on Windows, it can cause |
|
582 | 582 | # raw_input() to emit an extra trailing carriage return |
|
583 | 583 | if os.linesep == '\r\n' and line and line[-1] == '\r': |
|
584 | 584 | line = line[:-1] |
|
585 | 585 | return line |
|
586 | 586 | |
|
587 | 587 | def prompt(self, msg, default="y"): |
|
588 | 588 | """Prompt user with msg, read response. |
|
589 | 589 | If ui is not interactive, the default is returned. |
|
590 | 590 | """ |
|
591 | 591 | if not self.interactive(): |
|
592 | 592 | self.write(msg, ' ', default, "\n") |
|
593 | 593 | return default |
|
594 | 594 | try: |
|
595 | 595 | r = self._readline(self.label(msg, 'ui.prompt')) |
|
596 | 596 | if not r: |
|
597 | 597 | return default |
|
598 | 598 | return r |
|
599 | 599 | except EOFError: |
|
600 | 600 | raise util.Abort(_('response expected')) |
|
601 | 601 | |
|
602 | 602 | def promptchoice(self, msg, choices, default=0): |
|
603 | 603 | """Prompt user with msg, read response, and ensure it matches |
|
604 | 604 | one of the provided choices. The index of the choice is returned. |
|
605 | 605 | choices is a sequence of acceptable responses with the format: |
|
606 | 606 | ('&None', 'E&xec', 'Sym&link') Responses are case insensitive. |
|
607 | 607 | If ui is not interactive, the default is returned. |
|
608 | 608 | """ |
|
609 | 609 | resps = [s[s.index('&')+1].lower() for s in choices] |
|
610 | 610 | while True: |
|
611 | 611 | r = self.prompt(msg, resps[default]) |
|
612 | 612 | if r.lower() in resps: |
|
613 | 613 | return resps.index(r.lower()) |
|
614 | 614 | self.write(_("unrecognized response\n")) |
|
615 | 615 | |
|
616 | 616 | def getpass(self, prompt=None, default=None): |
|
617 | 617 | if not self.interactive(): |
|
618 | 618 | return default |
|
619 | 619 | try: |
|
620 | 620 | return getpass.getpass(prompt or _('password: ')) |
|
621 | 621 | except EOFError: |
|
622 | 622 | raise util.Abort(_('response expected')) |
|
623 | 623 | def status(self, *msg, **opts): |
|
624 | 624 | '''write status message to output (if ui.quiet is False) |
|
625 | 625 | |
|
626 | 626 | This adds an output label of "ui.status". |
|
627 | 627 | ''' |
|
628 | 628 | if not self.quiet: |
|
629 | 629 | opts['label'] = opts.get('label', '') + ' ui.status' |
|
630 | 630 | self.write(*msg, **opts) |
|
631 | 631 | def warn(self, *msg, **opts): |
|
632 | 632 | '''write warning message to output (stderr) |
|
633 | 633 | |
|
634 | 634 | This adds an output label of "ui.warning". |
|
635 | 635 | ''' |
|
636 | 636 | opts['label'] = opts.get('label', '') + ' ui.warning' |
|
637 | 637 | self.write_err(*msg, **opts) |
|
638 | 638 | def note(self, *msg, **opts): |
|
639 | 639 | '''write note to output (if ui.verbose is True) |
|
640 | 640 | |
|
641 | 641 | This adds an output label of "ui.note". |
|
642 | 642 | ''' |
|
643 | 643 | if self.verbose: |
|
644 | 644 | opts['label'] = opts.get('label', '') + ' ui.note' |
|
645 | 645 | self.write(*msg, **opts) |
|
646 | 646 | def debug(self, *msg, **opts): |
|
647 | 647 | '''write debug message to output (if ui.debugflag is True) |
|
648 | 648 | |
|
649 | 649 | This adds an output label of "ui.debug". |
|
650 | 650 | ''' |
|
651 | 651 | if self.debugflag: |
|
652 | 652 | opts['label'] = opts.get('label', '') + ' ui.debug' |
|
653 | 653 | self.write(*msg, **opts) |
|
654 | 654 | def edit(self, text, user): |
|
655 | 655 | (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt", |
|
656 | 656 | text=True) |
|
657 | 657 | try: |
|
658 | 658 | f = os.fdopen(fd, "w") |
|
659 | 659 | f.write(text) |
|
660 | 660 | f.close() |
|
661 | 661 | |
|
662 | 662 | editor = self.geteditor() |
|
663 | 663 | |
|
664 | 664 | util.system("%s \"%s\"" % (editor, name), |
|
665 | 665 | environ={'HGUSER': user}, |
|
666 | 666 | onerr=util.Abort, errprefix=_("edit failed"), |
|
667 | 667 | out=self.fout) |
|
668 | 668 | |
|
669 | 669 | f = open(name) |
|
670 | 670 | t = f.read() |
|
671 | 671 | f.close() |
|
672 | 672 | finally: |
|
673 | 673 | os.unlink(name) |
|
674 | 674 | |
|
675 | 675 | return t |
|
676 | 676 | |
|
677 | 677 | def traceback(self, exc=None): |
|
678 | 678 | '''print exception traceback if traceback printing enabled. |
|
679 | 679 | only to call in exception handler. returns true if traceback |
|
680 | 680 | printed.''' |
|
681 | 681 | if self.tracebackflag: |
|
682 | 682 | if exc: |
|
683 | 683 | traceback.print_exception(exc[0], exc[1], exc[2], file=self.ferr) |
|
684 | 684 | else: |
|
685 | 685 | traceback.print_exc(file=self.ferr) |
|
686 | 686 | return self.tracebackflag |
|
687 | 687 | |
|
688 | 688 | def geteditor(self): |
|
689 | 689 | '''return editor to use''' |
|
690 | 690 | return (os.environ.get("HGEDITOR") or |
|
691 | 691 | self.config("ui", "editor") or |
|
692 | 692 | os.environ.get("VISUAL") or |
|
693 | 693 | os.environ.get("EDITOR", "vi")) |
|
694 | 694 | |
|
695 | 695 | def progress(self, topic, pos, item="", unit="", total=None): |
|
696 | 696 | '''show a progress message |
|
697 | 697 | |
|
698 | 698 | With stock hg, this is simply a debug message that is hidden |
|
699 | 699 | by default, but with extensions or GUI tools it may be |
|
700 | 700 | visible. 'topic' is the current operation, 'item' is a |
|
701 | 701 | non-numeric marker of the current position (ie the currently |
|
702 | 702 | in-process file), 'pos' is the current numeric position (ie |
|
703 | 703 | revision, bytes, etc.), unit is a corresponding unit label, |
|
704 | 704 | and total is the highest expected pos. |
|
705 | 705 | |
|
706 | 706 | Multiple nested topics may be active at a time. |
|
707 | 707 | |
|
708 | 708 | All topics should be marked closed by setting pos to None at |
|
709 | 709 | termination. |
|
710 | 710 | ''' |
|
711 | 711 | |
|
712 | 712 | if pos is None or not self.debugflag: |
|
713 | 713 | return |
|
714 | 714 | |
|
715 | 715 | if unit: |
|
716 | 716 | unit = ' ' + unit |
|
717 | 717 | if item: |
|
718 | 718 | item = ' ' + item |
|
719 | 719 | |
|
720 | 720 | if total: |
|
721 | 721 | pct = 100.0 * pos / total |
|
722 | 722 | self.debug('%s:%s %s/%s%s (%4.2f%%)\n' |
|
723 | 723 | % (topic, item, pos, total, unit, pct)) |
|
724 | 724 | else: |
|
725 | 725 | self.debug('%s:%s %s%s\n' % (topic, item, pos, unit)) |
|
726 | 726 | |
|
727 | 727 | def log(self, service, message): |
|
728 | 728 | '''hook for logging facility extensions |
|
729 | 729 | |
|
730 | 730 | service should be a readily-identifiable subsystem, which will |
|
731 | 731 | allow filtering. |
|
732 | 732 | message should be a newline-terminated string to log. |
|
733 | 733 | ''' |
|
734 | 734 | pass |
|
735 | 735 | |
|
736 | 736 | def label(self, msg, label): |
|
737 | 737 | '''style msg based on supplied label |
|
738 | 738 | |
|
739 | 739 | Like ui.write(), this just returns msg unchanged, but extensions |
|
740 | 740 | and GUI tools can override it to allow styling output without |
|
741 | 741 | writing it. |
|
742 | 742 | |
|
743 | 743 | ui.write(s, 'label') is equivalent to |
|
744 | 744 | ui.write(ui.label(s, 'label')). |
|
745 | 745 | ''' |
|
746 | 746 | return msg |
@@ -1,345 +1,344 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | """Test the running system for features availability. Exit with zero |
|
3 | 3 | if all features are there, non-zero otherwise. If a feature name is |
|
4 | 4 | prefixed with "no-", the absence of feature is tested. |
|
5 | 5 | """ |
|
6 | 6 | import optparse |
|
7 | 7 | import os, stat |
|
8 | 8 | import re |
|
9 | 9 | import sys |
|
10 | 10 | import tempfile |
|
11 | 11 | |
|
12 | 12 | tempprefix = 'hg-hghave-' |
|
13 | 13 | |
|
14 | 14 | def matchoutput(cmd, regexp, ignorestatus=False): |
|
15 | 15 | """Return True if cmd executes successfully and its output |
|
16 | 16 | is matched by the supplied regular expression. |
|
17 | 17 | """ |
|
18 | 18 | r = re.compile(regexp) |
|
19 | 19 | fh = os.popen(cmd) |
|
20 | 20 | s = fh.read() |
|
21 | 21 | try: |
|
22 | 22 | ret = fh.close() |
|
23 | 23 | except IOError: |
|
24 | 24 | # Happen in Windows test environment |
|
25 | 25 | ret = 1 |
|
26 | 26 | return (ignorestatus or ret is None) and r.search(s) |
|
27 | 27 | |
|
28 | 28 | def has_baz(): |
|
29 | 29 | return matchoutput('baz --version 2>&1', r'baz Bazaar version') |
|
30 | 30 | |
|
31 | 31 | def has_bzr(): |
|
32 | 32 | try: |
|
33 | 33 | import bzrlib |
|
34 | 34 | return bzrlib.__doc__ != None |
|
35 | 35 | except ImportError: |
|
36 | 36 | return False |
|
37 | 37 | |
|
38 | 38 | def has_bzr114(): |
|
39 | 39 | try: |
|
40 | 40 | import bzrlib |
|
41 | 41 | return (bzrlib.__doc__ != None |
|
42 | 42 | and bzrlib.version_info[:2] >= (1, 14)) |
|
43 | 43 | except ImportError: |
|
44 | 44 | return False |
|
45 | 45 | |
|
46 | 46 | def has_cvs(): |
|
47 | 47 | re = r'Concurrent Versions System.*?server' |
|
48 | 48 | return matchoutput('cvs --version 2>&1', re) and not has_msys() |
|
49 | 49 | |
|
50 | 50 | def has_darcs(): |
|
51 | 51 | return matchoutput('darcs --version', r'2\.[2-9]', True) |
|
52 | 52 | |
|
53 | 53 | def has_mtn(): |
|
54 | 54 | return matchoutput('mtn --version', r'monotone', True) and not matchoutput( |
|
55 | 55 | 'mtn --version', r'monotone 0\.', True) |
|
56 | 56 | |
|
57 | 57 | def has_eol_in_paths(): |
|
58 | 58 | try: |
|
59 | 59 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') |
|
60 | 60 | os.close(fd) |
|
61 | 61 | os.remove(path) |
|
62 | 62 | return True |
|
63 | 63 | except: |
|
64 | 64 | return False |
|
65 | 65 | |
|
66 | 66 | def has_executablebit(): |
|
67 | 67 | try: |
|
68 | 68 | EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH |
|
69 | 69 | fh, fn = tempfile.mkstemp(dir=".", prefix='hg-checkexec-') |
|
70 | 70 | try: |
|
71 | 71 | os.close(fh) |
|
72 | 72 | m = os.stat(fn).st_mode & 0777 |
|
73 | 73 | new_file_has_exec = m & EXECFLAGS |
|
74 | 74 | os.chmod(fn, m ^ EXECFLAGS) |
|
75 | 75 | exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m) |
|
76 | 76 | finally: |
|
77 | 77 | os.unlink(fn) |
|
78 | 78 | except (IOError, OSError): |
|
79 | 79 | # we don't care, the user probably won't be able to commit anyway |
|
80 | 80 | return False |
|
81 | 81 | return not (new_file_has_exec or exec_flags_cannot_flip) |
|
82 | 82 | |
|
83 | 83 | def has_icasefs(): |
|
84 | 84 | # Stolen from mercurial.util |
|
85 | 85 | fd, path = tempfile.mkstemp(prefix=tempprefix, dir='.') |
|
86 | 86 | os.close(fd) |
|
87 | 87 | try: |
|
88 | 88 | s1 = os.stat(path) |
|
89 | 89 | d, b = os.path.split(path) |
|
90 | 90 | p2 = os.path.join(d, b.upper()) |
|
91 | 91 | if path == p2: |
|
92 | 92 | p2 = os.path.join(d, b.lower()) |
|
93 | 93 | try: |
|
94 | 94 | s2 = os.stat(p2) |
|
95 | 95 | return s2 == s1 |
|
96 | 96 | except: |
|
97 | 97 | return False |
|
98 | 98 | finally: |
|
99 | 99 | os.remove(path) |
|
100 | 100 | |
|
101 | 101 | def has_inotify(): |
|
102 | 102 | try: |
|
103 | 103 | import hgext.inotify.linux.watcher |
|
104 | 104 | return True |
|
105 | 105 | except ImportError: |
|
106 | 106 | return False |
|
107 | 107 | |
|
108 | 108 | def has_fifo(): |
|
109 | 109 | return hasattr(os, "mkfifo") |
|
110 | 110 | |
|
111 | 111 | def has_cacheable_fs(): |
|
112 | 112 | from mercurial import util |
|
113 | 113 | |
|
114 | 114 | fd, path = tempfile.mkstemp(prefix=tempprefix) |
|
115 | 115 | os.close(fd) |
|
116 | 116 | try: |
|
117 | 117 | return util.cachestat(path).cacheable() |
|
118 | 118 | finally: |
|
119 | 119 | os.remove(path) |
|
120 | 120 | |
|
121 | 121 | def has_lsprof(): |
|
122 | 122 | try: |
|
123 | 123 | import _lsprof |
|
124 | 124 | return True |
|
125 | 125 | except ImportError: |
|
126 | 126 | return False |
|
127 | 127 | |
|
128 | 128 | def has_gettext(): |
|
129 | 129 | return matchoutput('msgfmt --version', 'GNU gettext-tools') |
|
130 | 130 | |
|
131 | 131 | def has_git(): |
|
132 | 132 | return matchoutput('git --version 2>&1', r'^git version') |
|
133 | 133 | |
|
134 | 134 | def has_docutils(): |
|
135 | 135 | try: |
|
136 | 136 | from docutils.core import publish_cmdline |
|
137 | 137 | return True |
|
138 | 138 | except ImportError: |
|
139 | 139 | return False |
|
140 | 140 | |
|
141 | 141 | def getsvnversion(): |
|
142 | 142 | m = matchoutput('svn --version 2>&1', r'^svn,\s+version\s+(\d+)\.(\d+)') |
|
143 | 143 | if not m: |
|
144 | 144 | return (0, 0) |
|
145 | 145 | return (int(m.group(1)), int(m.group(2))) |
|
146 | 146 | |
|
147 | 147 | def has_svn15(): |
|
148 | 148 | return getsvnversion() >= (1, 5) |
|
149 | 149 | |
|
150 | 150 | def has_svn13(): |
|
151 | 151 | return getsvnversion() >= (1, 3) |
|
152 | 152 | |
|
153 | 153 | def has_svn(): |
|
154 | 154 | return matchoutput('svn --version 2>&1', r'^svn, version') and \ |
|
155 | 155 | matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') |
|
156 | 156 | |
|
157 | 157 | def has_svn_bindings(): |
|
158 | 158 | try: |
|
159 | 159 | import svn.core |
|
160 | 160 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR |
|
161 | 161 | if version < (1, 4): |
|
162 | 162 | return False |
|
163 | 163 | return True |
|
164 | 164 | except ImportError: |
|
165 | 165 | return False |
|
166 | 166 | |
|
167 | 167 | def has_p4(): |
|
168 | 168 | return matchoutput('p4 -V', r'Rev\. P4/') and matchoutput('p4d -V', r'Rev\. P4D/') |
|
169 | 169 | |
|
170 | 170 | def has_symlink(): |
|
171 | 171 | if not hasattr(os, "symlink"): |
|
172 | 172 | return False |
|
173 | 173 | name = tempfile.mktemp(dir=".", prefix='hg-checklink-') |
|
174 | 174 | try: |
|
175 | 175 | os.symlink(".", name) |
|
176 | 176 | os.unlink(name) |
|
177 | 177 | return True |
|
178 | 178 | except (OSError, AttributeError): |
|
179 | 179 | return False |
|
180 | return hasattr(os, "symlink") # FIXME: should also check file system and os | |
|
181 | 180 | |
|
182 | 181 | def has_tla(): |
|
183 | 182 | return matchoutput('tla --version 2>&1', r'The GNU Arch Revision') |
|
184 | 183 | |
|
185 | 184 | def has_gpg(): |
|
186 | 185 | return matchoutput('gpg --version 2>&1', r'GnuPG') |
|
187 | 186 | |
|
188 | 187 | def has_unix_permissions(): |
|
189 | 188 | d = tempfile.mkdtemp(prefix=tempprefix, dir=".") |
|
190 | 189 | try: |
|
191 | 190 | fname = os.path.join(d, 'foo') |
|
192 | 191 | for umask in (077, 007, 022): |
|
193 | 192 | os.umask(umask) |
|
194 | 193 | f = open(fname, 'w') |
|
195 | 194 | f.close() |
|
196 | 195 | mode = os.stat(fname).st_mode |
|
197 | 196 | os.unlink(fname) |
|
198 | 197 | if mode & 0777 != ~umask & 0666: |
|
199 | 198 | return False |
|
200 | 199 | return True |
|
201 | 200 | finally: |
|
202 | 201 | os.rmdir(d) |
|
203 | 202 | |
|
204 | 203 | def has_pyflakes(): |
|
205 | 204 | return matchoutput('echo "import re" 2>&1 | pyflakes', |
|
206 | 205 | r"<stdin>:1: 're' imported but unused", |
|
207 | 206 | True) |
|
208 | 207 | |
|
209 | 208 | def has_pygments(): |
|
210 | 209 | try: |
|
211 | 210 | import pygments |
|
212 | 211 | return True |
|
213 | 212 | except ImportError: |
|
214 | 213 | return False |
|
215 | 214 | |
|
216 | 215 | def has_outer_repo(): |
|
217 | 216 | return matchoutput('hg root 2>&1', r'') |
|
218 | 217 | |
|
219 | 218 | def has_ssl(): |
|
220 | 219 | try: |
|
221 | 220 | import ssl |
|
222 | 221 | import OpenSSL |
|
223 | 222 | OpenSSL.SSL.Context |
|
224 | 223 | return True |
|
225 | 224 | except ImportError: |
|
226 | 225 | return False |
|
227 | 226 | |
|
228 | 227 | def has_windows(): |
|
229 | 228 | return os.name == 'nt' |
|
230 | 229 | |
|
231 | 230 | def has_system_sh(): |
|
232 | 231 | return os.name != 'nt' |
|
233 | 232 | |
|
234 | 233 | def has_serve(): |
|
235 | 234 | return os.name != 'nt' # gross approximation |
|
236 | 235 | |
|
237 | 236 | def has_tic(): |
|
238 | 237 | return matchoutput('test -x "`which tic`"', '') |
|
239 | 238 | |
|
240 | 239 | def has_msys(): |
|
241 | 240 | return os.getenv('MSYSTEM') |
|
242 | 241 | |
|
243 | 242 | checks = { |
|
244 | 243 | "baz": (has_baz, "GNU Arch baz client"), |
|
245 | 244 | "bzr": (has_bzr, "Canonical's Bazaar client"), |
|
246 | 245 | "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"), |
|
247 | 246 | "cacheable": (has_cacheable_fs, "cacheable filesystem"), |
|
248 | 247 | "cvs": (has_cvs, "cvs client/server"), |
|
249 | 248 | "darcs": (has_darcs, "darcs client"), |
|
250 | 249 | "docutils": (has_docutils, "Docutils text processing library"), |
|
251 | 250 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), |
|
252 | 251 | "execbit": (has_executablebit, "executable bit"), |
|
253 | 252 | "fifo": (has_fifo, "named pipes"), |
|
254 | 253 | "gettext": (has_gettext, "GNU Gettext (msgfmt)"), |
|
255 | 254 | "git": (has_git, "git command line client"), |
|
256 | 255 | "gpg": (has_gpg, "gpg client"), |
|
257 | 256 | "icasefs": (has_icasefs, "case insensitive file system"), |
|
258 | 257 | "inotify": (has_inotify, "inotify extension support"), |
|
259 | 258 | "lsprof": (has_lsprof, "python lsprof module"), |
|
260 | 259 | "mtn": (has_mtn, "monotone client (>= 1.0)"), |
|
261 | 260 | "outer-repo": (has_outer_repo, "outer repo"), |
|
262 | 261 | "p4": (has_p4, "Perforce server and client"), |
|
263 | 262 | "pyflakes": (has_pyflakes, "Pyflakes python linter"), |
|
264 | 263 | "pygments": (has_pygments, "Pygments source highlighting library"), |
|
265 | 264 | "serve": (has_serve, "platform and python can manage 'hg serve -d'"), |
|
266 | 265 | "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"), |
|
267 | 266 | "svn": (has_svn, "subversion client and admin tools"), |
|
268 | 267 | "svn13": (has_svn13, "subversion client and admin tools >= 1.3"), |
|
269 | 268 | "svn15": (has_svn15, "subversion client and admin tools >= 1.5"), |
|
270 | 269 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), |
|
271 | 270 | "symlink": (has_symlink, "symbolic links"), |
|
272 | 271 | "system-sh": (has_system_sh, "system() uses sh"), |
|
273 | 272 | "tic": (has_tic, "terminfo compiler"), |
|
274 | 273 | "tla": (has_tla, "GNU Arch tla client"), |
|
275 | 274 | "unix-permissions": (has_unix_permissions, "unix-style permissions"), |
|
276 | 275 | "windows": (has_windows, "Windows"), |
|
277 | 276 | "msys": (has_msys, "Windows with MSYS"), |
|
278 | 277 | } |
|
279 | 278 | |
|
280 | 279 | def list_features(): |
|
281 | 280 | for name, feature in checks.iteritems(): |
|
282 | 281 | desc = feature[1] |
|
283 | 282 | print name + ':', desc |
|
284 | 283 | |
|
285 | 284 | def test_features(): |
|
286 | 285 | failed = 0 |
|
287 | 286 | for name, feature in checks.iteritems(): |
|
288 | 287 | check, _ = feature |
|
289 | 288 | try: |
|
290 | 289 | check() |
|
291 | 290 | except Exception, e: |
|
292 | 291 | print "feature %s failed: %s" % (name, e) |
|
293 | 292 | failed += 1 |
|
294 | 293 | return failed |
|
295 | 294 | |
|
296 | 295 | parser = optparse.OptionParser("%prog [options] [features]") |
|
297 | 296 | parser.add_option("--test-features", action="store_true", |
|
298 | 297 | help="test available features") |
|
299 | 298 | parser.add_option("--list-features", action="store_true", |
|
300 | 299 | help="list available features") |
|
301 | 300 | parser.add_option("-q", "--quiet", action="store_true", |
|
302 | 301 | help="check features silently") |
|
303 | 302 | |
|
304 | 303 | if __name__ == '__main__': |
|
305 | 304 | options, args = parser.parse_args() |
|
306 | 305 | if options.list_features: |
|
307 | 306 | list_features() |
|
308 | 307 | sys.exit(0) |
|
309 | 308 | |
|
310 | 309 | if options.test_features: |
|
311 | 310 | sys.exit(test_features()) |
|
312 | 311 | |
|
313 | 312 | quiet = options.quiet |
|
314 | 313 | |
|
315 | 314 | failures = 0 |
|
316 | 315 | |
|
317 | 316 | def error(msg): |
|
318 | 317 | global failures |
|
319 | 318 | if not quiet: |
|
320 | 319 | sys.stderr.write(msg + '\n') |
|
321 | 320 | failures += 1 |
|
322 | 321 | |
|
323 | 322 | for feature in args: |
|
324 | 323 | negate = feature.startswith('no-') |
|
325 | 324 | if negate: |
|
326 | 325 | feature = feature[3:] |
|
327 | 326 | |
|
328 | 327 | if feature not in checks: |
|
329 | 328 | error('skipped: unknown feature: ' + feature) |
|
330 | 329 | continue |
|
331 | 330 | |
|
332 | 331 | check, desc = checks[feature] |
|
333 | 332 | try: |
|
334 | 333 | available = check() |
|
335 | 334 | except Exception, e: |
|
336 | 335 | error('hghave check failed: ' + feature) |
|
337 | 336 | continue |
|
338 | 337 | |
|
339 | 338 | if not negate and not available: |
|
340 | 339 | error('skipped: missing feature: ' + desc) |
|
341 | 340 | elif negate and available: |
|
342 | 341 | error('skipped: system supports %s' % desc) |
|
343 | 342 | |
|
344 | 343 | if failures != 0: |
|
345 | 344 | sys.exit(1) |
@@ -1,349 +1,350 b'' | |||
|
1 | 1 | $ echo "[extensions]" >> $HGRCPATH |
|
2 | 2 | $ echo "graphlog=" >> $HGRCPATH |
|
3 | 3 | |
|
4 | 4 | plain |
|
5 | 5 | |
|
6 | 6 | $ hg init |
|
7 | 7 | $ hg debugbuilddag '+2:f +3:p2 @temp <f+4 @default /p2 +2' \ |
|
8 | 8 | > --config extensions.progress= --config progress.assume-tty=1 \ |
|
9 | 9 | > --config progress.delay=0 --config progress.refresh=0 \ |
|
10 | > --config progress.format=topic,bar,number \ | |
|
10 | 11 | > --config progress.width=60 2>&1 | \ |
|
11 | 12 | > python "$TESTDIR/filtercr.py" |
|
12 | 13 | |
|
13 | 14 | building [ ] 0/12 |
|
14 | 15 | building [ ] 0/12 |
|
15 | 16 | building [ ] 0/12 |
|
16 | 17 | building [ ] 0/12 |
|
17 | 18 | building [==> ] 1/12 |
|
18 | 19 | building [==> ] 1/12 |
|
19 | 20 | building [==> ] 1/12 |
|
20 | 21 | building [==> ] 1/12 |
|
21 | 22 | building [======> ] 2/12 |
|
22 | 23 | building [======> ] 2/12 |
|
23 | 24 | building [=========> ] 3/12 |
|
24 | 25 | building [=========> ] 3/12 |
|
25 | 26 | building [=============> ] 4/12 |
|
26 | 27 | building [=============> ] 4/12 |
|
27 | 28 | building [=============> ] 4/12 |
|
28 | 29 | building [=============> ] 4/12 |
|
29 | 30 | building [=============> ] 4/12 |
|
30 | 31 | building [=============> ] 4/12 |
|
31 | 32 | building [================> ] 5/12 |
|
32 | 33 | building [================> ] 5/12 |
|
33 | 34 | building [====================> ] 6/12 |
|
34 | 35 | building [====================> ] 6/12 |
|
35 | 36 | building [=======================> ] 7/12 |
|
36 | 37 | building [=======================> ] 7/12 |
|
37 | 38 | building [===========================> ] 8/12 |
|
38 | 39 | building [===========================> ] 8/12 |
|
39 | 40 | building [===========================> ] 8/12 |
|
40 | 41 | building [===========================> ] 8/12 |
|
41 | 42 | building [==============================> ] 9/12 |
|
42 | 43 | building [==============================> ] 9/12 |
|
43 | 44 | building [==================================> ] 10/12 |
|
44 | 45 | building [==================================> ] 10/12 |
|
45 | 46 | building [=====================================> ] 11/12 |
|
46 | 47 | building [=====================================> ] 11/12 |
|
47 | 48 | \r (esc) |
|
48 | 49 | |
|
49 | 50 | tags |
|
50 | 51 | $ cat .hg/localtags |
|
51 | 52 | 66f7d451a68b85ed82ff5fcc254daf50c74144bd f |
|
52 | 53 | bebd167eb94d257ace0e814aeb98e6972ed2970d p2 |
|
53 | 54 | dag |
|
54 | 55 | $ hg debugdag -t -b |
|
55 | 56 | +2:f |
|
56 | 57 | +3:p2 |
|
57 | 58 | @temp*f+3 |
|
58 | 59 | @default*/p2+2:tip |
|
59 | 60 | tip |
|
60 | 61 | $ hg id |
|
61 | 62 | 000000000000 |
|
62 | 63 | glog |
|
63 | 64 | $ hg glog --template '{rev}: {desc} [{branches}] @ {date}\n' |
|
64 | 65 | o 11: r11 [] @ 11.00 |
|
65 | 66 | | |
|
66 | 67 | o 10: r10 [] @ 10.00 |
|
67 | 68 | | |
|
68 | 69 | o 9: r9 [] @ 9.00 |
|
69 | 70 | |\ |
|
70 | 71 | | o 8: r8 [temp] @ 8.00 |
|
71 | 72 | | | |
|
72 | 73 | | o 7: r7 [temp] @ 7.00 |
|
73 | 74 | | | |
|
74 | 75 | | o 6: r6 [temp] @ 6.00 |
|
75 | 76 | | | |
|
76 | 77 | | o 5: r5 [temp] @ 5.00 |
|
77 | 78 | | | |
|
78 | 79 | o | 4: r4 [] @ 4.00 |
|
79 | 80 | | | |
|
80 | 81 | o | 3: r3 [] @ 3.00 |
|
81 | 82 | | | |
|
82 | 83 | o | 2: r2 [] @ 2.00 |
|
83 | 84 | |/ |
|
84 | 85 | o 1: r1 [] @ 1.00 |
|
85 | 86 | | |
|
86 | 87 | o 0: r0 [] @ 0.00 |
|
87 | 88 | |
|
88 | 89 | |
|
89 | 90 | overwritten files, starting on a non-default branch |
|
90 | 91 | |
|
91 | 92 | $ rm -r .hg |
|
92 | 93 | $ hg init |
|
93 | 94 | $ hg debugbuilddag '@start.@default.:f +3:p2 @temp <f+4 @default /p2 +2' -q -o |
|
94 | 95 | tags |
|
95 | 96 | $ cat .hg/localtags |
|
96 | 97 | f778700ebd50fcf282b23a4446bd155da6453eb6 f |
|
97 | 98 | bbccf169769006e2490efd2a02f11c3d38d462bd p2 |
|
98 | 99 | dag |
|
99 | 100 | $ hg debugdag -t -b |
|
100 | 101 | @start+1 |
|
101 | 102 | @default+1:f |
|
102 | 103 | +3:p2 |
|
103 | 104 | @temp*f+3 |
|
104 | 105 | @default*/p2+2:tip |
|
105 | 106 | tip |
|
106 | 107 | $ hg id |
|
107 | 108 | 000000000000 |
|
108 | 109 | glog |
|
109 | 110 | $ hg glog --template '{rev}: {desc} [{branches}] @ {date}\n' |
|
110 | 111 | o 11: r11 [] @ 11.00 |
|
111 | 112 | | |
|
112 | 113 | o 10: r10 [] @ 10.00 |
|
113 | 114 | | |
|
114 | 115 | o 9: r9 [] @ 9.00 |
|
115 | 116 | |\ |
|
116 | 117 | | o 8: r8 [temp] @ 8.00 |
|
117 | 118 | | | |
|
118 | 119 | | o 7: r7 [temp] @ 7.00 |
|
119 | 120 | | | |
|
120 | 121 | | o 6: r6 [temp] @ 6.00 |
|
121 | 122 | | | |
|
122 | 123 | | o 5: r5 [temp] @ 5.00 |
|
123 | 124 | | | |
|
124 | 125 | o | 4: r4 [] @ 4.00 |
|
125 | 126 | | | |
|
126 | 127 | o | 3: r3 [] @ 3.00 |
|
127 | 128 | | | |
|
128 | 129 | o | 2: r2 [] @ 2.00 |
|
129 | 130 | |/ |
|
130 | 131 | o 1: r1 [] @ 1.00 |
|
131 | 132 | | |
|
132 | 133 | o 0: r0 [start] @ 0.00 |
|
133 | 134 | |
|
134 | 135 | glog of |
|
135 | 136 | $ hg glog --template '{rev}: {desc} [{branches}]\n' of |
|
136 | 137 | o 11: r11 [] |
|
137 | 138 | | |
|
138 | 139 | o 10: r10 [] |
|
139 | 140 | | |
|
140 | 141 | o 9: r9 [] |
|
141 | 142 | |\ |
|
142 | 143 | | o 8: r8 [temp] |
|
143 | 144 | | | |
|
144 | 145 | | o 7: r7 [temp] |
|
145 | 146 | | | |
|
146 | 147 | | o 6: r6 [temp] |
|
147 | 148 | | | |
|
148 | 149 | | o 5: r5 [temp] |
|
149 | 150 | | | |
|
150 | 151 | o | 4: r4 [] |
|
151 | 152 | | | |
|
152 | 153 | o | 3: r3 [] |
|
153 | 154 | | | |
|
154 | 155 | o | 2: r2 [] |
|
155 | 156 | |/ |
|
156 | 157 | o 1: r1 [] |
|
157 | 158 | | |
|
158 | 159 | o 0: r0 [start] |
|
159 | 160 | |
|
160 | 161 | tags |
|
161 | 162 | $ hg tags -v |
|
162 | 163 | tip 11:9ffe238a67a2 |
|
163 | 164 | p2 4:bbccf1697690 local |
|
164 | 165 | f 1:f778700ebd50 local |
|
165 | 166 | cat of |
|
166 | 167 | $ hg cat of --rev tip |
|
167 | 168 | r11 |
|
168 | 169 | |
|
169 | 170 | |
|
170 | 171 | new and mergeable files |
|
171 | 172 | |
|
172 | 173 | $ rm -r .hg |
|
173 | 174 | $ hg init |
|
174 | 175 | $ hg debugbuilddag '+2:f +3:p2 @temp <f+4 @default /p2 +2' -q -mn |
|
175 | 176 | dag |
|
176 | 177 | $ hg debugdag -t -b |
|
177 | 178 | +2:f |
|
178 | 179 | +3:p2 |
|
179 | 180 | @temp*f+3 |
|
180 | 181 | @default*/p2+2:tip |
|
181 | 182 | tip |
|
182 | 183 | $ hg id |
|
183 | 184 | 000000000000 |
|
184 | 185 | glog |
|
185 | 186 | $ hg glog --template '{rev}: {desc} [{branches}] @ {date}\n' |
|
186 | 187 | o 11: r11 [] @ 11.00 |
|
187 | 188 | | |
|
188 | 189 | o 10: r10 [] @ 10.00 |
|
189 | 190 | | |
|
190 | 191 | o 9: r9 [] @ 9.00 |
|
191 | 192 | |\ |
|
192 | 193 | | o 8: r8 [temp] @ 8.00 |
|
193 | 194 | | | |
|
194 | 195 | | o 7: r7 [temp] @ 7.00 |
|
195 | 196 | | | |
|
196 | 197 | | o 6: r6 [temp] @ 6.00 |
|
197 | 198 | | | |
|
198 | 199 | | o 5: r5 [temp] @ 5.00 |
|
199 | 200 | | | |
|
200 | 201 | o | 4: r4 [] @ 4.00 |
|
201 | 202 | | | |
|
202 | 203 | o | 3: r3 [] @ 3.00 |
|
203 | 204 | | | |
|
204 | 205 | o | 2: r2 [] @ 2.00 |
|
205 | 206 | |/ |
|
206 | 207 | o 1: r1 [] @ 1.00 |
|
207 | 208 | | |
|
208 | 209 | o 0: r0 [] @ 0.00 |
|
209 | 210 | |
|
210 | 211 | glog mf |
|
211 | 212 | $ hg glog --template '{rev}: {desc} [{branches}]\n' mf |
|
212 | 213 | o 11: r11 [] |
|
213 | 214 | | |
|
214 | 215 | o 10: r10 [] |
|
215 | 216 | | |
|
216 | 217 | o 9: r9 [] |
|
217 | 218 | |\ |
|
218 | 219 | | o 8: r8 [temp] |
|
219 | 220 | | | |
|
220 | 221 | | o 7: r7 [temp] |
|
221 | 222 | | | |
|
222 | 223 | | o 6: r6 [temp] |
|
223 | 224 | | | |
|
224 | 225 | | o 5: r5 [temp] |
|
225 | 226 | | | |
|
226 | 227 | o | 4: r4 [] |
|
227 | 228 | | | |
|
228 | 229 | o | 3: r3 [] |
|
229 | 230 | | | |
|
230 | 231 | o | 2: r2 [] |
|
231 | 232 | |/ |
|
232 | 233 | o 1: r1 [] |
|
233 | 234 | | |
|
234 | 235 | o 0: r0 [] |
|
235 | 236 | |
|
236 | 237 | |
|
237 | 238 | man r4 |
|
238 | 239 | $ hg manifest -r4 |
|
239 | 240 | mf |
|
240 | 241 | nf0 |
|
241 | 242 | nf1 |
|
242 | 243 | nf2 |
|
243 | 244 | nf3 |
|
244 | 245 | nf4 |
|
245 | 246 | cat r4 mf |
|
246 | 247 | $ hg cat -r4 mf |
|
247 | 248 | 0 r0 |
|
248 | 249 | 1 |
|
249 | 250 | 2 r1 |
|
250 | 251 | 3 |
|
251 | 252 | 4 r2 |
|
252 | 253 | 5 |
|
253 | 254 | 6 r3 |
|
254 | 255 | 7 |
|
255 | 256 | 8 r4 |
|
256 | 257 | 9 |
|
257 | 258 | 10 |
|
258 | 259 | 11 |
|
259 | 260 | 12 |
|
260 | 261 | 13 |
|
261 | 262 | 14 |
|
262 | 263 | 15 |
|
263 | 264 | 16 |
|
264 | 265 | 17 |
|
265 | 266 | 18 |
|
266 | 267 | 19 |
|
267 | 268 | 20 |
|
268 | 269 | 21 |
|
269 | 270 | 22 |
|
270 | 271 | 23 |
|
271 | 272 | man r8 |
|
272 | 273 | $ hg manifest -r8 |
|
273 | 274 | mf |
|
274 | 275 | nf0 |
|
275 | 276 | nf1 |
|
276 | 277 | nf5 |
|
277 | 278 | nf6 |
|
278 | 279 | nf7 |
|
279 | 280 | nf8 |
|
280 | 281 | cat r8 mf |
|
281 | 282 | $ hg cat -r8 mf |
|
282 | 283 | 0 r0 |
|
283 | 284 | 1 |
|
284 | 285 | 2 r1 |
|
285 | 286 | 3 |
|
286 | 287 | 4 |
|
287 | 288 | 5 |
|
288 | 289 | 6 |
|
289 | 290 | 7 |
|
290 | 291 | 8 |
|
291 | 292 | 9 |
|
292 | 293 | 10 r5 |
|
293 | 294 | 11 |
|
294 | 295 | 12 r6 |
|
295 | 296 | 13 |
|
296 | 297 | 14 r7 |
|
297 | 298 | 15 |
|
298 | 299 | 16 r8 |
|
299 | 300 | 17 |
|
300 | 301 | 18 |
|
301 | 302 | 19 |
|
302 | 303 | 20 |
|
303 | 304 | 21 |
|
304 | 305 | 22 |
|
305 | 306 | 23 |
|
306 | 307 | man |
|
307 | 308 | $ hg manifest --rev tip |
|
308 | 309 | mf |
|
309 | 310 | nf0 |
|
310 | 311 | nf1 |
|
311 | 312 | nf10 |
|
312 | 313 | nf11 |
|
313 | 314 | nf2 |
|
314 | 315 | nf3 |
|
315 | 316 | nf4 |
|
316 | 317 | nf5 |
|
317 | 318 | nf6 |
|
318 | 319 | nf7 |
|
319 | 320 | nf8 |
|
320 | 321 | nf9 |
|
321 | 322 | cat mf |
|
322 | 323 | $ hg cat mf --rev tip |
|
323 | 324 | 0 r0 |
|
324 | 325 | 1 |
|
325 | 326 | 2 r1 |
|
326 | 327 | 3 |
|
327 | 328 | 4 r2 |
|
328 | 329 | 5 |
|
329 | 330 | 6 r3 |
|
330 | 331 | 7 |
|
331 | 332 | 8 r4 |
|
332 | 333 | 9 |
|
333 | 334 | 10 r5 |
|
334 | 335 | 11 |
|
335 | 336 | 12 r6 |
|
336 | 337 | 13 |
|
337 | 338 | 14 r7 |
|
338 | 339 | 15 |
|
339 | 340 | 16 r8 |
|
340 | 341 | 17 |
|
341 | 342 | 18 r9 |
|
342 | 343 | 19 |
|
343 | 344 | 20 r10 |
|
344 | 345 | 21 |
|
345 | 346 | 22 r11 |
|
346 | 347 | 23 |
|
347 | 348 | |
|
348 | 349 | |
|
349 | 350 |
@@ -1,142 +1,193 b'' | |||
|
1 | 1 | $ hg init repo |
|
2 | 2 | $ cd repo |
|
3 | 3 | $ cat > a <<EOF |
|
4 | 4 | > c |
|
5 | 5 | > c |
|
6 | 6 | > a |
|
7 | 7 | > a |
|
8 | 8 | > b |
|
9 | 9 | > a |
|
10 | 10 | > a |
|
11 | 11 | > c |
|
12 | 12 | > c |
|
13 | 13 | > EOF |
|
14 | 14 | $ hg ci -Am adda |
|
15 | 15 | adding a |
|
16 | 16 | |
|
17 | 17 | $ cat > a <<EOF |
|
18 | 18 | > c |
|
19 | 19 | > c |
|
20 | 20 | > a |
|
21 | 21 | > a |
|
22 | 22 | > dd |
|
23 | 23 | > a |
|
24 | 24 | > a |
|
25 | 25 | > c |
|
26 | 26 | > c |
|
27 | 27 | > EOF |
|
28 | 28 | |
|
29 | 29 | default context |
|
30 | 30 | |
|
31 | 31 | $ hg diff --nodates |
|
32 | 32 | diff -r cf9f4ba66af2 a |
|
33 | 33 | --- a/a |
|
34 | 34 | +++ b/a |
|
35 | 35 | @@ -2,7 +2,7 @@ |
|
36 | 36 | c |
|
37 | 37 | a |
|
38 | 38 | a |
|
39 | 39 | -b |
|
40 | 40 | +dd |
|
41 | 41 | a |
|
42 | 42 | a |
|
43 | 43 | c |
|
44 | 44 | |
|
45 | 45 | invalid --unified |
|
46 | 46 | |
|
47 | 47 | $ hg diff --nodates -U foo |
|
48 | 48 | abort: diff context lines count must be an integer, not 'foo' |
|
49 | 49 | [255] |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 52 | $ hg diff --nodates -U 2 |
|
53 | 53 | diff -r cf9f4ba66af2 a |
|
54 | 54 | --- a/a |
|
55 | 55 | +++ b/a |
|
56 | 56 | @@ -3,5 +3,5 @@ |
|
57 | 57 | a |
|
58 | 58 | a |
|
59 | 59 | -b |
|
60 | 60 | +dd |
|
61 | 61 | a |
|
62 | 62 | a |
|
63 | 63 | |
|
64 | 64 | $ hg --config diff.unified=2 diff --nodates |
|
65 | 65 | diff -r cf9f4ba66af2 a |
|
66 | 66 | --- a/a |
|
67 | 67 | +++ b/a |
|
68 | 68 | @@ -3,5 +3,5 @@ |
|
69 | 69 | a |
|
70 | 70 | a |
|
71 | 71 | -b |
|
72 | 72 | +dd |
|
73 | 73 | a |
|
74 | 74 | a |
|
75 | 75 | |
|
76 | 76 | $ hg diff --nodates -U 1 |
|
77 | 77 | diff -r cf9f4ba66af2 a |
|
78 | 78 | --- a/a |
|
79 | 79 | +++ b/a |
|
80 | 80 | @@ -4,3 +4,3 @@ |
|
81 | 81 | a |
|
82 | 82 | -b |
|
83 | 83 | +dd |
|
84 | 84 | a |
|
85 | 85 | |
|
86 | 86 | invalid diff.unified |
|
87 | 87 | |
|
88 | 88 | $ hg --config diff.unified=foo diff --nodates |
|
89 | 89 | abort: diff context lines count must be an integer, not 'foo' |
|
90 | 90 | [255] |
|
91 | 91 | |
|
92 | 92 | 0 lines of context hunk header matches gnu diff hunk header |
|
93 | 93 | |
|
94 | 94 | $ hg init diffzero |
|
95 | 95 | $ cd diffzero |
|
96 | 96 | $ cat > f1 << EOF |
|
97 | 97 | > c2 |
|
98 | 98 | > c4 |
|
99 | 99 | > c5 |
|
100 | 100 | > EOF |
|
101 | 101 | $ hg commit -Am0 |
|
102 | 102 | adding f1 |
|
103 | 103 | |
|
104 | 104 | $ cat > f2 << EOF |
|
105 | 105 | > c1 |
|
106 | 106 | > c2 |
|
107 | 107 | > c3 |
|
108 | 108 | > c4 |
|
109 | 109 | > EOF |
|
110 | 110 | $ mv f2 f1 |
|
111 | 111 | $ hg diff -U0 --nodates |
|
112 | 112 | diff -r 55d8ff78db23 f1 |
|
113 | 113 | --- a/f1 |
|
114 | 114 | +++ b/f1 |
|
115 | 115 | @@ -0,0 +1,1 @@ |
|
116 | 116 | +c1 |
|
117 | 117 | @@ -1,0 +3,1 @@ |
|
118 | 118 | +c3 |
|
119 | 119 | @@ -3,1 +4,0 @@ |
|
120 | 120 | -c5 |
|
121 | 121 | |
|
122 | 122 | $ hg diff -U0 --nodates --git |
|
123 | 123 | diff --git a/f1 b/f1 |
|
124 | 124 | --- a/f1 |
|
125 | 125 | +++ b/f1 |
|
126 | 126 | @@ -0,0 +1,1 @@ |
|
127 | 127 | +c1 |
|
128 | 128 | @@ -1,0 +3,1 @@ |
|
129 | 129 | +c3 |
|
130 | 130 | @@ -3,1 +4,0 @@ |
|
131 | 131 | -c5 |
|
132 | 132 | |
|
133 | 133 | $ hg diff -U0 --nodates -p |
|
134 | 134 | diff -r 55d8ff78db23 f1 |
|
135 | 135 | --- a/f1 |
|
136 | 136 | +++ b/f1 |
|
137 | 137 | @@ -0,0 +1,1 @@ |
|
138 | 138 | +c1 |
|
139 | 139 | @@ -1,0 +3,1 @@ c2 |
|
140 | 140 | +c3 |
|
141 | 141 | @@ -3,1 +4,0 @@ c4 |
|
142 | 142 | -c5 |
|
143 | ||
|
144 | $ echo a > f1 | |
|
145 | $ hg ci -m movef2 | |
|
146 | ||
|
147 | Test diff headers terminating with TAB when necessary (issue3357) | |
|
148 | Regular diff --nodates, file creation | |
|
149 | ||
|
150 | $ hg mv f1 'f 1' | |
|
151 | $ echo b > 'f 1' | |
|
152 | $ hg diff --nodates 'f 1' | |
|
153 | diff -r 7574207d0d15 f 1 | |
|
154 | --- /dev/null | |
|
155 | +++ b/f 1 | |
|
156 | @@ -0,0 +1,1 @@ | |
|
157 | +b | |
|
158 | ||
|
159 | Git diff, adding space | |
|
160 | ||
|
161 | $ hg diff --git | |
|
162 | diff --git a/f1 b/f 1 | |
|
163 | rename from f1 | |
|
164 | rename to f 1 | |
|
165 | --- a/f1 | |
|
166 | +++ b/f 1 | |
|
167 | @@ -1,1 +1,1 @@ | |
|
168 | -a | |
|
169 | +b | |
|
170 | ||
|
171 | Regular diff --nodates, file deletion | |
|
172 | ||
|
173 | $ hg ci -m addspace | |
|
174 | $ hg mv 'f 1' f1 | |
|
175 | $ echo a > f1 | |
|
176 | $ hg diff --nodates 'f 1' | |
|
177 | diff -r ca50fe67c9c7 f 1 | |
|
178 | --- a/f 1 | |
|
179 | +++ /dev/null | |
|
180 | @@ -1,1 +0,0 @@ | |
|
181 | -b | |
|
182 | ||
|
183 | Git diff, removing space | |
|
184 | ||
|
185 | $ hg diff --git | |
|
186 | diff --git a/f 1 b/f1 | |
|
187 | rename from f 1 | |
|
188 | rename to f1 | |
|
189 | --- a/f 1 | |
|
190 | +++ b/f1 | |
|
191 | @@ -1,1 +1,1 @@ | |
|
192 | -b | |
|
193 | +a |
@@ -1,131 +1,145 b'' | |||
|
1 | 1 | $ hg init repo |
|
2 | 2 | $ cd repo |
|
3 | 3 | $ touch foo |
|
4 | 4 | $ hg add foo |
|
5 | 5 | $ for i in 0 1 2 3 4 5 6 7 8 9 10 11; do |
|
6 | 6 | > echo "foo-$i" >> foo |
|
7 | 7 | > hg ci -m "foo-$i" |
|
8 | 8 | > done |
|
9 | 9 | |
|
10 | 10 | $ for out in "%nof%N" "%%%H" "%b-%R" "%h" "%r" "%m"; do |
|
11 | 11 | > echo |
|
12 | 12 | > echo "# foo-$out.patch" |
|
13 | 13 | > hg export -v -o "foo-$out.patch" 2:tip |
|
14 | 14 | > done |
|
15 | 15 | |
|
16 | 16 | # foo-%nof%N.patch |
|
17 | 17 | exporting patches: |
|
18 | 18 | foo-01of10.patch |
|
19 | 19 | foo-02of10.patch |
|
20 | 20 | foo-03of10.patch |
|
21 | 21 | foo-04of10.patch |
|
22 | 22 | foo-05of10.patch |
|
23 | 23 | foo-06of10.patch |
|
24 | 24 | foo-07of10.patch |
|
25 | 25 | foo-08of10.patch |
|
26 | 26 | foo-09of10.patch |
|
27 | 27 | foo-10of10.patch |
|
28 | 28 | |
|
29 | 29 | # foo-%%%H.patch |
|
30 | 30 | exporting patches: |
|
31 | 31 | foo-%617188a1c80f869a7b66c85134da88a6fb145f67.patch |
|
32 | 32 | foo-%dd41a5ff707a5225204105611ba49cc5c229d55f.patch |
|
33 | 33 | foo-%f95a5410f8664b6e1490a4af654e4b7d41a7b321.patch |
|
34 | 34 | foo-%4346bcfde53b4d9042489078bcfa9c3e28201db2.patch |
|
35 | 35 | foo-%afda8c3a009cc99449a05ad8aa4655648c4ecd34.patch |
|
36 | 36 | foo-%35284ce2b6b99c9d2ac66268fe99e68e1974e1aa.patch |
|
37 | 37 | foo-%9688c41894e6931305fa7165a37f6568050b4e9b.patch |
|
38 | 38 | foo-%747d3c68f8ec44bb35816bfcd59aeb50b9654c2f.patch |
|
39 | 39 | foo-%5f17a83f5fbd9414006a5e563eab4c8a00729efd.patch |
|
40 | 40 | foo-%f3acbafac161ec68f1598af38f794f28847ca5d3.patch |
|
41 | 41 | |
|
42 | 42 | # foo-%b-%R.patch |
|
43 | 43 | exporting patches: |
|
44 | 44 | foo-repo-2.patch |
|
45 | 45 | foo-repo-3.patch |
|
46 | 46 | foo-repo-4.patch |
|
47 | 47 | foo-repo-5.patch |
|
48 | 48 | foo-repo-6.patch |
|
49 | 49 | foo-repo-7.patch |
|
50 | 50 | foo-repo-8.patch |
|
51 | 51 | foo-repo-9.patch |
|
52 | 52 | foo-repo-10.patch |
|
53 | 53 | foo-repo-11.patch |
|
54 | 54 | |
|
55 | 55 | # foo-%h.patch |
|
56 | 56 | exporting patches: |
|
57 | 57 | foo-617188a1c80f.patch |
|
58 | 58 | foo-dd41a5ff707a.patch |
|
59 | 59 | foo-f95a5410f866.patch |
|
60 | 60 | foo-4346bcfde53b.patch |
|
61 | 61 | foo-afda8c3a009c.patch |
|
62 | 62 | foo-35284ce2b6b9.patch |
|
63 | 63 | foo-9688c41894e6.patch |
|
64 | 64 | foo-747d3c68f8ec.patch |
|
65 | 65 | foo-5f17a83f5fbd.patch |
|
66 | 66 | foo-f3acbafac161.patch |
|
67 | 67 | |
|
68 | 68 | # foo-%r.patch |
|
69 | 69 | exporting patches: |
|
70 | 70 | foo-02.patch |
|
71 | 71 | foo-03.patch |
|
72 | 72 | foo-04.patch |
|
73 | 73 | foo-05.patch |
|
74 | 74 | foo-06.patch |
|
75 | 75 | foo-07.patch |
|
76 | 76 | foo-08.patch |
|
77 | 77 | foo-09.patch |
|
78 | 78 | foo-10.patch |
|
79 | 79 | foo-11.patch |
|
80 | 80 | |
|
81 | 81 | # foo-%m.patch |
|
82 | 82 | exporting patches: |
|
83 | 83 | foo-foo_2.patch |
|
84 | 84 | foo-foo_3.patch |
|
85 | 85 | foo-foo_4.patch |
|
86 | 86 | foo-foo_5.patch |
|
87 | 87 | foo-foo_6.patch |
|
88 | 88 | foo-foo_7.patch |
|
89 | 89 | foo-foo_8.patch |
|
90 | 90 | foo-foo_9.patch |
|
91 | 91 | foo-foo_10.patch |
|
92 | 92 | foo-foo_11.patch |
|
93 | 93 | |
|
94 | 94 | Exporting 4 changesets to a file: |
|
95 | 95 | |
|
96 | 96 | $ hg export -o export_internal 1 2 3 4 |
|
97 | 97 | $ grep HG export_internal | wc -l |
|
98 | 98 | \s*4 (re) |
|
99 | 99 | |
|
100 | 100 | Exporting 4 changesets to a file: |
|
101 | 101 | |
|
102 | 102 | $ hg export 1 2 3 4 | grep HG | wc -l |
|
103 | 103 | \s*4 (re) |
|
104 | 104 | |
|
105 | 105 | Exporting revision -2 to a file: |
|
106 | 106 | |
|
107 | 107 | $ hg export -- -2 |
|
108 | 108 | # HG changeset patch |
|
109 | 109 | # User test |
|
110 | 110 | # Date 0 0 |
|
111 | 111 | # Node ID 5f17a83f5fbd9414006a5e563eab4c8a00729efd |
|
112 | 112 | # Parent 747d3c68f8ec44bb35816bfcd59aeb50b9654c2f |
|
113 | 113 | foo-10 |
|
114 | 114 | |
|
115 | 115 | diff -r 747d3c68f8ec -r 5f17a83f5fbd foo |
|
116 | 116 | --- a/foo Thu Jan 01 00:00:00 1970 +0000 |
|
117 | 117 | +++ b/foo Thu Jan 01 00:00:00 1970 +0000 |
|
118 | 118 | @@ -8,3 +8,4 @@ |
|
119 | 119 | foo-7 |
|
120 | 120 | foo-8 |
|
121 | 121 | foo-9 |
|
122 | 122 | +foo-10 |
|
123 | 123 | |
|
124 | 124 | Checking if only alphanumeric characters are used in the file name (%m option): |
|
125 | 125 | |
|
126 | 126 | $ echo "line" >> foo |
|
127 | 127 | $ hg commit -m " !\"#$%&(,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\`abcdefghijklmnopqrstuvwxyz{|}~" |
|
128 | 128 | $ hg export -v -o %m.patch tip |
|
129 | 129 | exporting patch: |
|
130 | 130 | ____________0123456789_______ABCDEFGHIJKLMNOPQRSTUVWXYZ______abcdefghijklmnopqrstuvwxyz____.patch |
|
131 | 131 | |
|
132 | Catch exporting unknown revisions (especially empty revsets, see issue3353) | |
|
133 | ||
|
134 | $ hg export | |
|
135 | abort: export requires at least one changeset | |
|
136 | [255] | |
|
137 | $ hg export "" | |
|
138 | hg: parse error: empty query | |
|
139 | [255] | |
|
140 | $ hg export 999 | |
|
141 | abort: unknown revision '999'! | |
|
142 | [255] | |
|
143 | $ hg export "not all()" | |
|
144 | abort: export requires at least one changeset | |
|
145 | [255] |
@@ -1,28 +1,28 b'' | |||
|
1 | 1 | Test hangup signal in the middle of transaction |
|
2 | 2 | |
|
3 | 3 | $ "$TESTDIR/hghave" serve fifo || exit 80 |
|
4 | 4 | $ hg init |
|
5 | 5 | $ mkfifo p |
|
6 | 6 | $ hg serve --stdio < p 1>out 2>&1 & |
|
7 | 7 | $ P=$! |
|
8 | 8 | |
|
9 | 9 | Do test while holding fifo open |
|
10 | 10 | |
|
11 | 11 | $ ( |
|
12 | 12 | > echo lock |
|
13 | 13 | > echo addchangegroup |
|
14 |
> while [ ! -s .hg/store/journal ]; do |
|
|
14 | > while [ ! -s .hg/store/journal ]; do sleep 0; done | |
|
15 | 15 | > kill -HUP $P |
|
16 | 16 | > ) > p |
|
17 | 17 | |
|
18 | 18 | $ wait |
|
19 | 19 | $ cat out |
|
20 | 20 | 0 |
|
21 | 21 | 0 |
|
22 | 22 | adding changesets |
|
23 | 23 | transaction abort! |
|
24 | 24 | rollback completed |
|
25 | 25 | killed! |
|
26 | 26 | |
|
27 | 27 | $ echo .hg/* .hg/store/* |
|
28 | 28 | .hg/00changelog.i .hg/journal.bookmarks .hg/journal.branch .hg/journal.desc .hg/journal.dirstate .hg/requires .hg/store .hg/store/00changelog.i .hg/store/00changelog.i.a .hg/store/journal.phaseroots |
@@ -1,264 +1,272 b'' | |||
|
1 | 1 | $ "$TESTDIR/hghave" serve || exit 80 |
|
2 | 2 | |
|
3 | 3 | $ cat > writelines.py <<EOF |
|
4 | 4 | > import sys |
|
5 | 5 | > path = sys.argv[1] |
|
6 | 6 | > args = sys.argv[2:] |
|
7 | 7 | > assert (len(args) % 2) == 0 |
|
8 | 8 | > |
|
9 | 9 | > f = file(path, 'wb') |
|
10 | 10 | > for i in xrange(len(args)/2): |
|
11 | 11 | > count, s = args[2*i:2*i+2] |
|
12 | 12 | > count = int(count) |
|
13 | 13 | > s = s.decode('string_escape') |
|
14 | 14 | > f.write(s*count) |
|
15 | 15 | > f.close() |
|
16 | 16 | > |
|
17 | 17 | > EOF |
|
18 | 18 | $ echo "[extensions]" >> $HGRCPATH |
|
19 | 19 | $ echo "mq=" >> $HGRCPATH |
|
20 | 20 | $ echo "[diff]" >> $HGRCPATH |
|
21 | 21 | $ echo "git=1" >> $HGRCPATH |
|
22 | 22 | $ hg init repo |
|
23 | 23 | $ cd repo |
|
24 | 24 | |
|
25 | 25 | qimport non-existing-file |
|
26 | 26 | |
|
27 | 27 | $ hg qimport non-existing-file |
|
28 | 28 | abort: unable to read file non-existing-file |
|
29 | 29 | [255] |
|
30 | 30 | |
|
31 | qimport null revision | |
|
32 | ||
|
33 | $ hg qimport -r null | |
|
34 | abort: revision -1 is not mutable | |
|
35 | (see "hg help phases" for details) | |
|
36 | [255] | |
|
37 | $ hg qseries | |
|
38 | ||
|
31 | 39 | import email |
|
32 | 40 | |
|
33 | 41 | $ hg qimport --push -n email - <<EOF |
|
34 | 42 | > From: Username in email <test@example.net> |
|
35 | 43 | > Subject: [PATCH] Message in email |
|
36 | 44 | > Date: Fri, 02 Jan 1970 00:00:00 +0000 |
|
37 | 45 | > |
|
38 | 46 | > Text before patch. |
|
39 | 47 | > |
|
40 | 48 | > # HG changeset patch |
|
41 | 49 | > # User Username in patch <test@example.net> |
|
42 | 50 | > # Date 0 0 |
|
43 | 51 | > # Node ID 1a706973a7d84cb549823634a821d9bdf21c6220 |
|
44 | 52 | > # Parent 0000000000000000000000000000000000000000 |
|
45 | 53 | > First line of commit message. |
|
46 | 54 | > |
|
47 | 55 | > More text in commit message. |
|
48 | 56 | > --- confuse the diff detection |
|
49 | 57 | > |
|
50 | 58 | > diff --git a/x b/x |
|
51 | 59 | > new file mode 100644 |
|
52 | 60 | > --- /dev/null |
|
53 | 61 | > +++ b/x |
|
54 | 62 | > @@ -0,0 +1,1 @@ |
|
55 | 63 | > +new file |
|
56 | 64 | > Text after patch. |
|
57 | 65 | > |
|
58 | 66 | > EOF |
|
59 | 67 | adding email to series file |
|
60 | 68 | applying email |
|
61 | 69 | now at: email |
|
62 | 70 | |
|
63 | 71 | hg tip -v |
|
64 | 72 | |
|
65 | 73 | $ hg tip -v |
|
66 | 74 | changeset: 0:1a706973a7d8 |
|
67 | 75 | tag: email |
|
68 | 76 | tag: qbase |
|
69 | 77 | tag: qtip |
|
70 | 78 | tag: tip |
|
71 | 79 | user: Username in patch <test@example.net> |
|
72 | 80 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
73 | 81 | files: x |
|
74 | 82 | description: |
|
75 | 83 | First line of commit message. |
|
76 | 84 | |
|
77 | 85 | More text in commit message. |
|
78 | 86 | |
|
79 | 87 | |
|
80 | 88 | $ hg qpop |
|
81 | 89 | popping email |
|
82 | 90 | patch queue now empty |
|
83 | 91 | $ hg qdelete email |
|
84 | 92 | |
|
85 | 93 | import URL |
|
86 | 94 | |
|
87 | 95 | $ echo foo >> foo |
|
88 | 96 | $ hg add foo |
|
89 | 97 | $ hg diff > url.diff |
|
90 | 98 | $ hg revert --no-backup foo |
|
91 | 99 | $ rm foo |
|
92 | 100 | |
|
93 | 101 | Under unix: file:///foobar/blah |
|
94 | 102 | Under windows: file:///c:/foobar/blah |
|
95 | 103 | |
|
96 | 104 | $ patchurl=`pwd | tr '\\\\' /`/url.diff |
|
97 | 105 | $ expr "$patchurl" : "\/" > /dev/null || patchurl="/$patchurl" |
|
98 | 106 | $ hg qimport file://"$patchurl" |
|
99 | 107 | adding url.diff to series file |
|
100 | 108 | $ rm url.diff |
|
101 | 109 | $ hg qun |
|
102 | 110 | url.diff |
|
103 | 111 | |
|
104 | 112 | import patch that already exists |
|
105 | 113 | |
|
106 | 114 | $ echo foo2 >> foo |
|
107 | 115 | $ hg add foo |
|
108 | 116 | $ hg diff > ../url.diff |
|
109 | 117 | $ hg revert --no-backup foo |
|
110 | 118 | $ rm foo |
|
111 | 119 | $ hg qimport ../url.diff |
|
112 | 120 | abort: patch "url.diff" already exists |
|
113 | 121 | [255] |
|
114 | 122 | $ hg qpush |
|
115 | 123 | applying url.diff |
|
116 | 124 | now at: url.diff |
|
117 | 125 | $ cat foo |
|
118 | 126 | foo |
|
119 | 127 | $ hg qpop |
|
120 | 128 | popping url.diff |
|
121 | 129 | patch queue now empty |
|
122 | 130 | |
|
123 | 131 | qimport -f |
|
124 | 132 | |
|
125 | 133 | $ hg qimport -f ../url.diff |
|
126 | 134 | adding url.diff to series file |
|
127 | 135 | $ hg qpush |
|
128 | 136 | applying url.diff |
|
129 | 137 | now at: url.diff |
|
130 | 138 | $ cat foo |
|
131 | 139 | foo2 |
|
132 | 140 | $ hg qpop |
|
133 | 141 | popping url.diff |
|
134 | 142 | patch queue now empty |
|
135 | 143 | |
|
136 | 144 | build diff with CRLF |
|
137 | 145 | |
|
138 | 146 | $ python ../writelines.py b 5 'a\n' 5 'a\r\n' |
|
139 | 147 | $ hg ci -Am addb |
|
140 | 148 | adding b |
|
141 | 149 | $ python ../writelines.py b 2 'a\n' 10 'b\n' 2 'a\r\n' |
|
142 | 150 | $ hg diff > b.diff |
|
143 | 151 | $ hg up -C |
|
144 | 152 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
145 | 153 | |
|
146 | 154 | qimport CRLF diff |
|
147 | 155 | |
|
148 | 156 | $ hg qimport b.diff |
|
149 | 157 | adding b.diff to series file |
|
150 | 158 | $ hg qpush |
|
151 | 159 | applying b.diff |
|
152 | 160 | now at: b.diff |
|
153 | 161 | |
|
154 | 162 | try to import --push |
|
155 | 163 | |
|
156 | 164 | $ cat > appendfoo.diff <<EOF |
|
157 | 165 | > append foo |
|
158 | 166 | > |
|
159 | 167 | > diff -r 07f494440405 -r 261500830e46 baz |
|
160 | 168 | > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
161 | 169 | > +++ b/baz Thu Jan 01 00:00:00 1970 +0000 |
|
162 | 170 | > @@ -0,0 +1,1 @@ |
|
163 | 171 | > +foo |
|
164 | 172 | > EOF |
|
165 | 173 | |
|
166 | 174 | $ cat > appendbar.diff <<EOF |
|
167 | 175 | > append bar |
|
168 | 176 | > |
|
169 | 177 | > diff -r 07f494440405 -r 261500830e46 baz |
|
170 | 178 | > --- a/baz Thu Jan 01 00:00:00 1970 +0000 |
|
171 | 179 | > +++ b/baz Thu Jan 01 00:00:00 1970 +0000 |
|
172 | 180 | > @@ -1,1 +1,2 @@ |
|
173 | 181 | > foo |
|
174 | 182 | > +bar |
|
175 | 183 | > EOF |
|
176 | 184 | |
|
177 | 185 | $ hg qimport --push appendfoo.diff appendbar.diff |
|
178 | 186 | adding appendfoo.diff to series file |
|
179 | 187 | adding appendbar.diff to series file |
|
180 | 188 | applying appendfoo.diff |
|
181 | 189 | applying appendbar.diff |
|
182 | 190 | now at: appendbar.diff |
|
183 | 191 | $ hg qfin -a |
|
184 | 192 | patch b.diff finalized without changeset message |
|
185 | 193 | $ hg qimport -r 'p1(.)::' -P |
|
186 | 194 | $ hg qpop -a |
|
187 | 195 | popping 3.diff |
|
188 | 196 | popping 2.diff |
|
189 | 197 | patch queue now empty |
|
190 | 198 | $ hg qdel 3.diff |
|
191 | 199 | $ hg qdel -k 2.diff |
|
192 | 200 | |
|
193 | 201 | qimport -e |
|
194 | 202 | |
|
195 | 203 | $ hg qimport -e 2.diff |
|
196 | 204 | adding 2.diff to series file |
|
197 | 205 | $ hg qdel -k 2.diff |
|
198 | 206 | |
|
199 | 207 | qimport -e --name newname oldexisitingpatch |
|
200 | 208 | |
|
201 | 209 | $ hg qimport -e --name this-name-is-better 2.diff |
|
202 | 210 | renaming 2.diff to this-name-is-better |
|
203 | 211 | adding this-name-is-better to series file |
|
204 | 212 | $ hg qser |
|
205 | 213 | this-name-is-better |
|
206 | 214 | url.diff |
|
207 | 215 | |
|
208 | 216 | qimport -e --name without --force |
|
209 | 217 | |
|
210 | 218 | $ cp .hg/patches/this-name-is-better .hg/patches/3.diff |
|
211 | 219 | $ hg qimport -e --name this-name-is-better 3.diff |
|
212 | 220 | abort: patch "this-name-is-better" already exists |
|
213 | 221 | [255] |
|
214 | 222 | $ hg qser |
|
215 | 223 | this-name-is-better |
|
216 | 224 | url.diff |
|
217 | 225 | |
|
218 | 226 | qimport -e --name with --force |
|
219 | 227 | |
|
220 | 228 | $ hg qimport --force -e --name this-name-is-better 3.diff |
|
221 | 229 | renaming 3.diff to this-name-is-better |
|
222 | 230 | adding this-name-is-better to series file |
|
223 | 231 | $ hg qser |
|
224 | 232 | this-name-is-better |
|
225 | 233 | url.diff |
|
226 | 234 | |
|
227 | 235 | qimport with bad name, should abort before reading file |
|
228 | 236 | |
|
229 | 237 | $ hg qimport non-existant-file --name .hg |
|
230 | 238 | abort: patch name cannot begin with ".hg" |
|
231 | 239 | [255] |
|
232 | 240 | |
|
233 | 241 | qimport http:// patch with leading slashes in url |
|
234 | 242 | |
|
235 | 243 | set up hgweb |
|
236 | 244 | |
|
237 | 245 | $ cd .. |
|
238 | 246 | $ hg init served |
|
239 | 247 | $ cd served |
|
240 | 248 | $ echo a > a |
|
241 | 249 | $ hg ci -Am patch |
|
242 | 250 | adding a |
|
243 | 251 | $ hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log |
|
244 | 252 | $ cat hg.pid >> $DAEMON_PIDS |
|
245 | 253 | |
|
246 | 254 | $ cd ../repo |
|
247 | 255 | $ hg qimport http://localhost:$HGPORT/raw-rev/0/// |
|
248 | 256 | adding 0 to series file |
|
249 | 257 | |
|
250 | 258 | check qimport phase: |
|
251 | 259 | |
|
252 | 260 | $ hg -q qpush |
|
253 | 261 | now at: 0 |
|
254 | 262 | $ hg phase qparent |
|
255 | 263 | 1: draft |
|
256 | 264 | $ hg qimport -r qparent |
|
257 | 265 | $ hg phase qbase |
|
258 | 266 | 1: draft |
|
259 | 267 | $ hg qfinish qbase |
|
260 | 268 | $ echo '[mq]' >> $HGRCPATH |
|
261 | 269 | $ echo 'secret=true' >> $HGRCPATH |
|
262 | 270 | $ hg qimport -r qparent |
|
263 | 271 | $ hg phase qbase |
|
264 | 272 | 1: secret |
@@ -1,82 +1,82 b'' | |||
|
1 | 1 | $ "$TESTDIR/hghave" serve || exit 80 |
|
2 | 2 | |
|
3 | 3 | $ hgserve() |
|
4 | 4 | > { |
|
5 | 5 | > hg serve -a localhost -d --pid-file=hg.pid -E errors.log -v $@ \ |
|
6 | 6 | > | sed -e "s/:$HGPORT1\\([^0-9]\\)/:HGPORT1\1/g" \ |
|
7 | 7 | > -e "s/:$HGPORT2\\([^0-9]\\)/:HGPORT2\1/g" \ |
|
8 | 8 | > -e 's/http:\/\/[^/]*\//http:\/\/localhost\//' |
|
9 | 9 | > cat hg.pid >> "$DAEMON_PIDS" |
|
10 | 10 | > echo % errors |
|
11 | 11 | > cat errors.log |
|
12 | 12 | > if [ "$KILLQUIETLY" = "Y" ]; then |
|
13 | 13 | > kill `cat hg.pid` 2>/dev/null |
|
14 | 14 | > else |
|
15 | 15 | > kill `cat hg.pid` |
|
16 | 16 | > fi |
|
17 |
> while kill -0 `cat hg.pid` 2>/dev/null; do |
|
|
17 | > while kill -0 `cat hg.pid` 2>/dev/null; do sleep 0; done | |
|
18 | 18 | > } |
|
19 | 19 | |
|
20 | 20 | $ hg init test |
|
21 | 21 | $ cd test |
|
22 | 22 | $ echo '[web]' > .hg/hgrc |
|
23 | 23 | $ echo 'accesslog = access.log' >> .hg/hgrc |
|
24 | 24 | $ echo "port = $HGPORT1" >> .hg/hgrc |
|
25 | 25 | |
|
26 | 26 | Without -v |
|
27 | 27 | |
|
28 | 28 | $ hg serve -a localhost -p $HGPORT -d --pid-file=hg.pid -E errors.log |
|
29 | 29 | $ cat hg.pid >> "$DAEMON_PIDS" |
|
30 | 30 | $ if [ -f access.log ]; then |
|
31 | 31 | $ echo 'access log created - .hg/hgrc respected' |
|
32 | 32 | access log created - .hg/hgrc respected |
|
33 | 33 | $ fi |
|
34 | 34 | |
|
35 | 35 | errors |
|
36 | 36 | |
|
37 | 37 | $ cat errors.log |
|
38 | 38 | |
|
39 | 39 | With -v |
|
40 | 40 | |
|
41 | 41 | $ hgserve |
|
42 | 42 | listening at http://localhost/ (bound to 127.0.0.1:HGPORT1) |
|
43 | 43 | % errors |
|
44 | 44 | |
|
45 | 45 | With -v and -p HGPORT2 |
|
46 | 46 | |
|
47 | 47 | $ hgserve -p "$HGPORT2" |
|
48 | 48 | listening at http://localhost/ (bound to 127.0.0.1:HGPORT2) |
|
49 | 49 | % errors |
|
50 | 50 | |
|
51 | 51 | With -v and -p daytime (should fail because low port) |
|
52 | 52 | |
|
53 | 53 | $ KILLQUIETLY=Y |
|
54 | 54 | $ hgserve -p daytime |
|
55 | 55 | abort: cannot start server at 'localhost:13': Permission denied |
|
56 | 56 | abort: child process failed to start |
|
57 | 57 | % errors |
|
58 | 58 | $ KILLQUIETLY=N |
|
59 | 59 | |
|
60 | 60 | With --prefix foo |
|
61 | 61 | |
|
62 | 62 | $ hgserve --prefix foo |
|
63 | 63 | listening at http://localhost/foo/ (bound to 127.0.0.1:HGPORT1) |
|
64 | 64 | % errors |
|
65 | 65 | |
|
66 | 66 | With --prefix /foo |
|
67 | 67 | |
|
68 | 68 | $ hgserve --prefix /foo |
|
69 | 69 | listening at http://localhost/foo/ (bound to 127.0.0.1:HGPORT1) |
|
70 | 70 | % errors |
|
71 | 71 | |
|
72 | 72 | With --prefix foo/ |
|
73 | 73 | |
|
74 | 74 | $ hgserve --prefix foo/ |
|
75 | 75 | listening at http://localhost/foo/ (bound to 127.0.0.1:HGPORT1) |
|
76 | 76 | % errors |
|
77 | 77 | |
|
78 | 78 | With --prefix /foo/ |
|
79 | 79 | |
|
80 | 80 | $ hgserve --prefix /foo/ |
|
81 | 81 | listening at http://localhost/foo/ (bound to 127.0.0.1:HGPORT1) |
|
82 | 82 | % errors |
General Comments 0
You need to be logged in to leave comments.
Login now