Show More
@@ -1,3896 +1,3901 b'' | |||
|
1 | 1 | # cmdutil.py - help for command processing in 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 __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import copy as copymod |
|
11 | 11 | import errno |
|
12 | 12 | import os |
|
13 | 13 | import re |
|
14 | 14 | |
|
15 | 15 | from .i18n import _ |
|
16 | 16 | from .node import ( |
|
17 | 17 | hex, |
|
18 | 18 | nullid, |
|
19 | 19 | short, |
|
20 | 20 | ) |
|
21 | 21 | from .pycompat import ( |
|
22 | 22 | getattr, |
|
23 | 23 | open, |
|
24 | 24 | setattr, |
|
25 | 25 | ) |
|
26 | 26 | from .thirdparty import attr |
|
27 | 27 | |
|
28 | 28 | from . import ( |
|
29 | 29 | bookmarks, |
|
30 | 30 | changelog, |
|
31 | 31 | copies, |
|
32 | 32 | crecord as crecordmod, |
|
33 | 33 | dirstateguard, |
|
34 | 34 | encoding, |
|
35 | 35 | error, |
|
36 | 36 | formatter, |
|
37 | 37 | logcmdutil, |
|
38 | 38 | match as matchmod, |
|
39 | 39 | merge as mergemod, |
|
40 | 40 | mergestate as mergestatemod, |
|
41 | 41 | mergeutil, |
|
42 | 42 | obsolete, |
|
43 | 43 | patch, |
|
44 | 44 | pathutil, |
|
45 | 45 | phases, |
|
46 | 46 | pycompat, |
|
47 | 47 | repair, |
|
48 | 48 | revlog, |
|
49 | 49 | rewriteutil, |
|
50 | 50 | scmutil, |
|
51 | 51 | state as statemod, |
|
52 | 52 | subrepoutil, |
|
53 | 53 | templatekw, |
|
54 | 54 | templater, |
|
55 | 55 | util, |
|
56 | 56 | vfs as vfsmod, |
|
57 | 57 | ) |
|
58 | 58 | |
|
59 | 59 | from .utils import ( |
|
60 | 60 | dateutil, |
|
61 | 61 | stringutil, |
|
62 | 62 | ) |
|
63 | 63 | |
|
64 | 64 | if pycompat.TYPE_CHECKING: |
|
65 | 65 | from typing import ( |
|
66 | 66 | Any, |
|
67 | 67 | Dict, |
|
68 | 68 | ) |
|
69 | 69 | |
|
70 | 70 | for t in (Any, Dict): |
|
71 | 71 | assert t |
|
72 | 72 | |
|
73 | 73 | stringio = util.stringio |
|
74 | 74 | |
|
75 | 75 | # templates of common command options |
|
76 | 76 | |
|
77 | 77 | dryrunopts = [ |
|
78 | 78 | (b'n', b'dry-run', None, _(b'do not perform actions, just print output')), |
|
79 | 79 | ] |
|
80 | 80 | |
|
81 | 81 | confirmopts = [ |
|
82 | 82 | (b'', b'confirm', None, _(b'ask before applying actions')), |
|
83 | 83 | ] |
|
84 | 84 | |
|
85 | 85 | remoteopts = [ |
|
86 | 86 | (b'e', b'ssh', b'', _(b'specify ssh command to use'), _(b'CMD')), |
|
87 | 87 | ( |
|
88 | 88 | b'', |
|
89 | 89 | b'remotecmd', |
|
90 | 90 | b'', |
|
91 | 91 | _(b'specify hg command to run on the remote side'), |
|
92 | 92 | _(b'CMD'), |
|
93 | 93 | ), |
|
94 | 94 | ( |
|
95 | 95 | b'', |
|
96 | 96 | b'insecure', |
|
97 | 97 | None, |
|
98 | 98 | _(b'do not verify server certificate (ignoring web.cacerts config)'), |
|
99 | 99 | ), |
|
100 | 100 | ] |
|
101 | 101 | |
|
102 | 102 | walkopts = [ |
|
103 | 103 | ( |
|
104 | 104 | b'I', |
|
105 | 105 | b'include', |
|
106 | 106 | [], |
|
107 | 107 | _(b'include names matching the given patterns'), |
|
108 | 108 | _(b'PATTERN'), |
|
109 | 109 | ), |
|
110 | 110 | ( |
|
111 | 111 | b'X', |
|
112 | 112 | b'exclude', |
|
113 | 113 | [], |
|
114 | 114 | _(b'exclude names matching the given patterns'), |
|
115 | 115 | _(b'PATTERN'), |
|
116 | 116 | ), |
|
117 | 117 | ] |
|
118 | 118 | |
|
119 | 119 | commitopts = [ |
|
120 | 120 | (b'm', b'message', b'', _(b'use text as commit message'), _(b'TEXT')), |
|
121 | 121 | (b'l', b'logfile', b'', _(b'read commit message from file'), _(b'FILE')), |
|
122 | 122 | ] |
|
123 | 123 | |
|
124 | 124 | commitopts2 = [ |
|
125 | 125 | ( |
|
126 | 126 | b'd', |
|
127 | 127 | b'date', |
|
128 | 128 | b'', |
|
129 | 129 | _(b'record the specified date as commit date'), |
|
130 | 130 | _(b'DATE'), |
|
131 | 131 | ), |
|
132 | 132 | ( |
|
133 | 133 | b'u', |
|
134 | 134 | b'user', |
|
135 | 135 | b'', |
|
136 | 136 | _(b'record the specified user as committer'), |
|
137 | 137 | _(b'USER'), |
|
138 | 138 | ), |
|
139 | 139 | ] |
|
140 | 140 | |
|
141 | 141 | commitopts3 = [ |
|
142 | 142 | (b'D', b'currentdate', None, _(b'record the current date as commit date')), |
|
143 | 143 | (b'U', b'currentuser', None, _(b'record the current user as committer')), |
|
144 | 144 | ] |
|
145 | 145 | |
|
146 | 146 | formatteropts = [ |
|
147 | 147 | (b'T', b'template', b'', _(b'display with template'), _(b'TEMPLATE')), |
|
148 | 148 | ] |
|
149 | 149 | |
|
150 | 150 | templateopts = [ |
|
151 | 151 | ( |
|
152 | 152 | b'', |
|
153 | 153 | b'style', |
|
154 | 154 | b'', |
|
155 | 155 | _(b'display using template map file (DEPRECATED)'), |
|
156 | 156 | _(b'STYLE'), |
|
157 | 157 | ), |
|
158 | 158 | (b'T', b'template', b'', _(b'display with template'), _(b'TEMPLATE')), |
|
159 | 159 | ] |
|
160 | 160 | |
|
161 | 161 | logopts = [ |
|
162 | 162 | (b'p', b'patch', None, _(b'show patch')), |
|
163 | 163 | (b'g', b'git', None, _(b'use git extended diff format')), |
|
164 | 164 | (b'l', b'limit', b'', _(b'limit number of changes displayed'), _(b'NUM')), |
|
165 | 165 | (b'M', b'no-merges', None, _(b'do not show merges')), |
|
166 | 166 | (b'', b'stat', None, _(b'output diffstat-style summary of changes')), |
|
167 | 167 | (b'G', b'graph', None, _(b"show the revision DAG")), |
|
168 | 168 | ] + templateopts |
|
169 | 169 | |
|
170 | 170 | diffopts = [ |
|
171 | 171 | (b'a', b'text', None, _(b'treat all files as text')), |
|
172 | 172 | ( |
|
173 | 173 | b'g', |
|
174 | 174 | b'git', |
|
175 | 175 | None, |
|
176 | 176 | _(b'use git extended diff format (DEFAULT: diff.git)'), |
|
177 | 177 | ), |
|
178 | 178 | (b'', b'binary', None, _(b'generate binary diffs in git mode (default)')), |
|
179 | 179 | (b'', b'nodates', None, _(b'omit dates from diff headers')), |
|
180 | 180 | ] |
|
181 | 181 | |
|
182 | 182 | diffwsopts = [ |
|
183 | 183 | ( |
|
184 | 184 | b'w', |
|
185 | 185 | b'ignore-all-space', |
|
186 | 186 | None, |
|
187 | 187 | _(b'ignore white space when comparing lines'), |
|
188 | 188 | ), |
|
189 | 189 | ( |
|
190 | 190 | b'b', |
|
191 | 191 | b'ignore-space-change', |
|
192 | 192 | None, |
|
193 | 193 | _(b'ignore changes in the amount of white space'), |
|
194 | 194 | ), |
|
195 | 195 | ( |
|
196 | 196 | b'B', |
|
197 | 197 | b'ignore-blank-lines', |
|
198 | 198 | None, |
|
199 | 199 | _(b'ignore changes whose lines are all blank'), |
|
200 | 200 | ), |
|
201 | 201 | ( |
|
202 | 202 | b'Z', |
|
203 | 203 | b'ignore-space-at-eol', |
|
204 | 204 | None, |
|
205 | 205 | _(b'ignore changes in whitespace at EOL'), |
|
206 | 206 | ), |
|
207 | 207 | ] |
|
208 | 208 | |
|
209 | 209 | diffopts2 = ( |
|
210 | 210 | [ |
|
211 | 211 | (b'', b'noprefix', None, _(b'omit a/ and b/ prefixes from filenames')), |
|
212 | 212 | ( |
|
213 | 213 | b'p', |
|
214 | 214 | b'show-function', |
|
215 | 215 | None, |
|
216 | 216 | _( |
|
217 | 217 | b'show which function each change is in (DEFAULT: diff.showfunc)' |
|
218 | 218 | ), |
|
219 | 219 | ), |
|
220 | 220 | (b'', b'reverse', None, _(b'produce a diff that undoes the changes')), |
|
221 | 221 | ] |
|
222 | 222 | + diffwsopts |
|
223 | 223 | + [ |
|
224 | 224 | ( |
|
225 | 225 | b'U', |
|
226 | 226 | b'unified', |
|
227 | 227 | b'', |
|
228 | 228 | _(b'number of lines of context to show'), |
|
229 | 229 | _(b'NUM'), |
|
230 | 230 | ), |
|
231 | 231 | (b'', b'stat', None, _(b'output diffstat-style summary of changes')), |
|
232 | 232 | ( |
|
233 | 233 | b'', |
|
234 | 234 | b'root', |
|
235 | 235 | b'', |
|
236 | 236 | _(b'produce diffs relative to subdirectory'), |
|
237 | 237 | _(b'DIR'), |
|
238 | 238 | ), |
|
239 | 239 | ] |
|
240 | 240 | ) |
|
241 | 241 | |
|
242 | 242 | mergetoolopts = [ |
|
243 | 243 | (b't', b'tool', b'', _(b'specify merge tool'), _(b'TOOL')), |
|
244 | 244 | ] |
|
245 | 245 | |
|
246 | 246 | similarityopts = [ |
|
247 | 247 | ( |
|
248 | 248 | b's', |
|
249 | 249 | b'similarity', |
|
250 | 250 | b'', |
|
251 | 251 | _(b'guess renamed files by similarity (0<=s<=100)'), |
|
252 | 252 | _(b'SIMILARITY'), |
|
253 | 253 | ) |
|
254 | 254 | ] |
|
255 | 255 | |
|
256 | 256 | subrepoopts = [(b'S', b'subrepos', None, _(b'recurse into subrepositories'))] |
|
257 | 257 | |
|
258 | 258 | debugrevlogopts = [ |
|
259 | 259 | (b'c', b'changelog', False, _(b'open changelog')), |
|
260 | 260 | (b'm', b'manifest', False, _(b'open manifest')), |
|
261 | 261 | (b'', b'dir', b'', _(b'open directory manifest')), |
|
262 | 262 | ] |
|
263 | 263 | |
|
264 | 264 | # special string such that everything below this line will be ingored in the |
|
265 | 265 | # editor text |
|
266 | 266 | _linebelow = b"^HG: ------------------------ >8 ------------------------$" |
|
267 | 267 | |
|
268 | 268 | |
|
269 | 269 | def check_at_most_one_arg(opts, *args): |
|
270 | 270 | """abort if more than one of the arguments are in opts |
|
271 | 271 | |
|
272 | 272 | Returns the unique argument or None if none of them were specified. |
|
273 | 273 | """ |
|
274 | 274 | |
|
275 | 275 | def to_display(name): |
|
276 | 276 | return pycompat.sysbytes(name).replace(b'_', b'-') |
|
277 | 277 | |
|
278 | 278 | previous = None |
|
279 | 279 | for x in args: |
|
280 | 280 | if opts.get(x): |
|
281 | 281 | if previous: |
|
282 | 282 | raise error.Abort( |
|
283 | 283 | _(b'cannot specify both --%s and --%s') |
|
284 | 284 | % (to_display(previous), to_display(x)) |
|
285 | 285 | ) |
|
286 | 286 | previous = x |
|
287 | 287 | return previous |
|
288 | 288 | |
|
289 | 289 | |
|
290 | 290 | def check_incompatible_arguments(opts, first, others): |
|
291 | 291 | """abort if the first argument is given along with any of the others |
|
292 | 292 | |
|
293 | 293 | Unlike check_at_most_one_arg(), `others` are not mutually exclusive |
|
294 | 294 | among themselves, and they're passed as a single collection. |
|
295 | 295 | """ |
|
296 | 296 | for other in others: |
|
297 | 297 | check_at_most_one_arg(opts, first, other) |
|
298 | 298 | |
|
299 | 299 | |
|
300 | 300 | def resolvecommitoptions(ui, opts): |
|
301 | 301 | """modify commit options dict to handle related options |
|
302 | 302 | |
|
303 | 303 | The return value indicates that ``rewrite.update-timestamp`` is the reason |
|
304 | 304 | the ``date`` option is set. |
|
305 | 305 | """ |
|
306 | 306 | check_at_most_one_arg(opts, b'date', b'currentdate') |
|
307 | 307 | check_at_most_one_arg(opts, b'user', b'currentuser') |
|
308 | 308 | |
|
309 | 309 | datemaydiffer = False # date-only change should be ignored? |
|
310 | 310 | |
|
311 | 311 | if opts.get(b'currentdate'): |
|
312 | 312 | opts[b'date'] = b'%d %d' % dateutil.makedate() |
|
313 | 313 | elif ( |
|
314 | 314 | not opts.get(b'date') |
|
315 | 315 | and ui.configbool(b'rewrite', b'update-timestamp') |
|
316 | 316 | and opts.get(b'currentdate') is None |
|
317 | 317 | ): |
|
318 | 318 | opts[b'date'] = b'%d %d' % dateutil.makedate() |
|
319 | 319 | datemaydiffer = True |
|
320 | 320 | |
|
321 | 321 | if opts.get(b'currentuser'): |
|
322 | 322 | opts[b'user'] = ui.username() |
|
323 | 323 | |
|
324 | 324 | return datemaydiffer |
|
325 | 325 | |
|
326 | 326 | |
|
327 | 327 | def checknotesize(ui, opts): |
|
328 | 328 | """ make sure note is of valid format """ |
|
329 | 329 | |
|
330 | 330 | note = opts.get(b'note') |
|
331 | 331 | if not note: |
|
332 | 332 | return |
|
333 | 333 | |
|
334 | 334 | if len(note) > 255: |
|
335 | 335 | raise error.Abort(_(b"cannot store a note of more than 255 bytes")) |
|
336 | 336 | if b'\n' in note: |
|
337 | 337 | raise error.Abort(_(b"note cannot contain a newline")) |
|
338 | 338 | |
|
339 | 339 | |
|
340 | 340 | def ishunk(x): |
|
341 | 341 | hunkclasses = (crecordmod.uihunk, patch.recordhunk) |
|
342 | 342 | return isinstance(x, hunkclasses) |
|
343 | 343 | |
|
344 | 344 | |
|
345 | 345 | def newandmodified(chunks, originalchunks): |
|
346 | 346 | newlyaddedandmodifiedfiles = set() |
|
347 | 347 | alsorestore = set() |
|
348 | 348 | for chunk in chunks: |
|
349 | 349 | if ( |
|
350 | 350 | ishunk(chunk) |
|
351 | 351 | and chunk.header.isnewfile() |
|
352 | 352 | and chunk not in originalchunks |
|
353 | 353 | ): |
|
354 | 354 | newlyaddedandmodifiedfiles.add(chunk.header.filename()) |
|
355 | 355 | alsorestore.update( |
|
356 | 356 | set(chunk.header.files()) - {chunk.header.filename()} |
|
357 | 357 | ) |
|
358 | 358 | return newlyaddedandmodifiedfiles, alsorestore |
|
359 | 359 | |
|
360 | 360 | |
|
361 | 361 | def parsealiases(cmd): |
|
362 | 362 | return cmd.split(b"|") |
|
363 | 363 | |
|
364 | 364 | |
|
365 | 365 | def setupwrapcolorwrite(ui): |
|
366 | 366 | # wrap ui.write so diff output can be labeled/colorized |
|
367 | 367 | def wrapwrite(orig, *args, **kw): |
|
368 | 368 | label = kw.pop('label', b'') |
|
369 | 369 | for chunk, l in patch.difflabel(lambda: args): |
|
370 | 370 | orig(chunk, label=label + l) |
|
371 | 371 | |
|
372 | 372 | oldwrite = ui.write |
|
373 | 373 | |
|
374 | 374 | def wrap(*args, **kwargs): |
|
375 | 375 | return wrapwrite(oldwrite, *args, **kwargs) |
|
376 | 376 | |
|
377 | 377 | setattr(ui, 'write', wrap) |
|
378 | 378 | return oldwrite |
|
379 | 379 | |
|
380 | 380 | |
|
381 | 381 | def filterchunks(ui, originalhunks, usecurses, testfile, match, operation=None): |
|
382 | 382 | try: |
|
383 | 383 | if usecurses: |
|
384 | 384 | if testfile: |
|
385 | 385 | recordfn = crecordmod.testdecorator( |
|
386 | 386 | testfile, crecordmod.testchunkselector |
|
387 | 387 | ) |
|
388 | 388 | else: |
|
389 | 389 | recordfn = crecordmod.chunkselector |
|
390 | 390 | |
|
391 | 391 | return crecordmod.filterpatch( |
|
392 | 392 | ui, originalhunks, recordfn, operation |
|
393 | 393 | ) |
|
394 | 394 | except crecordmod.fallbackerror as e: |
|
395 | 395 | ui.warn(b'%s\n' % e) |
|
396 | 396 | ui.warn(_(b'falling back to text mode\n')) |
|
397 | 397 | |
|
398 | 398 | return patch.filterpatch(ui, originalhunks, match, operation) |
|
399 | 399 | |
|
400 | 400 | |
|
401 | 401 | def recordfilter(ui, originalhunks, match, operation=None): |
|
402 | 402 | """ Prompts the user to filter the originalhunks and return a list of |
|
403 | 403 | selected hunks. |
|
404 | 404 | *operation* is used for to build ui messages to indicate the user what |
|
405 | 405 | kind of filtering they are doing: reverting, committing, shelving, etc. |
|
406 | 406 | (see patch.filterpatch). |
|
407 | 407 | """ |
|
408 | 408 | usecurses = crecordmod.checkcurses(ui) |
|
409 | 409 | testfile = ui.config(b'experimental', b'crecordtest') |
|
410 | 410 | oldwrite = setupwrapcolorwrite(ui) |
|
411 | 411 | try: |
|
412 | 412 | newchunks, newopts = filterchunks( |
|
413 | 413 | ui, originalhunks, usecurses, testfile, match, operation |
|
414 | 414 | ) |
|
415 | 415 | finally: |
|
416 | 416 | ui.write = oldwrite |
|
417 | 417 | return newchunks, newopts |
|
418 | 418 | |
|
419 | 419 | |
|
420 | 420 | def dorecord( |
|
421 | 421 | ui, repo, commitfunc, cmdsuggest, backupall, filterfn, *pats, **opts |
|
422 | 422 | ): |
|
423 | 423 | opts = pycompat.byteskwargs(opts) |
|
424 | 424 | if not ui.interactive(): |
|
425 | 425 | if cmdsuggest: |
|
426 | 426 | msg = _(b'running non-interactively, use %s instead') % cmdsuggest |
|
427 | 427 | else: |
|
428 | 428 | msg = _(b'running non-interactively') |
|
429 | 429 | raise error.Abort(msg) |
|
430 | 430 | |
|
431 | 431 | # make sure username is set before going interactive |
|
432 | 432 | if not opts.get(b'user'): |
|
433 | 433 | ui.username() # raise exception, username not provided |
|
434 | 434 | |
|
435 | 435 | def recordfunc(ui, repo, message, match, opts): |
|
436 | 436 | """This is generic record driver. |
|
437 | 437 | |
|
438 | 438 | Its job is to interactively filter local changes, and |
|
439 | 439 | accordingly prepare working directory into a state in which the |
|
440 | 440 | job can be delegated to a non-interactive commit command such as |
|
441 | 441 | 'commit' or 'qrefresh'. |
|
442 | 442 | |
|
443 | 443 | After the actual job is done by non-interactive command, the |
|
444 | 444 | working directory is restored to its original state. |
|
445 | 445 | |
|
446 | 446 | In the end we'll record interesting changes, and everything else |
|
447 | 447 | will be left in place, so the user can continue working. |
|
448 | 448 | """ |
|
449 | 449 | if not opts.get(b'interactive-unshelve'): |
|
450 | 450 | checkunfinished(repo, commit=True) |
|
451 | 451 | wctx = repo[None] |
|
452 | 452 | merge = len(wctx.parents()) > 1 |
|
453 | 453 | if merge: |
|
454 | 454 | raise error.Abort( |
|
455 | 455 | _( |
|
456 | 456 | b'cannot partially commit a merge ' |
|
457 | 457 | b'(use "hg commit" instead)' |
|
458 | 458 | ) |
|
459 | 459 | ) |
|
460 | 460 | |
|
461 | 461 | def fail(f, msg): |
|
462 | 462 | raise error.Abort(b'%s: %s' % (f, msg)) |
|
463 | 463 | |
|
464 | 464 | force = opts.get(b'force') |
|
465 | 465 | if not force: |
|
466 | 466 | match = matchmod.badmatch(match, fail) |
|
467 | 467 | |
|
468 | 468 | status = repo.status(match=match) |
|
469 | 469 | |
|
470 | 470 | overrides = {(b'ui', b'commitsubrepos'): True} |
|
471 | 471 | |
|
472 | 472 | with repo.ui.configoverride(overrides, b'record'): |
|
473 | 473 | # subrepoutil.precommit() modifies the status |
|
474 | 474 | tmpstatus = scmutil.status( |
|
475 | 475 | copymod.copy(status.modified), |
|
476 | 476 | copymod.copy(status.added), |
|
477 | 477 | copymod.copy(status.removed), |
|
478 | 478 | copymod.copy(status.deleted), |
|
479 | 479 | copymod.copy(status.unknown), |
|
480 | 480 | copymod.copy(status.ignored), |
|
481 | 481 | copymod.copy(status.clean), # pytype: disable=wrong-arg-count |
|
482 | 482 | ) |
|
483 | 483 | |
|
484 | 484 | # Force allows -X subrepo to skip the subrepo. |
|
485 | 485 | subs, commitsubs, newstate = subrepoutil.precommit( |
|
486 | 486 | repo.ui, wctx, tmpstatus, match, force=True |
|
487 | 487 | ) |
|
488 | 488 | for s in subs: |
|
489 | 489 | if s in commitsubs: |
|
490 | 490 | dirtyreason = wctx.sub(s).dirtyreason(True) |
|
491 | 491 | raise error.Abort(dirtyreason) |
|
492 | 492 | |
|
493 | 493 | if not force: |
|
494 | 494 | repo.checkcommitpatterns(wctx, match, status, fail) |
|
495 | 495 | diffopts = patch.difffeatureopts( |
|
496 | 496 | ui, |
|
497 | 497 | opts=opts, |
|
498 | 498 | whitespace=True, |
|
499 | 499 | section=b'commands', |
|
500 | 500 | configprefix=b'commit.interactive.', |
|
501 | 501 | ) |
|
502 | 502 | diffopts.nodates = True |
|
503 | 503 | diffopts.git = True |
|
504 | 504 | diffopts.showfunc = True |
|
505 | 505 | originaldiff = patch.diff(repo, changes=status, opts=diffopts) |
|
506 | 506 | originalchunks = patch.parsepatch(originaldiff) |
|
507 | 507 | match = scmutil.match(repo[None], pats) |
|
508 | 508 | |
|
509 | 509 | # 1. filter patch, since we are intending to apply subset of it |
|
510 | 510 | try: |
|
511 | 511 | chunks, newopts = filterfn(ui, originalchunks, match) |
|
512 | 512 | except error.PatchError as err: |
|
513 | 513 | raise error.Abort(_(b'error parsing patch: %s') % err) |
|
514 | 514 | opts.update(newopts) |
|
515 | 515 | |
|
516 | 516 | # We need to keep a backup of files that have been newly added and |
|
517 | 517 | # modified during the recording process because there is a previous |
|
518 | 518 | # version without the edit in the workdir. We also will need to restore |
|
519 | 519 | # files that were the sources of renames so that the patch application |
|
520 | 520 | # works. |
|
521 | 521 | newlyaddedandmodifiedfiles, alsorestore = newandmodified( |
|
522 | 522 | chunks, originalchunks |
|
523 | 523 | ) |
|
524 | 524 | contenders = set() |
|
525 | 525 | for h in chunks: |
|
526 | 526 | try: |
|
527 | 527 | contenders.update(set(h.files())) |
|
528 | 528 | except AttributeError: |
|
529 | 529 | pass |
|
530 | 530 | |
|
531 | 531 | changed = status.modified + status.added + status.removed |
|
532 | 532 | newfiles = [f for f in changed if f in contenders] |
|
533 | 533 | if not newfiles: |
|
534 | 534 | ui.status(_(b'no changes to record\n')) |
|
535 | 535 | return 0 |
|
536 | 536 | |
|
537 | 537 | modified = set(status.modified) |
|
538 | 538 | |
|
539 | 539 | # 2. backup changed files, so we can restore them in the end |
|
540 | 540 | |
|
541 | 541 | if backupall: |
|
542 | 542 | tobackup = changed |
|
543 | 543 | else: |
|
544 | 544 | tobackup = [ |
|
545 | 545 | f |
|
546 | 546 | for f in newfiles |
|
547 | 547 | if f in modified or f in newlyaddedandmodifiedfiles |
|
548 | 548 | ] |
|
549 | 549 | backups = {} |
|
550 | 550 | if tobackup: |
|
551 | 551 | backupdir = repo.vfs.join(b'record-backups') |
|
552 | 552 | try: |
|
553 | 553 | os.mkdir(backupdir) |
|
554 | 554 | except OSError as err: |
|
555 | 555 | if err.errno != errno.EEXIST: |
|
556 | 556 | raise |
|
557 | 557 | try: |
|
558 | 558 | # backup continues |
|
559 | 559 | for f in tobackup: |
|
560 | 560 | fd, tmpname = pycompat.mkstemp( |
|
561 | 561 | prefix=os.path.basename(f) + b'.', dir=backupdir |
|
562 | 562 | ) |
|
563 | 563 | os.close(fd) |
|
564 | 564 | ui.debug(b'backup %r as %r\n' % (f, tmpname)) |
|
565 | 565 | util.copyfile(repo.wjoin(f), tmpname, copystat=True) |
|
566 | 566 | backups[f] = tmpname |
|
567 | 567 | |
|
568 | 568 | fp = stringio() |
|
569 | 569 | for c in chunks: |
|
570 | 570 | fname = c.filename() |
|
571 | 571 | if fname in backups: |
|
572 | 572 | c.write(fp) |
|
573 | 573 | dopatch = fp.tell() |
|
574 | 574 | fp.seek(0) |
|
575 | 575 | |
|
576 | 576 | # 2.5 optionally review / modify patch in text editor |
|
577 | 577 | if opts.get(b'review', False): |
|
578 | 578 | patchtext = ( |
|
579 | 579 | crecordmod.diffhelptext |
|
580 | 580 | + crecordmod.patchhelptext |
|
581 | 581 | + fp.read() |
|
582 | 582 | ) |
|
583 | 583 | reviewedpatch = ui.edit( |
|
584 | 584 | patchtext, b"", action=b"diff", repopath=repo.path |
|
585 | 585 | ) |
|
586 | 586 | fp.truncate(0) |
|
587 | 587 | fp.write(reviewedpatch) |
|
588 | 588 | fp.seek(0) |
|
589 | 589 | |
|
590 | 590 | [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles] |
|
591 | 591 | # 3a. apply filtered patch to clean repo (clean) |
|
592 | 592 | if backups: |
|
593 | 593 | m = scmutil.matchfiles(repo, set(backups.keys()) | alsorestore) |
|
594 | 594 | mergemod.revert_to(repo[b'.'], matcher=m) |
|
595 | 595 | |
|
596 | 596 | # 3b. (apply) |
|
597 | 597 | if dopatch: |
|
598 | 598 | try: |
|
599 | 599 | ui.debug(b'applying patch\n') |
|
600 | 600 | ui.debug(fp.getvalue()) |
|
601 | 601 | patch.internalpatch(ui, repo, fp, 1, eolmode=None) |
|
602 | 602 | except error.PatchError as err: |
|
603 | 603 | raise error.Abort(pycompat.bytestr(err)) |
|
604 | 604 | del fp |
|
605 | 605 | |
|
606 | 606 | # 4. We prepared working directory according to filtered |
|
607 | 607 | # patch. Now is the time to delegate the job to |
|
608 | 608 | # commit/qrefresh or the like! |
|
609 | 609 | |
|
610 | 610 | # Make all of the pathnames absolute. |
|
611 | 611 | newfiles = [repo.wjoin(nf) for nf in newfiles] |
|
612 | 612 | return commitfunc(ui, repo, *newfiles, **pycompat.strkwargs(opts)) |
|
613 | 613 | finally: |
|
614 | 614 | # 5. finally restore backed-up files |
|
615 | 615 | try: |
|
616 | 616 | dirstate = repo.dirstate |
|
617 | 617 | for realname, tmpname in pycompat.iteritems(backups): |
|
618 | 618 | ui.debug(b'restoring %r to %r\n' % (tmpname, realname)) |
|
619 | 619 | |
|
620 | 620 | if dirstate[realname] == b'n': |
|
621 | 621 | # without normallookup, restoring timestamp |
|
622 | 622 | # may cause partially committed files |
|
623 | 623 | # to be treated as unmodified |
|
624 | 624 | dirstate.normallookup(realname) |
|
625 | 625 | |
|
626 | 626 | # copystat=True here and above are a hack to trick any |
|
627 | 627 | # editors that have f open that we haven't modified them. |
|
628 | 628 | # |
|
629 | 629 | # Also note that this racy as an editor could notice the |
|
630 | 630 | # file's mtime before we've finished writing it. |
|
631 | 631 | util.copyfile(tmpname, repo.wjoin(realname), copystat=True) |
|
632 | 632 | os.unlink(tmpname) |
|
633 | 633 | if tobackup: |
|
634 | 634 | os.rmdir(backupdir) |
|
635 | 635 | except OSError: |
|
636 | 636 | pass |
|
637 | 637 | |
|
638 | 638 | def recordinwlock(ui, repo, message, match, opts): |
|
639 | 639 | with repo.wlock(): |
|
640 | 640 | return recordfunc(ui, repo, message, match, opts) |
|
641 | 641 | |
|
642 | 642 | return commit(ui, repo, recordinwlock, pats, opts) |
|
643 | 643 | |
|
644 | 644 | |
|
645 | 645 | class dirnode(object): |
|
646 | 646 | """ |
|
647 | 647 | Represent a directory in user working copy with information required for |
|
648 | 648 | the purpose of tersing its status. |
|
649 | 649 | |
|
650 | 650 | path is the path to the directory, without a trailing '/' |
|
651 | 651 | |
|
652 | 652 | statuses is a set of statuses of all files in this directory (this includes |
|
653 | 653 | all the files in all the subdirectories too) |
|
654 | 654 | |
|
655 | 655 | files is a list of files which are direct child of this directory |
|
656 | 656 | |
|
657 | 657 | subdirs is a dictionary of sub-directory name as the key and it's own |
|
658 | 658 | dirnode object as the value |
|
659 | 659 | """ |
|
660 | 660 | |
|
661 | 661 | def __init__(self, dirpath): |
|
662 | 662 | self.path = dirpath |
|
663 | 663 | self.statuses = set() |
|
664 | 664 | self.files = [] |
|
665 | 665 | self.subdirs = {} |
|
666 | 666 | |
|
667 | 667 | def _addfileindir(self, filename, status): |
|
668 | 668 | """Add a file in this directory as a direct child.""" |
|
669 | 669 | self.files.append((filename, status)) |
|
670 | 670 | |
|
671 | 671 | def addfile(self, filename, status): |
|
672 | 672 | """ |
|
673 | 673 | Add a file to this directory or to its direct parent directory. |
|
674 | 674 | |
|
675 | 675 | If the file is not direct child of this directory, we traverse to the |
|
676 | 676 | directory of which this file is a direct child of and add the file |
|
677 | 677 | there. |
|
678 | 678 | """ |
|
679 | 679 | |
|
680 | 680 | # the filename contains a path separator, it means it's not the direct |
|
681 | 681 | # child of this directory |
|
682 | 682 | if b'/' in filename: |
|
683 | 683 | subdir, filep = filename.split(b'/', 1) |
|
684 | 684 | |
|
685 | 685 | # does the dirnode object for subdir exists |
|
686 | 686 | if subdir not in self.subdirs: |
|
687 | 687 | subdirpath = pathutil.join(self.path, subdir) |
|
688 | 688 | self.subdirs[subdir] = dirnode(subdirpath) |
|
689 | 689 | |
|
690 | 690 | # try adding the file in subdir |
|
691 | 691 | self.subdirs[subdir].addfile(filep, status) |
|
692 | 692 | |
|
693 | 693 | else: |
|
694 | 694 | self._addfileindir(filename, status) |
|
695 | 695 | |
|
696 | 696 | if status not in self.statuses: |
|
697 | 697 | self.statuses.add(status) |
|
698 | 698 | |
|
699 | 699 | def iterfilepaths(self): |
|
700 | 700 | """Yield (status, path) for files directly under this directory.""" |
|
701 | 701 | for f, st in self.files: |
|
702 | 702 | yield st, pathutil.join(self.path, f) |
|
703 | 703 | |
|
704 | 704 | def tersewalk(self, terseargs): |
|
705 | 705 | """ |
|
706 | 706 | Yield (status, path) obtained by processing the status of this |
|
707 | 707 | dirnode. |
|
708 | 708 | |
|
709 | 709 | terseargs is the string of arguments passed by the user with `--terse` |
|
710 | 710 | flag. |
|
711 | 711 | |
|
712 | 712 | Following are the cases which can happen: |
|
713 | 713 | |
|
714 | 714 | 1) All the files in the directory (including all the files in its |
|
715 | 715 | subdirectories) share the same status and the user has asked us to terse |
|
716 | 716 | that status. -> yield (status, dirpath). dirpath will end in '/'. |
|
717 | 717 | |
|
718 | 718 | 2) Otherwise, we do following: |
|
719 | 719 | |
|
720 | 720 | a) Yield (status, filepath) for all the files which are in this |
|
721 | 721 | directory (only the ones in this directory, not the subdirs) |
|
722 | 722 | |
|
723 | 723 | b) Recurse the function on all the subdirectories of this |
|
724 | 724 | directory |
|
725 | 725 | """ |
|
726 | 726 | |
|
727 | 727 | if len(self.statuses) == 1: |
|
728 | 728 | onlyst = self.statuses.pop() |
|
729 | 729 | |
|
730 | 730 | # Making sure we terse only when the status abbreviation is |
|
731 | 731 | # passed as terse argument |
|
732 | 732 | if onlyst in terseargs: |
|
733 | 733 | yield onlyst, self.path + b'/' |
|
734 | 734 | return |
|
735 | 735 | |
|
736 | 736 | # add the files to status list |
|
737 | 737 | for st, fpath in self.iterfilepaths(): |
|
738 | 738 | yield st, fpath |
|
739 | 739 | |
|
740 | 740 | # recurse on the subdirs |
|
741 | 741 | for dirobj in self.subdirs.values(): |
|
742 | 742 | for st, fpath in dirobj.tersewalk(terseargs): |
|
743 | 743 | yield st, fpath |
|
744 | 744 | |
|
745 | 745 | |
|
746 | 746 | def tersedir(statuslist, terseargs): |
|
747 | 747 | """ |
|
748 | 748 | Terse the status if all the files in a directory shares the same status. |
|
749 | 749 | |
|
750 | 750 | statuslist is scmutil.status() object which contains a list of files for |
|
751 | 751 | each status. |
|
752 | 752 | terseargs is string which is passed by the user as the argument to `--terse` |
|
753 | 753 | flag. |
|
754 | 754 | |
|
755 | 755 | The function makes a tree of objects of dirnode class, and at each node it |
|
756 | 756 | stores the information required to know whether we can terse a certain |
|
757 | 757 | directory or not. |
|
758 | 758 | """ |
|
759 | 759 | # the order matters here as that is used to produce final list |
|
760 | 760 | allst = (b'm', b'a', b'r', b'd', b'u', b'i', b'c') |
|
761 | 761 | |
|
762 | 762 | # checking the argument validity |
|
763 | 763 | for s in pycompat.bytestr(terseargs): |
|
764 | 764 | if s not in allst: |
|
765 | 765 | raise error.Abort(_(b"'%s' not recognized") % s) |
|
766 | 766 | |
|
767 | 767 | # creating a dirnode object for the root of the repo |
|
768 | 768 | rootobj = dirnode(b'') |
|
769 | 769 | pstatus = ( |
|
770 | 770 | b'modified', |
|
771 | 771 | b'added', |
|
772 | 772 | b'deleted', |
|
773 | 773 | b'clean', |
|
774 | 774 | b'unknown', |
|
775 | 775 | b'ignored', |
|
776 | 776 | b'removed', |
|
777 | 777 | ) |
|
778 | 778 | |
|
779 | 779 | tersedict = {} |
|
780 | 780 | for attrname in pstatus: |
|
781 | 781 | statuschar = attrname[0:1] |
|
782 | 782 | for f in getattr(statuslist, attrname): |
|
783 | 783 | rootobj.addfile(f, statuschar) |
|
784 | 784 | tersedict[statuschar] = [] |
|
785 | 785 | |
|
786 | 786 | # we won't be tersing the root dir, so add files in it |
|
787 | 787 | for st, fpath in rootobj.iterfilepaths(): |
|
788 | 788 | tersedict[st].append(fpath) |
|
789 | 789 | |
|
790 | 790 | # process each sub-directory and build tersedict |
|
791 | 791 | for subdir in rootobj.subdirs.values(): |
|
792 | 792 | for st, f in subdir.tersewalk(terseargs): |
|
793 | 793 | tersedict[st].append(f) |
|
794 | 794 | |
|
795 | 795 | tersedlist = [] |
|
796 | 796 | for st in allst: |
|
797 | 797 | tersedict[st].sort() |
|
798 | 798 | tersedlist.append(tersedict[st]) |
|
799 | 799 | |
|
800 | 800 | return scmutil.status(*tersedlist) |
|
801 | 801 | |
|
802 | 802 | |
|
803 | 803 | def _commentlines(raw): |
|
804 | 804 | '''Surround lineswith a comment char and a new line''' |
|
805 | 805 | lines = raw.splitlines() |
|
806 | 806 | commentedlines = [b'# %s' % line for line in lines] |
|
807 | 807 | return b'\n'.join(commentedlines) + b'\n' |
|
808 | 808 | |
|
809 | 809 | |
|
810 | 810 | @attr.s(frozen=True) |
|
811 | 811 | class morestatus(object): |
|
812 | 812 | reporoot = attr.ib() |
|
813 | 813 | unfinishedop = attr.ib() |
|
814 | 814 | unfinishedmsg = attr.ib() |
|
815 | 815 | activemerge = attr.ib() |
|
816 | 816 | unresolvedpaths = attr.ib() |
|
817 | 817 | _formattedpaths = attr.ib(init=False, default=set()) |
|
818 | 818 | _label = b'status.morestatus' |
|
819 | 819 | |
|
820 | 820 | def formatfile(self, path, fm): |
|
821 | 821 | self._formattedpaths.add(path) |
|
822 | 822 | if self.activemerge and path in self.unresolvedpaths: |
|
823 | 823 | fm.data(unresolved=True) |
|
824 | 824 | |
|
825 | 825 | def formatfooter(self, fm): |
|
826 | 826 | if self.unfinishedop or self.unfinishedmsg: |
|
827 | 827 | fm.startitem() |
|
828 | 828 | fm.data(itemtype=b'morestatus') |
|
829 | 829 | |
|
830 | 830 | if self.unfinishedop: |
|
831 | 831 | fm.data(unfinished=self.unfinishedop) |
|
832 | 832 | statemsg = ( |
|
833 | 833 | _(b'The repository is in an unfinished *%s* state.') |
|
834 | 834 | % self.unfinishedop |
|
835 | 835 | ) |
|
836 | 836 | fm.plain(b'%s\n' % _commentlines(statemsg), label=self._label) |
|
837 | 837 | if self.unfinishedmsg: |
|
838 | 838 | fm.data(unfinishedmsg=self.unfinishedmsg) |
|
839 | 839 | |
|
840 | 840 | # May also start new data items. |
|
841 | 841 | self._formatconflicts(fm) |
|
842 | 842 | |
|
843 | 843 | if self.unfinishedmsg: |
|
844 | 844 | fm.plain( |
|
845 | 845 | b'%s\n' % _commentlines(self.unfinishedmsg), label=self._label |
|
846 | 846 | ) |
|
847 | 847 | |
|
848 | 848 | def _formatconflicts(self, fm): |
|
849 | 849 | if not self.activemerge: |
|
850 | 850 | return |
|
851 | 851 | |
|
852 | 852 | if self.unresolvedpaths: |
|
853 | 853 | mergeliststr = b'\n'.join( |
|
854 | 854 | [ |
|
855 | 855 | b' %s' |
|
856 | 856 | % util.pathto(self.reporoot, encoding.getcwd(), path) |
|
857 | 857 | for path in self.unresolvedpaths |
|
858 | 858 | ] |
|
859 | 859 | ) |
|
860 | 860 | msg = ( |
|
861 | 861 | _( |
|
862 | 862 | '''Unresolved merge conflicts: |
|
863 | 863 | |
|
864 | 864 | %s |
|
865 | 865 | |
|
866 | 866 | To mark files as resolved: hg resolve --mark FILE''' |
|
867 | 867 | ) |
|
868 | 868 | % mergeliststr |
|
869 | 869 | ) |
|
870 | 870 | |
|
871 | 871 | # If any paths with unresolved conflicts were not previously |
|
872 | 872 | # formatted, output them now. |
|
873 | 873 | for f in self.unresolvedpaths: |
|
874 | 874 | if f in self._formattedpaths: |
|
875 | 875 | # Already output. |
|
876 | 876 | continue |
|
877 | 877 | fm.startitem() |
|
878 | 878 | # We can't claim to know the status of the file - it may just |
|
879 | 879 | # have been in one of the states that were not requested for |
|
880 | 880 | # display, so it could be anything. |
|
881 | 881 | fm.data(itemtype=b'file', path=f, unresolved=True) |
|
882 | 882 | |
|
883 | 883 | else: |
|
884 | 884 | msg = _(b'No unresolved merge conflicts.') |
|
885 | 885 | |
|
886 | 886 | fm.plain(b'%s\n' % _commentlines(msg), label=self._label) |
|
887 | 887 | |
|
888 | 888 | |
|
889 | 889 | def readmorestatus(repo): |
|
890 | 890 | """Returns a morestatus object if the repo has unfinished state.""" |
|
891 | 891 | statetuple = statemod.getrepostate(repo) |
|
892 | 892 | mergestate = mergestatemod.mergestate.read(repo) |
|
893 | 893 | activemerge = mergestate.active() |
|
894 | 894 | if not statetuple and not activemerge: |
|
895 | 895 | return None |
|
896 | 896 | |
|
897 | 897 | unfinishedop = unfinishedmsg = unresolved = None |
|
898 | 898 | if statetuple: |
|
899 | 899 | unfinishedop, unfinishedmsg = statetuple |
|
900 | 900 | if activemerge: |
|
901 | 901 | unresolved = sorted(mergestate.unresolved()) |
|
902 | 902 | return morestatus( |
|
903 | 903 | repo.root, unfinishedop, unfinishedmsg, activemerge, unresolved |
|
904 | 904 | ) |
|
905 | 905 | |
|
906 | 906 | |
|
907 | 907 | def findpossible(cmd, table, strict=False): |
|
908 | 908 | """ |
|
909 | 909 | Return cmd -> (aliases, command table entry) |
|
910 | 910 | for each matching command. |
|
911 | 911 | Return debug commands (or their aliases) only if no normal command matches. |
|
912 | 912 | """ |
|
913 | 913 | choice = {} |
|
914 | 914 | debugchoice = {} |
|
915 | 915 | |
|
916 | 916 | if cmd in table: |
|
917 | 917 | # short-circuit exact matches, "log" alias beats "log|history" |
|
918 | 918 | keys = [cmd] |
|
919 | 919 | else: |
|
920 | 920 | keys = table.keys() |
|
921 | 921 | |
|
922 | 922 | allcmds = [] |
|
923 | 923 | for e in keys: |
|
924 | 924 | aliases = parsealiases(e) |
|
925 | 925 | allcmds.extend(aliases) |
|
926 | 926 | found = None |
|
927 | 927 | if cmd in aliases: |
|
928 | 928 | found = cmd |
|
929 | 929 | elif not strict: |
|
930 | 930 | for a in aliases: |
|
931 | 931 | if a.startswith(cmd): |
|
932 | 932 | found = a |
|
933 | 933 | break |
|
934 | 934 | if found is not None: |
|
935 | 935 | if aliases[0].startswith(b"debug") or found.startswith(b"debug"): |
|
936 | 936 | debugchoice[found] = (aliases, table[e]) |
|
937 | 937 | else: |
|
938 | 938 | choice[found] = (aliases, table[e]) |
|
939 | 939 | |
|
940 | 940 | if not choice and debugchoice: |
|
941 | 941 | choice = debugchoice |
|
942 | 942 | |
|
943 | 943 | return choice, allcmds |
|
944 | 944 | |
|
945 | 945 | |
|
946 | 946 | def findcmd(cmd, table, strict=True): |
|
947 | 947 | """Return (aliases, command table entry) for command string.""" |
|
948 | 948 | choice, allcmds = findpossible(cmd, table, strict) |
|
949 | 949 | |
|
950 | 950 | if cmd in choice: |
|
951 | 951 | return choice[cmd] |
|
952 | 952 | |
|
953 | 953 | if len(choice) > 1: |
|
954 | 954 | clist = sorted(choice) |
|
955 | 955 | raise error.AmbiguousCommand(cmd, clist) |
|
956 | 956 | |
|
957 | 957 | if choice: |
|
958 | 958 | return list(choice.values())[0] |
|
959 | 959 | |
|
960 | 960 | raise error.UnknownCommand(cmd, allcmds) |
|
961 | 961 | |
|
962 | 962 | |
|
963 | 963 | def changebranch(ui, repo, revs, label, opts): |
|
964 | 964 | """ Change the branch name of given revs to label """ |
|
965 | 965 | |
|
966 | 966 | with repo.wlock(), repo.lock(), repo.transaction(b'branches'): |
|
967 | 967 | # abort in case of uncommitted merge or dirty wdir |
|
968 | 968 | bailifchanged(repo) |
|
969 | 969 | revs = scmutil.revrange(repo, revs) |
|
970 | 970 | if not revs: |
|
971 | 971 | raise error.Abort(b"empty revision set") |
|
972 | 972 | roots = repo.revs(b'roots(%ld)', revs) |
|
973 | 973 | if len(roots) > 1: |
|
974 | 974 | raise error.Abort( |
|
975 | 975 | _(b"cannot change branch of non-linear revisions") |
|
976 | 976 | ) |
|
977 | 977 | rewriteutil.precheck(repo, revs, b'change branch of') |
|
978 | 978 | |
|
979 | 979 | root = repo[roots.first()] |
|
980 | 980 | rpb = {parent.branch() for parent in root.parents()} |
|
981 | 981 | if ( |
|
982 | 982 | not opts.get(b'force') |
|
983 | 983 | and label not in rpb |
|
984 | 984 | and label in repo.branchmap() |
|
985 | 985 | ): |
|
986 | 986 | raise error.Abort(_(b"a branch of the same name already exists")) |
|
987 | 987 | |
|
988 | 988 | if repo.revs(b'obsolete() and %ld', revs): |
|
989 | 989 | raise error.Abort( |
|
990 | 990 | _(b"cannot change branch of a obsolete changeset") |
|
991 | 991 | ) |
|
992 | 992 | |
|
993 | 993 | # make sure only topological heads |
|
994 | 994 | if repo.revs(b'heads(%ld) - head()', revs): |
|
995 | 995 | raise error.Abort(_(b"cannot change branch in middle of a stack")) |
|
996 | 996 | |
|
997 | 997 | replacements = {} |
|
998 | 998 | # avoid import cycle mercurial.cmdutil -> mercurial.context -> |
|
999 | 999 | # mercurial.subrepo -> mercurial.cmdutil |
|
1000 | 1000 | from . import context |
|
1001 | 1001 | |
|
1002 | 1002 | for rev in revs: |
|
1003 | 1003 | ctx = repo[rev] |
|
1004 | 1004 | oldbranch = ctx.branch() |
|
1005 | 1005 | # check if ctx has same branch |
|
1006 | 1006 | if oldbranch == label: |
|
1007 | 1007 | continue |
|
1008 | 1008 | |
|
1009 | 1009 | def filectxfn(repo, newctx, path): |
|
1010 | 1010 | try: |
|
1011 | 1011 | return ctx[path] |
|
1012 | 1012 | except error.ManifestLookupError: |
|
1013 | 1013 | return None |
|
1014 | 1014 | |
|
1015 | 1015 | ui.debug( |
|
1016 | 1016 | b"changing branch of '%s' from '%s' to '%s'\n" |
|
1017 | 1017 | % (hex(ctx.node()), oldbranch, label) |
|
1018 | 1018 | ) |
|
1019 | 1019 | extra = ctx.extra() |
|
1020 | 1020 | extra[b'branch_change'] = hex(ctx.node()) |
|
1021 | 1021 | # While changing branch of set of linear commits, make sure that |
|
1022 | 1022 | # we base our commits on new parent rather than old parent which |
|
1023 | 1023 | # was obsoleted while changing the branch |
|
1024 | 1024 | p1 = ctx.p1().node() |
|
1025 | 1025 | p2 = ctx.p2().node() |
|
1026 | 1026 | if p1 in replacements: |
|
1027 | 1027 | p1 = replacements[p1][0] |
|
1028 | 1028 | if p2 in replacements: |
|
1029 | 1029 | p2 = replacements[p2][0] |
|
1030 | 1030 | |
|
1031 | 1031 | mc = context.memctx( |
|
1032 | 1032 | repo, |
|
1033 | 1033 | (p1, p2), |
|
1034 | 1034 | ctx.description(), |
|
1035 | 1035 | ctx.files(), |
|
1036 | 1036 | filectxfn, |
|
1037 | 1037 | user=ctx.user(), |
|
1038 | 1038 | date=ctx.date(), |
|
1039 | 1039 | extra=extra, |
|
1040 | 1040 | branch=label, |
|
1041 | 1041 | ) |
|
1042 | 1042 | |
|
1043 | 1043 | newnode = repo.commitctx(mc) |
|
1044 | 1044 | replacements[ctx.node()] = (newnode,) |
|
1045 | 1045 | ui.debug(b'new node id is %s\n' % hex(newnode)) |
|
1046 | 1046 | |
|
1047 | 1047 | # create obsmarkers and move bookmarks |
|
1048 | 1048 | scmutil.cleanupnodes( |
|
1049 | 1049 | repo, replacements, b'branch-change', fixphase=True |
|
1050 | 1050 | ) |
|
1051 | 1051 | |
|
1052 | 1052 | # move the working copy too |
|
1053 | 1053 | wctx = repo[None] |
|
1054 | 1054 | # in-progress merge is a bit too complex for now. |
|
1055 | 1055 | if len(wctx.parents()) == 1: |
|
1056 | 1056 | newid = replacements.get(wctx.p1().node()) |
|
1057 | 1057 | if newid is not None: |
|
1058 | 1058 | # avoid import cycle mercurial.cmdutil -> mercurial.hg -> |
|
1059 | 1059 | # mercurial.cmdutil |
|
1060 | 1060 | from . import hg |
|
1061 | 1061 | |
|
1062 | 1062 | hg.update(repo, newid[0], quietempty=True) |
|
1063 | 1063 | |
|
1064 | 1064 | ui.status(_(b"changed branch on %d changesets\n") % len(replacements)) |
|
1065 | 1065 | |
|
1066 | 1066 | |
|
1067 | 1067 | def findrepo(p): |
|
1068 | 1068 | while not os.path.isdir(os.path.join(p, b".hg")): |
|
1069 | 1069 | oldp, p = p, os.path.dirname(p) |
|
1070 | 1070 | if p == oldp: |
|
1071 | 1071 | return None |
|
1072 | 1072 | |
|
1073 | 1073 | return p |
|
1074 | 1074 | |
|
1075 | 1075 | |
|
1076 | 1076 | def bailifchanged(repo, merge=True, hint=None): |
|
1077 | 1077 | """ enforce the precondition that working directory must be clean. |
|
1078 | 1078 | |
|
1079 | 1079 | 'merge' can be set to false if a pending uncommitted merge should be |
|
1080 | 1080 | ignored (such as when 'update --check' runs). |
|
1081 | 1081 | |
|
1082 | 1082 | 'hint' is the usual hint given to Abort exception. |
|
1083 | 1083 | """ |
|
1084 | 1084 | |
|
1085 | 1085 | if merge and repo.dirstate.p2() != nullid: |
|
1086 | 1086 | raise error.Abort(_(b'outstanding uncommitted merge'), hint=hint) |
|
1087 | 1087 | st = repo.status() |
|
1088 | 1088 | if st.modified or st.added or st.removed or st.deleted: |
|
1089 | 1089 | raise error.Abort(_(b'uncommitted changes'), hint=hint) |
|
1090 | 1090 | ctx = repo[None] |
|
1091 | 1091 | for s in sorted(ctx.substate): |
|
1092 | 1092 | ctx.sub(s).bailifchanged(hint=hint) |
|
1093 | 1093 | |
|
1094 | 1094 | |
|
1095 | 1095 | def logmessage(ui, opts): |
|
1096 | 1096 | """ get the log message according to -m and -l option """ |
|
1097 | 1097 | |
|
1098 | 1098 | check_at_most_one_arg(opts, b'message', b'logfile') |
|
1099 | 1099 | |
|
1100 | 1100 | message = opts.get(b'message') |
|
1101 | 1101 | logfile = opts.get(b'logfile') |
|
1102 | 1102 | |
|
1103 | 1103 | if not message and logfile: |
|
1104 | 1104 | try: |
|
1105 | 1105 | if isstdiofilename(logfile): |
|
1106 | 1106 | message = ui.fin.read() |
|
1107 | 1107 | else: |
|
1108 | 1108 | message = b'\n'.join(util.readfile(logfile).splitlines()) |
|
1109 | 1109 | except IOError as inst: |
|
1110 | 1110 | raise error.Abort( |
|
1111 | 1111 | _(b"can't read commit message '%s': %s") |
|
1112 | 1112 | % (logfile, encoding.strtolocal(inst.strerror)) |
|
1113 | 1113 | ) |
|
1114 | 1114 | return message |
|
1115 | 1115 | |
|
1116 | 1116 | |
|
1117 | 1117 | def mergeeditform(ctxorbool, baseformname): |
|
1118 | 1118 | """return appropriate editform name (referencing a committemplate) |
|
1119 | 1119 | |
|
1120 | 1120 | 'ctxorbool' is either a ctx to be committed, or a bool indicating whether |
|
1121 | 1121 | merging is committed. |
|
1122 | 1122 | |
|
1123 | 1123 | This returns baseformname with '.merge' appended if it is a merge, |
|
1124 | 1124 | otherwise '.normal' is appended. |
|
1125 | 1125 | """ |
|
1126 | 1126 | if isinstance(ctxorbool, bool): |
|
1127 | 1127 | if ctxorbool: |
|
1128 | 1128 | return baseformname + b".merge" |
|
1129 | 1129 | elif len(ctxorbool.parents()) > 1: |
|
1130 | 1130 | return baseformname + b".merge" |
|
1131 | 1131 | |
|
1132 | 1132 | return baseformname + b".normal" |
|
1133 | 1133 | |
|
1134 | 1134 | |
|
1135 | 1135 | def getcommiteditor( |
|
1136 | 1136 | edit=False, finishdesc=None, extramsg=None, editform=b'', **opts |
|
1137 | 1137 | ): |
|
1138 | 1138 | """get appropriate commit message editor according to '--edit' option |
|
1139 | 1139 | |
|
1140 | 1140 | 'finishdesc' is a function to be called with edited commit message |
|
1141 | 1141 | (= 'description' of the new changeset) just after editing, but |
|
1142 | 1142 | before checking empty-ness. It should return actual text to be |
|
1143 | 1143 | stored into history. This allows to change description before |
|
1144 | 1144 | storing. |
|
1145 | 1145 | |
|
1146 | 1146 | 'extramsg' is a extra message to be shown in the editor instead of |
|
1147 | 1147 | 'Leave message empty to abort commit' line. 'HG: ' prefix and EOL |
|
1148 | 1148 | is automatically added. |
|
1149 | 1149 | |
|
1150 | 1150 | 'editform' is a dot-separated list of names, to distinguish |
|
1151 | 1151 | the purpose of commit text editing. |
|
1152 | 1152 | |
|
1153 | 1153 | 'getcommiteditor' returns 'commitforceeditor' regardless of |
|
1154 | 1154 | 'edit', if one of 'finishdesc' or 'extramsg' is specified, because |
|
1155 | 1155 | they are specific for usage in MQ. |
|
1156 | 1156 | """ |
|
1157 | 1157 | if edit or finishdesc or extramsg: |
|
1158 | 1158 | return lambda r, c, s: commitforceeditor( |
|
1159 | 1159 | r, c, s, finishdesc=finishdesc, extramsg=extramsg, editform=editform |
|
1160 | 1160 | ) |
|
1161 | 1161 | elif editform: |
|
1162 | 1162 | return lambda r, c, s: commiteditor(r, c, s, editform=editform) |
|
1163 | 1163 | else: |
|
1164 | 1164 | return commiteditor |
|
1165 | 1165 | |
|
1166 | 1166 | |
|
1167 | 1167 | def _escapecommandtemplate(tmpl): |
|
1168 | 1168 | parts = [] |
|
1169 | 1169 | for typ, start, end in templater.scantemplate(tmpl, raw=True): |
|
1170 | 1170 | if typ == b'string': |
|
1171 | 1171 | parts.append(stringutil.escapestr(tmpl[start:end])) |
|
1172 | 1172 | else: |
|
1173 | 1173 | parts.append(tmpl[start:end]) |
|
1174 | 1174 | return b''.join(parts) |
|
1175 | 1175 | |
|
1176 | 1176 | |
|
1177 | 1177 | def rendercommandtemplate(ui, tmpl, props): |
|
1178 | 1178 | r"""Expand a literal template 'tmpl' in a way suitable for command line |
|
1179 | 1179 | |
|
1180 | 1180 | '\' in outermost string is not taken as an escape character because it |
|
1181 | 1181 | is a directory separator on Windows. |
|
1182 | 1182 | |
|
1183 | 1183 | >>> from . import ui as uimod |
|
1184 | 1184 | >>> ui = uimod.ui() |
|
1185 | 1185 | >>> rendercommandtemplate(ui, b'c:\\{path}', {b'path': b'foo'}) |
|
1186 | 1186 | 'c:\\foo' |
|
1187 | 1187 | >>> rendercommandtemplate(ui, b'{"c:\\{path}"}', {'path': b'foo'}) |
|
1188 | 1188 | 'c:{path}' |
|
1189 | 1189 | """ |
|
1190 | 1190 | if not tmpl: |
|
1191 | 1191 | return tmpl |
|
1192 | 1192 | t = formatter.maketemplater(ui, _escapecommandtemplate(tmpl)) |
|
1193 | 1193 | return t.renderdefault(props) |
|
1194 | 1194 | |
|
1195 | 1195 | |
|
1196 | 1196 | def rendertemplate(ctx, tmpl, props=None): |
|
1197 | 1197 | """Expand a literal template 'tmpl' byte-string against one changeset |
|
1198 | 1198 | |
|
1199 | 1199 | Each props item must be a stringify-able value or a callable returning |
|
1200 | 1200 | such value, i.e. no bare list nor dict should be passed. |
|
1201 | 1201 | """ |
|
1202 | 1202 | repo = ctx.repo() |
|
1203 | 1203 | tres = formatter.templateresources(repo.ui, repo) |
|
1204 | 1204 | t = formatter.maketemplater( |
|
1205 | 1205 | repo.ui, tmpl, defaults=templatekw.keywords, resources=tres |
|
1206 | 1206 | ) |
|
1207 | 1207 | mapping = {b'ctx': ctx} |
|
1208 | 1208 | if props: |
|
1209 | 1209 | mapping.update(props) |
|
1210 | 1210 | return t.renderdefault(mapping) |
|
1211 | 1211 | |
|
1212 | 1212 | |
|
1213 | 1213 | def format_changeset_summary(ui, ctx, command=None, default_spec=None): |
|
1214 | 1214 | """Format a changeset summary (one line).""" |
|
1215 | 1215 | spec = None |
|
1216 | 1216 | if command: |
|
1217 | 1217 | spec = ui.config( |
|
1218 | 1218 | b'command-templates', b'oneline-summary.%s' % command, None |
|
1219 | 1219 | ) |
|
1220 | 1220 | if not spec: |
|
1221 | 1221 | spec = ui.config(b'command-templates', b'oneline-summary') |
|
1222 | 1222 | if not spec: |
|
1223 | 1223 | spec = default_spec |
|
1224 | 1224 | if not spec: |
|
1225 | 1225 | spec = ( |
|
1226 | 1226 | b'{separate(" ", ' |
|
1227 | 1227 | b'label("oneline-summary.changeset", "{rev}:{node|short}")' |
|
1228 | 1228 | b', ' |
|
1229 | 1229 | b'join(filter(namespaces % "{ifeq(namespace, "branches", "", join(names % "{label("oneline-summary.{namespace}", name)}", " "))}"), " ")' |
|
1230 | 1230 | b')} ' |
|
1231 | 1231 | b'"{label("oneline-summary.desc", desc|firstline)}"' |
|
1232 | 1232 | ) |
|
1233 | 1233 | text = rendertemplate(ctx, spec) |
|
1234 | 1234 | return text.split(b'\n')[0] |
|
1235 | 1235 | |
|
1236 | 1236 | |
|
1237 | 1237 | def _buildfntemplate(pat, total=None, seqno=None, revwidth=None, pathname=None): |
|
1238 | 1238 | r"""Convert old-style filename format string to template string |
|
1239 | 1239 | |
|
1240 | 1240 | >>> _buildfntemplate(b'foo-%b-%n.patch', seqno=0) |
|
1241 | 1241 | 'foo-{reporoot|basename}-{seqno}.patch' |
|
1242 | 1242 | >>> _buildfntemplate(b'%R{tags % "{tag}"}%H') |
|
1243 | 1243 | '{rev}{tags % "{tag}"}{node}' |
|
1244 | 1244 | |
|
1245 | 1245 | '\' in outermost strings has to be escaped because it is a directory |
|
1246 | 1246 | separator on Windows: |
|
1247 | 1247 | |
|
1248 | 1248 | >>> _buildfntemplate(b'c:\\tmp\\%R\\%n.patch', seqno=0) |
|
1249 | 1249 | 'c:\\\\tmp\\\\{rev}\\\\{seqno}.patch' |
|
1250 | 1250 | >>> _buildfntemplate(b'\\\\foo\\bar.patch') |
|
1251 | 1251 | '\\\\\\\\foo\\\\bar.patch' |
|
1252 | 1252 | >>> _buildfntemplate(b'\\{tags % "{tag}"}') |
|
1253 | 1253 | '\\\\{tags % "{tag}"}' |
|
1254 | 1254 | |
|
1255 | 1255 | but inner strings follow the template rules (i.e. '\' is taken as an |
|
1256 | 1256 | escape character): |
|
1257 | 1257 | |
|
1258 | 1258 | >>> _buildfntemplate(br'{"c:\tmp"}', seqno=0) |
|
1259 | 1259 | '{"c:\\tmp"}' |
|
1260 | 1260 | """ |
|
1261 | 1261 | expander = { |
|
1262 | 1262 | b'H': b'{node}', |
|
1263 | 1263 | b'R': b'{rev}', |
|
1264 | 1264 | b'h': b'{node|short}', |
|
1265 | 1265 | b'm': br'{sub(r"[^\w]", "_", desc|firstline)}', |
|
1266 | 1266 | b'r': b'{if(revwidth, pad(rev, revwidth, "0", left=True), rev)}', |
|
1267 | 1267 | b'%': b'%', |
|
1268 | 1268 | b'b': b'{reporoot|basename}', |
|
1269 | 1269 | } |
|
1270 | 1270 | if total is not None: |
|
1271 | 1271 | expander[b'N'] = b'{total}' |
|
1272 | 1272 | if seqno is not None: |
|
1273 | 1273 | expander[b'n'] = b'{seqno}' |
|
1274 | 1274 | if total is not None and seqno is not None: |
|
1275 | 1275 | expander[b'n'] = b'{pad(seqno, total|stringify|count, "0", left=True)}' |
|
1276 | 1276 | if pathname is not None: |
|
1277 | 1277 | expander[b's'] = b'{pathname|basename}' |
|
1278 | 1278 | expander[b'd'] = b'{if(pathname|dirname, pathname|dirname, ".")}' |
|
1279 | 1279 | expander[b'p'] = b'{pathname}' |
|
1280 | 1280 | |
|
1281 | 1281 | newname = [] |
|
1282 | 1282 | for typ, start, end in templater.scantemplate(pat, raw=True): |
|
1283 | 1283 | if typ != b'string': |
|
1284 | 1284 | newname.append(pat[start:end]) |
|
1285 | 1285 | continue |
|
1286 | 1286 | i = start |
|
1287 | 1287 | while i < end: |
|
1288 | 1288 | n = pat.find(b'%', i, end) |
|
1289 | 1289 | if n < 0: |
|
1290 | 1290 | newname.append(stringutil.escapestr(pat[i:end])) |
|
1291 | 1291 | break |
|
1292 | 1292 | newname.append(stringutil.escapestr(pat[i:n])) |
|
1293 | 1293 | if n + 2 > end: |
|
1294 | 1294 | raise error.Abort( |
|
1295 | 1295 | _(b"incomplete format spec in output filename") |
|
1296 | 1296 | ) |
|
1297 | 1297 | c = pat[n + 1 : n + 2] |
|
1298 | 1298 | i = n + 2 |
|
1299 | 1299 | try: |
|
1300 | 1300 | newname.append(expander[c]) |
|
1301 | 1301 | except KeyError: |
|
1302 | 1302 | raise error.Abort( |
|
1303 | 1303 | _(b"invalid format spec '%%%s' in output filename") % c |
|
1304 | 1304 | ) |
|
1305 | 1305 | return b''.join(newname) |
|
1306 | 1306 | |
|
1307 | 1307 | |
|
1308 | 1308 | def makefilename(ctx, pat, **props): |
|
1309 | 1309 | if not pat: |
|
1310 | 1310 | return pat |
|
1311 | 1311 | tmpl = _buildfntemplate(pat, **props) |
|
1312 | 1312 | # BUG: alias expansion shouldn't be made against template fragments |
|
1313 | 1313 | # rewritten from %-format strings, but we have no easy way to partially |
|
1314 | 1314 | # disable the expansion. |
|
1315 | 1315 | return rendertemplate(ctx, tmpl, pycompat.byteskwargs(props)) |
|
1316 | 1316 | |
|
1317 | 1317 | |
|
1318 | 1318 | def isstdiofilename(pat): |
|
1319 | 1319 | """True if the given pat looks like a filename denoting stdin/stdout""" |
|
1320 | 1320 | return not pat or pat == b'-' |
|
1321 | 1321 | |
|
1322 | 1322 | |
|
1323 | 1323 | class _unclosablefile(object): |
|
1324 | 1324 | def __init__(self, fp): |
|
1325 | 1325 | self._fp = fp |
|
1326 | 1326 | |
|
1327 | 1327 | def close(self): |
|
1328 | 1328 | pass |
|
1329 | 1329 | |
|
1330 | 1330 | def __iter__(self): |
|
1331 | 1331 | return iter(self._fp) |
|
1332 | 1332 | |
|
1333 | 1333 | def __getattr__(self, attr): |
|
1334 | 1334 | return getattr(self._fp, attr) |
|
1335 | 1335 | |
|
1336 | 1336 | def __enter__(self): |
|
1337 | 1337 | return self |
|
1338 | 1338 | |
|
1339 | 1339 | def __exit__(self, exc_type, exc_value, exc_tb): |
|
1340 | 1340 | pass |
|
1341 | 1341 | |
|
1342 | 1342 | |
|
1343 | 1343 | def makefileobj(ctx, pat, mode=b'wb', **props): |
|
1344 | 1344 | writable = mode not in (b'r', b'rb') |
|
1345 | 1345 | |
|
1346 | 1346 | if isstdiofilename(pat): |
|
1347 | 1347 | repo = ctx.repo() |
|
1348 | 1348 | if writable: |
|
1349 | 1349 | fp = repo.ui.fout |
|
1350 | 1350 | else: |
|
1351 | 1351 | fp = repo.ui.fin |
|
1352 | 1352 | return _unclosablefile(fp) |
|
1353 | 1353 | fn = makefilename(ctx, pat, **props) |
|
1354 | 1354 | return open(fn, mode) |
|
1355 | 1355 | |
|
1356 | 1356 | |
|
1357 | 1357 | def openstorage(repo, cmd, file_, opts, returnrevlog=False): |
|
1358 | 1358 | """opens the changelog, manifest, a filelog or a given revlog""" |
|
1359 | 1359 | cl = opts[b'changelog'] |
|
1360 | 1360 | mf = opts[b'manifest'] |
|
1361 | 1361 | dir = opts[b'dir'] |
|
1362 | 1362 | msg = None |
|
1363 | 1363 | if cl and mf: |
|
1364 | 1364 | msg = _(b'cannot specify --changelog and --manifest at the same time') |
|
1365 | 1365 | elif cl and dir: |
|
1366 | 1366 | msg = _(b'cannot specify --changelog and --dir at the same time') |
|
1367 | 1367 | elif cl or mf or dir: |
|
1368 | 1368 | if file_: |
|
1369 | 1369 | msg = _(b'cannot specify filename with --changelog or --manifest') |
|
1370 | 1370 | elif not repo: |
|
1371 | 1371 | msg = _( |
|
1372 | 1372 | b'cannot specify --changelog or --manifest or --dir ' |
|
1373 | 1373 | b'without a repository' |
|
1374 | 1374 | ) |
|
1375 | 1375 | if msg: |
|
1376 | 1376 | raise error.Abort(msg) |
|
1377 | 1377 | |
|
1378 | 1378 | r = None |
|
1379 | 1379 | if repo: |
|
1380 | 1380 | if cl: |
|
1381 | 1381 | r = repo.unfiltered().changelog |
|
1382 | 1382 | elif dir: |
|
1383 | 1383 | if not scmutil.istreemanifest(repo): |
|
1384 | 1384 | raise error.Abort( |
|
1385 | 1385 | _( |
|
1386 | 1386 | b"--dir can only be used on repos with " |
|
1387 | 1387 | b"treemanifest enabled" |
|
1388 | 1388 | ) |
|
1389 | 1389 | ) |
|
1390 | 1390 | if not dir.endswith(b'/'): |
|
1391 | 1391 | dir = dir + b'/' |
|
1392 | 1392 | dirlog = repo.manifestlog.getstorage(dir) |
|
1393 | 1393 | if len(dirlog): |
|
1394 | 1394 | r = dirlog |
|
1395 | 1395 | elif mf: |
|
1396 | 1396 | r = repo.manifestlog.getstorage(b'') |
|
1397 | 1397 | elif file_: |
|
1398 | 1398 | filelog = repo.file(file_) |
|
1399 | 1399 | if len(filelog): |
|
1400 | 1400 | r = filelog |
|
1401 | 1401 | |
|
1402 | 1402 | # Not all storage may be revlogs. If requested, try to return an actual |
|
1403 | 1403 | # revlog instance. |
|
1404 | 1404 | if returnrevlog: |
|
1405 | 1405 | if isinstance(r, revlog.revlog): |
|
1406 | 1406 | pass |
|
1407 | 1407 | elif util.safehasattr(r, b'_revlog'): |
|
1408 | 1408 | r = r._revlog # pytype: disable=attribute-error |
|
1409 | 1409 | elif r is not None: |
|
1410 | 1410 | raise error.Abort(_(b'%r does not appear to be a revlog') % r) |
|
1411 | 1411 | |
|
1412 | 1412 | if not r: |
|
1413 | 1413 | if not returnrevlog: |
|
1414 | 1414 | raise error.Abort(_(b'cannot give path to non-revlog')) |
|
1415 | 1415 | |
|
1416 | 1416 | if not file_: |
|
1417 | 1417 | raise error.CommandError(cmd, _(b'invalid arguments')) |
|
1418 | 1418 | if not os.path.isfile(file_): |
|
1419 | 1419 | raise error.Abort(_(b"revlog '%s' not found") % file_) |
|
1420 | 1420 | r = revlog.revlog( |
|
1421 | 1421 | vfsmod.vfs(encoding.getcwd(), audit=False), file_[:-2] + b".i" |
|
1422 | 1422 | ) |
|
1423 | 1423 | return r |
|
1424 | 1424 | |
|
1425 | 1425 | |
|
1426 | 1426 | def openrevlog(repo, cmd, file_, opts): |
|
1427 | 1427 | """Obtain a revlog backing storage of an item. |
|
1428 | 1428 | |
|
1429 | 1429 | This is similar to ``openstorage()`` except it always returns a revlog. |
|
1430 | 1430 | |
|
1431 | 1431 | In most cases, a caller cares about the main storage object - not the |
|
1432 | 1432 | revlog backing it. Therefore, this function should only be used by code |
|
1433 | 1433 | that needs to examine low-level revlog implementation details. e.g. debug |
|
1434 | 1434 | commands. |
|
1435 | 1435 | """ |
|
1436 | 1436 | return openstorage(repo, cmd, file_, opts, returnrevlog=True) |
|
1437 | 1437 | |
|
1438 | 1438 | |
|
1439 | 1439 | def copy(ui, repo, pats, opts, rename=False): |
|
1440 | 1440 | check_incompatible_arguments(opts, b'forget', [b'dry_run']) |
|
1441 | 1441 | |
|
1442 | 1442 | # called with the repo lock held |
|
1443 | 1443 | # |
|
1444 | 1444 | # hgsep => pathname that uses "/" to separate directories |
|
1445 | 1445 | # ossep => pathname that uses os.sep to separate directories |
|
1446 | 1446 | cwd = repo.getcwd() |
|
1447 | 1447 | targets = {} |
|
1448 | 1448 | forget = opts.get(b"forget") |
|
1449 | 1449 | after = opts.get(b"after") |
|
1450 | 1450 | dryrun = opts.get(b"dry_run") |
|
1451 | 1451 | rev = opts.get(b'at_rev') |
|
1452 | 1452 | if rev: |
|
1453 | 1453 | if not forget and not after: |
|
1454 | 1454 | # TODO: Remove this restriction and make it also create the copy |
|
1455 | 1455 | # targets (and remove the rename source if rename==True). |
|
1456 | 1456 | raise error.Abort(_(b'--at-rev requires --after')) |
|
1457 | 1457 | ctx = scmutil.revsingle(repo, rev) |
|
1458 | 1458 | if len(ctx.parents()) > 1: |
|
1459 | 1459 | raise error.Abort(_(b'cannot mark/unmark copy in merge commit')) |
|
1460 | 1460 | else: |
|
1461 | 1461 | ctx = repo[None] |
|
1462 | 1462 | |
|
1463 | 1463 | pctx = ctx.p1() |
|
1464 | 1464 | |
|
1465 | 1465 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
|
1466 | 1466 | |
|
1467 | 1467 | if forget: |
|
1468 | 1468 | if ctx.rev() is None: |
|
1469 | 1469 | new_ctx = ctx |
|
1470 | 1470 | else: |
|
1471 | 1471 | if len(ctx.parents()) > 1: |
|
1472 | 1472 | raise error.Abort(_(b'cannot unmark copy in merge commit')) |
|
1473 | 1473 | # avoid cycle context -> subrepo -> cmdutil |
|
1474 | 1474 | from . import context |
|
1475 | 1475 | |
|
1476 | 1476 | rewriteutil.precheck(repo, [ctx.rev()], b'uncopy') |
|
1477 | 1477 | new_ctx = context.overlayworkingctx(repo) |
|
1478 | 1478 | new_ctx.setbase(ctx.p1()) |
|
1479 | 1479 | mergemod.graft(repo, ctx, wctx=new_ctx) |
|
1480 | 1480 | |
|
1481 | 1481 | match = scmutil.match(ctx, pats, opts) |
|
1482 | 1482 | |
|
1483 | 1483 | current_copies = ctx.p1copies() |
|
1484 | 1484 | current_copies.update(ctx.p2copies()) |
|
1485 | 1485 | |
|
1486 | 1486 | uipathfn = scmutil.getuipathfn(repo) |
|
1487 | 1487 | for f in ctx.walk(match): |
|
1488 | 1488 | if f in current_copies: |
|
1489 | 1489 | new_ctx[f].markcopied(None) |
|
1490 | 1490 | elif match.exact(f): |
|
1491 | 1491 | ui.warn( |
|
1492 | 1492 | _( |
|
1493 | 1493 | b'%s: not unmarking as copy - file is not marked as copied\n' |
|
1494 | 1494 | ) |
|
1495 | 1495 | % uipathfn(f) |
|
1496 | 1496 | ) |
|
1497 | 1497 | |
|
1498 | 1498 | if ctx.rev() is not None: |
|
1499 | 1499 | with repo.lock(): |
|
1500 | 1500 | mem_ctx = new_ctx.tomemctx_for_amend(ctx) |
|
1501 | 1501 | new_node = mem_ctx.commit() |
|
1502 | 1502 | |
|
1503 | 1503 | if repo.dirstate.p1() == ctx.node(): |
|
1504 | 1504 | with repo.dirstate.parentchange(): |
|
1505 | 1505 | scmutil.movedirstate(repo, repo[new_node]) |
|
1506 | 1506 | replacements = {ctx.node(): [new_node]} |
|
1507 | 1507 | scmutil.cleanupnodes( |
|
1508 | 1508 | repo, replacements, b'uncopy', fixphase=True |
|
1509 | 1509 | ) |
|
1510 | 1510 | |
|
1511 | 1511 | return |
|
1512 | 1512 | |
|
1513 | 1513 | pats = scmutil.expandpats(pats) |
|
1514 | 1514 | if not pats: |
|
1515 | 1515 | raise error.Abort(_(b'no source or destination specified')) |
|
1516 | 1516 | if len(pats) == 1: |
|
1517 | 1517 | raise error.Abort(_(b'no destination specified')) |
|
1518 | 1518 | dest = pats.pop() |
|
1519 | 1519 | |
|
1520 | 1520 | def walkpat(pat): |
|
1521 | 1521 | srcs = [] |
|
1522 | 1522 | # TODO: Inline and simplify the non-working-copy version of this code |
|
1523 | 1523 | # since it shares very little with the working-copy version of it. |
|
1524 | 1524 | ctx_to_walk = ctx if ctx.rev() is None else pctx |
|
1525 | 1525 | m = scmutil.match(ctx_to_walk, [pat], opts, globbed=True) |
|
1526 | 1526 | for abs in ctx_to_walk.walk(m): |
|
1527 | 1527 | rel = uipathfn(abs) |
|
1528 | 1528 | exact = m.exact(abs) |
|
1529 | 1529 | if abs not in ctx: |
|
1530 | 1530 | if abs in pctx: |
|
1531 | 1531 | if not after: |
|
1532 | 1532 | if exact: |
|
1533 | 1533 | ui.warn( |
|
1534 | 1534 | _( |
|
1535 | 1535 | b'%s: not copying - file has been marked ' |
|
1536 | 1536 | b'for remove\n' |
|
1537 | 1537 | ) |
|
1538 | 1538 | % rel |
|
1539 | 1539 | ) |
|
1540 | 1540 | continue |
|
1541 | 1541 | else: |
|
1542 | 1542 | if exact: |
|
1543 | 1543 | ui.warn( |
|
1544 | 1544 | _(b'%s: not copying - file is not managed\n') % rel |
|
1545 | 1545 | ) |
|
1546 | 1546 | continue |
|
1547 | 1547 | |
|
1548 | 1548 | # abs: hgsep |
|
1549 | 1549 | # rel: ossep |
|
1550 | 1550 | srcs.append((abs, rel, exact)) |
|
1551 | 1551 | return srcs |
|
1552 | 1552 | |
|
1553 | 1553 | if ctx.rev() is not None: |
|
1554 | 1554 | rewriteutil.precheck(repo, [ctx.rev()], b'uncopy') |
|
1555 | 1555 | absdest = pathutil.canonpath(repo.root, cwd, dest) |
|
1556 | 1556 | if ctx.hasdir(absdest): |
|
1557 | 1557 | raise error.Abort( |
|
1558 | 1558 | _(b'%s: --at-rev does not support a directory as destination') |
|
1559 | 1559 | % uipathfn(absdest) |
|
1560 | 1560 | ) |
|
1561 | 1561 | if absdest not in ctx: |
|
1562 | 1562 | raise error.Abort( |
|
1563 | 1563 | _(b'%s: copy destination does not exist in %s') |
|
1564 | 1564 | % (uipathfn(absdest), ctx) |
|
1565 | 1565 | ) |
|
1566 | 1566 | |
|
1567 | 1567 | # avoid cycle context -> subrepo -> cmdutil |
|
1568 | 1568 | from . import context |
|
1569 | 1569 | |
|
1570 | 1570 | copylist = [] |
|
1571 | 1571 | for pat in pats: |
|
1572 | 1572 | srcs = walkpat(pat) |
|
1573 | 1573 | if not srcs: |
|
1574 | 1574 | continue |
|
1575 | 1575 | for abs, rel, exact in srcs: |
|
1576 | 1576 | copylist.append(abs) |
|
1577 | 1577 | |
|
1578 | 1578 | if not copylist: |
|
1579 | 1579 | raise error.Abort(_(b'no files to copy')) |
|
1580 | 1580 | # TODO: Add support for `hg cp --at-rev . foo bar dir` and |
|
1581 | 1581 | # `hg cp --at-rev . dir1 dir2`, preferably unifying the code with the |
|
1582 | 1582 | # existing functions below. |
|
1583 | 1583 | if len(copylist) != 1: |
|
1584 | 1584 | raise error.Abort(_(b'--at-rev requires a single source')) |
|
1585 | 1585 | |
|
1586 | 1586 | new_ctx = context.overlayworkingctx(repo) |
|
1587 | 1587 | new_ctx.setbase(ctx.p1()) |
|
1588 | 1588 | mergemod.graft(repo, ctx, wctx=new_ctx) |
|
1589 | 1589 | |
|
1590 | 1590 | new_ctx.markcopied(absdest, copylist[0]) |
|
1591 | 1591 | |
|
1592 | 1592 | with repo.lock(): |
|
1593 | 1593 | mem_ctx = new_ctx.tomemctx_for_amend(ctx) |
|
1594 | 1594 | new_node = mem_ctx.commit() |
|
1595 | 1595 | |
|
1596 | 1596 | if repo.dirstate.p1() == ctx.node(): |
|
1597 | 1597 | with repo.dirstate.parentchange(): |
|
1598 | 1598 | scmutil.movedirstate(repo, repo[new_node]) |
|
1599 | 1599 | replacements = {ctx.node(): [new_node]} |
|
1600 | 1600 | scmutil.cleanupnodes(repo, replacements, b'copy', fixphase=True) |
|
1601 | 1601 | |
|
1602 | 1602 | return |
|
1603 | 1603 | |
|
1604 | 1604 | # abssrc: hgsep |
|
1605 | 1605 | # relsrc: ossep |
|
1606 | 1606 | # otarget: ossep |
|
1607 | 1607 | def copyfile(abssrc, relsrc, otarget, exact): |
|
1608 | 1608 | abstarget = pathutil.canonpath(repo.root, cwd, otarget) |
|
1609 | 1609 | if b'/' in abstarget: |
|
1610 | 1610 | # We cannot normalize abstarget itself, this would prevent |
|
1611 | 1611 | # case only renames, like a => A. |
|
1612 | 1612 | abspath, absname = abstarget.rsplit(b'/', 1) |
|
1613 | 1613 | abstarget = repo.dirstate.normalize(abspath) + b'/' + absname |
|
1614 | 1614 | reltarget = repo.pathto(abstarget, cwd) |
|
1615 | 1615 | target = repo.wjoin(abstarget) |
|
1616 | 1616 | src = repo.wjoin(abssrc) |
|
1617 | 1617 | state = repo.dirstate[abstarget] |
|
1618 | 1618 | |
|
1619 | 1619 | scmutil.checkportable(ui, abstarget) |
|
1620 | 1620 | |
|
1621 | 1621 | # check for collisions |
|
1622 | 1622 | prevsrc = targets.get(abstarget) |
|
1623 | 1623 | if prevsrc is not None: |
|
1624 | 1624 | ui.warn( |
|
1625 | 1625 | _(b'%s: not overwriting - %s collides with %s\n') |
|
1626 | 1626 | % ( |
|
1627 | 1627 | reltarget, |
|
1628 | 1628 | repo.pathto(abssrc, cwd), |
|
1629 | 1629 | repo.pathto(prevsrc, cwd), |
|
1630 | 1630 | ) |
|
1631 | 1631 | ) |
|
1632 | 1632 | return True # report a failure |
|
1633 | 1633 | |
|
1634 | 1634 | # check for overwrites |
|
1635 | 1635 | exists = os.path.lexists(target) |
|
1636 | 1636 | samefile = False |
|
1637 | 1637 | if exists and abssrc != abstarget: |
|
1638 | 1638 | if repo.dirstate.normalize(abssrc) == repo.dirstate.normalize( |
|
1639 | 1639 | abstarget |
|
1640 | 1640 | ): |
|
1641 | 1641 | if not rename: |
|
1642 | 1642 | ui.warn(_(b"%s: can't copy - same file\n") % reltarget) |
|
1643 | 1643 | return True # report a failure |
|
1644 | 1644 | exists = False |
|
1645 | 1645 | samefile = True |
|
1646 | 1646 | |
|
1647 | 1647 | if not after and exists or after and state in b'mn': |
|
1648 | 1648 | if not opts[b'force']: |
|
1649 | 1649 | if state in b'mn': |
|
1650 | 1650 | msg = _(b'%s: not overwriting - file already committed\n') |
|
1651 | 1651 | if after: |
|
1652 | 1652 | flags = b'--after --force' |
|
1653 | 1653 | else: |
|
1654 | 1654 | flags = b'--force' |
|
1655 | 1655 | if rename: |
|
1656 | 1656 | hint = ( |
|
1657 | 1657 | _( |
|
1658 | 1658 | b"('hg rename %s' to replace the file by " |
|
1659 | 1659 | b'recording a rename)\n' |
|
1660 | 1660 | ) |
|
1661 | 1661 | % flags |
|
1662 | 1662 | ) |
|
1663 | 1663 | else: |
|
1664 | 1664 | hint = ( |
|
1665 | 1665 | _( |
|
1666 | 1666 | b"('hg copy %s' to replace the file by " |
|
1667 | 1667 | b'recording a copy)\n' |
|
1668 | 1668 | ) |
|
1669 | 1669 | % flags |
|
1670 | 1670 | ) |
|
1671 | 1671 | else: |
|
1672 | 1672 | msg = _(b'%s: not overwriting - file exists\n') |
|
1673 | 1673 | if rename: |
|
1674 | 1674 | hint = _( |
|
1675 | 1675 | b"('hg rename --after' to record the rename)\n" |
|
1676 | 1676 | ) |
|
1677 | 1677 | else: |
|
1678 | 1678 | hint = _(b"('hg copy --after' to record the copy)\n") |
|
1679 | 1679 | ui.warn(msg % reltarget) |
|
1680 | 1680 | ui.warn(hint) |
|
1681 | 1681 | return True # report a failure |
|
1682 | 1682 | |
|
1683 | 1683 | if after: |
|
1684 | 1684 | if not exists: |
|
1685 | 1685 | if rename: |
|
1686 | 1686 | ui.warn( |
|
1687 | 1687 | _(b'%s: not recording move - %s does not exist\n') |
|
1688 | 1688 | % (relsrc, reltarget) |
|
1689 | 1689 | ) |
|
1690 | 1690 | else: |
|
1691 | 1691 | ui.warn( |
|
1692 | 1692 | _(b'%s: not recording copy - %s does not exist\n') |
|
1693 | 1693 | % (relsrc, reltarget) |
|
1694 | 1694 | ) |
|
1695 | 1695 | return True # report a failure |
|
1696 | 1696 | elif not dryrun: |
|
1697 | 1697 | try: |
|
1698 | 1698 | if exists: |
|
1699 | 1699 | os.unlink(target) |
|
1700 | 1700 | targetdir = os.path.dirname(target) or b'.' |
|
1701 | 1701 | if not os.path.isdir(targetdir): |
|
1702 | 1702 | os.makedirs(targetdir) |
|
1703 | 1703 | if samefile: |
|
1704 | 1704 | tmp = target + b"~hgrename" |
|
1705 | 1705 | os.rename(src, tmp) |
|
1706 | 1706 | os.rename(tmp, target) |
|
1707 | 1707 | else: |
|
1708 | 1708 | # Preserve stat info on renames, not on copies; this matches |
|
1709 | 1709 | # Linux CLI behavior. |
|
1710 | 1710 | util.copyfile(src, target, copystat=rename) |
|
1711 | 1711 | srcexists = True |
|
1712 | 1712 | except IOError as inst: |
|
1713 | 1713 | if inst.errno == errno.ENOENT: |
|
1714 | 1714 | ui.warn(_(b'%s: deleted in working directory\n') % relsrc) |
|
1715 | 1715 | srcexists = False |
|
1716 | 1716 | else: |
|
1717 | 1717 | ui.warn( |
|
1718 | 1718 | _(b'%s: cannot copy - %s\n') |
|
1719 | 1719 | % (relsrc, encoding.strtolocal(inst.strerror)) |
|
1720 | 1720 | ) |
|
1721 | 1721 | return True # report a failure |
|
1722 | 1722 | |
|
1723 | 1723 | if ui.verbose or not exact: |
|
1724 | 1724 | if rename: |
|
1725 | 1725 | ui.status(_(b'moving %s to %s\n') % (relsrc, reltarget)) |
|
1726 | 1726 | else: |
|
1727 | 1727 | ui.status(_(b'copying %s to %s\n') % (relsrc, reltarget)) |
|
1728 | 1728 | |
|
1729 | 1729 | targets[abstarget] = abssrc |
|
1730 | 1730 | |
|
1731 | 1731 | # fix up dirstate |
|
1732 | 1732 | scmutil.dirstatecopy( |
|
1733 | 1733 | ui, repo, ctx, abssrc, abstarget, dryrun=dryrun, cwd=cwd |
|
1734 | 1734 | ) |
|
1735 | 1735 | if rename and not dryrun: |
|
1736 | 1736 | if not after and srcexists and not samefile: |
|
1737 | 1737 | rmdir = repo.ui.configbool(b'experimental', b'removeemptydirs') |
|
1738 | 1738 | repo.wvfs.unlinkpath(abssrc, rmdir=rmdir) |
|
1739 | 1739 | ctx.forget([abssrc]) |
|
1740 | 1740 | |
|
1741 | 1741 | # pat: ossep |
|
1742 | 1742 | # dest ossep |
|
1743 | 1743 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
1744 | 1744 | # return: function that takes hgsep and returns ossep |
|
1745 | 1745 | def targetpathfn(pat, dest, srcs): |
|
1746 | 1746 | if os.path.isdir(pat): |
|
1747 | 1747 | abspfx = pathutil.canonpath(repo.root, cwd, pat) |
|
1748 | 1748 | abspfx = util.localpath(abspfx) |
|
1749 | 1749 | if destdirexists: |
|
1750 | 1750 | striplen = len(os.path.split(abspfx)[0]) |
|
1751 | 1751 | else: |
|
1752 | 1752 | striplen = len(abspfx) |
|
1753 | 1753 | if striplen: |
|
1754 | 1754 | striplen += len(pycompat.ossep) |
|
1755 | 1755 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
|
1756 | 1756 | elif destdirexists: |
|
1757 | 1757 | res = lambda p: os.path.join( |
|
1758 | 1758 | dest, os.path.basename(util.localpath(p)) |
|
1759 | 1759 | ) |
|
1760 | 1760 | else: |
|
1761 | 1761 | res = lambda p: dest |
|
1762 | 1762 | return res |
|
1763 | 1763 | |
|
1764 | 1764 | # pat: ossep |
|
1765 | 1765 | # dest ossep |
|
1766 | 1766 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
1767 | 1767 | # return: function that takes hgsep and returns ossep |
|
1768 | 1768 | def targetpathafterfn(pat, dest, srcs): |
|
1769 | 1769 | if matchmod.patkind(pat): |
|
1770 | 1770 | # a mercurial pattern |
|
1771 | 1771 | res = lambda p: os.path.join( |
|
1772 | 1772 | dest, os.path.basename(util.localpath(p)) |
|
1773 | 1773 | ) |
|
1774 | 1774 | else: |
|
1775 | 1775 | abspfx = pathutil.canonpath(repo.root, cwd, pat) |
|
1776 | 1776 | if len(abspfx) < len(srcs[0][0]): |
|
1777 | 1777 | # A directory. Either the target path contains the last |
|
1778 | 1778 | # component of the source path or it does not. |
|
1779 | 1779 | def evalpath(striplen): |
|
1780 | 1780 | score = 0 |
|
1781 | 1781 | for s in srcs: |
|
1782 | 1782 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
|
1783 | 1783 | if os.path.lexists(t): |
|
1784 | 1784 | score += 1 |
|
1785 | 1785 | return score |
|
1786 | 1786 | |
|
1787 | 1787 | abspfx = util.localpath(abspfx) |
|
1788 | 1788 | striplen = len(abspfx) |
|
1789 | 1789 | if striplen: |
|
1790 | 1790 | striplen += len(pycompat.ossep) |
|
1791 | 1791 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
1792 | 1792 | score = evalpath(striplen) |
|
1793 | 1793 | striplen1 = len(os.path.split(abspfx)[0]) |
|
1794 | 1794 | if striplen1: |
|
1795 | 1795 | striplen1 += len(pycompat.ossep) |
|
1796 | 1796 | if evalpath(striplen1) > score: |
|
1797 | 1797 | striplen = striplen1 |
|
1798 | 1798 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
|
1799 | 1799 | else: |
|
1800 | 1800 | # a file |
|
1801 | 1801 | if destdirexists: |
|
1802 | 1802 | res = lambda p: os.path.join( |
|
1803 | 1803 | dest, os.path.basename(util.localpath(p)) |
|
1804 | 1804 | ) |
|
1805 | 1805 | else: |
|
1806 | 1806 | res = lambda p: dest |
|
1807 | 1807 | return res |
|
1808 | 1808 | |
|
1809 | 1809 | destdirexists = os.path.isdir(dest) and not os.path.islink(dest) |
|
1810 | 1810 | if not destdirexists: |
|
1811 | 1811 | if len(pats) > 1 or matchmod.patkind(pats[0]): |
|
1812 | 1812 | raise error.Abort( |
|
1813 | 1813 | _( |
|
1814 | 1814 | b'with multiple sources, destination must be an ' |
|
1815 | 1815 | b'existing directory' |
|
1816 | 1816 | ) |
|
1817 | 1817 | ) |
|
1818 | 1818 | if util.endswithsep(dest): |
|
1819 | 1819 | raise error.Abort(_(b'destination %s is not a directory') % dest) |
|
1820 | 1820 | |
|
1821 | 1821 | tfn = targetpathfn |
|
1822 | 1822 | if after: |
|
1823 | 1823 | tfn = targetpathafterfn |
|
1824 | 1824 | copylist = [] |
|
1825 | 1825 | for pat in pats: |
|
1826 | 1826 | srcs = walkpat(pat) |
|
1827 | 1827 | if not srcs: |
|
1828 | 1828 | continue |
|
1829 | 1829 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
1830 | 1830 | if not copylist: |
|
1831 | 1831 | raise error.Abort(_(b'no files to copy')) |
|
1832 | 1832 | |
|
1833 | 1833 | errors = 0 |
|
1834 | 1834 | for targetpath, srcs in copylist: |
|
1835 | 1835 | for abssrc, relsrc, exact in srcs: |
|
1836 | 1836 | if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
|
1837 | 1837 | errors += 1 |
|
1838 | 1838 | |
|
1839 | 1839 | return errors != 0 |
|
1840 | 1840 | |
|
1841 | 1841 | |
|
1842 | 1842 | ## facility to let extension process additional data into an import patch |
|
1843 | 1843 | # list of identifier to be executed in order |
|
1844 | 1844 | extrapreimport = [] # run before commit |
|
1845 | 1845 | extrapostimport = [] # run after commit |
|
1846 | 1846 | # mapping from identifier to actual import function |
|
1847 | 1847 | # |
|
1848 | 1848 | # 'preimport' are run before the commit is made and are provided the following |
|
1849 | 1849 | # arguments: |
|
1850 | 1850 | # - repo: the localrepository instance, |
|
1851 | 1851 | # - patchdata: data extracted from patch header (cf m.patch.patchheadermap), |
|
1852 | 1852 | # - extra: the future extra dictionary of the changeset, please mutate it, |
|
1853 | 1853 | # - opts: the import options. |
|
1854 | 1854 | # XXX ideally, we would just pass an ctx ready to be computed, that would allow |
|
1855 | 1855 | # mutation of in memory commit and more. Feel free to rework the code to get |
|
1856 | 1856 | # there. |
|
1857 | 1857 | extrapreimportmap = {} |
|
1858 | 1858 | # 'postimport' are run after the commit is made and are provided the following |
|
1859 | 1859 | # argument: |
|
1860 | 1860 | # - ctx: the changectx created by import. |
|
1861 | 1861 | extrapostimportmap = {} |
|
1862 | 1862 | |
|
1863 | 1863 | |
|
1864 | 1864 | def tryimportone(ui, repo, patchdata, parents, opts, msgs, updatefunc): |
|
1865 | 1865 | """Utility function used by commands.import to import a single patch |
|
1866 | 1866 | |
|
1867 | 1867 | This function is explicitly defined here to help the evolve extension to |
|
1868 | 1868 | wrap this part of the import logic. |
|
1869 | 1869 | |
|
1870 | 1870 | The API is currently a bit ugly because it a simple code translation from |
|
1871 | 1871 | the import command. Feel free to make it better. |
|
1872 | 1872 | |
|
1873 | 1873 | :patchdata: a dictionary containing parsed patch data (such as from |
|
1874 | 1874 | ``patch.extract()``) |
|
1875 | 1875 | :parents: nodes that will be parent of the created commit |
|
1876 | 1876 | :opts: the full dict of option passed to the import command |
|
1877 | 1877 | :msgs: list to save commit message to. |
|
1878 | 1878 | (used in case we need to save it when failing) |
|
1879 | 1879 | :updatefunc: a function that update a repo to a given node |
|
1880 | 1880 | updatefunc(<repo>, <node>) |
|
1881 | 1881 | """ |
|
1882 | 1882 | # avoid cycle context -> subrepo -> cmdutil |
|
1883 | 1883 | from . import context |
|
1884 | 1884 | |
|
1885 | 1885 | tmpname = patchdata.get(b'filename') |
|
1886 | 1886 | message = patchdata.get(b'message') |
|
1887 | 1887 | user = opts.get(b'user') or patchdata.get(b'user') |
|
1888 | 1888 | date = opts.get(b'date') or patchdata.get(b'date') |
|
1889 | 1889 | branch = patchdata.get(b'branch') |
|
1890 | 1890 | nodeid = patchdata.get(b'nodeid') |
|
1891 | 1891 | p1 = patchdata.get(b'p1') |
|
1892 | 1892 | p2 = patchdata.get(b'p2') |
|
1893 | 1893 | |
|
1894 | 1894 | nocommit = opts.get(b'no_commit') |
|
1895 | 1895 | importbranch = opts.get(b'import_branch') |
|
1896 | 1896 | update = not opts.get(b'bypass') |
|
1897 | 1897 | strip = opts[b"strip"] |
|
1898 | 1898 | prefix = opts[b"prefix"] |
|
1899 | 1899 | sim = float(opts.get(b'similarity') or 0) |
|
1900 | 1900 | |
|
1901 | 1901 | if not tmpname: |
|
1902 | 1902 | return None, None, False |
|
1903 | 1903 | |
|
1904 | 1904 | rejects = False |
|
1905 | 1905 | |
|
1906 | 1906 | cmdline_message = logmessage(ui, opts) |
|
1907 | 1907 | if cmdline_message: |
|
1908 | 1908 | # pickup the cmdline msg |
|
1909 | 1909 | message = cmdline_message |
|
1910 | 1910 | elif message: |
|
1911 | 1911 | # pickup the patch msg |
|
1912 | 1912 | message = message.strip() |
|
1913 | 1913 | else: |
|
1914 | 1914 | # launch the editor |
|
1915 | 1915 | message = None |
|
1916 | 1916 | ui.debug(b'message:\n%s\n' % (message or b'')) |
|
1917 | 1917 | |
|
1918 | 1918 | if len(parents) == 1: |
|
1919 | 1919 | parents.append(repo[nullid]) |
|
1920 | 1920 | if opts.get(b'exact'): |
|
1921 | 1921 | if not nodeid or not p1: |
|
1922 | 1922 | raise error.Abort(_(b'not a Mercurial patch')) |
|
1923 | 1923 | p1 = repo[p1] |
|
1924 | 1924 | p2 = repo[p2 or nullid] |
|
1925 | 1925 | elif p2: |
|
1926 | 1926 | try: |
|
1927 | 1927 | p1 = repo[p1] |
|
1928 | 1928 | p2 = repo[p2] |
|
1929 | 1929 | # Without any options, consider p2 only if the |
|
1930 | 1930 | # patch is being applied on top of the recorded |
|
1931 | 1931 | # first parent. |
|
1932 | 1932 | if p1 != parents[0]: |
|
1933 | 1933 | p1 = parents[0] |
|
1934 | 1934 | p2 = repo[nullid] |
|
1935 | 1935 | except error.RepoError: |
|
1936 | 1936 | p1, p2 = parents |
|
1937 | 1937 | if p2.node() == nullid: |
|
1938 | 1938 | ui.warn( |
|
1939 | 1939 | _( |
|
1940 | 1940 | b"warning: import the patch as a normal revision\n" |
|
1941 | 1941 | b"(use --exact to import the patch as a merge)\n" |
|
1942 | 1942 | ) |
|
1943 | 1943 | ) |
|
1944 | 1944 | else: |
|
1945 | 1945 | p1, p2 = parents |
|
1946 | 1946 | |
|
1947 | 1947 | n = None |
|
1948 | 1948 | if update: |
|
1949 | 1949 | if p1 != parents[0]: |
|
1950 | 1950 | updatefunc(repo, p1.node()) |
|
1951 | 1951 | if p2 != parents[1]: |
|
1952 | 1952 | repo.setparents(p1.node(), p2.node()) |
|
1953 | 1953 | |
|
1954 | 1954 | if opts.get(b'exact') or importbranch: |
|
1955 | 1955 | repo.dirstate.setbranch(branch or b'default') |
|
1956 | 1956 | |
|
1957 | 1957 | partial = opts.get(b'partial', False) |
|
1958 | 1958 | files = set() |
|
1959 | 1959 | try: |
|
1960 | 1960 | patch.patch( |
|
1961 | 1961 | ui, |
|
1962 | 1962 | repo, |
|
1963 | 1963 | tmpname, |
|
1964 | 1964 | strip=strip, |
|
1965 | 1965 | prefix=prefix, |
|
1966 | 1966 | files=files, |
|
1967 | 1967 | eolmode=None, |
|
1968 | 1968 | similarity=sim / 100.0, |
|
1969 | 1969 | ) |
|
1970 | 1970 | except error.PatchError as e: |
|
1971 | 1971 | if not partial: |
|
1972 | 1972 | raise error.Abort(pycompat.bytestr(e)) |
|
1973 | 1973 | if partial: |
|
1974 | 1974 | rejects = True |
|
1975 | 1975 | |
|
1976 | 1976 | files = list(files) |
|
1977 | 1977 | if nocommit: |
|
1978 | 1978 | if message: |
|
1979 | 1979 | msgs.append(message) |
|
1980 | 1980 | else: |
|
1981 | 1981 | if opts.get(b'exact') or p2: |
|
1982 | 1982 | # If you got here, you either use --force and know what |
|
1983 | 1983 | # you are doing or used --exact or a merge patch while |
|
1984 | 1984 | # being updated to its first parent. |
|
1985 | 1985 | m = None |
|
1986 | 1986 | else: |
|
1987 | 1987 | m = scmutil.matchfiles(repo, files or []) |
|
1988 | 1988 | editform = mergeeditform(repo[None], b'import.normal') |
|
1989 | 1989 | if opts.get(b'exact'): |
|
1990 | 1990 | editor = None |
|
1991 | 1991 | else: |
|
1992 | 1992 | editor = getcommiteditor( |
|
1993 | 1993 | editform=editform, **pycompat.strkwargs(opts) |
|
1994 | 1994 | ) |
|
1995 | 1995 | extra = {} |
|
1996 | 1996 | for idfunc in extrapreimport: |
|
1997 | 1997 | extrapreimportmap[idfunc](repo, patchdata, extra, opts) |
|
1998 | 1998 | overrides = {} |
|
1999 | 1999 | if partial: |
|
2000 | 2000 | overrides[(b'ui', b'allowemptycommit')] = True |
|
2001 | 2001 | if opts.get(b'secret'): |
|
2002 | 2002 | overrides[(b'phases', b'new-commit')] = b'secret' |
|
2003 | 2003 | with repo.ui.configoverride(overrides, b'import'): |
|
2004 | 2004 | n = repo.commit( |
|
2005 | 2005 | message, user, date, match=m, editor=editor, extra=extra |
|
2006 | 2006 | ) |
|
2007 | 2007 | for idfunc in extrapostimport: |
|
2008 | 2008 | extrapostimportmap[idfunc](repo[n]) |
|
2009 | 2009 | else: |
|
2010 | 2010 | if opts.get(b'exact') or importbranch: |
|
2011 | 2011 | branch = branch or b'default' |
|
2012 | 2012 | else: |
|
2013 | 2013 | branch = p1.branch() |
|
2014 | 2014 | store = patch.filestore() |
|
2015 | 2015 | try: |
|
2016 | 2016 | files = set() |
|
2017 | 2017 | try: |
|
2018 | 2018 | patch.patchrepo( |
|
2019 | 2019 | ui, |
|
2020 | 2020 | repo, |
|
2021 | 2021 | p1, |
|
2022 | 2022 | store, |
|
2023 | 2023 | tmpname, |
|
2024 | 2024 | strip, |
|
2025 | 2025 | prefix, |
|
2026 | 2026 | files, |
|
2027 | 2027 | eolmode=None, |
|
2028 | 2028 | ) |
|
2029 | 2029 | except error.PatchError as e: |
|
2030 | 2030 | raise error.Abort(stringutil.forcebytestr(e)) |
|
2031 | 2031 | if opts.get(b'exact'): |
|
2032 | 2032 | editor = None |
|
2033 | 2033 | else: |
|
2034 | 2034 | editor = getcommiteditor(editform=b'import.bypass') |
|
2035 | 2035 | memctx = context.memctx( |
|
2036 | 2036 | repo, |
|
2037 | 2037 | (p1.node(), p2.node()), |
|
2038 | 2038 | message, |
|
2039 | 2039 | files=files, |
|
2040 | 2040 | filectxfn=store, |
|
2041 | 2041 | user=user, |
|
2042 | 2042 | date=date, |
|
2043 | 2043 | branch=branch, |
|
2044 | 2044 | editor=editor, |
|
2045 | 2045 | ) |
|
2046 | 2046 | |
|
2047 | 2047 | overrides = {} |
|
2048 | 2048 | if opts.get(b'secret'): |
|
2049 | 2049 | overrides[(b'phases', b'new-commit')] = b'secret' |
|
2050 | 2050 | with repo.ui.configoverride(overrides, b'import'): |
|
2051 | 2051 | n = memctx.commit() |
|
2052 | 2052 | finally: |
|
2053 | 2053 | store.close() |
|
2054 | 2054 | if opts.get(b'exact') and nocommit: |
|
2055 | 2055 | # --exact with --no-commit is still useful in that it does merge |
|
2056 | 2056 | # and branch bits |
|
2057 | 2057 | ui.warn(_(b"warning: can't check exact import with --no-commit\n")) |
|
2058 | 2058 | elif opts.get(b'exact') and (not n or hex(n) != nodeid): |
|
2059 | 2059 | raise error.Abort(_(b'patch is damaged or loses information')) |
|
2060 | 2060 | msg = _(b'applied to working directory') |
|
2061 | 2061 | if n: |
|
2062 | 2062 | # i18n: refers to a short changeset id |
|
2063 | 2063 | msg = _(b'created %s') % short(n) |
|
2064 | 2064 | return msg, n, rejects |
|
2065 | 2065 | |
|
2066 | 2066 | |
|
2067 | 2067 | # facility to let extensions include additional data in an exported patch |
|
2068 | 2068 | # list of identifiers to be executed in order |
|
2069 | 2069 | extraexport = [] |
|
2070 | 2070 | # mapping from identifier to actual export function |
|
2071 | 2071 | # function as to return a string to be added to the header or None |
|
2072 | 2072 | # it is given two arguments (sequencenumber, changectx) |
|
2073 | 2073 | extraexportmap = {} |
|
2074 | 2074 | |
|
2075 | 2075 | |
|
2076 | 2076 | def _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts): |
|
2077 | 2077 | node = scmutil.binnode(ctx) |
|
2078 | 2078 | parents = [p.node() for p in ctx.parents() if p] |
|
2079 | 2079 | branch = ctx.branch() |
|
2080 | 2080 | if switch_parent: |
|
2081 | 2081 | parents.reverse() |
|
2082 | 2082 | |
|
2083 | 2083 | if parents: |
|
2084 | 2084 | prev = parents[0] |
|
2085 | 2085 | else: |
|
2086 | 2086 | prev = nullid |
|
2087 | 2087 | |
|
2088 | 2088 | fm.context(ctx=ctx) |
|
2089 | 2089 | fm.plain(b'# HG changeset patch\n') |
|
2090 | 2090 | fm.write(b'user', b'# User %s\n', ctx.user()) |
|
2091 | 2091 | fm.plain(b'# Date %d %d\n' % ctx.date()) |
|
2092 | 2092 | fm.write(b'date', b'# %s\n', fm.formatdate(ctx.date())) |
|
2093 | 2093 | fm.condwrite( |
|
2094 | 2094 | branch and branch != b'default', b'branch', b'# Branch %s\n', branch |
|
2095 | 2095 | ) |
|
2096 | 2096 | fm.write(b'node', b'# Node ID %s\n', hex(node)) |
|
2097 | 2097 | fm.plain(b'# Parent %s\n' % hex(prev)) |
|
2098 | 2098 | if len(parents) > 1: |
|
2099 | 2099 | fm.plain(b'# Parent %s\n' % hex(parents[1])) |
|
2100 | 2100 | fm.data(parents=fm.formatlist(pycompat.maplist(hex, parents), name=b'node')) |
|
2101 | 2101 | |
|
2102 | 2102 | # TODO: redesign extraexportmap function to support formatter |
|
2103 | 2103 | for headerid in extraexport: |
|
2104 | 2104 | header = extraexportmap[headerid](seqno, ctx) |
|
2105 | 2105 | if header is not None: |
|
2106 | 2106 | fm.plain(b'# %s\n' % header) |
|
2107 | 2107 | |
|
2108 | 2108 | fm.write(b'desc', b'%s\n', ctx.description().rstrip()) |
|
2109 | 2109 | fm.plain(b'\n') |
|
2110 | 2110 | |
|
2111 | 2111 | if fm.isplain(): |
|
2112 | 2112 | chunkiter = patch.diffui(repo, prev, node, match, opts=diffopts) |
|
2113 | 2113 | for chunk, label in chunkiter: |
|
2114 | 2114 | fm.plain(chunk, label=label) |
|
2115 | 2115 | else: |
|
2116 | 2116 | chunkiter = patch.diff(repo, prev, node, match, opts=diffopts) |
|
2117 | 2117 | # TODO: make it structured? |
|
2118 | 2118 | fm.data(diff=b''.join(chunkiter)) |
|
2119 | 2119 | |
|
2120 | 2120 | |
|
2121 | 2121 | def _exportfile(repo, revs, fm, dest, switch_parent, diffopts, match): |
|
2122 | 2122 | """Export changesets to stdout or a single file""" |
|
2123 | 2123 | for seqno, rev in enumerate(revs, 1): |
|
2124 | 2124 | ctx = repo[rev] |
|
2125 | 2125 | if not dest.startswith(b'<'): |
|
2126 | 2126 | repo.ui.note(b"%s\n" % dest) |
|
2127 | 2127 | fm.startitem() |
|
2128 | 2128 | _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts) |
|
2129 | 2129 | |
|
2130 | 2130 | |
|
2131 | 2131 | def _exportfntemplate( |
|
2132 | 2132 | repo, revs, basefm, fntemplate, switch_parent, diffopts, match |
|
2133 | 2133 | ): |
|
2134 | 2134 | """Export changesets to possibly multiple files""" |
|
2135 | 2135 | total = len(revs) |
|
2136 | 2136 | revwidth = max(len(str(rev)) for rev in revs) |
|
2137 | 2137 | filemap = util.sortdict() # filename: [(seqno, rev), ...] |
|
2138 | 2138 | |
|
2139 | 2139 | for seqno, rev in enumerate(revs, 1): |
|
2140 | 2140 | ctx = repo[rev] |
|
2141 | 2141 | dest = makefilename( |
|
2142 | 2142 | ctx, fntemplate, total=total, seqno=seqno, revwidth=revwidth |
|
2143 | 2143 | ) |
|
2144 | 2144 | filemap.setdefault(dest, []).append((seqno, rev)) |
|
2145 | 2145 | |
|
2146 | 2146 | for dest in filemap: |
|
2147 | 2147 | with formatter.maybereopen(basefm, dest) as fm: |
|
2148 | 2148 | repo.ui.note(b"%s\n" % dest) |
|
2149 | 2149 | for seqno, rev in filemap[dest]: |
|
2150 | 2150 | fm.startitem() |
|
2151 | 2151 | ctx = repo[rev] |
|
2152 | 2152 | _exportsingle( |
|
2153 | 2153 | repo, ctx, fm, match, switch_parent, seqno, diffopts |
|
2154 | 2154 | ) |
|
2155 | 2155 | |
|
2156 | 2156 | |
|
2157 | 2157 | def _prefetchchangedfiles(repo, revs, match): |
|
2158 | 2158 | allfiles = set() |
|
2159 | 2159 | for rev in revs: |
|
2160 | 2160 | for file in repo[rev].files(): |
|
2161 | 2161 | if not match or match(file): |
|
2162 | 2162 | allfiles.add(file) |
|
2163 | 2163 | match = scmutil.matchfiles(repo, allfiles) |
|
2164 | 2164 | revmatches = [(rev, match) for rev in revs] |
|
2165 | 2165 | scmutil.prefetchfiles(repo, revmatches) |
|
2166 | 2166 | |
|
2167 | 2167 | |
|
2168 | 2168 | def export( |
|
2169 | 2169 | repo, |
|
2170 | 2170 | revs, |
|
2171 | 2171 | basefm, |
|
2172 | 2172 | fntemplate=b'hg-%h.patch', |
|
2173 | 2173 | switch_parent=False, |
|
2174 | 2174 | opts=None, |
|
2175 | 2175 | match=None, |
|
2176 | 2176 | ): |
|
2177 | 2177 | '''export changesets as hg patches |
|
2178 | 2178 | |
|
2179 | 2179 | Args: |
|
2180 | 2180 | repo: The repository from which we're exporting revisions. |
|
2181 | 2181 | revs: A list of revisions to export as revision numbers. |
|
2182 | 2182 | basefm: A formatter to which patches should be written. |
|
2183 | 2183 | fntemplate: An optional string to use for generating patch file names. |
|
2184 | 2184 | switch_parent: If True, show diffs against second parent when not nullid. |
|
2185 | 2185 | Default is false, which always shows diff against p1. |
|
2186 | 2186 | opts: diff options to use for generating the patch. |
|
2187 | 2187 | match: If specified, only export changes to files matching this matcher. |
|
2188 | 2188 | |
|
2189 | 2189 | Returns: |
|
2190 | 2190 | Nothing. |
|
2191 | 2191 | |
|
2192 | 2192 | Side Effect: |
|
2193 | 2193 | "HG Changeset Patch" data is emitted to one of the following |
|
2194 | 2194 | destinations: |
|
2195 | 2195 | fntemplate specified: Each rev is written to a unique file named using |
|
2196 | 2196 | the given template. |
|
2197 | 2197 | Otherwise: All revs will be written to basefm. |
|
2198 | 2198 | ''' |
|
2199 | 2199 | _prefetchchangedfiles(repo, revs, match) |
|
2200 | 2200 | |
|
2201 | 2201 | if not fntemplate: |
|
2202 | 2202 | _exportfile( |
|
2203 | 2203 | repo, revs, basefm, b'<unnamed>', switch_parent, opts, match |
|
2204 | 2204 | ) |
|
2205 | 2205 | else: |
|
2206 | 2206 | _exportfntemplate( |
|
2207 | 2207 | repo, revs, basefm, fntemplate, switch_parent, opts, match |
|
2208 | 2208 | ) |
|
2209 | 2209 | |
|
2210 | 2210 | |
|
2211 | 2211 | def exportfile(repo, revs, fp, switch_parent=False, opts=None, match=None): |
|
2212 | 2212 | """Export changesets to the given file stream""" |
|
2213 | 2213 | _prefetchchangedfiles(repo, revs, match) |
|
2214 | 2214 | |
|
2215 | 2215 | dest = getattr(fp, 'name', b'<unnamed>') |
|
2216 | 2216 | with formatter.formatter(repo.ui, fp, b'export', {}) as fm: |
|
2217 | 2217 | _exportfile(repo, revs, fm, dest, switch_parent, opts, match) |
|
2218 | 2218 | |
|
2219 | 2219 | |
|
2220 | 2220 | def showmarker(fm, marker, index=None): |
|
2221 | 2221 | """utility function to display obsolescence marker in a readable way |
|
2222 | 2222 | |
|
2223 | 2223 | To be used by debug function.""" |
|
2224 | 2224 | if index is not None: |
|
2225 | 2225 | fm.write(b'index', b'%i ', index) |
|
2226 | 2226 | fm.write(b'prednode', b'%s ', hex(marker.prednode())) |
|
2227 | 2227 | succs = marker.succnodes() |
|
2228 | 2228 | fm.condwrite( |
|
2229 | 2229 | succs, |
|
2230 | 2230 | b'succnodes', |
|
2231 | 2231 | b'%s ', |
|
2232 | 2232 | fm.formatlist(map(hex, succs), name=b'node'), |
|
2233 | 2233 | ) |
|
2234 | 2234 | fm.write(b'flag', b'%X ', marker.flags()) |
|
2235 | 2235 | parents = marker.parentnodes() |
|
2236 | 2236 | if parents is not None: |
|
2237 | 2237 | fm.write( |
|
2238 | 2238 | b'parentnodes', |
|
2239 | 2239 | b'{%s} ', |
|
2240 | 2240 | fm.formatlist(map(hex, parents), name=b'node', sep=b', '), |
|
2241 | 2241 | ) |
|
2242 | 2242 | fm.write(b'date', b'(%s) ', fm.formatdate(marker.date())) |
|
2243 | 2243 | meta = marker.metadata().copy() |
|
2244 | 2244 | meta.pop(b'date', None) |
|
2245 | 2245 | smeta = pycompat.rapply(pycompat.maybebytestr, meta) |
|
2246 | 2246 | fm.write( |
|
2247 | 2247 | b'metadata', b'{%s}', fm.formatdict(smeta, fmt=b'%r: %r', sep=b', ') |
|
2248 | 2248 | ) |
|
2249 | 2249 | fm.plain(b'\n') |
|
2250 | 2250 | |
|
2251 | 2251 | |
|
2252 | 2252 | def finddate(ui, repo, date): |
|
2253 | 2253 | """Find the tipmost changeset that matches the given date spec""" |
|
2254 | 2254 | mrevs = repo.revs(b'date(%s)', date) |
|
2255 | 2255 | try: |
|
2256 | 2256 | rev = mrevs.max() |
|
2257 | 2257 | except ValueError: |
|
2258 | 2258 | raise error.Abort(_(b"revision matching date not found")) |
|
2259 | 2259 | |
|
2260 | 2260 | ui.status( |
|
2261 | 2261 | _(b"found revision %d from %s\n") |
|
2262 | 2262 | % (rev, dateutil.datestr(repo[rev].date())) |
|
2263 | 2263 | ) |
|
2264 | 2264 | return b'%d' % rev |
|
2265 | 2265 | |
|
2266 | 2266 | |
|
2267 | 2267 | def add(ui, repo, match, prefix, uipathfn, explicitonly, **opts): |
|
2268 | 2268 | bad = [] |
|
2269 | 2269 | |
|
2270 | 2270 | badfn = lambda x, y: bad.append(x) or match.bad(x, y) |
|
2271 | 2271 | names = [] |
|
2272 | 2272 | wctx = repo[None] |
|
2273 | 2273 | cca = None |
|
2274 | 2274 | abort, warn = scmutil.checkportabilityalert(ui) |
|
2275 | 2275 | if abort or warn: |
|
2276 | 2276 | cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate) |
|
2277 | 2277 | |
|
2278 | 2278 | match = repo.narrowmatch(match, includeexact=True) |
|
2279 | 2279 | badmatch = matchmod.badmatch(match, badfn) |
|
2280 | 2280 | dirstate = repo.dirstate |
|
2281 | 2281 | # We don't want to just call wctx.walk here, since it would return a lot of |
|
2282 | 2282 | # clean files, which we aren't interested in and takes time. |
|
2283 | 2283 | for f in sorted( |
|
2284 | 2284 | dirstate.walk( |
|
2285 | 2285 | badmatch, |
|
2286 | 2286 | subrepos=sorted(wctx.substate), |
|
2287 | 2287 | unknown=True, |
|
2288 | 2288 | ignored=False, |
|
2289 | 2289 | full=False, |
|
2290 | 2290 | ) |
|
2291 | 2291 | ): |
|
2292 | 2292 | exact = match.exact(f) |
|
2293 | 2293 | if exact or not explicitonly and f not in wctx and repo.wvfs.lexists(f): |
|
2294 | 2294 | if cca: |
|
2295 | 2295 | cca(f) |
|
2296 | 2296 | names.append(f) |
|
2297 | 2297 | if ui.verbose or not exact: |
|
2298 | 2298 | ui.status( |
|
2299 | 2299 | _(b'adding %s\n') % uipathfn(f), label=b'ui.addremove.added' |
|
2300 | 2300 | ) |
|
2301 | 2301 | |
|
2302 | 2302 | for subpath in sorted(wctx.substate): |
|
2303 | 2303 | sub = wctx.sub(subpath) |
|
2304 | 2304 | try: |
|
2305 | 2305 | submatch = matchmod.subdirmatcher(subpath, match) |
|
2306 | 2306 | subprefix = repo.wvfs.reljoin(prefix, subpath) |
|
2307 | 2307 | subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
|
2308 | 2308 | if opts.get('subrepos'): |
|
2309 | 2309 | bad.extend( |
|
2310 | 2310 | sub.add(ui, submatch, subprefix, subuipathfn, False, **opts) |
|
2311 | 2311 | ) |
|
2312 | 2312 | else: |
|
2313 | 2313 | bad.extend( |
|
2314 | 2314 | sub.add(ui, submatch, subprefix, subuipathfn, True, **opts) |
|
2315 | 2315 | ) |
|
2316 | 2316 | except error.LookupError: |
|
2317 | 2317 | ui.status( |
|
2318 | 2318 | _(b"skipping missing subrepository: %s\n") % uipathfn(subpath) |
|
2319 | 2319 | ) |
|
2320 | 2320 | |
|
2321 | 2321 | if not opts.get('dry_run'): |
|
2322 | 2322 | rejected = wctx.add(names, prefix) |
|
2323 | 2323 | bad.extend(f for f in rejected if f in match.files()) |
|
2324 | 2324 | return bad |
|
2325 | 2325 | |
|
2326 | 2326 | |
|
2327 | 2327 | def addwebdirpath(repo, serverpath, webconf): |
|
2328 | 2328 | webconf[serverpath] = repo.root |
|
2329 | 2329 | repo.ui.debug(b'adding %s = %s\n' % (serverpath, repo.root)) |
|
2330 | 2330 | |
|
2331 | 2331 | for r in repo.revs(b'filelog("path:.hgsub")'): |
|
2332 | 2332 | ctx = repo[r] |
|
2333 | 2333 | for subpath in ctx.substate: |
|
2334 | 2334 | ctx.sub(subpath).addwebdirpath(serverpath, webconf) |
|
2335 | 2335 | |
|
2336 | 2336 | |
|
2337 | 2337 | def forget( |
|
2338 | 2338 | ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive |
|
2339 | 2339 | ): |
|
2340 | 2340 | if dryrun and interactive: |
|
2341 | 2341 | raise error.Abort(_(b"cannot specify both --dry-run and --interactive")) |
|
2342 | 2342 | bad = [] |
|
2343 | 2343 | badfn = lambda x, y: bad.append(x) or match.bad(x, y) |
|
2344 | 2344 | wctx = repo[None] |
|
2345 | 2345 | forgot = [] |
|
2346 | 2346 | |
|
2347 | 2347 | s = repo.status(match=matchmod.badmatch(match, badfn), clean=True) |
|
2348 | 2348 | forget = sorted(s.modified + s.added + s.deleted + s.clean) |
|
2349 | 2349 | if explicitonly: |
|
2350 | 2350 | forget = [f for f in forget if match.exact(f)] |
|
2351 | 2351 | |
|
2352 | 2352 | for subpath in sorted(wctx.substate): |
|
2353 | 2353 | sub = wctx.sub(subpath) |
|
2354 | 2354 | submatch = matchmod.subdirmatcher(subpath, match) |
|
2355 | 2355 | subprefix = repo.wvfs.reljoin(prefix, subpath) |
|
2356 | 2356 | subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
|
2357 | 2357 | try: |
|
2358 | 2358 | subbad, subforgot = sub.forget( |
|
2359 | 2359 | submatch, |
|
2360 | 2360 | subprefix, |
|
2361 | 2361 | subuipathfn, |
|
2362 | 2362 | dryrun=dryrun, |
|
2363 | 2363 | interactive=interactive, |
|
2364 | 2364 | ) |
|
2365 | 2365 | bad.extend([subpath + b'/' + f for f in subbad]) |
|
2366 | 2366 | forgot.extend([subpath + b'/' + f for f in subforgot]) |
|
2367 | 2367 | except error.LookupError: |
|
2368 | 2368 | ui.status( |
|
2369 | 2369 | _(b"skipping missing subrepository: %s\n") % uipathfn(subpath) |
|
2370 | 2370 | ) |
|
2371 | 2371 | |
|
2372 | 2372 | if not explicitonly: |
|
2373 | 2373 | for f in match.files(): |
|
2374 | 2374 | if f not in repo.dirstate and not repo.wvfs.isdir(f): |
|
2375 | 2375 | if f not in forgot: |
|
2376 | 2376 | if repo.wvfs.exists(f): |
|
2377 | 2377 | # Don't complain if the exact case match wasn't given. |
|
2378 | 2378 | # But don't do this until after checking 'forgot', so |
|
2379 | 2379 | # that subrepo files aren't normalized, and this op is |
|
2380 | 2380 | # purely from data cached by the status walk above. |
|
2381 | 2381 | if repo.dirstate.normalize(f) in repo.dirstate: |
|
2382 | 2382 | continue |
|
2383 | 2383 | ui.warn( |
|
2384 | 2384 | _( |
|
2385 | 2385 | b'not removing %s: ' |
|
2386 | 2386 | b'file is already untracked\n' |
|
2387 | 2387 | ) |
|
2388 | 2388 | % uipathfn(f) |
|
2389 | 2389 | ) |
|
2390 | 2390 | bad.append(f) |
|
2391 | 2391 | |
|
2392 | 2392 | if interactive: |
|
2393 | 2393 | responses = _( |
|
2394 | 2394 | b'[Ynsa?]' |
|
2395 | 2395 | b'$$ &Yes, forget this file' |
|
2396 | 2396 | b'$$ &No, skip this file' |
|
2397 | 2397 | b'$$ &Skip remaining files' |
|
2398 | 2398 | b'$$ Include &all remaining files' |
|
2399 | 2399 | b'$$ &? (display help)' |
|
2400 | 2400 | ) |
|
2401 | 2401 | for filename in forget[:]: |
|
2402 | 2402 | r = ui.promptchoice( |
|
2403 | 2403 | _(b'forget %s %s') % (uipathfn(filename), responses) |
|
2404 | 2404 | ) |
|
2405 | 2405 | if r == 4: # ? |
|
2406 | 2406 | while r == 4: |
|
2407 | 2407 | for c, t in ui.extractchoices(responses)[1]: |
|
2408 | 2408 | ui.write(b'%s - %s\n' % (c, encoding.lower(t))) |
|
2409 | 2409 | r = ui.promptchoice( |
|
2410 | 2410 | _(b'forget %s %s') % (uipathfn(filename), responses) |
|
2411 | 2411 | ) |
|
2412 | 2412 | if r == 0: # yes |
|
2413 | 2413 | continue |
|
2414 | 2414 | elif r == 1: # no |
|
2415 | 2415 | forget.remove(filename) |
|
2416 | 2416 | elif r == 2: # Skip |
|
2417 | 2417 | fnindex = forget.index(filename) |
|
2418 | 2418 | del forget[fnindex:] |
|
2419 | 2419 | break |
|
2420 | 2420 | elif r == 3: # All |
|
2421 | 2421 | break |
|
2422 | 2422 | |
|
2423 | 2423 | for f in forget: |
|
2424 | 2424 | if ui.verbose or not match.exact(f) or interactive: |
|
2425 | 2425 | ui.status( |
|
2426 | 2426 | _(b'removing %s\n') % uipathfn(f), label=b'ui.addremove.removed' |
|
2427 | 2427 | ) |
|
2428 | 2428 | |
|
2429 | 2429 | if not dryrun: |
|
2430 | 2430 | rejected = wctx.forget(forget, prefix) |
|
2431 | 2431 | bad.extend(f for f in rejected if f in match.files()) |
|
2432 | 2432 | forgot.extend(f for f in forget if f not in rejected) |
|
2433 | 2433 | return bad, forgot |
|
2434 | 2434 | |
|
2435 | 2435 | |
|
2436 | 2436 | def files(ui, ctx, m, uipathfn, fm, fmt, subrepos): |
|
2437 | 2437 | ret = 1 |
|
2438 | 2438 | |
|
2439 | 2439 | needsfctx = ui.verbose or {b'size', b'flags'} & fm.datahint() |
|
2440 | 2440 | if fm.isplain() and not needsfctx: |
|
2441 | 2441 | # Fast path. The speed-up comes from skipping the formatter, and batching |
|
2442 | 2442 | # calls to ui.write. |
|
2443 | 2443 | buf = [] |
|
2444 | 2444 | for f in ctx.matches(m): |
|
2445 | 2445 | buf.append(fmt % uipathfn(f)) |
|
2446 | 2446 | if len(buf) > 100: |
|
2447 | 2447 | ui.write(b''.join(buf)) |
|
2448 | 2448 | del buf[:] |
|
2449 | 2449 | ret = 0 |
|
2450 | 2450 | if buf: |
|
2451 | 2451 | ui.write(b''.join(buf)) |
|
2452 | 2452 | else: |
|
2453 | 2453 | for f in ctx.matches(m): |
|
2454 | 2454 | fm.startitem() |
|
2455 | 2455 | fm.context(ctx=ctx) |
|
2456 | 2456 | if needsfctx: |
|
2457 | 2457 | fc = ctx[f] |
|
2458 | 2458 | fm.write(b'size flags', b'% 10d % 1s ', fc.size(), fc.flags()) |
|
2459 | 2459 | fm.data(path=f) |
|
2460 | 2460 | fm.plain(fmt % uipathfn(f)) |
|
2461 | 2461 | ret = 0 |
|
2462 | 2462 | |
|
2463 | 2463 | for subpath in sorted(ctx.substate): |
|
2464 | 2464 | submatch = matchmod.subdirmatcher(subpath, m) |
|
2465 | 2465 | subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
|
2466 | 2466 | if subrepos or m.exact(subpath) or any(submatch.files()): |
|
2467 | 2467 | sub = ctx.sub(subpath) |
|
2468 | 2468 | try: |
|
2469 | 2469 | recurse = m.exact(subpath) or subrepos |
|
2470 | 2470 | if ( |
|
2471 | 2471 | sub.printfiles(ui, submatch, subuipathfn, fm, fmt, recurse) |
|
2472 | 2472 | == 0 |
|
2473 | 2473 | ): |
|
2474 | 2474 | ret = 0 |
|
2475 | 2475 | except error.LookupError: |
|
2476 | 2476 | ui.status( |
|
2477 | 2477 | _(b"skipping missing subrepository: %s\n") |
|
2478 | 2478 | % uipathfn(subpath) |
|
2479 | 2479 | ) |
|
2480 | 2480 | |
|
2481 | 2481 | return ret |
|
2482 | 2482 | |
|
2483 | 2483 | |
|
2484 | 2484 | def remove( |
|
2485 | 2485 | ui, repo, m, prefix, uipathfn, after, force, subrepos, dryrun, warnings=None |
|
2486 | 2486 | ): |
|
2487 | 2487 | ret = 0 |
|
2488 | 2488 | s = repo.status(match=m, clean=True) |
|
2489 | 2489 | modified, added, deleted, clean = s.modified, s.added, s.deleted, s.clean |
|
2490 | 2490 | |
|
2491 | 2491 | wctx = repo[None] |
|
2492 | 2492 | |
|
2493 | 2493 | if warnings is None: |
|
2494 | 2494 | warnings = [] |
|
2495 | 2495 | warn = True |
|
2496 | 2496 | else: |
|
2497 | 2497 | warn = False |
|
2498 | 2498 | |
|
2499 | 2499 | subs = sorted(wctx.substate) |
|
2500 | 2500 | progress = ui.makeprogress( |
|
2501 | 2501 | _(b'searching'), total=len(subs), unit=_(b'subrepos') |
|
2502 | 2502 | ) |
|
2503 | 2503 | for subpath in subs: |
|
2504 | 2504 | submatch = matchmod.subdirmatcher(subpath, m) |
|
2505 | 2505 | subprefix = repo.wvfs.reljoin(prefix, subpath) |
|
2506 | 2506 | subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
|
2507 | 2507 | if subrepos or m.exact(subpath) or any(submatch.files()): |
|
2508 | 2508 | progress.increment() |
|
2509 | 2509 | sub = wctx.sub(subpath) |
|
2510 | 2510 | try: |
|
2511 | 2511 | if sub.removefiles( |
|
2512 | 2512 | submatch, |
|
2513 | 2513 | subprefix, |
|
2514 | 2514 | subuipathfn, |
|
2515 | 2515 | after, |
|
2516 | 2516 | force, |
|
2517 | 2517 | subrepos, |
|
2518 | 2518 | dryrun, |
|
2519 | 2519 | warnings, |
|
2520 | 2520 | ): |
|
2521 | 2521 | ret = 1 |
|
2522 | 2522 | except error.LookupError: |
|
2523 | 2523 | warnings.append( |
|
2524 | 2524 | _(b"skipping missing subrepository: %s\n") |
|
2525 | 2525 | % uipathfn(subpath) |
|
2526 | 2526 | ) |
|
2527 | 2527 | progress.complete() |
|
2528 | 2528 | |
|
2529 | 2529 | # warn about failure to delete explicit files/dirs |
|
2530 | 2530 | deleteddirs = pathutil.dirs(deleted) |
|
2531 | 2531 | files = m.files() |
|
2532 | 2532 | progress = ui.makeprogress( |
|
2533 | 2533 | _(b'deleting'), total=len(files), unit=_(b'files') |
|
2534 | 2534 | ) |
|
2535 | 2535 | for f in files: |
|
2536 | 2536 | |
|
2537 | 2537 | def insubrepo(): |
|
2538 | 2538 | for subpath in wctx.substate: |
|
2539 | 2539 | if f.startswith(subpath + b'/'): |
|
2540 | 2540 | return True |
|
2541 | 2541 | return False |
|
2542 | 2542 | |
|
2543 | 2543 | progress.increment() |
|
2544 | 2544 | isdir = f in deleteddirs or wctx.hasdir(f) |
|
2545 | 2545 | if f in repo.dirstate or isdir or f == b'.' or insubrepo() or f in subs: |
|
2546 | 2546 | continue |
|
2547 | 2547 | |
|
2548 | 2548 | if repo.wvfs.exists(f): |
|
2549 | 2549 | if repo.wvfs.isdir(f): |
|
2550 | 2550 | warnings.append( |
|
2551 | 2551 | _(b'not removing %s: no tracked files\n') % uipathfn(f) |
|
2552 | 2552 | ) |
|
2553 | 2553 | else: |
|
2554 | 2554 | warnings.append( |
|
2555 | 2555 | _(b'not removing %s: file is untracked\n') % uipathfn(f) |
|
2556 | 2556 | ) |
|
2557 | 2557 | # missing files will generate a warning elsewhere |
|
2558 | 2558 | ret = 1 |
|
2559 | 2559 | progress.complete() |
|
2560 | 2560 | |
|
2561 | 2561 | if force: |
|
2562 | 2562 | list = modified + deleted + clean + added |
|
2563 | 2563 | elif after: |
|
2564 | 2564 | list = deleted |
|
2565 | 2565 | remaining = modified + added + clean |
|
2566 | 2566 | progress = ui.makeprogress( |
|
2567 | 2567 | _(b'skipping'), total=len(remaining), unit=_(b'files') |
|
2568 | 2568 | ) |
|
2569 | 2569 | for f in remaining: |
|
2570 | 2570 | progress.increment() |
|
2571 | 2571 | if ui.verbose or (f in files): |
|
2572 | 2572 | warnings.append( |
|
2573 | 2573 | _(b'not removing %s: file still exists\n') % uipathfn(f) |
|
2574 | 2574 | ) |
|
2575 | 2575 | ret = 1 |
|
2576 | 2576 | progress.complete() |
|
2577 | 2577 | else: |
|
2578 | 2578 | list = deleted + clean |
|
2579 | 2579 | progress = ui.makeprogress( |
|
2580 | 2580 | _(b'skipping'), total=(len(modified) + len(added)), unit=_(b'files') |
|
2581 | 2581 | ) |
|
2582 | 2582 | for f in modified: |
|
2583 | 2583 | progress.increment() |
|
2584 | 2584 | warnings.append( |
|
2585 | 2585 | _( |
|
2586 | 2586 | b'not removing %s: file is modified (use -f' |
|
2587 | 2587 | b' to force removal)\n' |
|
2588 | 2588 | ) |
|
2589 | 2589 | % uipathfn(f) |
|
2590 | 2590 | ) |
|
2591 | 2591 | ret = 1 |
|
2592 | 2592 | for f in added: |
|
2593 | 2593 | progress.increment() |
|
2594 | 2594 | warnings.append( |
|
2595 | 2595 | _( |
|
2596 | 2596 | b"not removing %s: file has been marked for add" |
|
2597 | 2597 | b" (use 'hg forget' to undo add)\n" |
|
2598 | 2598 | ) |
|
2599 | 2599 | % uipathfn(f) |
|
2600 | 2600 | ) |
|
2601 | 2601 | ret = 1 |
|
2602 | 2602 | progress.complete() |
|
2603 | 2603 | |
|
2604 | 2604 | list = sorted(list) |
|
2605 | 2605 | progress = ui.makeprogress( |
|
2606 | 2606 | _(b'deleting'), total=len(list), unit=_(b'files') |
|
2607 | 2607 | ) |
|
2608 | 2608 | for f in list: |
|
2609 | 2609 | if ui.verbose or not m.exact(f): |
|
2610 | 2610 | progress.increment() |
|
2611 | 2611 | ui.status( |
|
2612 | 2612 | _(b'removing %s\n') % uipathfn(f), label=b'ui.addremove.removed' |
|
2613 | 2613 | ) |
|
2614 | 2614 | progress.complete() |
|
2615 | 2615 | |
|
2616 | 2616 | if not dryrun: |
|
2617 | 2617 | with repo.wlock(): |
|
2618 | 2618 | if not after: |
|
2619 | 2619 | for f in list: |
|
2620 | 2620 | if f in added: |
|
2621 | 2621 | continue # we never unlink added files on remove |
|
2622 | 2622 | rmdir = repo.ui.configbool( |
|
2623 | 2623 | b'experimental', b'removeemptydirs' |
|
2624 | 2624 | ) |
|
2625 | 2625 | repo.wvfs.unlinkpath(f, ignoremissing=True, rmdir=rmdir) |
|
2626 | 2626 | repo[None].forget(list) |
|
2627 | 2627 | |
|
2628 | 2628 | if warn: |
|
2629 | 2629 | for warning in warnings: |
|
2630 | 2630 | ui.warn(warning) |
|
2631 | 2631 | |
|
2632 | 2632 | return ret |
|
2633 | 2633 | |
|
2634 | 2634 | |
|
2635 | 2635 | def _catfmtneedsdata(fm): |
|
2636 | 2636 | return not fm.datahint() or b'data' in fm.datahint() |
|
2637 | 2637 | |
|
2638 | 2638 | |
|
2639 | 2639 | def _updatecatformatter(fm, ctx, matcher, path, decode): |
|
2640 | 2640 | """Hook for adding data to the formatter used by ``hg cat``. |
|
2641 | 2641 | |
|
2642 | 2642 | Extensions (e.g., lfs) can wrap this to inject keywords/data, but must call |
|
2643 | 2643 | this method first.""" |
|
2644 | 2644 | |
|
2645 | 2645 | # data() can be expensive to fetch (e.g. lfs), so don't fetch it if it |
|
2646 | 2646 | # wasn't requested. |
|
2647 | 2647 | data = b'' |
|
2648 | 2648 | if _catfmtneedsdata(fm): |
|
2649 | 2649 | data = ctx[path].data() |
|
2650 | 2650 | if decode: |
|
2651 | 2651 | data = ctx.repo().wwritedata(path, data) |
|
2652 | 2652 | fm.startitem() |
|
2653 | 2653 | fm.context(ctx=ctx) |
|
2654 | 2654 | fm.write(b'data', b'%s', data) |
|
2655 | 2655 | fm.data(path=path) |
|
2656 | 2656 | |
|
2657 | 2657 | |
|
2658 | 2658 | def cat(ui, repo, ctx, matcher, basefm, fntemplate, prefix, **opts): |
|
2659 | 2659 | err = 1 |
|
2660 | 2660 | opts = pycompat.byteskwargs(opts) |
|
2661 | 2661 | |
|
2662 | 2662 | def write(path): |
|
2663 | 2663 | filename = None |
|
2664 | 2664 | if fntemplate: |
|
2665 | 2665 | filename = makefilename( |
|
2666 | 2666 | ctx, fntemplate, pathname=os.path.join(prefix, path) |
|
2667 | 2667 | ) |
|
2668 | 2668 | # attempt to create the directory if it does not already exist |
|
2669 | 2669 | try: |
|
2670 | 2670 | os.makedirs(os.path.dirname(filename)) |
|
2671 | 2671 | except OSError: |
|
2672 | 2672 | pass |
|
2673 | 2673 | with formatter.maybereopen(basefm, filename) as fm: |
|
2674 | 2674 | _updatecatformatter(fm, ctx, matcher, path, opts.get(b'decode')) |
|
2675 | 2675 | |
|
2676 | 2676 | # Automation often uses hg cat on single files, so special case it |
|
2677 | 2677 | # for performance to avoid the cost of parsing the manifest. |
|
2678 | 2678 | if len(matcher.files()) == 1 and not matcher.anypats(): |
|
2679 | 2679 | file = matcher.files()[0] |
|
2680 | 2680 | mfl = repo.manifestlog |
|
2681 | 2681 | mfnode = ctx.manifestnode() |
|
2682 | 2682 | try: |
|
2683 | 2683 | if mfnode and mfl[mfnode].find(file)[0]: |
|
2684 | 2684 | if _catfmtneedsdata(basefm): |
|
2685 | 2685 | scmutil.prefetchfiles(repo, [(ctx.rev(), matcher)]) |
|
2686 | 2686 | write(file) |
|
2687 | 2687 | return 0 |
|
2688 | 2688 | except KeyError: |
|
2689 | 2689 | pass |
|
2690 | 2690 | |
|
2691 | 2691 | if _catfmtneedsdata(basefm): |
|
2692 | 2692 | scmutil.prefetchfiles(repo, [(ctx.rev(), matcher)]) |
|
2693 | 2693 | |
|
2694 | 2694 | for abs in ctx.walk(matcher): |
|
2695 | 2695 | write(abs) |
|
2696 | 2696 | err = 0 |
|
2697 | 2697 | |
|
2698 | 2698 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
|
2699 | 2699 | for subpath in sorted(ctx.substate): |
|
2700 | 2700 | sub = ctx.sub(subpath) |
|
2701 | 2701 | try: |
|
2702 | 2702 | submatch = matchmod.subdirmatcher(subpath, matcher) |
|
2703 | 2703 | subprefix = os.path.join(prefix, subpath) |
|
2704 | 2704 | if not sub.cat( |
|
2705 | 2705 | submatch, |
|
2706 | 2706 | basefm, |
|
2707 | 2707 | fntemplate, |
|
2708 | 2708 | subprefix, |
|
2709 | 2709 | **pycompat.strkwargs(opts) |
|
2710 | 2710 | ): |
|
2711 | 2711 | err = 0 |
|
2712 | 2712 | except error.RepoLookupError: |
|
2713 | 2713 | ui.status( |
|
2714 | 2714 | _(b"skipping missing subrepository: %s\n") % uipathfn(subpath) |
|
2715 | 2715 | ) |
|
2716 | 2716 | |
|
2717 | 2717 | return err |
|
2718 | 2718 | |
|
2719 | 2719 | |
|
2720 | 2720 | def commit(ui, repo, commitfunc, pats, opts): |
|
2721 | 2721 | '''commit the specified files or all outstanding changes''' |
|
2722 | 2722 | date = opts.get(b'date') |
|
2723 | 2723 | if date: |
|
2724 | 2724 | opts[b'date'] = dateutil.parsedate(date) |
|
2725 | 2725 | message = logmessage(ui, opts) |
|
2726 | 2726 | matcher = scmutil.match(repo[None], pats, opts) |
|
2727 | 2727 | |
|
2728 | 2728 | dsguard = None |
|
2729 | 2729 | # extract addremove carefully -- this function can be called from a command |
|
2730 | 2730 | # that doesn't support addremove |
|
2731 | 2731 | if opts.get(b'addremove'): |
|
2732 | 2732 | dsguard = dirstateguard.dirstateguard(repo, b'commit') |
|
2733 | 2733 | with dsguard or util.nullcontextmanager(): |
|
2734 | 2734 | if dsguard: |
|
2735 | 2735 | relative = scmutil.anypats(pats, opts) |
|
2736 | 2736 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=relative) |
|
2737 | 2737 | if scmutil.addremove(repo, matcher, b"", uipathfn, opts) != 0: |
|
2738 | 2738 | raise error.Abort( |
|
2739 | 2739 | _(b"failed to mark all new/missing files as added/removed") |
|
2740 | 2740 | ) |
|
2741 | 2741 | |
|
2742 | 2742 | return commitfunc(ui, repo, message, matcher, opts) |
|
2743 | 2743 | |
|
2744 | 2744 | |
|
2745 | 2745 | def samefile(f, ctx1, ctx2): |
|
2746 | 2746 | if f in ctx1.manifest(): |
|
2747 | 2747 | a = ctx1.filectx(f) |
|
2748 | 2748 | if f in ctx2.manifest(): |
|
2749 | 2749 | b = ctx2.filectx(f) |
|
2750 | 2750 | return not a.cmp(b) and a.flags() == b.flags() |
|
2751 | 2751 | else: |
|
2752 | 2752 | return False |
|
2753 | 2753 | else: |
|
2754 | 2754 | return f not in ctx2.manifest() |
|
2755 | 2755 | |
|
2756 | 2756 | |
|
2757 | 2757 | def amend(ui, repo, old, extra, pats, opts): |
|
2758 | 2758 | # avoid cycle context -> subrepo -> cmdutil |
|
2759 | 2759 | from . import context |
|
2760 | 2760 | |
|
2761 | 2761 | # amend will reuse the existing user if not specified, but the obsolete |
|
2762 | 2762 | # marker creation requires that the current user's name is specified. |
|
2763 | 2763 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
2764 | 2764 | ui.username() # raise exception if username not set |
|
2765 | 2765 | |
|
2766 | 2766 | ui.note(_(b'amending changeset %s\n') % old) |
|
2767 | 2767 | base = old.p1() |
|
2768 | 2768 | |
|
2769 | 2769 | with repo.wlock(), repo.lock(), repo.transaction(b'amend'): |
|
2770 | 2770 | # Participating changesets: |
|
2771 | 2771 | # |
|
2772 | 2772 | # wctx o - workingctx that contains changes from working copy |
|
2773 | 2773 | # | to go into amending commit |
|
2774 | 2774 | # | |
|
2775 | 2775 | # old o - changeset to amend |
|
2776 | 2776 | # | |
|
2777 | 2777 | # base o - first parent of the changeset to amend |
|
2778 | 2778 | wctx = repo[None] |
|
2779 | 2779 | |
|
2780 | 2780 | # Copy to avoid mutating input |
|
2781 | 2781 | extra = extra.copy() |
|
2782 | 2782 | # Update extra dict from amended commit (e.g. to preserve graft |
|
2783 | 2783 | # source) |
|
2784 | 2784 | extra.update(old.extra()) |
|
2785 | 2785 | |
|
2786 | 2786 | # Also update it from the from the wctx |
|
2787 | 2787 | extra.update(wctx.extra()) |
|
2788 | 2788 | |
|
2789 | 2789 | # date-only change should be ignored? |
|
2790 | 2790 | datemaydiffer = resolvecommitoptions(ui, opts) |
|
2791 | 2791 | |
|
2792 | 2792 | date = old.date() |
|
2793 | 2793 | if opts.get(b'date'): |
|
2794 | 2794 | date = dateutil.parsedate(opts.get(b'date')) |
|
2795 | 2795 | user = opts.get(b'user') or old.user() |
|
2796 | 2796 | |
|
2797 | 2797 | if len(old.parents()) > 1: |
|
2798 | 2798 | # ctx.files() isn't reliable for merges, so fall back to the |
|
2799 | 2799 | # slower repo.status() method |
|
2800 | 2800 | st = base.status(old) |
|
2801 | 2801 | files = set(st.modified) | set(st.added) | set(st.removed) |
|
2802 | 2802 | else: |
|
2803 | 2803 | files = set(old.files()) |
|
2804 | 2804 | |
|
2805 | 2805 | # add/remove the files to the working copy if the "addremove" option |
|
2806 | 2806 | # was specified. |
|
2807 | 2807 | matcher = scmutil.match(wctx, pats, opts) |
|
2808 | 2808 | relative = scmutil.anypats(pats, opts) |
|
2809 | 2809 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=relative) |
|
2810 | 2810 | if opts.get(b'addremove') and scmutil.addremove( |
|
2811 | 2811 | repo, matcher, b"", uipathfn, opts |
|
2812 | 2812 | ): |
|
2813 | 2813 | raise error.Abort( |
|
2814 | 2814 | _(b"failed to mark all new/missing files as added/removed") |
|
2815 | 2815 | ) |
|
2816 | 2816 | |
|
2817 | 2817 | # Check subrepos. This depends on in-place wctx._status update in |
|
2818 | 2818 | # subrepo.precommit(). To minimize the risk of this hack, we do |
|
2819 | 2819 | # nothing if .hgsub does not exist. |
|
2820 | 2820 | if b'.hgsub' in wctx or b'.hgsub' in old: |
|
2821 | 2821 | subs, commitsubs, newsubstate = subrepoutil.precommit( |
|
2822 | 2822 | ui, wctx, wctx._status, matcher |
|
2823 | 2823 | ) |
|
2824 | 2824 | # amend should abort if commitsubrepos is enabled |
|
2825 | 2825 | assert not commitsubs |
|
2826 | 2826 | if subs: |
|
2827 | 2827 | subrepoutil.writestate(repo, newsubstate) |
|
2828 | 2828 | |
|
2829 | 2829 | ms = mergestatemod.mergestate.read(repo) |
|
2830 | 2830 | mergeutil.checkunresolved(ms) |
|
2831 | 2831 | |
|
2832 | 2832 | filestoamend = {f for f in wctx.files() if matcher(f)} |
|
2833 | 2833 | |
|
2834 | 2834 | changes = len(filestoamend) > 0 |
|
2835 | 2835 | if changes: |
|
2836 | 2836 | # Recompute copies (avoid recording a -> b -> a) |
|
2837 | 2837 | copied = copies.pathcopies(base, wctx, matcher) |
|
2838 | 2838 | if old.p2: |
|
2839 | 2839 | copied.update(copies.pathcopies(old.p2(), wctx, matcher)) |
|
2840 | 2840 | |
|
2841 | 2841 | # Prune files which were reverted by the updates: if old |
|
2842 | 2842 | # introduced file X and the file was renamed in the working |
|
2843 | 2843 | # copy, then those two files are the same and |
|
2844 | 2844 | # we can discard X from our list of files. Likewise if X |
|
2845 | 2845 | # was removed, it's no longer relevant. If X is missing (aka |
|
2846 | 2846 | # deleted), old X must be preserved. |
|
2847 | 2847 | files.update(filestoamend) |
|
2848 | 2848 | files = [ |
|
2849 | 2849 | f |
|
2850 | 2850 | for f in files |
|
2851 | 2851 | if (f not in filestoamend or not samefile(f, wctx, base)) |
|
2852 | 2852 | ] |
|
2853 | 2853 | |
|
2854 | 2854 | def filectxfn(repo, ctx_, path): |
|
2855 | 2855 | try: |
|
2856 | 2856 | # If the file being considered is not amongst the files |
|
2857 | 2857 | # to be amended, we should return the file context from the |
|
2858 | 2858 | # old changeset. This avoids issues when only some files in |
|
2859 | 2859 | # the working copy are being amended but there are also |
|
2860 | 2860 | # changes to other files from the old changeset. |
|
2861 | 2861 | if path not in filestoamend: |
|
2862 | 2862 | return old.filectx(path) |
|
2863 | 2863 | |
|
2864 | 2864 | # Return None for removed files. |
|
2865 | 2865 | if path in wctx.removed(): |
|
2866 | 2866 | return None |
|
2867 | 2867 | |
|
2868 | 2868 | fctx = wctx[path] |
|
2869 | 2869 | flags = fctx.flags() |
|
2870 | 2870 | mctx = context.memfilectx( |
|
2871 | 2871 | repo, |
|
2872 | 2872 | ctx_, |
|
2873 | 2873 | fctx.path(), |
|
2874 | 2874 | fctx.data(), |
|
2875 | 2875 | islink=b'l' in flags, |
|
2876 | 2876 | isexec=b'x' in flags, |
|
2877 | 2877 | copysource=copied.get(path), |
|
2878 | 2878 | ) |
|
2879 | 2879 | return mctx |
|
2880 | 2880 | except KeyError: |
|
2881 | 2881 | return None |
|
2882 | 2882 | |
|
2883 | 2883 | else: |
|
2884 | 2884 | ui.note(_(b'copying changeset %s to %s\n') % (old, base)) |
|
2885 | 2885 | |
|
2886 | 2886 | # Use version of files as in the old cset |
|
2887 | 2887 | def filectxfn(repo, ctx_, path): |
|
2888 | 2888 | try: |
|
2889 | 2889 | return old.filectx(path) |
|
2890 | 2890 | except KeyError: |
|
2891 | 2891 | return None |
|
2892 | 2892 | |
|
2893 | 2893 | # See if we got a message from -m or -l, if not, open the editor with |
|
2894 | 2894 | # the message of the changeset to amend. |
|
2895 | 2895 | message = logmessage(ui, opts) |
|
2896 | 2896 | |
|
2897 | 2897 | editform = mergeeditform(old, b'commit.amend') |
|
2898 | 2898 | |
|
2899 | 2899 | if not message: |
|
2900 | 2900 | message = old.description() |
|
2901 | 2901 | # Default if message isn't provided and --edit is not passed is to |
|
2902 | 2902 | # invoke editor, but allow --no-edit. If somehow we don't have any |
|
2903 | 2903 | # description, let's always start the editor. |
|
2904 | 2904 | doedit = not message or opts.get(b'edit') in [True, None] |
|
2905 | 2905 | else: |
|
2906 | 2906 | # Default if message is provided is to not invoke editor, but allow |
|
2907 | 2907 | # --edit. |
|
2908 | 2908 | doedit = opts.get(b'edit') is True |
|
2909 | 2909 | editor = getcommiteditor(edit=doedit, editform=editform) |
|
2910 | 2910 | |
|
2911 | 2911 | pureextra = extra.copy() |
|
2912 | 2912 | extra[b'amend_source'] = old.hex() |
|
2913 | 2913 | |
|
2914 | 2914 | new = context.memctx( |
|
2915 | 2915 | repo, |
|
2916 | 2916 | parents=[base.node(), old.p2().node()], |
|
2917 | 2917 | text=message, |
|
2918 | 2918 | files=files, |
|
2919 | 2919 | filectxfn=filectxfn, |
|
2920 | 2920 | user=user, |
|
2921 | 2921 | date=date, |
|
2922 | 2922 | extra=extra, |
|
2923 | 2923 | editor=editor, |
|
2924 | 2924 | ) |
|
2925 | 2925 | |
|
2926 | 2926 | newdesc = changelog.stripdesc(new.description()) |
|
2927 | 2927 | if ( |
|
2928 | 2928 | (not changes) |
|
2929 | 2929 | and newdesc == old.description() |
|
2930 | 2930 | and user == old.user() |
|
2931 | 2931 | and (date == old.date() or datemaydiffer) |
|
2932 | 2932 | and pureextra == old.extra() |
|
2933 | 2933 | ): |
|
2934 | 2934 | # nothing changed. continuing here would create a new node |
|
2935 | 2935 | # anyway because of the amend_source noise. |
|
2936 | 2936 | # |
|
2937 | 2937 | # This not what we expect from amend. |
|
2938 | 2938 | return old.node() |
|
2939 | 2939 | |
|
2940 | 2940 | commitphase = None |
|
2941 | 2941 | if opts.get(b'secret'): |
|
2942 | 2942 | commitphase = phases.secret |
|
2943 | 2943 | newid = repo.commitctx(new) |
|
2944 | 2944 | ms.reset() |
|
2945 | 2945 | |
|
2946 | 2946 | # Reroute the working copy parent to the new changeset |
|
2947 | 2947 | repo.setparents(newid, nullid) |
|
2948 | 2948 | mapping = {old.node(): (newid,)} |
|
2949 | 2949 | obsmetadata = None |
|
2950 | 2950 | if opts.get(b'note'): |
|
2951 | 2951 | obsmetadata = {b'note': encoding.fromlocal(opts[b'note'])} |
|
2952 | 2952 | backup = ui.configbool(b'rewrite', b'backup-bundle') |
|
2953 | 2953 | scmutil.cleanupnodes( |
|
2954 | 2954 | repo, |
|
2955 | 2955 | mapping, |
|
2956 | 2956 | b'amend', |
|
2957 | 2957 | metadata=obsmetadata, |
|
2958 | 2958 | fixphase=True, |
|
2959 | 2959 | targetphase=commitphase, |
|
2960 | 2960 | backup=backup, |
|
2961 | 2961 | ) |
|
2962 | 2962 | |
|
2963 | 2963 | # Fixing the dirstate because localrepo.commitctx does not update |
|
2964 | 2964 | # it. This is rather convenient because we did not need to update |
|
2965 | 2965 | # the dirstate for all the files in the new commit which commitctx |
|
2966 | 2966 | # could have done if it updated the dirstate. Now, we can |
|
2967 | 2967 | # selectively update the dirstate only for the amended files. |
|
2968 | 2968 | dirstate = repo.dirstate |
|
2969 | 2969 | |
|
2970 | 2970 | # Update the state of the files which were added and modified in the |
|
2971 | 2971 | # amend to "normal" in the dirstate. We need to use "normallookup" since |
|
2972 | 2972 | # the files may have changed since the command started; using "normal" |
|
2973 | 2973 | # would mark them as clean but with uncommitted contents. |
|
2974 | 2974 | normalfiles = set(wctx.modified() + wctx.added()) & filestoamend |
|
2975 | 2975 | for f in normalfiles: |
|
2976 | 2976 | dirstate.normallookup(f) |
|
2977 | 2977 | |
|
2978 | 2978 | # Update the state of files which were removed in the amend |
|
2979 | 2979 | # to "removed" in the dirstate. |
|
2980 | 2980 | removedfiles = set(wctx.removed()) & filestoamend |
|
2981 | 2981 | for f in removedfiles: |
|
2982 | 2982 | dirstate.drop(f) |
|
2983 | 2983 | |
|
2984 | 2984 | return newid |
|
2985 | 2985 | |
|
2986 | 2986 | |
|
2987 | 2987 | def commiteditor(repo, ctx, subs, editform=b''): |
|
2988 | 2988 | if ctx.description(): |
|
2989 | 2989 | return ctx.description() |
|
2990 | 2990 | return commitforceeditor( |
|
2991 | 2991 | repo, ctx, subs, editform=editform, unchangedmessagedetection=True |
|
2992 | 2992 | ) |
|
2993 | 2993 | |
|
2994 | 2994 | |
|
2995 | 2995 | def commitforceeditor( |
|
2996 | 2996 | repo, |
|
2997 | 2997 | ctx, |
|
2998 | 2998 | subs, |
|
2999 | 2999 | finishdesc=None, |
|
3000 | 3000 | extramsg=None, |
|
3001 | 3001 | editform=b'', |
|
3002 | 3002 | unchangedmessagedetection=False, |
|
3003 | 3003 | ): |
|
3004 | 3004 | if not extramsg: |
|
3005 | 3005 | extramsg = _(b"Leave message empty to abort commit.") |
|
3006 | 3006 | |
|
3007 | 3007 | forms = [e for e in editform.split(b'.') if e] |
|
3008 | 3008 | forms.insert(0, b'changeset') |
|
3009 | 3009 | templatetext = None |
|
3010 | 3010 | while forms: |
|
3011 | 3011 | ref = b'.'.join(forms) |
|
3012 | 3012 | if repo.ui.config(b'committemplate', ref): |
|
3013 | 3013 | templatetext = committext = buildcommittemplate( |
|
3014 | 3014 | repo, ctx, subs, extramsg, ref |
|
3015 | 3015 | ) |
|
3016 | 3016 | break |
|
3017 | 3017 | forms.pop() |
|
3018 | 3018 | else: |
|
3019 | 3019 | committext = buildcommittext(repo, ctx, subs, extramsg) |
|
3020 | 3020 | |
|
3021 | 3021 | # run editor in the repository root |
|
3022 | 3022 | olddir = encoding.getcwd() |
|
3023 | 3023 | os.chdir(repo.root) |
|
3024 | 3024 | |
|
3025 | 3025 | # make in-memory changes visible to external process |
|
3026 | 3026 | tr = repo.currenttransaction() |
|
3027 | 3027 | repo.dirstate.write(tr) |
|
3028 | 3028 | pending = tr and tr.writepending() and repo.root |
|
3029 | 3029 | |
|
3030 | 3030 | editortext = repo.ui.edit( |
|
3031 | 3031 | committext, |
|
3032 | 3032 | ctx.user(), |
|
3033 | 3033 | ctx.extra(), |
|
3034 | 3034 | editform=editform, |
|
3035 | 3035 | pending=pending, |
|
3036 | 3036 | repopath=repo.path, |
|
3037 | 3037 | action=b'commit', |
|
3038 | 3038 | ) |
|
3039 | 3039 | text = editortext |
|
3040 | 3040 | |
|
3041 | 3041 | # strip away anything below this special string (used for editors that want |
|
3042 | 3042 | # to display the diff) |
|
3043 | 3043 | stripbelow = re.search(_linebelow, text, flags=re.MULTILINE) |
|
3044 | 3044 | if stripbelow: |
|
3045 | 3045 | text = text[: stripbelow.start()] |
|
3046 | 3046 | |
|
3047 | 3047 | text = re.sub(b"(?m)^HG:.*(\n|$)", b"", text) |
|
3048 | 3048 | os.chdir(olddir) |
|
3049 | 3049 | |
|
3050 | 3050 | if finishdesc: |
|
3051 | 3051 | text = finishdesc(text) |
|
3052 | 3052 | if not text.strip(): |
|
3053 | 3053 | raise error.Abort(_(b"empty commit message")) |
|
3054 | 3054 | if unchangedmessagedetection and editortext == templatetext: |
|
3055 | 3055 | raise error.Abort(_(b"commit message unchanged")) |
|
3056 | 3056 | |
|
3057 | 3057 | return text |
|
3058 | 3058 | |
|
3059 | 3059 | |
|
3060 | 3060 | def buildcommittemplate(repo, ctx, subs, extramsg, ref): |
|
3061 | 3061 | ui = repo.ui |
|
3062 | 3062 | spec = formatter.reference_templatespec(ref) |
|
3063 | 3063 | t = logcmdutil.changesettemplater(ui, repo, spec) |
|
3064 | 3064 | t.t.cache.update( |
|
3065 | 3065 | (k, templater.unquotestring(v)) |
|
3066 | 3066 | for k, v in repo.ui.configitems(b'committemplate') |
|
3067 | 3067 | ) |
|
3068 | 3068 | |
|
3069 | 3069 | if not extramsg: |
|
3070 | 3070 | extramsg = b'' # ensure that extramsg is string |
|
3071 | 3071 | |
|
3072 | 3072 | ui.pushbuffer() |
|
3073 | 3073 | t.show(ctx, extramsg=extramsg) |
|
3074 | 3074 | return ui.popbuffer() |
|
3075 | 3075 | |
|
3076 | 3076 | |
|
3077 | 3077 | def hgprefix(msg): |
|
3078 | 3078 | return b"\n".join([b"HG: %s" % a for a in msg.split(b"\n") if a]) |
|
3079 | 3079 | |
|
3080 | 3080 | |
|
3081 | 3081 | def buildcommittext(repo, ctx, subs, extramsg): |
|
3082 | 3082 | edittext = [] |
|
3083 | 3083 | modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() |
|
3084 | 3084 | if ctx.description(): |
|
3085 | 3085 | edittext.append(ctx.description()) |
|
3086 | 3086 | edittext.append(b"") |
|
3087 | 3087 | edittext.append(b"") # Empty line between message and comments. |
|
3088 | 3088 | edittext.append( |
|
3089 | 3089 | hgprefix( |
|
3090 | 3090 | _( |
|
3091 | 3091 | b"Enter commit message." |
|
3092 | 3092 | b" Lines beginning with 'HG:' are removed." |
|
3093 | 3093 | ) |
|
3094 | 3094 | ) |
|
3095 | 3095 | ) |
|
3096 | 3096 | edittext.append(hgprefix(extramsg)) |
|
3097 | 3097 | edittext.append(b"HG: --") |
|
3098 | 3098 | edittext.append(hgprefix(_(b"user: %s") % ctx.user())) |
|
3099 | 3099 | if ctx.p2(): |
|
3100 | 3100 | edittext.append(hgprefix(_(b"branch merge"))) |
|
3101 | 3101 | if ctx.branch(): |
|
3102 | 3102 | edittext.append(hgprefix(_(b"branch '%s'") % ctx.branch())) |
|
3103 | 3103 | if bookmarks.isactivewdirparent(repo): |
|
3104 | 3104 | edittext.append(hgprefix(_(b"bookmark '%s'") % repo._activebookmark)) |
|
3105 | 3105 | edittext.extend([hgprefix(_(b"subrepo %s") % s) for s in subs]) |
|
3106 | 3106 | edittext.extend([hgprefix(_(b"added %s") % f) for f in added]) |
|
3107 | 3107 | edittext.extend([hgprefix(_(b"changed %s") % f) for f in modified]) |
|
3108 | 3108 | edittext.extend([hgprefix(_(b"removed %s") % f) for f in removed]) |
|
3109 | 3109 | if not added and not modified and not removed: |
|
3110 | 3110 | edittext.append(hgprefix(_(b"no files changed"))) |
|
3111 | 3111 | edittext.append(b"") |
|
3112 | 3112 | |
|
3113 | 3113 | return b"\n".join(edittext) |
|
3114 | 3114 | |
|
3115 | 3115 | |
|
3116 | def commitstatus(repo, node, branch, bheads=None, opts=None): | |
|
3116 | def commitstatus(repo, node, branch, bheads=None, tip=None, opts=None): | |
|
3117 | 3117 | if opts is None: |
|
3118 | 3118 | opts = {} |
|
3119 | 3119 | ctx = repo[node] |
|
3120 | 3120 | parents = ctx.parents() |
|
3121 | 3121 | |
|
3122 | if ( | |
|
3122 | if tip is not None and repo.changelog.tip() == tip: | |
|
3123 | # avoid reporting something like "committed new head" when | |
|
3124 | # recommitting old changesets, and issue a helpful warning | |
|
3125 | # for most instances | |
|
3126 | repo.ui.warn(_("warning: commit already existed in the repository!\n")) | |
|
3127 | elif ( | |
|
3123 | 3128 | not opts.get(b'amend') |
|
3124 | 3129 | and bheads |
|
3125 | 3130 | and node not in bheads |
|
3126 | 3131 | and not any( |
|
3127 | 3132 | p.node() in bheads and p.branch() == branch for p in parents |
|
3128 | 3133 | ) |
|
3129 | 3134 | ): |
|
3130 | 3135 | repo.ui.status(_(b'created new head\n')) |
|
3131 | 3136 | # The message is not printed for initial roots. For the other |
|
3132 | 3137 | # changesets, it is printed in the following situations: |
|
3133 | 3138 | # |
|
3134 | 3139 | # Par column: for the 2 parents with ... |
|
3135 | 3140 | # N: null or no parent |
|
3136 | 3141 | # B: parent is on another named branch |
|
3137 | 3142 | # C: parent is a regular non head changeset |
|
3138 | 3143 | # H: parent was a branch head of the current branch |
|
3139 | 3144 | # Msg column: whether we print "created new head" message |
|
3140 | 3145 | # In the following, it is assumed that there already exists some |
|
3141 | 3146 | # initial branch heads of the current branch, otherwise nothing is |
|
3142 | 3147 | # printed anyway. |
|
3143 | 3148 | # |
|
3144 | 3149 | # Par Msg Comment |
|
3145 | 3150 | # N N y additional topo root |
|
3146 | 3151 | # |
|
3147 | 3152 | # B N y additional branch root |
|
3148 | 3153 | # C N y additional topo head |
|
3149 | 3154 | # H N n usual case |
|
3150 | 3155 | # |
|
3151 | 3156 | # B B y weird additional branch root |
|
3152 | 3157 | # C B y branch merge |
|
3153 | 3158 | # H B n merge with named branch |
|
3154 | 3159 | # |
|
3155 | 3160 | # C C y additional head from merge |
|
3156 | 3161 | # C H n merge with a head |
|
3157 | 3162 | # |
|
3158 | 3163 | # H H n head merge: head count decreases |
|
3159 | 3164 | |
|
3160 | 3165 | if not opts.get(b'close_branch'): |
|
3161 | 3166 | for r in parents: |
|
3162 | 3167 | if r.closesbranch() and r.branch() == branch: |
|
3163 | 3168 | repo.ui.status( |
|
3164 | 3169 | _(b'reopening closed branch head %d\n') % r.rev() |
|
3165 | 3170 | ) |
|
3166 | 3171 | |
|
3167 | 3172 | if repo.ui.debugflag: |
|
3168 | 3173 | repo.ui.write( |
|
3169 | 3174 | _(b'committed changeset %d:%s\n') % (ctx.rev(), ctx.hex()) |
|
3170 | 3175 | ) |
|
3171 | 3176 | elif repo.ui.verbose: |
|
3172 | 3177 | repo.ui.write(_(b'committed changeset %d:%s\n') % (ctx.rev(), ctx)) |
|
3173 | 3178 | |
|
3174 | 3179 | |
|
3175 | 3180 | def postcommitstatus(repo, pats, opts): |
|
3176 | 3181 | return repo.status(match=scmutil.match(repo[None], pats, opts)) |
|
3177 | 3182 | |
|
3178 | 3183 | |
|
3179 | 3184 | def revert(ui, repo, ctx, *pats, **opts): |
|
3180 | 3185 | opts = pycompat.byteskwargs(opts) |
|
3181 | 3186 | parent, p2 = repo.dirstate.parents() |
|
3182 | 3187 | node = ctx.node() |
|
3183 | 3188 | |
|
3184 | 3189 | mf = ctx.manifest() |
|
3185 | 3190 | if node == p2: |
|
3186 | 3191 | parent = p2 |
|
3187 | 3192 | |
|
3188 | 3193 | # need all matching names in dirstate and manifest of target rev, |
|
3189 | 3194 | # so have to walk both. do not print errors if files exist in one |
|
3190 | 3195 | # but not other. in both cases, filesets should be evaluated against |
|
3191 | 3196 | # workingctx to get consistent result (issue4497). this means 'set:**' |
|
3192 | 3197 | # cannot be used to select missing files from target rev. |
|
3193 | 3198 | |
|
3194 | 3199 | # `names` is a mapping for all elements in working copy and target revision |
|
3195 | 3200 | # The mapping is in the form: |
|
3196 | 3201 | # <abs path in repo> -> (<path from CWD>, <exactly specified by matcher?>) |
|
3197 | 3202 | names = {} |
|
3198 | 3203 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
|
3199 | 3204 | |
|
3200 | 3205 | with repo.wlock(): |
|
3201 | 3206 | ## filling of the `names` mapping |
|
3202 | 3207 | # walk dirstate to fill `names` |
|
3203 | 3208 | |
|
3204 | 3209 | interactive = opts.get(b'interactive', False) |
|
3205 | 3210 | wctx = repo[None] |
|
3206 | 3211 | m = scmutil.match(wctx, pats, opts) |
|
3207 | 3212 | |
|
3208 | 3213 | # we'll need this later |
|
3209 | 3214 | targetsubs = sorted(s for s in wctx.substate if m(s)) |
|
3210 | 3215 | |
|
3211 | 3216 | if not m.always(): |
|
3212 | 3217 | matcher = matchmod.badmatch(m, lambda x, y: False) |
|
3213 | 3218 | for abs in wctx.walk(matcher): |
|
3214 | 3219 | names[abs] = m.exact(abs) |
|
3215 | 3220 | |
|
3216 | 3221 | # walk target manifest to fill `names` |
|
3217 | 3222 | |
|
3218 | 3223 | def badfn(path, msg): |
|
3219 | 3224 | if path in names: |
|
3220 | 3225 | return |
|
3221 | 3226 | if path in ctx.substate: |
|
3222 | 3227 | return |
|
3223 | 3228 | path_ = path + b'/' |
|
3224 | 3229 | for f in names: |
|
3225 | 3230 | if f.startswith(path_): |
|
3226 | 3231 | return |
|
3227 | 3232 | ui.warn(b"%s: %s\n" % (uipathfn(path), msg)) |
|
3228 | 3233 | |
|
3229 | 3234 | for abs in ctx.walk(matchmod.badmatch(m, badfn)): |
|
3230 | 3235 | if abs not in names: |
|
3231 | 3236 | names[abs] = m.exact(abs) |
|
3232 | 3237 | |
|
3233 | 3238 | # Find status of all file in `names`. |
|
3234 | 3239 | m = scmutil.matchfiles(repo, names) |
|
3235 | 3240 | |
|
3236 | 3241 | changes = repo.status( |
|
3237 | 3242 | node1=node, match=m, unknown=True, ignored=True, clean=True |
|
3238 | 3243 | ) |
|
3239 | 3244 | else: |
|
3240 | 3245 | changes = repo.status(node1=node, match=m) |
|
3241 | 3246 | for kind in changes: |
|
3242 | 3247 | for abs in kind: |
|
3243 | 3248 | names[abs] = m.exact(abs) |
|
3244 | 3249 | |
|
3245 | 3250 | m = scmutil.matchfiles(repo, names) |
|
3246 | 3251 | |
|
3247 | 3252 | modified = set(changes.modified) |
|
3248 | 3253 | added = set(changes.added) |
|
3249 | 3254 | removed = set(changes.removed) |
|
3250 | 3255 | _deleted = set(changes.deleted) |
|
3251 | 3256 | unknown = set(changes.unknown) |
|
3252 | 3257 | unknown.update(changes.ignored) |
|
3253 | 3258 | clean = set(changes.clean) |
|
3254 | 3259 | modadded = set() |
|
3255 | 3260 | |
|
3256 | 3261 | # We need to account for the state of the file in the dirstate, |
|
3257 | 3262 | # even when we revert against something else than parent. This will |
|
3258 | 3263 | # slightly alter the behavior of revert (doing back up or not, delete |
|
3259 | 3264 | # or just forget etc). |
|
3260 | 3265 | if parent == node: |
|
3261 | 3266 | dsmodified = modified |
|
3262 | 3267 | dsadded = added |
|
3263 | 3268 | dsremoved = removed |
|
3264 | 3269 | # store all local modifications, useful later for rename detection |
|
3265 | 3270 | localchanges = dsmodified | dsadded |
|
3266 | 3271 | modified, added, removed = set(), set(), set() |
|
3267 | 3272 | else: |
|
3268 | 3273 | changes = repo.status(node1=parent, match=m) |
|
3269 | 3274 | dsmodified = set(changes.modified) |
|
3270 | 3275 | dsadded = set(changes.added) |
|
3271 | 3276 | dsremoved = set(changes.removed) |
|
3272 | 3277 | # store all local modifications, useful later for rename detection |
|
3273 | 3278 | localchanges = dsmodified | dsadded |
|
3274 | 3279 | |
|
3275 | 3280 | # only take into account for removes between wc and target |
|
3276 | 3281 | clean |= dsremoved - removed |
|
3277 | 3282 | dsremoved &= removed |
|
3278 | 3283 | # distinct between dirstate remove and other |
|
3279 | 3284 | removed -= dsremoved |
|
3280 | 3285 | |
|
3281 | 3286 | modadded = added & dsmodified |
|
3282 | 3287 | added -= modadded |
|
3283 | 3288 | |
|
3284 | 3289 | # tell newly modified apart. |
|
3285 | 3290 | dsmodified &= modified |
|
3286 | 3291 | dsmodified |= modified & dsadded # dirstate added may need backup |
|
3287 | 3292 | modified -= dsmodified |
|
3288 | 3293 | |
|
3289 | 3294 | # We need to wait for some post-processing to update this set |
|
3290 | 3295 | # before making the distinction. The dirstate will be used for |
|
3291 | 3296 | # that purpose. |
|
3292 | 3297 | dsadded = added |
|
3293 | 3298 | |
|
3294 | 3299 | # in case of merge, files that are actually added can be reported as |
|
3295 | 3300 | # modified, we need to post process the result |
|
3296 | 3301 | if p2 != nullid: |
|
3297 | 3302 | mergeadd = set(dsmodified) |
|
3298 | 3303 | for path in dsmodified: |
|
3299 | 3304 | if path in mf: |
|
3300 | 3305 | mergeadd.remove(path) |
|
3301 | 3306 | dsadded |= mergeadd |
|
3302 | 3307 | dsmodified -= mergeadd |
|
3303 | 3308 | |
|
3304 | 3309 | # if f is a rename, update `names` to also revert the source |
|
3305 | 3310 | for f in localchanges: |
|
3306 | 3311 | src = repo.dirstate.copied(f) |
|
3307 | 3312 | # XXX should we check for rename down to target node? |
|
3308 | 3313 | if src and src not in names and repo.dirstate[src] == b'r': |
|
3309 | 3314 | dsremoved.add(src) |
|
3310 | 3315 | names[src] = True |
|
3311 | 3316 | |
|
3312 | 3317 | # determine the exact nature of the deleted changesets |
|
3313 | 3318 | deladded = set(_deleted) |
|
3314 | 3319 | for path in _deleted: |
|
3315 | 3320 | if path in mf: |
|
3316 | 3321 | deladded.remove(path) |
|
3317 | 3322 | deleted = _deleted - deladded |
|
3318 | 3323 | |
|
3319 | 3324 | # distinguish between file to forget and the other |
|
3320 | 3325 | added = set() |
|
3321 | 3326 | for abs in dsadded: |
|
3322 | 3327 | if repo.dirstate[abs] != b'a': |
|
3323 | 3328 | added.add(abs) |
|
3324 | 3329 | dsadded -= added |
|
3325 | 3330 | |
|
3326 | 3331 | for abs in deladded: |
|
3327 | 3332 | if repo.dirstate[abs] == b'a': |
|
3328 | 3333 | dsadded.add(abs) |
|
3329 | 3334 | deladded -= dsadded |
|
3330 | 3335 | |
|
3331 | 3336 | # For files marked as removed, we check if an unknown file is present at |
|
3332 | 3337 | # the same path. If a such file exists it may need to be backed up. |
|
3333 | 3338 | # Making the distinction at this stage helps have simpler backup |
|
3334 | 3339 | # logic. |
|
3335 | 3340 | removunk = set() |
|
3336 | 3341 | for abs in removed: |
|
3337 | 3342 | target = repo.wjoin(abs) |
|
3338 | 3343 | if os.path.lexists(target): |
|
3339 | 3344 | removunk.add(abs) |
|
3340 | 3345 | removed -= removunk |
|
3341 | 3346 | |
|
3342 | 3347 | dsremovunk = set() |
|
3343 | 3348 | for abs in dsremoved: |
|
3344 | 3349 | target = repo.wjoin(abs) |
|
3345 | 3350 | if os.path.lexists(target): |
|
3346 | 3351 | dsremovunk.add(abs) |
|
3347 | 3352 | dsremoved -= dsremovunk |
|
3348 | 3353 | |
|
3349 | 3354 | # action to be actually performed by revert |
|
3350 | 3355 | # (<list of file>, message>) tuple |
|
3351 | 3356 | actions = { |
|
3352 | 3357 | b'revert': ([], _(b'reverting %s\n')), |
|
3353 | 3358 | b'add': ([], _(b'adding %s\n')), |
|
3354 | 3359 | b'remove': ([], _(b'removing %s\n')), |
|
3355 | 3360 | b'drop': ([], _(b'removing %s\n')), |
|
3356 | 3361 | b'forget': ([], _(b'forgetting %s\n')), |
|
3357 | 3362 | b'undelete': ([], _(b'undeleting %s\n')), |
|
3358 | 3363 | b'noop': (None, _(b'no changes needed to %s\n')), |
|
3359 | 3364 | b'unknown': (None, _(b'file not managed: %s\n')), |
|
3360 | 3365 | } |
|
3361 | 3366 | |
|
3362 | 3367 | # "constant" that convey the backup strategy. |
|
3363 | 3368 | # All set to `discard` if `no-backup` is set do avoid checking |
|
3364 | 3369 | # no_backup lower in the code. |
|
3365 | 3370 | # These values are ordered for comparison purposes |
|
3366 | 3371 | backupinteractive = 3 # do backup if interactively modified |
|
3367 | 3372 | backup = 2 # unconditionally do backup |
|
3368 | 3373 | check = 1 # check if the existing file differs from target |
|
3369 | 3374 | discard = 0 # never do backup |
|
3370 | 3375 | if opts.get(b'no_backup'): |
|
3371 | 3376 | backupinteractive = backup = check = discard |
|
3372 | 3377 | if interactive: |
|
3373 | 3378 | dsmodifiedbackup = backupinteractive |
|
3374 | 3379 | else: |
|
3375 | 3380 | dsmodifiedbackup = backup |
|
3376 | 3381 | tobackup = set() |
|
3377 | 3382 | |
|
3378 | 3383 | backupanddel = actions[b'remove'] |
|
3379 | 3384 | if not opts.get(b'no_backup'): |
|
3380 | 3385 | backupanddel = actions[b'drop'] |
|
3381 | 3386 | |
|
3382 | 3387 | disptable = ( |
|
3383 | 3388 | # dispatch table: |
|
3384 | 3389 | # file state |
|
3385 | 3390 | # action |
|
3386 | 3391 | # make backup |
|
3387 | 3392 | ## Sets that results that will change file on disk |
|
3388 | 3393 | # Modified compared to target, no local change |
|
3389 | 3394 | (modified, actions[b'revert'], discard), |
|
3390 | 3395 | # Modified compared to target, but local file is deleted |
|
3391 | 3396 | (deleted, actions[b'revert'], discard), |
|
3392 | 3397 | # Modified compared to target, local change |
|
3393 | 3398 | (dsmodified, actions[b'revert'], dsmodifiedbackup), |
|
3394 | 3399 | # Added since target |
|
3395 | 3400 | (added, actions[b'remove'], discard), |
|
3396 | 3401 | # Added in working directory |
|
3397 | 3402 | (dsadded, actions[b'forget'], discard), |
|
3398 | 3403 | # Added since target, have local modification |
|
3399 | 3404 | (modadded, backupanddel, backup), |
|
3400 | 3405 | # Added since target but file is missing in working directory |
|
3401 | 3406 | (deladded, actions[b'drop'], discard), |
|
3402 | 3407 | # Removed since target, before working copy parent |
|
3403 | 3408 | (removed, actions[b'add'], discard), |
|
3404 | 3409 | # Same as `removed` but an unknown file exists at the same path |
|
3405 | 3410 | (removunk, actions[b'add'], check), |
|
3406 | 3411 | # Removed since targe, marked as such in working copy parent |
|
3407 | 3412 | (dsremoved, actions[b'undelete'], discard), |
|
3408 | 3413 | # Same as `dsremoved` but an unknown file exists at the same path |
|
3409 | 3414 | (dsremovunk, actions[b'undelete'], check), |
|
3410 | 3415 | ## the following sets does not result in any file changes |
|
3411 | 3416 | # File with no modification |
|
3412 | 3417 | (clean, actions[b'noop'], discard), |
|
3413 | 3418 | # Existing file, not tracked anywhere |
|
3414 | 3419 | (unknown, actions[b'unknown'], discard), |
|
3415 | 3420 | ) |
|
3416 | 3421 | |
|
3417 | 3422 | for abs, exact in sorted(names.items()): |
|
3418 | 3423 | # target file to be touch on disk (relative to cwd) |
|
3419 | 3424 | target = repo.wjoin(abs) |
|
3420 | 3425 | # search the entry in the dispatch table. |
|
3421 | 3426 | # if the file is in any of these sets, it was touched in the working |
|
3422 | 3427 | # directory parent and we are sure it needs to be reverted. |
|
3423 | 3428 | for table, (xlist, msg), dobackup in disptable: |
|
3424 | 3429 | if abs not in table: |
|
3425 | 3430 | continue |
|
3426 | 3431 | if xlist is not None: |
|
3427 | 3432 | xlist.append(abs) |
|
3428 | 3433 | if dobackup: |
|
3429 | 3434 | # If in interactive mode, don't automatically create |
|
3430 | 3435 | # .orig files (issue4793) |
|
3431 | 3436 | if dobackup == backupinteractive: |
|
3432 | 3437 | tobackup.add(abs) |
|
3433 | 3438 | elif backup <= dobackup or wctx[abs].cmp(ctx[abs]): |
|
3434 | 3439 | absbakname = scmutil.backuppath(ui, repo, abs) |
|
3435 | 3440 | bakname = os.path.relpath( |
|
3436 | 3441 | absbakname, start=repo.root |
|
3437 | 3442 | ) |
|
3438 | 3443 | ui.note( |
|
3439 | 3444 | _(b'saving current version of %s as %s\n') |
|
3440 | 3445 | % (uipathfn(abs), uipathfn(bakname)) |
|
3441 | 3446 | ) |
|
3442 | 3447 | if not opts.get(b'dry_run'): |
|
3443 | 3448 | if interactive: |
|
3444 | 3449 | util.copyfile(target, absbakname) |
|
3445 | 3450 | else: |
|
3446 | 3451 | util.rename(target, absbakname) |
|
3447 | 3452 | if opts.get(b'dry_run'): |
|
3448 | 3453 | if ui.verbose or not exact: |
|
3449 | 3454 | ui.status(msg % uipathfn(abs)) |
|
3450 | 3455 | elif exact: |
|
3451 | 3456 | ui.warn(msg % uipathfn(abs)) |
|
3452 | 3457 | break |
|
3453 | 3458 | |
|
3454 | 3459 | if not opts.get(b'dry_run'): |
|
3455 | 3460 | needdata = (b'revert', b'add', b'undelete') |
|
3456 | 3461 | oplist = [actions[name][0] for name in needdata] |
|
3457 | 3462 | prefetch = scmutil.prefetchfiles |
|
3458 | 3463 | matchfiles = scmutil.matchfiles( |
|
3459 | 3464 | repo, [f for sublist in oplist for f in sublist] |
|
3460 | 3465 | ) |
|
3461 | 3466 | prefetch( |
|
3462 | 3467 | repo, [(ctx.rev(), matchfiles)], |
|
3463 | 3468 | ) |
|
3464 | 3469 | match = scmutil.match(repo[None], pats) |
|
3465 | 3470 | _performrevert( |
|
3466 | 3471 | repo, |
|
3467 | 3472 | ctx, |
|
3468 | 3473 | names, |
|
3469 | 3474 | uipathfn, |
|
3470 | 3475 | actions, |
|
3471 | 3476 | match, |
|
3472 | 3477 | interactive, |
|
3473 | 3478 | tobackup, |
|
3474 | 3479 | ) |
|
3475 | 3480 | |
|
3476 | 3481 | if targetsubs: |
|
3477 | 3482 | # Revert the subrepos on the revert list |
|
3478 | 3483 | for sub in targetsubs: |
|
3479 | 3484 | try: |
|
3480 | 3485 | wctx.sub(sub).revert( |
|
3481 | 3486 | ctx.substate[sub], *pats, **pycompat.strkwargs(opts) |
|
3482 | 3487 | ) |
|
3483 | 3488 | except KeyError: |
|
3484 | 3489 | raise error.Abort( |
|
3485 | 3490 | b"subrepository '%s' does not exist in %s!" |
|
3486 | 3491 | % (sub, short(ctx.node())) |
|
3487 | 3492 | ) |
|
3488 | 3493 | |
|
3489 | 3494 | |
|
3490 | 3495 | def _performrevert( |
|
3491 | 3496 | repo, |
|
3492 | 3497 | ctx, |
|
3493 | 3498 | names, |
|
3494 | 3499 | uipathfn, |
|
3495 | 3500 | actions, |
|
3496 | 3501 | match, |
|
3497 | 3502 | interactive=False, |
|
3498 | 3503 | tobackup=None, |
|
3499 | 3504 | ): |
|
3500 | 3505 | """function that actually perform all the actions computed for revert |
|
3501 | 3506 | |
|
3502 | 3507 | This is an independent function to let extension to plug in and react to |
|
3503 | 3508 | the imminent revert. |
|
3504 | 3509 | |
|
3505 | 3510 | Make sure you have the working directory locked when calling this function. |
|
3506 | 3511 | """ |
|
3507 | 3512 | parent, p2 = repo.dirstate.parents() |
|
3508 | 3513 | node = ctx.node() |
|
3509 | 3514 | excluded_files = [] |
|
3510 | 3515 | |
|
3511 | 3516 | def checkout(f): |
|
3512 | 3517 | fc = ctx[f] |
|
3513 | 3518 | repo.wwrite(f, fc.data(), fc.flags()) |
|
3514 | 3519 | |
|
3515 | 3520 | def doremove(f): |
|
3516 | 3521 | try: |
|
3517 | 3522 | rmdir = repo.ui.configbool(b'experimental', b'removeemptydirs') |
|
3518 | 3523 | repo.wvfs.unlinkpath(f, rmdir=rmdir) |
|
3519 | 3524 | except OSError: |
|
3520 | 3525 | pass |
|
3521 | 3526 | repo.dirstate.remove(f) |
|
3522 | 3527 | |
|
3523 | 3528 | def prntstatusmsg(action, f): |
|
3524 | 3529 | exact = names[f] |
|
3525 | 3530 | if repo.ui.verbose or not exact: |
|
3526 | 3531 | repo.ui.status(actions[action][1] % uipathfn(f)) |
|
3527 | 3532 | |
|
3528 | 3533 | audit_path = pathutil.pathauditor(repo.root, cached=True) |
|
3529 | 3534 | for f in actions[b'forget'][0]: |
|
3530 | 3535 | if interactive: |
|
3531 | 3536 | choice = repo.ui.promptchoice( |
|
3532 | 3537 | _(b"forget added file %s (Yn)?$$ &Yes $$ &No") % uipathfn(f) |
|
3533 | 3538 | ) |
|
3534 | 3539 | if choice == 0: |
|
3535 | 3540 | prntstatusmsg(b'forget', f) |
|
3536 | 3541 | repo.dirstate.drop(f) |
|
3537 | 3542 | else: |
|
3538 | 3543 | excluded_files.append(f) |
|
3539 | 3544 | else: |
|
3540 | 3545 | prntstatusmsg(b'forget', f) |
|
3541 | 3546 | repo.dirstate.drop(f) |
|
3542 | 3547 | for f in actions[b'remove'][0]: |
|
3543 | 3548 | audit_path(f) |
|
3544 | 3549 | if interactive: |
|
3545 | 3550 | choice = repo.ui.promptchoice( |
|
3546 | 3551 | _(b"remove added file %s (Yn)?$$ &Yes $$ &No") % uipathfn(f) |
|
3547 | 3552 | ) |
|
3548 | 3553 | if choice == 0: |
|
3549 | 3554 | prntstatusmsg(b'remove', f) |
|
3550 | 3555 | doremove(f) |
|
3551 | 3556 | else: |
|
3552 | 3557 | excluded_files.append(f) |
|
3553 | 3558 | else: |
|
3554 | 3559 | prntstatusmsg(b'remove', f) |
|
3555 | 3560 | doremove(f) |
|
3556 | 3561 | for f in actions[b'drop'][0]: |
|
3557 | 3562 | audit_path(f) |
|
3558 | 3563 | prntstatusmsg(b'drop', f) |
|
3559 | 3564 | repo.dirstate.remove(f) |
|
3560 | 3565 | |
|
3561 | 3566 | normal = None |
|
3562 | 3567 | if node == parent: |
|
3563 | 3568 | # We're reverting to our parent. If possible, we'd like status |
|
3564 | 3569 | # to report the file as clean. We have to use normallookup for |
|
3565 | 3570 | # merges to avoid losing information about merged/dirty files. |
|
3566 | 3571 | if p2 != nullid: |
|
3567 | 3572 | normal = repo.dirstate.normallookup |
|
3568 | 3573 | else: |
|
3569 | 3574 | normal = repo.dirstate.normal |
|
3570 | 3575 | |
|
3571 | 3576 | newlyaddedandmodifiedfiles = set() |
|
3572 | 3577 | if interactive: |
|
3573 | 3578 | # Prompt the user for changes to revert |
|
3574 | 3579 | torevert = [f for f in actions[b'revert'][0] if f not in excluded_files] |
|
3575 | 3580 | m = scmutil.matchfiles(repo, torevert) |
|
3576 | 3581 | diffopts = patch.difffeatureopts( |
|
3577 | 3582 | repo.ui, |
|
3578 | 3583 | whitespace=True, |
|
3579 | 3584 | section=b'commands', |
|
3580 | 3585 | configprefix=b'revert.interactive.', |
|
3581 | 3586 | ) |
|
3582 | 3587 | diffopts.nodates = True |
|
3583 | 3588 | diffopts.git = True |
|
3584 | 3589 | operation = b'apply' |
|
3585 | 3590 | if node == parent: |
|
3586 | 3591 | if repo.ui.configbool( |
|
3587 | 3592 | b'experimental', b'revert.interactive.select-to-keep' |
|
3588 | 3593 | ): |
|
3589 | 3594 | operation = b'keep' |
|
3590 | 3595 | else: |
|
3591 | 3596 | operation = b'discard' |
|
3592 | 3597 | |
|
3593 | 3598 | if operation == b'apply': |
|
3594 | 3599 | diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts) |
|
3595 | 3600 | else: |
|
3596 | 3601 | diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts) |
|
3597 | 3602 | originalchunks = patch.parsepatch(diff) |
|
3598 | 3603 | |
|
3599 | 3604 | try: |
|
3600 | 3605 | |
|
3601 | 3606 | chunks, opts = recordfilter( |
|
3602 | 3607 | repo.ui, originalchunks, match, operation=operation |
|
3603 | 3608 | ) |
|
3604 | 3609 | if operation == b'discard': |
|
3605 | 3610 | chunks = patch.reversehunks(chunks) |
|
3606 | 3611 | |
|
3607 | 3612 | except error.PatchError as err: |
|
3608 | 3613 | raise error.Abort(_(b'error parsing patch: %s') % err) |
|
3609 | 3614 | |
|
3610 | 3615 | # FIXME: when doing an interactive revert of a copy, there's no way of |
|
3611 | 3616 | # performing a partial revert of the added file, the only option is |
|
3612 | 3617 | # "remove added file <name> (Yn)?", so we don't need to worry about the |
|
3613 | 3618 | # alsorestore value. Ideally we'd be able to partially revert |
|
3614 | 3619 | # copied/renamed files. |
|
3615 | 3620 | newlyaddedandmodifiedfiles, unusedalsorestore = newandmodified( |
|
3616 | 3621 | chunks, originalchunks |
|
3617 | 3622 | ) |
|
3618 | 3623 | if tobackup is None: |
|
3619 | 3624 | tobackup = set() |
|
3620 | 3625 | # Apply changes |
|
3621 | 3626 | fp = stringio() |
|
3622 | 3627 | # chunks are serialized per file, but files aren't sorted |
|
3623 | 3628 | for f in sorted({c.header.filename() for c in chunks if ishunk(c)}): |
|
3624 | 3629 | prntstatusmsg(b'revert', f) |
|
3625 | 3630 | files = set() |
|
3626 | 3631 | for c in chunks: |
|
3627 | 3632 | if ishunk(c): |
|
3628 | 3633 | abs = c.header.filename() |
|
3629 | 3634 | # Create a backup file only if this hunk should be backed up |
|
3630 | 3635 | if c.header.filename() in tobackup: |
|
3631 | 3636 | target = repo.wjoin(abs) |
|
3632 | 3637 | bakname = scmutil.backuppath(repo.ui, repo, abs) |
|
3633 | 3638 | util.copyfile(target, bakname) |
|
3634 | 3639 | tobackup.remove(abs) |
|
3635 | 3640 | if abs not in files: |
|
3636 | 3641 | files.add(abs) |
|
3637 | 3642 | if operation == b'keep': |
|
3638 | 3643 | checkout(abs) |
|
3639 | 3644 | c.write(fp) |
|
3640 | 3645 | dopatch = fp.tell() |
|
3641 | 3646 | fp.seek(0) |
|
3642 | 3647 | if dopatch: |
|
3643 | 3648 | try: |
|
3644 | 3649 | patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None) |
|
3645 | 3650 | except error.PatchError as err: |
|
3646 | 3651 | raise error.Abort(pycompat.bytestr(err)) |
|
3647 | 3652 | del fp |
|
3648 | 3653 | else: |
|
3649 | 3654 | for f in actions[b'revert'][0]: |
|
3650 | 3655 | prntstatusmsg(b'revert', f) |
|
3651 | 3656 | checkout(f) |
|
3652 | 3657 | if normal: |
|
3653 | 3658 | normal(f) |
|
3654 | 3659 | |
|
3655 | 3660 | for f in actions[b'add'][0]: |
|
3656 | 3661 | # Don't checkout modified files, they are already created by the diff |
|
3657 | 3662 | if f not in newlyaddedandmodifiedfiles: |
|
3658 | 3663 | prntstatusmsg(b'add', f) |
|
3659 | 3664 | checkout(f) |
|
3660 | 3665 | repo.dirstate.add(f) |
|
3661 | 3666 | |
|
3662 | 3667 | normal = repo.dirstate.normallookup |
|
3663 | 3668 | if node == parent and p2 == nullid: |
|
3664 | 3669 | normal = repo.dirstate.normal |
|
3665 | 3670 | for f in actions[b'undelete'][0]: |
|
3666 | 3671 | if interactive: |
|
3667 | 3672 | choice = repo.ui.promptchoice( |
|
3668 | 3673 | _(b"add back removed file %s (Yn)?$$ &Yes $$ &No") % f |
|
3669 | 3674 | ) |
|
3670 | 3675 | if choice == 0: |
|
3671 | 3676 | prntstatusmsg(b'undelete', f) |
|
3672 | 3677 | checkout(f) |
|
3673 | 3678 | normal(f) |
|
3674 | 3679 | else: |
|
3675 | 3680 | excluded_files.append(f) |
|
3676 | 3681 | else: |
|
3677 | 3682 | prntstatusmsg(b'undelete', f) |
|
3678 | 3683 | checkout(f) |
|
3679 | 3684 | normal(f) |
|
3680 | 3685 | |
|
3681 | 3686 | copied = copies.pathcopies(repo[parent], ctx) |
|
3682 | 3687 | |
|
3683 | 3688 | for f in ( |
|
3684 | 3689 | actions[b'add'][0] + actions[b'undelete'][0] + actions[b'revert'][0] |
|
3685 | 3690 | ): |
|
3686 | 3691 | if f in copied: |
|
3687 | 3692 | repo.dirstate.copy(copied[f], f) |
|
3688 | 3693 | |
|
3689 | 3694 | |
|
3690 | 3695 | # a list of (ui, repo, otherpeer, opts, missing) functions called by |
|
3691 | 3696 | # commands.outgoing. "missing" is "missing" of the result of |
|
3692 | 3697 | # "findcommonoutgoing()" |
|
3693 | 3698 | outgoinghooks = util.hooks() |
|
3694 | 3699 | |
|
3695 | 3700 | # a list of (ui, repo) functions called by commands.summary |
|
3696 | 3701 | summaryhooks = util.hooks() |
|
3697 | 3702 | |
|
3698 | 3703 | # a list of (ui, repo, opts, changes) functions called by commands.summary. |
|
3699 | 3704 | # |
|
3700 | 3705 | # functions should return tuple of booleans below, if 'changes' is None: |
|
3701 | 3706 | # (whether-incomings-are-needed, whether-outgoings-are-needed) |
|
3702 | 3707 | # |
|
3703 | 3708 | # otherwise, 'changes' is a tuple of tuples below: |
|
3704 | 3709 | # - (sourceurl, sourcebranch, sourcepeer, incoming) |
|
3705 | 3710 | # - (desturl, destbranch, destpeer, outgoing) |
|
3706 | 3711 | summaryremotehooks = util.hooks() |
|
3707 | 3712 | |
|
3708 | 3713 | |
|
3709 | 3714 | def checkunfinished(repo, commit=False, skipmerge=False): |
|
3710 | 3715 | '''Look for an unfinished multistep operation, like graft, and abort |
|
3711 | 3716 | if found. It's probably good to check this right before |
|
3712 | 3717 | bailifchanged(). |
|
3713 | 3718 | ''' |
|
3714 | 3719 | # Check for non-clearable states first, so things like rebase will take |
|
3715 | 3720 | # precedence over update. |
|
3716 | 3721 | for state in statemod._unfinishedstates: |
|
3717 | 3722 | if ( |
|
3718 | 3723 | state._clearable |
|
3719 | 3724 | or (commit and state._allowcommit) |
|
3720 | 3725 | or state._reportonly |
|
3721 | 3726 | ): |
|
3722 | 3727 | continue |
|
3723 | 3728 | if state.isunfinished(repo): |
|
3724 | 3729 | raise error.Abort(state.msg(), hint=state.hint()) |
|
3725 | 3730 | |
|
3726 | 3731 | for s in statemod._unfinishedstates: |
|
3727 | 3732 | if ( |
|
3728 | 3733 | not s._clearable |
|
3729 | 3734 | or (commit and s._allowcommit) |
|
3730 | 3735 | or (s._opname == b'merge' and skipmerge) |
|
3731 | 3736 | or s._reportonly |
|
3732 | 3737 | ): |
|
3733 | 3738 | continue |
|
3734 | 3739 | if s.isunfinished(repo): |
|
3735 | 3740 | raise error.Abort(s.msg(), hint=s.hint()) |
|
3736 | 3741 | |
|
3737 | 3742 | |
|
3738 | 3743 | def clearunfinished(repo): |
|
3739 | 3744 | '''Check for unfinished operations (as above), and clear the ones |
|
3740 | 3745 | that are clearable. |
|
3741 | 3746 | ''' |
|
3742 | 3747 | for state in statemod._unfinishedstates: |
|
3743 | 3748 | if state._reportonly: |
|
3744 | 3749 | continue |
|
3745 | 3750 | if not state._clearable and state.isunfinished(repo): |
|
3746 | 3751 | raise error.Abort(state.msg(), hint=state.hint()) |
|
3747 | 3752 | |
|
3748 | 3753 | for s in statemod._unfinishedstates: |
|
3749 | 3754 | if s._opname == b'merge' or state._reportonly: |
|
3750 | 3755 | continue |
|
3751 | 3756 | if s._clearable and s.isunfinished(repo): |
|
3752 | 3757 | util.unlink(repo.vfs.join(s._fname)) |
|
3753 | 3758 | |
|
3754 | 3759 | |
|
3755 | 3760 | def getunfinishedstate(repo): |
|
3756 | 3761 | ''' Checks for unfinished operations and returns statecheck object |
|
3757 | 3762 | for it''' |
|
3758 | 3763 | for state in statemod._unfinishedstates: |
|
3759 | 3764 | if state.isunfinished(repo): |
|
3760 | 3765 | return state |
|
3761 | 3766 | return None |
|
3762 | 3767 | |
|
3763 | 3768 | |
|
3764 | 3769 | def howtocontinue(repo): |
|
3765 | 3770 | '''Check for an unfinished operation and return the command to finish |
|
3766 | 3771 | it. |
|
3767 | 3772 | |
|
3768 | 3773 | statemod._unfinishedstates list is checked for an unfinished operation |
|
3769 | 3774 | and the corresponding message to finish it is generated if a method to |
|
3770 | 3775 | continue is supported by the operation. |
|
3771 | 3776 | |
|
3772 | 3777 | Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is |
|
3773 | 3778 | a boolean. |
|
3774 | 3779 | ''' |
|
3775 | 3780 | contmsg = _(b"continue: %s") |
|
3776 | 3781 | for state in statemod._unfinishedstates: |
|
3777 | 3782 | if not state._continueflag: |
|
3778 | 3783 | continue |
|
3779 | 3784 | if state.isunfinished(repo): |
|
3780 | 3785 | return contmsg % state.continuemsg(), True |
|
3781 | 3786 | if repo[None].dirty(missing=True, merge=False, branch=False): |
|
3782 | 3787 | return contmsg % _(b"hg commit"), False |
|
3783 | 3788 | return None, None |
|
3784 | 3789 | |
|
3785 | 3790 | |
|
3786 | 3791 | def checkafterresolved(repo): |
|
3787 | 3792 | '''Inform the user about the next action after completing hg resolve |
|
3788 | 3793 | |
|
3789 | 3794 | If there's a an unfinished operation that supports continue flag, |
|
3790 | 3795 | howtocontinue will yield repo.ui.warn as the reporter. |
|
3791 | 3796 | |
|
3792 | 3797 | Otherwise, it will yield repo.ui.note. |
|
3793 | 3798 | ''' |
|
3794 | 3799 | msg, warning = howtocontinue(repo) |
|
3795 | 3800 | if msg is not None: |
|
3796 | 3801 | if warning: |
|
3797 | 3802 | repo.ui.warn(b"%s\n" % msg) |
|
3798 | 3803 | else: |
|
3799 | 3804 | repo.ui.note(b"%s\n" % msg) |
|
3800 | 3805 | |
|
3801 | 3806 | |
|
3802 | 3807 | def wrongtooltocontinue(repo, task): |
|
3803 | 3808 | '''Raise an abort suggesting how to properly continue if there is an |
|
3804 | 3809 | active task. |
|
3805 | 3810 | |
|
3806 | 3811 | Uses howtocontinue() to find the active task. |
|
3807 | 3812 | |
|
3808 | 3813 | If there's no task (repo.ui.note for 'hg commit'), it does not offer |
|
3809 | 3814 | a hint. |
|
3810 | 3815 | ''' |
|
3811 | 3816 | after = howtocontinue(repo) |
|
3812 | 3817 | hint = None |
|
3813 | 3818 | if after[1]: |
|
3814 | 3819 | hint = after[0] |
|
3815 | 3820 | raise error.Abort(_(b'no %s in progress') % task, hint=hint) |
|
3816 | 3821 | |
|
3817 | 3822 | |
|
3818 | 3823 | def abortgraft(ui, repo, graftstate): |
|
3819 | 3824 | """abort the interrupted graft and rollbacks to the state before interrupted |
|
3820 | 3825 | graft""" |
|
3821 | 3826 | if not graftstate.exists(): |
|
3822 | 3827 | raise error.Abort(_(b"no interrupted graft to abort")) |
|
3823 | 3828 | statedata = readgraftstate(repo, graftstate) |
|
3824 | 3829 | newnodes = statedata.get(b'newnodes') |
|
3825 | 3830 | if newnodes is None: |
|
3826 | 3831 | # and old graft state which does not have all the data required to abort |
|
3827 | 3832 | # the graft |
|
3828 | 3833 | raise error.Abort(_(b"cannot abort using an old graftstate")) |
|
3829 | 3834 | |
|
3830 | 3835 | # changeset from which graft operation was started |
|
3831 | 3836 | if len(newnodes) > 0: |
|
3832 | 3837 | startctx = repo[newnodes[0]].p1() |
|
3833 | 3838 | else: |
|
3834 | 3839 | startctx = repo[b'.'] |
|
3835 | 3840 | # whether to strip or not |
|
3836 | 3841 | cleanup = False |
|
3837 | 3842 | |
|
3838 | 3843 | if newnodes: |
|
3839 | 3844 | newnodes = [repo[r].rev() for r in newnodes] |
|
3840 | 3845 | cleanup = True |
|
3841 | 3846 | # checking that none of the newnodes turned public or is public |
|
3842 | 3847 | immutable = [c for c in newnodes if not repo[c].mutable()] |
|
3843 | 3848 | if immutable: |
|
3844 | 3849 | repo.ui.warn( |
|
3845 | 3850 | _(b"cannot clean up public changesets %s\n") |
|
3846 | 3851 | % b', '.join(bytes(repo[r]) for r in immutable), |
|
3847 | 3852 | hint=_(b"see 'hg help phases' for details"), |
|
3848 | 3853 | ) |
|
3849 | 3854 | cleanup = False |
|
3850 | 3855 | |
|
3851 | 3856 | # checking that no new nodes are created on top of grafted revs |
|
3852 | 3857 | desc = set(repo.changelog.descendants(newnodes)) |
|
3853 | 3858 | if desc - set(newnodes): |
|
3854 | 3859 | repo.ui.warn( |
|
3855 | 3860 | _( |
|
3856 | 3861 | b"new changesets detected on destination " |
|
3857 | 3862 | b"branch, can't strip\n" |
|
3858 | 3863 | ) |
|
3859 | 3864 | ) |
|
3860 | 3865 | cleanup = False |
|
3861 | 3866 | |
|
3862 | 3867 | if cleanup: |
|
3863 | 3868 | with repo.wlock(), repo.lock(): |
|
3864 | 3869 | mergemod.clean_update(startctx) |
|
3865 | 3870 | # stripping the new nodes created |
|
3866 | 3871 | strippoints = [ |
|
3867 | 3872 | c.node() for c in repo.set(b"roots(%ld)", newnodes) |
|
3868 | 3873 | ] |
|
3869 | 3874 | repair.strip(repo.ui, repo, strippoints, backup=False) |
|
3870 | 3875 | |
|
3871 | 3876 | if not cleanup: |
|
3872 | 3877 | # we don't update to the startnode if we can't strip |
|
3873 | 3878 | startctx = repo[b'.'] |
|
3874 | 3879 | mergemod.clean_update(startctx) |
|
3875 | 3880 | |
|
3876 | 3881 | ui.status(_(b"graft aborted\n")) |
|
3877 | 3882 | ui.status(_(b"working directory is now at %s\n") % startctx.hex()[:12]) |
|
3878 | 3883 | graftstate.delete() |
|
3879 | 3884 | return 0 |
|
3880 | 3885 | |
|
3881 | 3886 | |
|
3882 | 3887 | def readgraftstate(repo, graftstate): |
|
3883 | 3888 | # type: (Any, statemod.cmdstate) -> Dict[bytes, Any] |
|
3884 | 3889 | """read the graft state file and return a dict of the data stored in it""" |
|
3885 | 3890 | try: |
|
3886 | 3891 | return graftstate.read() |
|
3887 | 3892 | except error.CorruptedState: |
|
3888 | 3893 | nodes = repo.vfs.read(b'graftstate').splitlines() |
|
3889 | 3894 | return {b'nodes': nodes} |
|
3890 | 3895 | |
|
3891 | 3896 | |
|
3892 | 3897 | def hgabortgraft(ui, repo): |
|
3893 | 3898 | """ abort logic for aborting graft using 'hg abort'""" |
|
3894 | 3899 | with repo.wlock(): |
|
3895 | 3900 | graftstate = statemod.cmdstate(repo, b'graftstate') |
|
3896 | 3901 | return abortgraft(ui, repo, graftstate) |
@@ -1,7673 +1,7677 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 __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import errno |
|
11 | 11 | import os |
|
12 | 12 | import re |
|
13 | 13 | import sys |
|
14 | 14 | |
|
15 | 15 | from .i18n import _ |
|
16 | 16 | from .node import ( |
|
17 | 17 | hex, |
|
18 | 18 | nullid, |
|
19 | 19 | nullrev, |
|
20 | 20 | short, |
|
21 | 21 | wdirhex, |
|
22 | 22 | wdirrev, |
|
23 | 23 | ) |
|
24 | 24 | from .pycompat import open |
|
25 | 25 | from . import ( |
|
26 | 26 | archival, |
|
27 | 27 | bookmarks, |
|
28 | 28 | bundle2, |
|
29 | 29 | bundlecaches, |
|
30 | 30 | changegroup, |
|
31 | 31 | cmdutil, |
|
32 | 32 | copies, |
|
33 | 33 | debugcommands as debugcommandsmod, |
|
34 | 34 | destutil, |
|
35 | 35 | dirstateguard, |
|
36 | 36 | discovery, |
|
37 | 37 | encoding, |
|
38 | 38 | error, |
|
39 | 39 | exchange, |
|
40 | 40 | extensions, |
|
41 | 41 | filemerge, |
|
42 | 42 | formatter, |
|
43 | 43 | graphmod, |
|
44 | 44 | grep as grepmod, |
|
45 | 45 | hbisect, |
|
46 | 46 | help, |
|
47 | 47 | hg, |
|
48 | 48 | logcmdutil, |
|
49 | 49 | merge as mergemod, |
|
50 | 50 | mergestate as mergestatemod, |
|
51 | 51 | narrowspec, |
|
52 | 52 | obsolete, |
|
53 | 53 | obsutil, |
|
54 | 54 | patch, |
|
55 | 55 | phases, |
|
56 | 56 | pycompat, |
|
57 | 57 | rcutil, |
|
58 | 58 | registrar, |
|
59 | 59 | requirements, |
|
60 | 60 | revsetlang, |
|
61 | 61 | rewriteutil, |
|
62 | 62 | scmutil, |
|
63 | 63 | server, |
|
64 | 64 | shelve as shelvemod, |
|
65 | 65 | state as statemod, |
|
66 | 66 | streamclone, |
|
67 | 67 | tags as tagsmod, |
|
68 | 68 | ui as uimod, |
|
69 | 69 | util, |
|
70 | 70 | verify as verifymod, |
|
71 | 71 | vfs as vfsmod, |
|
72 | 72 | wireprotoserver, |
|
73 | 73 | ) |
|
74 | 74 | from .utils import ( |
|
75 | 75 | dateutil, |
|
76 | 76 | stringutil, |
|
77 | 77 | ) |
|
78 | 78 | |
|
79 | 79 | table = {} |
|
80 | 80 | table.update(debugcommandsmod.command._table) |
|
81 | 81 | |
|
82 | 82 | command = registrar.command(table) |
|
83 | 83 | INTENT_READONLY = registrar.INTENT_READONLY |
|
84 | 84 | |
|
85 | 85 | # common command options |
|
86 | 86 | |
|
87 | 87 | globalopts = [ |
|
88 | 88 | ( |
|
89 | 89 | b'R', |
|
90 | 90 | b'repository', |
|
91 | 91 | b'', |
|
92 | 92 | _(b'repository root directory or name of overlay bundle file'), |
|
93 | 93 | _(b'REPO'), |
|
94 | 94 | ), |
|
95 | 95 | (b'', b'cwd', b'', _(b'change working directory'), _(b'DIR')), |
|
96 | 96 | ( |
|
97 | 97 | b'y', |
|
98 | 98 | b'noninteractive', |
|
99 | 99 | None, |
|
100 | 100 | _( |
|
101 | 101 | b'do not prompt, automatically pick the first choice for all prompts' |
|
102 | 102 | ), |
|
103 | 103 | ), |
|
104 | 104 | (b'q', b'quiet', None, _(b'suppress output')), |
|
105 | 105 | (b'v', b'verbose', None, _(b'enable additional output')), |
|
106 | 106 | ( |
|
107 | 107 | b'', |
|
108 | 108 | b'color', |
|
109 | 109 | b'', |
|
110 | 110 | # i18n: 'always', 'auto', 'never', and 'debug' are keywords |
|
111 | 111 | # and should not be translated |
|
112 | 112 | _(b"when to colorize (boolean, always, auto, never, or debug)"), |
|
113 | 113 | _(b'TYPE'), |
|
114 | 114 | ), |
|
115 | 115 | ( |
|
116 | 116 | b'', |
|
117 | 117 | b'config', |
|
118 | 118 | [], |
|
119 | 119 | _(b'set/override config option (use \'section.name=value\')'), |
|
120 | 120 | _(b'CONFIG'), |
|
121 | 121 | ), |
|
122 | 122 | (b'', b'debug', None, _(b'enable debugging output')), |
|
123 | 123 | (b'', b'debugger', None, _(b'start debugger')), |
|
124 | 124 | ( |
|
125 | 125 | b'', |
|
126 | 126 | b'encoding', |
|
127 | 127 | encoding.encoding, |
|
128 | 128 | _(b'set the charset encoding'), |
|
129 | 129 | _(b'ENCODE'), |
|
130 | 130 | ), |
|
131 | 131 | ( |
|
132 | 132 | b'', |
|
133 | 133 | b'encodingmode', |
|
134 | 134 | encoding.encodingmode, |
|
135 | 135 | _(b'set the charset encoding mode'), |
|
136 | 136 | _(b'MODE'), |
|
137 | 137 | ), |
|
138 | 138 | (b'', b'traceback', None, _(b'always print a traceback on exception')), |
|
139 | 139 | (b'', b'time', None, _(b'time how long the command takes')), |
|
140 | 140 | (b'', b'profile', None, _(b'print command execution profile')), |
|
141 | 141 | (b'', b'version', None, _(b'output version information and exit')), |
|
142 | 142 | (b'h', b'help', None, _(b'display help and exit')), |
|
143 | 143 | (b'', b'hidden', False, _(b'consider hidden changesets')), |
|
144 | 144 | ( |
|
145 | 145 | b'', |
|
146 | 146 | b'pager', |
|
147 | 147 | b'auto', |
|
148 | 148 | _(b"when to paginate (boolean, always, auto, or never)"), |
|
149 | 149 | _(b'TYPE'), |
|
150 | 150 | ), |
|
151 | 151 | ] |
|
152 | 152 | |
|
153 | 153 | dryrunopts = cmdutil.dryrunopts |
|
154 | 154 | remoteopts = cmdutil.remoteopts |
|
155 | 155 | walkopts = cmdutil.walkopts |
|
156 | 156 | commitopts = cmdutil.commitopts |
|
157 | 157 | commitopts2 = cmdutil.commitopts2 |
|
158 | 158 | commitopts3 = cmdutil.commitopts3 |
|
159 | 159 | formatteropts = cmdutil.formatteropts |
|
160 | 160 | templateopts = cmdutil.templateopts |
|
161 | 161 | logopts = cmdutil.logopts |
|
162 | 162 | diffopts = cmdutil.diffopts |
|
163 | 163 | diffwsopts = cmdutil.diffwsopts |
|
164 | 164 | diffopts2 = cmdutil.diffopts2 |
|
165 | 165 | mergetoolopts = cmdutil.mergetoolopts |
|
166 | 166 | similarityopts = cmdutil.similarityopts |
|
167 | 167 | subrepoopts = cmdutil.subrepoopts |
|
168 | 168 | debugrevlogopts = cmdutil.debugrevlogopts |
|
169 | 169 | |
|
170 | 170 | # Commands start here, listed alphabetically |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | @command( |
|
174 | 174 | b'abort', |
|
175 | 175 | dryrunopts, |
|
176 | 176 | helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
|
177 | 177 | helpbasic=True, |
|
178 | 178 | ) |
|
179 | 179 | def abort(ui, repo, **opts): |
|
180 | 180 | """abort an unfinished operation (EXPERIMENTAL) |
|
181 | 181 | |
|
182 | 182 | Aborts a multistep operation like graft, histedit, rebase, merge, |
|
183 | 183 | and unshelve if they are in an unfinished state. |
|
184 | 184 | |
|
185 | 185 | use --dry-run/-n to dry run the command. |
|
186 | 186 | """ |
|
187 | 187 | dryrun = opts.get('dry_run') |
|
188 | 188 | abortstate = cmdutil.getunfinishedstate(repo) |
|
189 | 189 | if not abortstate: |
|
190 | 190 | raise error.Abort(_(b'no operation in progress')) |
|
191 | 191 | if not abortstate.abortfunc: |
|
192 | 192 | raise error.Abort( |
|
193 | 193 | ( |
|
194 | 194 | _(b"%s in progress but does not support 'hg abort'") |
|
195 | 195 | % (abortstate._opname) |
|
196 | 196 | ), |
|
197 | 197 | hint=abortstate.hint(), |
|
198 | 198 | ) |
|
199 | 199 | if dryrun: |
|
200 | 200 | ui.status( |
|
201 | 201 | _(b'%s in progress, will be aborted\n') % (abortstate._opname) |
|
202 | 202 | ) |
|
203 | 203 | return |
|
204 | 204 | return abortstate.abortfunc(ui, repo) |
|
205 | 205 | |
|
206 | 206 | |
|
207 | 207 | @command( |
|
208 | 208 | b'add', |
|
209 | 209 | walkopts + subrepoopts + dryrunopts, |
|
210 | 210 | _(b'[OPTION]... [FILE]...'), |
|
211 | 211 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
212 | 212 | helpbasic=True, |
|
213 | 213 | inferrepo=True, |
|
214 | 214 | ) |
|
215 | 215 | def add(ui, repo, *pats, **opts): |
|
216 | 216 | """add the specified files on the next commit |
|
217 | 217 | |
|
218 | 218 | Schedule files to be version controlled and added to the |
|
219 | 219 | repository. |
|
220 | 220 | |
|
221 | 221 | The files will be added to the repository at the next commit. To |
|
222 | 222 | undo an add before that, see :hg:`forget`. |
|
223 | 223 | |
|
224 | 224 | If no names are given, add all files to the repository (except |
|
225 | 225 | files matching ``.hgignore``). |
|
226 | 226 | |
|
227 | 227 | .. container:: verbose |
|
228 | 228 | |
|
229 | 229 | Examples: |
|
230 | 230 | |
|
231 | 231 | - New (unknown) files are added |
|
232 | 232 | automatically by :hg:`add`:: |
|
233 | 233 | |
|
234 | 234 | $ ls |
|
235 | 235 | foo.c |
|
236 | 236 | $ hg status |
|
237 | 237 | ? foo.c |
|
238 | 238 | $ hg add |
|
239 | 239 | adding foo.c |
|
240 | 240 | $ hg status |
|
241 | 241 | A foo.c |
|
242 | 242 | |
|
243 | 243 | - Specific files to be added can be specified:: |
|
244 | 244 | |
|
245 | 245 | $ ls |
|
246 | 246 | bar.c foo.c |
|
247 | 247 | $ hg status |
|
248 | 248 | ? bar.c |
|
249 | 249 | ? foo.c |
|
250 | 250 | $ hg add bar.c |
|
251 | 251 | $ hg status |
|
252 | 252 | A bar.c |
|
253 | 253 | ? foo.c |
|
254 | 254 | |
|
255 | 255 | Returns 0 if all files are successfully added. |
|
256 | 256 | """ |
|
257 | 257 | |
|
258 | 258 | m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts)) |
|
259 | 259 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
|
260 | 260 | rejected = cmdutil.add(ui, repo, m, b"", uipathfn, False, **opts) |
|
261 | 261 | return rejected and 1 or 0 |
|
262 | 262 | |
|
263 | 263 | |
|
264 | 264 | @command( |
|
265 | 265 | b'addremove', |
|
266 | 266 | similarityopts + subrepoopts + walkopts + dryrunopts, |
|
267 | 267 | _(b'[OPTION]... [FILE]...'), |
|
268 | 268 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
269 | 269 | inferrepo=True, |
|
270 | 270 | ) |
|
271 | 271 | def addremove(ui, repo, *pats, **opts): |
|
272 | 272 | """add all new files, delete all missing files |
|
273 | 273 | |
|
274 | 274 | Add all new files and remove all missing files from the |
|
275 | 275 | repository. |
|
276 | 276 | |
|
277 | 277 | Unless names are given, new files are ignored if they match any of |
|
278 | 278 | the patterns in ``.hgignore``. As with add, these changes take |
|
279 | 279 | effect at the next commit. |
|
280 | 280 | |
|
281 | 281 | Use the -s/--similarity option to detect renamed files. This |
|
282 | 282 | option takes a percentage between 0 (disabled) and 100 (files must |
|
283 | 283 | be identical) as its parameter. With a parameter greater than 0, |
|
284 | 284 | this compares every removed file with every added file and records |
|
285 | 285 | those similar enough as renames. Detecting renamed files this way |
|
286 | 286 | can be expensive. After using this option, :hg:`status -C` can be |
|
287 | 287 | used to check which files were identified as moved or renamed. If |
|
288 | 288 | not specified, -s/--similarity defaults to 100 and only renames of |
|
289 | 289 | identical files are detected. |
|
290 | 290 | |
|
291 | 291 | .. container:: verbose |
|
292 | 292 | |
|
293 | 293 | Examples: |
|
294 | 294 | |
|
295 | 295 | - A number of files (bar.c and foo.c) are new, |
|
296 | 296 | while foobar.c has been removed (without using :hg:`remove`) |
|
297 | 297 | from the repository:: |
|
298 | 298 | |
|
299 | 299 | $ ls |
|
300 | 300 | bar.c foo.c |
|
301 | 301 | $ hg status |
|
302 | 302 | ! foobar.c |
|
303 | 303 | ? bar.c |
|
304 | 304 | ? foo.c |
|
305 | 305 | $ hg addremove |
|
306 | 306 | adding bar.c |
|
307 | 307 | adding foo.c |
|
308 | 308 | removing foobar.c |
|
309 | 309 | $ hg status |
|
310 | 310 | A bar.c |
|
311 | 311 | A foo.c |
|
312 | 312 | R foobar.c |
|
313 | 313 | |
|
314 | 314 | - A file foobar.c was moved to foo.c without using :hg:`rename`. |
|
315 | 315 | Afterwards, it was edited slightly:: |
|
316 | 316 | |
|
317 | 317 | $ ls |
|
318 | 318 | foo.c |
|
319 | 319 | $ hg status |
|
320 | 320 | ! foobar.c |
|
321 | 321 | ? foo.c |
|
322 | 322 | $ hg addremove --similarity 90 |
|
323 | 323 | removing foobar.c |
|
324 | 324 | adding foo.c |
|
325 | 325 | recording removal of foobar.c as rename to foo.c (94% similar) |
|
326 | 326 | $ hg status -C |
|
327 | 327 | A foo.c |
|
328 | 328 | foobar.c |
|
329 | 329 | R foobar.c |
|
330 | 330 | |
|
331 | 331 | Returns 0 if all files are successfully added. |
|
332 | 332 | """ |
|
333 | 333 | opts = pycompat.byteskwargs(opts) |
|
334 | 334 | if not opts.get(b'similarity'): |
|
335 | 335 | opts[b'similarity'] = b'100' |
|
336 | 336 | matcher = scmutil.match(repo[None], pats, opts) |
|
337 | 337 | relative = scmutil.anypats(pats, opts) |
|
338 | 338 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=relative) |
|
339 | 339 | return scmutil.addremove(repo, matcher, b"", uipathfn, opts) |
|
340 | 340 | |
|
341 | 341 | |
|
342 | 342 | @command( |
|
343 | 343 | b'annotate|blame', |
|
344 | 344 | [ |
|
345 | 345 | (b'r', b'rev', b'', _(b'annotate the specified revision'), _(b'REV')), |
|
346 | 346 | ( |
|
347 | 347 | b'', |
|
348 | 348 | b'follow', |
|
349 | 349 | None, |
|
350 | 350 | _(b'follow copies/renames and list the filename (DEPRECATED)'), |
|
351 | 351 | ), |
|
352 | 352 | (b'', b'no-follow', None, _(b"don't follow copies and renames")), |
|
353 | 353 | (b'a', b'text', None, _(b'treat all files as text')), |
|
354 | 354 | (b'u', b'user', None, _(b'list the author (long with -v)')), |
|
355 | 355 | (b'f', b'file', None, _(b'list the filename')), |
|
356 | 356 | (b'd', b'date', None, _(b'list the date (short with -q)')), |
|
357 | 357 | (b'n', b'number', None, _(b'list the revision number (default)')), |
|
358 | 358 | (b'c', b'changeset', None, _(b'list the changeset')), |
|
359 | 359 | ( |
|
360 | 360 | b'l', |
|
361 | 361 | b'line-number', |
|
362 | 362 | None, |
|
363 | 363 | _(b'show line number at the first appearance'), |
|
364 | 364 | ), |
|
365 | 365 | ( |
|
366 | 366 | b'', |
|
367 | 367 | b'skip', |
|
368 | 368 | [], |
|
369 | 369 | _(b'revset to not display (EXPERIMENTAL)'), |
|
370 | 370 | _(b'REV'), |
|
371 | 371 | ), |
|
372 | 372 | ] |
|
373 | 373 | + diffwsopts |
|
374 | 374 | + walkopts |
|
375 | 375 | + formatteropts, |
|
376 | 376 | _(b'[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), |
|
377 | 377 | helpcategory=command.CATEGORY_FILE_CONTENTS, |
|
378 | 378 | helpbasic=True, |
|
379 | 379 | inferrepo=True, |
|
380 | 380 | ) |
|
381 | 381 | def annotate(ui, repo, *pats, **opts): |
|
382 | 382 | """show changeset information by line for each file |
|
383 | 383 | |
|
384 | 384 | List changes in files, showing the revision id responsible for |
|
385 | 385 | each line. |
|
386 | 386 | |
|
387 | 387 | This command is useful for discovering when a change was made and |
|
388 | 388 | by whom. |
|
389 | 389 | |
|
390 | 390 | If you include --file, --user, or --date, the revision number is |
|
391 | 391 | suppressed unless you also include --number. |
|
392 | 392 | |
|
393 | 393 | Without the -a/--text option, annotate will avoid processing files |
|
394 | 394 | it detects as binary. With -a, annotate will annotate the file |
|
395 | 395 | anyway, although the results will probably be neither useful |
|
396 | 396 | nor desirable. |
|
397 | 397 | |
|
398 | 398 | .. container:: verbose |
|
399 | 399 | |
|
400 | 400 | Template: |
|
401 | 401 | |
|
402 | 402 | The following keywords are supported in addition to the common template |
|
403 | 403 | keywords and functions. See also :hg:`help templates`. |
|
404 | 404 | |
|
405 | 405 | :lines: List of lines with annotation data. |
|
406 | 406 | :path: String. Repository-absolute path of the specified file. |
|
407 | 407 | |
|
408 | 408 | And each entry of ``{lines}`` provides the following sub-keywords in |
|
409 | 409 | addition to ``{date}``, ``{node}``, ``{rev}``, ``{user}``, etc. |
|
410 | 410 | |
|
411 | 411 | :line: String. Line content. |
|
412 | 412 | :lineno: Integer. Line number at that revision. |
|
413 | 413 | :path: String. Repository-absolute path of the file at that revision. |
|
414 | 414 | |
|
415 | 415 | See :hg:`help templates.operators` for the list expansion syntax. |
|
416 | 416 | |
|
417 | 417 | Returns 0 on success. |
|
418 | 418 | """ |
|
419 | 419 | opts = pycompat.byteskwargs(opts) |
|
420 | 420 | if not pats: |
|
421 | 421 | raise error.Abort(_(b'at least one filename or pattern is required')) |
|
422 | 422 | |
|
423 | 423 | if opts.get(b'follow'): |
|
424 | 424 | # --follow is deprecated and now just an alias for -f/--file |
|
425 | 425 | # to mimic the behavior of Mercurial before version 1.5 |
|
426 | 426 | opts[b'file'] = True |
|
427 | 427 | |
|
428 | 428 | if ( |
|
429 | 429 | not opts.get(b'user') |
|
430 | 430 | and not opts.get(b'changeset') |
|
431 | 431 | and not opts.get(b'date') |
|
432 | 432 | and not opts.get(b'file') |
|
433 | 433 | ): |
|
434 | 434 | opts[b'number'] = True |
|
435 | 435 | |
|
436 | 436 | linenumber = opts.get(b'line_number') is not None |
|
437 | 437 | if ( |
|
438 | 438 | linenumber |
|
439 | 439 | and (not opts.get(b'changeset')) |
|
440 | 440 | and (not opts.get(b'number')) |
|
441 | 441 | ): |
|
442 | 442 | raise error.Abort(_(b'at least one of -n/-c is required for -l')) |
|
443 | 443 | |
|
444 | 444 | rev = opts.get(b'rev') |
|
445 | 445 | if rev: |
|
446 | 446 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
447 | 447 | ctx = scmutil.revsingle(repo, rev) |
|
448 | 448 | |
|
449 | 449 | ui.pager(b'annotate') |
|
450 | 450 | rootfm = ui.formatter(b'annotate', opts) |
|
451 | 451 | if ui.debugflag: |
|
452 | 452 | shorthex = pycompat.identity |
|
453 | 453 | else: |
|
454 | 454 | |
|
455 | 455 | def shorthex(h): |
|
456 | 456 | return h[:12] |
|
457 | 457 | |
|
458 | 458 | if ui.quiet: |
|
459 | 459 | datefunc = dateutil.shortdate |
|
460 | 460 | else: |
|
461 | 461 | datefunc = dateutil.datestr |
|
462 | 462 | if ctx.rev() is None: |
|
463 | 463 | if opts.get(b'changeset'): |
|
464 | 464 | # omit "+" suffix which is appended to node hex |
|
465 | 465 | def formatrev(rev): |
|
466 | 466 | if rev == wdirrev: |
|
467 | 467 | return b'%d' % ctx.p1().rev() |
|
468 | 468 | else: |
|
469 | 469 | return b'%d' % rev |
|
470 | 470 | |
|
471 | 471 | else: |
|
472 | 472 | |
|
473 | 473 | def formatrev(rev): |
|
474 | 474 | if rev == wdirrev: |
|
475 | 475 | return b'%d+' % ctx.p1().rev() |
|
476 | 476 | else: |
|
477 | 477 | return b'%d ' % rev |
|
478 | 478 | |
|
479 | 479 | def formathex(h): |
|
480 | 480 | if h == wdirhex: |
|
481 | 481 | return b'%s+' % shorthex(hex(ctx.p1().node())) |
|
482 | 482 | else: |
|
483 | 483 | return b'%s ' % shorthex(h) |
|
484 | 484 | |
|
485 | 485 | else: |
|
486 | 486 | formatrev = b'%d'.__mod__ |
|
487 | 487 | formathex = shorthex |
|
488 | 488 | |
|
489 | 489 | opmap = [ |
|
490 | 490 | (b'user', b' ', lambda x: x.fctx.user(), ui.shortuser), |
|
491 | 491 | (b'rev', b' ', lambda x: scmutil.intrev(x.fctx), formatrev), |
|
492 | 492 | (b'node', b' ', lambda x: hex(scmutil.binnode(x.fctx)), formathex), |
|
493 | 493 | (b'date', b' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)), |
|
494 | 494 | (b'path', b' ', lambda x: x.fctx.path(), pycompat.bytestr), |
|
495 | 495 | (b'lineno', b':', lambda x: x.lineno, pycompat.bytestr), |
|
496 | 496 | ] |
|
497 | 497 | opnamemap = { |
|
498 | 498 | b'rev': b'number', |
|
499 | 499 | b'node': b'changeset', |
|
500 | 500 | b'path': b'file', |
|
501 | 501 | b'lineno': b'line_number', |
|
502 | 502 | } |
|
503 | 503 | |
|
504 | 504 | if rootfm.isplain(): |
|
505 | 505 | |
|
506 | 506 | def makefunc(get, fmt): |
|
507 | 507 | return lambda x: fmt(get(x)) |
|
508 | 508 | |
|
509 | 509 | else: |
|
510 | 510 | |
|
511 | 511 | def makefunc(get, fmt): |
|
512 | 512 | return get |
|
513 | 513 | |
|
514 | 514 | datahint = rootfm.datahint() |
|
515 | 515 | funcmap = [ |
|
516 | 516 | (makefunc(get, fmt), sep) |
|
517 | 517 | for fn, sep, get, fmt in opmap |
|
518 | 518 | if opts.get(opnamemap.get(fn, fn)) or fn in datahint |
|
519 | 519 | ] |
|
520 | 520 | funcmap[0] = (funcmap[0][0], b'') # no separator in front of first column |
|
521 | 521 | fields = b' '.join( |
|
522 | 522 | fn |
|
523 | 523 | for fn, sep, get, fmt in opmap |
|
524 | 524 | if opts.get(opnamemap.get(fn, fn)) or fn in datahint |
|
525 | 525 | ) |
|
526 | 526 | |
|
527 | 527 | def bad(x, y): |
|
528 | 528 | raise error.Abort(b"%s: %s" % (x, y)) |
|
529 | 529 | |
|
530 | 530 | m = scmutil.match(ctx, pats, opts, badfn=bad) |
|
531 | 531 | |
|
532 | 532 | follow = not opts.get(b'no_follow') |
|
533 | 533 | diffopts = patch.difffeatureopts( |
|
534 | 534 | ui, opts, section=b'annotate', whitespace=True |
|
535 | 535 | ) |
|
536 | 536 | skiprevs = opts.get(b'skip') |
|
537 | 537 | if skiprevs: |
|
538 | 538 | skiprevs = scmutil.revrange(repo, skiprevs) |
|
539 | 539 | |
|
540 | 540 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
|
541 | 541 | for abs in ctx.walk(m): |
|
542 | 542 | fctx = ctx[abs] |
|
543 | 543 | rootfm.startitem() |
|
544 | 544 | rootfm.data(path=abs) |
|
545 | 545 | if not opts.get(b'text') and fctx.isbinary(): |
|
546 | 546 | rootfm.plain(_(b"%s: binary file\n") % uipathfn(abs)) |
|
547 | 547 | continue |
|
548 | 548 | |
|
549 | 549 | fm = rootfm.nested(b'lines', tmpl=b'{rev}: {line}') |
|
550 | 550 | lines = fctx.annotate( |
|
551 | 551 | follow=follow, skiprevs=skiprevs, diffopts=diffopts |
|
552 | 552 | ) |
|
553 | 553 | if not lines: |
|
554 | 554 | fm.end() |
|
555 | 555 | continue |
|
556 | 556 | formats = [] |
|
557 | 557 | pieces = [] |
|
558 | 558 | |
|
559 | 559 | for f, sep in funcmap: |
|
560 | 560 | l = [f(n) for n in lines] |
|
561 | 561 | if fm.isplain(): |
|
562 | 562 | sizes = [encoding.colwidth(x) for x in l] |
|
563 | 563 | ml = max(sizes) |
|
564 | 564 | formats.append([sep + b' ' * (ml - w) + b'%s' for w in sizes]) |
|
565 | 565 | else: |
|
566 | 566 | formats.append([b'%s'] * len(l)) |
|
567 | 567 | pieces.append(l) |
|
568 | 568 | |
|
569 | 569 | for f, p, n in zip(zip(*formats), zip(*pieces), lines): |
|
570 | 570 | fm.startitem() |
|
571 | 571 | fm.context(fctx=n.fctx) |
|
572 | 572 | fm.write(fields, b"".join(f), *p) |
|
573 | 573 | if n.skip: |
|
574 | 574 | fmt = b"* %s" |
|
575 | 575 | else: |
|
576 | 576 | fmt = b": %s" |
|
577 | 577 | fm.write(b'line', fmt, n.text) |
|
578 | 578 | |
|
579 | 579 | if not lines[-1].text.endswith(b'\n'): |
|
580 | 580 | fm.plain(b'\n') |
|
581 | 581 | fm.end() |
|
582 | 582 | |
|
583 | 583 | rootfm.end() |
|
584 | 584 | |
|
585 | 585 | |
|
586 | 586 | @command( |
|
587 | 587 | b'archive', |
|
588 | 588 | [ |
|
589 | 589 | (b'', b'no-decode', None, _(b'do not pass files through decoders')), |
|
590 | 590 | ( |
|
591 | 591 | b'p', |
|
592 | 592 | b'prefix', |
|
593 | 593 | b'', |
|
594 | 594 | _(b'directory prefix for files in archive'), |
|
595 | 595 | _(b'PREFIX'), |
|
596 | 596 | ), |
|
597 | 597 | (b'r', b'rev', b'', _(b'revision to distribute'), _(b'REV')), |
|
598 | 598 | (b't', b'type', b'', _(b'type of distribution to create'), _(b'TYPE')), |
|
599 | 599 | ] |
|
600 | 600 | + subrepoopts |
|
601 | 601 | + walkopts, |
|
602 | 602 | _(b'[OPTION]... DEST'), |
|
603 | 603 | helpcategory=command.CATEGORY_IMPORT_EXPORT, |
|
604 | 604 | ) |
|
605 | 605 | def archive(ui, repo, dest, **opts): |
|
606 | 606 | '''create an unversioned archive of a repository revision |
|
607 | 607 | |
|
608 | 608 | By default, the revision used is the parent of the working |
|
609 | 609 | directory; use -r/--rev to specify a different revision. |
|
610 | 610 | |
|
611 | 611 | The archive type is automatically detected based on file |
|
612 | 612 | extension (to override, use -t/--type). |
|
613 | 613 | |
|
614 | 614 | .. container:: verbose |
|
615 | 615 | |
|
616 | 616 | Examples: |
|
617 | 617 | |
|
618 | 618 | - create a zip file containing the 1.0 release:: |
|
619 | 619 | |
|
620 | 620 | hg archive -r 1.0 project-1.0.zip |
|
621 | 621 | |
|
622 | 622 | - create a tarball excluding .hg files:: |
|
623 | 623 | |
|
624 | 624 | hg archive project.tar.gz -X ".hg*" |
|
625 | 625 | |
|
626 | 626 | Valid types are: |
|
627 | 627 | |
|
628 | 628 | :``files``: a directory full of files (default) |
|
629 | 629 | :``tar``: tar archive, uncompressed |
|
630 | 630 | :``tbz2``: tar archive, compressed using bzip2 |
|
631 | 631 | :``tgz``: tar archive, compressed using gzip |
|
632 | 632 | :``txz``: tar archive, compressed using lzma (only in Python 3) |
|
633 | 633 | :``uzip``: zip archive, uncompressed |
|
634 | 634 | :``zip``: zip archive, compressed using deflate |
|
635 | 635 | |
|
636 | 636 | The exact name of the destination archive or directory is given |
|
637 | 637 | using a format string; see :hg:`help export` for details. |
|
638 | 638 | |
|
639 | 639 | Each member added to an archive file has a directory prefix |
|
640 | 640 | prepended. Use -p/--prefix to specify a format string for the |
|
641 | 641 | prefix. The default is the basename of the archive, with suffixes |
|
642 | 642 | removed. |
|
643 | 643 | |
|
644 | 644 | Returns 0 on success. |
|
645 | 645 | ''' |
|
646 | 646 | |
|
647 | 647 | opts = pycompat.byteskwargs(opts) |
|
648 | 648 | rev = opts.get(b'rev') |
|
649 | 649 | if rev: |
|
650 | 650 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
651 | 651 | ctx = scmutil.revsingle(repo, rev) |
|
652 | 652 | if not ctx: |
|
653 | 653 | raise error.Abort(_(b'no working directory: please specify a revision')) |
|
654 | 654 | node = ctx.node() |
|
655 | 655 | dest = cmdutil.makefilename(ctx, dest) |
|
656 | 656 | if os.path.realpath(dest) == repo.root: |
|
657 | 657 | raise error.Abort(_(b'repository root cannot be destination')) |
|
658 | 658 | |
|
659 | 659 | kind = opts.get(b'type') or archival.guesskind(dest) or b'files' |
|
660 | 660 | prefix = opts.get(b'prefix') |
|
661 | 661 | |
|
662 | 662 | if dest == b'-': |
|
663 | 663 | if kind == b'files': |
|
664 | 664 | raise error.Abort(_(b'cannot archive plain files to stdout')) |
|
665 | 665 | dest = cmdutil.makefileobj(ctx, dest) |
|
666 | 666 | if not prefix: |
|
667 | 667 | prefix = os.path.basename(repo.root) + b'-%h' |
|
668 | 668 | |
|
669 | 669 | prefix = cmdutil.makefilename(ctx, prefix) |
|
670 | 670 | match = scmutil.match(ctx, [], opts) |
|
671 | 671 | archival.archive( |
|
672 | 672 | repo, |
|
673 | 673 | dest, |
|
674 | 674 | node, |
|
675 | 675 | kind, |
|
676 | 676 | not opts.get(b'no_decode'), |
|
677 | 677 | match, |
|
678 | 678 | prefix, |
|
679 | 679 | subrepos=opts.get(b'subrepos'), |
|
680 | 680 | ) |
|
681 | 681 | |
|
682 | 682 | |
|
683 | 683 | @command( |
|
684 | 684 | b'backout', |
|
685 | 685 | [ |
|
686 | 686 | ( |
|
687 | 687 | b'', |
|
688 | 688 | b'merge', |
|
689 | 689 | None, |
|
690 | 690 | _(b'merge with old dirstate parent after backout'), |
|
691 | 691 | ), |
|
692 | 692 | ( |
|
693 | 693 | b'', |
|
694 | 694 | b'commit', |
|
695 | 695 | None, |
|
696 | 696 | _(b'commit if no conflicts were encountered (DEPRECATED)'), |
|
697 | 697 | ), |
|
698 | 698 | (b'', b'no-commit', None, _(b'do not commit')), |
|
699 | 699 | ( |
|
700 | 700 | b'', |
|
701 | 701 | b'parent', |
|
702 | 702 | b'', |
|
703 | 703 | _(b'parent to choose when backing out merge (DEPRECATED)'), |
|
704 | 704 | _(b'REV'), |
|
705 | 705 | ), |
|
706 | 706 | (b'r', b'rev', b'', _(b'revision to backout'), _(b'REV')), |
|
707 | 707 | (b'e', b'edit', False, _(b'invoke editor on commit messages')), |
|
708 | 708 | ] |
|
709 | 709 | + mergetoolopts |
|
710 | 710 | + walkopts |
|
711 | 711 | + commitopts |
|
712 | 712 | + commitopts2, |
|
713 | 713 | _(b'[OPTION]... [-r] REV'), |
|
714 | 714 | helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
|
715 | 715 | ) |
|
716 | 716 | def backout(ui, repo, node=None, rev=None, **opts): |
|
717 | 717 | '''reverse effect of earlier changeset |
|
718 | 718 | |
|
719 | 719 | Prepare a new changeset with the effect of REV undone in the |
|
720 | 720 | current working directory. If no conflicts were encountered, |
|
721 | 721 | it will be committed immediately. |
|
722 | 722 | |
|
723 | 723 | If REV is the parent of the working directory, then this new changeset |
|
724 | 724 | is committed automatically (unless --no-commit is specified). |
|
725 | 725 | |
|
726 | 726 | .. note:: |
|
727 | 727 | |
|
728 | 728 | :hg:`backout` cannot be used to fix either an unwanted or |
|
729 | 729 | incorrect merge. |
|
730 | 730 | |
|
731 | 731 | .. container:: verbose |
|
732 | 732 | |
|
733 | 733 | Examples: |
|
734 | 734 | |
|
735 | 735 | - Reverse the effect of the parent of the working directory. |
|
736 | 736 | This backout will be committed immediately:: |
|
737 | 737 | |
|
738 | 738 | hg backout -r . |
|
739 | 739 | |
|
740 | 740 | - Reverse the effect of previous bad revision 23:: |
|
741 | 741 | |
|
742 | 742 | hg backout -r 23 |
|
743 | 743 | |
|
744 | 744 | - Reverse the effect of previous bad revision 23 and |
|
745 | 745 | leave changes uncommitted:: |
|
746 | 746 | |
|
747 | 747 | hg backout -r 23 --no-commit |
|
748 | 748 | hg commit -m "Backout revision 23" |
|
749 | 749 | |
|
750 | 750 | By default, the pending changeset will have one parent, |
|
751 | 751 | maintaining a linear history. With --merge, the pending |
|
752 | 752 | changeset will instead have two parents: the old parent of the |
|
753 | 753 | working directory and a new child of REV that simply undoes REV. |
|
754 | 754 | |
|
755 | 755 | Before version 1.7, the behavior without --merge was equivalent |
|
756 | 756 | to specifying --merge followed by :hg:`update --clean .` to |
|
757 | 757 | cancel the merge and leave the child of REV as a head to be |
|
758 | 758 | merged separately. |
|
759 | 759 | |
|
760 | 760 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
761 | 761 | |
|
762 | 762 | See :hg:`help revert` for a way to restore files to the state |
|
763 | 763 | of another revision. |
|
764 | 764 | |
|
765 | 765 | Returns 0 on success, 1 if nothing to backout or there are unresolved |
|
766 | 766 | files. |
|
767 | 767 | ''' |
|
768 | 768 | with repo.wlock(), repo.lock(): |
|
769 | 769 | return _dobackout(ui, repo, node, rev, **opts) |
|
770 | 770 | |
|
771 | 771 | |
|
772 | 772 | def _dobackout(ui, repo, node=None, rev=None, **opts): |
|
773 | 773 | cmdutil.check_incompatible_arguments(opts, 'no_commit', ['commit', 'merge']) |
|
774 | 774 | opts = pycompat.byteskwargs(opts) |
|
775 | 775 | |
|
776 | 776 | if rev and node: |
|
777 | 777 | raise error.Abort(_(b"please specify just one revision")) |
|
778 | 778 | |
|
779 | 779 | if not rev: |
|
780 | 780 | rev = node |
|
781 | 781 | |
|
782 | 782 | if not rev: |
|
783 | 783 | raise error.Abort(_(b"please specify a revision to backout")) |
|
784 | 784 | |
|
785 | 785 | date = opts.get(b'date') |
|
786 | 786 | if date: |
|
787 | 787 | opts[b'date'] = dateutil.parsedate(date) |
|
788 | 788 | |
|
789 | 789 | cmdutil.checkunfinished(repo) |
|
790 | 790 | cmdutil.bailifchanged(repo) |
|
791 | 791 | ctx = scmutil.revsingle(repo, rev) |
|
792 | 792 | node = ctx.node() |
|
793 | 793 | |
|
794 | 794 | op1, op2 = repo.dirstate.parents() |
|
795 | 795 | if not repo.changelog.isancestor(node, op1): |
|
796 | 796 | raise error.Abort(_(b'cannot backout change that is not an ancestor')) |
|
797 | 797 | |
|
798 | 798 | p1, p2 = repo.changelog.parents(node) |
|
799 | 799 | if p1 == nullid: |
|
800 | 800 | raise error.Abort(_(b'cannot backout a change with no parents')) |
|
801 | 801 | if p2 != nullid: |
|
802 | 802 | if not opts.get(b'parent'): |
|
803 | 803 | raise error.Abort(_(b'cannot backout a merge changeset')) |
|
804 | 804 | p = repo.lookup(opts[b'parent']) |
|
805 | 805 | if p not in (p1, p2): |
|
806 | 806 | raise error.Abort( |
|
807 | 807 | _(b'%s is not a parent of %s') % (short(p), short(node)) |
|
808 | 808 | ) |
|
809 | 809 | parent = p |
|
810 | 810 | else: |
|
811 | 811 | if opts.get(b'parent'): |
|
812 | 812 | raise error.Abort(_(b'cannot use --parent on non-merge changeset')) |
|
813 | 813 | parent = p1 |
|
814 | 814 | |
|
815 | 815 | # the backout should appear on the same branch |
|
816 | 816 | branch = repo.dirstate.branch() |
|
817 | 817 | bheads = repo.branchheads(branch) |
|
818 | 818 | rctx = scmutil.revsingle(repo, hex(parent)) |
|
819 | 819 | if not opts.get(b'merge') and op1 != node: |
|
820 | 820 | with dirstateguard.dirstateguard(repo, b'backout'): |
|
821 | 821 | overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')} |
|
822 | 822 | with ui.configoverride(overrides, b'backout'): |
|
823 | 823 | stats = mergemod.back_out(ctx, parent=repo[parent]) |
|
824 | 824 | repo.setparents(op1, op2) |
|
825 | 825 | hg._showstats(repo, stats) |
|
826 | 826 | if stats.unresolvedcount: |
|
827 | 827 | repo.ui.status( |
|
828 | 828 | _(b"use 'hg resolve' to retry unresolved file merges\n") |
|
829 | 829 | ) |
|
830 | 830 | return 1 |
|
831 | 831 | else: |
|
832 | 832 | hg.clean(repo, node, show_stats=False) |
|
833 | 833 | repo.dirstate.setbranch(branch) |
|
834 | 834 | cmdutil.revert(ui, repo, rctx) |
|
835 | 835 | |
|
836 | 836 | if opts.get(b'no_commit'): |
|
837 | 837 | msg = _(b"changeset %s backed out, don't forget to commit.\n") |
|
838 | 838 | ui.status(msg % short(node)) |
|
839 | 839 | return 0 |
|
840 | 840 | |
|
841 | 841 | def commitfunc(ui, repo, message, match, opts): |
|
842 | 842 | editform = b'backout' |
|
843 | 843 | e = cmdutil.getcommiteditor( |
|
844 | 844 | editform=editform, **pycompat.strkwargs(opts) |
|
845 | 845 | ) |
|
846 | 846 | if not message: |
|
847 | 847 | # we don't translate commit messages |
|
848 | 848 | message = b"Backed out changeset %s" % short(node) |
|
849 | 849 | e = cmdutil.getcommiteditor(edit=True, editform=editform) |
|
850 | 850 | return repo.commit( |
|
851 | 851 | message, opts.get(b'user'), opts.get(b'date'), match, editor=e |
|
852 | 852 | ) |
|
853 | 853 | |
|
854 | # save to detect changes | |
|
855 | tip = repo.changelog.tip() | |
|
856 | ||
|
854 | 857 | newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) |
|
855 | 858 | if not newnode: |
|
856 | 859 | ui.status(_(b"nothing changed\n")) |
|
857 | 860 | return 1 |
|
858 | cmdutil.commitstatus(repo, newnode, branch, bheads) | |
|
861 | cmdutil.commitstatus(repo, newnode, branch, bheads, tip) | |
|
859 | 862 | |
|
860 | 863 | def nice(node): |
|
861 | 864 | return b'%d:%s' % (repo.changelog.rev(node), short(node)) |
|
862 | 865 | |
|
863 | 866 | ui.status( |
|
864 | 867 | _(b'changeset %s backs out changeset %s\n') |
|
865 | 868 | % (nice(newnode), nice(node)) |
|
866 | 869 | ) |
|
867 | 870 | if opts.get(b'merge') and op1 != node: |
|
868 | 871 | hg.clean(repo, op1, show_stats=False) |
|
869 | 872 | ui.status(_(b'merging with changeset %s\n') % nice(newnode)) |
|
870 | 873 | overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')} |
|
871 | 874 | with ui.configoverride(overrides, b'backout'): |
|
872 | 875 | return hg.merge(repo[b'tip']) |
|
873 | 876 | return 0 |
|
874 | 877 | |
|
875 | 878 | |
|
876 | 879 | @command( |
|
877 | 880 | b'bisect', |
|
878 | 881 | [ |
|
879 | 882 | (b'r', b'reset', False, _(b'reset bisect state')), |
|
880 | 883 | (b'g', b'good', False, _(b'mark changeset good')), |
|
881 | 884 | (b'b', b'bad', False, _(b'mark changeset bad')), |
|
882 | 885 | (b's', b'skip', False, _(b'skip testing changeset')), |
|
883 | 886 | (b'e', b'extend', False, _(b'extend the bisect range')), |
|
884 | 887 | ( |
|
885 | 888 | b'c', |
|
886 | 889 | b'command', |
|
887 | 890 | b'', |
|
888 | 891 | _(b'use command to check changeset state'), |
|
889 | 892 | _(b'CMD'), |
|
890 | 893 | ), |
|
891 | 894 | (b'U', b'noupdate', False, _(b'do not update to target')), |
|
892 | 895 | ], |
|
893 | 896 | _(b"[-gbsr] [-U] [-c CMD] [REV]"), |
|
894 | 897 | helpcategory=command.CATEGORY_CHANGE_NAVIGATION, |
|
895 | 898 | ) |
|
896 | 899 | def bisect( |
|
897 | 900 | ui, |
|
898 | 901 | repo, |
|
899 | 902 | rev=None, |
|
900 | 903 | extra=None, |
|
901 | 904 | command=None, |
|
902 | 905 | reset=None, |
|
903 | 906 | good=None, |
|
904 | 907 | bad=None, |
|
905 | 908 | skip=None, |
|
906 | 909 | extend=None, |
|
907 | 910 | noupdate=None, |
|
908 | 911 | ): |
|
909 | 912 | """subdivision search of changesets |
|
910 | 913 | |
|
911 | 914 | This command helps to find changesets which introduce problems. To |
|
912 | 915 | use, mark the earliest changeset you know exhibits the problem as |
|
913 | 916 | bad, then mark the latest changeset which is free from the problem |
|
914 | 917 | as good. Bisect will update your working directory to a revision |
|
915 | 918 | for testing (unless the -U/--noupdate option is specified). Once |
|
916 | 919 | you have performed tests, mark the working directory as good or |
|
917 | 920 | bad, and bisect will either update to another candidate changeset |
|
918 | 921 | or announce that it has found the bad revision. |
|
919 | 922 | |
|
920 | 923 | As a shortcut, you can also use the revision argument to mark a |
|
921 | 924 | revision as good or bad without checking it out first. |
|
922 | 925 | |
|
923 | 926 | If you supply a command, it will be used for automatic bisection. |
|
924 | 927 | The environment variable HG_NODE will contain the ID of the |
|
925 | 928 | changeset being tested. The exit status of the command will be |
|
926 | 929 | used to mark revisions as good or bad: status 0 means good, 125 |
|
927 | 930 | means to skip the revision, 127 (command not found) will abort the |
|
928 | 931 | bisection, and any other non-zero exit status means the revision |
|
929 | 932 | is bad. |
|
930 | 933 | |
|
931 | 934 | .. container:: verbose |
|
932 | 935 | |
|
933 | 936 | Some examples: |
|
934 | 937 | |
|
935 | 938 | - start a bisection with known bad revision 34, and good revision 12:: |
|
936 | 939 | |
|
937 | 940 | hg bisect --bad 34 |
|
938 | 941 | hg bisect --good 12 |
|
939 | 942 | |
|
940 | 943 | - advance the current bisection by marking current revision as good or |
|
941 | 944 | bad:: |
|
942 | 945 | |
|
943 | 946 | hg bisect --good |
|
944 | 947 | hg bisect --bad |
|
945 | 948 | |
|
946 | 949 | - mark the current revision, or a known revision, to be skipped (e.g. if |
|
947 | 950 | that revision is not usable because of another issue):: |
|
948 | 951 | |
|
949 | 952 | hg bisect --skip |
|
950 | 953 | hg bisect --skip 23 |
|
951 | 954 | |
|
952 | 955 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: |
|
953 | 956 | |
|
954 | 957 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" |
|
955 | 958 | |
|
956 | 959 | - forget the current bisection:: |
|
957 | 960 | |
|
958 | 961 | hg bisect --reset |
|
959 | 962 | |
|
960 | 963 | - use 'make && make tests' to automatically find the first broken |
|
961 | 964 | revision:: |
|
962 | 965 | |
|
963 | 966 | hg bisect --reset |
|
964 | 967 | hg bisect --bad 34 |
|
965 | 968 | hg bisect --good 12 |
|
966 | 969 | hg bisect --command "make && make tests" |
|
967 | 970 | |
|
968 | 971 | - see all changesets whose states are already known in the current |
|
969 | 972 | bisection:: |
|
970 | 973 | |
|
971 | 974 | hg log -r "bisect(pruned)" |
|
972 | 975 | |
|
973 | 976 | - see the changeset currently being bisected (especially useful |
|
974 | 977 | if running with -U/--noupdate):: |
|
975 | 978 | |
|
976 | 979 | hg log -r "bisect(current)" |
|
977 | 980 | |
|
978 | 981 | - see all changesets that took part in the current bisection:: |
|
979 | 982 | |
|
980 | 983 | hg log -r "bisect(range)" |
|
981 | 984 | |
|
982 | 985 | - you can even get a nice graph:: |
|
983 | 986 | |
|
984 | 987 | hg log --graph -r "bisect(range)" |
|
985 | 988 | |
|
986 | 989 | See :hg:`help revisions.bisect` for more about the `bisect()` predicate. |
|
987 | 990 | |
|
988 | 991 | Returns 0 on success. |
|
989 | 992 | """ |
|
990 | 993 | # backward compatibility |
|
991 | 994 | if rev in b"good bad reset init".split(): |
|
992 | 995 | ui.warn(_(b"(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
993 | 996 | cmd, rev, extra = rev, extra, None |
|
994 | 997 | if cmd == b"good": |
|
995 | 998 | good = True |
|
996 | 999 | elif cmd == b"bad": |
|
997 | 1000 | bad = True |
|
998 | 1001 | else: |
|
999 | 1002 | reset = True |
|
1000 | 1003 | elif extra: |
|
1001 | 1004 | raise error.Abort(_(b'incompatible arguments')) |
|
1002 | 1005 | |
|
1003 | 1006 | incompatibles = { |
|
1004 | 1007 | b'--bad': bad, |
|
1005 | 1008 | b'--command': bool(command), |
|
1006 | 1009 | b'--extend': extend, |
|
1007 | 1010 | b'--good': good, |
|
1008 | 1011 | b'--reset': reset, |
|
1009 | 1012 | b'--skip': skip, |
|
1010 | 1013 | } |
|
1011 | 1014 | |
|
1012 | 1015 | enabled = [x for x in incompatibles if incompatibles[x]] |
|
1013 | 1016 | |
|
1014 | 1017 | if len(enabled) > 1: |
|
1015 | 1018 | raise error.Abort( |
|
1016 | 1019 | _(b'%s and %s are incompatible') % tuple(sorted(enabled)[0:2]) |
|
1017 | 1020 | ) |
|
1018 | 1021 | |
|
1019 | 1022 | if reset: |
|
1020 | 1023 | hbisect.resetstate(repo) |
|
1021 | 1024 | return |
|
1022 | 1025 | |
|
1023 | 1026 | state = hbisect.load_state(repo) |
|
1024 | 1027 | |
|
1025 | 1028 | # update state |
|
1026 | 1029 | if good or bad or skip: |
|
1027 | 1030 | if rev: |
|
1028 | 1031 | nodes = [repo[i].node() for i in scmutil.revrange(repo, [rev])] |
|
1029 | 1032 | else: |
|
1030 | 1033 | nodes = [repo.lookup(b'.')] |
|
1031 | 1034 | if good: |
|
1032 | 1035 | state[b'good'] += nodes |
|
1033 | 1036 | elif bad: |
|
1034 | 1037 | state[b'bad'] += nodes |
|
1035 | 1038 | elif skip: |
|
1036 | 1039 | state[b'skip'] += nodes |
|
1037 | 1040 | hbisect.save_state(repo, state) |
|
1038 | 1041 | if not (state[b'good'] and state[b'bad']): |
|
1039 | 1042 | return |
|
1040 | 1043 | |
|
1041 | 1044 | def mayupdate(repo, node, show_stats=True): |
|
1042 | 1045 | """common used update sequence""" |
|
1043 | 1046 | if noupdate: |
|
1044 | 1047 | return |
|
1045 | 1048 | cmdutil.checkunfinished(repo) |
|
1046 | 1049 | cmdutil.bailifchanged(repo) |
|
1047 | 1050 | return hg.clean(repo, node, show_stats=show_stats) |
|
1048 | 1051 | |
|
1049 | 1052 | displayer = logcmdutil.changesetdisplayer(ui, repo, {}) |
|
1050 | 1053 | |
|
1051 | 1054 | if command: |
|
1052 | 1055 | changesets = 1 |
|
1053 | 1056 | if noupdate: |
|
1054 | 1057 | try: |
|
1055 | 1058 | node = state[b'current'][0] |
|
1056 | 1059 | except LookupError: |
|
1057 | 1060 | raise error.Abort( |
|
1058 | 1061 | _( |
|
1059 | 1062 | b'current bisect revision is unknown - ' |
|
1060 | 1063 | b'start a new bisect to fix' |
|
1061 | 1064 | ) |
|
1062 | 1065 | ) |
|
1063 | 1066 | else: |
|
1064 | 1067 | node, p2 = repo.dirstate.parents() |
|
1065 | 1068 | if p2 != nullid: |
|
1066 | 1069 | raise error.Abort(_(b'current bisect revision is a merge')) |
|
1067 | 1070 | if rev: |
|
1068 | 1071 | node = repo[scmutil.revsingle(repo, rev, node)].node() |
|
1069 | 1072 | with hbisect.restore_state(repo, state, node): |
|
1070 | 1073 | while changesets: |
|
1071 | 1074 | # update state |
|
1072 | 1075 | state[b'current'] = [node] |
|
1073 | 1076 | hbisect.save_state(repo, state) |
|
1074 | 1077 | status = ui.system( |
|
1075 | 1078 | command, |
|
1076 | 1079 | environ={b'HG_NODE': hex(node)}, |
|
1077 | 1080 | blockedtag=b'bisect_check', |
|
1078 | 1081 | ) |
|
1079 | 1082 | if status == 125: |
|
1080 | 1083 | transition = b"skip" |
|
1081 | 1084 | elif status == 0: |
|
1082 | 1085 | transition = b"good" |
|
1083 | 1086 | # status < 0 means process was killed |
|
1084 | 1087 | elif status == 127: |
|
1085 | 1088 | raise error.Abort(_(b"failed to execute %s") % command) |
|
1086 | 1089 | elif status < 0: |
|
1087 | 1090 | raise error.Abort(_(b"%s killed") % command) |
|
1088 | 1091 | else: |
|
1089 | 1092 | transition = b"bad" |
|
1090 | 1093 | state[transition].append(node) |
|
1091 | 1094 | ctx = repo[node] |
|
1092 | 1095 | ui.status( |
|
1093 | 1096 | _(b'changeset %d:%s: %s\n') % (ctx.rev(), ctx, transition) |
|
1094 | 1097 | ) |
|
1095 | 1098 | hbisect.checkstate(state) |
|
1096 | 1099 | # bisect |
|
1097 | 1100 | nodes, changesets, bgood = hbisect.bisect(repo, state) |
|
1098 | 1101 | # update to next check |
|
1099 | 1102 | node = nodes[0] |
|
1100 | 1103 | mayupdate(repo, node, show_stats=False) |
|
1101 | 1104 | hbisect.printresult(ui, repo, state, displayer, nodes, bgood) |
|
1102 | 1105 | return |
|
1103 | 1106 | |
|
1104 | 1107 | hbisect.checkstate(state) |
|
1105 | 1108 | |
|
1106 | 1109 | # actually bisect |
|
1107 | 1110 | nodes, changesets, good = hbisect.bisect(repo, state) |
|
1108 | 1111 | if extend: |
|
1109 | 1112 | if not changesets: |
|
1110 | 1113 | extendnode = hbisect.extendrange(repo, state, nodes, good) |
|
1111 | 1114 | if extendnode is not None: |
|
1112 | 1115 | ui.write( |
|
1113 | 1116 | _(b"Extending search to changeset %d:%s\n") |
|
1114 | 1117 | % (extendnode.rev(), extendnode) |
|
1115 | 1118 | ) |
|
1116 | 1119 | state[b'current'] = [extendnode.node()] |
|
1117 | 1120 | hbisect.save_state(repo, state) |
|
1118 | 1121 | return mayupdate(repo, extendnode.node()) |
|
1119 | 1122 | raise error.Abort(_(b"nothing to extend")) |
|
1120 | 1123 | |
|
1121 | 1124 | if changesets == 0: |
|
1122 | 1125 | hbisect.printresult(ui, repo, state, displayer, nodes, good) |
|
1123 | 1126 | else: |
|
1124 | 1127 | assert len(nodes) == 1 # only a single node can be tested next |
|
1125 | 1128 | node = nodes[0] |
|
1126 | 1129 | # compute the approximate number of remaining tests |
|
1127 | 1130 | tests, size = 0, 2 |
|
1128 | 1131 | while size <= changesets: |
|
1129 | 1132 | tests, size = tests + 1, size * 2 |
|
1130 | 1133 | rev = repo.changelog.rev(node) |
|
1131 | 1134 | ui.write( |
|
1132 | 1135 | _( |
|
1133 | 1136 | b"Testing changeset %d:%s " |
|
1134 | 1137 | b"(%d changesets remaining, ~%d tests)\n" |
|
1135 | 1138 | ) |
|
1136 | 1139 | % (rev, short(node), changesets, tests) |
|
1137 | 1140 | ) |
|
1138 | 1141 | state[b'current'] = [node] |
|
1139 | 1142 | hbisect.save_state(repo, state) |
|
1140 | 1143 | return mayupdate(repo, node) |
|
1141 | 1144 | |
|
1142 | 1145 | |
|
1143 | 1146 | @command( |
|
1144 | 1147 | b'bookmarks|bookmark', |
|
1145 | 1148 | [ |
|
1146 | 1149 | (b'f', b'force', False, _(b'force')), |
|
1147 | 1150 | (b'r', b'rev', b'', _(b'revision for bookmark action'), _(b'REV')), |
|
1148 | 1151 | (b'd', b'delete', False, _(b'delete a given bookmark')), |
|
1149 | 1152 | (b'm', b'rename', b'', _(b'rename a given bookmark'), _(b'OLD')), |
|
1150 | 1153 | (b'i', b'inactive', False, _(b'mark a bookmark inactive')), |
|
1151 | 1154 | (b'l', b'list', False, _(b'list existing bookmarks')), |
|
1152 | 1155 | ] |
|
1153 | 1156 | + formatteropts, |
|
1154 | 1157 | _(b'hg bookmarks [OPTIONS]... [NAME]...'), |
|
1155 | 1158 | helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, |
|
1156 | 1159 | ) |
|
1157 | 1160 | def bookmark(ui, repo, *names, **opts): |
|
1158 | 1161 | '''create a new bookmark or list existing bookmarks |
|
1159 | 1162 | |
|
1160 | 1163 | Bookmarks are labels on changesets to help track lines of development. |
|
1161 | 1164 | Bookmarks are unversioned and can be moved, renamed and deleted. |
|
1162 | 1165 | Deleting or moving a bookmark has no effect on the associated changesets. |
|
1163 | 1166 | |
|
1164 | 1167 | Creating or updating to a bookmark causes it to be marked as 'active'. |
|
1165 | 1168 | The active bookmark is indicated with a '*'. |
|
1166 | 1169 | When a commit is made, the active bookmark will advance to the new commit. |
|
1167 | 1170 | A plain :hg:`update` will also advance an active bookmark, if possible. |
|
1168 | 1171 | Updating away from a bookmark will cause it to be deactivated. |
|
1169 | 1172 | |
|
1170 | 1173 | Bookmarks can be pushed and pulled between repositories (see |
|
1171 | 1174 | :hg:`help push` and :hg:`help pull`). If a shared bookmark has |
|
1172 | 1175 | diverged, a new 'divergent bookmark' of the form 'name@path' will |
|
1173 | 1176 | be created. Using :hg:`merge` will resolve the divergence. |
|
1174 | 1177 | |
|
1175 | 1178 | Specifying bookmark as '.' to -m/-d/-l options is equivalent to specifying |
|
1176 | 1179 | the active bookmark's name. |
|
1177 | 1180 | |
|
1178 | 1181 | A bookmark named '@' has the special property that :hg:`clone` will |
|
1179 | 1182 | check it out by default if it exists. |
|
1180 | 1183 | |
|
1181 | 1184 | .. container:: verbose |
|
1182 | 1185 | |
|
1183 | 1186 | Template: |
|
1184 | 1187 | |
|
1185 | 1188 | The following keywords are supported in addition to the common template |
|
1186 | 1189 | keywords and functions such as ``{bookmark}``. See also |
|
1187 | 1190 | :hg:`help templates`. |
|
1188 | 1191 | |
|
1189 | 1192 | :active: Boolean. True if the bookmark is active. |
|
1190 | 1193 | |
|
1191 | 1194 | Examples: |
|
1192 | 1195 | |
|
1193 | 1196 | - create an active bookmark for a new line of development:: |
|
1194 | 1197 | |
|
1195 | 1198 | hg book new-feature |
|
1196 | 1199 | |
|
1197 | 1200 | - create an inactive bookmark as a place marker:: |
|
1198 | 1201 | |
|
1199 | 1202 | hg book -i reviewed |
|
1200 | 1203 | |
|
1201 | 1204 | - create an inactive bookmark on another changeset:: |
|
1202 | 1205 | |
|
1203 | 1206 | hg book -r .^ tested |
|
1204 | 1207 | |
|
1205 | 1208 | - rename bookmark turkey to dinner:: |
|
1206 | 1209 | |
|
1207 | 1210 | hg book -m turkey dinner |
|
1208 | 1211 | |
|
1209 | 1212 | - move the '@' bookmark from another branch:: |
|
1210 | 1213 | |
|
1211 | 1214 | hg book -f @ |
|
1212 | 1215 | |
|
1213 | 1216 | - print only the active bookmark name:: |
|
1214 | 1217 | |
|
1215 | 1218 | hg book -ql . |
|
1216 | 1219 | ''' |
|
1217 | 1220 | opts = pycompat.byteskwargs(opts) |
|
1218 | 1221 | force = opts.get(b'force') |
|
1219 | 1222 | rev = opts.get(b'rev') |
|
1220 | 1223 | inactive = opts.get(b'inactive') # meaning add/rename to inactive bookmark |
|
1221 | 1224 | |
|
1222 | 1225 | action = cmdutil.check_at_most_one_arg(opts, b'delete', b'rename', b'list') |
|
1223 | 1226 | if action: |
|
1224 | 1227 | cmdutil.check_incompatible_arguments(opts, action, [b'rev']) |
|
1225 | 1228 | elif names or rev: |
|
1226 | 1229 | action = b'add' |
|
1227 | 1230 | elif inactive: |
|
1228 | 1231 | action = b'inactive' # meaning deactivate |
|
1229 | 1232 | else: |
|
1230 | 1233 | action = b'list' |
|
1231 | 1234 | |
|
1232 | 1235 | cmdutil.check_incompatible_arguments( |
|
1233 | 1236 | opts, b'inactive', [b'delete', b'list'] |
|
1234 | 1237 | ) |
|
1235 | 1238 | if not names and action in {b'add', b'delete'}: |
|
1236 | 1239 | raise error.Abort(_(b"bookmark name required")) |
|
1237 | 1240 | |
|
1238 | 1241 | if action in {b'add', b'delete', b'rename', b'inactive'}: |
|
1239 | 1242 | with repo.wlock(), repo.lock(), repo.transaction(b'bookmark') as tr: |
|
1240 | 1243 | if action == b'delete': |
|
1241 | 1244 | names = pycompat.maplist(repo._bookmarks.expandname, names) |
|
1242 | 1245 | bookmarks.delete(repo, tr, names) |
|
1243 | 1246 | elif action == b'rename': |
|
1244 | 1247 | if not names: |
|
1245 | 1248 | raise error.Abort(_(b"new bookmark name required")) |
|
1246 | 1249 | elif len(names) > 1: |
|
1247 | 1250 | raise error.Abort(_(b"only one new bookmark name allowed")) |
|
1248 | 1251 | oldname = repo._bookmarks.expandname(opts[b'rename']) |
|
1249 | 1252 | bookmarks.rename(repo, tr, oldname, names[0], force, inactive) |
|
1250 | 1253 | elif action == b'add': |
|
1251 | 1254 | bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) |
|
1252 | 1255 | elif action == b'inactive': |
|
1253 | 1256 | if len(repo._bookmarks) == 0: |
|
1254 | 1257 | ui.status(_(b"no bookmarks set\n")) |
|
1255 | 1258 | elif not repo._activebookmark: |
|
1256 | 1259 | ui.status(_(b"no active bookmark\n")) |
|
1257 | 1260 | else: |
|
1258 | 1261 | bookmarks.deactivate(repo) |
|
1259 | 1262 | elif action == b'list': |
|
1260 | 1263 | names = pycompat.maplist(repo._bookmarks.expandname, names) |
|
1261 | 1264 | with ui.formatter(b'bookmarks', opts) as fm: |
|
1262 | 1265 | bookmarks.printbookmarks(ui, repo, fm, names) |
|
1263 | 1266 | else: |
|
1264 | 1267 | raise error.ProgrammingError(b'invalid action: %s' % action) |
|
1265 | 1268 | |
|
1266 | 1269 | |
|
1267 | 1270 | @command( |
|
1268 | 1271 | b'branch', |
|
1269 | 1272 | [ |
|
1270 | 1273 | ( |
|
1271 | 1274 | b'f', |
|
1272 | 1275 | b'force', |
|
1273 | 1276 | None, |
|
1274 | 1277 | _(b'set branch name even if it shadows an existing branch'), |
|
1275 | 1278 | ), |
|
1276 | 1279 | (b'C', b'clean', None, _(b'reset branch name to parent branch name')), |
|
1277 | 1280 | ( |
|
1278 | 1281 | b'r', |
|
1279 | 1282 | b'rev', |
|
1280 | 1283 | [], |
|
1281 | 1284 | _(b'change branches of the given revs (EXPERIMENTAL)'), |
|
1282 | 1285 | ), |
|
1283 | 1286 | ], |
|
1284 | 1287 | _(b'[-fC] [NAME]'), |
|
1285 | 1288 | helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, |
|
1286 | 1289 | ) |
|
1287 | 1290 | def branch(ui, repo, label=None, **opts): |
|
1288 | 1291 | """set or show the current branch name |
|
1289 | 1292 | |
|
1290 | 1293 | .. note:: |
|
1291 | 1294 | |
|
1292 | 1295 | Branch names are permanent and global. Use :hg:`bookmark` to create a |
|
1293 | 1296 | light-weight bookmark instead. See :hg:`help glossary` for more |
|
1294 | 1297 | information about named branches and bookmarks. |
|
1295 | 1298 | |
|
1296 | 1299 | With no argument, show the current branch name. With one argument, |
|
1297 | 1300 | set the working directory branch name (the branch will not exist |
|
1298 | 1301 | in the repository until the next commit). Standard practice |
|
1299 | 1302 | recommends that primary development take place on the 'default' |
|
1300 | 1303 | branch. |
|
1301 | 1304 | |
|
1302 | 1305 | Unless -f/--force is specified, branch will not let you set a |
|
1303 | 1306 | branch name that already exists. |
|
1304 | 1307 | |
|
1305 | 1308 | Use -C/--clean to reset the working directory branch to that of |
|
1306 | 1309 | the parent of the working directory, negating a previous branch |
|
1307 | 1310 | change. |
|
1308 | 1311 | |
|
1309 | 1312 | Use the command :hg:`update` to switch to an existing branch. Use |
|
1310 | 1313 | :hg:`commit --close-branch` to mark this branch head as closed. |
|
1311 | 1314 | When all heads of a branch are closed, the branch will be |
|
1312 | 1315 | considered closed. |
|
1313 | 1316 | |
|
1314 | 1317 | Returns 0 on success. |
|
1315 | 1318 | """ |
|
1316 | 1319 | opts = pycompat.byteskwargs(opts) |
|
1317 | 1320 | revs = opts.get(b'rev') |
|
1318 | 1321 | if label: |
|
1319 | 1322 | label = label.strip() |
|
1320 | 1323 | |
|
1321 | 1324 | if not opts.get(b'clean') and not label: |
|
1322 | 1325 | if revs: |
|
1323 | 1326 | raise error.Abort(_(b"no branch name specified for the revisions")) |
|
1324 | 1327 | ui.write(b"%s\n" % repo.dirstate.branch()) |
|
1325 | 1328 | return |
|
1326 | 1329 | |
|
1327 | 1330 | with repo.wlock(): |
|
1328 | 1331 | if opts.get(b'clean'): |
|
1329 | 1332 | label = repo[b'.'].branch() |
|
1330 | 1333 | repo.dirstate.setbranch(label) |
|
1331 | 1334 | ui.status(_(b'reset working directory to branch %s\n') % label) |
|
1332 | 1335 | elif label: |
|
1333 | 1336 | |
|
1334 | 1337 | scmutil.checknewlabel(repo, label, b'branch') |
|
1335 | 1338 | if revs: |
|
1336 | 1339 | return cmdutil.changebranch(ui, repo, revs, label, opts) |
|
1337 | 1340 | |
|
1338 | 1341 | if not opts.get(b'force') and label in repo.branchmap(): |
|
1339 | 1342 | if label not in [p.branch() for p in repo[None].parents()]: |
|
1340 | 1343 | raise error.Abort( |
|
1341 | 1344 | _(b'a branch of the same name already exists'), |
|
1342 | 1345 | # i18n: "it" refers to an existing branch |
|
1343 | 1346 | hint=_(b"use 'hg update' to switch to it"), |
|
1344 | 1347 | ) |
|
1345 | 1348 | |
|
1346 | 1349 | repo.dirstate.setbranch(label) |
|
1347 | 1350 | ui.status(_(b'marked working directory as branch %s\n') % label) |
|
1348 | 1351 | |
|
1349 | 1352 | # find any open named branches aside from default |
|
1350 | 1353 | for n, h, t, c in repo.branchmap().iterbranches(): |
|
1351 | 1354 | if n != b"default" and not c: |
|
1352 | 1355 | return 0 |
|
1353 | 1356 | ui.status( |
|
1354 | 1357 | _( |
|
1355 | 1358 | b'(branches are permanent and global, ' |
|
1356 | 1359 | b'did you want a bookmark?)\n' |
|
1357 | 1360 | ) |
|
1358 | 1361 | ) |
|
1359 | 1362 | |
|
1360 | 1363 | |
|
1361 | 1364 | @command( |
|
1362 | 1365 | b'branches', |
|
1363 | 1366 | [ |
|
1364 | 1367 | ( |
|
1365 | 1368 | b'a', |
|
1366 | 1369 | b'active', |
|
1367 | 1370 | False, |
|
1368 | 1371 | _(b'show only branches that have unmerged heads (DEPRECATED)'), |
|
1369 | 1372 | ), |
|
1370 | 1373 | (b'c', b'closed', False, _(b'show normal and closed branches')), |
|
1371 | 1374 | (b'r', b'rev', [], _(b'show branch name(s) of the given rev')), |
|
1372 | 1375 | ] |
|
1373 | 1376 | + formatteropts, |
|
1374 | 1377 | _(b'[-c]'), |
|
1375 | 1378 | helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, |
|
1376 | 1379 | intents={INTENT_READONLY}, |
|
1377 | 1380 | ) |
|
1378 | 1381 | def branches(ui, repo, active=False, closed=False, **opts): |
|
1379 | 1382 | """list repository named branches |
|
1380 | 1383 | |
|
1381 | 1384 | List the repository's named branches, indicating which ones are |
|
1382 | 1385 | inactive. If -c/--closed is specified, also list branches which have |
|
1383 | 1386 | been marked closed (see :hg:`commit --close-branch`). |
|
1384 | 1387 | |
|
1385 | 1388 | Use the command :hg:`update` to switch to an existing branch. |
|
1386 | 1389 | |
|
1387 | 1390 | .. container:: verbose |
|
1388 | 1391 | |
|
1389 | 1392 | Template: |
|
1390 | 1393 | |
|
1391 | 1394 | The following keywords are supported in addition to the common template |
|
1392 | 1395 | keywords and functions such as ``{branch}``. See also |
|
1393 | 1396 | :hg:`help templates`. |
|
1394 | 1397 | |
|
1395 | 1398 | :active: Boolean. True if the branch is active. |
|
1396 | 1399 | :closed: Boolean. True if the branch is closed. |
|
1397 | 1400 | :current: Boolean. True if it is the current branch. |
|
1398 | 1401 | |
|
1399 | 1402 | Returns 0. |
|
1400 | 1403 | """ |
|
1401 | 1404 | |
|
1402 | 1405 | opts = pycompat.byteskwargs(opts) |
|
1403 | 1406 | revs = opts.get(b'rev') |
|
1404 | 1407 | selectedbranches = None |
|
1405 | 1408 | if revs: |
|
1406 | 1409 | revs = scmutil.revrange(repo, revs) |
|
1407 | 1410 | getbi = repo.revbranchcache().branchinfo |
|
1408 | 1411 | selectedbranches = {getbi(r)[0] for r in revs} |
|
1409 | 1412 | |
|
1410 | 1413 | ui.pager(b'branches') |
|
1411 | 1414 | fm = ui.formatter(b'branches', opts) |
|
1412 | 1415 | hexfunc = fm.hexfunc |
|
1413 | 1416 | |
|
1414 | 1417 | allheads = set(repo.heads()) |
|
1415 | 1418 | branches = [] |
|
1416 | 1419 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): |
|
1417 | 1420 | if selectedbranches is not None and tag not in selectedbranches: |
|
1418 | 1421 | continue |
|
1419 | 1422 | isactive = False |
|
1420 | 1423 | if not isclosed: |
|
1421 | 1424 | openheads = set(repo.branchmap().iteropen(heads)) |
|
1422 | 1425 | isactive = bool(openheads & allheads) |
|
1423 | 1426 | branches.append((tag, repo[tip], isactive, not isclosed)) |
|
1424 | 1427 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), reverse=True) |
|
1425 | 1428 | |
|
1426 | 1429 | for tag, ctx, isactive, isopen in branches: |
|
1427 | 1430 | if active and not isactive: |
|
1428 | 1431 | continue |
|
1429 | 1432 | if isactive: |
|
1430 | 1433 | label = b'branches.active' |
|
1431 | 1434 | notice = b'' |
|
1432 | 1435 | elif not isopen: |
|
1433 | 1436 | if not closed: |
|
1434 | 1437 | continue |
|
1435 | 1438 | label = b'branches.closed' |
|
1436 | 1439 | notice = _(b' (closed)') |
|
1437 | 1440 | else: |
|
1438 | 1441 | label = b'branches.inactive' |
|
1439 | 1442 | notice = _(b' (inactive)') |
|
1440 | 1443 | current = tag == repo.dirstate.branch() |
|
1441 | 1444 | if current: |
|
1442 | 1445 | label = b'branches.current' |
|
1443 | 1446 | |
|
1444 | 1447 | fm.startitem() |
|
1445 | 1448 | fm.write(b'branch', b'%s', tag, label=label) |
|
1446 | 1449 | rev = ctx.rev() |
|
1447 | 1450 | padsize = max(31 - len(b"%d" % rev) - encoding.colwidth(tag), 0) |
|
1448 | 1451 | fmt = b' ' * padsize + b' %d:%s' |
|
1449 | 1452 | fm.condwrite( |
|
1450 | 1453 | not ui.quiet, |
|
1451 | 1454 | b'rev node', |
|
1452 | 1455 | fmt, |
|
1453 | 1456 | rev, |
|
1454 | 1457 | hexfunc(ctx.node()), |
|
1455 | 1458 | label=b'log.changeset changeset.%s' % ctx.phasestr(), |
|
1456 | 1459 | ) |
|
1457 | 1460 | fm.context(ctx=ctx) |
|
1458 | 1461 | fm.data(active=isactive, closed=not isopen, current=current) |
|
1459 | 1462 | if not ui.quiet: |
|
1460 | 1463 | fm.plain(notice) |
|
1461 | 1464 | fm.plain(b'\n') |
|
1462 | 1465 | fm.end() |
|
1463 | 1466 | |
|
1464 | 1467 | |
|
1465 | 1468 | @command( |
|
1466 | 1469 | b'bundle', |
|
1467 | 1470 | [ |
|
1468 | 1471 | ( |
|
1469 | 1472 | b'f', |
|
1470 | 1473 | b'force', |
|
1471 | 1474 | None, |
|
1472 | 1475 | _(b'run even when the destination is unrelated'), |
|
1473 | 1476 | ), |
|
1474 | 1477 | ( |
|
1475 | 1478 | b'r', |
|
1476 | 1479 | b'rev', |
|
1477 | 1480 | [], |
|
1478 | 1481 | _(b'a changeset intended to be added to the destination'), |
|
1479 | 1482 | _(b'REV'), |
|
1480 | 1483 | ), |
|
1481 | 1484 | ( |
|
1482 | 1485 | b'b', |
|
1483 | 1486 | b'branch', |
|
1484 | 1487 | [], |
|
1485 | 1488 | _(b'a specific branch you would like to bundle'), |
|
1486 | 1489 | _(b'BRANCH'), |
|
1487 | 1490 | ), |
|
1488 | 1491 | ( |
|
1489 | 1492 | b'', |
|
1490 | 1493 | b'base', |
|
1491 | 1494 | [], |
|
1492 | 1495 | _(b'a base changeset assumed to be available at the destination'), |
|
1493 | 1496 | _(b'REV'), |
|
1494 | 1497 | ), |
|
1495 | 1498 | (b'a', b'all', None, _(b'bundle all changesets in the repository')), |
|
1496 | 1499 | ( |
|
1497 | 1500 | b't', |
|
1498 | 1501 | b'type', |
|
1499 | 1502 | b'bzip2', |
|
1500 | 1503 | _(b'bundle compression type to use'), |
|
1501 | 1504 | _(b'TYPE'), |
|
1502 | 1505 | ), |
|
1503 | 1506 | ] |
|
1504 | 1507 | + remoteopts, |
|
1505 | 1508 | _(b'[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]'), |
|
1506 | 1509 | helpcategory=command.CATEGORY_IMPORT_EXPORT, |
|
1507 | 1510 | ) |
|
1508 | 1511 | def bundle(ui, repo, fname, dest=None, **opts): |
|
1509 | 1512 | """create a bundle file |
|
1510 | 1513 | |
|
1511 | 1514 | Generate a bundle file containing data to be transferred to another |
|
1512 | 1515 | repository. |
|
1513 | 1516 | |
|
1514 | 1517 | To create a bundle containing all changesets, use -a/--all |
|
1515 | 1518 | (or --base null). Otherwise, hg assumes the destination will have |
|
1516 | 1519 | all the nodes you specify with --base parameters. Otherwise, hg |
|
1517 | 1520 | will assume the repository has all the nodes in destination, or |
|
1518 | 1521 | default-push/default if no destination is specified, where destination |
|
1519 | 1522 | is the repository you provide through DEST option. |
|
1520 | 1523 | |
|
1521 | 1524 | You can change bundle format with the -t/--type option. See |
|
1522 | 1525 | :hg:`help bundlespec` for documentation on this format. By default, |
|
1523 | 1526 | the most appropriate format is used and compression defaults to |
|
1524 | 1527 | bzip2. |
|
1525 | 1528 | |
|
1526 | 1529 | The bundle file can then be transferred using conventional means |
|
1527 | 1530 | and applied to another repository with the unbundle or pull |
|
1528 | 1531 | command. This is useful when direct push and pull are not |
|
1529 | 1532 | available or when exporting an entire repository is undesirable. |
|
1530 | 1533 | |
|
1531 | 1534 | Applying bundles preserves all changeset contents including |
|
1532 | 1535 | permissions, copy/rename information, and revision history. |
|
1533 | 1536 | |
|
1534 | 1537 | Returns 0 on success, 1 if no changes found. |
|
1535 | 1538 | """ |
|
1536 | 1539 | opts = pycompat.byteskwargs(opts) |
|
1537 | 1540 | revs = None |
|
1538 | 1541 | if b'rev' in opts: |
|
1539 | 1542 | revstrings = opts[b'rev'] |
|
1540 | 1543 | revs = scmutil.revrange(repo, revstrings) |
|
1541 | 1544 | if revstrings and not revs: |
|
1542 | 1545 | raise error.Abort(_(b'no commits to bundle')) |
|
1543 | 1546 | |
|
1544 | 1547 | bundletype = opts.get(b'type', b'bzip2').lower() |
|
1545 | 1548 | try: |
|
1546 | 1549 | bundlespec = bundlecaches.parsebundlespec( |
|
1547 | 1550 | repo, bundletype, strict=False |
|
1548 | 1551 | ) |
|
1549 | 1552 | except error.UnsupportedBundleSpecification as e: |
|
1550 | 1553 | raise error.Abort( |
|
1551 | 1554 | pycompat.bytestr(e), |
|
1552 | 1555 | hint=_(b"see 'hg help bundlespec' for supported values for --type"), |
|
1553 | 1556 | ) |
|
1554 | 1557 | cgversion = bundlespec.contentopts[b"cg.version"] |
|
1555 | 1558 | |
|
1556 | 1559 | # Packed bundles are a pseudo bundle format for now. |
|
1557 | 1560 | if cgversion == b's1': |
|
1558 | 1561 | raise error.Abort( |
|
1559 | 1562 | _(b'packed bundles cannot be produced by "hg bundle"'), |
|
1560 | 1563 | hint=_(b"use 'hg debugcreatestreamclonebundle'"), |
|
1561 | 1564 | ) |
|
1562 | 1565 | |
|
1563 | 1566 | if opts.get(b'all'): |
|
1564 | 1567 | if dest: |
|
1565 | 1568 | raise error.Abort( |
|
1566 | 1569 | _(b"--all is incompatible with specifying a destination") |
|
1567 | 1570 | ) |
|
1568 | 1571 | if opts.get(b'base'): |
|
1569 | 1572 | ui.warn(_(b"ignoring --base because --all was specified\n")) |
|
1570 | 1573 | base = [nullrev] |
|
1571 | 1574 | else: |
|
1572 | 1575 | base = scmutil.revrange(repo, opts.get(b'base')) |
|
1573 | 1576 | if cgversion not in changegroup.supportedoutgoingversions(repo): |
|
1574 | 1577 | raise error.Abort( |
|
1575 | 1578 | _(b"repository does not support bundle version %s") % cgversion |
|
1576 | 1579 | ) |
|
1577 | 1580 | |
|
1578 | 1581 | if base: |
|
1579 | 1582 | if dest: |
|
1580 | 1583 | raise error.Abort( |
|
1581 | 1584 | _(b"--base is incompatible with specifying a destination") |
|
1582 | 1585 | ) |
|
1583 | 1586 | common = [repo[rev].node() for rev in base] |
|
1584 | 1587 | heads = [repo[r].node() for r in revs] if revs else None |
|
1585 | 1588 | outgoing = discovery.outgoing(repo, common, heads) |
|
1586 | 1589 | else: |
|
1587 | 1590 | dest = ui.expandpath(dest or b'default-push', dest or b'default') |
|
1588 | 1591 | dest, branches = hg.parseurl(dest, opts.get(b'branch')) |
|
1589 | 1592 | other = hg.peer(repo, opts, dest) |
|
1590 | 1593 | revs = [repo[r].hex() for r in revs] |
|
1591 | 1594 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) |
|
1592 | 1595 | heads = revs and pycompat.maplist(repo.lookup, revs) or revs |
|
1593 | 1596 | outgoing = discovery.findcommonoutgoing( |
|
1594 | 1597 | repo, |
|
1595 | 1598 | other, |
|
1596 | 1599 | onlyheads=heads, |
|
1597 | 1600 | force=opts.get(b'force'), |
|
1598 | 1601 | portable=True, |
|
1599 | 1602 | ) |
|
1600 | 1603 | |
|
1601 | 1604 | if not outgoing.missing: |
|
1602 | 1605 | scmutil.nochangesfound(ui, repo, not base and outgoing.excluded) |
|
1603 | 1606 | return 1 |
|
1604 | 1607 | |
|
1605 | 1608 | if cgversion == b'01': # bundle1 |
|
1606 | 1609 | bversion = b'HG10' + bundlespec.wirecompression |
|
1607 | 1610 | bcompression = None |
|
1608 | 1611 | elif cgversion in (b'02', b'03'): |
|
1609 | 1612 | bversion = b'HG20' |
|
1610 | 1613 | bcompression = bundlespec.wirecompression |
|
1611 | 1614 | else: |
|
1612 | 1615 | raise error.ProgrammingError( |
|
1613 | 1616 | b'bundle: unexpected changegroup version %s' % cgversion |
|
1614 | 1617 | ) |
|
1615 | 1618 | |
|
1616 | 1619 | # TODO compression options should be derived from bundlespec parsing. |
|
1617 | 1620 | # This is a temporary hack to allow adjusting bundle compression |
|
1618 | 1621 | # level without a) formalizing the bundlespec changes to declare it |
|
1619 | 1622 | # b) introducing a command flag. |
|
1620 | 1623 | compopts = {} |
|
1621 | 1624 | complevel = ui.configint( |
|
1622 | 1625 | b'experimental', b'bundlecomplevel.' + bundlespec.compression |
|
1623 | 1626 | ) |
|
1624 | 1627 | if complevel is None: |
|
1625 | 1628 | complevel = ui.configint(b'experimental', b'bundlecomplevel') |
|
1626 | 1629 | if complevel is not None: |
|
1627 | 1630 | compopts[b'level'] = complevel |
|
1628 | 1631 | |
|
1629 | 1632 | # Allow overriding the bundling of obsmarker in phases through |
|
1630 | 1633 | # configuration while we don't have a bundle version that include them |
|
1631 | 1634 | if repo.ui.configbool(b'experimental', b'evolution.bundle-obsmarker'): |
|
1632 | 1635 | bundlespec.contentopts[b'obsolescence'] = True |
|
1633 | 1636 | if repo.ui.configbool(b'experimental', b'bundle-phases'): |
|
1634 | 1637 | bundlespec.contentopts[b'phases'] = True |
|
1635 | 1638 | |
|
1636 | 1639 | bundle2.writenewbundle( |
|
1637 | 1640 | ui, |
|
1638 | 1641 | repo, |
|
1639 | 1642 | b'bundle', |
|
1640 | 1643 | fname, |
|
1641 | 1644 | bversion, |
|
1642 | 1645 | outgoing, |
|
1643 | 1646 | bundlespec.contentopts, |
|
1644 | 1647 | compression=bcompression, |
|
1645 | 1648 | compopts=compopts, |
|
1646 | 1649 | ) |
|
1647 | 1650 | |
|
1648 | 1651 | |
|
1649 | 1652 | @command( |
|
1650 | 1653 | b'cat', |
|
1651 | 1654 | [ |
|
1652 | 1655 | ( |
|
1653 | 1656 | b'o', |
|
1654 | 1657 | b'output', |
|
1655 | 1658 | b'', |
|
1656 | 1659 | _(b'print output to file with formatted name'), |
|
1657 | 1660 | _(b'FORMAT'), |
|
1658 | 1661 | ), |
|
1659 | 1662 | (b'r', b'rev', b'', _(b'print the given revision'), _(b'REV')), |
|
1660 | 1663 | (b'', b'decode', None, _(b'apply any matching decode filter')), |
|
1661 | 1664 | ] |
|
1662 | 1665 | + walkopts |
|
1663 | 1666 | + formatteropts, |
|
1664 | 1667 | _(b'[OPTION]... FILE...'), |
|
1665 | 1668 | helpcategory=command.CATEGORY_FILE_CONTENTS, |
|
1666 | 1669 | inferrepo=True, |
|
1667 | 1670 | intents={INTENT_READONLY}, |
|
1668 | 1671 | ) |
|
1669 | 1672 | def cat(ui, repo, file1, *pats, **opts): |
|
1670 | 1673 | """output the current or given revision of files |
|
1671 | 1674 | |
|
1672 | 1675 | Print the specified files as they were at the given revision. If |
|
1673 | 1676 | no revision is given, the parent of the working directory is used. |
|
1674 | 1677 | |
|
1675 | 1678 | Output may be to a file, in which case the name of the file is |
|
1676 | 1679 | given using a template string. See :hg:`help templates`. In addition |
|
1677 | 1680 | to the common template keywords, the following formatting rules are |
|
1678 | 1681 | supported: |
|
1679 | 1682 | |
|
1680 | 1683 | :``%%``: literal "%" character |
|
1681 | 1684 | :``%s``: basename of file being printed |
|
1682 | 1685 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
1683 | 1686 | :``%p``: root-relative path name of file being printed |
|
1684 | 1687 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1685 | 1688 | :``%R``: changeset revision number |
|
1686 | 1689 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1687 | 1690 | :``%r``: zero-padded changeset revision number |
|
1688 | 1691 | :``%b``: basename of the exporting repository |
|
1689 | 1692 | :``\\``: literal "\\" character |
|
1690 | 1693 | |
|
1691 | 1694 | .. container:: verbose |
|
1692 | 1695 | |
|
1693 | 1696 | Template: |
|
1694 | 1697 | |
|
1695 | 1698 | The following keywords are supported in addition to the common template |
|
1696 | 1699 | keywords and functions. See also :hg:`help templates`. |
|
1697 | 1700 | |
|
1698 | 1701 | :data: String. File content. |
|
1699 | 1702 | :path: String. Repository-absolute path of the file. |
|
1700 | 1703 | |
|
1701 | 1704 | Returns 0 on success. |
|
1702 | 1705 | """ |
|
1703 | 1706 | opts = pycompat.byteskwargs(opts) |
|
1704 | 1707 | rev = opts.get(b'rev') |
|
1705 | 1708 | if rev: |
|
1706 | 1709 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
1707 | 1710 | ctx = scmutil.revsingle(repo, rev) |
|
1708 | 1711 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1709 | 1712 | fntemplate = opts.pop(b'output', b'') |
|
1710 | 1713 | if cmdutil.isstdiofilename(fntemplate): |
|
1711 | 1714 | fntemplate = b'' |
|
1712 | 1715 | |
|
1713 | 1716 | if fntemplate: |
|
1714 | 1717 | fm = formatter.nullformatter(ui, b'cat', opts) |
|
1715 | 1718 | else: |
|
1716 | 1719 | ui.pager(b'cat') |
|
1717 | 1720 | fm = ui.formatter(b'cat', opts) |
|
1718 | 1721 | with fm: |
|
1719 | 1722 | return cmdutil.cat( |
|
1720 | 1723 | ui, repo, ctx, m, fm, fntemplate, b'', **pycompat.strkwargs(opts) |
|
1721 | 1724 | ) |
|
1722 | 1725 | |
|
1723 | 1726 | |
|
1724 | 1727 | @command( |
|
1725 | 1728 | b'clone', |
|
1726 | 1729 | [ |
|
1727 | 1730 | ( |
|
1728 | 1731 | b'U', |
|
1729 | 1732 | b'noupdate', |
|
1730 | 1733 | None, |
|
1731 | 1734 | _( |
|
1732 | 1735 | b'the clone will include an empty working ' |
|
1733 | 1736 | b'directory (only a repository)' |
|
1734 | 1737 | ), |
|
1735 | 1738 | ), |
|
1736 | 1739 | ( |
|
1737 | 1740 | b'u', |
|
1738 | 1741 | b'updaterev', |
|
1739 | 1742 | b'', |
|
1740 | 1743 | _(b'revision, tag, or branch to check out'), |
|
1741 | 1744 | _(b'REV'), |
|
1742 | 1745 | ), |
|
1743 | 1746 | ( |
|
1744 | 1747 | b'r', |
|
1745 | 1748 | b'rev', |
|
1746 | 1749 | [], |
|
1747 | 1750 | _( |
|
1748 | 1751 | b'do not clone everything, but include this changeset' |
|
1749 | 1752 | b' and its ancestors' |
|
1750 | 1753 | ), |
|
1751 | 1754 | _(b'REV'), |
|
1752 | 1755 | ), |
|
1753 | 1756 | ( |
|
1754 | 1757 | b'b', |
|
1755 | 1758 | b'branch', |
|
1756 | 1759 | [], |
|
1757 | 1760 | _( |
|
1758 | 1761 | b'do not clone everything, but include this branch\'s' |
|
1759 | 1762 | b' changesets and their ancestors' |
|
1760 | 1763 | ), |
|
1761 | 1764 | _(b'BRANCH'), |
|
1762 | 1765 | ), |
|
1763 | 1766 | (b'', b'pull', None, _(b'use pull protocol to copy metadata')), |
|
1764 | 1767 | (b'', b'uncompressed', None, _(b'an alias to --stream (DEPRECATED)')), |
|
1765 | 1768 | (b'', b'stream', None, _(b'clone with minimal data processing')), |
|
1766 | 1769 | ] |
|
1767 | 1770 | + remoteopts, |
|
1768 | 1771 | _(b'[OPTION]... SOURCE [DEST]'), |
|
1769 | 1772 | helpcategory=command.CATEGORY_REPO_CREATION, |
|
1770 | 1773 | helpbasic=True, |
|
1771 | 1774 | norepo=True, |
|
1772 | 1775 | ) |
|
1773 | 1776 | def clone(ui, source, dest=None, **opts): |
|
1774 | 1777 | """make a copy of an existing repository |
|
1775 | 1778 | |
|
1776 | 1779 | Create a copy of an existing repository in a new directory. |
|
1777 | 1780 | |
|
1778 | 1781 | If no destination directory name is specified, it defaults to the |
|
1779 | 1782 | basename of the source. |
|
1780 | 1783 | |
|
1781 | 1784 | The location of the source is added to the new repository's |
|
1782 | 1785 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
1783 | 1786 | |
|
1784 | 1787 | Only local paths and ``ssh://`` URLs are supported as |
|
1785 | 1788 | destinations. For ``ssh://`` destinations, no working directory or |
|
1786 | 1789 | ``.hg/hgrc`` will be created on the remote side. |
|
1787 | 1790 | |
|
1788 | 1791 | If the source repository has a bookmark called '@' set, that |
|
1789 | 1792 | revision will be checked out in the new repository by default. |
|
1790 | 1793 | |
|
1791 | 1794 | To check out a particular version, use -u/--update, or |
|
1792 | 1795 | -U/--noupdate to create a clone with no working directory. |
|
1793 | 1796 | |
|
1794 | 1797 | To pull only a subset of changesets, specify one or more revisions |
|
1795 | 1798 | identifiers with -r/--rev or branches with -b/--branch. The |
|
1796 | 1799 | resulting clone will contain only the specified changesets and |
|
1797 | 1800 | their ancestors. These options (or 'clone src#rev dest') imply |
|
1798 | 1801 | --pull, even for local source repositories. |
|
1799 | 1802 | |
|
1800 | 1803 | In normal clone mode, the remote normalizes repository data into a common |
|
1801 | 1804 | exchange format and the receiving end translates this data into its local |
|
1802 | 1805 | storage format. --stream activates a different clone mode that essentially |
|
1803 | 1806 | copies repository files from the remote with minimal data processing. This |
|
1804 | 1807 | significantly reduces the CPU cost of a clone both remotely and locally. |
|
1805 | 1808 | However, it often increases the transferred data size by 30-40%. This can |
|
1806 | 1809 | result in substantially faster clones where I/O throughput is plentiful, |
|
1807 | 1810 | especially for larger repositories. A side-effect of --stream clones is |
|
1808 | 1811 | that storage settings and requirements on the remote are applied locally: |
|
1809 | 1812 | a modern client may inherit legacy or inefficient storage used by the |
|
1810 | 1813 | remote or a legacy Mercurial client may not be able to clone from a |
|
1811 | 1814 | modern Mercurial remote. |
|
1812 | 1815 | |
|
1813 | 1816 | .. note:: |
|
1814 | 1817 | |
|
1815 | 1818 | Specifying a tag will include the tagged changeset but not the |
|
1816 | 1819 | changeset containing the tag. |
|
1817 | 1820 | |
|
1818 | 1821 | .. container:: verbose |
|
1819 | 1822 | |
|
1820 | 1823 | For efficiency, hardlinks are used for cloning whenever the |
|
1821 | 1824 | source and destination are on the same filesystem (note this |
|
1822 | 1825 | applies only to the repository data, not to the working |
|
1823 | 1826 | directory). Some filesystems, such as AFS, implement hardlinking |
|
1824 | 1827 | incorrectly, but do not report errors. In these cases, use the |
|
1825 | 1828 | --pull option to avoid hardlinking. |
|
1826 | 1829 | |
|
1827 | 1830 | Mercurial will update the working directory to the first applicable |
|
1828 | 1831 | revision from this list: |
|
1829 | 1832 | |
|
1830 | 1833 | a) null if -U or the source repository has no changesets |
|
1831 | 1834 | b) if -u . and the source repository is local, the first parent of |
|
1832 | 1835 | the source repository's working directory |
|
1833 | 1836 | c) the changeset specified with -u (if a branch name, this means the |
|
1834 | 1837 | latest head of that branch) |
|
1835 | 1838 | d) the changeset specified with -r |
|
1836 | 1839 | e) the tipmost head specified with -b |
|
1837 | 1840 | f) the tipmost head specified with the url#branch source syntax |
|
1838 | 1841 | g) the revision marked with the '@' bookmark, if present |
|
1839 | 1842 | h) the tipmost head of the default branch |
|
1840 | 1843 | i) tip |
|
1841 | 1844 | |
|
1842 | 1845 | When cloning from servers that support it, Mercurial may fetch |
|
1843 | 1846 | pre-generated data from a server-advertised URL or inline from the |
|
1844 | 1847 | same stream. When this is done, hooks operating on incoming changesets |
|
1845 | 1848 | and changegroups may fire more than once, once for each pre-generated |
|
1846 | 1849 | bundle and as well as for any additional remaining data. In addition, |
|
1847 | 1850 | if an error occurs, the repository may be rolled back to a partial |
|
1848 | 1851 | clone. This behavior may change in future releases. |
|
1849 | 1852 | See :hg:`help -e clonebundles` for more. |
|
1850 | 1853 | |
|
1851 | 1854 | Examples: |
|
1852 | 1855 | |
|
1853 | 1856 | - clone a remote repository to a new directory named hg/:: |
|
1854 | 1857 | |
|
1855 | 1858 | hg clone https://www.mercurial-scm.org/repo/hg/ |
|
1856 | 1859 | |
|
1857 | 1860 | - create a lightweight local clone:: |
|
1858 | 1861 | |
|
1859 | 1862 | hg clone project/ project-feature/ |
|
1860 | 1863 | |
|
1861 | 1864 | - clone from an absolute path on an ssh server (note double-slash):: |
|
1862 | 1865 | |
|
1863 | 1866 | hg clone ssh://user@server//home/projects/alpha/ |
|
1864 | 1867 | |
|
1865 | 1868 | - do a streaming clone while checking out a specified version:: |
|
1866 | 1869 | |
|
1867 | 1870 | hg clone --stream http://server/repo -u 1.5 |
|
1868 | 1871 | |
|
1869 | 1872 | - create a repository without changesets after a particular revision:: |
|
1870 | 1873 | |
|
1871 | 1874 | hg clone -r 04e544 experimental/ good/ |
|
1872 | 1875 | |
|
1873 | 1876 | - clone (and track) a particular named branch:: |
|
1874 | 1877 | |
|
1875 | 1878 | hg clone https://www.mercurial-scm.org/repo/hg/#stable |
|
1876 | 1879 | |
|
1877 | 1880 | See :hg:`help urls` for details on specifying URLs. |
|
1878 | 1881 | |
|
1879 | 1882 | Returns 0 on success. |
|
1880 | 1883 | """ |
|
1881 | 1884 | opts = pycompat.byteskwargs(opts) |
|
1882 | 1885 | cmdutil.check_at_most_one_arg(opts, b'noupdate', b'updaterev') |
|
1883 | 1886 | |
|
1884 | 1887 | # --include/--exclude can come from narrow or sparse. |
|
1885 | 1888 | includepats, excludepats = None, None |
|
1886 | 1889 | |
|
1887 | 1890 | # hg.clone() differentiates between None and an empty set. So make sure |
|
1888 | 1891 | # patterns are sets if narrow is requested without patterns. |
|
1889 | 1892 | if opts.get(b'narrow'): |
|
1890 | 1893 | includepats = set() |
|
1891 | 1894 | excludepats = set() |
|
1892 | 1895 | |
|
1893 | 1896 | if opts.get(b'include'): |
|
1894 | 1897 | includepats = narrowspec.parsepatterns(opts.get(b'include')) |
|
1895 | 1898 | if opts.get(b'exclude'): |
|
1896 | 1899 | excludepats = narrowspec.parsepatterns(opts.get(b'exclude')) |
|
1897 | 1900 | |
|
1898 | 1901 | r = hg.clone( |
|
1899 | 1902 | ui, |
|
1900 | 1903 | opts, |
|
1901 | 1904 | source, |
|
1902 | 1905 | dest, |
|
1903 | 1906 | pull=opts.get(b'pull'), |
|
1904 | 1907 | stream=opts.get(b'stream') or opts.get(b'uncompressed'), |
|
1905 | 1908 | revs=opts.get(b'rev'), |
|
1906 | 1909 | update=opts.get(b'updaterev') or not opts.get(b'noupdate'), |
|
1907 | 1910 | branch=opts.get(b'branch'), |
|
1908 | 1911 | shareopts=opts.get(b'shareopts'), |
|
1909 | 1912 | storeincludepats=includepats, |
|
1910 | 1913 | storeexcludepats=excludepats, |
|
1911 | 1914 | depth=opts.get(b'depth') or None, |
|
1912 | 1915 | ) |
|
1913 | 1916 | |
|
1914 | 1917 | return r is None |
|
1915 | 1918 | |
|
1916 | 1919 | |
|
1917 | 1920 | @command( |
|
1918 | 1921 | b'commit|ci', |
|
1919 | 1922 | [ |
|
1920 | 1923 | ( |
|
1921 | 1924 | b'A', |
|
1922 | 1925 | b'addremove', |
|
1923 | 1926 | None, |
|
1924 | 1927 | _(b'mark new/missing files as added/removed before committing'), |
|
1925 | 1928 | ), |
|
1926 | 1929 | (b'', b'close-branch', None, _(b'mark a branch head as closed')), |
|
1927 | 1930 | (b'', b'amend', None, _(b'amend the parent of the working directory')), |
|
1928 | 1931 | (b's', b'secret', None, _(b'use the secret phase for committing')), |
|
1929 | 1932 | (b'e', b'edit', None, _(b'invoke editor on commit messages')), |
|
1930 | 1933 | ( |
|
1931 | 1934 | b'', |
|
1932 | 1935 | b'force-close-branch', |
|
1933 | 1936 | None, |
|
1934 | 1937 | _(b'forcibly close branch from a non-head changeset (ADVANCED)'), |
|
1935 | 1938 | ), |
|
1936 | 1939 | (b'i', b'interactive', None, _(b'use interactive mode')), |
|
1937 | 1940 | ] |
|
1938 | 1941 | + walkopts |
|
1939 | 1942 | + commitopts |
|
1940 | 1943 | + commitopts2 |
|
1941 | 1944 | + subrepoopts, |
|
1942 | 1945 | _(b'[OPTION]... [FILE]...'), |
|
1943 | 1946 | helpcategory=command.CATEGORY_COMMITTING, |
|
1944 | 1947 | helpbasic=True, |
|
1945 | 1948 | inferrepo=True, |
|
1946 | 1949 | ) |
|
1947 | 1950 | def commit(ui, repo, *pats, **opts): |
|
1948 | 1951 | """commit the specified files or all outstanding changes |
|
1949 | 1952 | |
|
1950 | 1953 | Commit changes to the given files into the repository. Unlike a |
|
1951 | 1954 | centralized SCM, this operation is a local operation. See |
|
1952 | 1955 | :hg:`push` for a way to actively distribute your changes. |
|
1953 | 1956 | |
|
1954 | 1957 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1955 | 1958 | will be committed. |
|
1956 | 1959 | |
|
1957 | 1960 | If you are committing the result of a merge, do not provide any |
|
1958 | 1961 | filenames or -I/-X filters. |
|
1959 | 1962 | |
|
1960 | 1963 | If no commit message is specified, Mercurial starts your |
|
1961 | 1964 | configured editor where you can enter a message. In case your |
|
1962 | 1965 | commit fails, you will find a backup of your message in |
|
1963 | 1966 | ``.hg/last-message.txt``. |
|
1964 | 1967 | |
|
1965 | 1968 | The --close-branch flag can be used to mark the current branch |
|
1966 | 1969 | head closed. When all heads of a branch are closed, the branch |
|
1967 | 1970 | will be considered closed and no longer listed. |
|
1968 | 1971 | |
|
1969 | 1972 | The --amend flag can be used to amend the parent of the |
|
1970 | 1973 | working directory with a new commit that contains the changes |
|
1971 | 1974 | in the parent in addition to those currently reported by :hg:`status`, |
|
1972 | 1975 | if there are any. The old commit is stored in a backup bundle in |
|
1973 | 1976 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` |
|
1974 | 1977 | on how to restore it). |
|
1975 | 1978 | |
|
1976 | 1979 | Message, user and date are taken from the amended commit unless |
|
1977 | 1980 | specified. When a message isn't specified on the command line, |
|
1978 | 1981 | the editor will open with the message of the amended commit. |
|
1979 | 1982 | |
|
1980 | 1983 | It is not possible to amend public changesets (see :hg:`help phases`) |
|
1981 | 1984 | or changesets that have children. |
|
1982 | 1985 | |
|
1983 | 1986 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1984 | 1987 | |
|
1985 | 1988 | Returns 0 on success, 1 if nothing changed. |
|
1986 | 1989 | |
|
1987 | 1990 | .. container:: verbose |
|
1988 | 1991 | |
|
1989 | 1992 | Examples: |
|
1990 | 1993 | |
|
1991 | 1994 | - commit all files ending in .py:: |
|
1992 | 1995 | |
|
1993 | 1996 | hg commit --include "set:**.py" |
|
1994 | 1997 | |
|
1995 | 1998 | - commit all non-binary files:: |
|
1996 | 1999 | |
|
1997 | 2000 | hg commit --exclude "set:binary()" |
|
1998 | 2001 | |
|
1999 | 2002 | - amend the current commit and set the date to now:: |
|
2000 | 2003 | |
|
2001 | 2004 | hg commit --amend --date now |
|
2002 | 2005 | """ |
|
2003 | 2006 | with repo.wlock(), repo.lock(): |
|
2004 | 2007 | return _docommit(ui, repo, *pats, **opts) |
|
2005 | 2008 | |
|
2006 | 2009 | |
|
2007 | 2010 | def _docommit(ui, repo, *pats, **opts): |
|
2008 | 2011 | if opts.get('interactive'): |
|
2009 | 2012 | opts.pop('interactive') |
|
2010 | 2013 | ret = cmdutil.dorecord( |
|
2011 | 2014 | ui, repo, commit, None, False, cmdutil.recordfilter, *pats, **opts |
|
2012 | 2015 | ) |
|
2013 | 2016 | # ret can be 0 (no changes to record) or the value returned by |
|
2014 | 2017 | # commit(), 1 if nothing changed or None on success. |
|
2015 | 2018 | return 1 if ret == 0 else ret |
|
2016 | 2019 | |
|
2017 | 2020 | opts = pycompat.byteskwargs(opts) |
|
2018 | 2021 | if opts.get(b'subrepos'): |
|
2019 | 2022 | cmdutil.check_incompatible_arguments(opts, b'subrepos', [b'amend']) |
|
2020 | 2023 | # Let --subrepos on the command line override config setting. |
|
2021 | 2024 | ui.setconfig(b'ui', b'commitsubrepos', True, b'commit') |
|
2022 | 2025 | |
|
2023 | 2026 | cmdutil.checkunfinished(repo, commit=True) |
|
2024 | 2027 | |
|
2025 | 2028 | branch = repo[None].branch() |
|
2026 | 2029 | bheads = repo.branchheads(branch) |
|
2030 | tip = repo.changelog.tip() | |
|
2027 | 2031 | |
|
2028 | 2032 | extra = {} |
|
2029 | 2033 | if opts.get(b'close_branch') or opts.get(b'force_close_branch'): |
|
2030 | 2034 | extra[b'close'] = b'1' |
|
2031 | 2035 | |
|
2032 | 2036 | if repo[b'.'].closesbranch(): |
|
2033 | 2037 | raise error.Abort( |
|
2034 | 2038 | _(b'current revision is already a branch closing head') |
|
2035 | 2039 | ) |
|
2036 | 2040 | elif not bheads: |
|
2037 | 2041 | raise error.Abort(_(b'branch "%s" has no heads to close') % branch) |
|
2038 | 2042 | elif ( |
|
2039 | 2043 | branch == repo[b'.'].branch() |
|
2040 | 2044 | and repo[b'.'].node() not in bheads |
|
2041 | 2045 | and not opts.get(b'force_close_branch') |
|
2042 | 2046 | ): |
|
2043 | 2047 | hint = _( |
|
2044 | 2048 | b'use --force-close-branch to close branch from a non-head' |
|
2045 | 2049 | b' changeset' |
|
2046 | 2050 | ) |
|
2047 | 2051 | raise error.Abort(_(b'can only close branch heads'), hint=hint) |
|
2048 | 2052 | elif opts.get(b'amend'): |
|
2049 | 2053 | if ( |
|
2050 | 2054 | repo[b'.'].p1().branch() != branch |
|
2051 | 2055 | and repo[b'.'].p2().branch() != branch |
|
2052 | 2056 | ): |
|
2053 | 2057 | raise error.Abort(_(b'can only close branch heads')) |
|
2054 | 2058 | |
|
2055 | 2059 | if opts.get(b'amend'): |
|
2056 | 2060 | if ui.configbool(b'ui', b'commitsubrepos'): |
|
2057 | 2061 | raise error.Abort(_(b'cannot amend with ui.commitsubrepos enabled')) |
|
2058 | 2062 | |
|
2059 | 2063 | old = repo[b'.'] |
|
2060 | 2064 | rewriteutil.precheck(repo, [old.rev()], b'amend') |
|
2061 | 2065 | |
|
2062 | 2066 | # Currently histedit gets confused if an amend happens while histedit |
|
2063 | 2067 | # is in progress. Since we have a checkunfinished command, we are |
|
2064 | 2068 | # temporarily honoring it. |
|
2065 | 2069 | # |
|
2066 | 2070 | # Note: eventually this guard will be removed. Please do not expect |
|
2067 | 2071 | # this behavior to remain. |
|
2068 | 2072 | if not obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
2069 | 2073 | cmdutil.checkunfinished(repo) |
|
2070 | 2074 | |
|
2071 | 2075 | node = cmdutil.amend(ui, repo, old, extra, pats, opts) |
|
2072 | 2076 | if node == old.node(): |
|
2073 | 2077 | ui.status(_(b"nothing changed\n")) |
|
2074 | 2078 | return 1 |
|
2075 | 2079 | else: |
|
2076 | 2080 | |
|
2077 | 2081 | def commitfunc(ui, repo, message, match, opts): |
|
2078 | 2082 | overrides = {} |
|
2079 | 2083 | if opts.get(b'secret'): |
|
2080 | 2084 | overrides[(b'phases', b'new-commit')] = b'secret' |
|
2081 | 2085 | |
|
2082 | 2086 | baseui = repo.baseui |
|
2083 | 2087 | with baseui.configoverride(overrides, b'commit'): |
|
2084 | 2088 | with ui.configoverride(overrides, b'commit'): |
|
2085 | 2089 | editform = cmdutil.mergeeditform( |
|
2086 | 2090 | repo[None], b'commit.normal' |
|
2087 | 2091 | ) |
|
2088 | 2092 | editor = cmdutil.getcommiteditor( |
|
2089 | 2093 | editform=editform, **pycompat.strkwargs(opts) |
|
2090 | 2094 | ) |
|
2091 | 2095 | return repo.commit( |
|
2092 | 2096 | message, |
|
2093 | 2097 | opts.get(b'user'), |
|
2094 | 2098 | opts.get(b'date'), |
|
2095 | 2099 | match, |
|
2096 | 2100 | editor=editor, |
|
2097 | 2101 | extra=extra, |
|
2098 | 2102 | ) |
|
2099 | 2103 | |
|
2100 | 2104 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
2101 | 2105 | |
|
2102 | 2106 | if not node: |
|
2103 | 2107 | stat = cmdutil.postcommitstatus(repo, pats, opts) |
|
2104 | 2108 | if stat.deleted: |
|
2105 | 2109 | ui.status( |
|
2106 | 2110 | _( |
|
2107 | 2111 | b"nothing changed (%d missing files, see " |
|
2108 | 2112 | b"'hg status')\n" |
|
2109 | 2113 | ) |
|
2110 | 2114 | % len(stat.deleted) |
|
2111 | 2115 | ) |
|
2112 | 2116 | else: |
|
2113 | 2117 | ui.status(_(b"nothing changed\n")) |
|
2114 | 2118 | return 1 |
|
2115 | 2119 | |
|
2116 | cmdutil.commitstatus(repo, node, branch, bheads, opts) | |
|
2120 | cmdutil.commitstatus(repo, node, branch, bheads, tip, opts) | |
|
2117 | 2121 | |
|
2118 | 2122 | if not ui.quiet and ui.configbool(b'commands', b'commit.post-status'): |
|
2119 | 2123 | status( |
|
2120 | 2124 | ui, |
|
2121 | 2125 | repo, |
|
2122 | 2126 | modified=True, |
|
2123 | 2127 | added=True, |
|
2124 | 2128 | removed=True, |
|
2125 | 2129 | deleted=True, |
|
2126 | 2130 | unknown=True, |
|
2127 | 2131 | subrepos=opts.get(b'subrepos'), |
|
2128 | 2132 | ) |
|
2129 | 2133 | |
|
2130 | 2134 | |
|
2131 | 2135 | @command( |
|
2132 | 2136 | b'config|showconfig|debugconfig', |
|
2133 | 2137 | [ |
|
2134 | 2138 | (b'u', b'untrusted', None, _(b'show untrusted configuration options')), |
|
2135 | 2139 | (b'e', b'edit', None, _(b'edit user config')), |
|
2136 | 2140 | (b'l', b'local', None, _(b'edit repository config')), |
|
2137 | 2141 | ( |
|
2138 | 2142 | b'', |
|
2139 | 2143 | b'shared', |
|
2140 | 2144 | None, |
|
2141 | 2145 | _(b'edit shared source repository config (EXPERIMENTAL)'), |
|
2142 | 2146 | ), |
|
2143 | 2147 | (b'', b'non-shared', None, _(b'edit non shared config (EXPERIMENTAL)')), |
|
2144 | 2148 | (b'g', b'global', None, _(b'edit global config')), |
|
2145 | 2149 | ] |
|
2146 | 2150 | + formatteropts, |
|
2147 | 2151 | _(b'[-u] [NAME]...'), |
|
2148 | 2152 | helpcategory=command.CATEGORY_HELP, |
|
2149 | 2153 | optionalrepo=True, |
|
2150 | 2154 | intents={INTENT_READONLY}, |
|
2151 | 2155 | ) |
|
2152 | 2156 | def config(ui, repo, *values, **opts): |
|
2153 | 2157 | """show combined config settings from all hgrc files |
|
2154 | 2158 | |
|
2155 | 2159 | With no arguments, print names and values of all config items. |
|
2156 | 2160 | |
|
2157 | 2161 | With one argument of the form section.name, print just the value |
|
2158 | 2162 | of that config item. |
|
2159 | 2163 | |
|
2160 | 2164 | With multiple arguments, print names and values of all config |
|
2161 | 2165 | items with matching section names or section.names. |
|
2162 | 2166 | |
|
2163 | 2167 | With --edit, start an editor on the user-level config file. With |
|
2164 | 2168 | --global, edit the system-wide config file. With --local, edit the |
|
2165 | 2169 | repository-level config file. |
|
2166 | 2170 | |
|
2167 | 2171 | With --debug, the source (filename and line number) is printed |
|
2168 | 2172 | for each config item. |
|
2169 | 2173 | |
|
2170 | 2174 | See :hg:`help config` for more information about config files. |
|
2171 | 2175 | |
|
2172 | 2176 | .. container:: verbose |
|
2173 | 2177 | |
|
2174 | 2178 | --non-shared flag is used to edit `.hg/hgrc-not-shared` config file. |
|
2175 | 2179 | This file is not shared across shares when in share-safe mode. |
|
2176 | 2180 | |
|
2177 | 2181 | Template: |
|
2178 | 2182 | |
|
2179 | 2183 | The following keywords are supported. See also :hg:`help templates`. |
|
2180 | 2184 | |
|
2181 | 2185 | :name: String. Config name. |
|
2182 | 2186 | :source: String. Filename and line number where the item is defined. |
|
2183 | 2187 | :value: String. Config value. |
|
2184 | 2188 | |
|
2185 | 2189 | The --shared flag can be used to edit the config file of shared source |
|
2186 | 2190 | repository. It only works when you have shared using the experimental |
|
2187 | 2191 | share safe feature. |
|
2188 | 2192 | |
|
2189 | 2193 | Returns 0 on success, 1 if NAME does not exist. |
|
2190 | 2194 | |
|
2191 | 2195 | """ |
|
2192 | 2196 | |
|
2193 | 2197 | opts = pycompat.byteskwargs(opts) |
|
2194 | 2198 | editopts = (b'edit', b'local', b'global', b'shared', b'non_shared') |
|
2195 | 2199 | if any(opts.get(o) for o in editopts): |
|
2196 | 2200 | cmdutil.check_at_most_one_arg(opts, *editopts[1:]) |
|
2197 | 2201 | if opts.get(b'local'): |
|
2198 | 2202 | if not repo: |
|
2199 | 2203 | raise error.Abort(_(b"can't use --local outside a repository")) |
|
2200 | 2204 | paths = [repo.vfs.join(b'hgrc')] |
|
2201 | 2205 | elif opts.get(b'global'): |
|
2202 | 2206 | paths = rcutil.systemrcpath() |
|
2203 | 2207 | elif opts.get(b'shared'): |
|
2204 | 2208 | if not repo.shared(): |
|
2205 | 2209 | raise error.Abort( |
|
2206 | 2210 | _(b"repository is not shared; can't use --shared") |
|
2207 | 2211 | ) |
|
2208 | 2212 | if requirements.SHARESAFE_REQUIREMENT not in repo.requirements: |
|
2209 | 2213 | raise error.Abort( |
|
2210 | 2214 | _( |
|
2211 | 2215 | b"share safe feature not unabled; " |
|
2212 | 2216 | b"unable to edit shared source repository config" |
|
2213 | 2217 | ) |
|
2214 | 2218 | ) |
|
2215 | 2219 | paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')] |
|
2216 | 2220 | elif opts.get(b'non_shared'): |
|
2217 | 2221 | paths = [repo.vfs.join(b'hgrc-not-shared')] |
|
2218 | 2222 | else: |
|
2219 | 2223 | paths = rcutil.userrcpath() |
|
2220 | 2224 | |
|
2221 | 2225 | for f in paths: |
|
2222 | 2226 | if os.path.exists(f): |
|
2223 | 2227 | break |
|
2224 | 2228 | else: |
|
2225 | 2229 | if opts.get(b'global'): |
|
2226 | 2230 | samplehgrc = uimod.samplehgrcs[b'global'] |
|
2227 | 2231 | elif opts.get(b'local'): |
|
2228 | 2232 | samplehgrc = uimod.samplehgrcs[b'local'] |
|
2229 | 2233 | else: |
|
2230 | 2234 | samplehgrc = uimod.samplehgrcs[b'user'] |
|
2231 | 2235 | |
|
2232 | 2236 | f = paths[0] |
|
2233 | 2237 | fp = open(f, b"wb") |
|
2234 | 2238 | fp.write(util.tonativeeol(samplehgrc)) |
|
2235 | 2239 | fp.close() |
|
2236 | 2240 | |
|
2237 | 2241 | editor = ui.geteditor() |
|
2238 | 2242 | ui.system( |
|
2239 | 2243 | b"%s \"%s\"" % (editor, f), |
|
2240 | 2244 | onerr=error.Abort, |
|
2241 | 2245 | errprefix=_(b"edit failed"), |
|
2242 | 2246 | blockedtag=b'config_edit', |
|
2243 | 2247 | ) |
|
2244 | 2248 | return |
|
2245 | 2249 | ui.pager(b'config') |
|
2246 | 2250 | fm = ui.formatter(b'config', opts) |
|
2247 | 2251 | for t, f in rcutil.rccomponents(): |
|
2248 | 2252 | if t == b'path': |
|
2249 | 2253 | ui.debug(b'read config from: %s\n' % f) |
|
2250 | 2254 | elif t == b'resource': |
|
2251 | 2255 | ui.debug(b'read config from: resource:%s.%s\n' % (f[0], f[1])) |
|
2252 | 2256 | elif t == b'items': |
|
2253 | 2257 | # Don't print anything for 'items'. |
|
2254 | 2258 | pass |
|
2255 | 2259 | else: |
|
2256 | 2260 | raise error.ProgrammingError(b'unknown rctype: %s' % t) |
|
2257 | 2261 | untrusted = bool(opts.get(b'untrusted')) |
|
2258 | 2262 | |
|
2259 | 2263 | selsections = selentries = [] |
|
2260 | 2264 | if values: |
|
2261 | 2265 | selsections = [v for v in values if b'.' not in v] |
|
2262 | 2266 | selentries = [v for v in values if b'.' in v] |
|
2263 | 2267 | uniquesel = len(selentries) == 1 and not selsections |
|
2264 | 2268 | selsections = set(selsections) |
|
2265 | 2269 | selentries = set(selentries) |
|
2266 | 2270 | |
|
2267 | 2271 | matched = False |
|
2268 | 2272 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
2269 | 2273 | source = ui.configsource(section, name, untrusted) |
|
2270 | 2274 | value = pycompat.bytestr(value) |
|
2271 | 2275 | defaultvalue = ui.configdefault(section, name) |
|
2272 | 2276 | if fm.isplain(): |
|
2273 | 2277 | source = source or b'none' |
|
2274 | 2278 | value = value.replace(b'\n', b'\\n') |
|
2275 | 2279 | entryname = section + b'.' + name |
|
2276 | 2280 | if values and not (section in selsections or entryname in selentries): |
|
2277 | 2281 | continue |
|
2278 | 2282 | fm.startitem() |
|
2279 | 2283 | fm.condwrite(ui.debugflag, b'source', b'%s: ', source) |
|
2280 | 2284 | if uniquesel: |
|
2281 | 2285 | fm.data(name=entryname) |
|
2282 | 2286 | fm.write(b'value', b'%s\n', value) |
|
2283 | 2287 | else: |
|
2284 | 2288 | fm.write(b'name value', b'%s=%s\n', entryname, value) |
|
2285 | 2289 | if formatter.isprintable(defaultvalue): |
|
2286 | 2290 | fm.data(defaultvalue=defaultvalue) |
|
2287 | 2291 | elif isinstance(defaultvalue, list) and all( |
|
2288 | 2292 | formatter.isprintable(e) for e in defaultvalue |
|
2289 | 2293 | ): |
|
2290 | 2294 | fm.data(defaultvalue=fm.formatlist(defaultvalue, name=b'value')) |
|
2291 | 2295 | # TODO: no idea how to process unsupported defaultvalue types |
|
2292 | 2296 | matched = True |
|
2293 | 2297 | fm.end() |
|
2294 | 2298 | if matched: |
|
2295 | 2299 | return 0 |
|
2296 | 2300 | return 1 |
|
2297 | 2301 | |
|
2298 | 2302 | |
|
2299 | 2303 | @command( |
|
2300 | 2304 | b'continue', |
|
2301 | 2305 | dryrunopts, |
|
2302 | 2306 | helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
|
2303 | 2307 | helpbasic=True, |
|
2304 | 2308 | ) |
|
2305 | 2309 | def continuecmd(ui, repo, **opts): |
|
2306 | 2310 | """resumes an interrupted operation (EXPERIMENTAL) |
|
2307 | 2311 | |
|
2308 | 2312 | Finishes a multistep operation like graft, histedit, rebase, merge, |
|
2309 | 2313 | and unshelve if they are in an interrupted state. |
|
2310 | 2314 | |
|
2311 | 2315 | use --dry-run/-n to dry run the command. |
|
2312 | 2316 | """ |
|
2313 | 2317 | dryrun = opts.get('dry_run') |
|
2314 | 2318 | contstate = cmdutil.getunfinishedstate(repo) |
|
2315 | 2319 | if not contstate: |
|
2316 | 2320 | raise error.Abort(_(b'no operation in progress')) |
|
2317 | 2321 | if not contstate.continuefunc: |
|
2318 | 2322 | raise error.Abort( |
|
2319 | 2323 | ( |
|
2320 | 2324 | _(b"%s in progress but does not support 'hg continue'") |
|
2321 | 2325 | % (contstate._opname) |
|
2322 | 2326 | ), |
|
2323 | 2327 | hint=contstate.continuemsg(), |
|
2324 | 2328 | ) |
|
2325 | 2329 | if dryrun: |
|
2326 | 2330 | ui.status(_(b'%s in progress, will be resumed\n') % (contstate._opname)) |
|
2327 | 2331 | return |
|
2328 | 2332 | return contstate.continuefunc(ui, repo) |
|
2329 | 2333 | |
|
2330 | 2334 | |
|
2331 | 2335 | @command( |
|
2332 | 2336 | b'copy|cp', |
|
2333 | 2337 | [ |
|
2334 | 2338 | (b'', b'forget', None, _(b'unmark a destination file as copied')), |
|
2335 | 2339 | (b'A', b'after', None, _(b'record a copy that has already occurred')), |
|
2336 | 2340 | ( |
|
2337 | 2341 | b'', |
|
2338 | 2342 | b'at-rev', |
|
2339 | 2343 | b'', |
|
2340 | 2344 | _(b'(un)mark copies in the given revision (EXPERIMENTAL)'), |
|
2341 | 2345 | _(b'REV'), |
|
2342 | 2346 | ), |
|
2343 | 2347 | ( |
|
2344 | 2348 | b'f', |
|
2345 | 2349 | b'force', |
|
2346 | 2350 | None, |
|
2347 | 2351 | _(b'forcibly copy over an existing managed file'), |
|
2348 | 2352 | ), |
|
2349 | 2353 | ] |
|
2350 | 2354 | + walkopts |
|
2351 | 2355 | + dryrunopts, |
|
2352 | 2356 | _(b'[OPTION]... (SOURCE... DEST | --forget DEST...)'), |
|
2353 | 2357 | helpcategory=command.CATEGORY_FILE_CONTENTS, |
|
2354 | 2358 | ) |
|
2355 | 2359 | def copy(ui, repo, *pats, **opts): |
|
2356 | 2360 | """mark files as copied for the next commit |
|
2357 | 2361 | |
|
2358 | 2362 | Mark dest as having copies of source files. If dest is a |
|
2359 | 2363 | directory, copies are put in that directory. If dest is a file, |
|
2360 | 2364 | the source must be a single file. |
|
2361 | 2365 | |
|
2362 | 2366 | By default, this command copies the contents of files as they |
|
2363 | 2367 | exist in the working directory. If invoked with -A/--after, the |
|
2364 | 2368 | operation is recorded, but no copying is performed. |
|
2365 | 2369 | |
|
2366 | 2370 | To undo marking a destination file as copied, use --forget. With that |
|
2367 | 2371 | option, all given (positional) arguments are unmarked as copies. The |
|
2368 | 2372 | destination file(s) will be left in place (still tracked). |
|
2369 | 2373 | |
|
2370 | 2374 | This command takes effect with the next commit by default. |
|
2371 | 2375 | |
|
2372 | 2376 | Returns 0 on success, 1 if errors are encountered. |
|
2373 | 2377 | """ |
|
2374 | 2378 | opts = pycompat.byteskwargs(opts) |
|
2375 | 2379 | with repo.wlock(): |
|
2376 | 2380 | return cmdutil.copy(ui, repo, pats, opts) |
|
2377 | 2381 | |
|
2378 | 2382 | |
|
2379 | 2383 | @command( |
|
2380 | 2384 | b'debugcommands', |
|
2381 | 2385 | [], |
|
2382 | 2386 | _(b'[COMMAND]'), |
|
2383 | 2387 | helpcategory=command.CATEGORY_HELP, |
|
2384 | 2388 | norepo=True, |
|
2385 | 2389 | ) |
|
2386 | 2390 | def debugcommands(ui, cmd=b'', *args): |
|
2387 | 2391 | """list all available commands and options""" |
|
2388 | 2392 | for cmd, vals in sorted(pycompat.iteritems(table)): |
|
2389 | 2393 | cmd = cmd.split(b'|')[0] |
|
2390 | 2394 | opts = b', '.join([i[1] for i in vals[1]]) |
|
2391 | 2395 | ui.write(b'%s: %s\n' % (cmd, opts)) |
|
2392 | 2396 | |
|
2393 | 2397 | |
|
2394 | 2398 | @command( |
|
2395 | 2399 | b'debugcomplete', |
|
2396 | 2400 | [(b'o', b'options', None, _(b'show the command options'))], |
|
2397 | 2401 | _(b'[-o] CMD'), |
|
2398 | 2402 | helpcategory=command.CATEGORY_HELP, |
|
2399 | 2403 | norepo=True, |
|
2400 | 2404 | ) |
|
2401 | 2405 | def debugcomplete(ui, cmd=b'', **opts): |
|
2402 | 2406 | """returns the completion list associated with the given command""" |
|
2403 | 2407 | |
|
2404 | 2408 | if opts.get('options'): |
|
2405 | 2409 | options = [] |
|
2406 | 2410 | otables = [globalopts] |
|
2407 | 2411 | if cmd: |
|
2408 | 2412 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
2409 | 2413 | otables.append(entry[1]) |
|
2410 | 2414 | for t in otables: |
|
2411 | 2415 | for o in t: |
|
2412 | 2416 | if b"(DEPRECATED)" in o[3]: |
|
2413 | 2417 | continue |
|
2414 | 2418 | if o[0]: |
|
2415 | 2419 | options.append(b'-%s' % o[0]) |
|
2416 | 2420 | options.append(b'--%s' % o[1]) |
|
2417 | 2421 | ui.write(b"%s\n" % b"\n".join(options)) |
|
2418 | 2422 | return |
|
2419 | 2423 | |
|
2420 | 2424 | cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table) |
|
2421 | 2425 | if ui.verbose: |
|
2422 | 2426 | cmdlist = [b' '.join(c[0]) for c in cmdlist.values()] |
|
2423 | 2427 | ui.write(b"%s\n" % b"\n".join(sorted(cmdlist))) |
|
2424 | 2428 | |
|
2425 | 2429 | |
|
2426 | 2430 | @command( |
|
2427 | 2431 | b'diff', |
|
2428 | 2432 | [ |
|
2429 | 2433 | (b'r', b'rev', [], _(b'revision'), _(b'REV')), |
|
2430 | 2434 | (b'c', b'change', b'', _(b'change made by revision'), _(b'REV')), |
|
2431 | 2435 | ] |
|
2432 | 2436 | + diffopts |
|
2433 | 2437 | + diffopts2 |
|
2434 | 2438 | + walkopts |
|
2435 | 2439 | + subrepoopts, |
|
2436 | 2440 | _(b'[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), |
|
2437 | 2441 | helpcategory=command.CATEGORY_FILE_CONTENTS, |
|
2438 | 2442 | helpbasic=True, |
|
2439 | 2443 | inferrepo=True, |
|
2440 | 2444 | intents={INTENT_READONLY}, |
|
2441 | 2445 | ) |
|
2442 | 2446 | def diff(ui, repo, *pats, **opts): |
|
2443 | 2447 | """diff repository (or selected files) |
|
2444 | 2448 | |
|
2445 | 2449 | Show differences between revisions for the specified files. |
|
2446 | 2450 | |
|
2447 | 2451 | Differences between files are shown using the unified diff format. |
|
2448 | 2452 | |
|
2449 | 2453 | .. note:: |
|
2450 | 2454 | |
|
2451 | 2455 | :hg:`diff` may generate unexpected results for merges, as it will |
|
2452 | 2456 | default to comparing against the working directory's first |
|
2453 | 2457 | parent changeset if no revisions are specified. |
|
2454 | 2458 | |
|
2455 | 2459 | When two revision arguments are given, then changes are shown |
|
2456 | 2460 | between those revisions. If only one revision is specified then |
|
2457 | 2461 | that revision is compared to the working directory, and, when no |
|
2458 | 2462 | revisions are specified, the working directory files are compared |
|
2459 | 2463 | to its first parent. |
|
2460 | 2464 | |
|
2461 | 2465 | Alternatively you can specify -c/--change with a revision to see |
|
2462 | 2466 | the changes in that changeset relative to its first parent. |
|
2463 | 2467 | |
|
2464 | 2468 | Without the -a/--text option, diff will avoid generating diffs of |
|
2465 | 2469 | files it detects as binary. With -a, diff will generate a diff |
|
2466 | 2470 | anyway, probably with undesirable results. |
|
2467 | 2471 | |
|
2468 | 2472 | Use the -g/--git option to generate diffs in the git extended diff |
|
2469 | 2473 | format. For more information, read :hg:`help diffs`. |
|
2470 | 2474 | |
|
2471 | 2475 | .. container:: verbose |
|
2472 | 2476 | |
|
2473 | 2477 | Examples: |
|
2474 | 2478 | |
|
2475 | 2479 | - compare a file in the current working directory to its parent:: |
|
2476 | 2480 | |
|
2477 | 2481 | hg diff foo.c |
|
2478 | 2482 | |
|
2479 | 2483 | - compare two historical versions of a directory, with rename info:: |
|
2480 | 2484 | |
|
2481 | 2485 | hg diff --git -r 1.0:1.2 lib/ |
|
2482 | 2486 | |
|
2483 | 2487 | - get change stats relative to the last change on some date:: |
|
2484 | 2488 | |
|
2485 | 2489 | hg diff --stat -r "date('may 2')" |
|
2486 | 2490 | |
|
2487 | 2491 | - diff all newly-added files that contain a keyword:: |
|
2488 | 2492 | |
|
2489 | 2493 | hg diff "set:added() and grep(GNU)" |
|
2490 | 2494 | |
|
2491 | 2495 | - compare a revision and its parents:: |
|
2492 | 2496 | |
|
2493 | 2497 | hg diff -c 9353 # compare against first parent |
|
2494 | 2498 | hg diff -r 9353^:9353 # same using revset syntax |
|
2495 | 2499 | hg diff -r 9353^2:9353 # compare against the second parent |
|
2496 | 2500 | |
|
2497 | 2501 | Returns 0 on success. |
|
2498 | 2502 | """ |
|
2499 | 2503 | |
|
2500 | 2504 | cmdutil.check_at_most_one_arg(opts, 'rev', 'change') |
|
2501 | 2505 | opts = pycompat.byteskwargs(opts) |
|
2502 | 2506 | revs = opts.get(b'rev') |
|
2503 | 2507 | change = opts.get(b'change') |
|
2504 | 2508 | stat = opts.get(b'stat') |
|
2505 | 2509 | reverse = opts.get(b'reverse') |
|
2506 | 2510 | |
|
2507 | 2511 | if change: |
|
2508 | 2512 | repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn') |
|
2509 | 2513 | ctx2 = scmutil.revsingle(repo, change, None) |
|
2510 | 2514 | ctx1 = ctx2.p1() |
|
2511 | 2515 | else: |
|
2512 | 2516 | repo = scmutil.unhidehashlikerevs(repo, revs, b'nowarn') |
|
2513 | 2517 | ctx1, ctx2 = scmutil.revpair(repo, revs) |
|
2514 | 2518 | |
|
2515 | 2519 | if reverse: |
|
2516 | 2520 | ctxleft = ctx2 |
|
2517 | 2521 | ctxright = ctx1 |
|
2518 | 2522 | else: |
|
2519 | 2523 | ctxleft = ctx1 |
|
2520 | 2524 | ctxright = ctx2 |
|
2521 | 2525 | |
|
2522 | 2526 | diffopts = patch.diffallopts(ui, opts) |
|
2523 | 2527 | m = scmutil.match(ctx2, pats, opts) |
|
2524 | 2528 | m = repo.narrowmatch(m) |
|
2525 | 2529 | ui.pager(b'diff') |
|
2526 | 2530 | logcmdutil.diffordiffstat( |
|
2527 | 2531 | ui, |
|
2528 | 2532 | repo, |
|
2529 | 2533 | diffopts, |
|
2530 | 2534 | ctxleft, |
|
2531 | 2535 | ctxright, |
|
2532 | 2536 | m, |
|
2533 | 2537 | stat=stat, |
|
2534 | 2538 | listsubrepos=opts.get(b'subrepos'), |
|
2535 | 2539 | root=opts.get(b'root'), |
|
2536 | 2540 | ) |
|
2537 | 2541 | |
|
2538 | 2542 | |
|
2539 | 2543 | @command( |
|
2540 | 2544 | b'export', |
|
2541 | 2545 | [ |
|
2542 | 2546 | ( |
|
2543 | 2547 | b'B', |
|
2544 | 2548 | b'bookmark', |
|
2545 | 2549 | b'', |
|
2546 | 2550 | _(b'export changes only reachable by given bookmark'), |
|
2547 | 2551 | _(b'BOOKMARK'), |
|
2548 | 2552 | ), |
|
2549 | 2553 | ( |
|
2550 | 2554 | b'o', |
|
2551 | 2555 | b'output', |
|
2552 | 2556 | b'', |
|
2553 | 2557 | _(b'print output to file with formatted name'), |
|
2554 | 2558 | _(b'FORMAT'), |
|
2555 | 2559 | ), |
|
2556 | 2560 | (b'', b'switch-parent', None, _(b'diff against the second parent')), |
|
2557 | 2561 | (b'r', b'rev', [], _(b'revisions to export'), _(b'REV')), |
|
2558 | 2562 | ] |
|
2559 | 2563 | + diffopts |
|
2560 | 2564 | + formatteropts, |
|
2561 | 2565 | _(b'[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'), |
|
2562 | 2566 | helpcategory=command.CATEGORY_IMPORT_EXPORT, |
|
2563 | 2567 | helpbasic=True, |
|
2564 | 2568 | intents={INTENT_READONLY}, |
|
2565 | 2569 | ) |
|
2566 | 2570 | def export(ui, repo, *changesets, **opts): |
|
2567 | 2571 | """dump the header and diffs for one or more changesets |
|
2568 | 2572 | |
|
2569 | 2573 | Print the changeset header and diffs for one or more revisions. |
|
2570 | 2574 | If no revision is given, the parent of the working directory is used. |
|
2571 | 2575 | |
|
2572 | 2576 | The information shown in the changeset header is: author, date, |
|
2573 | 2577 | branch name (if non-default), changeset hash, parent(s) and commit |
|
2574 | 2578 | comment. |
|
2575 | 2579 | |
|
2576 | 2580 | .. note:: |
|
2577 | 2581 | |
|
2578 | 2582 | :hg:`export` may generate unexpected diff output for merge |
|
2579 | 2583 | changesets, as it will compare the merge changeset against its |
|
2580 | 2584 | first parent only. |
|
2581 | 2585 | |
|
2582 | 2586 | Output may be to a file, in which case the name of the file is |
|
2583 | 2587 | given using a template string. See :hg:`help templates`. In addition |
|
2584 | 2588 | to the common template keywords, the following formatting rules are |
|
2585 | 2589 | supported: |
|
2586 | 2590 | |
|
2587 | 2591 | :``%%``: literal "%" character |
|
2588 | 2592 | :``%H``: changeset hash (40 hexadecimal digits) |
|
2589 | 2593 | :``%N``: number of patches being generated |
|
2590 | 2594 | :``%R``: changeset revision number |
|
2591 | 2595 | :``%b``: basename of the exporting repository |
|
2592 | 2596 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
2593 | 2597 | :``%m``: first line of the commit message (only alphanumeric characters) |
|
2594 | 2598 | :``%n``: zero-padded sequence number, starting at 1 |
|
2595 | 2599 | :``%r``: zero-padded changeset revision number |
|
2596 | 2600 | :``\\``: literal "\\" character |
|
2597 | 2601 | |
|
2598 | 2602 | Without the -a/--text option, export will avoid generating diffs |
|
2599 | 2603 | of files it detects as binary. With -a, export will generate a |
|
2600 | 2604 | diff anyway, probably with undesirable results. |
|
2601 | 2605 | |
|
2602 | 2606 | With -B/--bookmark changesets reachable by the given bookmark are |
|
2603 | 2607 | selected. |
|
2604 | 2608 | |
|
2605 | 2609 | Use the -g/--git option to generate diffs in the git extended diff |
|
2606 | 2610 | format. See :hg:`help diffs` for more information. |
|
2607 | 2611 | |
|
2608 | 2612 | With the --switch-parent option, the diff will be against the |
|
2609 | 2613 | second parent. It can be useful to review a merge. |
|
2610 | 2614 | |
|
2611 | 2615 | .. container:: verbose |
|
2612 | 2616 | |
|
2613 | 2617 | Template: |
|
2614 | 2618 | |
|
2615 | 2619 | The following keywords are supported in addition to the common template |
|
2616 | 2620 | keywords and functions. See also :hg:`help templates`. |
|
2617 | 2621 | |
|
2618 | 2622 | :diff: String. Diff content. |
|
2619 | 2623 | :parents: List of strings. Parent nodes of the changeset. |
|
2620 | 2624 | |
|
2621 | 2625 | Examples: |
|
2622 | 2626 | |
|
2623 | 2627 | - use export and import to transplant a bugfix to the current |
|
2624 | 2628 | branch:: |
|
2625 | 2629 | |
|
2626 | 2630 | hg export -r 9353 | hg import - |
|
2627 | 2631 | |
|
2628 | 2632 | - export all the changesets between two revisions to a file with |
|
2629 | 2633 | rename information:: |
|
2630 | 2634 | |
|
2631 | 2635 | hg export --git -r 123:150 > changes.txt |
|
2632 | 2636 | |
|
2633 | 2637 | - split outgoing changes into a series of patches with |
|
2634 | 2638 | descriptive names:: |
|
2635 | 2639 | |
|
2636 | 2640 | hg export -r "outgoing()" -o "%n-%m.patch" |
|
2637 | 2641 | |
|
2638 | 2642 | Returns 0 on success. |
|
2639 | 2643 | """ |
|
2640 | 2644 | opts = pycompat.byteskwargs(opts) |
|
2641 | 2645 | bookmark = opts.get(b'bookmark') |
|
2642 | 2646 | changesets += tuple(opts.get(b'rev', [])) |
|
2643 | 2647 | |
|
2644 | 2648 | cmdutil.check_at_most_one_arg(opts, b'rev', b'bookmark') |
|
2645 | 2649 | |
|
2646 | 2650 | if bookmark: |
|
2647 | 2651 | if bookmark not in repo._bookmarks: |
|
2648 | 2652 | raise error.Abort(_(b"bookmark '%s' not found") % bookmark) |
|
2649 | 2653 | |
|
2650 | 2654 | revs = scmutil.bookmarkrevs(repo, bookmark) |
|
2651 | 2655 | else: |
|
2652 | 2656 | if not changesets: |
|
2653 | 2657 | changesets = [b'.'] |
|
2654 | 2658 | |
|
2655 | 2659 | repo = scmutil.unhidehashlikerevs(repo, changesets, b'nowarn') |
|
2656 | 2660 | revs = scmutil.revrange(repo, changesets) |
|
2657 | 2661 | |
|
2658 | 2662 | if not revs: |
|
2659 | 2663 | raise error.Abort(_(b"export requires at least one changeset")) |
|
2660 | 2664 | if len(revs) > 1: |
|
2661 | 2665 | ui.note(_(b'exporting patches:\n')) |
|
2662 | 2666 | else: |
|
2663 | 2667 | ui.note(_(b'exporting patch:\n')) |
|
2664 | 2668 | |
|
2665 | 2669 | fntemplate = opts.get(b'output') |
|
2666 | 2670 | if cmdutil.isstdiofilename(fntemplate): |
|
2667 | 2671 | fntemplate = b'' |
|
2668 | 2672 | |
|
2669 | 2673 | if fntemplate: |
|
2670 | 2674 | fm = formatter.nullformatter(ui, b'export', opts) |
|
2671 | 2675 | else: |
|
2672 | 2676 | ui.pager(b'export') |
|
2673 | 2677 | fm = ui.formatter(b'export', opts) |
|
2674 | 2678 | with fm: |
|
2675 | 2679 | cmdutil.export( |
|
2676 | 2680 | repo, |
|
2677 | 2681 | revs, |
|
2678 | 2682 | fm, |
|
2679 | 2683 | fntemplate=fntemplate, |
|
2680 | 2684 | switch_parent=opts.get(b'switch_parent'), |
|
2681 | 2685 | opts=patch.diffallopts(ui, opts), |
|
2682 | 2686 | ) |
|
2683 | 2687 | |
|
2684 | 2688 | |
|
2685 | 2689 | @command( |
|
2686 | 2690 | b'files', |
|
2687 | 2691 | [ |
|
2688 | 2692 | ( |
|
2689 | 2693 | b'r', |
|
2690 | 2694 | b'rev', |
|
2691 | 2695 | b'', |
|
2692 | 2696 | _(b'search the repository as it is in REV'), |
|
2693 | 2697 | _(b'REV'), |
|
2694 | 2698 | ), |
|
2695 | 2699 | ( |
|
2696 | 2700 | b'0', |
|
2697 | 2701 | b'print0', |
|
2698 | 2702 | None, |
|
2699 | 2703 | _(b'end filenames with NUL, for use with xargs'), |
|
2700 | 2704 | ), |
|
2701 | 2705 | ] |
|
2702 | 2706 | + walkopts |
|
2703 | 2707 | + formatteropts |
|
2704 | 2708 | + subrepoopts, |
|
2705 | 2709 | _(b'[OPTION]... [FILE]...'), |
|
2706 | 2710 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
2707 | 2711 | intents={INTENT_READONLY}, |
|
2708 | 2712 | ) |
|
2709 | 2713 | def files(ui, repo, *pats, **opts): |
|
2710 | 2714 | """list tracked files |
|
2711 | 2715 | |
|
2712 | 2716 | Print files under Mercurial control in the working directory or |
|
2713 | 2717 | specified revision for given files (excluding removed files). |
|
2714 | 2718 | Files can be specified as filenames or filesets. |
|
2715 | 2719 | |
|
2716 | 2720 | If no files are given to match, this command prints the names |
|
2717 | 2721 | of all files under Mercurial control. |
|
2718 | 2722 | |
|
2719 | 2723 | .. container:: verbose |
|
2720 | 2724 | |
|
2721 | 2725 | Template: |
|
2722 | 2726 | |
|
2723 | 2727 | The following keywords are supported in addition to the common template |
|
2724 | 2728 | keywords and functions. See also :hg:`help templates`. |
|
2725 | 2729 | |
|
2726 | 2730 | :flags: String. Character denoting file's symlink and executable bits. |
|
2727 | 2731 | :path: String. Repository-absolute path of the file. |
|
2728 | 2732 | :size: Integer. Size of the file in bytes. |
|
2729 | 2733 | |
|
2730 | 2734 | Examples: |
|
2731 | 2735 | |
|
2732 | 2736 | - list all files under the current directory:: |
|
2733 | 2737 | |
|
2734 | 2738 | hg files . |
|
2735 | 2739 | |
|
2736 | 2740 | - shows sizes and flags for current revision:: |
|
2737 | 2741 | |
|
2738 | 2742 | hg files -vr . |
|
2739 | 2743 | |
|
2740 | 2744 | - list all files named README:: |
|
2741 | 2745 | |
|
2742 | 2746 | hg files -I "**/README" |
|
2743 | 2747 | |
|
2744 | 2748 | - list all binary files:: |
|
2745 | 2749 | |
|
2746 | 2750 | hg files "set:binary()" |
|
2747 | 2751 | |
|
2748 | 2752 | - find files containing a regular expression:: |
|
2749 | 2753 | |
|
2750 | 2754 | hg files "set:grep('bob')" |
|
2751 | 2755 | |
|
2752 | 2756 | - search tracked file contents with xargs and grep:: |
|
2753 | 2757 | |
|
2754 | 2758 | hg files -0 | xargs -0 grep foo |
|
2755 | 2759 | |
|
2756 | 2760 | See :hg:`help patterns` and :hg:`help filesets` for more information |
|
2757 | 2761 | on specifying file patterns. |
|
2758 | 2762 | |
|
2759 | 2763 | Returns 0 if a match is found, 1 otherwise. |
|
2760 | 2764 | |
|
2761 | 2765 | """ |
|
2762 | 2766 | |
|
2763 | 2767 | opts = pycompat.byteskwargs(opts) |
|
2764 | 2768 | rev = opts.get(b'rev') |
|
2765 | 2769 | if rev: |
|
2766 | 2770 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
2767 | 2771 | ctx = scmutil.revsingle(repo, rev, None) |
|
2768 | 2772 | |
|
2769 | 2773 | end = b'\n' |
|
2770 | 2774 | if opts.get(b'print0'): |
|
2771 | 2775 | end = b'\0' |
|
2772 | 2776 | fmt = b'%s' + end |
|
2773 | 2777 | |
|
2774 | 2778 | m = scmutil.match(ctx, pats, opts) |
|
2775 | 2779 | ui.pager(b'files') |
|
2776 | 2780 | uipathfn = scmutil.getuipathfn(ctx.repo(), legacyrelativevalue=True) |
|
2777 | 2781 | with ui.formatter(b'files', opts) as fm: |
|
2778 | 2782 | return cmdutil.files( |
|
2779 | 2783 | ui, ctx, m, uipathfn, fm, fmt, opts.get(b'subrepos') |
|
2780 | 2784 | ) |
|
2781 | 2785 | |
|
2782 | 2786 | |
|
2783 | 2787 | @command( |
|
2784 | 2788 | b'forget', |
|
2785 | 2789 | [(b'i', b'interactive', None, _(b'use interactive mode')),] |
|
2786 | 2790 | + walkopts |
|
2787 | 2791 | + dryrunopts, |
|
2788 | 2792 | _(b'[OPTION]... FILE...'), |
|
2789 | 2793 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
2790 | 2794 | helpbasic=True, |
|
2791 | 2795 | inferrepo=True, |
|
2792 | 2796 | ) |
|
2793 | 2797 | def forget(ui, repo, *pats, **opts): |
|
2794 | 2798 | """forget the specified files on the next commit |
|
2795 | 2799 | |
|
2796 | 2800 | Mark the specified files so they will no longer be tracked |
|
2797 | 2801 | after the next commit. |
|
2798 | 2802 | |
|
2799 | 2803 | This only removes files from the current branch, not from the |
|
2800 | 2804 | entire project history, and it does not delete them from the |
|
2801 | 2805 | working directory. |
|
2802 | 2806 | |
|
2803 | 2807 | To delete the file from the working directory, see :hg:`remove`. |
|
2804 | 2808 | |
|
2805 | 2809 | To undo a forget before the next commit, see :hg:`add`. |
|
2806 | 2810 | |
|
2807 | 2811 | .. container:: verbose |
|
2808 | 2812 | |
|
2809 | 2813 | Examples: |
|
2810 | 2814 | |
|
2811 | 2815 | - forget newly-added binary files:: |
|
2812 | 2816 | |
|
2813 | 2817 | hg forget "set:added() and binary()" |
|
2814 | 2818 | |
|
2815 | 2819 | - forget files that would be excluded by .hgignore:: |
|
2816 | 2820 | |
|
2817 | 2821 | hg forget "set:hgignore()" |
|
2818 | 2822 | |
|
2819 | 2823 | Returns 0 on success. |
|
2820 | 2824 | """ |
|
2821 | 2825 | |
|
2822 | 2826 | opts = pycompat.byteskwargs(opts) |
|
2823 | 2827 | if not pats: |
|
2824 | 2828 | raise error.Abort(_(b'no files specified')) |
|
2825 | 2829 | |
|
2826 | 2830 | m = scmutil.match(repo[None], pats, opts) |
|
2827 | 2831 | dryrun, interactive = opts.get(b'dry_run'), opts.get(b'interactive') |
|
2828 | 2832 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
|
2829 | 2833 | rejected = cmdutil.forget( |
|
2830 | 2834 | ui, |
|
2831 | 2835 | repo, |
|
2832 | 2836 | m, |
|
2833 | 2837 | prefix=b"", |
|
2834 | 2838 | uipathfn=uipathfn, |
|
2835 | 2839 | explicitonly=False, |
|
2836 | 2840 | dryrun=dryrun, |
|
2837 | 2841 | interactive=interactive, |
|
2838 | 2842 | )[0] |
|
2839 | 2843 | return rejected and 1 or 0 |
|
2840 | 2844 | |
|
2841 | 2845 | |
|
2842 | 2846 | @command( |
|
2843 | 2847 | b'graft', |
|
2844 | 2848 | [ |
|
2845 | 2849 | (b'r', b'rev', [], _(b'revisions to graft'), _(b'REV')), |
|
2846 | 2850 | ( |
|
2847 | 2851 | b'', |
|
2848 | 2852 | b'base', |
|
2849 | 2853 | b'', |
|
2850 | 2854 | _(b'base revision when doing the graft merge (ADVANCED)'), |
|
2851 | 2855 | _(b'REV'), |
|
2852 | 2856 | ), |
|
2853 | 2857 | (b'c', b'continue', False, _(b'resume interrupted graft')), |
|
2854 | 2858 | (b'', b'stop', False, _(b'stop interrupted graft')), |
|
2855 | 2859 | (b'', b'abort', False, _(b'abort interrupted graft')), |
|
2856 | 2860 | (b'e', b'edit', False, _(b'invoke editor on commit messages')), |
|
2857 | 2861 | (b'', b'log', None, _(b'append graft info to log message')), |
|
2858 | 2862 | ( |
|
2859 | 2863 | b'', |
|
2860 | 2864 | b'no-commit', |
|
2861 | 2865 | None, |
|
2862 | 2866 | _(b"don't commit, just apply the changes in working directory"), |
|
2863 | 2867 | ), |
|
2864 | 2868 | (b'f', b'force', False, _(b'force graft')), |
|
2865 | 2869 | ( |
|
2866 | 2870 | b'D', |
|
2867 | 2871 | b'currentdate', |
|
2868 | 2872 | False, |
|
2869 | 2873 | _(b'record the current date as commit date'), |
|
2870 | 2874 | ), |
|
2871 | 2875 | ( |
|
2872 | 2876 | b'U', |
|
2873 | 2877 | b'currentuser', |
|
2874 | 2878 | False, |
|
2875 | 2879 | _(b'record the current user as committer'), |
|
2876 | 2880 | ), |
|
2877 | 2881 | ] |
|
2878 | 2882 | + commitopts2 |
|
2879 | 2883 | + mergetoolopts |
|
2880 | 2884 | + dryrunopts, |
|
2881 | 2885 | _(b'[OPTION]... [-r REV]... REV...'), |
|
2882 | 2886 | helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
|
2883 | 2887 | ) |
|
2884 | 2888 | def graft(ui, repo, *revs, **opts): |
|
2885 | 2889 | '''copy changes from other branches onto the current branch |
|
2886 | 2890 | |
|
2887 | 2891 | This command uses Mercurial's merge logic to copy individual |
|
2888 | 2892 | changes from other branches without merging branches in the |
|
2889 | 2893 | history graph. This is sometimes known as 'backporting' or |
|
2890 | 2894 | 'cherry-picking'. By default, graft will copy user, date, and |
|
2891 | 2895 | description from the source changesets. |
|
2892 | 2896 | |
|
2893 | 2897 | Changesets that are ancestors of the current revision, that have |
|
2894 | 2898 | already been grafted, or that are merges will be skipped. |
|
2895 | 2899 | |
|
2896 | 2900 | If --log is specified, log messages will have a comment appended |
|
2897 | 2901 | of the form:: |
|
2898 | 2902 | |
|
2899 | 2903 | (grafted from CHANGESETHASH) |
|
2900 | 2904 | |
|
2901 | 2905 | If --force is specified, revisions will be grafted even if they |
|
2902 | 2906 | are already ancestors of, or have been grafted to, the destination. |
|
2903 | 2907 | This is useful when the revisions have since been backed out. |
|
2904 | 2908 | |
|
2905 | 2909 | If a graft merge results in conflicts, the graft process is |
|
2906 | 2910 | interrupted so that the current merge can be manually resolved. |
|
2907 | 2911 | Once all conflicts are addressed, the graft process can be |
|
2908 | 2912 | continued with the -c/--continue option. |
|
2909 | 2913 | |
|
2910 | 2914 | The -c/--continue option reapplies all the earlier options. |
|
2911 | 2915 | |
|
2912 | 2916 | .. container:: verbose |
|
2913 | 2917 | |
|
2914 | 2918 | The --base option exposes more of how graft internally uses merge with a |
|
2915 | 2919 | custom base revision. --base can be used to specify another ancestor than |
|
2916 | 2920 | the first and only parent. |
|
2917 | 2921 | |
|
2918 | 2922 | The command:: |
|
2919 | 2923 | |
|
2920 | 2924 | hg graft -r 345 --base 234 |
|
2921 | 2925 | |
|
2922 | 2926 | is thus pretty much the same as:: |
|
2923 | 2927 | |
|
2924 | 2928 | hg diff -r 234 -r 345 | hg import |
|
2925 | 2929 | |
|
2926 | 2930 | but using merge to resolve conflicts and track moved files. |
|
2927 | 2931 | |
|
2928 | 2932 | The result of a merge can thus be backported as a single commit by |
|
2929 | 2933 | specifying one of the merge parents as base, and thus effectively |
|
2930 | 2934 | grafting the changes from the other side. |
|
2931 | 2935 | |
|
2932 | 2936 | It is also possible to collapse multiple changesets and clean up history |
|
2933 | 2937 | by specifying another ancestor as base, much like rebase --collapse |
|
2934 | 2938 | --keep. |
|
2935 | 2939 | |
|
2936 | 2940 | The commit message can be tweaked after the fact using commit --amend . |
|
2937 | 2941 | |
|
2938 | 2942 | For using non-ancestors as the base to backout changes, see the backout |
|
2939 | 2943 | command and the hidden --parent option. |
|
2940 | 2944 | |
|
2941 | 2945 | .. container:: verbose |
|
2942 | 2946 | |
|
2943 | 2947 | Examples: |
|
2944 | 2948 | |
|
2945 | 2949 | - copy a single change to the stable branch and edit its description:: |
|
2946 | 2950 | |
|
2947 | 2951 | hg update stable |
|
2948 | 2952 | hg graft --edit 9393 |
|
2949 | 2953 | |
|
2950 | 2954 | - graft a range of changesets with one exception, updating dates:: |
|
2951 | 2955 | |
|
2952 | 2956 | hg graft -D "2085::2093 and not 2091" |
|
2953 | 2957 | |
|
2954 | 2958 | - continue a graft after resolving conflicts:: |
|
2955 | 2959 | |
|
2956 | 2960 | hg graft -c |
|
2957 | 2961 | |
|
2958 | 2962 | - show the source of a grafted changeset:: |
|
2959 | 2963 | |
|
2960 | 2964 | hg log --debug -r . |
|
2961 | 2965 | |
|
2962 | 2966 | - show revisions sorted by date:: |
|
2963 | 2967 | |
|
2964 | 2968 | hg log -r "sort(all(), date)" |
|
2965 | 2969 | |
|
2966 | 2970 | - backport the result of a merge as a single commit:: |
|
2967 | 2971 | |
|
2968 | 2972 | hg graft -r 123 --base 123^ |
|
2969 | 2973 | |
|
2970 | 2974 | - land a feature branch as one changeset:: |
|
2971 | 2975 | |
|
2972 | 2976 | hg up -cr default |
|
2973 | 2977 | hg graft -r featureX --base "ancestor('featureX', 'default')" |
|
2974 | 2978 | |
|
2975 | 2979 | See :hg:`help revisions` for more about specifying revisions. |
|
2976 | 2980 | |
|
2977 | 2981 | Returns 0 on successful completion, 1 if there are unresolved files. |
|
2978 | 2982 | ''' |
|
2979 | 2983 | with repo.wlock(): |
|
2980 | 2984 | return _dograft(ui, repo, *revs, **opts) |
|
2981 | 2985 | |
|
2982 | 2986 | |
|
2983 | 2987 | def _dograft(ui, repo, *revs, **opts): |
|
2984 | 2988 | opts = pycompat.byteskwargs(opts) |
|
2985 | 2989 | if revs and opts.get(b'rev'): |
|
2986 | 2990 | ui.warn( |
|
2987 | 2991 | _( |
|
2988 | 2992 | b'warning: inconsistent use of --rev might give unexpected ' |
|
2989 | 2993 | b'revision ordering!\n' |
|
2990 | 2994 | ) |
|
2991 | 2995 | ) |
|
2992 | 2996 | |
|
2993 | 2997 | revs = list(revs) |
|
2994 | 2998 | revs.extend(opts.get(b'rev')) |
|
2995 | 2999 | # a dict of data to be stored in state file |
|
2996 | 3000 | statedata = {} |
|
2997 | 3001 | # list of new nodes created by ongoing graft |
|
2998 | 3002 | statedata[b'newnodes'] = [] |
|
2999 | 3003 | |
|
3000 | 3004 | cmdutil.resolvecommitoptions(ui, opts) |
|
3001 | 3005 | |
|
3002 | 3006 | editor = cmdutil.getcommiteditor( |
|
3003 | 3007 | editform=b'graft', **pycompat.strkwargs(opts) |
|
3004 | 3008 | ) |
|
3005 | 3009 | |
|
3006 | 3010 | cmdutil.check_at_most_one_arg(opts, b'abort', b'stop', b'continue') |
|
3007 | 3011 | |
|
3008 | 3012 | cont = False |
|
3009 | 3013 | if opts.get(b'no_commit'): |
|
3010 | 3014 | cmdutil.check_incompatible_arguments( |
|
3011 | 3015 | opts, |
|
3012 | 3016 | b'no_commit', |
|
3013 | 3017 | [b'edit', b'currentuser', b'currentdate', b'log'], |
|
3014 | 3018 | ) |
|
3015 | 3019 | |
|
3016 | 3020 | graftstate = statemod.cmdstate(repo, b'graftstate') |
|
3017 | 3021 | |
|
3018 | 3022 | if opts.get(b'stop'): |
|
3019 | 3023 | cmdutil.check_incompatible_arguments( |
|
3020 | 3024 | opts, |
|
3021 | 3025 | b'stop', |
|
3022 | 3026 | [ |
|
3023 | 3027 | b'edit', |
|
3024 | 3028 | b'log', |
|
3025 | 3029 | b'user', |
|
3026 | 3030 | b'date', |
|
3027 | 3031 | b'currentdate', |
|
3028 | 3032 | b'currentuser', |
|
3029 | 3033 | b'rev', |
|
3030 | 3034 | ], |
|
3031 | 3035 | ) |
|
3032 | 3036 | return _stopgraft(ui, repo, graftstate) |
|
3033 | 3037 | elif opts.get(b'abort'): |
|
3034 | 3038 | cmdutil.check_incompatible_arguments( |
|
3035 | 3039 | opts, |
|
3036 | 3040 | b'abort', |
|
3037 | 3041 | [ |
|
3038 | 3042 | b'edit', |
|
3039 | 3043 | b'log', |
|
3040 | 3044 | b'user', |
|
3041 | 3045 | b'date', |
|
3042 | 3046 | b'currentdate', |
|
3043 | 3047 | b'currentuser', |
|
3044 | 3048 | b'rev', |
|
3045 | 3049 | ], |
|
3046 | 3050 | ) |
|
3047 | 3051 | return cmdutil.abortgraft(ui, repo, graftstate) |
|
3048 | 3052 | elif opts.get(b'continue'): |
|
3049 | 3053 | cont = True |
|
3050 | 3054 | if revs: |
|
3051 | 3055 | raise error.Abort(_(b"can't specify --continue and revisions")) |
|
3052 | 3056 | # read in unfinished revisions |
|
3053 | 3057 | if graftstate.exists(): |
|
3054 | 3058 | statedata = cmdutil.readgraftstate(repo, graftstate) |
|
3055 | 3059 | if statedata.get(b'date'): |
|
3056 | 3060 | opts[b'date'] = statedata[b'date'] |
|
3057 | 3061 | if statedata.get(b'user'): |
|
3058 | 3062 | opts[b'user'] = statedata[b'user'] |
|
3059 | 3063 | if statedata.get(b'log'): |
|
3060 | 3064 | opts[b'log'] = True |
|
3061 | 3065 | if statedata.get(b'no_commit'): |
|
3062 | 3066 | opts[b'no_commit'] = statedata.get(b'no_commit') |
|
3063 | 3067 | if statedata.get(b'base'): |
|
3064 | 3068 | opts[b'base'] = statedata.get(b'base') |
|
3065 | 3069 | nodes = statedata[b'nodes'] |
|
3066 | 3070 | revs = [repo[node].rev() for node in nodes] |
|
3067 | 3071 | else: |
|
3068 | 3072 | cmdutil.wrongtooltocontinue(repo, _(b'graft')) |
|
3069 | 3073 | else: |
|
3070 | 3074 | if not revs: |
|
3071 | 3075 | raise error.Abort(_(b'no revisions specified')) |
|
3072 | 3076 | cmdutil.checkunfinished(repo) |
|
3073 | 3077 | cmdutil.bailifchanged(repo) |
|
3074 | 3078 | revs = scmutil.revrange(repo, revs) |
|
3075 | 3079 | |
|
3076 | 3080 | skipped = set() |
|
3077 | 3081 | basectx = None |
|
3078 | 3082 | if opts.get(b'base'): |
|
3079 | 3083 | basectx = scmutil.revsingle(repo, opts[b'base'], None) |
|
3080 | 3084 | if basectx is None: |
|
3081 | 3085 | # check for merges |
|
3082 | 3086 | for rev in repo.revs(b'%ld and merge()', revs): |
|
3083 | 3087 | ui.warn(_(b'skipping ungraftable merge revision %d\n') % rev) |
|
3084 | 3088 | skipped.add(rev) |
|
3085 | 3089 | revs = [r for r in revs if r not in skipped] |
|
3086 | 3090 | if not revs: |
|
3087 | 3091 | return -1 |
|
3088 | 3092 | if basectx is not None and len(revs) != 1: |
|
3089 | 3093 | raise error.Abort(_(b'only one revision allowed with --base ')) |
|
3090 | 3094 | |
|
3091 | 3095 | # Don't check in the --continue case, in effect retaining --force across |
|
3092 | 3096 | # --continues. That's because without --force, any revisions we decided to |
|
3093 | 3097 | # skip would have been filtered out here, so they wouldn't have made their |
|
3094 | 3098 | # way to the graftstate. With --force, any revisions we would have otherwise |
|
3095 | 3099 | # skipped would not have been filtered out, and if they hadn't been applied |
|
3096 | 3100 | # already, they'd have been in the graftstate. |
|
3097 | 3101 | if not (cont or opts.get(b'force')) and basectx is None: |
|
3098 | 3102 | # check for ancestors of dest branch |
|
3099 | 3103 | ancestors = repo.revs(b'%ld & (::.)', revs) |
|
3100 | 3104 | for rev in ancestors: |
|
3101 | 3105 | ui.warn(_(b'skipping ancestor revision %d:%s\n') % (rev, repo[rev])) |
|
3102 | 3106 | |
|
3103 | 3107 | revs = [r for r in revs if r not in ancestors] |
|
3104 | 3108 | |
|
3105 | 3109 | if not revs: |
|
3106 | 3110 | return -1 |
|
3107 | 3111 | |
|
3108 | 3112 | # analyze revs for earlier grafts |
|
3109 | 3113 | ids = {} |
|
3110 | 3114 | for ctx in repo.set(b"%ld", revs): |
|
3111 | 3115 | ids[ctx.hex()] = ctx.rev() |
|
3112 | 3116 | n = ctx.extra().get(b'source') |
|
3113 | 3117 | if n: |
|
3114 | 3118 | ids[n] = ctx.rev() |
|
3115 | 3119 | |
|
3116 | 3120 | # check ancestors for earlier grafts |
|
3117 | 3121 | ui.debug(b'scanning for duplicate grafts\n') |
|
3118 | 3122 | |
|
3119 | 3123 | # The only changesets we can be sure doesn't contain grafts of any |
|
3120 | 3124 | # revs, are the ones that are common ancestors of *all* revs: |
|
3121 | 3125 | for rev in repo.revs(b'only(%d,ancestor(%ld))', repo[b'.'].rev(), revs): |
|
3122 | 3126 | ctx = repo[rev] |
|
3123 | 3127 | n = ctx.extra().get(b'source') |
|
3124 | 3128 | if n in ids: |
|
3125 | 3129 | try: |
|
3126 | 3130 | r = repo[n].rev() |
|
3127 | 3131 | except error.RepoLookupError: |
|
3128 | 3132 | r = None |
|
3129 | 3133 | if r in revs: |
|
3130 | 3134 | ui.warn( |
|
3131 | 3135 | _( |
|
3132 | 3136 | b'skipping revision %d:%s ' |
|
3133 | 3137 | b'(already grafted to %d:%s)\n' |
|
3134 | 3138 | ) |
|
3135 | 3139 | % (r, repo[r], rev, ctx) |
|
3136 | 3140 | ) |
|
3137 | 3141 | revs.remove(r) |
|
3138 | 3142 | elif ids[n] in revs: |
|
3139 | 3143 | if r is None: |
|
3140 | 3144 | ui.warn( |
|
3141 | 3145 | _( |
|
3142 | 3146 | b'skipping already grafted revision %d:%s ' |
|
3143 | 3147 | b'(%d:%s also has unknown origin %s)\n' |
|
3144 | 3148 | ) |
|
3145 | 3149 | % (ids[n], repo[ids[n]], rev, ctx, n[:12]) |
|
3146 | 3150 | ) |
|
3147 | 3151 | else: |
|
3148 | 3152 | ui.warn( |
|
3149 | 3153 | _( |
|
3150 | 3154 | b'skipping already grafted revision %d:%s ' |
|
3151 | 3155 | b'(%d:%s also has origin %d:%s)\n' |
|
3152 | 3156 | ) |
|
3153 | 3157 | % (ids[n], repo[ids[n]], rev, ctx, r, n[:12]) |
|
3154 | 3158 | ) |
|
3155 | 3159 | revs.remove(ids[n]) |
|
3156 | 3160 | elif ctx.hex() in ids: |
|
3157 | 3161 | r = ids[ctx.hex()] |
|
3158 | 3162 | if r in revs: |
|
3159 | 3163 | ui.warn( |
|
3160 | 3164 | _( |
|
3161 | 3165 | b'skipping already grafted revision %d:%s ' |
|
3162 | 3166 | b'(was grafted from %d:%s)\n' |
|
3163 | 3167 | ) |
|
3164 | 3168 | % (r, repo[r], rev, ctx) |
|
3165 | 3169 | ) |
|
3166 | 3170 | revs.remove(r) |
|
3167 | 3171 | if not revs: |
|
3168 | 3172 | return -1 |
|
3169 | 3173 | |
|
3170 | 3174 | if opts.get(b'no_commit'): |
|
3171 | 3175 | statedata[b'no_commit'] = True |
|
3172 | 3176 | if opts.get(b'base'): |
|
3173 | 3177 | statedata[b'base'] = opts[b'base'] |
|
3174 | 3178 | for pos, ctx in enumerate(repo.set(b"%ld", revs)): |
|
3175 | 3179 | desc = b'%d:%s "%s"' % ( |
|
3176 | 3180 | ctx.rev(), |
|
3177 | 3181 | ctx, |
|
3178 | 3182 | ctx.description().split(b'\n', 1)[0], |
|
3179 | 3183 | ) |
|
3180 | 3184 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
|
3181 | 3185 | if names: |
|
3182 | 3186 | desc += b' (%s)' % b' '.join(names) |
|
3183 | 3187 | ui.status(_(b'grafting %s\n') % desc) |
|
3184 | 3188 | if opts.get(b'dry_run'): |
|
3185 | 3189 | continue |
|
3186 | 3190 | |
|
3187 | 3191 | source = ctx.extra().get(b'source') |
|
3188 | 3192 | extra = {} |
|
3189 | 3193 | if source: |
|
3190 | 3194 | extra[b'source'] = source |
|
3191 | 3195 | extra[b'intermediate-source'] = ctx.hex() |
|
3192 | 3196 | else: |
|
3193 | 3197 | extra[b'source'] = ctx.hex() |
|
3194 | 3198 | user = ctx.user() |
|
3195 | 3199 | if opts.get(b'user'): |
|
3196 | 3200 | user = opts[b'user'] |
|
3197 | 3201 | statedata[b'user'] = user |
|
3198 | 3202 | date = ctx.date() |
|
3199 | 3203 | if opts.get(b'date'): |
|
3200 | 3204 | date = opts[b'date'] |
|
3201 | 3205 | statedata[b'date'] = date |
|
3202 | 3206 | message = ctx.description() |
|
3203 | 3207 | if opts.get(b'log'): |
|
3204 | 3208 | message += b'\n(grafted from %s)' % ctx.hex() |
|
3205 | 3209 | statedata[b'log'] = True |
|
3206 | 3210 | |
|
3207 | 3211 | # we don't merge the first commit when continuing |
|
3208 | 3212 | if not cont: |
|
3209 | 3213 | # perform the graft merge with p1(rev) as 'ancestor' |
|
3210 | 3214 | overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')} |
|
3211 | 3215 | base = ctx.p1() if basectx is None else basectx |
|
3212 | 3216 | with ui.configoverride(overrides, b'graft'): |
|
3213 | 3217 | stats = mergemod.graft(repo, ctx, base, [b'local', b'graft']) |
|
3214 | 3218 | # report any conflicts |
|
3215 | 3219 | if stats.unresolvedcount > 0: |
|
3216 | 3220 | # write out state for --continue |
|
3217 | 3221 | nodes = [repo[rev].hex() for rev in revs[pos:]] |
|
3218 | 3222 | statedata[b'nodes'] = nodes |
|
3219 | 3223 | stateversion = 1 |
|
3220 | 3224 | graftstate.save(stateversion, statedata) |
|
3221 | 3225 | ui.error(_(b"abort: unresolved conflicts, can't continue\n")) |
|
3222 | 3226 | ui.error(_(b"(use 'hg resolve' and 'hg graft --continue')\n")) |
|
3223 | 3227 | return 1 |
|
3224 | 3228 | else: |
|
3225 | 3229 | cont = False |
|
3226 | 3230 | |
|
3227 | 3231 | # commit if --no-commit is false |
|
3228 | 3232 | if not opts.get(b'no_commit'): |
|
3229 | 3233 | node = repo.commit( |
|
3230 | 3234 | text=message, user=user, date=date, extra=extra, editor=editor |
|
3231 | 3235 | ) |
|
3232 | 3236 | if node is None: |
|
3233 | 3237 | ui.warn( |
|
3234 | 3238 | _(b'note: graft of %d:%s created no changes to commit\n') |
|
3235 | 3239 | % (ctx.rev(), ctx) |
|
3236 | 3240 | ) |
|
3237 | 3241 | # checking that newnodes exist because old state files won't have it |
|
3238 | 3242 | elif statedata.get(b'newnodes') is not None: |
|
3239 | 3243 | statedata[b'newnodes'].append(node) |
|
3240 | 3244 | |
|
3241 | 3245 | # remove state when we complete successfully |
|
3242 | 3246 | if not opts.get(b'dry_run'): |
|
3243 | 3247 | graftstate.delete() |
|
3244 | 3248 | |
|
3245 | 3249 | return 0 |
|
3246 | 3250 | |
|
3247 | 3251 | |
|
3248 | 3252 | def _stopgraft(ui, repo, graftstate): |
|
3249 | 3253 | """stop the interrupted graft""" |
|
3250 | 3254 | if not graftstate.exists(): |
|
3251 | 3255 | raise error.Abort(_(b"no interrupted graft found")) |
|
3252 | 3256 | pctx = repo[b'.'] |
|
3253 | 3257 | mergemod.clean_update(pctx) |
|
3254 | 3258 | graftstate.delete() |
|
3255 | 3259 | ui.status(_(b"stopped the interrupted graft\n")) |
|
3256 | 3260 | ui.status(_(b"working directory is now at %s\n") % pctx.hex()[:12]) |
|
3257 | 3261 | return 0 |
|
3258 | 3262 | |
|
3259 | 3263 | |
|
3260 | 3264 | statemod.addunfinished( |
|
3261 | 3265 | b'graft', |
|
3262 | 3266 | fname=b'graftstate', |
|
3263 | 3267 | clearable=True, |
|
3264 | 3268 | stopflag=True, |
|
3265 | 3269 | continueflag=True, |
|
3266 | 3270 | abortfunc=cmdutil.hgabortgraft, |
|
3267 | 3271 | cmdhint=_(b"use 'hg graft --continue' or 'hg graft --stop' to stop"), |
|
3268 | 3272 | ) |
|
3269 | 3273 | |
|
3270 | 3274 | |
|
3271 | 3275 | @command( |
|
3272 | 3276 | b'grep', |
|
3273 | 3277 | [ |
|
3274 | 3278 | (b'0', b'print0', None, _(b'end fields with NUL')), |
|
3275 | 3279 | (b'', b'all', None, _(b'an alias to --diff (DEPRECATED)')), |
|
3276 | 3280 | ( |
|
3277 | 3281 | b'', |
|
3278 | 3282 | b'diff', |
|
3279 | 3283 | None, |
|
3280 | 3284 | _( |
|
3281 | 3285 | b'search revision differences for when the pattern was added ' |
|
3282 | 3286 | b'or removed' |
|
3283 | 3287 | ), |
|
3284 | 3288 | ), |
|
3285 | 3289 | (b'a', b'text', None, _(b'treat all files as text')), |
|
3286 | 3290 | ( |
|
3287 | 3291 | b'f', |
|
3288 | 3292 | b'follow', |
|
3289 | 3293 | None, |
|
3290 | 3294 | _( |
|
3291 | 3295 | b'follow changeset history,' |
|
3292 | 3296 | b' or file history across copies and renames' |
|
3293 | 3297 | ), |
|
3294 | 3298 | ), |
|
3295 | 3299 | (b'i', b'ignore-case', None, _(b'ignore case when matching')), |
|
3296 | 3300 | ( |
|
3297 | 3301 | b'l', |
|
3298 | 3302 | b'files-with-matches', |
|
3299 | 3303 | None, |
|
3300 | 3304 | _(b'print only filenames and revisions that match'), |
|
3301 | 3305 | ), |
|
3302 | 3306 | (b'n', b'line-number', None, _(b'print matching line numbers')), |
|
3303 | 3307 | ( |
|
3304 | 3308 | b'r', |
|
3305 | 3309 | b'rev', |
|
3306 | 3310 | [], |
|
3307 | 3311 | _(b'search files changed within revision range'), |
|
3308 | 3312 | _(b'REV'), |
|
3309 | 3313 | ), |
|
3310 | 3314 | ( |
|
3311 | 3315 | b'', |
|
3312 | 3316 | b'all-files', |
|
3313 | 3317 | None, |
|
3314 | 3318 | _( |
|
3315 | 3319 | b'include all files in the changeset while grepping (DEPRECATED)' |
|
3316 | 3320 | ), |
|
3317 | 3321 | ), |
|
3318 | 3322 | (b'u', b'user', None, _(b'list the author (long with -v)')), |
|
3319 | 3323 | (b'd', b'date', None, _(b'list the date (short with -q)')), |
|
3320 | 3324 | ] |
|
3321 | 3325 | + formatteropts |
|
3322 | 3326 | + walkopts, |
|
3323 | 3327 | _(b'[--diff] [OPTION]... PATTERN [FILE]...'), |
|
3324 | 3328 | helpcategory=command.CATEGORY_FILE_CONTENTS, |
|
3325 | 3329 | inferrepo=True, |
|
3326 | 3330 | intents={INTENT_READONLY}, |
|
3327 | 3331 | ) |
|
3328 | 3332 | def grep(ui, repo, pattern, *pats, **opts): |
|
3329 | 3333 | """search for a pattern in specified files |
|
3330 | 3334 | |
|
3331 | 3335 | Search the working directory or revision history for a regular |
|
3332 | 3336 | expression in the specified files for the entire repository. |
|
3333 | 3337 | |
|
3334 | 3338 | By default, grep searches the repository files in the working |
|
3335 | 3339 | directory and prints the files where it finds a match. To specify |
|
3336 | 3340 | historical revisions instead of the working directory, use the |
|
3337 | 3341 | --rev flag. |
|
3338 | 3342 | |
|
3339 | 3343 | To search instead historical revision differences that contains a |
|
3340 | 3344 | change in match status ("-" for a match that becomes a non-match, |
|
3341 | 3345 | or "+" for a non-match that becomes a match), use the --diff flag. |
|
3342 | 3346 | |
|
3343 | 3347 | PATTERN can be any Python (roughly Perl-compatible) regular |
|
3344 | 3348 | expression. |
|
3345 | 3349 | |
|
3346 | 3350 | If no FILEs are specified and the --rev flag isn't supplied, all |
|
3347 | 3351 | files in the working directory are searched. When using the --rev |
|
3348 | 3352 | flag and specifying FILEs, use the --follow argument to also |
|
3349 | 3353 | follow the specified FILEs across renames and copies. |
|
3350 | 3354 | |
|
3351 | 3355 | .. container:: verbose |
|
3352 | 3356 | |
|
3353 | 3357 | Template: |
|
3354 | 3358 | |
|
3355 | 3359 | The following keywords are supported in addition to the common template |
|
3356 | 3360 | keywords and functions. See also :hg:`help templates`. |
|
3357 | 3361 | |
|
3358 | 3362 | :change: String. Character denoting insertion ``+`` or removal ``-``. |
|
3359 | 3363 | Available if ``--diff`` is specified. |
|
3360 | 3364 | :lineno: Integer. Line number of the match. |
|
3361 | 3365 | :path: String. Repository-absolute path of the file. |
|
3362 | 3366 | :texts: List of text chunks. |
|
3363 | 3367 | |
|
3364 | 3368 | And each entry of ``{texts}`` provides the following sub-keywords. |
|
3365 | 3369 | |
|
3366 | 3370 | :matched: Boolean. True if the chunk matches the specified pattern. |
|
3367 | 3371 | :text: String. Chunk content. |
|
3368 | 3372 | |
|
3369 | 3373 | See :hg:`help templates.operators` for the list expansion syntax. |
|
3370 | 3374 | |
|
3371 | 3375 | Returns 0 if a match is found, 1 otherwise. |
|
3372 | 3376 | |
|
3373 | 3377 | """ |
|
3374 | 3378 | cmdutil.check_incompatible_arguments(opts, 'all_files', ['all', 'diff']) |
|
3375 | 3379 | opts = pycompat.byteskwargs(opts) |
|
3376 | 3380 | diff = opts.get(b'all') or opts.get(b'diff') |
|
3377 | 3381 | follow = opts.get(b'follow') |
|
3378 | 3382 | if opts.get(b'all_files') is None and not diff: |
|
3379 | 3383 | opts[b'all_files'] = True |
|
3380 | 3384 | plaingrep = ( |
|
3381 | 3385 | opts.get(b'all_files') |
|
3382 | 3386 | and not opts.get(b'rev') |
|
3383 | 3387 | and not opts.get(b'follow') |
|
3384 | 3388 | ) |
|
3385 | 3389 | all_files = opts.get(b'all_files') |
|
3386 | 3390 | if plaingrep: |
|
3387 | 3391 | opts[b'rev'] = [b'wdir()'] |
|
3388 | 3392 | |
|
3389 | 3393 | reflags = re.M |
|
3390 | 3394 | if opts.get(b'ignore_case'): |
|
3391 | 3395 | reflags |= re.I |
|
3392 | 3396 | try: |
|
3393 | 3397 | regexp = util.re.compile(pattern, reflags) |
|
3394 | 3398 | except re.error as inst: |
|
3395 | 3399 | ui.warn( |
|
3396 | 3400 | _(b"grep: invalid match pattern: %s\n") % pycompat.bytestr(inst) |
|
3397 | 3401 | ) |
|
3398 | 3402 | return 1 |
|
3399 | 3403 | sep, eol = b':', b'\n' |
|
3400 | 3404 | if opts.get(b'print0'): |
|
3401 | 3405 | sep = eol = b'\0' |
|
3402 | 3406 | |
|
3403 | 3407 | searcher = grepmod.grepsearcher( |
|
3404 | 3408 | ui, repo, regexp, all_files=all_files, diff=diff, follow=follow |
|
3405 | 3409 | ) |
|
3406 | 3410 | |
|
3407 | 3411 | getfile = searcher._getfile |
|
3408 | 3412 | |
|
3409 | 3413 | uipathfn = scmutil.getuipathfn(repo) |
|
3410 | 3414 | |
|
3411 | 3415 | def display(fm, fn, ctx, pstates, states): |
|
3412 | 3416 | rev = scmutil.intrev(ctx) |
|
3413 | 3417 | if fm.isplain(): |
|
3414 | 3418 | formatuser = ui.shortuser |
|
3415 | 3419 | else: |
|
3416 | 3420 | formatuser = pycompat.bytestr |
|
3417 | 3421 | if ui.quiet: |
|
3418 | 3422 | datefmt = b'%Y-%m-%d' |
|
3419 | 3423 | else: |
|
3420 | 3424 | datefmt = b'%a %b %d %H:%M:%S %Y %1%2' |
|
3421 | 3425 | found = False |
|
3422 | 3426 | |
|
3423 | 3427 | @util.cachefunc |
|
3424 | 3428 | def binary(): |
|
3425 | 3429 | flog = getfile(fn) |
|
3426 | 3430 | try: |
|
3427 | 3431 | return stringutil.binary(flog.read(ctx.filenode(fn))) |
|
3428 | 3432 | except error.WdirUnsupported: |
|
3429 | 3433 | return ctx[fn].isbinary() |
|
3430 | 3434 | |
|
3431 | 3435 | fieldnamemap = {b'linenumber': b'lineno'} |
|
3432 | 3436 | if diff: |
|
3433 | 3437 | iter = grepmod.difflinestates(pstates, states) |
|
3434 | 3438 | else: |
|
3435 | 3439 | iter = [(b'', l) for l in states] |
|
3436 | 3440 | for change, l in iter: |
|
3437 | 3441 | fm.startitem() |
|
3438 | 3442 | fm.context(ctx=ctx) |
|
3439 | 3443 | fm.data(node=fm.hexfunc(scmutil.binnode(ctx)), path=fn) |
|
3440 | 3444 | fm.plain(uipathfn(fn), label=b'grep.filename') |
|
3441 | 3445 | |
|
3442 | 3446 | cols = [ |
|
3443 | 3447 | (b'rev', b'%d', rev, not plaingrep, b''), |
|
3444 | 3448 | ( |
|
3445 | 3449 | b'linenumber', |
|
3446 | 3450 | b'%d', |
|
3447 | 3451 | l.linenum, |
|
3448 | 3452 | opts.get(b'line_number'), |
|
3449 | 3453 | b'', |
|
3450 | 3454 | ), |
|
3451 | 3455 | ] |
|
3452 | 3456 | if diff: |
|
3453 | 3457 | cols.append( |
|
3454 | 3458 | ( |
|
3455 | 3459 | b'change', |
|
3456 | 3460 | b'%s', |
|
3457 | 3461 | change, |
|
3458 | 3462 | True, |
|
3459 | 3463 | b'grep.inserted ' |
|
3460 | 3464 | if change == b'+' |
|
3461 | 3465 | else b'grep.deleted ', |
|
3462 | 3466 | ) |
|
3463 | 3467 | ) |
|
3464 | 3468 | cols.extend( |
|
3465 | 3469 | [ |
|
3466 | 3470 | ( |
|
3467 | 3471 | b'user', |
|
3468 | 3472 | b'%s', |
|
3469 | 3473 | formatuser(ctx.user()), |
|
3470 | 3474 | opts.get(b'user'), |
|
3471 | 3475 | b'', |
|
3472 | 3476 | ), |
|
3473 | 3477 | ( |
|
3474 | 3478 | b'date', |
|
3475 | 3479 | b'%s', |
|
3476 | 3480 | fm.formatdate(ctx.date(), datefmt), |
|
3477 | 3481 | opts.get(b'date'), |
|
3478 | 3482 | b'', |
|
3479 | 3483 | ), |
|
3480 | 3484 | ] |
|
3481 | 3485 | ) |
|
3482 | 3486 | for name, fmt, data, cond, extra_label in cols: |
|
3483 | 3487 | if cond: |
|
3484 | 3488 | fm.plain(sep, label=b'grep.sep') |
|
3485 | 3489 | field = fieldnamemap.get(name, name) |
|
3486 | 3490 | label = extra_label + (b'grep.%s' % name) |
|
3487 | 3491 | fm.condwrite(cond, field, fmt, data, label=label) |
|
3488 | 3492 | if not opts.get(b'files_with_matches'): |
|
3489 | 3493 | fm.plain(sep, label=b'grep.sep') |
|
3490 | 3494 | if not opts.get(b'text') and binary(): |
|
3491 | 3495 | fm.plain(_(b" Binary file matches")) |
|
3492 | 3496 | else: |
|
3493 | 3497 | displaymatches(fm.nested(b'texts', tmpl=b'{text}'), l) |
|
3494 | 3498 | fm.plain(eol) |
|
3495 | 3499 | found = True |
|
3496 | 3500 | if opts.get(b'files_with_matches'): |
|
3497 | 3501 | break |
|
3498 | 3502 | return found |
|
3499 | 3503 | |
|
3500 | 3504 | def displaymatches(fm, l): |
|
3501 | 3505 | p = 0 |
|
3502 | 3506 | for s, e in l.findpos(regexp): |
|
3503 | 3507 | if p < s: |
|
3504 | 3508 | fm.startitem() |
|
3505 | 3509 | fm.write(b'text', b'%s', l.line[p:s]) |
|
3506 | 3510 | fm.data(matched=False) |
|
3507 | 3511 | fm.startitem() |
|
3508 | 3512 | fm.write(b'text', b'%s', l.line[s:e], label=b'grep.match') |
|
3509 | 3513 | fm.data(matched=True) |
|
3510 | 3514 | p = e |
|
3511 | 3515 | if p < len(l.line): |
|
3512 | 3516 | fm.startitem() |
|
3513 | 3517 | fm.write(b'text', b'%s', l.line[p:]) |
|
3514 | 3518 | fm.data(matched=False) |
|
3515 | 3519 | fm.end() |
|
3516 | 3520 | |
|
3517 | 3521 | found = False |
|
3518 | 3522 | |
|
3519 | 3523 | wopts = logcmdutil.walkopts( |
|
3520 | 3524 | pats=pats, |
|
3521 | 3525 | opts=opts, |
|
3522 | 3526 | revspec=opts[b'rev'], |
|
3523 | 3527 | include_pats=opts[b'include'], |
|
3524 | 3528 | exclude_pats=opts[b'exclude'], |
|
3525 | 3529 | follow=follow, |
|
3526 | 3530 | force_changelog_traversal=all_files, |
|
3527 | 3531 | filter_revisions_by_pats=not all_files, |
|
3528 | 3532 | ) |
|
3529 | 3533 | revs, makefilematcher = logcmdutil.makewalker(repo, wopts) |
|
3530 | 3534 | |
|
3531 | 3535 | ui.pager(b'grep') |
|
3532 | 3536 | fm = ui.formatter(b'grep', opts) |
|
3533 | 3537 | for fn, ctx, pstates, states in searcher.searchfiles(revs, makefilematcher): |
|
3534 | 3538 | r = display(fm, fn, ctx, pstates, states) |
|
3535 | 3539 | found = found or r |
|
3536 | 3540 | if r and not diff and not all_files: |
|
3537 | 3541 | searcher.skipfile(fn, ctx.rev()) |
|
3538 | 3542 | fm.end() |
|
3539 | 3543 | |
|
3540 | 3544 | return not found |
|
3541 | 3545 | |
|
3542 | 3546 | |
|
3543 | 3547 | @command( |
|
3544 | 3548 | b'heads', |
|
3545 | 3549 | [ |
|
3546 | 3550 | ( |
|
3547 | 3551 | b'r', |
|
3548 | 3552 | b'rev', |
|
3549 | 3553 | b'', |
|
3550 | 3554 | _(b'show only heads which are descendants of STARTREV'), |
|
3551 | 3555 | _(b'STARTREV'), |
|
3552 | 3556 | ), |
|
3553 | 3557 | (b't', b'topo', False, _(b'show topological heads only')), |
|
3554 | 3558 | ( |
|
3555 | 3559 | b'a', |
|
3556 | 3560 | b'active', |
|
3557 | 3561 | False, |
|
3558 | 3562 | _(b'show active branchheads only (DEPRECATED)'), |
|
3559 | 3563 | ), |
|
3560 | 3564 | (b'c', b'closed', False, _(b'show normal and closed branch heads')), |
|
3561 | 3565 | ] |
|
3562 | 3566 | + templateopts, |
|
3563 | 3567 | _(b'[-ct] [-r STARTREV] [REV]...'), |
|
3564 | 3568 | helpcategory=command.CATEGORY_CHANGE_NAVIGATION, |
|
3565 | 3569 | intents={INTENT_READONLY}, |
|
3566 | 3570 | ) |
|
3567 | 3571 | def heads(ui, repo, *branchrevs, **opts): |
|
3568 | 3572 | """show branch heads |
|
3569 | 3573 | |
|
3570 | 3574 | With no arguments, show all open branch heads in the repository. |
|
3571 | 3575 | Branch heads are changesets that have no descendants on the |
|
3572 | 3576 | same branch. They are where development generally takes place and |
|
3573 | 3577 | are the usual targets for update and merge operations. |
|
3574 | 3578 | |
|
3575 | 3579 | If one or more REVs are given, only open branch heads on the |
|
3576 | 3580 | branches associated with the specified changesets are shown. This |
|
3577 | 3581 | means that you can use :hg:`heads .` to see the heads on the |
|
3578 | 3582 | currently checked-out branch. |
|
3579 | 3583 | |
|
3580 | 3584 | If -c/--closed is specified, also show branch heads marked closed |
|
3581 | 3585 | (see :hg:`commit --close-branch`). |
|
3582 | 3586 | |
|
3583 | 3587 | If STARTREV is specified, only those heads that are descendants of |
|
3584 | 3588 | STARTREV will be displayed. |
|
3585 | 3589 | |
|
3586 | 3590 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
3587 | 3591 | topological heads (changesets with no children) will be shown. |
|
3588 | 3592 | |
|
3589 | 3593 | Returns 0 if matching heads are found, 1 if not. |
|
3590 | 3594 | """ |
|
3591 | 3595 | |
|
3592 | 3596 | opts = pycompat.byteskwargs(opts) |
|
3593 | 3597 | start = None |
|
3594 | 3598 | rev = opts.get(b'rev') |
|
3595 | 3599 | if rev: |
|
3596 | 3600 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
3597 | 3601 | start = scmutil.revsingle(repo, rev, None).node() |
|
3598 | 3602 | |
|
3599 | 3603 | if opts.get(b'topo'): |
|
3600 | 3604 | heads = [repo[h] for h in repo.heads(start)] |
|
3601 | 3605 | else: |
|
3602 | 3606 | heads = [] |
|
3603 | 3607 | for branch in repo.branchmap(): |
|
3604 | 3608 | heads += repo.branchheads(branch, start, opts.get(b'closed')) |
|
3605 | 3609 | heads = [repo[h] for h in heads] |
|
3606 | 3610 | |
|
3607 | 3611 | if branchrevs: |
|
3608 | 3612 | branches = { |
|
3609 | 3613 | repo[r].branch() for r in scmutil.revrange(repo, branchrevs) |
|
3610 | 3614 | } |
|
3611 | 3615 | heads = [h for h in heads if h.branch() in branches] |
|
3612 | 3616 | |
|
3613 | 3617 | if opts.get(b'active') and branchrevs: |
|
3614 | 3618 | dagheads = repo.heads(start) |
|
3615 | 3619 | heads = [h for h in heads if h.node() in dagheads] |
|
3616 | 3620 | |
|
3617 | 3621 | if branchrevs: |
|
3618 | 3622 | haveheads = {h.branch() for h in heads} |
|
3619 | 3623 | if branches - haveheads: |
|
3620 | 3624 | headless = b', '.join(b for b in branches - haveheads) |
|
3621 | 3625 | msg = _(b'no open branch heads found on branches %s') |
|
3622 | 3626 | if opts.get(b'rev'): |
|
3623 | 3627 | msg += _(b' (started at %s)') % opts[b'rev'] |
|
3624 | 3628 | ui.warn((msg + b'\n') % headless) |
|
3625 | 3629 | |
|
3626 | 3630 | if not heads: |
|
3627 | 3631 | return 1 |
|
3628 | 3632 | |
|
3629 | 3633 | ui.pager(b'heads') |
|
3630 | 3634 | heads = sorted(heads, key=lambda x: -(x.rev())) |
|
3631 | 3635 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
3632 | 3636 | for ctx in heads: |
|
3633 | 3637 | displayer.show(ctx) |
|
3634 | 3638 | displayer.close() |
|
3635 | 3639 | |
|
3636 | 3640 | |
|
3637 | 3641 | @command( |
|
3638 | 3642 | b'help', |
|
3639 | 3643 | [ |
|
3640 | 3644 | (b'e', b'extension', None, _(b'show only help for extensions')), |
|
3641 | 3645 | (b'c', b'command', None, _(b'show only help for commands')), |
|
3642 | 3646 | (b'k', b'keyword', None, _(b'show topics matching keyword')), |
|
3643 | 3647 | ( |
|
3644 | 3648 | b's', |
|
3645 | 3649 | b'system', |
|
3646 | 3650 | [], |
|
3647 | 3651 | _(b'show help for specific platform(s)'), |
|
3648 | 3652 | _(b'PLATFORM'), |
|
3649 | 3653 | ), |
|
3650 | 3654 | ], |
|
3651 | 3655 | _(b'[-eck] [-s PLATFORM] [TOPIC]'), |
|
3652 | 3656 | helpcategory=command.CATEGORY_HELP, |
|
3653 | 3657 | norepo=True, |
|
3654 | 3658 | intents={INTENT_READONLY}, |
|
3655 | 3659 | ) |
|
3656 | 3660 | def help_(ui, name=None, **opts): |
|
3657 | 3661 | """show help for a given topic or a help overview |
|
3658 | 3662 | |
|
3659 | 3663 | With no arguments, print a list of commands with short help messages. |
|
3660 | 3664 | |
|
3661 | 3665 | Given a topic, extension, or command name, print help for that |
|
3662 | 3666 | topic. |
|
3663 | 3667 | |
|
3664 | 3668 | Returns 0 if successful. |
|
3665 | 3669 | """ |
|
3666 | 3670 | |
|
3667 | 3671 | keep = opts.get('system') or [] |
|
3668 | 3672 | if len(keep) == 0: |
|
3669 | 3673 | if pycompat.sysplatform.startswith(b'win'): |
|
3670 | 3674 | keep.append(b'windows') |
|
3671 | 3675 | elif pycompat.sysplatform == b'OpenVMS': |
|
3672 | 3676 | keep.append(b'vms') |
|
3673 | 3677 | elif pycompat.sysplatform == b'plan9': |
|
3674 | 3678 | keep.append(b'plan9') |
|
3675 | 3679 | else: |
|
3676 | 3680 | keep.append(b'unix') |
|
3677 | 3681 | keep.append(pycompat.sysplatform.lower()) |
|
3678 | 3682 | if ui.verbose: |
|
3679 | 3683 | keep.append(b'verbose') |
|
3680 | 3684 | |
|
3681 | 3685 | commands = sys.modules[__name__] |
|
3682 | 3686 | formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts) |
|
3683 | 3687 | ui.pager(b'help') |
|
3684 | 3688 | ui.write(formatted) |
|
3685 | 3689 | |
|
3686 | 3690 | |
|
3687 | 3691 | @command( |
|
3688 | 3692 | b'identify|id', |
|
3689 | 3693 | [ |
|
3690 | 3694 | (b'r', b'rev', b'', _(b'identify the specified revision'), _(b'REV')), |
|
3691 | 3695 | (b'n', b'num', None, _(b'show local revision number')), |
|
3692 | 3696 | (b'i', b'id', None, _(b'show global revision id')), |
|
3693 | 3697 | (b'b', b'branch', None, _(b'show branch')), |
|
3694 | 3698 | (b't', b'tags', None, _(b'show tags')), |
|
3695 | 3699 | (b'B', b'bookmarks', None, _(b'show bookmarks')), |
|
3696 | 3700 | ] |
|
3697 | 3701 | + remoteopts |
|
3698 | 3702 | + formatteropts, |
|
3699 | 3703 | _(b'[-nibtB] [-r REV] [SOURCE]'), |
|
3700 | 3704 | helpcategory=command.CATEGORY_CHANGE_NAVIGATION, |
|
3701 | 3705 | optionalrepo=True, |
|
3702 | 3706 | intents={INTENT_READONLY}, |
|
3703 | 3707 | ) |
|
3704 | 3708 | def identify( |
|
3705 | 3709 | ui, |
|
3706 | 3710 | repo, |
|
3707 | 3711 | source=None, |
|
3708 | 3712 | rev=None, |
|
3709 | 3713 | num=None, |
|
3710 | 3714 | id=None, |
|
3711 | 3715 | branch=None, |
|
3712 | 3716 | tags=None, |
|
3713 | 3717 | bookmarks=None, |
|
3714 | 3718 | **opts |
|
3715 | 3719 | ): |
|
3716 | 3720 | """identify the working directory or specified revision |
|
3717 | 3721 | |
|
3718 | 3722 | Print a summary identifying the repository state at REV using one or |
|
3719 | 3723 | two parent hash identifiers, followed by a "+" if the working |
|
3720 | 3724 | directory has uncommitted changes, the branch name (if not default), |
|
3721 | 3725 | a list of tags, and a list of bookmarks. |
|
3722 | 3726 | |
|
3723 | 3727 | When REV is not given, print a summary of the current state of the |
|
3724 | 3728 | repository including the working directory. Specify -r. to get information |
|
3725 | 3729 | of the working directory parent without scanning uncommitted changes. |
|
3726 | 3730 | |
|
3727 | 3731 | Specifying a path to a repository root or Mercurial bundle will |
|
3728 | 3732 | cause lookup to operate on that repository/bundle. |
|
3729 | 3733 | |
|
3730 | 3734 | .. container:: verbose |
|
3731 | 3735 | |
|
3732 | 3736 | Template: |
|
3733 | 3737 | |
|
3734 | 3738 | The following keywords are supported in addition to the common template |
|
3735 | 3739 | keywords and functions. See also :hg:`help templates`. |
|
3736 | 3740 | |
|
3737 | 3741 | :dirty: String. Character ``+`` denoting if the working directory has |
|
3738 | 3742 | uncommitted changes. |
|
3739 | 3743 | :id: String. One or two nodes, optionally followed by ``+``. |
|
3740 | 3744 | :parents: List of strings. Parent nodes of the changeset. |
|
3741 | 3745 | |
|
3742 | 3746 | Examples: |
|
3743 | 3747 | |
|
3744 | 3748 | - generate a build identifier for the working directory:: |
|
3745 | 3749 | |
|
3746 | 3750 | hg id --id > build-id.dat |
|
3747 | 3751 | |
|
3748 | 3752 | - find the revision corresponding to a tag:: |
|
3749 | 3753 | |
|
3750 | 3754 | hg id -n -r 1.3 |
|
3751 | 3755 | |
|
3752 | 3756 | - check the most recent revision of a remote repository:: |
|
3753 | 3757 | |
|
3754 | 3758 | hg id -r tip https://www.mercurial-scm.org/repo/hg/ |
|
3755 | 3759 | |
|
3756 | 3760 | See :hg:`log` for generating more information about specific revisions, |
|
3757 | 3761 | including full hash identifiers. |
|
3758 | 3762 | |
|
3759 | 3763 | Returns 0 if successful. |
|
3760 | 3764 | """ |
|
3761 | 3765 | |
|
3762 | 3766 | opts = pycompat.byteskwargs(opts) |
|
3763 | 3767 | if not repo and not source: |
|
3764 | 3768 | raise error.Abort( |
|
3765 | 3769 | _(b"there is no Mercurial repository here (.hg not found)") |
|
3766 | 3770 | ) |
|
3767 | 3771 | |
|
3768 | 3772 | default = not (num or id or branch or tags or bookmarks) |
|
3769 | 3773 | output = [] |
|
3770 | 3774 | revs = [] |
|
3771 | 3775 | |
|
3772 | 3776 | if source: |
|
3773 | 3777 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
3774 | 3778 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo |
|
3775 | 3779 | repo = peer.local() |
|
3776 | 3780 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) |
|
3777 | 3781 | |
|
3778 | 3782 | fm = ui.formatter(b'identify', opts) |
|
3779 | 3783 | fm.startitem() |
|
3780 | 3784 | |
|
3781 | 3785 | if not repo: |
|
3782 | 3786 | if num or branch or tags: |
|
3783 | 3787 | raise error.Abort( |
|
3784 | 3788 | _(b"can't query remote revision number, branch, or tags") |
|
3785 | 3789 | ) |
|
3786 | 3790 | if not rev and revs: |
|
3787 | 3791 | rev = revs[0] |
|
3788 | 3792 | if not rev: |
|
3789 | 3793 | rev = b"tip" |
|
3790 | 3794 | |
|
3791 | 3795 | remoterev = peer.lookup(rev) |
|
3792 | 3796 | hexrev = fm.hexfunc(remoterev) |
|
3793 | 3797 | if default or id: |
|
3794 | 3798 | output = [hexrev] |
|
3795 | 3799 | fm.data(id=hexrev) |
|
3796 | 3800 | |
|
3797 | 3801 | @util.cachefunc |
|
3798 | 3802 | def getbms(): |
|
3799 | 3803 | bms = [] |
|
3800 | 3804 | |
|
3801 | 3805 | if b'bookmarks' in peer.listkeys(b'namespaces'): |
|
3802 | 3806 | hexremoterev = hex(remoterev) |
|
3803 | 3807 | bms = [ |
|
3804 | 3808 | bm |
|
3805 | 3809 | for bm, bmr in pycompat.iteritems( |
|
3806 | 3810 | peer.listkeys(b'bookmarks') |
|
3807 | 3811 | ) |
|
3808 | 3812 | if bmr == hexremoterev |
|
3809 | 3813 | ] |
|
3810 | 3814 | |
|
3811 | 3815 | return sorted(bms) |
|
3812 | 3816 | |
|
3813 | 3817 | if fm.isplain(): |
|
3814 | 3818 | if bookmarks: |
|
3815 | 3819 | output.extend(getbms()) |
|
3816 | 3820 | elif default and not ui.quiet: |
|
3817 | 3821 | # multiple bookmarks for a single parent separated by '/' |
|
3818 | 3822 | bm = b'/'.join(getbms()) |
|
3819 | 3823 | if bm: |
|
3820 | 3824 | output.append(bm) |
|
3821 | 3825 | else: |
|
3822 | 3826 | fm.data(node=hex(remoterev)) |
|
3823 | 3827 | if bookmarks or b'bookmarks' in fm.datahint(): |
|
3824 | 3828 | fm.data(bookmarks=fm.formatlist(getbms(), name=b'bookmark')) |
|
3825 | 3829 | else: |
|
3826 | 3830 | if rev: |
|
3827 | 3831 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
3828 | 3832 | ctx = scmutil.revsingle(repo, rev, None) |
|
3829 | 3833 | |
|
3830 | 3834 | if ctx.rev() is None: |
|
3831 | 3835 | ctx = repo[None] |
|
3832 | 3836 | parents = ctx.parents() |
|
3833 | 3837 | taglist = [] |
|
3834 | 3838 | for p in parents: |
|
3835 | 3839 | taglist.extend(p.tags()) |
|
3836 | 3840 | |
|
3837 | 3841 | dirty = b"" |
|
3838 | 3842 | if ctx.dirty(missing=True, merge=False, branch=False): |
|
3839 | 3843 | dirty = b'+' |
|
3840 | 3844 | fm.data(dirty=dirty) |
|
3841 | 3845 | |
|
3842 | 3846 | hexoutput = [fm.hexfunc(p.node()) for p in parents] |
|
3843 | 3847 | if default or id: |
|
3844 | 3848 | output = [b"%s%s" % (b'+'.join(hexoutput), dirty)] |
|
3845 | 3849 | fm.data(id=b"%s%s" % (b'+'.join(hexoutput), dirty)) |
|
3846 | 3850 | |
|
3847 | 3851 | if num: |
|
3848 | 3852 | numoutput = [b"%d" % p.rev() for p in parents] |
|
3849 | 3853 | output.append(b"%s%s" % (b'+'.join(numoutput), dirty)) |
|
3850 | 3854 | |
|
3851 | 3855 | fm.data( |
|
3852 | 3856 | parents=fm.formatlist( |
|
3853 | 3857 | [fm.hexfunc(p.node()) for p in parents], name=b'node' |
|
3854 | 3858 | ) |
|
3855 | 3859 | ) |
|
3856 | 3860 | else: |
|
3857 | 3861 | hexoutput = fm.hexfunc(ctx.node()) |
|
3858 | 3862 | if default or id: |
|
3859 | 3863 | output = [hexoutput] |
|
3860 | 3864 | fm.data(id=hexoutput) |
|
3861 | 3865 | |
|
3862 | 3866 | if num: |
|
3863 | 3867 | output.append(pycompat.bytestr(ctx.rev())) |
|
3864 | 3868 | taglist = ctx.tags() |
|
3865 | 3869 | |
|
3866 | 3870 | if default and not ui.quiet: |
|
3867 | 3871 | b = ctx.branch() |
|
3868 | 3872 | if b != b'default': |
|
3869 | 3873 | output.append(b"(%s)" % b) |
|
3870 | 3874 | |
|
3871 | 3875 | # multiple tags for a single parent separated by '/' |
|
3872 | 3876 | t = b'/'.join(taglist) |
|
3873 | 3877 | if t: |
|
3874 | 3878 | output.append(t) |
|
3875 | 3879 | |
|
3876 | 3880 | # multiple bookmarks for a single parent separated by '/' |
|
3877 | 3881 | bm = b'/'.join(ctx.bookmarks()) |
|
3878 | 3882 | if bm: |
|
3879 | 3883 | output.append(bm) |
|
3880 | 3884 | else: |
|
3881 | 3885 | if branch: |
|
3882 | 3886 | output.append(ctx.branch()) |
|
3883 | 3887 | |
|
3884 | 3888 | if tags: |
|
3885 | 3889 | output.extend(taglist) |
|
3886 | 3890 | |
|
3887 | 3891 | if bookmarks: |
|
3888 | 3892 | output.extend(ctx.bookmarks()) |
|
3889 | 3893 | |
|
3890 | 3894 | fm.data(node=ctx.hex()) |
|
3891 | 3895 | fm.data(branch=ctx.branch()) |
|
3892 | 3896 | fm.data(tags=fm.formatlist(taglist, name=b'tag', sep=b':')) |
|
3893 | 3897 | fm.data(bookmarks=fm.formatlist(ctx.bookmarks(), name=b'bookmark')) |
|
3894 | 3898 | fm.context(ctx=ctx) |
|
3895 | 3899 | |
|
3896 | 3900 | fm.plain(b"%s\n" % b' '.join(output)) |
|
3897 | 3901 | fm.end() |
|
3898 | 3902 | |
|
3899 | 3903 | |
|
3900 | 3904 | @command( |
|
3901 | 3905 | b'import|patch', |
|
3902 | 3906 | [ |
|
3903 | 3907 | ( |
|
3904 | 3908 | b'p', |
|
3905 | 3909 | b'strip', |
|
3906 | 3910 | 1, |
|
3907 | 3911 | _( |
|
3908 | 3912 | b'directory strip option for patch. This has the same ' |
|
3909 | 3913 | b'meaning as the corresponding patch option' |
|
3910 | 3914 | ), |
|
3911 | 3915 | _(b'NUM'), |
|
3912 | 3916 | ), |
|
3913 | 3917 | (b'b', b'base', b'', _(b'base path (DEPRECATED)'), _(b'PATH')), |
|
3914 | 3918 | (b'', b'secret', None, _(b'use the secret phase for committing')), |
|
3915 | 3919 | (b'e', b'edit', False, _(b'invoke editor on commit messages')), |
|
3916 | 3920 | ( |
|
3917 | 3921 | b'f', |
|
3918 | 3922 | b'force', |
|
3919 | 3923 | None, |
|
3920 | 3924 | _(b'skip check for outstanding uncommitted changes (DEPRECATED)'), |
|
3921 | 3925 | ), |
|
3922 | 3926 | ( |
|
3923 | 3927 | b'', |
|
3924 | 3928 | b'no-commit', |
|
3925 | 3929 | None, |
|
3926 | 3930 | _(b"don't commit, just update the working directory"), |
|
3927 | 3931 | ), |
|
3928 | 3932 | ( |
|
3929 | 3933 | b'', |
|
3930 | 3934 | b'bypass', |
|
3931 | 3935 | None, |
|
3932 | 3936 | _(b"apply patch without touching the working directory"), |
|
3933 | 3937 | ), |
|
3934 | 3938 | (b'', b'partial', None, _(b'commit even if some hunks fail')), |
|
3935 | 3939 | (b'', b'exact', None, _(b'abort if patch would apply lossily')), |
|
3936 | 3940 | (b'', b'prefix', b'', _(b'apply patch to subdirectory'), _(b'DIR')), |
|
3937 | 3941 | ( |
|
3938 | 3942 | b'', |
|
3939 | 3943 | b'import-branch', |
|
3940 | 3944 | None, |
|
3941 | 3945 | _(b'use any branch information in patch (implied by --exact)'), |
|
3942 | 3946 | ), |
|
3943 | 3947 | ] |
|
3944 | 3948 | + commitopts |
|
3945 | 3949 | + commitopts2 |
|
3946 | 3950 | + similarityopts, |
|
3947 | 3951 | _(b'[OPTION]... PATCH...'), |
|
3948 | 3952 | helpcategory=command.CATEGORY_IMPORT_EXPORT, |
|
3949 | 3953 | ) |
|
3950 | 3954 | def import_(ui, repo, patch1=None, *patches, **opts): |
|
3951 | 3955 | """import an ordered set of patches |
|
3952 | 3956 | |
|
3953 | 3957 | Import a list of patches and commit them individually (unless |
|
3954 | 3958 | --no-commit is specified). |
|
3955 | 3959 | |
|
3956 | 3960 | To read a patch from standard input (stdin), use "-" as the patch |
|
3957 | 3961 | name. If a URL is specified, the patch will be downloaded from |
|
3958 | 3962 | there. |
|
3959 | 3963 | |
|
3960 | 3964 | Import first applies changes to the working directory (unless |
|
3961 | 3965 | --bypass is specified), import will abort if there are outstanding |
|
3962 | 3966 | changes. |
|
3963 | 3967 | |
|
3964 | 3968 | Use --bypass to apply and commit patches directly to the |
|
3965 | 3969 | repository, without affecting the working directory. Without |
|
3966 | 3970 | --exact, patches will be applied on top of the working directory |
|
3967 | 3971 | parent revision. |
|
3968 | 3972 | |
|
3969 | 3973 | You can import a patch straight from a mail message. Even patches |
|
3970 | 3974 | as attachments work (to use the body part, it must have type |
|
3971 | 3975 | text/plain or text/x-patch). From and Subject headers of email |
|
3972 | 3976 | message are used as default committer and commit message. All |
|
3973 | 3977 | text/plain body parts before first diff are added to the commit |
|
3974 | 3978 | message. |
|
3975 | 3979 | |
|
3976 | 3980 | If the imported patch was generated by :hg:`export`, user and |
|
3977 | 3981 | description from patch override values from message headers and |
|
3978 | 3982 | body. Values given on command line with -m/--message and -u/--user |
|
3979 | 3983 | override these. |
|
3980 | 3984 | |
|
3981 | 3985 | If --exact is specified, import will set the working directory to |
|
3982 | 3986 | the parent of each patch before applying it, and will abort if the |
|
3983 | 3987 | resulting changeset has a different ID than the one recorded in |
|
3984 | 3988 | the patch. This will guard against various ways that portable |
|
3985 | 3989 | patch formats and mail systems might fail to transfer Mercurial |
|
3986 | 3990 | data or metadata. See :hg:`bundle` for lossless transmission. |
|
3987 | 3991 | |
|
3988 | 3992 | Use --partial to ensure a changeset will be created from the patch |
|
3989 | 3993 | even if some hunks fail to apply. Hunks that fail to apply will be |
|
3990 | 3994 | written to a <target-file>.rej file. Conflicts can then be resolved |
|
3991 | 3995 | by hand before :hg:`commit --amend` is run to update the created |
|
3992 | 3996 | changeset. This flag exists to let people import patches that |
|
3993 | 3997 | partially apply without losing the associated metadata (author, |
|
3994 | 3998 | date, description, ...). |
|
3995 | 3999 | |
|
3996 | 4000 | .. note:: |
|
3997 | 4001 | |
|
3998 | 4002 | When no hunks apply cleanly, :hg:`import --partial` will create |
|
3999 | 4003 | an empty changeset, importing only the patch metadata. |
|
4000 | 4004 | |
|
4001 | 4005 | With -s/--similarity, hg will attempt to discover renames and |
|
4002 | 4006 | copies in the patch in the same way as :hg:`addremove`. |
|
4003 | 4007 | |
|
4004 | 4008 | It is possible to use external patch programs to perform the patch |
|
4005 | 4009 | by setting the ``ui.patch`` configuration option. For the default |
|
4006 | 4010 | internal tool, the fuzz can also be configured via ``patch.fuzz``. |
|
4007 | 4011 | See :hg:`help config` for more information about configuration |
|
4008 | 4012 | files and how to use these options. |
|
4009 | 4013 | |
|
4010 | 4014 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4011 | 4015 | |
|
4012 | 4016 | .. container:: verbose |
|
4013 | 4017 | |
|
4014 | 4018 | Examples: |
|
4015 | 4019 | |
|
4016 | 4020 | - import a traditional patch from a website and detect renames:: |
|
4017 | 4021 | |
|
4018 | 4022 | hg import -s 80 http://example.com/bugfix.patch |
|
4019 | 4023 | |
|
4020 | 4024 | - import a changeset from an hgweb server:: |
|
4021 | 4025 | |
|
4022 | 4026 | hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa |
|
4023 | 4027 | |
|
4024 | 4028 | - import all the patches in an Unix-style mbox:: |
|
4025 | 4029 | |
|
4026 | 4030 | hg import incoming-patches.mbox |
|
4027 | 4031 | |
|
4028 | 4032 | - import patches from stdin:: |
|
4029 | 4033 | |
|
4030 | 4034 | hg import - |
|
4031 | 4035 | |
|
4032 | 4036 | - attempt to exactly restore an exported changeset (not always |
|
4033 | 4037 | possible):: |
|
4034 | 4038 | |
|
4035 | 4039 | hg import --exact proposed-fix.patch |
|
4036 | 4040 | |
|
4037 | 4041 | - use an external tool to apply a patch which is too fuzzy for |
|
4038 | 4042 | the default internal tool. |
|
4039 | 4043 | |
|
4040 | 4044 | hg import --config ui.patch="patch --merge" fuzzy.patch |
|
4041 | 4045 | |
|
4042 | 4046 | - change the default fuzzing from 2 to a less strict 7 |
|
4043 | 4047 | |
|
4044 | 4048 | hg import --config ui.fuzz=7 fuzz.patch |
|
4045 | 4049 | |
|
4046 | 4050 | Returns 0 on success, 1 on partial success (see --partial). |
|
4047 | 4051 | """ |
|
4048 | 4052 | |
|
4049 | 4053 | cmdutil.check_incompatible_arguments( |
|
4050 | 4054 | opts, 'no_commit', ['bypass', 'secret'] |
|
4051 | 4055 | ) |
|
4052 | 4056 | cmdutil.check_incompatible_arguments(opts, 'exact', ['edit', 'prefix']) |
|
4053 | 4057 | opts = pycompat.byteskwargs(opts) |
|
4054 | 4058 | if not patch1: |
|
4055 | 4059 | raise error.Abort(_(b'need at least one patch to import')) |
|
4056 | 4060 | |
|
4057 | 4061 | patches = (patch1,) + patches |
|
4058 | 4062 | |
|
4059 | 4063 | date = opts.get(b'date') |
|
4060 | 4064 | if date: |
|
4061 | 4065 | opts[b'date'] = dateutil.parsedate(date) |
|
4062 | 4066 | |
|
4063 | 4067 | exact = opts.get(b'exact') |
|
4064 | 4068 | update = not opts.get(b'bypass') |
|
4065 | 4069 | try: |
|
4066 | 4070 | sim = float(opts.get(b'similarity') or 0) |
|
4067 | 4071 | except ValueError: |
|
4068 | 4072 | raise error.Abort(_(b'similarity must be a number')) |
|
4069 | 4073 | if sim < 0 or sim > 100: |
|
4070 | 4074 | raise error.Abort(_(b'similarity must be between 0 and 100')) |
|
4071 | 4075 | if sim and not update: |
|
4072 | 4076 | raise error.Abort(_(b'cannot use --similarity with --bypass')) |
|
4073 | 4077 | |
|
4074 | 4078 | base = opts[b"base"] |
|
4075 | 4079 | msgs = [] |
|
4076 | 4080 | ret = 0 |
|
4077 | 4081 | |
|
4078 | 4082 | with repo.wlock(): |
|
4079 | 4083 | if update: |
|
4080 | 4084 | cmdutil.checkunfinished(repo) |
|
4081 | 4085 | if exact or not opts.get(b'force'): |
|
4082 | 4086 | cmdutil.bailifchanged(repo) |
|
4083 | 4087 | |
|
4084 | 4088 | if not opts.get(b'no_commit'): |
|
4085 | 4089 | lock = repo.lock |
|
4086 | 4090 | tr = lambda: repo.transaction(b'import') |
|
4087 | 4091 | dsguard = util.nullcontextmanager |
|
4088 | 4092 | else: |
|
4089 | 4093 | lock = util.nullcontextmanager |
|
4090 | 4094 | tr = util.nullcontextmanager |
|
4091 | 4095 | dsguard = lambda: dirstateguard.dirstateguard(repo, b'import') |
|
4092 | 4096 | with lock(), tr(), dsguard(): |
|
4093 | 4097 | parents = repo[None].parents() |
|
4094 | 4098 | for patchurl in patches: |
|
4095 | 4099 | if patchurl == b'-': |
|
4096 | 4100 | ui.status(_(b'applying patch from stdin\n')) |
|
4097 | 4101 | patchfile = ui.fin |
|
4098 | 4102 | patchurl = b'stdin' # for error message |
|
4099 | 4103 | else: |
|
4100 | 4104 | patchurl = os.path.join(base, patchurl) |
|
4101 | 4105 | ui.status(_(b'applying %s\n') % patchurl) |
|
4102 | 4106 | patchfile = hg.openpath(ui, patchurl, sendaccept=False) |
|
4103 | 4107 | |
|
4104 | 4108 | haspatch = False |
|
4105 | 4109 | for hunk in patch.split(patchfile): |
|
4106 | 4110 | with patch.extract(ui, hunk) as patchdata: |
|
4107 | 4111 | msg, node, rej = cmdutil.tryimportone( |
|
4108 | 4112 | ui, repo, patchdata, parents, opts, msgs, hg.clean |
|
4109 | 4113 | ) |
|
4110 | 4114 | if msg: |
|
4111 | 4115 | haspatch = True |
|
4112 | 4116 | ui.note(msg + b'\n') |
|
4113 | 4117 | if update or exact: |
|
4114 | 4118 | parents = repo[None].parents() |
|
4115 | 4119 | else: |
|
4116 | 4120 | parents = [repo[node]] |
|
4117 | 4121 | if rej: |
|
4118 | 4122 | ui.write_err(_(b"patch applied partially\n")) |
|
4119 | 4123 | ui.write_err( |
|
4120 | 4124 | _( |
|
4121 | 4125 | b"(fix the .rej files and run " |
|
4122 | 4126 | b"`hg commit --amend`)\n" |
|
4123 | 4127 | ) |
|
4124 | 4128 | ) |
|
4125 | 4129 | ret = 1 |
|
4126 | 4130 | break |
|
4127 | 4131 | |
|
4128 | 4132 | if not haspatch: |
|
4129 | 4133 | raise error.Abort(_(b'%s: no diffs found') % patchurl) |
|
4130 | 4134 | |
|
4131 | 4135 | if msgs: |
|
4132 | 4136 | repo.savecommitmessage(b'\n* * *\n'.join(msgs)) |
|
4133 | 4137 | return ret |
|
4134 | 4138 | |
|
4135 | 4139 | |
|
4136 | 4140 | @command( |
|
4137 | 4141 | b'incoming|in', |
|
4138 | 4142 | [ |
|
4139 | 4143 | ( |
|
4140 | 4144 | b'f', |
|
4141 | 4145 | b'force', |
|
4142 | 4146 | None, |
|
4143 | 4147 | _(b'run even if remote repository is unrelated'), |
|
4144 | 4148 | ), |
|
4145 | 4149 | (b'n', b'newest-first', None, _(b'show newest record first')), |
|
4146 | 4150 | (b'', b'bundle', b'', _(b'file to store the bundles into'), _(b'FILE')), |
|
4147 | 4151 | ( |
|
4148 | 4152 | b'r', |
|
4149 | 4153 | b'rev', |
|
4150 | 4154 | [], |
|
4151 | 4155 | _(b'a remote changeset intended to be added'), |
|
4152 | 4156 | _(b'REV'), |
|
4153 | 4157 | ), |
|
4154 | 4158 | (b'B', b'bookmarks', False, _(b"compare bookmarks")), |
|
4155 | 4159 | ( |
|
4156 | 4160 | b'b', |
|
4157 | 4161 | b'branch', |
|
4158 | 4162 | [], |
|
4159 | 4163 | _(b'a specific branch you would like to pull'), |
|
4160 | 4164 | _(b'BRANCH'), |
|
4161 | 4165 | ), |
|
4162 | 4166 | ] |
|
4163 | 4167 | + logopts |
|
4164 | 4168 | + remoteopts |
|
4165 | 4169 | + subrepoopts, |
|
4166 | 4170 | _(b'[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]'), |
|
4167 | 4171 | helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT, |
|
4168 | 4172 | ) |
|
4169 | 4173 | def incoming(ui, repo, source=b"default", **opts): |
|
4170 | 4174 | """show new changesets found in source |
|
4171 | 4175 | |
|
4172 | 4176 | Show new changesets found in the specified path/URL or the default |
|
4173 | 4177 | pull location. These are the changesets that would have been pulled |
|
4174 | 4178 | by :hg:`pull` at the time you issued this command. |
|
4175 | 4179 | |
|
4176 | 4180 | See pull for valid source format details. |
|
4177 | 4181 | |
|
4178 | 4182 | .. container:: verbose |
|
4179 | 4183 | |
|
4180 | 4184 | With -B/--bookmarks, the result of bookmark comparison between |
|
4181 | 4185 | local and remote repositories is displayed. With -v/--verbose, |
|
4182 | 4186 | status is also displayed for each bookmark like below:: |
|
4183 | 4187 | |
|
4184 | 4188 | BM1 01234567890a added |
|
4185 | 4189 | BM2 1234567890ab advanced |
|
4186 | 4190 | BM3 234567890abc diverged |
|
4187 | 4191 | BM4 34567890abcd changed |
|
4188 | 4192 | |
|
4189 | 4193 | The action taken locally when pulling depends on the |
|
4190 | 4194 | status of each bookmark: |
|
4191 | 4195 | |
|
4192 | 4196 | :``added``: pull will create it |
|
4193 | 4197 | :``advanced``: pull will update it |
|
4194 | 4198 | :``diverged``: pull will create a divergent bookmark |
|
4195 | 4199 | :``changed``: result depends on remote changesets |
|
4196 | 4200 | |
|
4197 | 4201 | From the point of view of pulling behavior, bookmark |
|
4198 | 4202 | existing only in the remote repository are treated as ``added``, |
|
4199 | 4203 | even if it is in fact locally deleted. |
|
4200 | 4204 | |
|
4201 | 4205 | .. container:: verbose |
|
4202 | 4206 | |
|
4203 | 4207 | For remote repository, using --bundle avoids downloading the |
|
4204 | 4208 | changesets twice if the incoming is followed by a pull. |
|
4205 | 4209 | |
|
4206 | 4210 | Examples: |
|
4207 | 4211 | |
|
4208 | 4212 | - show incoming changes with patches and full description:: |
|
4209 | 4213 | |
|
4210 | 4214 | hg incoming -vp |
|
4211 | 4215 | |
|
4212 | 4216 | - show incoming changes excluding merges, store a bundle:: |
|
4213 | 4217 | |
|
4214 | 4218 | hg in -vpM --bundle incoming.hg |
|
4215 | 4219 | hg pull incoming.hg |
|
4216 | 4220 | |
|
4217 | 4221 | - briefly list changes inside a bundle:: |
|
4218 | 4222 | |
|
4219 | 4223 | hg in changes.hg -T "{desc|firstline}\\n" |
|
4220 | 4224 | |
|
4221 | 4225 | Returns 0 if there are incoming changes, 1 otherwise. |
|
4222 | 4226 | """ |
|
4223 | 4227 | opts = pycompat.byteskwargs(opts) |
|
4224 | 4228 | if opts.get(b'graph'): |
|
4225 | 4229 | logcmdutil.checkunsupportedgraphflags([], opts) |
|
4226 | 4230 | |
|
4227 | 4231 | def display(other, chlist, displayer): |
|
4228 | 4232 | revdag = logcmdutil.graphrevs(other, chlist, opts) |
|
4229 | 4233 | logcmdutil.displaygraph( |
|
4230 | 4234 | ui, repo, revdag, displayer, graphmod.asciiedges |
|
4231 | 4235 | ) |
|
4232 | 4236 | |
|
4233 | 4237 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) |
|
4234 | 4238 | return 0 |
|
4235 | 4239 | |
|
4236 | 4240 | cmdutil.check_incompatible_arguments(opts, b'subrepos', [b'bundle']) |
|
4237 | 4241 | |
|
4238 | 4242 | if opts.get(b'bookmarks'): |
|
4239 | 4243 | source, branches = hg.parseurl( |
|
4240 | 4244 | ui.expandpath(source), opts.get(b'branch') |
|
4241 | 4245 | ) |
|
4242 | 4246 | other = hg.peer(repo, opts, source) |
|
4243 | 4247 | if b'bookmarks' not in other.listkeys(b'namespaces'): |
|
4244 | 4248 | ui.warn(_(b"remote doesn't support bookmarks\n")) |
|
4245 | 4249 | return 0 |
|
4246 | 4250 | ui.pager(b'incoming') |
|
4247 | 4251 | ui.status(_(b'comparing with %s\n') % util.hidepassword(source)) |
|
4248 | 4252 | return bookmarks.incoming(ui, repo, other) |
|
4249 | 4253 | |
|
4250 | 4254 | repo._subtoppath = ui.expandpath(source) |
|
4251 | 4255 | try: |
|
4252 | 4256 | return hg.incoming(ui, repo, source, opts) |
|
4253 | 4257 | finally: |
|
4254 | 4258 | del repo._subtoppath |
|
4255 | 4259 | |
|
4256 | 4260 | |
|
4257 | 4261 | @command( |
|
4258 | 4262 | b'init', |
|
4259 | 4263 | remoteopts, |
|
4260 | 4264 | _(b'[-e CMD] [--remotecmd CMD] [DEST]'), |
|
4261 | 4265 | helpcategory=command.CATEGORY_REPO_CREATION, |
|
4262 | 4266 | helpbasic=True, |
|
4263 | 4267 | norepo=True, |
|
4264 | 4268 | ) |
|
4265 | 4269 | def init(ui, dest=b".", **opts): |
|
4266 | 4270 | """create a new repository in the given directory |
|
4267 | 4271 | |
|
4268 | 4272 | Initialize a new repository in the given directory. If the given |
|
4269 | 4273 | directory does not exist, it will be created. |
|
4270 | 4274 | |
|
4271 | 4275 | If no directory is given, the current directory is used. |
|
4272 | 4276 | |
|
4273 | 4277 | It is possible to specify an ``ssh://`` URL as the destination. |
|
4274 | 4278 | See :hg:`help urls` for more information. |
|
4275 | 4279 | |
|
4276 | 4280 | Returns 0 on success. |
|
4277 | 4281 | """ |
|
4278 | 4282 | opts = pycompat.byteskwargs(opts) |
|
4279 | 4283 | hg.peer(ui, opts, ui.expandpath(dest), create=True) |
|
4280 | 4284 | |
|
4281 | 4285 | |
|
4282 | 4286 | @command( |
|
4283 | 4287 | b'locate', |
|
4284 | 4288 | [ |
|
4285 | 4289 | ( |
|
4286 | 4290 | b'r', |
|
4287 | 4291 | b'rev', |
|
4288 | 4292 | b'', |
|
4289 | 4293 | _(b'search the repository as it is in REV'), |
|
4290 | 4294 | _(b'REV'), |
|
4291 | 4295 | ), |
|
4292 | 4296 | ( |
|
4293 | 4297 | b'0', |
|
4294 | 4298 | b'print0', |
|
4295 | 4299 | None, |
|
4296 | 4300 | _(b'end filenames with NUL, for use with xargs'), |
|
4297 | 4301 | ), |
|
4298 | 4302 | ( |
|
4299 | 4303 | b'f', |
|
4300 | 4304 | b'fullpath', |
|
4301 | 4305 | None, |
|
4302 | 4306 | _(b'print complete paths from the filesystem root'), |
|
4303 | 4307 | ), |
|
4304 | 4308 | ] |
|
4305 | 4309 | + walkopts, |
|
4306 | 4310 | _(b'[OPTION]... [PATTERN]...'), |
|
4307 | 4311 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
4308 | 4312 | ) |
|
4309 | 4313 | def locate(ui, repo, *pats, **opts): |
|
4310 | 4314 | """locate files matching specific patterns (DEPRECATED) |
|
4311 | 4315 | |
|
4312 | 4316 | Print files under Mercurial control in the working directory whose |
|
4313 | 4317 | names match the given patterns. |
|
4314 | 4318 | |
|
4315 | 4319 | By default, this command searches all directories in the working |
|
4316 | 4320 | directory. To search just the current directory and its |
|
4317 | 4321 | subdirectories, use "--include .". |
|
4318 | 4322 | |
|
4319 | 4323 | If no patterns are given to match, this command prints the names |
|
4320 | 4324 | of all files under Mercurial control in the working directory. |
|
4321 | 4325 | |
|
4322 | 4326 | If you want to feed the output of this command into the "xargs" |
|
4323 | 4327 | command, use the -0 option to both this command and "xargs". This |
|
4324 | 4328 | will avoid the problem of "xargs" treating single filenames that |
|
4325 | 4329 | contain whitespace as multiple filenames. |
|
4326 | 4330 | |
|
4327 | 4331 | See :hg:`help files` for a more versatile command. |
|
4328 | 4332 | |
|
4329 | 4333 | Returns 0 if a match is found, 1 otherwise. |
|
4330 | 4334 | """ |
|
4331 | 4335 | opts = pycompat.byteskwargs(opts) |
|
4332 | 4336 | if opts.get(b'print0'): |
|
4333 | 4337 | end = b'\0' |
|
4334 | 4338 | else: |
|
4335 | 4339 | end = b'\n' |
|
4336 | 4340 | ctx = scmutil.revsingle(repo, opts.get(b'rev'), None) |
|
4337 | 4341 | |
|
4338 | 4342 | ret = 1 |
|
4339 | 4343 | m = scmutil.match( |
|
4340 | 4344 | ctx, pats, opts, default=b'relglob', badfn=lambda x, y: False |
|
4341 | 4345 | ) |
|
4342 | 4346 | |
|
4343 | 4347 | ui.pager(b'locate') |
|
4344 | 4348 | if ctx.rev() is None: |
|
4345 | 4349 | # When run on the working copy, "locate" includes removed files, so |
|
4346 | 4350 | # we get the list of files from the dirstate. |
|
4347 | 4351 | filesgen = sorted(repo.dirstate.matches(m)) |
|
4348 | 4352 | else: |
|
4349 | 4353 | filesgen = ctx.matches(m) |
|
4350 | 4354 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=bool(pats)) |
|
4351 | 4355 | for abs in filesgen: |
|
4352 | 4356 | if opts.get(b'fullpath'): |
|
4353 | 4357 | ui.write(repo.wjoin(abs), end) |
|
4354 | 4358 | else: |
|
4355 | 4359 | ui.write(uipathfn(abs), end) |
|
4356 | 4360 | ret = 0 |
|
4357 | 4361 | |
|
4358 | 4362 | return ret |
|
4359 | 4363 | |
|
4360 | 4364 | |
|
4361 | 4365 | @command( |
|
4362 | 4366 | b'log|history', |
|
4363 | 4367 | [ |
|
4364 | 4368 | ( |
|
4365 | 4369 | b'f', |
|
4366 | 4370 | b'follow', |
|
4367 | 4371 | None, |
|
4368 | 4372 | _( |
|
4369 | 4373 | b'follow changeset history, or file history across copies and renames' |
|
4370 | 4374 | ), |
|
4371 | 4375 | ), |
|
4372 | 4376 | ( |
|
4373 | 4377 | b'', |
|
4374 | 4378 | b'follow-first', |
|
4375 | 4379 | None, |
|
4376 | 4380 | _(b'only follow the first parent of merge changesets (DEPRECATED)'), |
|
4377 | 4381 | ), |
|
4378 | 4382 | ( |
|
4379 | 4383 | b'd', |
|
4380 | 4384 | b'date', |
|
4381 | 4385 | b'', |
|
4382 | 4386 | _(b'show revisions matching date spec'), |
|
4383 | 4387 | _(b'DATE'), |
|
4384 | 4388 | ), |
|
4385 | 4389 | (b'C', b'copies', None, _(b'show copied files')), |
|
4386 | 4390 | ( |
|
4387 | 4391 | b'k', |
|
4388 | 4392 | b'keyword', |
|
4389 | 4393 | [], |
|
4390 | 4394 | _(b'do case-insensitive search for a given text'), |
|
4391 | 4395 | _(b'TEXT'), |
|
4392 | 4396 | ), |
|
4393 | 4397 | ( |
|
4394 | 4398 | b'r', |
|
4395 | 4399 | b'rev', |
|
4396 | 4400 | [], |
|
4397 | 4401 | _(b'show the specified revision or revset'), |
|
4398 | 4402 | _(b'REV'), |
|
4399 | 4403 | ), |
|
4400 | 4404 | ( |
|
4401 | 4405 | b'L', |
|
4402 | 4406 | b'line-range', |
|
4403 | 4407 | [], |
|
4404 | 4408 | _(b'follow line range of specified file (EXPERIMENTAL)'), |
|
4405 | 4409 | _(b'FILE,RANGE'), |
|
4406 | 4410 | ), |
|
4407 | 4411 | ( |
|
4408 | 4412 | b'', |
|
4409 | 4413 | b'removed', |
|
4410 | 4414 | None, |
|
4411 | 4415 | _(b'include revisions where files were removed'), |
|
4412 | 4416 | ), |
|
4413 | 4417 | ( |
|
4414 | 4418 | b'm', |
|
4415 | 4419 | b'only-merges', |
|
4416 | 4420 | None, |
|
4417 | 4421 | _(b'show only merges (DEPRECATED) (use -r "merge()" instead)'), |
|
4418 | 4422 | ), |
|
4419 | 4423 | (b'u', b'user', [], _(b'revisions committed by user'), _(b'USER')), |
|
4420 | 4424 | ( |
|
4421 | 4425 | b'', |
|
4422 | 4426 | b'only-branch', |
|
4423 | 4427 | [], |
|
4424 | 4428 | _( |
|
4425 | 4429 | b'show only changesets within the given named branch (DEPRECATED)' |
|
4426 | 4430 | ), |
|
4427 | 4431 | _(b'BRANCH'), |
|
4428 | 4432 | ), |
|
4429 | 4433 | ( |
|
4430 | 4434 | b'b', |
|
4431 | 4435 | b'branch', |
|
4432 | 4436 | [], |
|
4433 | 4437 | _(b'show changesets within the given named branch'), |
|
4434 | 4438 | _(b'BRANCH'), |
|
4435 | 4439 | ), |
|
4436 | 4440 | ( |
|
4437 | 4441 | b'P', |
|
4438 | 4442 | b'prune', |
|
4439 | 4443 | [], |
|
4440 | 4444 | _(b'do not display revision or any of its ancestors'), |
|
4441 | 4445 | _(b'REV'), |
|
4442 | 4446 | ), |
|
4443 | 4447 | ] |
|
4444 | 4448 | + logopts |
|
4445 | 4449 | + walkopts, |
|
4446 | 4450 | _(b'[OPTION]... [FILE]'), |
|
4447 | 4451 | helpcategory=command.CATEGORY_CHANGE_NAVIGATION, |
|
4448 | 4452 | helpbasic=True, |
|
4449 | 4453 | inferrepo=True, |
|
4450 | 4454 | intents={INTENT_READONLY}, |
|
4451 | 4455 | ) |
|
4452 | 4456 | def log(ui, repo, *pats, **opts): |
|
4453 | 4457 | """show revision history of entire repository or files |
|
4454 | 4458 | |
|
4455 | 4459 | Print the revision history of the specified files or the entire |
|
4456 | 4460 | project. |
|
4457 | 4461 | |
|
4458 | 4462 | If no revision range is specified, the default is ``tip:0`` unless |
|
4459 | 4463 | --follow is set, in which case the working directory parent is |
|
4460 | 4464 | used as the starting revision. |
|
4461 | 4465 | |
|
4462 | 4466 | File history is shown without following rename or copy history of |
|
4463 | 4467 | files. Use -f/--follow with a filename to follow history across |
|
4464 | 4468 | renames and copies. --follow without a filename will only show |
|
4465 | 4469 | ancestors of the starting revision. |
|
4466 | 4470 | |
|
4467 | 4471 | By default this command prints revision number and changeset id, |
|
4468 | 4472 | tags, non-trivial parents, user, date and time, and a summary for |
|
4469 | 4473 | each commit. When the -v/--verbose switch is used, the list of |
|
4470 | 4474 | changed files and full commit message are shown. |
|
4471 | 4475 | |
|
4472 | 4476 | With --graph the revisions are shown as an ASCII art DAG with the most |
|
4473 | 4477 | recent changeset at the top. |
|
4474 | 4478 | 'o' is a changeset, '@' is a working directory parent, '%' is a changeset |
|
4475 | 4479 | involved in an unresolved merge conflict, '_' closes a branch, |
|
4476 | 4480 | 'x' is obsolete, '*' is unstable, and '+' represents a fork where the |
|
4477 | 4481 | changeset from the lines below is a parent of the 'o' merge on the same |
|
4478 | 4482 | line. |
|
4479 | 4483 | Paths in the DAG are represented with '|', '/' and so forth. ':' in place |
|
4480 | 4484 | of a '|' indicates one or more revisions in a path are omitted. |
|
4481 | 4485 | |
|
4482 | 4486 | .. container:: verbose |
|
4483 | 4487 | |
|
4484 | 4488 | Use -L/--line-range FILE,M:N options to follow the history of lines |
|
4485 | 4489 | from M to N in FILE. With -p/--patch only diff hunks affecting |
|
4486 | 4490 | specified line range will be shown. This option requires --follow; |
|
4487 | 4491 | it can be specified multiple times. Currently, this option is not |
|
4488 | 4492 | compatible with --graph. This option is experimental. |
|
4489 | 4493 | |
|
4490 | 4494 | .. note:: |
|
4491 | 4495 | |
|
4492 | 4496 | :hg:`log --patch` may generate unexpected diff output for merge |
|
4493 | 4497 | changesets, as it will only compare the merge changeset against |
|
4494 | 4498 | its first parent. Also, only files different from BOTH parents |
|
4495 | 4499 | will appear in files:. |
|
4496 | 4500 | |
|
4497 | 4501 | .. note:: |
|
4498 | 4502 | |
|
4499 | 4503 | For performance reasons, :hg:`log FILE` may omit duplicate changes |
|
4500 | 4504 | made on branches and will not show removals or mode changes. To |
|
4501 | 4505 | see all such changes, use the --removed switch. |
|
4502 | 4506 | |
|
4503 | 4507 | .. container:: verbose |
|
4504 | 4508 | |
|
4505 | 4509 | .. note:: |
|
4506 | 4510 | |
|
4507 | 4511 | The history resulting from -L/--line-range options depends on diff |
|
4508 | 4512 | options; for instance if white-spaces are ignored, respective changes |
|
4509 | 4513 | with only white-spaces in specified line range will not be listed. |
|
4510 | 4514 | |
|
4511 | 4515 | .. container:: verbose |
|
4512 | 4516 | |
|
4513 | 4517 | Some examples: |
|
4514 | 4518 | |
|
4515 | 4519 | - changesets with full descriptions and file lists:: |
|
4516 | 4520 | |
|
4517 | 4521 | hg log -v |
|
4518 | 4522 | |
|
4519 | 4523 | - changesets ancestral to the working directory:: |
|
4520 | 4524 | |
|
4521 | 4525 | hg log -f |
|
4522 | 4526 | |
|
4523 | 4527 | - last 10 commits on the current branch:: |
|
4524 | 4528 | |
|
4525 | 4529 | hg log -l 10 -b . |
|
4526 | 4530 | |
|
4527 | 4531 | - changesets showing all modifications of a file, including removals:: |
|
4528 | 4532 | |
|
4529 | 4533 | hg log --removed file.c |
|
4530 | 4534 | |
|
4531 | 4535 | - all changesets that touch a directory, with diffs, excluding merges:: |
|
4532 | 4536 | |
|
4533 | 4537 | hg log -Mp lib/ |
|
4534 | 4538 | |
|
4535 | 4539 | - all revision numbers that match a keyword:: |
|
4536 | 4540 | |
|
4537 | 4541 | hg log -k bug --template "{rev}\\n" |
|
4538 | 4542 | |
|
4539 | 4543 | - the full hash identifier of the working directory parent:: |
|
4540 | 4544 | |
|
4541 | 4545 | hg log -r . --template "{node}\\n" |
|
4542 | 4546 | |
|
4543 | 4547 | - list available log templates:: |
|
4544 | 4548 | |
|
4545 | 4549 | hg log -T list |
|
4546 | 4550 | |
|
4547 | 4551 | - check if a given changeset is included in a tagged release:: |
|
4548 | 4552 | |
|
4549 | 4553 | hg log -r "a21ccf and ancestor(1.9)" |
|
4550 | 4554 | |
|
4551 | 4555 | - find all changesets by some user in a date range:: |
|
4552 | 4556 | |
|
4553 | 4557 | hg log -k alice -d "may 2008 to jul 2008" |
|
4554 | 4558 | |
|
4555 | 4559 | - summary of all changesets after the last tag:: |
|
4556 | 4560 | |
|
4557 | 4561 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" |
|
4558 | 4562 | |
|
4559 | 4563 | - changesets touching lines 13 to 23 for file.c:: |
|
4560 | 4564 | |
|
4561 | 4565 | hg log -L file.c,13:23 |
|
4562 | 4566 | |
|
4563 | 4567 | - changesets touching lines 13 to 23 for file.c and lines 2 to 6 of |
|
4564 | 4568 | main.c with patch:: |
|
4565 | 4569 | |
|
4566 | 4570 | hg log -L file.c,13:23 -L main.c,2:6 -p |
|
4567 | 4571 | |
|
4568 | 4572 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4569 | 4573 | |
|
4570 | 4574 | See :hg:`help revisions` for more about specifying and ordering |
|
4571 | 4575 | revisions. |
|
4572 | 4576 | |
|
4573 | 4577 | See :hg:`help templates` for more about pre-packaged styles and |
|
4574 | 4578 | specifying custom templates. The default template used by the log |
|
4575 | 4579 | command can be customized via the ``command-templates.log`` configuration |
|
4576 | 4580 | setting. |
|
4577 | 4581 | |
|
4578 | 4582 | Returns 0 on success. |
|
4579 | 4583 | |
|
4580 | 4584 | """ |
|
4581 | 4585 | opts = pycompat.byteskwargs(opts) |
|
4582 | 4586 | linerange = opts.get(b'line_range') |
|
4583 | 4587 | |
|
4584 | 4588 | if linerange and not opts.get(b'follow'): |
|
4585 | 4589 | raise error.Abort(_(b'--line-range requires --follow')) |
|
4586 | 4590 | |
|
4587 | 4591 | if linerange and pats: |
|
4588 | 4592 | # TODO: take pats as patterns with no line-range filter |
|
4589 | 4593 | raise error.Abort( |
|
4590 | 4594 | _(b'FILE arguments are not compatible with --line-range option') |
|
4591 | 4595 | ) |
|
4592 | 4596 | |
|
4593 | 4597 | repo = scmutil.unhidehashlikerevs(repo, opts.get(b'rev'), b'nowarn') |
|
4594 | 4598 | revs, differ = logcmdutil.getrevs( |
|
4595 | 4599 | repo, logcmdutil.parseopts(ui, pats, opts) |
|
4596 | 4600 | ) |
|
4597 | 4601 | if linerange: |
|
4598 | 4602 | # TODO: should follow file history from logcmdutil._initialrevs(), |
|
4599 | 4603 | # then filter the result by logcmdutil._makerevset() and --limit |
|
4600 | 4604 | revs, differ = logcmdutil.getlinerangerevs(repo, revs, opts) |
|
4601 | 4605 | |
|
4602 | 4606 | getcopies = None |
|
4603 | 4607 | if opts.get(b'copies'): |
|
4604 | 4608 | endrev = None |
|
4605 | 4609 | if revs: |
|
4606 | 4610 | endrev = revs.max() + 1 |
|
4607 | 4611 | getcopies = scmutil.getcopiesfn(repo, endrev=endrev) |
|
4608 | 4612 | |
|
4609 | 4613 | ui.pager(b'log') |
|
4610 | 4614 | displayer = logcmdutil.changesetdisplayer( |
|
4611 | 4615 | ui, repo, opts, differ, buffered=True |
|
4612 | 4616 | ) |
|
4613 | 4617 | if opts.get(b'graph'): |
|
4614 | 4618 | displayfn = logcmdutil.displaygraphrevs |
|
4615 | 4619 | else: |
|
4616 | 4620 | displayfn = logcmdutil.displayrevs |
|
4617 | 4621 | displayfn(ui, repo, revs, displayer, getcopies) |
|
4618 | 4622 | |
|
4619 | 4623 | |
|
4620 | 4624 | @command( |
|
4621 | 4625 | b'manifest', |
|
4622 | 4626 | [ |
|
4623 | 4627 | (b'r', b'rev', b'', _(b'revision to display'), _(b'REV')), |
|
4624 | 4628 | (b'', b'all', False, _(b"list files from all revisions")), |
|
4625 | 4629 | ] |
|
4626 | 4630 | + formatteropts, |
|
4627 | 4631 | _(b'[-r REV]'), |
|
4628 | 4632 | helpcategory=command.CATEGORY_MAINTENANCE, |
|
4629 | 4633 | intents={INTENT_READONLY}, |
|
4630 | 4634 | ) |
|
4631 | 4635 | def manifest(ui, repo, node=None, rev=None, **opts): |
|
4632 | 4636 | """output the current or given revision of the project manifest |
|
4633 | 4637 | |
|
4634 | 4638 | Print a list of version controlled files for the given revision. |
|
4635 | 4639 | If no revision is given, the first parent of the working directory |
|
4636 | 4640 | is used, or the null revision if no revision is checked out. |
|
4637 | 4641 | |
|
4638 | 4642 | With -v, print file permissions, symlink and executable bits. |
|
4639 | 4643 | With --debug, print file revision hashes. |
|
4640 | 4644 | |
|
4641 | 4645 | If option --all is specified, the list of all files from all revisions |
|
4642 | 4646 | is printed. This includes deleted and renamed files. |
|
4643 | 4647 | |
|
4644 | 4648 | Returns 0 on success. |
|
4645 | 4649 | """ |
|
4646 | 4650 | opts = pycompat.byteskwargs(opts) |
|
4647 | 4651 | fm = ui.formatter(b'manifest', opts) |
|
4648 | 4652 | |
|
4649 | 4653 | if opts.get(b'all'): |
|
4650 | 4654 | if rev or node: |
|
4651 | 4655 | raise error.Abort(_(b"can't specify a revision with --all")) |
|
4652 | 4656 | |
|
4653 | 4657 | res = set() |
|
4654 | 4658 | for rev in repo: |
|
4655 | 4659 | ctx = repo[rev] |
|
4656 | 4660 | res |= set(ctx.files()) |
|
4657 | 4661 | |
|
4658 | 4662 | ui.pager(b'manifest') |
|
4659 | 4663 | for f in sorted(res): |
|
4660 | 4664 | fm.startitem() |
|
4661 | 4665 | fm.write(b"path", b'%s\n', f) |
|
4662 | 4666 | fm.end() |
|
4663 | 4667 | return |
|
4664 | 4668 | |
|
4665 | 4669 | if rev and node: |
|
4666 | 4670 | raise error.Abort(_(b"please specify just one revision")) |
|
4667 | 4671 | |
|
4668 | 4672 | if not node: |
|
4669 | 4673 | node = rev |
|
4670 | 4674 | |
|
4671 | 4675 | char = {b'l': b'@', b'x': b'*', b'': b'', b't': b'd'} |
|
4672 | 4676 | mode = {b'l': b'644', b'x': b'755', b'': b'644', b't': b'755'} |
|
4673 | 4677 | if node: |
|
4674 | 4678 | repo = scmutil.unhidehashlikerevs(repo, [node], b'nowarn') |
|
4675 | 4679 | ctx = scmutil.revsingle(repo, node) |
|
4676 | 4680 | mf = ctx.manifest() |
|
4677 | 4681 | ui.pager(b'manifest') |
|
4678 | 4682 | for f in ctx: |
|
4679 | 4683 | fm.startitem() |
|
4680 | 4684 | fm.context(ctx=ctx) |
|
4681 | 4685 | fl = ctx[f].flags() |
|
4682 | 4686 | fm.condwrite(ui.debugflag, b'hash', b'%s ', hex(mf[f])) |
|
4683 | 4687 | fm.condwrite(ui.verbose, b'mode type', b'%s %1s ', mode[fl], char[fl]) |
|
4684 | 4688 | fm.write(b'path', b'%s\n', f) |
|
4685 | 4689 | fm.end() |
|
4686 | 4690 | |
|
4687 | 4691 | |
|
4688 | 4692 | @command( |
|
4689 | 4693 | b'merge', |
|
4690 | 4694 | [ |
|
4691 | 4695 | ( |
|
4692 | 4696 | b'f', |
|
4693 | 4697 | b'force', |
|
4694 | 4698 | None, |
|
4695 | 4699 | _(b'force a merge including outstanding changes (DEPRECATED)'), |
|
4696 | 4700 | ), |
|
4697 | 4701 | (b'r', b'rev', b'', _(b'revision to merge'), _(b'REV')), |
|
4698 | 4702 | ( |
|
4699 | 4703 | b'P', |
|
4700 | 4704 | b'preview', |
|
4701 | 4705 | None, |
|
4702 | 4706 | _(b'review revisions to merge (no merge is performed)'), |
|
4703 | 4707 | ), |
|
4704 | 4708 | (b'', b'abort', None, _(b'abort the ongoing merge')), |
|
4705 | 4709 | ] |
|
4706 | 4710 | + mergetoolopts, |
|
4707 | 4711 | _(b'[-P] [[-r] REV]'), |
|
4708 | 4712 | helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
|
4709 | 4713 | helpbasic=True, |
|
4710 | 4714 | ) |
|
4711 | 4715 | def merge(ui, repo, node=None, **opts): |
|
4712 | 4716 | """merge another revision into working directory |
|
4713 | 4717 | |
|
4714 | 4718 | The current working directory is updated with all changes made in |
|
4715 | 4719 | the requested revision since the last common predecessor revision. |
|
4716 | 4720 | |
|
4717 | 4721 | Files that changed between either parent are marked as changed for |
|
4718 | 4722 | the next commit and a commit must be performed before any further |
|
4719 | 4723 | updates to the repository are allowed. The next commit will have |
|
4720 | 4724 | two parents. |
|
4721 | 4725 | |
|
4722 | 4726 | ``--tool`` can be used to specify the merge tool used for file |
|
4723 | 4727 | merges. It overrides the HGMERGE environment variable and your |
|
4724 | 4728 | configuration files. See :hg:`help merge-tools` for options. |
|
4725 | 4729 | |
|
4726 | 4730 | If no revision is specified, the working directory's parent is a |
|
4727 | 4731 | head revision, and the current branch contains exactly one other |
|
4728 | 4732 | head, the other head is merged with by default. Otherwise, an |
|
4729 | 4733 | explicit revision with which to merge must be provided. |
|
4730 | 4734 | |
|
4731 | 4735 | See :hg:`help resolve` for information on handling file conflicts. |
|
4732 | 4736 | |
|
4733 | 4737 | To undo an uncommitted merge, use :hg:`merge --abort` which |
|
4734 | 4738 | will check out a clean copy of the original merge parent, losing |
|
4735 | 4739 | all changes. |
|
4736 | 4740 | |
|
4737 | 4741 | Returns 0 on success, 1 if there are unresolved files. |
|
4738 | 4742 | """ |
|
4739 | 4743 | |
|
4740 | 4744 | opts = pycompat.byteskwargs(opts) |
|
4741 | 4745 | abort = opts.get(b'abort') |
|
4742 | 4746 | if abort and repo.dirstate.p2() == nullid: |
|
4743 | 4747 | cmdutil.wrongtooltocontinue(repo, _(b'merge')) |
|
4744 | 4748 | cmdutil.check_incompatible_arguments(opts, b'abort', [b'rev', b'preview']) |
|
4745 | 4749 | if abort: |
|
4746 | 4750 | state = cmdutil.getunfinishedstate(repo) |
|
4747 | 4751 | if state and state._opname != b'merge': |
|
4748 | 4752 | raise error.Abort( |
|
4749 | 4753 | _(b'cannot abort merge with %s in progress') % (state._opname), |
|
4750 | 4754 | hint=state.hint(), |
|
4751 | 4755 | ) |
|
4752 | 4756 | if node: |
|
4753 | 4757 | raise error.Abort(_(b"cannot specify a node with --abort")) |
|
4754 | 4758 | return hg.abortmerge(repo.ui, repo) |
|
4755 | 4759 | |
|
4756 | 4760 | if opts.get(b'rev') and node: |
|
4757 | 4761 | raise error.Abort(_(b"please specify just one revision")) |
|
4758 | 4762 | if not node: |
|
4759 | 4763 | node = opts.get(b'rev') |
|
4760 | 4764 | |
|
4761 | 4765 | if node: |
|
4762 | 4766 | ctx = scmutil.revsingle(repo, node) |
|
4763 | 4767 | else: |
|
4764 | 4768 | if ui.configbool(b'commands', b'merge.require-rev'): |
|
4765 | 4769 | raise error.Abort( |
|
4766 | 4770 | _( |
|
4767 | 4771 | b'configuration requires specifying revision to merge ' |
|
4768 | 4772 | b'with' |
|
4769 | 4773 | ) |
|
4770 | 4774 | ) |
|
4771 | 4775 | ctx = repo[destutil.destmerge(repo)] |
|
4772 | 4776 | |
|
4773 | 4777 | if ctx.node() is None: |
|
4774 | 4778 | raise error.Abort(_(b'merging with the working copy has no effect')) |
|
4775 | 4779 | |
|
4776 | 4780 | if opts.get(b'preview'): |
|
4777 | 4781 | # find nodes that are ancestors of p2 but not of p1 |
|
4778 | 4782 | p1 = repo[b'.'].node() |
|
4779 | 4783 | p2 = ctx.node() |
|
4780 | 4784 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
4781 | 4785 | |
|
4782 | 4786 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
4783 | 4787 | for node in nodes: |
|
4784 | 4788 | displayer.show(repo[node]) |
|
4785 | 4789 | displayer.close() |
|
4786 | 4790 | return 0 |
|
4787 | 4791 | |
|
4788 | 4792 | # ui.forcemerge is an internal variable, do not document |
|
4789 | 4793 | overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')} |
|
4790 | 4794 | with ui.configoverride(overrides, b'merge'): |
|
4791 | 4795 | force = opts.get(b'force') |
|
4792 | 4796 | labels = [b'working copy', b'merge rev'] |
|
4793 | 4797 | return hg.merge(ctx, force=force, labels=labels) |
|
4794 | 4798 | |
|
4795 | 4799 | |
|
4796 | 4800 | statemod.addunfinished( |
|
4797 | 4801 | b'merge', |
|
4798 | 4802 | fname=None, |
|
4799 | 4803 | clearable=True, |
|
4800 | 4804 | allowcommit=True, |
|
4801 | 4805 | cmdmsg=_(b'outstanding uncommitted merge'), |
|
4802 | 4806 | abortfunc=hg.abortmerge, |
|
4803 | 4807 | statushint=_( |
|
4804 | 4808 | b'To continue: hg commit\nTo abort: hg merge --abort' |
|
4805 | 4809 | ), |
|
4806 | 4810 | cmdhint=_(b"use 'hg commit' or 'hg merge --abort'"), |
|
4807 | 4811 | ) |
|
4808 | 4812 | |
|
4809 | 4813 | |
|
4810 | 4814 | @command( |
|
4811 | 4815 | b'outgoing|out', |
|
4812 | 4816 | [ |
|
4813 | 4817 | ( |
|
4814 | 4818 | b'f', |
|
4815 | 4819 | b'force', |
|
4816 | 4820 | None, |
|
4817 | 4821 | _(b'run even when the destination is unrelated'), |
|
4818 | 4822 | ), |
|
4819 | 4823 | ( |
|
4820 | 4824 | b'r', |
|
4821 | 4825 | b'rev', |
|
4822 | 4826 | [], |
|
4823 | 4827 | _(b'a changeset intended to be included in the destination'), |
|
4824 | 4828 | _(b'REV'), |
|
4825 | 4829 | ), |
|
4826 | 4830 | (b'n', b'newest-first', None, _(b'show newest record first')), |
|
4827 | 4831 | (b'B', b'bookmarks', False, _(b'compare bookmarks')), |
|
4828 | 4832 | ( |
|
4829 | 4833 | b'b', |
|
4830 | 4834 | b'branch', |
|
4831 | 4835 | [], |
|
4832 | 4836 | _(b'a specific branch you would like to push'), |
|
4833 | 4837 | _(b'BRANCH'), |
|
4834 | 4838 | ), |
|
4835 | 4839 | ] |
|
4836 | 4840 | + logopts |
|
4837 | 4841 | + remoteopts |
|
4838 | 4842 | + subrepoopts, |
|
4839 | 4843 | _(b'[-M] [-p] [-n] [-f] [-r REV]... [DEST]'), |
|
4840 | 4844 | helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT, |
|
4841 | 4845 | ) |
|
4842 | 4846 | def outgoing(ui, repo, dest=None, **opts): |
|
4843 | 4847 | """show changesets not found in the destination |
|
4844 | 4848 | |
|
4845 | 4849 | Show changesets not found in the specified destination repository |
|
4846 | 4850 | or the default push location. These are the changesets that would |
|
4847 | 4851 | be pushed if a push was requested. |
|
4848 | 4852 | |
|
4849 | 4853 | See pull for details of valid destination formats. |
|
4850 | 4854 | |
|
4851 | 4855 | .. container:: verbose |
|
4852 | 4856 | |
|
4853 | 4857 | With -B/--bookmarks, the result of bookmark comparison between |
|
4854 | 4858 | local and remote repositories is displayed. With -v/--verbose, |
|
4855 | 4859 | status is also displayed for each bookmark like below:: |
|
4856 | 4860 | |
|
4857 | 4861 | BM1 01234567890a added |
|
4858 | 4862 | BM2 deleted |
|
4859 | 4863 | BM3 234567890abc advanced |
|
4860 | 4864 | BM4 34567890abcd diverged |
|
4861 | 4865 | BM5 4567890abcde changed |
|
4862 | 4866 | |
|
4863 | 4867 | The action taken when pushing depends on the |
|
4864 | 4868 | status of each bookmark: |
|
4865 | 4869 | |
|
4866 | 4870 | :``added``: push with ``-B`` will create it |
|
4867 | 4871 | :``deleted``: push with ``-B`` will delete it |
|
4868 | 4872 | :``advanced``: push will update it |
|
4869 | 4873 | :``diverged``: push with ``-B`` will update it |
|
4870 | 4874 | :``changed``: push with ``-B`` will update it |
|
4871 | 4875 | |
|
4872 | 4876 | From the point of view of pushing behavior, bookmarks |
|
4873 | 4877 | existing only in the remote repository are treated as |
|
4874 | 4878 | ``deleted``, even if it is in fact added remotely. |
|
4875 | 4879 | |
|
4876 | 4880 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
4877 | 4881 | """ |
|
4878 | 4882 | # hg._outgoing() needs to re-resolve the path in order to handle #branch |
|
4879 | 4883 | # style URLs, so don't overwrite dest. |
|
4880 | 4884 | path = ui.paths.getpath(dest, default=(b'default-push', b'default')) |
|
4881 | 4885 | if not path: |
|
4882 | 4886 | raise error.Abort( |
|
4883 | 4887 | _(b'default repository not configured!'), |
|
4884 | 4888 | hint=_(b"see 'hg help config.paths'"), |
|
4885 | 4889 | ) |
|
4886 | 4890 | |
|
4887 | 4891 | opts = pycompat.byteskwargs(opts) |
|
4888 | 4892 | if opts.get(b'graph'): |
|
4889 | 4893 | logcmdutil.checkunsupportedgraphflags([], opts) |
|
4890 | 4894 | o, other = hg._outgoing(ui, repo, dest, opts) |
|
4891 | 4895 | if not o: |
|
4892 | 4896 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
4893 | 4897 | return |
|
4894 | 4898 | |
|
4895 | 4899 | revdag = logcmdutil.graphrevs(repo, o, opts) |
|
4896 | 4900 | ui.pager(b'outgoing') |
|
4897 | 4901 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts, buffered=True) |
|
4898 | 4902 | logcmdutil.displaygraph( |
|
4899 | 4903 | ui, repo, revdag, displayer, graphmod.asciiedges |
|
4900 | 4904 | ) |
|
4901 | 4905 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
4902 | 4906 | return 0 |
|
4903 | 4907 | |
|
4904 | 4908 | if opts.get(b'bookmarks'): |
|
4905 | 4909 | dest = path.pushloc or path.loc |
|
4906 | 4910 | other = hg.peer(repo, opts, dest) |
|
4907 | 4911 | if b'bookmarks' not in other.listkeys(b'namespaces'): |
|
4908 | 4912 | ui.warn(_(b"remote doesn't support bookmarks\n")) |
|
4909 | 4913 | return 0 |
|
4910 | 4914 | ui.status(_(b'comparing with %s\n') % util.hidepassword(dest)) |
|
4911 | 4915 | ui.pager(b'outgoing') |
|
4912 | 4916 | return bookmarks.outgoing(ui, repo, other) |
|
4913 | 4917 | |
|
4914 | 4918 | repo._subtoppath = path.pushloc or path.loc |
|
4915 | 4919 | try: |
|
4916 | 4920 | return hg.outgoing(ui, repo, dest, opts) |
|
4917 | 4921 | finally: |
|
4918 | 4922 | del repo._subtoppath |
|
4919 | 4923 | |
|
4920 | 4924 | |
|
4921 | 4925 | @command( |
|
4922 | 4926 | b'parents', |
|
4923 | 4927 | [ |
|
4924 | 4928 | ( |
|
4925 | 4929 | b'r', |
|
4926 | 4930 | b'rev', |
|
4927 | 4931 | b'', |
|
4928 | 4932 | _(b'show parents of the specified revision'), |
|
4929 | 4933 | _(b'REV'), |
|
4930 | 4934 | ), |
|
4931 | 4935 | ] |
|
4932 | 4936 | + templateopts, |
|
4933 | 4937 | _(b'[-r REV] [FILE]'), |
|
4934 | 4938 | helpcategory=command.CATEGORY_CHANGE_NAVIGATION, |
|
4935 | 4939 | inferrepo=True, |
|
4936 | 4940 | ) |
|
4937 | 4941 | def parents(ui, repo, file_=None, **opts): |
|
4938 | 4942 | """show the parents of the working directory or revision (DEPRECATED) |
|
4939 | 4943 | |
|
4940 | 4944 | Print the working directory's parent revisions. If a revision is |
|
4941 | 4945 | given via -r/--rev, the parent of that revision will be printed. |
|
4942 | 4946 | If a file argument is given, the revision in which the file was |
|
4943 | 4947 | last changed (before the working directory revision or the |
|
4944 | 4948 | argument to --rev if given) is printed. |
|
4945 | 4949 | |
|
4946 | 4950 | This command is equivalent to:: |
|
4947 | 4951 | |
|
4948 | 4952 | hg log -r "p1()+p2()" or |
|
4949 | 4953 | hg log -r "p1(REV)+p2(REV)" or |
|
4950 | 4954 | hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or |
|
4951 | 4955 | hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))" |
|
4952 | 4956 | |
|
4953 | 4957 | See :hg:`summary` and :hg:`help revsets` for related information. |
|
4954 | 4958 | |
|
4955 | 4959 | Returns 0 on success. |
|
4956 | 4960 | """ |
|
4957 | 4961 | |
|
4958 | 4962 | opts = pycompat.byteskwargs(opts) |
|
4959 | 4963 | rev = opts.get(b'rev') |
|
4960 | 4964 | if rev: |
|
4961 | 4965 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
4962 | 4966 | ctx = scmutil.revsingle(repo, rev, None) |
|
4963 | 4967 | |
|
4964 | 4968 | if file_: |
|
4965 | 4969 | m = scmutil.match(ctx, (file_,), opts) |
|
4966 | 4970 | if m.anypats() or len(m.files()) != 1: |
|
4967 | 4971 | raise error.Abort(_(b'can only specify an explicit filename')) |
|
4968 | 4972 | file_ = m.files()[0] |
|
4969 | 4973 | filenodes = [] |
|
4970 | 4974 | for cp in ctx.parents(): |
|
4971 | 4975 | if not cp: |
|
4972 | 4976 | continue |
|
4973 | 4977 | try: |
|
4974 | 4978 | filenodes.append(cp.filenode(file_)) |
|
4975 | 4979 | except error.LookupError: |
|
4976 | 4980 | pass |
|
4977 | 4981 | if not filenodes: |
|
4978 | 4982 | raise error.Abort(_(b"'%s' not found in manifest!") % file_) |
|
4979 | 4983 | p = [] |
|
4980 | 4984 | for fn in filenodes: |
|
4981 | 4985 | fctx = repo.filectx(file_, fileid=fn) |
|
4982 | 4986 | p.append(fctx.node()) |
|
4983 | 4987 | else: |
|
4984 | 4988 | p = [cp.node() for cp in ctx.parents()] |
|
4985 | 4989 | |
|
4986 | 4990 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
4987 | 4991 | for n in p: |
|
4988 | 4992 | if n != nullid: |
|
4989 | 4993 | displayer.show(repo[n]) |
|
4990 | 4994 | displayer.close() |
|
4991 | 4995 | |
|
4992 | 4996 | |
|
4993 | 4997 | @command( |
|
4994 | 4998 | b'paths', |
|
4995 | 4999 | formatteropts, |
|
4996 | 5000 | _(b'[NAME]'), |
|
4997 | 5001 | helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT, |
|
4998 | 5002 | optionalrepo=True, |
|
4999 | 5003 | intents={INTENT_READONLY}, |
|
5000 | 5004 | ) |
|
5001 | 5005 | def paths(ui, repo, search=None, **opts): |
|
5002 | 5006 | """show aliases for remote repositories |
|
5003 | 5007 | |
|
5004 | 5008 | Show definition of symbolic path name NAME. If no name is given, |
|
5005 | 5009 | show definition of all available names. |
|
5006 | 5010 | |
|
5007 | 5011 | Option -q/--quiet suppresses all output when searching for NAME |
|
5008 | 5012 | and shows only the path names when listing all definitions. |
|
5009 | 5013 | |
|
5010 | 5014 | Path names are defined in the [paths] section of your |
|
5011 | 5015 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
5012 | 5016 | repository, ``.hg/hgrc`` is used, too. |
|
5013 | 5017 | |
|
5014 | 5018 | The path names ``default`` and ``default-push`` have a special |
|
5015 | 5019 | meaning. When performing a push or pull operation, they are used |
|
5016 | 5020 | as fallbacks if no location is specified on the command-line. |
|
5017 | 5021 | When ``default-push`` is set, it will be used for push and |
|
5018 | 5022 | ``default`` will be used for pull; otherwise ``default`` is used |
|
5019 | 5023 | as the fallback for both. When cloning a repository, the clone |
|
5020 | 5024 | source is written as ``default`` in ``.hg/hgrc``. |
|
5021 | 5025 | |
|
5022 | 5026 | .. note:: |
|
5023 | 5027 | |
|
5024 | 5028 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
5025 | 5029 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` |
|
5026 | 5030 | and :hg:`bundle`) operations. |
|
5027 | 5031 | |
|
5028 | 5032 | See :hg:`help urls` for more information. |
|
5029 | 5033 | |
|
5030 | 5034 | .. container:: verbose |
|
5031 | 5035 | |
|
5032 | 5036 | Template: |
|
5033 | 5037 | |
|
5034 | 5038 | The following keywords are supported. See also :hg:`help templates`. |
|
5035 | 5039 | |
|
5036 | 5040 | :name: String. Symbolic name of the path alias. |
|
5037 | 5041 | :pushurl: String. URL for push operations. |
|
5038 | 5042 | :url: String. URL or directory path for the other operations. |
|
5039 | 5043 | |
|
5040 | 5044 | Returns 0 on success. |
|
5041 | 5045 | """ |
|
5042 | 5046 | |
|
5043 | 5047 | opts = pycompat.byteskwargs(opts) |
|
5044 | 5048 | ui.pager(b'paths') |
|
5045 | 5049 | if search: |
|
5046 | 5050 | pathitems = [ |
|
5047 | 5051 | (name, path) |
|
5048 | 5052 | for name, path in pycompat.iteritems(ui.paths) |
|
5049 | 5053 | if name == search |
|
5050 | 5054 | ] |
|
5051 | 5055 | else: |
|
5052 | 5056 | pathitems = sorted(pycompat.iteritems(ui.paths)) |
|
5053 | 5057 | |
|
5054 | 5058 | fm = ui.formatter(b'paths', opts) |
|
5055 | 5059 | if fm.isplain(): |
|
5056 | 5060 | hidepassword = util.hidepassword |
|
5057 | 5061 | else: |
|
5058 | 5062 | hidepassword = bytes |
|
5059 | 5063 | if ui.quiet: |
|
5060 | 5064 | namefmt = b'%s\n' |
|
5061 | 5065 | else: |
|
5062 | 5066 | namefmt = b'%s = ' |
|
5063 | 5067 | showsubopts = not search and not ui.quiet |
|
5064 | 5068 | |
|
5065 | 5069 | for name, path in pathitems: |
|
5066 | 5070 | fm.startitem() |
|
5067 | 5071 | fm.condwrite(not search, b'name', namefmt, name) |
|
5068 | 5072 | fm.condwrite(not ui.quiet, b'url', b'%s\n', hidepassword(path.rawloc)) |
|
5069 | 5073 | for subopt, value in sorted(path.suboptions.items()): |
|
5070 | 5074 | assert subopt not in (b'name', b'url') |
|
5071 | 5075 | if showsubopts: |
|
5072 | 5076 | fm.plain(b'%s:%s = ' % (name, subopt)) |
|
5073 | 5077 | fm.condwrite(showsubopts, subopt, b'%s\n', value) |
|
5074 | 5078 | |
|
5075 | 5079 | fm.end() |
|
5076 | 5080 | |
|
5077 | 5081 | if search and not pathitems: |
|
5078 | 5082 | if not ui.quiet: |
|
5079 | 5083 | ui.warn(_(b"not found!\n")) |
|
5080 | 5084 | return 1 |
|
5081 | 5085 | else: |
|
5082 | 5086 | return 0 |
|
5083 | 5087 | |
|
5084 | 5088 | |
|
5085 | 5089 | @command( |
|
5086 | 5090 | b'phase', |
|
5087 | 5091 | [ |
|
5088 | 5092 | (b'p', b'public', False, _(b'set changeset phase to public')), |
|
5089 | 5093 | (b'd', b'draft', False, _(b'set changeset phase to draft')), |
|
5090 | 5094 | (b's', b'secret', False, _(b'set changeset phase to secret')), |
|
5091 | 5095 | (b'f', b'force', False, _(b'allow to move boundary backward')), |
|
5092 | 5096 | (b'r', b'rev', [], _(b'target revision'), _(b'REV')), |
|
5093 | 5097 | ], |
|
5094 | 5098 | _(b'[-p|-d|-s] [-f] [-r] [REV...]'), |
|
5095 | 5099 | helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, |
|
5096 | 5100 | ) |
|
5097 | 5101 | def phase(ui, repo, *revs, **opts): |
|
5098 | 5102 | """set or show the current phase name |
|
5099 | 5103 | |
|
5100 | 5104 | With no argument, show the phase name of the current revision(s). |
|
5101 | 5105 | |
|
5102 | 5106 | With one of -p/--public, -d/--draft or -s/--secret, change the |
|
5103 | 5107 | phase value of the specified revisions. |
|
5104 | 5108 | |
|
5105 | 5109 | Unless -f/--force is specified, :hg:`phase` won't move changesets from a |
|
5106 | 5110 | lower phase to a higher phase. Phases are ordered as follows:: |
|
5107 | 5111 | |
|
5108 | 5112 | public < draft < secret |
|
5109 | 5113 | |
|
5110 | 5114 | Returns 0 on success, 1 if some phases could not be changed. |
|
5111 | 5115 | |
|
5112 | 5116 | (For more information about the phases concept, see :hg:`help phases`.) |
|
5113 | 5117 | """ |
|
5114 | 5118 | opts = pycompat.byteskwargs(opts) |
|
5115 | 5119 | # search for a unique phase argument |
|
5116 | 5120 | targetphase = None |
|
5117 | 5121 | for idx, name in enumerate(phases.cmdphasenames): |
|
5118 | 5122 | if opts[name]: |
|
5119 | 5123 | if targetphase is not None: |
|
5120 | 5124 | raise error.Abort(_(b'only one phase can be specified')) |
|
5121 | 5125 | targetphase = idx |
|
5122 | 5126 | |
|
5123 | 5127 | # look for specified revision |
|
5124 | 5128 | revs = list(revs) |
|
5125 | 5129 | revs.extend(opts[b'rev']) |
|
5126 | 5130 | if not revs: |
|
5127 | 5131 | # display both parents as the second parent phase can influence |
|
5128 | 5132 | # the phase of a merge commit |
|
5129 | 5133 | revs = [c.rev() for c in repo[None].parents()] |
|
5130 | 5134 | |
|
5131 | 5135 | revs = scmutil.revrange(repo, revs) |
|
5132 | 5136 | |
|
5133 | 5137 | ret = 0 |
|
5134 | 5138 | if targetphase is None: |
|
5135 | 5139 | # display |
|
5136 | 5140 | for r in revs: |
|
5137 | 5141 | ctx = repo[r] |
|
5138 | 5142 | ui.write(b'%i: %s\n' % (ctx.rev(), ctx.phasestr())) |
|
5139 | 5143 | else: |
|
5140 | 5144 | with repo.lock(), repo.transaction(b"phase") as tr: |
|
5141 | 5145 | # set phase |
|
5142 | 5146 | if not revs: |
|
5143 | 5147 | raise error.Abort(_(b'empty revision set')) |
|
5144 | 5148 | nodes = [repo[r].node() for r in revs] |
|
5145 | 5149 | # moving revision from public to draft may hide them |
|
5146 | 5150 | # We have to check result on an unfiltered repository |
|
5147 | 5151 | unfi = repo.unfiltered() |
|
5148 | 5152 | getphase = unfi._phasecache.phase |
|
5149 | 5153 | olddata = [getphase(unfi, r) for r in unfi] |
|
5150 | 5154 | phases.advanceboundary(repo, tr, targetphase, nodes) |
|
5151 | 5155 | if opts[b'force']: |
|
5152 | 5156 | phases.retractboundary(repo, tr, targetphase, nodes) |
|
5153 | 5157 | getphase = unfi._phasecache.phase |
|
5154 | 5158 | newdata = [getphase(unfi, r) for r in unfi] |
|
5155 | 5159 | changes = sum(newdata[r] != olddata[r] for r in unfi) |
|
5156 | 5160 | cl = unfi.changelog |
|
5157 | 5161 | rejected = [n for n in nodes if newdata[cl.rev(n)] < targetphase] |
|
5158 | 5162 | if rejected: |
|
5159 | 5163 | ui.warn( |
|
5160 | 5164 | _( |
|
5161 | 5165 | b'cannot move %i changesets to a higher ' |
|
5162 | 5166 | b'phase, use --force\n' |
|
5163 | 5167 | ) |
|
5164 | 5168 | % len(rejected) |
|
5165 | 5169 | ) |
|
5166 | 5170 | ret = 1 |
|
5167 | 5171 | if changes: |
|
5168 | 5172 | msg = _(b'phase changed for %i changesets\n') % changes |
|
5169 | 5173 | if ret: |
|
5170 | 5174 | ui.status(msg) |
|
5171 | 5175 | else: |
|
5172 | 5176 | ui.note(msg) |
|
5173 | 5177 | else: |
|
5174 | 5178 | ui.warn(_(b'no phases changed\n')) |
|
5175 | 5179 | return ret |
|
5176 | 5180 | |
|
5177 | 5181 | |
|
5178 | 5182 | def postincoming(ui, repo, modheads, optupdate, checkout, brev): |
|
5179 | 5183 | """Run after a changegroup has been added via pull/unbundle |
|
5180 | 5184 | |
|
5181 | 5185 | This takes arguments below: |
|
5182 | 5186 | |
|
5183 | 5187 | :modheads: change of heads by pull/unbundle |
|
5184 | 5188 | :optupdate: updating working directory is needed or not |
|
5185 | 5189 | :checkout: update destination revision (or None to default destination) |
|
5186 | 5190 | :brev: a name, which might be a bookmark to be activated after updating |
|
5187 | 5191 | """ |
|
5188 | 5192 | if modheads == 0: |
|
5189 | 5193 | return |
|
5190 | 5194 | if optupdate: |
|
5191 | 5195 | try: |
|
5192 | 5196 | return hg.updatetotally(ui, repo, checkout, brev) |
|
5193 | 5197 | except error.UpdateAbort as inst: |
|
5194 | 5198 | msg = _(b"not updating: %s") % stringutil.forcebytestr(inst) |
|
5195 | 5199 | hint = inst.hint |
|
5196 | 5200 | raise error.UpdateAbort(msg, hint=hint) |
|
5197 | 5201 | if modheads is not None and modheads > 1: |
|
5198 | 5202 | currentbranchheads = len(repo.branchheads()) |
|
5199 | 5203 | if currentbranchheads == modheads: |
|
5200 | 5204 | ui.status( |
|
5201 | 5205 | _(b"(run 'hg heads' to see heads, 'hg merge' to merge)\n") |
|
5202 | 5206 | ) |
|
5203 | 5207 | elif currentbranchheads > 1: |
|
5204 | 5208 | ui.status( |
|
5205 | 5209 | _(b"(run 'hg heads .' to see heads, 'hg merge' to merge)\n") |
|
5206 | 5210 | ) |
|
5207 | 5211 | else: |
|
5208 | 5212 | ui.status(_(b"(run 'hg heads' to see heads)\n")) |
|
5209 | 5213 | elif not ui.configbool(b'commands', b'update.requiredest'): |
|
5210 | 5214 | ui.status(_(b"(run 'hg update' to get a working copy)\n")) |
|
5211 | 5215 | |
|
5212 | 5216 | |
|
5213 | 5217 | @command( |
|
5214 | 5218 | b'pull', |
|
5215 | 5219 | [ |
|
5216 | 5220 | ( |
|
5217 | 5221 | b'u', |
|
5218 | 5222 | b'update', |
|
5219 | 5223 | None, |
|
5220 | 5224 | _(b'update to new branch head if new descendants were pulled'), |
|
5221 | 5225 | ), |
|
5222 | 5226 | ( |
|
5223 | 5227 | b'f', |
|
5224 | 5228 | b'force', |
|
5225 | 5229 | None, |
|
5226 | 5230 | _(b'run even when remote repository is unrelated'), |
|
5227 | 5231 | ), |
|
5228 | 5232 | (b'', b'confirm', None, _(b'confirm pull before applying changes'),), |
|
5229 | 5233 | ( |
|
5230 | 5234 | b'r', |
|
5231 | 5235 | b'rev', |
|
5232 | 5236 | [], |
|
5233 | 5237 | _(b'a remote changeset intended to be added'), |
|
5234 | 5238 | _(b'REV'), |
|
5235 | 5239 | ), |
|
5236 | 5240 | (b'B', b'bookmark', [], _(b"bookmark to pull"), _(b'BOOKMARK')), |
|
5237 | 5241 | ( |
|
5238 | 5242 | b'b', |
|
5239 | 5243 | b'branch', |
|
5240 | 5244 | [], |
|
5241 | 5245 | _(b'a specific branch you would like to pull'), |
|
5242 | 5246 | _(b'BRANCH'), |
|
5243 | 5247 | ), |
|
5244 | 5248 | ] |
|
5245 | 5249 | + remoteopts, |
|
5246 | 5250 | _(b'[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]'), |
|
5247 | 5251 | helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT, |
|
5248 | 5252 | helpbasic=True, |
|
5249 | 5253 | ) |
|
5250 | 5254 | def pull(ui, repo, source=b"default", **opts): |
|
5251 | 5255 | """pull changes from the specified source |
|
5252 | 5256 | |
|
5253 | 5257 | Pull changes from a remote repository to a local one. |
|
5254 | 5258 | |
|
5255 | 5259 | This finds all changes from the repository at the specified path |
|
5256 | 5260 | or URL and adds them to a local repository (the current one unless |
|
5257 | 5261 | -R is specified). By default, this does not update the copy of the |
|
5258 | 5262 | project in the working directory. |
|
5259 | 5263 | |
|
5260 | 5264 | When cloning from servers that support it, Mercurial may fetch |
|
5261 | 5265 | pre-generated data. When this is done, hooks operating on incoming |
|
5262 | 5266 | changesets and changegroups may fire more than once, once for each |
|
5263 | 5267 | pre-generated bundle and as well as for any additional remaining |
|
5264 | 5268 | data. See :hg:`help -e clonebundles` for more. |
|
5265 | 5269 | |
|
5266 | 5270 | Use :hg:`incoming` if you want to see what would have been added |
|
5267 | 5271 | by a pull at the time you issued this command. If you then decide |
|
5268 | 5272 | to add those changes to the repository, you should use :hg:`pull |
|
5269 | 5273 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
5270 | 5274 | |
|
5271 | 5275 | If SOURCE is omitted, the 'default' path will be used. |
|
5272 | 5276 | See :hg:`help urls` for more information. |
|
5273 | 5277 | |
|
5274 | 5278 | Specifying bookmark as ``.`` is equivalent to specifying the active |
|
5275 | 5279 | bookmark's name. |
|
5276 | 5280 | |
|
5277 | 5281 | Returns 0 on success, 1 if an update had unresolved files. |
|
5278 | 5282 | """ |
|
5279 | 5283 | |
|
5280 | 5284 | opts = pycompat.byteskwargs(opts) |
|
5281 | 5285 | if ui.configbool(b'commands', b'update.requiredest') and opts.get( |
|
5282 | 5286 | b'update' |
|
5283 | 5287 | ): |
|
5284 | 5288 | msg = _(b'update destination required by configuration') |
|
5285 | 5289 | hint = _(b'use hg pull followed by hg update DEST') |
|
5286 | 5290 | raise error.Abort(msg, hint=hint) |
|
5287 | 5291 | |
|
5288 | 5292 | source, branches = hg.parseurl(ui.expandpath(source), opts.get(b'branch')) |
|
5289 | 5293 | ui.status(_(b'pulling from %s\n') % util.hidepassword(source)) |
|
5290 | 5294 | other = hg.peer(repo, opts, source) |
|
5291 | 5295 | try: |
|
5292 | 5296 | revs, checkout = hg.addbranchrevs( |
|
5293 | 5297 | repo, other, branches, opts.get(b'rev') |
|
5294 | 5298 | ) |
|
5295 | 5299 | |
|
5296 | 5300 | pullopargs = {} |
|
5297 | 5301 | |
|
5298 | 5302 | nodes = None |
|
5299 | 5303 | if opts.get(b'bookmark') or revs: |
|
5300 | 5304 | # The list of bookmark used here is the same used to actually update |
|
5301 | 5305 | # the bookmark names, to avoid the race from issue 4689 and we do |
|
5302 | 5306 | # all lookup and bookmark queries in one go so they see the same |
|
5303 | 5307 | # version of the server state (issue 4700). |
|
5304 | 5308 | nodes = [] |
|
5305 | 5309 | fnodes = [] |
|
5306 | 5310 | revs = revs or [] |
|
5307 | 5311 | if revs and not other.capable(b'lookup'): |
|
5308 | 5312 | err = _( |
|
5309 | 5313 | b"other repository doesn't support revision lookup, " |
|
5310 | 5314 | b"so a rev cannot be specified." |
|
5311 | 5315 | ) |
|
5312 | 5316 | raise error.Abort(err) |
|
5313 | 5317 | with other.commandexecutor() as e: |
|
5314 | 5318 | fremotebookmarks = e.callcommand( |
|
5315 | 5319 | b'listkeys', {b'namespace': b'bookmarks'} |
|
5316 | 5320 | ) |
|
5317 | 5321 | for r in revs: |
|
5318 | 5322 | fnodes.append(e.callcommand(b'lookup', {b'key': r})) |
|
5319 | 5323 | remotebookmarks = fremotebookmarks.result() |
|
5320 | 5324 | remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks) |
|
5321 | 5325 | pullopargs[b'remotebookmarks'] = remotebookmarks |
|
5322 | 5326 | for b in opts.get(b'bookmark', []): |
|
5323 | 5327 | b = repo._bookmarks.expandname(b) |
|
5324 | 5328 | if b not in remotebookmarks: |
|
5325 | 5329 | raise error.Abort(_(b'remote bookmark %s not found!') % b) |
|
5326 | 5330 | nodes.append(remotebookmarks[b]) |
|
5327 | 5331 | for i, rev in enumerate(revs): |
|
5328 | 5332 | node = fnodes[i].result() |
|
5329 | 5333 | nodes.append(node) |
|
5330 | 5334 | if rev == checkout: |
|
5331 | 5335 | checkout = node |
|
5332 | 5336 | |
|
5333 | 5337 | wlock = util.nullcontextmanager() |
|
5334 | 5338 | if opts.get(b'update'): |
|
5335 | 5339 | wlock = repo.wlock() |
|
5336 | 5340 | with wlock: |
|
5337 | 5341 | pullopargs.update(opts.get(b'opargs', {})) |
|
5338 | 5342 | modheads = exchange.pull( |
|
5339 | 5343 | repo, |
|
5340 | 5344 | other, |
|
5341 | 5345 | heads=nodes, |
|
5342 | 5346 | force=opts.get(b'force'), |
|
5343 | 5347 | bookmarks=opts.get(b'bookmark', ()), |
|
5344 | 5348 | opargs=pullopargs, |
|
5345 | 5349 | confirm=opts.get(b'confirm'), |
|
5346 | 5350 | ).cgresult |
|
5347 | 5351 | |
|
5348 | 5352 | # brev is a name, which might be a bookmark to be activated at |
|
5349 | 5353 | # the end of the update. In other words, it is an explicit |
|
5350 | 5354 | # destination of the update |
|
5351 | 5355 | brev = None |
|
5352 | 5356 | |
|
5353 | 5357 | if checkout: |
|
5354 | 5358 | checkout = repo.unfiltered().changelog.rev(checkout) |
|
5355 | 5359 | |
|
5356 | 5360 | # order below depends on implementation of |
|
5357 | 5361 | # hg.addbranchrevs(). opts['bookmark'] is ignored, |
|
5358 | 5362 | # because 'checkout' is determined without it. |
|
5359 | 5363 | if opts.get(b'rev'): |
|
5360 | 5364 | brev = opts[b'rev'][0] |
|
5361 | 5365 | elif opts.get(b'branch'): |
|
5362 | 5366 | brev = opts[b'branch'][0] |
|
5363 | 5367 | else: |
|
5364 | 5368 | brev = branches[0] |
|
5365 | 5369 | repo._subtoppath = source |
|
5366 | 5370 | try: |
|
5367 | 5371 | ret = postincoming( |
|
5368 | 5372 | ui, repo, modheads, opts.get(b'update'), checkout, brev |
|
5369 | 5373 | ) |
|
5370 | 5374 | except error.FilteredRepoLookupError as exc: |
|
5371 | 5375 | msg = _(b'cannot update to target: %s') % exc.args[0] |
|
5372 | 5376 | exc.args = (msg,) + exc.args[1:] |
|
5373 | 5377 | raise |
|
5374 | 5378 | finally: |
|
5375 | 5379 | del repo._subtoppath |
|
5376 | 5380 | |
|
5377 | 5381 | finally: |
|
5378 | 5382 | other.close() |
|
5379 | 5383 | return ret |
|
5380 | 5384 | |
|
5381 | 5385 | |
|
5382 | 5386 | @command( |
|
5383 | 5387 | b'push', |
|
5384 | 5388 | [ |
|
5385 | 5389 | (b'f', b'force', None, _(b'force push')), |
|
5386 | 5390 | ( |
|
5387 | 5391 | b'r', |
|
5388 | 5392 | b'rev', |
|
5389 | 5393 | [], |
|
5390 | 5394 | _(b'a changeset intended to be included in the destination'), |
|
5391 | 5395 | _(b'REV'), |
|
5392 | 5396 | ), |
|
5393 | 5397 | (b'B', b'bookmark', [], _(b"bookmark to push"), _(b'BOOKMARK')), |
|
5394 | 5398 | (b'', b'all-bookmarks', None, _(b"push all bookmarks (EXPERIMENTAL)")), |
|
5395 | 5399 | ( |
|
5396 | 5400 | b'b', |
|
5397 | 5401 | b'branch', |
|
5398 | 5402 | [], |
|
5399 | 5403 | _(b'a specific branch you would like to push'), |
|
5400 | 5404 | _(b'BRANCH'), |
|
5401 | 5405 | ), |
|
5402 | 5406 | (b'', b'new-branch', False, _(b'allow pushing a new branch')), |
|
5403 | 5407 | ( |
|
5404 | 5408 | b'', |
|
5405 | 5409 | b'pushvars', |
|
5406 | 5410 | [], |
|
5407 | 5411 | _(b'variables that can be sent to server (ADVANCED)'), |
|
5408 | 5412 | ), |
|
5409 | 5413 | ( |
|
5410 | 5414 | b'', |
|
5411 | 5415 | b'publish', |
|
5412 | 5416 | False, |
|
5413 | 5417 | _(b'push the changeset as public (EXPERIMENTAL)'), |
|
5414 | 5418 | ), |
|
5415 | 5419 | ] |
|
5416 | 5420 | + remoteopts, |
|
5417 | 5421 | _(b'[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]'), |
|
5418 | 5422 | helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT, |
|
5419 | 5423 | helpbasic=True, |
|
5420 | 5424 | ) |
|
5421 | 5425 | def push(ui, repo, dest=None, **opts): |
|
5422 | 5426 | """push changes to the specified destination |
|
5423 | 5427 | |
|
5424 | 5428 | Push changesets from the local repository to the specified |
|
5425 | 5429 | destination. |
|
5426 | 5430 | |
|
5427 | 5431 | This operation is symmetrical to pull: it is identical to a pull |
|
5428 | 5432 | in the destination repository from the current one. |
|
5429 | 5433 | |
|
5430 | 5434 | By default, push will not allow creation of new heads at the |
|
5431 | 5435 | destination, since multiple heads would make it unclear which head |
|
5432 | 5436 | to use. In this situation, it is recommended to pull and merge |
|
5433 | 5437 | before pushing. |
|
5434 | 5438 | |
|
5435 | 5439 | Use --new-branch if you want to allow push to create a new named |
|
5436 | 5440 | branch that is not present at the destination. This allows you to |
|
5437 | 5441 | only create a new branch without forcing other changes. |
|
5438 | 5442 | |
|
5439 | 5443 | .. note:: |
|
5440 | 5444 | |
|
5441 | 5445 | Extra care should be taken with the -f/--force option, |
|
5442 | 5446 | which will push all new heads on all branches, an action which will |
|
5443 | 5447 | almost always cause confusion for collaborators. |
|
5444 | 5448 | |
|
5445 | 5449 | If -r/--rev is used, the specified revision and all its ancestors |
|
5446 | 5450 | will be pushed to the remote repository. |
|
5447 | 5451 | |
|
5448 | 5452 | If -B/--bookmark is used, the specified bookmarked revision, its |
|
5449 | 5453 | ancestors, and the bookmark will be pushed to the remote |
|
5450 | 5454 | repository. Specifying ``.`` is equivalent to specifying the active |
|
5451 | 5455 | bookmark's name. Use the --all-bookmarks option for pushing all |
|
5452 | 5456 | current bookmarks. |
|
5453 | 5457 | |
|
5454 | 5458 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
5455 | 5459 | URLs. If DESTINATION is omitted, a default path will be used. |
|
5456 | 5460 | |
|
5457 | 5461 | .. container:: verbose |
|
5458 | 5462 | |
|
5459 | 5463 | The --pushvars option sends strings to the server that become |
|
5460 | 5464 | environment variables prepended with ``HG_USERVAR_``. For example, |
|
5461 | 5465 | ``--pushvars ENABLE_FEATURE=true``, provides the server side hooks with |
|
5462 | 5466 | ``HG_USERVAR_ENABLE_FEATURE=true`` as part of their environment. |
|
5463 | 5467 | |
|
5464 | 5468 | pushvars can provide for user-overridable hooks as well as set debug |
|
5465 | 5469 | levels. One example is having a hook that blocks commits containing |
|
5466 | 5470 | conflict markers, but enables the user to override the hook if the file |
|
5467 | 5471 | is using conflict markers for testing purposes or the file format has |
|
5468 | 5472 | strings that look like conflict markers. |
|
5469 | 5473 | |
|
5470 | 5474 | By default, servers will ignore `--pushvars`. To enable it add the |
|
5471 | 5475 | following to your configuration file:: |
|
5472 | 5476 | |
|
5473 | 5477 | [push] |
|
5474 | 5478 | pushvars.server = true |
|
5475 | 5479 | |
|
5476 | 5480 | Returns 0 if push was successful, 1 if nothing to push. |
|
5477 | 5481 | """ |
|
5478 | 5482 | |
|
5479 | 5483 | opts = pycompat.byteskwargs(opts) |
|
5480 | 5484 | |
|
5481 | 5485 | if opts.get(b'all_bookmarks'): |
|
5482 | 5486 | cmdutil.check_incompatible_arguments( |
|
5483 | 5487 | opts, b'all_bookmarks', [b'bookmark', b'rev'], |
|
5484 | 5488 | ) |
|
5485 | 5489 | opts[b'bookmark'] = list(repo._bookmarks) |
|
5486 | 5490 | |
|
5487 | 5491 | if opts.get(b'bookmark'): |
|
5488 | 5492 | ui.setconfig(b'bookmarks', b'pushing', opts[b'bookmark'], b'push') |
|
5489 | 5493 | for b in opts[b'bookmark']: |
|
5490 | 5494 | # translate -B options to -r so changesets get pushed |
|
5491 | 5495 | b = repo._bookmarks.expandname(b) |
|
5492 | 5496 | if b in repo._bookmarks: |
|
5493 | 5497 | opts.setdefault(b'rev', []).append(b) |
|
5494 | 5498 | else: |
|
5495 | 5499 | # if we try to push a deleted bookmark, translate it to null |
|
5496 | 5500 | # this lets simultaneous -r, -b options continue working |
|
5497 | 5501 | opts.setdefault(b'rev', []).append(b"null") |
|
5498 | 5502 | |
|
5499 | 5503 | path = ui.paths.getpath(dest, default=(b'default-push', b'default')) |
|
5500 | 5504 | if not path: |
|
5501 | 5505 | raise error.Abort( |
|
5502 | 5506 | _(b'default repository not configured!'), |
|
5503 | 5507 | hint=_(b"see 'hg help config.paths'"), |
|
5504 | 5508 | ) |
|
5505 | 5509 | dest = path.pushloc or path.loc |
|
5506 | 5510 | branches = (path.branch, opts.get(b'branch') or []) |
|
5507 | 5511 | ui.status(_(b'pushing to %s\n') % util.hidepassword(dest)) |
|
5508 | 5512 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get(b'rev')) |
|
5509 | 5513 | other = hg.peer(repo, opts, dest) |
|
5510 | 5514 | |
|
5511 | 5515 | if revs: |
|
5512 | 5516 | revs = [repo[r].node() for r in scmutil.revrange(repo, revs)] |
|
5513 | 5517 | if not revs: |
|
5514 | 5518 | raise error.Abort( |
|
5515 | 5519 | _(b"specified revisions evaluate to an empty set"), |
|
5516 | 5520 | hint=_(b"use different revision arguments"), |
|
5517 | 5521 | ) |
|
5518 | 5522 | elif path.pushrev: |
|
5519 | 5523 | # It doesn't make any sense to specify ancestor revisions. So limit |
|
5520 | 5524 | # to DAG heads to make discovery simpler. |
|
5521 | 5525 | expr = revsetlang.formatspec(b'heads(%r)', path.pushrev) |
|
5522 | 5526 | revs = scmutil.revrange(repo, [expr]) |
|
5523 | 5527 | revs = [repo[rev].node() for rev in revs] |
|
5524 | 5528 | if not revs: |
|
5525 | 5529 | raise error.Abort( |
|
5526 | 5530 | _(b'default push revset for path evaluates to an empty set') |
|
5527 | 5531 | ) |
|
5528 | 5532 | elif ui.configbool(b'commands', b'push.require-revs'): |
|
5529 | 5533 | raise error.Abort( |
|
5530 | 5534 | _(b'no revisions specified to push'), |
|
5531 | 5535 | hint=_(b'did you mean "hg push -r ."?'), |
|
5532 | 5536 | ) |
|
5533 | 5537 | |
|
5534 | 5538 | repo._subtoppath = dest |
|
5535 | 5539 | try: |
|
5536 | 5540 | # push subrepos depth-first for coherent ordering |
|
5537 | 5541 | c = repo[b'.'] |
|
5538 | 5542 | subs = c.substate # only repos that are committed |
|
5539 | 5543 | for s in sorted(subs): |
|
5540 | 5544 | result = c.sub(s).push(opts) |
|
5541 | 5545 | if result == 0: |
|
5542 | 5546 | return not result |
|
5543 | 5547 | finally: |
|
5544 | 5548 | del repo._subtoppath |
|
5545 | 5549 | |
|
5546 | 5550 | opargs = dict(opts.get(b'opargs', {})) # copy opargs since we may mutate it |
|
5547 | 5551 | opargs.setdefault(b'pushvars', []).extend(opts.get(b'pushvars', [])) |
|
5548 | 5552 | |
|
5549 | 5553 | pushop = exchange.push( |
|
5550 | 5554 | repo, |
|
5551 | 5555 | other, |
|
5552 | 5556 | opts.get(b'force'), |
|
5553 | 5557 | revs=revs, |
|
5554 | 5558 | newbranch=opts.get(b'new_branch'), |
|
5555 | 5559 | bookmarks=opts.get(b'bookmark', ()), |
|
5556 | 5560 | publish=opts.get(b'publish'), |
|
5557 | 5561 | opargs=opargs, |
|
5558 | 5562 | ) |
|
5559 | 5563 | |
|
5560 | 5564 | result = not pushop.cgresult |
|
5561 | 5565 | |
|
5562 | 5566 | if pushop.bkresult is not None: |
|
5563 | 5567 | if pushop.bkresult == 2: |
|
5564 | 5568 | result = 2 |
|
5565 | 5569 | elif not result and pushop.bkresult: |
|
5566 | 5570 | result = 2 |
|
5567 | 5571 | |
|
5568 | 5572 | return result |
|
5569 | 5573 | |
|
5570 | 5574 | |
|
5571 | 5575 | @command( |
|
5572 | 5576 | b'recover', |
|
5573 | 5577 | [(b'', b'verify', False, b"run `hg verify` after successful recover"),], |
|
5574 | 5578 | helpcategory=command.CATEGORY_MAINTENANCE, |
|
5575 | 5579 | ) |
|
5576 | 5580 | def recover(ui, repo, **opts): |
|
5577 | 5581 | """roll back an interrupted transaction |
|
5578 | 5582 | |
|
5579 | 5583 | Recover from an interrupted commit or pull. |
|
5580 | 5584 | |
|
5581 | 5585 | This command tries to fix the repository status after an |
|
5582 | 5586 | interrupted operation. It should only be necessary when Mercurial |
|
5583 | 5587 | suggests it. |
|
5584 | 5588 | |
|
5585 | 5589 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
5586 | 5590 | """ |
|
5587 | 5591 | ret = repo.recover() |
|
5588 | 5592 | if ret: |
|
5589 | 5593 | if opts['verify']: |
|
5590 | 5594 | return hg.verify(repo) |
|
5591 | 5595 | else: |
|
5592 | 5596 | msg = _( |
|
5593 | 5597 | b"(verify step skipped, run `hg verify` to check your " |
|
5594 | 5598 | b"repository content)\n" |
|
5595 | 5599 | ) |
|
5596 | 5600 | ui.warn(msg) |
|
5597 | 5601 | return 0 |
|
5598 | 5602 | return 1 |
|
5599 | 5603 | |
|
5600 | 5604 | |
|
5601 | 5605 | @command( |
|
5602 | 5606 | b'remove|rm', |
|
5603 | 5607 | [ |
|
5604 | 5608 | (b'A', b'after', None, _(b'record delete for missing files')), |
|
5605 | 5609 | (b'f', b'force', None, _(b'forget added files, delete modified files')), |
|
5606 | 5610 | ] |
|
5607 | 5611 | + subrepoopts |
|
5608 | 5612 | + walkopts |
|
5609 | 5613 | + dryrunopts, |
|
5610 | 5614 | _(b'[OPTION]... FILE...'), |
|
5611 | 5615 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
5612 | 5616 | helpbasic=True, |
|
5613 | 5617 | inferrepo=True, |
|
5614 | 5618 | ) |
|
5615 | 5619 | def remove(ui, repo, *pats, **opts): |
|
5616 | 5620 | """remove the specified files on the next commit |
|
5617 | 5621 | |
|
5618 | 5622 | Schedule the indicated files for removal from the current branch. |
|
5619 | 5623 | |
|
5620 | 5624 | This command schedules the files to be removed at the next commit. |
|
5621 | 5625 | To undo a remove before that, see :hg:`revert`. To undo added |
|
5622 | 5626 | files, see :hg:`forget`. |
|
5623 | 5627 | |
|
5624 | 5628 | .. container:: verbose |
|
5625 | 5629 | |
|
5626 | 5630 | -A/--after can be used to remove only files that have already |
|
5627 | 5631 | been deleted, -f/--force can be used to force deletion, and -Af |
|
5628 | 5632 | can be used to remove files from the next revision without |
|
5629 | 5633 | deleting them from the working directory. |
|
5630 | 5634 | |
|
5631 | 5635 | The following table details the behavior of remove for different |
|
5632 | 5636 | file states (columns) and option combinations (rows). The file |
|
5633 | 5637 | states are Added [A], Clean [C], Modified [M] and Missing [!] |
|
5634 | 5638 | (as reported by :hg:`status`). The actions are Warn, Remove |
|
5635 | 5639 | (from branch) and Delete (from disk): |
|
5636 | 5640 | |
|
5637 | 5641 | ========= == == == == |
|
5638 | 5642 | opt/state A C M ! |
|
5639 | 5643 | ========= == == == == |
|
5640 | 5644 | none W RD W R |
|
5641 | 5645 | -f R RD RD R |
|
5642 | 5646 | -A W W W R |
|
5643 | 5647 | -Af R R R R |
|
5644 | 5648 | ========= == == == == |
|
5645 | 5649 | |
|
5646 | 5650 | .. note:: |
|
5647 | 5651 | |
|
5648 | 5652 | :hg:`remove` never deletes files in Added [A] state from the |
|
5649 | 5653 | working directory, not even if ``--force`` is specified. |
|
5650 | 5654 | |
|
5651 | 5655 | Returns 0 on success, 1 if any warnings encountered. |
|
5652 | 5656 | """ |
|
5653 | 5657 | |
|
5654 | 5658 | opts = pycompat.byteskwargs(opts) |
|
5655 | 5659 | after, force = opts.get(b'after'), opts.get(b'force') |
|
5656 | 5660 | dryrun = opts.get(b'dry_run') |
|
5657 | 5661 | if not pats and not after: |
|
5658 | 5662 | raise error.Abort(_(b'no files specified')) |
|
5659 | 5663 | |
|
5660 | 5664 | m = scmutil.match(repo[None], pats, opts) |
|
5661 | 5665 | subrepos = opts.get(b'subrepos') |
|
5662 | 5666 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
|
5663 | 5667 | return cmdutil.remove( |
|
5664 | 5668 | ui, repo, m, b"", uipathfn, after, force, subrepos, dryrun=dryrun |
|
5665 | 5669 | ) |
|
5666 | 5670 | |
|
5667 | 5671 | |
|
5668 | 5672 | @command( |
|
5669 | 5673 | b'rename|move|mv', |
|
5670 | 5674 | [ |
|
5671 | 5675 | (b'A', b'after', None, _(b'record a rename that has already occurred')), |
|
5672 | 5676 | ( |
|
5673 | 5677 | b'', |
|
5674 | 5678 | b'at-rev', |
|
5675 | 5679 | b'', |
|
5676 | 5680 | _(b'(un)mark renames in the given revision (EXPERIMENTAL)'), |
|
5677 | 5681 | _(b'REV'), |
|
5678 | 5682 | ), |
|
5679 | 5683 | ( |
|
5680 | 5684 | b'f', |
|
5681 | 5685 | b'force', |
|
5682 | 5686 | None, |
|
5683 | 5687 | _(b'forcibly move over an existing managed file'), |
|
5684 | 5688 | ), |
|
5685 | 5689 | ] |
|
5686 | 5690 | + walkopts |
|
5687 | 5691 | + dryrunopts, |
|
5688 | 5692 | _(b'[OPTION]... SOURCE... DEST'), |
|
5689 | 5693 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
5690 | 5694 | ) |
|
5691 | 5695 | def rename(ui, repo, *pats, **opts): |
|
5692 | 5696 | """rename files; equivalent of copy + remove |
|
5693 | 5697 | |
|
5694 | 5698 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
5695 | 5699 | is a directory, copies are put in that directory. If dest is a |
|
5696 | 5700 | file, there can only be one source. |
|
5697 | 5701 | |
|
5698 | 5702 | By default, this command copies the contents of files as they |
|
5699 | 5703 | exist in the working directory. If invoked with -A/--after, the |
|
5700 | 5704 | operation is recorded, but no copying is performed. |
|
5701 | 5705 | |
|
5702 | 5706 | This command takes effect at the next commit. To undo a rename |
|
5703 | 5707 | before that, see :hg:`revert`. |
|
5704 | 5708 | |
|
5705 | 5709 | Returns 0 on success, 1 if errors are encountered. |
|
5706 | 5710 | """ |
|
5707 | 5711 | opts = pycompat.byteskwargs(opts) |
|
5708 | 5712 | with repo.wlock(): |
|
5709 | 5713 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
5710 | 5714 | |
|
5711 | 5715 | |
|
5712 | 5716 | @command( |
|
5713 | 5717 | b'resolve', |
|
5714 | 5718 | [ |
|
5715 | 5719 | (b'a', b'all', None, _(b'select all unresolved files')), |
|
5716 | 5720 | (b'l', b'list', None, _(b'list state of files needing merge')), |
|
5717 | 5721 | (b'm', b'mark', None, _(b'mark files as resolved')), |
|
5718 | 5722 | (b'u', b'unmark', None, _(b'mark files as unresolved')), |
|
5719 | 5723 | (b'n', b'no-status', None, _(b'hide status prefix')), |
|
5720 | 5724 | (b'', b're-merge', None, _(b're-merge files')), |
|
5721 | 5725 | ] |
|
5722 | 5726 | + mergetoolopts |
|
5723 | 5727 | + walkopts |
|
5724 | 5728 | + formatteropts, |
|
5725 | 5729 | _(b'[OPTION]... [FILE]...'), |
|
5726 | 5730 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
5727 | 5731 | inferrepo=True, |
|
5728 | 5732 | ) |
|
5729 | 5733 | def resolve(ui, repo, *pats, **opts): |
|
5730 | 5734 | """redo merges or set/view the merge status of files |
|
5731 | 5735 | |
|
5732 | 5736 | Merges with unresolved conflicts are often the result of |
|
5733 | 5737 | non-interactive merging using the ``internal:merge`` configuration |
|
5734 | 5738 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
5735 | 5739 | command is used to manage the files involved in a merge, after |
|
5736 | 5740 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
5737 | 5741 | working directory must have two parents). See :hg:`help |
|
5738 | 5742 | merge-tools` for information on configuring merge tools. |
|
5739 | 5743 | |
|
5740 | 5744 | The resolve command can be used in the following ways: |
|
5741 | 5745 | |
|
5742 | 5746 | - :hg:`resolve [--re-merge] [--tool TOOL] FILE...`: attempt to re-merge |
|
5743 | 5747 | the specified files, discarding any previous merge attempts. Re-merging |
|
5744 | 5748 | is not performed for files already marked as resolved. Use ``--all/-a`` |
|
5745 | 5749 | to select all unresolved files. ``--tool`` can be used to specify |
|
5746 | 5750 | the merge tool used for the given files. It overrides the HGMERGE |
|
5747 | 5751 | environment variable and your configuration files. Previous file |
|
5748 | 5752 | contents are saved with a ``.orig`` suffix. |
|
5749 | 5753 | |
|
5750 | 5754 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
5751 | 5755 | (e.g. after having manually fixed-up the files). The default is |
|
5752 | 5756 | to mark all unresolved files. |
|
5753 | 5757 | |
|
5754 | 5758 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
5755 | 5759 | default is to mark all resolved files. |
|
5756 | 5760 | |
|
5757 | 5761 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
5758 | 5762 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
5759 | 5763 | You can use ``set:unresolved()`` or ``set:resolved()`` to filter |
|
5760 | 5764 | the list. See :hg:`help filesets` for details. |
|
5761 | 5765 | |
|
5762 | 5766 | .. note:: |
|
5763 | 5767 | |
|
5764 | 5768 | Mercurial will not let you commit files with unresolved merge |
|
5765 | 5769 | conflicts. You must use :hg:`resolve -m ...` before you can |
|
5766 | 5770 | commit after a conflicting merge. |
|
5767 | 5771 | |
|
5768 | 5772 | .. container:: verbose |
|
5769 | 5773 | |
|
5770 | 5774 | Template: |
|
5771 | 5775 | |
|
5772 | 5776 | The following keywords are supported in addition to the common template |
|
5773 | 5777 | keywords and functions. See also :hg:`help templates`. |
|
5774 | 5778 | |
|
5775 | 5779 | :mergestatus: String. Character denoting merge conflicts, ``U`` or ``R``. |
|
5776 | 5780 | :path: String. Repository-absolute path of the file. |
|
5777 | 5781 | |
|
5778 | 5782 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
5779 | 5783 | """ |
|
5780 | 5784 | |
|
5781 | 5785 | opts = pycompat.byteskwargs(opts) |
|
5782 | 5786 | confirm = ui.configbool(b'commands', b'resolve.confirm') |
|
5783 | 5787 | flaglist = b'all mark unmark list no_status re_merge'.split() |
|
5784 | 5788 | all, mark, unmark, show, nostatus, remerge = [opts.get(o) for o in flaglist] |
|
5785 | 5789 | |
|
5786 | 5790 | actioncount = len(list(filter(None, [show, mark, unmark, remerge]))) |
|
5787 | 5791 | if actioncount > 1: |
|
5788 | 5792 | raise error.Abort(_(b"too many actions specified")) |
|
5789 | 5793 | elif actioncount == 0 and ui.configbool( |
|
5790 | 5794 | b'commands', b'resolve.explicit-re-merge' |
|
5791 | 5795 | ): |
|
5792 | 5796 | hint = _(b'use --mark, --unmark, --list or --re-merge') |
|
5793 | 5797 | raise error.Abort(_(b'no action specified'), hint=hint) |
|
5794 | 5798 | if pats and all: |
|
5795 | 5799 | raise error.Abort(_(b"can't specify --all and patterns")) |
|
5796 | 5800 | if not (all or pats or show or mark or unmark): |
|
5797 | 5801 | raise error.Abort( |
|
5798 | 5802 | _(b'no files or directories specified'), |
|
5799 | 5803 | hint=b'use --all to re-merge all unresolved files', |
|
5800 | 5804 | ) |
|
5801 | 5805 | |
|
5802 | 5806 | if confirm: |
|
5803 | 5807 | if all: |
|
5804 | 5808 | if ui.promptchoice( |
|
5805 | 5809 | _(b're-merge all unresolved files (yn)?$$ &Yes $$ &No') |
|
5806 | 5810 | ): |
|
5807 | 5811 | raise error.Abort(_(b'user quit')) |
|
5808 | 5812 | if mark and not pats: |
|
5809 | 5813 | if ui.promptchoice( |
|
5810 | 5814 | _( |
|
5811 | 5815 | b'mark all unresolved files as resolved (yn)?' |
|
5812 | 5816 | b'$$ &Yes $$ &No' |
|
5813 | 5817 | ) |
|
5814 | 5818 | ): |
|
5815 | 5819 | raise error.Abort(_(b'user quit')) |
|
5816 | 5820 | if unmark and not pats: |
|
5817 | 5821 | if ui.promptchoice( |
|
5818 | 5822 | _( |
|
5819 | 5823 | b'mark all resolved files as unresolved (yn)?' |
|
5820 | 5824 | b'$$ &Yes $$ &No' |
|
5821 | 5825 | ) |
|
5822 | 5826 | ): |
|
5823 | 5827 | raise error.Abort(_(b'user quit')) |
|
5824 | 5828 | |
|
5825 | 5829 | uipathfn = scmutil.getuipathfn(repo) |
|
5826 | 5830 | |
|
5827 | 5831 | if show: |
|
5828 | 5832 | ui.pager(b'resolve') |
|
5829 | 5833 | fm = ui.formatter(b'resolve', opts) |
|
5830 | 5834 | ms = mergestatemod.mergestate.read(repo) |
|
5831 | 5835 | wctx = repo[None] |
|
5832 | 5836 | m = scmutil.match(wctx, pats, opts) |
|
5833 | 5837 | |
|
5834 | 5838 | # Labels and keys based on merge state. Unresolved path conflicts show |
|
5835 | 5839 | # as 'P'. Resolved path conflicts show as 'R', the same as normal |
|
5836 | 5840 | # resolved conflicts. |
|
5837 | 5841 | mergestateinfo = { |
|
5838 | 5842 | mergestatemod.MERGE_RECORD_UNRESOLVED: ( |
|
5839 | 5843 | b'resolve.unresolved', |
|
5840 | 5844 | b'U', |
|
5841 | 5845 | ), |
|
5842 | 5846 | mergestatemod.MERGE_RECORD_RESOLVED: (b'resolve.resolved', b'R'), |
|
5843 | 5847 | mergestatemod.MERGE_RECORD_UNRESOLVED_PATH: ( |
|
5844 | 5848 | b'resolve.unresolved', |
|
5845 | 5849 | b'P', |
|
5846 | 5850 | ), |
|
5847 | 5851 | mergestatemod.MERGE_RECORD_RESOLVED_PATH: ( |
|
5848 | 5852 | b'resolve.resolved', |
|
5849 | 5853 | b'R', |
|
5850 | 5854 | ), |
|
5851 | 5855 | } |
|
5852 | 5856 | |
|
5853 | 5857 | for f in ms: |
|
5854 | 5858 | if not m(f): |
|
5855 | 5859 | continue |
|
5856 | 5860 | |
|
5857 | 5861 | label, key = mergestateinfo[ms[f]] |
|
5858 | 5862 | fm.startitem() |
|
5859 | 5863 | fm.context(ctx=wctx) |
|
5860 | 5864 | fm.condwrite(not nostatus, b'mergestatus', b'%s ', key, label=label) |
|
5861 | 5865 | fm.data(path=f) |
|
5862 | 5866 | fm.plain(b'%s\n' % uipathfn(f), label=label) |
|
5863 | 5867 | fm.end() |
|
5864 | 5868 | return 0 |
|
5865 | 5869 | |
|
5866 | 5870 | with repo.wlock(): |
|
5867 | 5871 | ms = mergestatemod.mergestate.read(repo) |
|
5868 | 5872 | |
|
5869 | 5873 | if not (ms.active() or repo.dirstate.p2() != nullid): |
|
5870 | 5874 | raise error.Abort( |
|
5871 | 5875 | _(b'resolve command not applicable when not merging') |
|
5872 | 5876 | ) |
|
5873 | 5877 | |
|
5874 | 5878 | wctx = repo[None] |
|
5875 | 5879 | m = scmutil.match(wctx, pats, opts) |
|
5876 | 5880 | ret = 0 |
|
5877 | 5881 | didwork = False |
|
5878 | 5882 | |
|
5879 | 5883 | tocomplete = [] |
|
5880 | 5884 | hasconflictmarkers = [] |
|
5881 | 5885 | if mark: |
|
5882 | 5886 | markcheck = ui.config(b'commands', b'resolve.mark-check') |
|
5883 | 5887 | if markcheck not in [b'warn', b'abort']: |
|
5884 | 5888 | # Treat all invalid / unrecognized values as 'none'. |
|
5885 | 5889 | markcheck = False |
|
5886 | 5890 | for f in ms: |
|
5887 | 5891 | if not m(f): |
|
5888 | 5892 | continue |
|
5889 | 5893 | |
|
5890 | 5894 | didwork = True |
|
5891 | 5895 | |
|
5892 | 5896 | # path conflicts must be resolved manually |
|
5893 | 5897 | if ms[f] in ( |
|
5894 | 5898 | mergestatemod.MERGE_RECORD_UNRESOLVED_PATH, |
|
5895 | 5899 | mergestatemod.MERGE_RECORD_RESOLVED_PATH, |
|
5896 | 5900 | ): |
|
5897 | 5901 | if mark: |
|
5898 | 5902 | ms.mark(f, mergestatemod.MERGE_RECORD_RESOLVED_PATH) |
|
5899 | 5903 | elif unmark: |
|
5900 | 5904 | ms.mark(f, mergestatemod.MERGE_RECORD_UNRESOLVED_PATH) |
|
5901 | 5905 | elif ms[f] == mergestatemod.MERGE_RECORD_UNRESOLVED_PATH: |
|
5902 | 5906 | ui.warn( |
|
5903 | 5907 | _(b'%s: path conflict must be resolved manually\n') |
|
5904 | 5908 | % uipathfn(f) |
|
5905 | 5909 | ) |
|
5906 | 5910 | continue |
|
5907 | 5911 | |
|
5908 | 5912 | if mark: |
|
5909 | 5913 | if markcheck: |
|
5910 | 5914 | fdata = repo.wvfs.tryread(f) |
|
5911 | 5915 | if ( |
|
5912 | 5916 | filemerge.hasconflictmarkers(fdata) |
|
5913 | 5917 | and ms[f] != mergestatemod.MERGE_RECORD_RESOLVED |
|
5914 | 5918 | ): |
|
5915 | 5919 | hasconflictmarkers.append(f) |
|
5916 | 5920 | ms.mark(f, mergestatemod.MERGE_RECORD_RESOLVED) |
|
5917 | 5921 | elif unmark: |
|
5918 | 5922 | ms.mark(f, mergestatemod.MERGE_RECORD_UNRESOLVED) |
|
5919 | 5923 | else: |
|
5920 | 5924 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
5921 | 5925 | a = repo.wjoin(f) |
|
5922 | 5926 | try: |
|
5923 | 5927 | util.copyfile(a, a + b".resolve") |
|
5924 | 5928 | except (IOError, OSError) as inst: |
|
5925 | 5929 | if inst.errno != errno.ENOENT: |
|
5926 | 5930 | raise |
|
5927 | 5931 | |
|
5928 | 5932 | try: |
|
5929 | 5933 | # preresolve file |
|
5930 | 5934 | overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')} |
|
5931 | 5935 | with ui.configoverride(overrides, b'resolve'): |
|
5932 | 5936 | complete, r = ms.preresolve(f, wctx) |
|
5933 | 5937 | if not complete: |
|
5934 | 5938 | tocomplete.append(f) |
|
5935 | 5939 | elif r: |
|
5936 | 5940 | ret = 1 |
|
5937 | 5941 | finally: |
|
5938 | 5942 | ms.commit() |
|
5939 | 5943 | |
|
5940 | 5944 | # replace filemerge's .orig file with our resolve file, but only |
|
5941 | 5945 | # for merges that are complete |
|
5942 | 5946 | if complete: |
|
5943 | 5947 | try: |
|
5944 | 5948 | util.rename( |
|
5945 | 5949 | a + b".resolve", scmutil.backuppath(ui, repo, f) |
|
5946 | 5950 | ) |
|
5947 | 5951 | except OSError as inst: |
|
5948 | 5952 | if inst.errno != errno.ENOENT: |
|
5949 | 5953 | raise |
|
5950 | 5954 | |
|
5951 | 5955 | if hasconflictmarkers: |
|
5952 | 5956 | ui.warn( |
|
5953 | 5957 | _( |
|
5954 | 5958 | b'warning: the following files still have conflict ' |
|
5955 | 5959 | b'markers:\n' |
|
5956 | 5960 | ) |
|
5957 | 5961 | + b''.join( |
|
5958 | 5962 | b' ' + uipathfn(f) + b'\n' for f in hasconflictmarkers |
|
5959 | 5963 | ) |
|
5960 | 5964 | ) |
|
5961 | 5965 | if markcheck == b'abort' and not all and not pats: |
|
5962 | 5966 | raise error.Abort( |
|
5963 | 5967 | _(b'conflict markers detected'), |
|
5964 | 5968 | hint=_(b'use --all to mark anyway'), |
|
5965 | 5969 | ) |
|
5966 | 5970 | |
|
5967 | 5971 | for f in tocomplete: |
|
5968 | 5972 | try: |
|
5969 | 5973 | # resolve file |
|
5970 | 5974 | overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')} |
|
5971 | 5975 | with ui.configoverride(overrides, b'resolve'): |
|
5972 | 5976 | r = ms.resolve(f, wctx) |
|
5973 | 5977 | if r: |
|
5974 | 5978 | ret = 1 |
|
5975 | 5979 | finally: |
|
5976 | 5980 | ms.commit() |
|
5977 | 5981 | |
|
5978 | 5982 | # replace filemerge's .orig file with our resolve file |
|
5979 | 5983 | a = repo.wjoin(f) |
|
5980 | 5984 | try: |
|
5981 | 5985 | util.rename(a + b".resolve", scmutil.backuppath(ui, repo, f)) |
|
5982 | 5986 | except OSError as inst: |
|
5983 | 5987 | if inst.errno != errno.ENOENT: |
|
5984 | 5988 | raise |
|
5985 | 5989 | |
|
5986 | 5990 | ms.commit() |
|
5987 | 5991 | branchmerge = repo.dirstate.p2() != nullid |
|
5988 | 5992 | mergestatemod.recordupdates(repo, ms.actions(), branchmerge, None) |
|
5989 | 5993 | |
|
5990 | 5994 | if not didwork and pats: |
|
5991 | 5995 | hint = None |
|
5992 | 5996 | if not any([p for p in pats if p.find(b':') >= 0]): |
|
5993 | 5997 | pats = [b'path:%s' % p for p in pats] |
|
5994 | 5998 | m = scmutil.match(wctx, pats, opts) |
|
5995 | 5999 | for f in ms: |
|
5996 | 6000 | if not m(f): |
|
5997 | 6001 | continue |
|
5998 | 6002 | |
|
5999 | 6003 | def flag(o): |
|
6000 | 6004 | if o == b're_merge': |
|
6001 | 6005 | return b'--re-merge ' |
|
6002 | 6006 | return b'-%s ' % o[0:1] |
|
6003 | 6007 | |
|
6004 | 6008 | flags = b''.join([flag(o) for o in flaglist if opts.get(o)]) |
|
6005 | 6009 | hint = _(b"(try: hg resolve %s%s)\n") % ( |
|
6006 | 6010 | flags, |
|
6007 | 6011 | b' '.join(pats), |
|
6008 | 6012 | ) |
|
6009 | 6013 | break |
|
6010 | 6014 | ui.warn(_(b"arguments do not match paths that need resolving\n")) |
|
6011 | 6015 | if hint: |
|
6012 | 6016 | ui.warn(hint) |
|
6013 | 6017 | |
|
6014 | 6018 | unresolvedf = list(ms.unresolved()) |
|
6015 | 6019 | if not unresolvedf: |
|
6016 | 6020 | ui.status(_(b'(no more unresolved files)\n')) |
|
6017 | 6021 | cmdutil.checkafterresolved(repo) |
|
6018 | 6022 | |
|
6019 | 6023 | return ret |
|
6020 | 6024 | |
|
6021 | 6025 | |
|
6022 | 6026 | @command( |
|
6023 | 6027 | b'revert', |
|
6024 | 6028 | [ |
|
6025 | 6029 | (b'a', b'all', None, _(b'revert all changes when no arguments given')), |
|
6026 | 6030 | (b'd', b'date', b'', _(b'tipmost revision matching date'), _(b'DATE')), |
|
6027 | 6031 | (b'r', b'rev', b'', _(b'revert to the specified revision'), _(b'REV')), |
|
6028 | 6032 | (b'C', b'no-backup', None, _(b'do not save backup copies of files')), |
|
6029 | 6033 | (b'i', b'interactive', None, _(b'interactively select the changes')), |
|
6030 | 6034 | ] |
|
6031 | 6035 | + walkopts |
|
6032 | 6036 | + dryrunopts, |
|
6033 | 6037 | _(b'[OPTION]... [-r REV] [NAME]...'), |
|
6034 | 6038 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
6035 | 6039 | ) |
|
6036 | 6040 | def revert(ui, repo, *pats, **opts): |
|
6037 | 6041 | """restore files to their checkout state |
|
6038 | 6042 | |
|
6039 | 6043 | .. note:: |
|
6040 | 6044 | |
|
6041 | 6045 | To check out earlier revisions, you should use :hg:`update REV`. |
|
6042 | 6046 | To cancel an uncommitted merge (and lose your changes), |
|
6043 | 6047 | use :hg:`merge --abort`. |
|
6044 | 6048 | |
|
6045 | 6049 | With no revision specified, revert the specified files or directories |
|
6046 | 6050 | to the contents they had in the parent of the working directory. |
|
6047 | 6051 | This restores the contents of files to an unmodified |
|
6048 | 6052 | state and unschedules adds, removes, copies, and renames. If the |
|
6049 | 6053 | working directory has two parents, you must explicitly specify a |
|
6050 | 6054 | revision. |
|
6051 | 6055 | |
|
6052 | 6056 | Using the -r/--rev or -d/--date options, revert the given files or |
|
6053 | 6057 | directories to their states as of a specific revision. Because |
|
6054 | 6058 | revert does not change the working directory parents, this will |
|
6055 | 6059 | cause these files to appear modified. This can be helpful to "back |
|
6056 | 6060 | out" some or all of an earlier change. See :hg:`backout` for a |
|
6057 | 6061 | related method. |
|
6058 | 6062 | |
|
6059 | 6063 | Modified files are saved with a .orig suffix before reverting. |
|
6060 | 6064 | To disable these backups, use --no-backup. It is possible to store |
|
6061 | 6065 | the backup files in a custom directory relative to the root of the |
|
6062 | 6066 | repository by setting the ``ui.origbackuppath`` configuration |
|
6063 | 6067 | option. |
|
6064 | 6068 | |
|
6065 | 6069 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
6066 | 6070 | |
|
6067 | 6071 | See :hg:`help backout` for a way to reverse the effect of an |
|
6068 | 6072 | earlier changeset. |
|
6069 | 6073 | |
|
6070 | 6074 | Returns 0 on success. |
|
6071 | 6075 | """ |
|
6072 | 6076 | |
|
6073 | 6077 | opts = pycompat.byteskwargs(opts) |
|
6074 | 6078 | if opts.get(b"date"): |
|
6075 | 6079 | cmdutil.check_incompatible_arguments(opts, b'date', [b'rev']) |
|
6076 | 6080 | opts[b"rev"] = cmdutil.finddate(ui, repo, opts[b"date"]) |
|
6077 | 6081 | |
|
6078 | 6082 | parent, p2 = repo.dirstate.parents() |
|
6079 | 6083 | if not opts.get(b'rev') and p2 != nullid: |
|
6080 | 6084 | # revert after merge is a trap for new users (issue2915) |
|
6081 | 6085 | raise error.Abort( |
|
6082 | 6086 | _(b'uncommitted merge with no revision specified'), |
|
6083 | 6087 | hint=_(b"use 'hg update' or see 'hg help revert'"), |
|
6084 | 6088 | ) |
|
6085 | 6089 | |
|
6086 | 6090 | rev = opts.get(b'rev') |
|
6087 | 6091 | if rev: |
|
6088 | 6092 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
6089 | 6093 | ctx = scmutil.revsingle(repo, rev) |
|
6090 | 6094 | |
|
6091 | 6095 | if not ( |
|
6092 | 6096 | pats |
|
6093 | 6097 | or opts.get(b'include') |
|
6094 | 6098 | or opts.get(b'exclude') |
|
6095 | 6099 | or opts.get(b'all') |
|
6096 | 6100 | or opts.get(b'interactive') |
|
6097 | 6101 | ): |
|
6098 | 6102 | msg = _(b"no files or directories specified") |
|
6099 | 6103 | if p2 != nullid: |
|
6100 | 6104 | hint = _( |
|
6101 | 6105 | b"uncommitted merge, use --all to discard all changes," |
|
6102 | 6106 | b" or 'hg update -C .' to abort the merge" |
|
6103 | 6107 | ) |
|
6104 | 6108 | raise error.Abort(msg, hint=hint) |
|
6105 | 6109 | dirty = any(repo.status()) |
|
6106 | 6110 | node = ctx.node() |
|
6107 | 6111 | if node != parent: |
|
6108 | 6112 | if dirty: |
|
6109 | 6113 | hint = ( |
|
6110 | 6114 | _( |
|
6111 | 6115 | b"uncommitted changes, use --all to discard all" |
|
6112 | 6116 | b" changes, or 'hg update %d' to update" |
|
6113 | 6117 | ) |
|
6114 | 6118 | % ctx.rev() |
|
6115 | 6119 | ) |
|
6116 | 6120 | else: |
|
6117 | 6121 | hint = ( |
|
6118 | 6122 | _( |
|
6119 | 6123 | b"use --all to revert all files," |
|
6120 | 6124 | b" or 'hg update %d' to update" |
|
6121 | 6125 | ) |
|
6122 | 6126 | % ctx.rev() |
|
6123 | 6127 | ) |
|
6124 | 6128 | elif dirty: |
|
6125 | 6129 | hint = _(b"uncommitted changes, use --all to discard all changes") |
|
6126 | 6130 | else: |
|
6127 | 6131 | hint = _(b"use --all to revert all files") |
|
6128 | 6132 | raise error.Abort(msg, hint=hint) |
|
6129 | 6133 | |
|
6130 | 6134 | return cmdutil.revert(ui, repo, ctx, *pats, **pycompat.strkwargs(opts)) |
|
6131 | 6135 | |
|
6132 | 6136 | |
|
6133 | 6137 | @command( |
|
6134 | 6138 | b'rollback', |
|
6135 | 6139 | dryrunopts + [(b'f', b'force', False, _(b'ignore safety measures'))], |
|
6136 | 6140 | helpcategory=command.CATEGORY_MAINTENANCE, |
|
6137 | 6141 | ) |
|
6138 | 6142 | def rollback(ui, repo, **opts): |
|
6139 | 6143 | """roll back the last transaction (DANGEROUS) (DEPRECATED) |
|
6140 | 6144 | |
|
6141 | 6145 | Please use :hg:`commit --amend` instead of rollback to correct |
|
6142 | 6146 | mistakes in the last commit. |
|
6143 | 6147 | |
|
6144 | 6148 | This command should be used with care. There is only one level of |
|
6145 | 6149 | rollback, and there is no way to undo a rollback. It will also |
|
6146 | 6150 | restore the dirstate at the time of the last transaction, losing |
|
6147 | 6151 | any dirstate changes since that time. This command does not alter |
|
6148 | 6152 | the working directory. |
|
6149 | 6153 | |
|
6150 | 6154 | Transactions are used to encapsulate the effects of all commands |
|
6151 | 6155 | that create new changesets or propagate existing changesets into a |
|
6152 | 6156 | repository. |
|
6153 | 6157 | |
|
6154 | 6158 | .. container:: verbose |
|
6155 | 6159 | |
|
6156 | 6160 | For example, the following commands are transactional, and their |
|
6157 | 6161 | effects can be rolled back: |
|
6158 | 6162 | |
|
6159 | 6163 | - commit |
|
6160 | 6164 | - import |
|
6161 | 6165 | - pull |
|
6162 | 6166 | - push (with this repository as the destination) |
|
6163 | 6167 | - unbundle |
|
6164 | 6168 | |
|
6165 | 6169 | To avoid permanent data loss, rollback will refuse to rollback a |
|
6166 | 6170 | commit transaction if it isn't checked out. Use --force to |
|
6167 | 6171 | override this protection. |
|
6168 | 6172 | |
|
6169 | 6173 | The rollback command can be entirely disabled by setting the |
|
6170 | 6174 | ``ui.rollback`` configuration setting to false. If you're here |
|
6171 | 6175 | because you want to use rollback and it's disabled, you can |
|
6172 | 6176 | re-enable the command by setting ``ui.rollback`` to true. |
|
6173 | 6177 | |
|
6174 | 6178 | This command is not intended for use on public repositories. Once |
|
6175 | 6179 | changes are visible for pull by other users, rolling a transaction |
|
6176 | 6180 | back locally is ineffective (someone else may already have pulled |
|
6177 | 6181 | the changes). Furthermore, a race is possible with readers of the |
|
6178 | 6182 | repository; for example an in-progress pull from the repository |
|
6179 | 6183 | may fail if a rollback is performed. |
|
6180 | 6184 | |
|
6181 | 6185 | Returns 0 on success, 1 if no rollback data is available. |
|
6182 | 6186 | """ |
|
6183 | 6187 | if not ui.configbool(b'ui', b'rollback'): |
|
6184 | 6188 | raise error.Abort( |
|
6185 | 6189 | _(b'rollback is disabled because it is unsafe'), |
|
6186 | 6190 | hint=b'see `hg help -v rollback` for information', |
|
6187 | 6191 | ) |
|
6188 | 6192 | return repo.rollback(dryrun=opts.get('dry_run'), force=opts.get('force')) |
|
6189 | 6193 | |
|
6190 | 6194 | |
|
6191 | 6195 | @command( |
|
6192 | 6196 | b'root', |
|
6193 | 6197 | [] + formatteropts, |
|
6194 | 6198 | intents={INTENT_READONLY}, |
|
6195 | 6199 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
6196 | 6200 | ) |
|
6197 | 6201 | def root(ui, repo, **opts): |
|
6198 | 6202 | """print the root (top) of the current working directory |
|
6199 | 6203 | |
|
6200 | 6204 | Print the root directory of the current repository. |
|
6201 | 6205 | |
|
6202 | 6206 | .. container:: verbose |
|
6203 | 6207 | |
|
6204 | 6208 | Template: |
|
6205 | 6209 | |
|
6206 | 6210 | The following keywords are supported in addition to the common template |
|
6207 | 6211 | keywords and functions. See also :hg:`help templates`. |
|
6208 | 6212 | |
|
6209 | 6213 | :hgpath: String. Path to the .hg directory. |
|
6210 | 6214 | :storepath: String. Path to the directory holding versioned data. |
|
6211 | 6215 | |
|
6212 | 6216 | Returns 0 on success. |
|
6213 | 6217 | """ |
|
6214 | 6218 | opts = pycompat.byteskwargs(opts) |
|
6215 | 6219 | with ui.formatter(b'root', opts) as fm: |
|
6216 | 6220 | fm.startitem() |
|
6217 | 6221 | fm.write(b'reporoot', b'%s\n', repo.root) |
|
6218 | 6222 | fm.data(hgpath=repo.path, storepath=repo.spath) |
|
6219 | 6223 | |
|
6220 | 6224 | |
|
6221 | 6225 | @command( |
|
6222 | 6226 | b'serve', |
|
6223 | 6227 | [ |
|
6224 | 6228 | ( |
|
6225 | 6229 | b'A', |
|
6226 | 6230 | b'accesslog', |
|
6227 | 6231 | b'', |
|
6228 | 6232 | _(b'name of access log file to write to'), |
|
6229 | 6233 | _(b'FILE'), |
|
6230 | 6234 | ), |
|
6231 | 6235 | (b'd', b'daemon', None, _(b'run server in background')), |
|
6232 | 6236 | (b'', b'daemon-postexec', [], _(b'used internally by daemon mode')), |
|
6233 | 6237 | ( |
|
6234 | 6238 | b'E', |
|
6235 | 6239 | b'errorlog', |
|
6236 | 6240 | b'', |
|
6237 | 6241 | _(b'name of error log file to write to'), |
|
6238 | 6242 | _(b'FILE'), |
|
6239 | 6243 | ), |
|
6240 | 6244 | # use string type, then we can check if something was passed |
|
6241 | 6245 | ( |
|
6242 | 6246 | b'p', |
|
6243 | 6247 | b'port', |
|
6244 | 6248 | b'', |
|
6245 | 6249 | _(b'port to listen on (default: 8000)'), |
|
6246 | 6250 | _(b'PORT'), |
|
6247 | 6251 | ), |
|
6248 | 6252 | ( |
|
6249 | 6253 | b'a', |
|
6250 | 6254 | b'address', |
|
6251 | 6255 | b'', |
|
6252 | 6256 | _(b'address to listen on (default: all interfaces)'), |
|
6253 | 6257 | _(b'ADDR'), |
|
6254 | 6258 | ), |
|
6255 | 6259 | ( |
|
6256 | 6260 | b'', |
|
6257 | 6261 | b'prefix', |
|
6258 | 6262 | b'', |
|
6259 | 6263 | _(b'prefix path to serve from (default: server root)'), |
|
6260 | 6264 | _(b'PREFIX'), |
|
6261 | 6265 | ), |
|
6262 | 6266 | ( |
|
6263 | 6267 | b'n', |
|
6264 | 6268 | b'name', |
|
6265 | 6269 | b'', |
|
6266 | 6270 | _(b'name to show in web pages (default: working directory)'), |
|
6267 | 6271 | _(b'NAME'), |
|
6268 | 6272 | ), |
|
6269 | 6273 | ( |
|
6270 | 6274 | b'', |
|
6271 | 6275 | b'web-conf', |
|
6272 | 6276 | b'', |
|
6273 | 6277 | _(b"name of the hgweb config file (see 'hg help hgweb')"), |
|
6274 | 6278 | _(b'FILE'), |
|
6275 | 6279 | ), |
|
6276 | 6280 | ( |
|
6277 | 6281 | b'', |
|
6278 | 6282 | b'webdir-conf', |
|
6279 | 6283 | b'', |
|
6280 | 6284 | _(b'name of the hgweb config file (DEPRECATED)'), |
|
6281 | 6285 | _(b'FILE'), |
|
6282 | 6286 | ), |
|
6283 | 6287 | ( |
|
6284 | 6288 | b'', |
|
6285 | 6289 | b'pid-file', |
|
6286 | 6290 | b'', |
|
6287 | 6291 | _(b'name of file to write process ID to'), |
|
6288 | 6292 | _(b'FILE'), |
|
6289 | 6293 | ), |
|
6290 | 6294 | (b'', b'stdio', None, _(b'for remote clients (ADVANCED)')), |
|
6291 | 6295 | ( |
|
6292 | 6296 | b'', |
|
6293 | 6297 | b'cmdserver', |
|
6294 | 6298 | b'', |
|
6295 | 6299 | _(b'for remote clients (ADVANCED)'), |
|
6296 | 6300 | _(b'MODE'), |
|
6297 | 6301 | ), |
|
6298 | 6302 | (b't', b'templates', b'', _(b'web templates to use'), _(b'TEMPLATE')), |
|
6299 | 6303 | (b'', b'style', b'', _(b'template style to use'), _(b'STYLE')), |
|
6300 | 6304 | (b'6', b'ipv6', None, _(b'use IPv6 in addition to IPv4')), |
|
6301 | 6305 | (b'', b'certificate', b'', _(b'SSL certificate file'), _(b'FILE')), |
|
6302 | 6306 | (b'', b'print-url', None, _(b'start and print only the URL')), |
|
6303 | 6307 | ] |
|
6304 | 6308 | + subrepoopts, |
|
6305 | 6309 | _(b'[OPTION]...'), |
|
6306 | 6310 | helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT, |
|
6307 | 6311 | helpbasic=True, |
|
6308 | 6312 | optionalrepo=True, |
|
6309 | 6313 | ) |
|
6310 | 6314 | def serve(ui, repo, **opts): |
|
6311 | 6315 | """start stand-alone webserver |
|
6312 | 6316 | |
|
6313 | 6317 | Start a local HTTP repository browser and pull server. You can use |
|
6314 | 6318 | this for ad-hoc sharing and browsing of repositories. It is |
|
6315 | 6319 | recommended to use a real web server to serve a repository for |
|
6316 | 6320 | longer periods of time. |
|
6317 | 6321 | |
|
6318 | 6322 | Please note that the server does not implement access control. |
|
6319 | 6323 | This means that, by default, anybody can read from the server and |
|
6320 | 6324 | nobody can write to it by default. Set the ``web.allow-push`` |
|
6321 | 6325 | option to ``*`` to allow everybody to push to the server. You |
|
6322 | 6326 | should use a real web server if you need to authenticate users. |
|
6323 | 6327 | |
|
6324 | 6328 | By default, the server logs accesses to stdout and errors to |
|
6325 | 6329 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
6326 | 6330 | files. |
|
6327 | 6331 | |
|
6328 | 6332 | To have the server choose a free port number to listen on, specify |
|
6329 | 6333 | a port number of 0; in this case, the server will print the port |
|
6330 | 6334 | number it uses. |
|
6331 | 6335 | |
|
6332 | 6336 | Returns 0 on success. |
|
6333 | 6337 | """ |
|
6334 | 6338 | |
|
6335 | 6339 | cmdutil.check_incompatible_arguments(opts, 'stdio', ['cmdserver']) |
|
6336 | 6340 | opts = pycompat.byteskwargs(opts) |
|
6337 | 6341 | if opts[b"print_url"] and ui.verbose: |
|
6338 | 6342 | raise error.Abort(_(b"cannot use --print-url with --verbose")) |
|
6339 | 6343 | |
|
6340 | 6344 | if opts[b"stdio"]: |
|
6341 | 6345 | if repo is None: |
|
6342 | 6346 | raise error.RepoError( |
|
6343 | 6347 | _(b"there is no Mercurial repository here (.hg not found)") |
|
6344 | 6348 | ) |
|
6345 | 6349 | s = wireprotoserver.sshserver(ui, repo) |
|
6346 | 6350 | s.serve_forever() |
|
6347 | 6351 | |
|
6348 | 6352 | service = server.createservice(ui, repo, opts) |
|
6349 | 6353 | return server.runservice(opts, initfn=service.init, runfn=service.run) |
|
6350 | 6354 | |
|
6351 | 6355 | |
|
6352 | 6356 | @command( |
|
6353 | 6357 | b'shelve', |
|
6354 | 6358 | [ |
|
6355 | 6359 | ( |
|
6356 | 6360 | b'A', |
|
6357 | 6361 | b'addremove', |
|
6358 | 6362 | None, |
|
6359 | 6363 | _(b'mark new/missing files as added/removed before shelving'), |
|
6360 | 6364 | ), |
|
6361 | 6365 | (b'u', b'unknown', None, _(b'store unknown files in the shelve')), |
|
6362 | 6366 | (b'', b'cleanup', None, _(b'delete all shelved changes')), |
|
6363 | 6367 | ( |
|
6364 | 6368 | b'', |
|
6365 | 6369 | b'date', |
|
6366 | 6370 | b'', |
|
6367 | 6371 | _(b'shelve with the specified commit date'), |
|
6368 | 6372 | _(b'DATE'), |
|
6369 | 6373 | ), |
|
6370 | 6374 | (b'd', b'delete', None, _(b'delete the named shelved change(s)')), |
|
6371 | 6375 | (b'e', b'edit', False, _(b'invoke editor on commit messages')), |
|
6372 | 6376 | ( |
|
6373 | 6377 | b'k', |
|
6374 | 6378 | b'keep', |
|
6375 | 6379 | False, |
|
6376 | 6380 | _(b'shelve, but keep changes in the working directory'), |
|
6377 | 6381 | ), |
|
6378 | 6382 | (b'l', b'list', None, _(b'list current shelves')), |
|
6379 | 6383 | (b'm', b'message', b'', _(b'use text as shelve message'), _(b'TEXT')), |
|
6380 | 6384 | ( |
|
6381 | 6385 | b'n', |
|
6382 | 6386 | b'name', |
|
6383 | 6387 | b'', |
|
6384 | 6388 | _(b'use the given name for the shelved commit'), |
|
6385 | 6389 | _(b'NAME'), |
|
6386 | 6390 | ), |
|
6387 | 6391 | ( |
|
6388 | 6392 | b'p', |
|
6389 | 6393 | b'patch', |
|
6390 | 6394 | None, |
|
6391 | 6395 | _( |
|
6392 | 6396 | b'output patches for changes (provide the names of the shelved ' |
|
6393 | 6397 | b'changes as positional arguments)' |
|
6394 | 6398 | ), |
|
6395 | 6399 | ), |
|
6396 | 6400 | (b'i', b'interactive', None, _(b'interactive mode')), |
|
6397 | 6401 | ( |
|
6398 | 6402 | b'', |
|
6399 | 6403 | b'stat', |
|
6400 | 6404 | None, |
|
6401 | 6405 | _( |
|
6402 | 6406 | b'output diffstat-style summary of changes (provide the names of ' |
|
6403 | 6407 | b'the shelved changes as positional arguments)' |
|
6404 | 6408 | ), |
|
6405 | 6409 | ), |
|
6406 | 6410 | ] |
|
6407 | 6411 | + cmdutil.walkopts, |
|
6408 | 6412 | _(b'hg shelve [OPTION]... [FILE]...'), |
|
6409 | 6413 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
6410 | 6414 | ) |
|
6411 | 6415 | def shelve(ui, repo, *pats, **opts): |
|
6412 | 6416 | '''save and set aside changes from the working directory |
|
6413 | 6417 | |
|
6414 | 6418 | Shelving takes files that "hg status" reports as not clean, saves |
|
6415 | 6419 | the modifications to a bundle (a shelved change), and reverts the |
|
6416 | 6420 | files so that their state in the working directory becomes clean. |
|
6417 | 6421 | |
|
6418 | 6422 | To restore these changes to the working directory, using "hg |
|
6419 | 6423 | unshelve"; this will work even if you switch to a different |
|
6420 | 6424 | commit. |
|
6421 | 6425 | |
|
6422 | 6426 | When no files are specified, "hg shelve" saves all not-clean |
|
6423 | 6427 | files. If specific files or directories are named, only changes to |
|
6424 | 6428 | those files are shelved. |
|
6425 | 6429 | |
|
6426 | 6430 | In bare shelve (when no files are specified, without interactive, |
|
6427 | 6431 | include and exclude option), shelving remembers information if the |
|
6428 | 6432 | working directory was on newly created branch, in other words working |
|
6429 | 6433 | directory was on different branch than its first parent. In this |
|
6430 | 6434 | situation unshelving restores branch information to the working directory. |
|
6431 | 6435 | |
|
6432 | 6436 | Each shelved change has a name that makes it easier to find later. |
|
6433 | 6437 | The name of a shelved change defaults to being based on the active |
|
6434 | 6438 | bookmark, or if there is no active bookmark, the current named |
|
6435 | 6439 | branch. To specify a different name, use ``--name``. |
|
6436 | 6440 | |
|
6437 | 6441 | To see a list of existing shelved changes, use the ``--list`` |
|
6438 | 6442 | option. For each shelved change, this will print its name, age, |
|
6439 | 6443 | and description; use ``--patch`` or ``--stat`` for more details. |
|
6440 | 6444 | |
|
6441 | 6445 | To delete specific shelved changes, use ``--delete``. To delete |
|
6442 | 6446 | all shelved changes, use ``--cleanup``. |
|
6443 | 6447 | ''' |
|
6444 | 6448 | opts = pycompat.byteskwargs(opts) |
|
6445 | 6449 | allowables = [ |
|
6446 | 6450 | (b'addremove', {b'create'}), # 'create' is pseudo action |
|
6447 | 6451 | (b'unknown', {b'create'}), |
|
6448 | 6452 | (b'cleanup', {b'cleanup'}), |
|
6449 | 6453 | # ('date', {'create'}), # ignored for passing '--date "0 0"' in tests |
|
6450 | 6454 | (b'delete', {b'delete'}), |
|
6451 | 6455 | (b'edit', {b'create'}), |
|
6452 | 6456 | (b'keep', {b'create'}), |
|
6453 | 6457 | (b'list', {b'list'}), |
|
6454 | 6458 | (b'message', {b'create'}), |
|
6455 | 6459 | (b'name', {b'create'}), |
|
6456 | 6460 | (b'patch', {b'patch', b'list'}), |
|
6457 | 6461 | (b'stat', {b'stat', b'list'}), |
|
6458 | 6462 | ] |
|
6459 | 6463 | |
|
6460 | 6464 | def checkopt(opt): |
|
6461 | 6465 | if opts.get(opt): |
|
6462 | 6466 | for i, allowable in allowables: |
|
6463 | 6467 | if opts[i] and opt not in allowable: |
|
6464 | 6468 | raise error.Abort( |
|
6465 | 6469 | _( |
|
6466 | 6470 | b"options '--%s' and '--%s' may not be " |
|
6467 | 6471 | b"used together" |
|
6468 | 6472 | ) |
|
6469 | 6473 | % (opt, i) |
|
6470 | 6474 | ) |
|
6471 | 6475 | return True |
|
6472 | 6476 | |
|
6473 | 6477 | if checkopt(b'cleanup'): |
|
6474 | 6478 | if pats: |
|
6475 | 6479 | raise error.Abort(_(b"cannot specify names when using '--cleanup'")) |
|
6476 | 6480 | return shelvemod.cleanupcmd(ui, repo) |
|
6477 | 6481 | elif checkopt(b'delete'): |
|
6478 | 6482 | return shelvemod.deletecmd(ui, repo, pats) |
|
6479 | 6483 | elif checkopt(b'list'): |
|
6480 | 6484 | return shelvemod.listcmd(ui, repo, pats, opts) |
|
6481 | 6485 | elif checkopt(b'patch') or checkopt(b'stat'): |
|
6482 | 6486 | return shelvemod.patchcmds(ui, repo, pats, opts) |
|
6483 | 6487 | else: |
|
6484 | 6488 | return shelvemod.createcmd(ui, repo, pats, opts) |
|
6485 | 6489 | |
|
6486 | 6490 | |
|
6487 | 6491 | _NOTTERSE = b'nothing' |
|
6488 | 6492 | |
|
6489 | 6493 | |
|
6490 | 6494 | @command( |
|
6491 | 6495 | b'status|st', |
|
6492 | 6496 | [ |
|
6493 | 6497 | (b'A', b'all', None, _(b'show status of all files')), |
|
6494 | 6498 | (b'm', b'modified', None, _(b'show only modified files')), |
|
6495 | 6499 | (b'a', b'added', None, _(b'show only added files')), |
|
6496 | 6500 | (b'r', b'removed', None, _(b'show only removed files')), |
|
6497 | 6501 | (b'd', b'deleted', None, _(b'show only missing files')), |
|
6498 | 6502 | (b'c', b'clean', None, _(b'show only files without changes')), |
|
6499 | 6503 | (b'u', b'unknown', None, _(b'show only unknown (not tracked) files')), |
|
6500 | 6504 | (b'i', b'ignored', None, _(b'show only ignored files')), |
|
6501 | 6505 | (b'n', b'no-status', None, _(b'hide status prefix')), |
|
6502 | 6506 | (b't', b'terse', _NOTTERSE, _(b'show the terse output (EXPERIMENTAL)')), |
|
6503 | 6507 | ( |
|
6504 | 6508 | b'C', |
|
6505 | 6509 | b'copies', |
|
6506 | 6510 | None, |
|
6507 | 6511 | _(b'show source of copied files (DEFAULT: ui.statuscopies)'), |
|
6508 | 6512 | ), |
|
6509 | 6513 | ( |
|
6510 | 6514 | b'0', |
|
6511 | 6515 | b'print0', |
|
6512 | 6516 | None, |
|
6513 | 6517 | _(b'end filenames with NUL, for use with xargs'), |
|
6514 | 6518 | ), |
|
6515 | 6519 | (b'', b'rev', [], _(b'show difference from revision'), _(b'REV')), |
|
6516 | 6520 | ( |
|
6517 | 6521 | b'', |
|
6518 | 6522 | b'change', |
|
6519 | 6523 | b'', |
|
6520 | 6524 | _(b'list the changed files of a revision'), |
|
6521 | 6525 | _(b'REV'), |
|
6522 | 6526 | ), |
|
6523 | 6527 | ] |
|
6524 | 6528 | + walkopts |
|
6525 | 6529 | + subrepoopts |
|
6526 | 6530 | + formatteropts, |
|
6527 | 6531 | _(b'[OPTION]... [FILE]...'), |
|
6528 | 6532 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
6529 | 6533 | helpbasic=True, |
|
6530 | 6534 | inferrepo=True, |
|
6531 | 6535 | intents={INTENT_READONLY}, |
|
6532 | 6536 | ) |
|
6533 | 6537 | def status(ui, repo, *pats, **opts): |
|
6534 | 6538 | """show changed files in the working directory |
|
6535 | 6539 | |
|
6536 | 6540 | Show status of files in the repository. If names are given, only |
|
6537 | 6541 | files that match are shown. Files that are clean or ignored or |
|
6538 | 6542 | the source of a copy/move operation, are not listed unless |
|
6539 | 6543 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
6540 | 6544 | Unless options described with "show only ..." are given, the |
|
6541 | 6545 | options -mardu are used. |
|
6542 | 6546 | |
|
6543 | 6547 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
6544 | 6548 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
6545 | 6549 | |
|
6546 | 6550 | .. note:: |
|
6547 | 6551 | |
|
6548 | 6552 | :hg:`status` may appear to disagree with diff if permissions have |
|
6549 | 6553 | changed or a merge has occurred. The standard diff format does |
|
6550 | 6554 | not report permission changes and diff only reports changes |
|
6551 | 6555 | relative to one merge parent. |
|
6552 | 6556 | |
|
6553 | 6557 | If one revision is given, it is used as the base revision. |
|
6554 | 6558 | If two revisions are given, the differences between them are |
|
6555 | 6559 | shown. The --change option can also be used as a shortcut to list |
|
6556 | 6560 | the changed files of a revision from its first parent. |
|
6557 | 6561 | |
|
6558 | 6562 | The codes used to show the status of files are:: |
|
6559 | 6563 | |
|
6560 | 6564 | M = modified |
|
6561 | 6565 | A = added |
|
6562 | 6566 | R = removed |
|
6563 | 6567 | C = clean |
|
6564 | 6568 | ! = missing (deleted by non-hg command, but still tracked) |
|
6565 | 6569 | ? = not tracked |
|
6566 | 6570 | I = ignored |
|
6567 | 6571 | = origin of the previous file (with --copies) |
|
6568 | 6572 | |
|
6569 | 6573 | .. container:: verbose |
|
6570 | 6574 | |
|
6571 | 6575 | The -t/--terse option abbreviates the output by showing only the directory |
|
6572 | 6576 | name if all the files in it share the same status. The option takes an |
|
6573 | 6577 | argument indicating the statuses to abbreviate: 'm' for 'modified', 'a' |
|
6574 | 6578 | for 'added', 'r' for 'removed', 'd' for 'deleted', 'u' for 'unknown', 'i' |
|
6575 | 6579 | for 'ignored' and 'c' for clean. |
|
6576 | 6580 | |
|
6577 | 6581 | It abbreviates only those statuses which are passed. Note that clean and |
|
6578 | 6582 | ignored files are not displayed with '--terse ic' unless the -c/--clean |
|
6579 | 6583 | and -i/--ignored options are also used. |
|
6580 | 6584 | |
|
6581 | 6585 | The -v/--verbose option shows information when the repository is in an |
|
6582 | 6586 | unfinished merge, shelve, rebase state etc. You can have this behavior |
|
6583 | 6587 | turned on by default by enabling the ``commands.status.verbose`` option. |
|
6584 | 6588 | |
|
6585 | 6589 | You can skip displaying some of these states by setting |
|
6586 | 6590 | ``commands.status.skipstates`` to one or more of: 'bisect', 'graft', |
|
6587 | 6591 | 'histedit', 'merge', 'rebase', or 'unshelve'. |
|
6588 | 6592 | |
|
6589 | 6593 | Template: |
|
6590 | 6594 | |
|
6591 | 6595 | The following keywords are supported in addition to the common template |
|
6592 | 6596 | keywords and functions. See also :hg:`help templates`. |
|
6593 | 6597 | |
|
6594 | 6598 | :path: String. Repository-absolute path of the file. |
|
6595 | 6599 | :source: String. Repository-absolute path of the file originated from. |
|
6596 | 6600 | Available if ``--copies`` is specified. |
|
6597 | 6601 | :status: String. Character denoting file's status. |
|
6598 | 6602 | |
|
6599 | 6603 | Examples: |
|
6600 | 6604 | |
|
6601 | 6605 | - show changes in the working directory relative to a |
|
6602 | 6606 | changeset:: |
|
6603 | 6607 | |
|
6604 | 6608 | hg status --rev 9353 |
|
6605 | 6609 | |
|
6606 | 6610 | - show changes in the working directory relative to the |
|
6607 | 6611 | current directory (see :hg:`help patterns` for more information):: |
|
6608 | 6612 | |
|
6609 | 6613 | hg status re: |
|
6610 | 6614 | |
|
6611 | 6615 | - show all changes including copies in an existing changeset:: |
|
6612 | 6616 | |
|
6613 | 6617 | hg status --copies --change 9353 |
|
6614 | 6618 | |
|
6615 | 6619 | - get a NUL separated list of added files, suitable for xargs:: |
|
6616 | 6620 | |
|
6617 | 6621 | hg status -an0 |
|
6618 | 6622 | |
|
6619 | 6623 | - show more information about the repository status, abbreviating |
|
6620 | 6624 | added, removed, modified, deleted, and untracked paths:: |
|
6621 | 6625 | |
|
6622 | 6626 | hg status -v -t mardu |
|
6623 | 6627 | |
|
6624 | 6628 | Returns 0 on success. |
|
6625 | 6629 | |
|
6626 | 6630 | """ |
|
6627 | 6631 | |
|
6628 | 6632 | cmdutil.check_at_most_one_arg(opts, 'rev', 'change') |
|
6629 | 6633 | opts = pycompat.byteskwargs(opts) |
|
6630 | 6634 | revs = opts.get(b'rev') |
|
6631 | 6635 | change = opts.get(b'change') |
|
6632 | 6636 | terse = opts.get(b'terse') |
|
6633 | 6637 | if terse is _NOTTERSE: |
|
6634 | 6638 | if revs: |
|
6635 | 6639 | terse = b'' |
|
6636 | 6640 | else: |
|
6637 | 6641 | terse = ui.config(b'commands', b'status.terse') |
|
6638 | 6642 | |
|
6639 | 6643 | if revs and terse: |
|
6640 | 6644 | msg = _(b'cannot use --terse with --rev') |
|
6641 | 6645 | raise error.Abort(msg) |
|
6642 | 6646 | elif change: |
|
6643 | 6647 | repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn') |
|
6644 | 6648 | ctx2 = scmutil.revsingle(repo, change, None) |
|
6645 | 6649 | ctx1 = ctx2.p1() |
|
6646 | 6650 | else: |
|
6647 | 6651 | repo = scmutil.unhidehashlikerevs(repo, revs, b'nowarn') |
|
6648 | 6652 | ctx1, ctx2 = scmutil.revpair(repo, revs) |
|
6649 | 6653 | |
|
6650 | 6654 | forcerelativevalue = None |
|
6651 | 6655 | if ui.hasconfig(b'commands', b'status.relative'): |
|
6652 | 6656 | forcerelativevalue = ui.configbool(b'commands', b'status.relative') |
|
6653 | 6657 | uipathfn = scmutil.getuipathfn( |
|
6654 | 6658 | repo, |
|
6655 | 6659 | legacyrelativevalue=bool(pats), |
|
6656 | 6660 | forcerelativevalue=forcerelativevalue, |
|
6657 | 6661 | ) |
|
6658 | 6662 | |
|
6659 | 6663 | if opts.get(b'print0'): |
|
6660 | 6664 | end = b'\0' |
|
6661 | 6665 | else: |
|
6662 | 6666 | end = b'\n' |
|
6663 | 6667 | states = b'modified added removed deleted unknown ignored clean'.split() |
|
6664 | 6668 | show = [k for k in states if opts.get(k)] |
|
6665 | 6669 | if opts.get(b'all'): |
|
6666 | 6670 | show += ui.quiet and (states[:4] + [b'clean']) or states |
|
6667 | 6671 | |
|
6668 | 6672 | if not show: |
|
6669 | 6673 | if ui.quiet: |
|
6670 | 6674 | show = states[:4] |
|
6671 | 6675 | else: |
|
6672 | 6676 | show = states[:5] |
|
6673 | 6677 | |
|
6674 | 6678 | m = scmutil.match(ctx2, pats, opts) |
|
6675 | 6679 | if terse: |
|
6676 | 6680 | # we need to compute clean and unknown to terse |
|
6677 | 6681 | stat = repo.status( |
|
6678 | 6682 | ctx1.node(), |
|
6679 | 6683 | ctx2.node(), |
|
6680 | 6684 | m, |
|
6681 | 6685 | b'ignored' in show or b'i' in terse, |
|
6682 | 6686 | clean=True, |
|
6683 | 6687 | unknown=True, |
|
6684 | 6688 | listsubrepos=opts.get(b'subrepos'), |
|
6685 | 6689 | ) |
|
6686 | 6690 | |
|
6687 | 6691 | stat = cmdutil.tersedir(stat, terse) |
|
6688 | 6692 | else: |
|
6689 | 6693 | stat = repo.status( |
|
6690 | 6694 | ctx1.node(), |
|
6691 | 6695 | ctx2.node(), |
|
6692 | 6696 | m, |
|
6693 | 6697 | b'ignored' in show, |
|
6694 | 6698 | b'clean' in show, |
|
6695 | 6699 | b'unknown' in show, |
|
6696 | 6700 | opts.get(b'subrepos'), |
|
6697 | 6701 | ) |
|
6698 | 6702 | |
|
6699 | 6703 | changestates = zip( |
|
6700 | 6704 | states, |
|
6701 | 6705 | pycompat.iterbytestr(b'MAR!?IC'), |
|
6702 | 6706 | [getattr(stat, s.decode('utf8')) for s in states], |
|
6703 | 6707 | ) |
|
6704 | 6708 | |
|
6705 | 6709 | copy = {} |
|
6706 | 6710 | if ( |
|
6707 | 6711 | opts.get(b'all') |
|
6708 | 6712 | or opts.get(b'copies') |
|
6709 | 6713 | or ui.configbool(b'ui', b'statuscopies') |
|
6710 | 6714 | ) and not opts.get(b'no_status'): |
|
6711 | 6715 | copy = copies.pathcopies(ctx1, ctx2, m) |
|
6712 | 6716 | |
|
6713 | 6717 | morestatus = None |
|
6714 | 6718 | if ( |
|
6715 | 6719 | ui.verbose or ui.configbool(b'commands', b'status.verbose') |
|
6716 | 6720 | ) and not ui.plain(): |
|
6717 | 6721 | morestatus = cmdutil.readmorestatus(repo) |
|
6718 | 6722 | |
|
6719 | 6723 | ui.pager(b'status') |
|
6720 | 6724 | fm = ui.formatter(b'status', opts) |
|
6721 | 6725 | fmt = b'%s' + end |
|
6722 | 6726 | showchar = not opts.get(b'no_status') |
|
6723 | 6727 | |
|
6724 | 6728 | for state, char, files in changestates: |
|
6725 | 6729 | if state in show: |
|
6726 | 6730 | label = b'status.' + state |
|
6727 | 6731 | for f in files: |
|
6728 | 6732 | fm.startitem() |
|
6729 | 6733 | fm.context(ctx=ctx2) |
|
6730 | 6734 | fm.data(itemtype=b'file', path=f) |
|
6731 | 6735 | fm.condwrite(showchar, b'status', b'%s ', char, label=label) |
|
6732 | 6736 | fm.plain(fmt % uipathfn(f), label=label) |
|
6733 | 6737 | if f in copy: |
|
6734 | 6738 | fm.data(source=copy[f]) |
|
6735 | 6739 | fm.plain( |
|
6736 | 6740 | (b' %s' + end) % uipathfn(copy[f]), |
|
6737 | 6741 | label=b'status.copied', |
|
6738 | 6742 | ) |
|
6739 | 6743 | if morestatus: |
|
6740 | 6744 | morestatus.formatfile(f, fm) |
|
6741 | 6745 | |
|
6742 | 6746 | if morestatus: |
|
6743 | 6747 | morestatus.formatfooter(fm) |
|
6744 | 6748 | fm.end() |
|
6745 | 6749 | |
|
6746 | 6750 | |
|
6747 | 6751 | @command( |
|
6748 | 6752 | b'summary|sum', |
|
6749 | 6753 | [(b'', b'remote', None, _(b'check for push and pull'))], |
|
6750 | 6754 | b'[--remote]', |
|
6751 | 6755 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
6752 | 6756 | helpbasic=True, |
|
6753 | 6757 | intents={INTENT_READONLY}, |
|
6754 | 6758 | ) |
|
6755 | 6759 | def summary(ui, repo, **opts): |
|
6756 | 6760 | """summarize working directory state |
|
6757 | 6761 | |
|
6758 | 6762 | This generates a brief summary of the working directory state, |
|
6759 | 6763 | including parents, branch, commit status, phase and available updates. |
|
6760 | 6764 | |
|
6761 | 6765 | With the --remote option, this will check the default paths for |
|
6762 | 6766 | incoming and outgoing changes. This can be time-consuming. |
|
6763 | 6767 | |
|
6764 | 6768 | Returns 0 on success. |
|
6765 | 6769 | """ |
|
6766 | 6770 | |
|
6767 | 6771 | opts = pycompat.byteskwargs(opts) |
|
6768 | 6772 | ui.pager(b'summary') |
|
6769 | 6773 | ctx = repo[None] |
|
6770 | 6774 | parents = ctx.parents() |
|
6771 | 6775 | pnode = parents[0].node() |
|
6772 | 6776 | marks = [] |
|
6773 | 6777 | |
|
6774 | 6778 | try: |
|
6775 | 6779 | ms = mergestatemod.mergestate.read(repo) |
|
6776 | 6780 | except error.UnsupportedMergeRecords as e: |
|
6777 | 6781 | s = b' '.join(e.recordtypes) |
|
6778 | 6782 | ui.warn( |
|
6779 | 6783 | _(b'warning: merge state has unsupported record types: %s\n') % s |
|
6780 | 6784 | ) |
|
6781 | 6785 | unresolved = [] |
|
6782 | 6786 | else: |
|
6783 | 6787 | unresolved = list(ms.unresolved()) |
|
6784 | 6788 | |
|
6785 | 6789 | for p in parents: |
|
6786 | 6790 | # label with log.changeset (instead of log.parent) since this |
|
6787 | 6791 | # shows a working directory parent *changeset*: |
|
6788 | 6792 | # i18n: column positioning for "hg summary" |
|
6789 | 6793 | ui.write( |
|
6790 | 6794 | _(b'parent: %d:%s ') % (p.rev(), p), |
|
6791 | 6795 | label=logcmdutil.changesetlabels(p), |
|
6792 | 6796 | ) |
|
6793 | 6797 | ui.write(b' '.join(p.tags()), label=b'log.tag') |
|
6794 | 6798 | if p.bookmarks(): |
|
6795 | 6799 | marks.extend(p.bookmarks()) |
|
6796 | 6800 | if p.rev() == -1: |
|
6797 | 6801 | if not len(repo): |
|
6798 | 6802 | ui.write(_(b' (empty repository)')) |
|
6799 | 6803 | else: |
|
6800 | 6804 | ui.write(_(b' (no revision checked out)')) |
|
6801 | 6805 | if p.obsolete(): |
|
6802 | 6806 | ui.write(_(b' (obsolete)')) |
|
6803 | 6807 | if p.isunstable(): |
|
6804 | 6808 | instabilities = ( |
|
6805 | 6809 | ui.label(instability, b'trouble.%s' % instability) |
|
6806 | 6810 | for instability in p.instabilities() |
|
6807 | 6811 | ) |
|
6808 | 6812 | ui.write(b' (' + b', '.join(instabilities) + b')') |
|
6809 | 6813 | ui.write(b'\n') |
|
6810 | 6814 | if p.description(): |
|
6811 | 6815 | ui.status( |
|
6812 | 6816 | b' ' + p.description().splitlines()[0].strip() + b'\n', |
|
6813 | 6817 | label=b'log.summary', |
|
6814 | 6818 | ) |
|
6815 | 6819 | |
|
6816 | 6820 | branch = ctx.branch() |
|
6817 | 6821 | bheads = repo.branchheads(branch) |
|
6818 | 6822 | # i18n: column positioning for "hg summary" |
|
6819 | 6823 | m = _(b'branch: %s\n') % branch |
|
6820 | 6824 | if branch != b'default': |
|
6821 | 6825 | ui.write(m, label=b'log.branch') |
|
6822 | 6826 | else: |
|
6823 | 6827 | ui.status(m, label=b'log.branch') |
|
6824 | 6828 | |
|
6825 | 6829 | if marks: |
|
6826 | 6830 | active = repo._activebookmark |
|
6827 | 6831 | # i18n: column positioning for "hg summary" |
|
6828 | 6832 | ui.write(_(b'bookmarks:'), label=b'log.bookmark') |
|
6829 | 6833 | if active is not None: |
|
6830 | 6834 | if active in marks: |
|
6831 | 6835 | ui.write(b' *' + active, label=bookmarks.activebookmarklabel) |
|
6832 | 6836 | marks.remove(active) |
|
6833 | 6837 | else: |
|
6834 | 6838 | ui.write(b' [%s]' % active, label=bookmarks.activebookmarklabel) |
|
6835 | 6839 | for m in marks: |
|
6836 | 6840 | ui.write(b' ' + m, label=b'log.bookmark') |
|
6837 | 6841 | ui.write(b'\n', label=b'log.bookmark') |
|
6838 | 6842 | |
|
6839 | 6843 | status = repo.status(unknown=True) |
|
6840 | 6844 | |
|
6841 | 6845 | c = repo.dirstate.copies() |
|
6842 | 6846 | copied, renamed = [], [] |
|
6843 | 6847 | for d, s in pycompat.iteritems(c): |
|
6844 | 6848 | if s in status.removed: |
|
6845 | 6849 | status.removed.remove(s) |
|
6846 | 6850 | renamed.append(d) |
|
6847 | 6851 | else: |
|
6848 | 6852 | copied.append(d) |
|
6849 | 6853 | if d in status.added: |
|
6850 | 6854 | status.added.remove(d) |
|
6851 | 6855 | |
|
6852 | 6856 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
6853 | 6857 | |
|
6854 | 6858 | labels = [ |
|
6855 | 6859 | (ui.label(_(b'%d modified'), b'status.modified'), status.modified), |
|
6856 | 6860 | (ui.label(_(b'%d added'), b'status.added'), status.added), |
|
6857 | 6861 | (ui.label(_(b'%d removed'), b'status.removed'), status.removed), |
|
6858 | 6862 | (ui.label(_(b'%d renamed'), b'status.copied'), renamed), |
|
6859 | 6863 | (ui.label(_(b'%d copied'), b'status.copied'), copied), |
|
6860 | 6864 | (ui.label(_(b'%d deleted'), b'status.deleted'), status.deleted), |
|
6861 | 6865 | (ui.label(_(b'%d unknown'), b'status.unknown'), status.unknown), |
|
6862 | 6866 | (ui.label(_(b'%d unresolved'), b'resolve.unresolved'), unresolved), |
|
6863 | 6867 | (ui.label(_(b'%d subrepos'), b'status.modified'), subs), |
|
6864 | 6868 | ] |
|
6865 | 6869 | t = [] |
|
6866 | 6870 | for l, s in labels: |
|
6867 | 6871 | if s: |
|
6868 | 6872 | t.append(l % len(s)) |
|
6869 | 6873 | |
|
6870 | 6874 | t = b', '.join(t) |
|
6871 | 6875 | cleanworkdir = False |
|
6872 | 6876 | |
|
6873 | 6877 | if repo.vfs.exists(b'graftstate'): |
|
6874 | 6878 | t += _(b' (graft in progress)') |
|
6875 | 6879 | if repo.vfs.exists(b'updatestate'): |
|
6876 | 6880 | t += _(b' (interrupted update)') |
|
6877 | 6881 | elif len(parents) > 1: |
|
6878 | 6882 | t += _(b' (merge)') |
|
6879 | 6883 | elif branch != parents[0].branch(): |
|
6880 | 6884 | t += _(b' (new branch)') |
|
6881 | 6885 | elif parents[0].closesbranch() and pnode in repo.branchheads( |
|
6882 | 6886 | branch, closed=True |
|
6883 | 6887 | ): |
|
6884 | 6888 | t += _(b' (head closed)') |
|
6885 | 6889 | elif not ( |
|
6886 | 6890 | status.modified |
|
6887 | 6891 | or status.added |
|
6888 | 6892 | or status.removed |
|
6889 | 6893 | or renamed |
|
6890 | 6894 | or copied |
|
6891 | 6895 | or subs |
|
6892 | 6896 | ): |
|
6893 | 6897 | t += _(b' (clean)') |
|
6894 | 6898 | cleanworkdir = True |
|
6895 | 6899 | elif pnode not in bheads: |
|
6896 | 6900 | t += _(b' (new branch head)') |
|
6897 | 6901 | |
|
6898 | 6902 | if parents: |
|
6899 | 6903 | pendingphase = max(p.phase() for p in parents) |
|
6900 | 6904 | else: |
|
6901 | 6905 | pendingphase = phases.public |
|
6902 | 6906 | |
|
6903 | 6907 | if pendingphase > phases.newcommitphase(ui): |
|
6904 | 6908 | t += b' (%s)' % phases.phasenames[pendingphase] |
|
6905 | 6909 | |
|
6906 | 6910 | if cleanworkdir: |
|
6907 | 6911 | # i18n: column positioning for "hg summary" |
|
6908 | 6912 | ui.status(_(b'commit: %s\n') % t.strip()) |
|
6909 | 6913 | else: |
|
6910 | 6914 | # i18n: column positioning for "hg summary" |
|
6911 | 6915 | ui.write(_(b'commit: %s\n') % t.strip()) |
|
6912 | 6916 | |
|
6913 | 6917 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
6914 | 6918 | new = len( |
|
6915 | 6919 | repo.changelog.findmissing([pctx.node() for pctx in parents], bheads) |
|
6916 | 6920 | ) |
|
6917 | 6921 | |
|
6918 | 6922 | if new == 0: |
|
6919 | 6923 | # i18n: column positioning for "hg summary" |
|
6920 | 6924 | ui.status(_(b'update: (current)\n')) |
|
6921 | 6925 | elif pnode not in bheads: |
|
6922 | 6926 | # i18n: column positioning for "hg summary" |
|
6923 | 6927 | ui.write(_(b'update: %d new changesets (update)\n') % new) |
|
6924 | 6928 | else: |
|
6925 | 6929 | # i18n: column positioning for "hg summary" |
|
6926 | 6930 | ui.write( |
|
6927 | 6931 | _(b'update: %d new changesets, %d branch heads (merge)\n') |
|
6928 | 6932 | % (new, len(bheads)) |
|
6929 | 6933 | ) |
|
6930 | 6934 | |
|
6931 | 6935 | t = [] |
|
6932 | 6936 | draft = len(repo.revs(b'draft()')) |
|
6933 | 6937 | if draft: |
|
6934 | 6938 | t.append(_(b'%d draft') % draft) |
|
6935 | 6939 | secret = len(repo.revs(b'secret()')) |
|
6936 | 6940 | if secret: |
|
6937 | 6941 | t.append(_(b'%d secret') % secret) |
|
6938 | 6942 | |
|
6939 | 6943 | if draft or secret: |
|
6940 | 6944 | ui.status(_(b'phases: %s\n') % b', '.join(t)) |
|
6941 | 6945 | |
|
6942 | 6946 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
6943 | 6947 | for trouble in (b"orphan", b"contentdivergent", b"phasedivergent"): |
|
6944 | 6948 | numtrouble = len(repo.revs(trouble + b"()")) |
|
6945 | 6949 | # We write all the possibilities to ease translation |
|
6946 | 6950 | troublemsg = { |
|
6947 | 6951 | b"orphan": _(b"orphan: %d changesets"), |
|
6948 | 6952 | b"contentdivergent": _(b"content-divergent: %d changesets"), |
|
6949 | 6953 | b"phasedivergent": _(b"phase-divergent: %d changesets"), |
|
6950 | 6954 | } |
|
6951 | 6955 | if numtrouble > 0: |
|
6952 | 6956 | ui.status(troublemsg[trouble] % numtrouble + b"\n") |
|
6953 | 6957 | |
|
6954 | 6958 | cmdutil.summaryhooks(ui, repo) |
|
6955 | 6959 | |
|
6956 | 6960 | if opts.get(b'remote'): |
|
6957 | 6961 | needsincoming, needsoutgoing = True, True |
|
6958 | 6962 | else: |
|
6959 | 6963 | needsincoming, needsoutgoing = False, False |
|
6960 | 6964 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): |
|
6961 | 6965 | if i: |
|
6962 | 6966 | needsincoming = True |
|
6963 | 6967 | if o: |
|
6964 | 6968 | needsoutgoing = True |
|
6965 | 6969 | if not needsincoming and not needsoutgoing: |
|
6966 | 6970 | return |
|
6967 | 6971 | |
|
6968 | 6972 | def getincoming(): |
|
6969 | 6973 | source, branches = hg.parseurl(ui.expandpath(b'default')) |
|
6970 | 6974 | sbranch = branches[0] |
|
6971 | 6975 | try: |
|
6972 | 6976 | other = hg.peer(repo, {}, source) |
|
6973 | 6977 | except error.RepoError: |
|
6974 | 6978 | if opts.get(b'remote'): |
|
6975 | 6979 | raise |
|
6976 | 6980 | return source, sbranch, None, None, None |
|
6977 | 6981 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) |
|
6978 | 6982 | if revs: |
|
6979 | 6983 | revs = [other.lookup(rev) for rev in revs] |
|
6980 | 6984 | ui.debug(b'comparing with %s\n' % util.hidepassword(source)) |
|
6981 | 6985 | repo.ui.pushbuffer() |
|
6982 | 6986 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) |
|
6983 | 6987 | repo.ui.popbuffer() |
|
6984 | 6988 | return source, sbranch, other, commoninc, commoninc[1] |
|
6985 | 6989 | |
|
6986 | 6990 | if needsincoming: |
|
6987 | 6991 | source, sbranch, sother, commoninc, incoming = getincoming() |
|
6988 | 6992 | else: |
|
6989 | 6993 | source = sbranch = sother = commoninc = incoming = None |
|
6990 | 6994 | |
|
6991 | 6995 | def getoutgoing(): |
|
6992 | 6996 | dest, branches = hg.parseurl(ui.expandpath(b'default-push', b'default')) |
|
6993 | 6997 | dbranch = branches[0] |
|
6994 | 6998 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
6995 | 6999 | if source != dest: |
|
6996 | 7000 | try: |
|
6997 | 7001 | dother = hg.peer(repo, {}, dest) |
|
6998 | 7002 | except error.RepoError: |
|
6999 | 7003 | if opts.get(b'remote'): |
|
7000 | 7004 | raise |
|
7001 | 7005 | return dest, dbranch, None, None |
|
7002 | 7006 | ui.debug(b'comparing with %s\n' % util.hidepassword(dest)) |
|
7003 | 7007 | elif sother is None: |
|
7004 | 7008 | # there is no explicit destination peer, but source one is invalid |
|
7005 | 7009 | return dest, dbranch, None, None |
|
7006 | 7010 | else: |
|
7007 | 7011 | dother = sother |
|
7008 | 7012 | if source != dest or (sbranch is not None and sbranch != dbranch): |
|
7009 | 7013 | common = None |
|
7010 | 7014 | else: |
|
7011 | 7015 | common = commoninc |
|
7012 | 7016 | if revs: |
|
7013 | 7017 | revs = [repo.lookup(rev) for rev in revs] |
|
7014 | 7018 | repo.ui.pushbuffer() |
|
7015 | 7019 | outgoing = discovery.findcommonoutgoing( |
|
7016 | 7020 | repo, dother, onlyheads=revs, commoninc=common |
|
7017 | 7021 | ) |
|
7018 | 7022 | repo.ui.popbuffer() |
|
7019 | 7023 | return dest, dbranch, dother, outgoing |
|
7020 | 7024 | |
|
7021 | 7025 | if needsoutgoing: |
|
7022 | 7026 | dest, dbranch, dother, outgoing = getoutgoing() |
|
7023 | 7027 | else: |
|
7024 | 7028 | dest = dbranch = dother = outgoing = None |
|
7025 | 7029 | |
|
7026 | 7030 | if opts.get(b'remote'): |
|
7027 | 7031 | t = [] |
|
7028 | 7032 | if incoming: |
|
7029 | 7033 | t.append(_(b'1 or more incoming')) |
|
7030 | 7034 | o = outgoing.missing |
|
7031 | 7035 | if o: |
|
7032 | 7036 | t.append(_(b'%d outgoing') % len(o)) |
|
7033 | 7037 | other = dother or sother |
|
7034 | 7038 | if b'bookmarks' in other.listkeys(b'namespaces'): |
|
7035 | 7039 | counts = bookmarks.summary(repo, other) |
|
7036 | 7040 | if counts[0] > 0: |
|
7037 | 7041 | t.append(_(b'%d incoming bookmarks') % counts[0]) |
|
7038 | 7042 | if counts[1] > 0: |
|
7039 | 7043 | t.append(_(b'%d outgoing bookmarks') % counts[1]) |
|
7040 | 7044 | |
|
7041 | 7045 | if t: |
|
7042 | 7046 | # i18n: column positioning for "hg summary" |
|
7043 | 7047 | ui.write(_(b'remote: %s\n') % (b', '.join(t))) |
|
7044 | 7048 | else: |
|
7045 | 7049 | # i18n: column positioning for "hg summary" |
|
7046 | 7050 | ui.status(_(b'remote: (synced)\n')) |
|
7047 | 7051 | |
|
7048 | 7052 | cmdutil.summaryremotehooks( |
|
7049 | 7053 | ui, |
|
7050 | 7054 | repo, |
|
7051 | 7055 | opts, |
|
7052 | 7056 | ( |
|
7053 | 7057 | (source, sbranch, sother, commoninc), |
|
7054 | 7058 | (dest, dbranch, dother, outgoing), |
|
7055 | 7059 | ), |
|
7056 | 7060 | ) |
|
7057 | 7061 | |
|
7058 | 7062 | |
|
7059 | 7063 | @command( |
|
7060 | 7064 | b'tag', |
|
7061 | 7065 | [ |
|
7062 | 7066 | (b'f', b'force', None, _(b'force tag')), |
|
7063 | 7067 | (b'l', b'local', None, _(b'make the tag local')), |
|
7064 | 7068 | (b'r', b'rev', b'', _(b'revision to tag'), _(b'REV')), |
|
7065 | 7069 | (b'', b'remove', None, _(b'remove a tag')), |
|
7066 | 7070 | # -l/--local is already there, commitopts cannot be used |
|
7067 | 7071 | (b'e', b'edit', None, _(b'invoke editor on commit messages')), |
|
7068 | 7072 | (b'm', b'message', b'', _(b'use text as commit message'), _(b'TEXT')), |
|
7069 | 7073 | ] |
|
7070 | 7074 | + commitopts2, |
|
7071 | 7075 | _(b'[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...'), |
|
7072 | 7076 | helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, |
|
7073 | 7077 | ) |
|
7074 | 7078 | def tag(ui, repo, name1, *names, **opts): |
|
7075 | 7079 | """add one or more tags for the current or given revision |
|
7076 | 7080 | |
|
7077 | 7081 | Name a particular revision using <name>. |
|
7078 | 7082 | |
|
7079 | 7083 | Tags are used to name particular revisions of the repository and are |
|
7080 | 7084 | very useful to compare different revisions, to go back to significant |
|
7081 | 7085 | earlier versions or to mark branch points as releases, etc. Changing |
|
7082 | 7086 | an existing tag is normally disallowed; use -f/--force to override. |
|
7083 | 7087 | |
|
7084 | 7088 | If no revision is given, the parent of the working directory is |
|
7085 | 7089 | used. |
|
7086 | 7090 | |
|
7087 | 7091 | To facilitate version control, distribution, and merging of tags, |
|
7088 | 7092 | they are stored as a file named ".hgtags" which is managed similarly |
|
7089 | 7093 | to other project files and can be hand-edited if necessary. This |
|
7090 | 7094 | also means that tagging creates a new commit. The file |
|
7091 | 7095 | ".hg/localtags" is used for local tags (not shared among |
|
7092 | 7096 | repositories). |
|
7093 | 7097 | |
|
7094 | 7098 | Tag commits are usually made at the head of a branch. If the parent |
|
7095 | 7099 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
7096 | 7100 | -f/--force to force the tag commit to be based on a non-head |
|
7097 | 7101 | changeset. |
|
7098 | 7102 | |
|
7099 | 7103 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
7100 | 7104 | |
|
7101 | 7105 | Since tag names have priority over branch names during revision |
|
7102 | 7106 | lookup, using an existing branch name as a tag name is discouraged. |
|
7103 | 7107 | |
|
7104 | 7108 | Returns 0 on success. |
|
7105 | 7109 | """ |
|
7106 | 7110 | cmdutil.check_incompatible_arguments(opts, 'remove', ['rev']) |
|
7107 | 7111 | opts = pycompat.byteskwargs(opts) |
|
7108 | 7112 | with repo.wlock(), repo.lock(): |
|
7109 | 7113 | rev_ = b"." |
|
7110 | 7114 | names = [t.strip() for t in (name1,) + names] |
|
7111 | 7115 | if len(names) != len(set(names)): |
|
7112 | 7116 | raise error.Abort(_(b'tag names must be unique')) |
|
7113 | 7117 | for n in names: |
|
7114 | 7118 | scmutil.checknewlabel(repo, n, b'tag') |
|
7115 | 7119 | if not n: |
|
7116 | 7120 | raise error.Abort( |
|
7117 | 7121 | _(b'tag names cannot consist entirely of whitespace') |
|
7118 | 7122 | ) |
|
7119 | 7123 | if opts.get(b'rev'): |
|
7120 | 7124 | rev_ = opts[b'rev'] |
|
7121 | 7125 | message = opts.get(b'message') |
|
7122 | 7126 | if opts.get(b'remove'): |
|
7123 | 7127 | if opts.get(b'local'): |
|
7124 | 7128 | expectedtype = b'local' |
|
7125 | 7129 | else: |
|
7126 | 7130 | expectedtype = b'global' |
|
7127 | 7131 | |
|
7128 | 7132 | for n in names: |
|
7129 | 7133 | if repo.tagtype(n) == b'global': |
|
7130 | 7134 | alltags = tagsmod.findglobaltags(ui, repo) |
|
7131 | 7135 | if alltags[n][0] == nullid: |
|
7132 | 7136 | raise error.Abort(_(b"tag '%s' is already removed") % n) |
|
7133 | 7137 | if not repo.tagtype(n): |
|
7134 | 7138 | raise error.Abort(_(b"tag '%s' does not exist") % n) |
|
7135 | 7139 | if repo.tagtype(n) != expectedtype: |
|
7136 | 7140 | if expectedtype == b'global': |
|
7137 | 7141 | raise error.Abort( |
|
7138 | 7142 | _(b"tag '%s' is not a global tag") % n |
|
7139 | 7143 | ) |
|
7140 | 7144 | else: |
|
7141 | 7145 | raise error.Abort(_(b"tag '%s' is not a local tag") % n) |
|
7142 | 7146 | rev_ = b'null' |
|
7143 | 7147 | if not message: |
|
7144 | 7148 | # we don't translate commit messages |
|
7145 | 7149 | message = b'Removed tag %s' % b', '.join(names) |
|
7146 | 7150 | elif not opts.get(b'force'): |
|
7147 | 7151 | for n in names: |
|
7148 | 7152 | if n in repo.tags(): |
|
7149 | 7153 | raise error.Abort( |
|
7150 | 7154 | _(b"tag '%s' already exists (use -f to force)") % n |
|
7151 | 7155 | ) |
|
7152 | 7156 | if not opts.get(b'local'): |
|
7153 | 7157 | p1, p2 = repo.dirstate.parents() |
|
7154 | 7158 | if p2 != nullid: |
|
7155 | 7159 | raise error.Abort(_(b'uncommitted merge')) |
|
7156 | 7160 | bheads = repo.branchheads() |
|
7157 | 7161 | if not opts.get(b'force') and bheads and p1 not in bheads: |
|
7158 | 7162 | raise error.Abort( |
|
7159 | 7163 | _( |
|
7160 | 7164 | b'working directory is not at a branch head ' |
|
7161 | 7165 | b'(use -f to force)' |
|
7162 | 7166 | ) |
|
7163 | 7167 | ) |
|
7164 | 7168 | node = scmutil.revsingle(repo, rev_).node() |
|
7165 | 7169 | |
|
7166 | 7170 | if not message: |
|
7167 | 7171 | # we don't translate commit messages |
|
7168 | 7172 | message = b'Added tag %s for changeset %s' % ( |
|
7169 | 7173 | b', '.join(names), |
|
7170 | 7174 | short(node), |
|
7171 | 7175 | ) |
|
7172 | 7176 | |
|
7173 | 7177 | date = opts.get(b'date') |
|
7174 | 7178 | if date: |
|
7175 | 7179 | date = dateutil.parsedate(date) |
|
7176 | 7180 | |
|
7177 | 7181 | if opts.get(b'remove'): |
|
7178 | 7182 | editform = b'tag.remove' |
|
7179 | 7183 | else: |
|
7180 | 7184 | editform = b'tag.add' |
|
7181 | 7185 | editor = cmdutil.getcommiteditor( |
|
7182 | 7186 | editform=editform, **pycompat.strkwargs(opts) |
|
7183 | 7187 | ) |
|
7184 | 7188 | |
|
7185 | 7189 | # don't allow tagging the null rev |
|
7186 | 7190 | if ( |
|
7187 | 7191 | not opts.get(b'remove') |
|
7188 | 7192 | and scmutil.revsingle(repo, rev_).rev() == nullrev |
|
7189 | 7193 | ): |
|
7190 | 7194 | raise error.Abort(_(b"cannot tag null revision")) |
|
7191 | 7195 | |
|
7192 | 7196 | tagsmod.tag( |
|
7193 | 7197 | repo, |
|
7194 | 7198 | names, |
|
7195 | 7199 | node, |
|
7196 | 7200 | message, |
|
7197 | 7201 | opts.get(b'local'), |
|
7198 | 7202 | opts.get(b'user'), |
|
7199 | 7203 | date, |
|
7200 | 7204 | editor=editor, |
|
7201 | 7205 | ) |
|
7202 | 7206 | |
|
7203 | 7207 | |
|
7204 | 7208 | @command( |
|
7205 | 7209 | b'tags', |
|
7206 | 7210 | formatteropts, |
|
7207 | 7211 | b'', |
|
7208 | 7212 | helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, |
|
7209 | 7213 | intents={INTENT_READONLY}, |
|
7210 | 7214 | ) |
|
7211 | 7215 | def tags(ui, repo, **opts): |
|
7212 | 7216 | """list repository tags |
|
7213 | 7217 | |
|
7214 | 7218 | This lists both regular and local tags. When the -v/--verbose |
|
7215 | 7219 | switch is used, a third column "local" is printed for local tags. |
|
7216 | 7220 | When the -q/--quiet switch is used, only the tag name is printed. |
|
7217 | 7221 | |
|
7218 | 7222 | .. container:: verbose |
|
7219 | 7223 | |
|
7220 | 7224 | Template: |
|
7221 | 7225 | |
|
7222 | 7226 | The following keywords are supported in addition to the common template |
|
7223 | 7227 | keywords and functions such as ``{tag}``. See also |
|
7224 | 7228 | :hg:`help templates`. |
|
7225 | 7229 | |
|
7226 | 7230 | :type: String. ``local`` for local tags. |
|
7227 | 7231 | |
|
7228 | 7232 | Returns 0 on success. |
|
7229 | 7233 | """ |
|
7230 | 7234 | |
|
7231 | 7235 | opts = pycompat.byteskwargs(opts) |
|
7232 | 7236 | ui.pager(b'tags') |
|
7233 | 7237 | fm = ui.formatter(b'tags', opts) |
|
7234 | 7238 | hexfunc = fm.hexfunc |
|
7235 | 7239 | |
|
7236 | 7240 | for t, n in reversed(repo.tagslist()): |
|
7237 | 7241 | hn = hexfunc(n) |
|
7238 | 7242 | label = b'tags.normal' |
|
7239 | 7243 | tagtype = b'' |
|
7240 | 7244 | if repo.tagtype(t) == b'local': |
|
7241 | 7245 | label = b'tags.local' |
|
7242 | 7246 | tagtype = b'local' |
|
7243 | 7247 | |
|
7244 | 7248 | fm.startitem() |
|
7245 | 7249 | fm.context(repo=repo) |
|
7246 | 7250 | fm.write(b'tag', b'%s', t, label=label) |
|
7247 | 7251 | fmt = b" " * (30 - encoding.colwidth(t)) + b' %5d:%s' |
|
7248 | 7252 | fm.condwrite( |
|
7249 | 7253 | not ui.quiet, |
|
7250 | 7254 | b'rev node', |
|
7251 | 7255 | fmt, |
|
7252 | 7256 | repo.changelog.rev(n), |
|
7253 | 7257 | hn, |
|
7254 | 7258 | label=label, |
|
7255 | 7259 | ) |
|
7256 | 7260 | fm.condwrite( |
|
7257 | 7261 | ui.verbose and tagtype, b'type', b' %s', tagtype, label=label |
|
7258 | 7262 | ) |
|
7259 | 7263 | fm.plain(b'\n') |
|
7260 | 7264 | fm.end() |
|
7261 | 7265 | |
|
7262 | 7266 | |
|
7263 | 7267 | @command( |
|
7264 | 7268 | b'tip', |
|
7265 | 7269 | [ |
|
7266 | 7270 | (b'p', b'patch', None, _(b'show patch')), |
|
7267 | 7271 | (b'g', b'git', None, _(b'use git extended diff format')), |
|
7268 | 7272 | ] |
|
7269 | 7273 | + templateopts, |
|
7270 | 7274 | _(b'[-p] [-g]'), |
|
7271 | 7275 | helpcategory=command.CATEGORY_CHANGE_NAVIGATION, |
|
7272 | 7276 | ) |
|
7273 | 7277 | def tip(ui, repo, **opts): |
|
7274 | 7278 | """show the tip revision (DEPRECATED) |
|
7275 | 7279 | |
|
7276 | 7280 | The tip revision (usually just called the tip) is the changeset |
|
7277 | 7281 | most recently added to the repository (and therefore the most |
|
7278 | 7282 | recently changed head). |
|
7279 | 7283 | |
|
7280 | 7284 | If you have just made a commit, that commit will be the tip. If |
|
7281 | 7285 | you have just pulled changes from another repository, the tip of |
|
7282 | 7286 | that repository becomes the current tip. The "tip" tag is special |
|
7283 | 7287 | and cannot be renamed or assigned to a different changeset. |
|
7284 | 7288 | |
|
7285 | 7289 | This command is deprecated, please use :hg:`heads` instead. |
|
7286 | 7290 | |
|
7287 | 7291 | Returns 0 on success. |
|
7288 | 7292 | """ |
|
7289 | 7293 | opts = pycompat.byteskwargs(opts) |
|
7290 | 7294 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
7291 | 7295 | displayer.show(repo[b'tip']) |
|
7292 | 7296 | displayer.close() |
|
7293 | 7297 | |
|
7294 | 7298 | |
|
7295 | 7299 | @command( |
|
7296 | 7300 | b'unbundle', |
|
7297 | 7301 | [ |
|
7298 | 7302 | ( |
|
7299 | 7303 | b'u', |
|
7300 | 7304 | b'update', |
|
7301 | 7305 | None, |
|
7302 | 7306 | _(b'update to new branch head if changesets were unbundled'), |
|
7303 | 7307 | ) |
|
7304 | 7308 | ], |
|
7305 | 7309 | _(b'[-u] FILE...'), |
|
7306 | 7310 | helpcategory=command.CATEGORY_IMPORT_EXPORT, |
|
7307 | 7311 | ) |
|
7308 | 7312 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
7309 | 7313 | """apply one or more bundle files |
|
7310 | 7314 | |
|
7311 | 7315 | Apply one or more bundle files generated by :hg:`bundle`. |
|
7312 | 7316 | |
|
7313 | 7317 | Returns 0 on success, 1 if an update has unresolved files. |
|
7314 | 7318 | """ |
|
7315 | 7319 | fnames = (fname1,) + fnames |
|
7316 | 7320 | |
|
7317 | 7321 | with repo.lock(): |
|
7318 | 7322 | for fname in fnames: |
|
7319 | 7323 | f = hg.openpath(ui, fname) |
|
7320 | 7324 | gen = exchange.readbundle(ui, f, fname) |
|
7321 | 7325 | if isinstance(gen, streamclone.streamcloneapplier): |
|
7322 | 7326 | raise error.Abort( |
|
7323 | 7327 | _( |
|
7324 | 7328 | b'packed bundles cannot be applied with ' |
|
7325 | 7329 | b'"hg unbundle"' |
|
7326 | 7330 | ), |
|
7327 | 7331 | hint=_(b'use "hg debugapplystreamclonebundle"'), |
|
7328 | 7332 | ) |
|
7329 | 7333 | url = b'bundle:' + fname |
|
7330 | 7334 | try: |
|
7331 | 7335 | txnname = b'unbundle' |
|
7332 | 7336 | if not isinstance(gen, bundle2.unbundle20): |
|
7333 | 7337 | txnname = b'unbundle\n%s' % util.hidepassword(url) |
|
7334 | 7338 | with repo.transaction(txnname) as tr: |
|
7335 | 7339 | op = bundle2.applybundle( |
|
7336 | 7340 | repo, gen, tr, source=b'unbundle', url=url |
|
7337 | 7341 | ) |
|
7338 | 7342 | except error.BundleUnknownFeatureError as exc: |
|
7339 | 7343 | raise error.Abort( |
|
7340 | 7344 | _(b'%s: unknown bundle feature, %s') % (fname, exc), |
|
7341 | 7345 | hint=_( |
|
7342 | 7346 | b"see https://mercurial-scm.org/" |
|
7343 | 7347 | b"wiki/BundleFeature for more " |
|
7344 | 7348 | b"information" |
|
7345 | 7349 | ), |
|
7346 | 7350 | ) |
|
7347 | 7351 | modheads = bundle2.combinechangegroupresults(op) |
|
7348 | 7352 | |
|
7349 | 7353 | return postincoming(ui, repo, modheads, opts.get('update'), None, None) |
|
7350 | 7354 | |
|
7351 | 7355 | |
|
7352 | 7356 | @command( |
|
7353 | 7357 | b'unshelve', |
|
7354 | 7358 | [ |
|
7355 | 7359 | (b'a', b'abort', None, _(b'abort an incomplete unshelve operation')), |
|
7356 | 7360 | ( |
|
7357 | 7361 | b'c', |
|
7358 | 7362 | b'continue', |
|
7359 | 7363 | None, |
|
7360 | 7364 | _(b'continue an incomplete unshelve operation'), |
|
7361 | 7365 | ), |
|
7362 | 7366 | (b'i', b'interactive', None, _(b'use interactive mode (EXPERIMENTAL)')), |
|
7363 | 7367 | (b'k', b'keep', None, _(b'keep shelve after unshelving')), |
|
7364 | 7368 | ( |
|
7365 | 7369 | b'n', |
|
7366 | 7370 | b'name', |
|
7367 | 7371 | b'', |
|
7368 | 7372 | _(b'restore shelved change with given name'), |
|
7369 | 7373 | _(b'NAME'), |
|
7370 | 7374 | ), |
|
7371 | 7375 | (b't', b'tool', b'', _(b'specify merge tool')), |
|
7372 | 7376 | ( |
|
7373 | 7377 | b'', |
|
7374 | 7378 | b'date', |
|
7375 | 7379 | b'', |
|
7376 | 7380 | _(b'set date for temporary commits (DEPRECATED)'), |
|
7377 | 7381 | _(b'DATE'), |
|
7378 | 7382 | ), |
|
7379 | 7383 | ], |
|
7380 | 7384 | _(b'hg unshelve [OPTION]... [[-n] SHELVED]'), |
|
7381 | 7385 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
7382 | 7386 | ) |
|
7383 | 7387 | def unshelve(ui, repo, *shelved, **opts): |
|
7384 | 7388 | """restore a shelved change to the working directory |
|
7385 | 7389 | |
|
7386 | 7390 | This command accepts an optional name of a shelved change to |
|
7387 | 7391 | restore. If none is given, the most recent shelved change is used. |
|
7388 | 7392 | |
|
7389 | 7393 | If a shelved change is applied successfully, the bundle that |
|
7390 | 7394 | contains the shelved changes is moved to a backup location |
|
7391 | 7395 | (.hg/shelve-backup). |
|
7392 | 7396 | |
|
7393 | 7397 | Since you can restore a shelved change on top of an arbitrary |
|
7394 | 7398 | commit, it is possible that unshelving will result in a conflict |
|
7395 | 7399 | between your changes and the commits you are unshelving onto. If |
|
7396 | 7400 | this occurs, you must resolve the conflict, then use |
|
7397 | 7401 | ``--continue`` to complete the unshelve operation. (The bundle |
|
7398 | 7402 | will not be moved until you successfully complete the unshelve.) |
|
7399 | 7403 | |
|
7400 | 7404 | (Alternatively, you can use ``--abort`` to abandon an unshelve |
|
7401 | 7405 | that causes a conflict. This reverts the unshelved changes, and |
|
7402 | 7406 | leaves the bundle in place.) |
|
7403 | 7407 | |
|
7404 | 7408 | If bare shelved change (without interactive, include and exclude |
|
7405 | 7409 | option) was done on newly created branch it would restore branch |
|
7406 | 7410 | information to the working directory. |
|
7407 | 7411 | |
|
7408 | 7412 | After a successful unshelve, the shelved changes are stored in a |
|
7409 | 7413 | backup directory. Only the N most recent backups are kept. N |
|
7410 | 7414 | defaults to 10 but can be overridden using the ``shelve.maxbackups`` |
|
7411 | 7415 | configuration option. |
|
7412 | 7416 | |
|
7413 | 7417 | .. container:: verbose |
|
7414 | 7418 | |
|
7415 | 7419 | Timestamp in seconds is used to decide order of backups. More |
|
7416 | 7420 | than ``maxbackups`` backups are kept, if same timestamp |
|
7417 | 7421 | prevents from deciding exact order of them, for safety. |
|
7418 | 7422 | |
|
7419 | 7423 | Selected changes can be unshelved with ``--interactive`` flag. |
|
7420 | 7424 | The working directory is updated with the selected changes, and |
|
7421 | 7425 | only the unselected changes remain shelved. |
|
7422 | 7426 | Note: The whole shelve is applied to working directory first before |
|
7423 | 7427 | running interactively. So, this will bring up all the conflicts between |
|
7424 | 7428 | working directory and the shelve, irrespective of which changes will be |
|
7425 | 7429 | unshelved. |
|
7426 | 7430 | """ |
|
7427 | 7431 | with repo.wlock(): |
|
7428 | 7432 | return shelvemod.unshelvecmd(ui, repo, *shelved, **opts) |
|
7429 | 7433 | |
|
7430 | 7434 | |
|
7431 | 7435 | statemod.addunfinished( |
|
7432 | 7436 | b'unshelve', |
|
7433 | 7437 | fname=b'shelvedstate', |
|
7434 | 7438 | continueflag=True, |
|
7435 | 7439 | abortfunc=shelvemod.hgabortunshelve, |
|
7436 | 7440 | continuefunc=shelvemod.hgcontinueunshelve, |
|
7437 | 7441 | cmdmsg=_(b'unshelve already in progress'), |
|
7438 | 7442 | ) |
|
7439 | 7443 | |
|
7440 | 7444 | |
|
7441 | 7445 | @command( |
|
7442 | 7446 | b'update|up|checkout|co', |
|
7443 | 7447 | [ |
|
7444 | 7448 | (b'C', b'clean', None, _(b'discard uncommitted changes (no backup)')), |
|
7445 | 7449 | (b'c', b'check', None, _(b'require clean working directory')), |
|
7446 | 7450 | (b'm', b'merge', None, _(b'merge uncommitted changes')), |
|
7447 | 7451 | (b'd', b'date', b'', _(b'tipmost revision matching date'), _(b'DATE')), |
|
7448 | 7452 | (b'r', b'rev', b'', _(b'revision'), _(b'REV')), |
|
7449 | 7453 | ] |
|
7450 | 7454 | + mergetoolopts, |
|
7451 | 7455 | _(b'[-C|-c|-m] [-d DATE] [[-r] REV]'), |
|
7452 | 7456 | helpcategory=command.CATEGORY_WORKING_DIRECTORY, |
|
7453 | 7457 | helpbasic=True, |
|
7454 | 7458 | ) |
|
7455 | 7459 | def update(ui, repo, node=None, **opts): |
|
7456 | 7460 | """update working directory (or switch revisions) |
|
7457 | 7461 | |
|
7458 | 7462 | Update the repository's working directory to the specified |
|
7459 | 7463 | changeset. If no changeset is specified, update to the tip of the |
|
7460 | 7464 | current named branch and move the active bookmark (see :hg:`help |
|
7461 | 7465 | bookmarks`). |
|
7462 | 7466 | |
|
7463 | 7467 | Update sets the working directory's parent revision to the specified |
|
7464 | 7468 | changeset (see :hg:`help parents`). |
|
7465 | 7469 | |
|
7466 | 7470 | If the changeset is not a descendant or ancestor of the working |
|
7467 | 7471 | directory's parent and there are uncommitted changes, the update is |
|
7468 | 7472 | aborted. With the -c/--check option, the working directory is checked |
|
7469 | 7473 | for uncommitted changes; if none are found, the working directory is |
|
7470 | 7474 | updated to the specified changeset. |
|
7471 | 7475 | |
|
7472 | 7476 | .. container:: verbose |
|
7473 | 7477 | |
|
7474 | 7478 | The -C/--clean, -c/--check, and -m/--merge options control what |
|
7475 | 7479 | happens if the working directory contains uncommitted changes. |
|
7476 | 7480 | At most of one of them can be specified. |
|
7477 | 7481 | |
|
7478 | 7482 | 1. If no option is specified, and if |
|
7479 | 7483 | the requested changeset is an ancestor or descendant of |
|
7480 | 7484 | the working directory's parent, the uncommitted changes |
|
7481 | 7485 | are merged into the requested changeset and the merged |
|
7482 | 7486 | result is left uncommitted. If the requested changeset is |
|
7483 | 7487 | not an ancestor or descendant (that is, it is on another |
|
7484 | 7488 | branch), the update is aborted and the uncommitted changes |
|
7485 | 7489 | are preserved. |
|
7486 | 7490 | |
|
7487 | 7491 | 2. With the -m/--merge option, the update is allowed even if the |
|
7488 | 7492 | requested changeset is not an ancestor or descendant of |
|
7489 | 7493 | the working directory's parent. |
|
7490 | 7494 | |
|
7491 | 7495 | 3. With the -c/--check option, the update is aborted and the |
|
7492 | 7496 | uncommitted changes are preserved. |
|
7493 | 7497 | |
|
7494 | 7498 | 4. With the -C/--clean option, uncommitted changes are discarded and |
|
7495 | 7499 | the working directory is updated to the requested changeset. |
|
7496 | 7500 | |
|
7497 | 7501 | To cancel an uncommitted merge (and lose your changes), use |
|
7498 | 7502 | :hg:`merge --abort`. |
|
7499 | 7503 | |
|
7500 | 7504 | Use null as the changeset to remove the working directory (like |
|
7501 | 7505 | :hg:`clone -U`). |
|
7502 | 7506 | |
|
7503 | 7507 | If you want to revert just one file to an older revision, use |
|
7504 | 7508 | :hg:`revert [-r REV] NAME`. |
|
7505 | 7509 | |
|
7506 | 7510 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
7507 | 7511 | |
|
7508 | 7512 | Returns 0 on success, 1 if there are unresolved files. |
|
7509 | 7513 | """ |
|
7510 | 7514 | cmdutil.check_at_most_one_arg(opts, 'clean', 'check', 'merge') |
|
7511 | 7515 | rev = opts.get('rev') |
|
7512 | 7516 | date = opts.get('date') |
|
7513 | 7517 | clean = opts.get('clean') |
|
7514 | 7518 | check = opts.get('check') |
|
7515 | 7519 | merge = opts.get('merge') |
|
7516 | 7520 | if rev and node: |
|
7517 | 7521 | raise error.Abort(_(b"please specify just one revision")) |
|
7518 | 7522 | |
|
7519 | 7523 | if ui.configbool(b'commands', b'update.requiredest'): |
|
7520 | 7524 | if not node and not rev and not date: |
|
7521 | 7525 | raise error.Abort( |
|
7522 | 7526 | _(b'you must specify a destination'), |
|
7523 | 7527 | hint=_(b'for example: hg update ".::"'), |
|
7524 | 7528 | ) |
|
7525 | 7529 | |
|
7526 | 7530 | if rev is None or rev == b'': |
|
7527 | 7531 | rev = node |
|
7528 | 7532 | |
|
7529 | 7533 | if date and rev is not None: |
|
7530 | 7534 | raise error.Abort(_(b"you can't specify a revision and a date")) |
|
7531 | 7535 | |
|
7532 | 7536 | updatecheck = None |
|
7533 | 7537 | if check: |
|
7534 | 7538 | updatecheck = b'abort' |
|
7535 | 7539 | elif merge: |
|
7536 | 7540 | updatecheck = b'none' |
|
7537 | 7541 | |
|
7538 | 7542 | with repo.wlock(): |
|
7539 | 7543 | cmdutil.clearunfinished(repo) |
|
7540 | 7544 | if date: |
|
7541 | 7545 | rev = cmdutil.finddate(ui, repo, date) |
|
7542 | 7546 | |
|
7543 | 7547 | # if we defined a bookmark, we have to remember the original name |
|
7544 | 7548 | brev = rev |
|
7545 | 7549 | if rev: |
|
7546 | 7550 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
7547 | 7551 | ctx = scmutil.revsingle(repo, rev, default=None) |
|
7548 | 7552 | rev = ctx.rev() |
|
7549 | 7553 | hidden = ctx.hidden() |
|
7550 | 7554 | overrides = {(b'ui', b'forcemerge'): opts.get('tool', b'')} |
|
7551 | 7555 | with ui.configoverride(overrides, b'update'): |
|
7552 | 7556 | ret = hg.updatetotally( |
|
7553 | 7557 | ui, repo, rev, brev, clean=clean, updatecheck=updatecheck |
|
7554 | 7558 | ) |
|
7555 | 7559 | if hidden: |
|
7556 | 7560 | ctxstr = ctx.hex()[:12] |
|
7557 | 7561 | ui.warn(_(b"updated to hidden changeset %s\n") % ctxstr) |
|
7558 | 7562 | |
|
7559 | 7563 | if ctx.obsolete(): |
|
7560 | 7564 | obsfatemsg = obsutil._getfilteredreason(repo, ctxstr, ctx) |
|
7561 | 7565 | ui.warn(b"(%s)\n" % obsfatemsg) |
|
7562 | 7566 | return ret |
|
7563 | 7567 | |
|
7564 | 7568 | |
|
7565 | 7569 | @command( |
|
7566 | 7570 | b'verify', |
|
7567 | 7571 | [(b'', b'full', False, b'perform more checks (EXPERIMENTAL)')], |
|
7568 | 7572 | helpcategory=command.CATEGORY_MAINTENANCE, |
|
7569 | 7573 | ) |
|
7570 | 7574 | def verify(ui, repo, **opts): |
|
7571 | 7575 | """verify the integrity of the repository |
|
7572 | 7576 | |
|
7573 | 7577 | Verify the integrity of the current repository. |
|
7574 | 7578 | |
|
7575 | 7579 | This will perform an extensive check of the repository's |
|
7576 | 7580 | integrity, validating the hashes and checksums of each entry in |
|
7577 | 7581 | the changelog, manifest, and tracked files, as well as the |
|
7578 | 7582 | integrity of their crosslinks and indices. |
|
7579 | 7583 | |
|
7580 | 7584 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption |
|
7581 | 7585 | for more information about recovery from corruption of the |
|
7582 | 7586 | repository. |
|
7583 | 7587 | |
|
7584 | 7588 | Returns 0 on success, 1 if errors are encountered. |
|
7585 | 7589 | """ |
|
7586 | 7590 | opts = pycompat.byteskwargs(opts) |
|
7587 | 7591 | |
|
7588 | 7592 | level = None |
|
7589 | 7593 | if opts[b'full']: |
|
7590 | 7594 | level = verifymod.VERIFY_FULL |
|
7591 | 7595 | return hg.verify(repo, level) |
|
7592 | 7596 | |
|
7593 | 7597 | |
|
7594 | 7598 | @command( |
|
7595 | 7599 | b'version', |
|
7596 | 7600 | [] + formatteropts, |
|
7597 | 7601 | helpcategory=command.CATEGORY_HELP, |
|
7598 | 7602 | norepo=True, |
|
7599 | 7603 | intents={INTENT_READONLY}, |
|
7600 | 7604 | ) |
|
7601 | 7605 | def version_(ui, **opts): |
|
7602 | 7606 | """output version and copyright information |
|
7603 | 7607 | |
|
7604 | 7608 | .. container:: verbose |
|
7605 | 7609 | |
|
7606 | 7610 | Template: |
|
7607 | 7611 | |
|
7608 | 7612 | The following keywords are supported. See also :hg:`help templates`. |
|
7609 | 7613 | |
|
7610 | 7614 | :extensions: List of extensions. |
|
7611 | 7615 | :ver: String. Version number. |
|
7612 | 7616 | |
|
7613 | 7617 | And each entry of ``{extensions}`` provides the following sub-keywords |
|
7614 | 7618 | in addition to ``{ver}``. |
|
7615 | 7619 | |
|
7616 | 7620 | :bundled: Boolean. True if included in the release. |
|
7617 | 7621 | :name: String. Extension name. |
|
7618 | 7622 | """ |
|
7619 | 7623 | opts = pycompat.byteskwargs(opts) |
|
7620 | 7624 | if ui.verbose: |
|
7621 | 7625 | ui.pager(b'version') |
|
7622 | 7626 | fm = ui.formatter(b"version", opts) |
|
7623 | 7627 | fm.startitem() |
|
7624 | 7628 | fm.write( |
|
7625 | 7629 | b"ver", _(b"Mercurial Distributed SCM (version %s)\n"), util.version() |
|
7626 | 7630 | ) |
|
7627 | 7631 | license = _( |
|
7628 | 7632 | b"(see https://mercurial-scm.org for more information)\n" |
|
7629 | 7633 | b"\nCopyright (C) 2005-2020 Matt Mackall and others\n" |
|
7630 | 7634 | b"This is free software; see the source for copying conditions. " |
|
7631 | 7635 | b"There is NO\nwarranty; " |
|
7632 | 7636 | b"not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
7633 | 7637 | ) |
|
7634 | 7638 | if not ui.quiet: |
|
7635 | 7639 | fm.plain(license) |
|
7636 | 7640 | |
|
7637 | 7641 | if ui.verbose: |
|
7638 | 7642 | fm.plain(_(b"\nEnabled extensions:\n\n")) |
|
7639 | 7643 | # format names and versions into columns |
|
7640 | 7644 | names = [] |
|
7641 | 7645 | vers = [] |
|
7642 | 7646 | isinternals = [] |
|
7643 | 7647 | for name, module in sorted(extensions.extensions()): |
|
7644 | 7648 | names.append(name) |
|
7645 | 7649 | vers.append(extensions.moduleversion(module) or None) |
|
7646 | 7650 | isinternals.append(extensions.ismoduleinternal(module)) |
|
7647 | 7651 | fn = fm.nested(b"extensions", tmpl=b'{name}\n') |
|
7648 | 7652 | if names: |
|
7649 | 7653 | namefmt = b" %%-%ds " % max(len(n) for n in names) |
|
7650 | 7654 | places = [_(b"external"), _(b"internal")] |
|
7651 | 7655 | for n, v, p in zip(names, vers, isinternals): |
|
7652 | 7656 | fn.startitem() |
|
7653 | 7657 | fn.condwrite(ui.verbose, b"name", namefmt, n) |
|
7654 | 7658 | if ui.verbose: |
|
7655 | 7659 | fn.plain(b"%s " % places[p]) |
|
7656 | 7660 | fn.data(bundled=p) |
|
7657 | 7661 | fn.condwrite(ui.verbose and v, b"ver", b"%s", v) |
|
7658 | 7662 | if ui.verbose: |
|
7659 | 7663 | fn.plain(b"\n") |
|
7660 | 7664 | fn.end() |
|
7661 | 7665 | fm.end() |
|
7662 | 7666 | |
|
7663 | 7667 | |
|
7664 | 7668 | def loadcmdtable(ui, name, cmdtable): |
|
7665 | 7669 | """Load command functions from specified cmdtable |
|
7666 | 7670 | """ |
|
7667 | 7671 | overrides = [cmd for cmd in cmdtable if cmd in table] |
|
7668 | 7672 | if overrides: |
|
7669 | 7673 | ui.warn( |
|
7670 | 7674 | _(b"extension '%s' overrides commands: %s\n") |
|
7671 | 7675 | % (name, b" ".join(overrides)) |
|
7672 | 7676 | ) |
|
7673 | 7677 | table.update(cmdtable) |
@@ -1,823 +1,823 b'' | |||
|
1 | 1 | $ hg init basic |
|
2 | 2 | $ cd basic |
|
3 | 3 | |
|
4 | 4 | should complain |
|
5 | 5 | |
|
6 | 6 | $ hg backout |
|
7 | 7 | abort: please specify a revision to backout |
|
8 | 8 | [255] |
|
9 | 9 | $ hg backout -r 0 0 |
|
10 | 10 | abort: please specify just one revision |
|
11 | 11 | [255] |
|
12 | 12 | |
|
13 | 13 | basic operation |
|
14 | 14 | (this also tests that editor is invoked if the commit message is not |
|
15 | 15 | specified explicitly) |
|
16 | 16 | |
|
17 | 17 | $ echo a > a |
|
18 | 18 | $ hg commit -d '0 0' -A -m a |
|
19 | 19 | adding a |
|
20 | 20 | $ echo b >> a |
|
21 | 21 | $ hg commit -d '1 0' -m b |
|
22 | 22 | |
|
23 | 23 | $ hg status --rev tip --rev "tip^1" |
|
24 | 24 | M a |
|
25 | 25 | $ HGEDITOR=cat hg backout -d '2 0' tip --tool=true |
|
26 | 26 | reverting a |
|
27 | 27 | Backed out changeset a820f4f40a57 |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | HG: Enter commit message. Lines beginning with 'HG:' are removed. |
|
31 | 31 | HG: Leave message empty to abort commit. |
|
32 | 32 | HG: -- |
|
33 | 33 | HG: user: test |
|
34 | 34 | HG: branch 'default' |
|
35 | 35 | HG: changed a |
|
36 | 36 | changeset 2:2929462c3dff backs out changeset 1:a820f4f40a57 |
|
37 | 37 | $ cat a |
|
38 | 38 | a |
|
39 | 39 | $ hg summary |
|
40 | 40 | parent: 2:2929462c3dff tip |
|
41 | 41 | Backed out changeset a820f4f40a57 |
|
42 | 42 | branch: default |
|
43 | 43 | commit: (clean) |
|
44 | 44 | update: (current) |
|
45 | 45 | phases: 3 draft |
|
46 | 46 | |
|
47 | 47 | commit option |
|
48 | 48 | |
|
49 | 49 | $ cd .. |
|
50 | 50 | $ hg init commit |
|
51 | 51 | $ cd commit |
|
52 | 52 | |
|
53 | 53 | $ echo tomatoes > a |
|
54 | 54 | $ hg add a |
|
55 | 55 | $ hg commit -d '0 0' -m tomatoes |
|
56 | 56 | |
|
57 | 57 | $ echo chair > b |
|
58 | 58 | $ hg add b |
|
59 | 59 | $ hg commit -d '1 0' -m chair |
|
60 | 60 | |
|
61 | 61 | $ echo grapes >> a |
|
62 | 62 | $ hg commit -d '2 0' -m grapes |
|
63 | 63 | |
|
64 | 64 | $ hg backout -d '4 0' 1 --tool=:fail |
|
65 | 65 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
66 | 66 | changeset 3:1c2161e97c0a backs out changeset 1:22cb4f70d813 |
|
67 | 67 | $ hg summary |
|
68 | 68 | parent: 3:1c2161e97c0a tip |
|
69 | 69 | Backed out changeset 22cb4f70d813 |
|
70 | 70 | branch: default |
|
71 | 71 | commit: (clean) |
|
72 | 72 | update: (current) |
|
73 | 73 | phases: 4 draft |
|
74 | 74 | |
|
75 | 75 | $ echo ypples > a |
|
76 | 76 | $ hg commit -d '5 0' -m ypples |
|
77 | 77 | |
|
78 | 78 | $ hg backout -d '6 0' 2 --tool=:fail |
|
79 | 79 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
80 | 80 | use 'hg resolve' to retry unresolved file merges |
|
81 | 81 | [1] |
|
82 | 82 | $ hg summary |
|
83 | 83 | parent: 4:ed99997b793d tip |
|
84 | 84 | ypples |
|
85 | 85 | branch: default |
|
86 | 86 | commit: 1 unresolved (clean) |
|
87 | 87 | update: (current) |
|
88 | 88 | phases: 5 draft |
|
89 | 89 | $ hg log -G |
|
90 | 90 | @ changeset: 4:ed99997b793d |
|
91 | 91 | | tag: tip |
|
92 | 92 | | user: test |
|
93 | 93 | | date: Thu Jan 01 00:00:05 1970 +0000 |
|
94 | 94 | | summary: ypples |
|
95 | 95 | | |
|
96 | 96 | o changeset: 3:1c2161e97c0a |
|
97 | 97 | | user: test |
|
98 | 98 | | date: Thu Jan 01 00:00:04 1970 +0000 |
|
99 | 99 | | summary: Backed out changeset 22cb4f70d813 |
|
100 | 100 | | |
|
101 | 101 | o changeset: 2:a8c6e511cfee |
|
102 | 102 | | user: test |
|
103 | 103 | | date: Thu Jan 01 00:00:02 1970 +0000 |
|
104 | 104 | | summary: grapes |
|
105 | 105 | | |
|
106 | 106 | % changeset: 1:22cb4f70d813 |
|
107 | 107 | | user: test |
|
108 | 108 | | date: Thu Jan 01 00:00:01 1970 +0000 |
|
109 | 109 | | summary: chair |
|
110 | 110 | | |
|
111 | 111 | o changeset: 0:a5cb2dde5805 |
|
112 | 112 | user: test |
|
113 | 113 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
114 | 114 | summary: tomatoes |
|
115 | 115 | |
|
116 | 116 | |
|
117 | 117 | file that was removed is recreated |
|
118 | 118 | (this also tests that editor is not invoked if the commit message is |
|
119 | 119 | specified explicitly) |
|
120 | 120 | |
|
121 | 121 | $ cd .. |
|
122 | 122 | $ hg init remove |
|
123 | 123 | $ cd remove |
|
124 | 124 | |
|
125 | 125 | $ echo content > a |
|
126 | 126 | $ hg commit -d '0 0' -A -m a |
|
127 | 127 | adding a |
|
128 | 128 | |
|
129 | 129 | $ hg rm a |
|
130 | 130 | $ hg commit -d '1 0' -m b |
|
131 | 131 | |
|
132 | 132 | $ HGEDITOR=cat hg backout -d '2 0' tip --tool=true -m "Backed out changeset 76862dcce372" |
|
133 | 133 | adding a |
|
134 | 134 | changeset 2:de31bdc76c0d backs out changeset 1:76862dcce372 |
|
135 | 135 | $ cat a |
|
136 | 136 | content |
|
137 | 137 | $ hg summary |
|
138 | 138 | parent: 2:de31bdc76c0d tip |
|
139 | 139 | Backed out changeset 76862dcce372 |
|
140 | 140 | branch: default |
|
141 | 141 | commit: (clean) |
|
142 | 142 | update: (current) |
|
143 | 143 | phases: 3 draft |
|
144 | 144 | |
|
145 | 145 | backout of backout is as if nothing happened |
|
146 | 146 | |
|
147 | 147 | $ hg backout -d '3 0' --merge tip --tool=true |
|
148 | 148 | removing a |
|
149 | 149 | changeset 3:7f6d0f120113 backs out changeset 2:de31bdc76c0d |
|
150 | 150 | $ test -f a |
|
151 | 151 | [1] |
|
152 | 152 | $ hg summary |
|
153 | 153 | parent: 3:7f6d0f120113 tip |
|
154 | 154 | Backed out changeset de31bdc76c0d |
|
155 | 155 | branch: default |
|
156 | 156 | commit: (clean) |
|
157 | 157 | update: (current) |
|
158 | 158 | phases: 4 draft |
|
159 | 159 | |
|
160 | 160 | Test that 'hg rollback' restores dirstate just before opening |
|
161 | 161 | transaction: in-memory dirstate changes should be written into |
|
162 | 162 | '.hg/journal.dirstate' as expected. |
|
163 | 163 | |
|
164 | 164 | $ echo 'removed soon' > b |
|
165 | 165 | $ hg commit -A -d '4 0' -m 'prepare for subsequent removing' |
|
166 | 166 | adding b |
|
167 | 167 | $ echo 'newly added' > c |
|
168 | 168 | $ hg add c |
|
169 | 169 | $ hg remove b |
|
170 | 170 | $ hg commit -d '5 0' -m 'prepare for subsequent backout' |
|
171 | 171 | $ touch -t 200001010000 c |
|
172 | 172 | $ hg status -A |
|
173 | 173 | C c |
|
174 | 174 | $ hg debugstate --no-dates |
|
175 | 175 | n 644 12 set c |
|
176 | 176 | $ hg backout -d '6 0' -m 'to be rollback-ed soon' -r . |
|
177 | 177 | removing c |
|
178 | 178 | adding b |
|
179 | 179 | changeset 6:4bfec048029d backs out changeset 5:fac0b729a654 |
|
180 | 180 | $ hg rollback -q |
|
181 | 181 | $ hg status -A |
|
182 | 182 | A b |
|
183 | 183 | R c |
|
184 | 184 | $ hg debugstate --no-dates |
|
185 | 185 | a 0 -1 unset b |
|
186 | 186 | r 0 0 set c |
|
187 | 187 | |
|
188 | 188 | across branch |
|
189 | 189 | |
|
190 | 190 | $ cd .. |
|
191 | 191 | $ hg init branch |
|
192 | 192 | $ cd branch |
|
193 | 193 | $ echo a > a |
|
194 | 194 | $ hg ci -Am0 |
|
195 | 195 | adding a |
|
196 | 196 | $ echo b > b |
|
197 | 197 | $ hg ci -Am1 |
|
198 | 198 | adding b |
|
199 | 199 | $ hg co -C 0 |
|
200 | 200 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
201 | 201 | $ hg summary |
|
202 | 202 | parent: 0:f7b1eb17ad24 |
|
203 | 203 | 0 |
|
204 | 204 | branch: default |
|
205 | 205 | commit: (clean) |
|
206 | 206 | update: 1 new changesets (update) |
|
207 | 207 | phases: 2 draft |
|
208 | 208 | |
|
209 | 209 | should fail |
|
210 | 210 | |
|
211 | 211 | $ hg backout 1 |
|
212 | 212 | abort: cannot backout change that is not an ancestor |
|
213 | 213 | [255] |
|
214 | 214 | $ echo c > c |
|
215 | 215 | $ hg ci -Am2 |
|
216 | 216 | adding c |
|
217 | 217 | created new head |
|
218 | 218 | $ hg summary |
|
219 | 219 | parent: 2:db815d6d32e6 tip |
|
220 | 220 | 2 |
|
221 | 221 | branch: default |
|
222 | 222 | commit: (clean) |
|
223 | 223 | update: 1 new changesets, 2 branch heads (merge) |
|
224 | 224 | phases: 3 draft |
|
225 | 225 | |
|
226 | 226 | should fail |
|
227 | 227 | |
|
228 | 228 | $ hg backout 1 |
|
229 | 229 | abort: cannot backout change that is not an ancestor |
|
230 | 230 | [255] |
|
231 | 231 | $ hg summary |
|
232 | 232 | parent: 2:db815d6d32e6 tip |
|
233 | 233 | 2 |
|
234 | 234 | branch: default |
|
235 | 235 | commit: (clean) |
|
236 | 236 | update: 1 new changesets, 2 branch heads (merge) |
|
237 | 237 | phases: 3 draft |
|
238 | 238 | |
|
239 | 239 | backout with merge |
|
240 | 240 | |
|
241 | 241 | $ cd .. |
|
242 | 242 | $ hg init merge |
|
243 | 243 | $ cd merge |
|
244 | 244 | |
|
245 | 245 | $ echo line 1 > a |
|
246 | 246 | $ echo line 2 >> a |
|
247 | 247 | $ hg commit -d '0 0' -A -m a |
|
248 | 248 | adding a |
|
249 | 249 | $ hg summary |
|
250 | 250 | parent: 0:59395513a13a tip |
|
251 | 251 | a |
|
252 | 252 | branch: default |
|
253 | 253 | commit: (clean) |
|
254 | 254 | update: (current) |
|
255 | 255 | phases: 1 draft |
|
256 | 256 | |
|
257 | 257 | remove line 1 |
|
258 | 258 | |
|
259 | 259 | $ echo line 2 > a |
|
260 | 260 | $ hg commit -d '1 0' -m b |
|
261 | 261 | |
|
262 | 262 | $ echo line 3 >> a |
|
263 | 263 | $ hg commit -d '2 0' -m c |
|
264 | 264 | |
|
265 | 265 | $ hg backout --merge -d '3 0' 1 --tool=true |
|
266 | 266 | reverting a |
|
267 | 267 | created new head |
|
268 | 268 | changeset 3:26b8ccb9ad91 backs out changeset 1:5a50a024c182 |
|
269 | 269 | merging with changeset 3:26b8ccb9ad91 |
|
270 | 270 | merging a |
|
271 | 271 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
272 | 272 | (branch merge, don't forget to commit) |
|
273 | 273 | $ hg commit -d '4 0' -m d |
|
274 | 274 | $ hg summary |
|
275 | 275 | parent: 4:c7df5e0b9c09 tip |
|
276 | 276 | d |
|
277 | 277 | branch: default |
|
278 | 278 | commit: (clean) |
|
279 | 279 | update: (current) |
|
280 | 280 | phases: 5 draft |
|
281 | 281 | |
|
282 | 282 | check line 1 is back |
|
283 | 283 | |
|
284 | 284 | $ cat a |
|
285 | 285 | line 1 |
|
286 | 286 | line 2 |
|
287 | 287 | line 3 |
|
288 | 288 | |
|
289 | 289 | Test visibility of in-memory dirstate changes outside transaction to |
|
290 | 290 | external hook process |
|
291 | 291 | |
|
292 | 292 | $ cat > $TESTTMP/checkvisibility.sh <<EOF |
|
293 | 293 | > echo "==== \$1:" |
|
294 | 294 | > hg parents --template "{rev}:{node|short}\n" |
|
295 | 295 | > echo "====" |
|
296 | 296 | > EOF |
|
297 | 297 | |
|
298 | 298 | "hg backout --merge REV1" at REV2 below implies steps below: |
|
299 | 299 | |
|
300 | 300 | (1) update to REV1 (REV2 => REV1) |
|
301 | 301 | (2) revert by REV1^1 |
|
302 | 302 | (3) commit backing out revision (REV3) |
|
303 | 303 | (4) update to REV2 (REV3 => REV2) |
|
304 | 304 | (5) merge with REV3 (REV2 => REV2, REV3) |
|
305 | 305 | |
|
306 | 306 | == test visibility to external preupdate hook |
|
307 | 307 | |
|
308 | 308 | $ hg update -q -C 2 |
|
309 | 309 | $ hg --config extensions.strip= strip 3 |
|
310 | 310 | saved backup bundle to * (glob) |
|
311 | 311 | |
|
312 | 312 | $ cat >> .hg/hgrc <<EOF |
|
313 | 313 | > [hooks] |
|
314 | 314 | > preupdate.visibility = sh $TESTTMP/checkvisibility.sh preupdate |
|
315 | 315 | > EOF |
|
316 | 316 | |
|
317 | 317 | ("-m" is needed to avoid writing dirstate changes out at other than |
|
318 | 318 | invocation of the hook to be examined) |
|
319 | 319 | |
|
320 | 320 | $ hg backout --merge -d '3 0' 1 --tool=true -m 'fixed comment' |
|
321 | 321 | ==== preupdate: |
|
322 | 322 | 2:6ea3f2a197a2 |
|
323 | 323 | ==== |
|
324 | 324 | reverting a |
|
325 | 325 | created new head |
|
326 | 326 | changeset 3:d92a3f57f067 backs out changeset 1:5a50a024c182 |
|
327 | 327 | ==== preupdate: |
|
328 | 328 | 3:d92a3f57f067 |
|
329 | 329 | ==== |
|
330 | 330 | merging with changeset 3:d92a3f57f067 |
|
331 | 331 | ==== preupdate: |
|
332 | 332 | 2:6ea3f2a197a2 |
|
333 | 333 | ==== |
|
334 | 334 | merging a |
|
335 | 335 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
336 | 336 | (branch merge, don't forget to commit) |
|
337 | 337 | |
|
338 | 338 | $ cat >> .hg/hgrc <<EOF |
|
339 | 339 | > [hooks] |
|
340 | 340 | > preupdate.visibility = |
|
341 | 341 | > EOF |
|
342 | 342 | |
|
343 | 343 | == test visibility to external update hook |
|
344 | 344 | |
|
345 | 345 | $ hg update -q -C 2 |
|
346 | 346 | $ hg --config extensions.strip= strip 3 |
|
347 | 347 | saved backup bundle to * (glob) |
|
348 | 348 | |
|
349 | 349 | $ cat >> .hg/hgrc <<EOF |
|
350 | 350 | > [hooks] |
|
351 | 351 | > update.visibility = sh $TESTTMP/checkvisibility.sh update |
|
352 | 352 | > EOF |
|
353 | 353 | |
|
354 | 354 | $ hg backout --merge -d '3 0' 1 --tool=true -m 'fixed comment' |
|
355 | 355 | ==== update: |
|
356 | 356 | 1:5a50a024c182 |
|
357 | 357 | ==== |
|
358 | 358 | reverting a |
|
359 | 359 | created new head |
|
360 | 360 | changeset 3:d92a3f57f067 backs out changeset 1:5a50a024c182 |
|
361 | 361 | ==== update: |
|
362 | 362 | 2:6ea3f2a197a2 |
|
363 | 363 | ==== |
|
364 | 364 | merging with changeset 3:d92a3f57f067 |
|
365 | 365 | merging a |
|
366 | 366 | ==== update: |
|
367 | 367 | 2:6ea3f2a197a2 |
|
368 | 368 | 3:d92a3f57f067 |
|
369 | 369 | ==== |
|
370 | 370 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
371 | 371 | (branch merge, don't forget to commit) |
|
372 | 372 | |
|
373 | 373 | $ cat >> .hg/hgrc <<EOF |
|
374 | 374 | > [hooks] |
|
375 | 375 | > update.visibility = |
|
376 | 376 | > EOF |
|
377 | 377 | |
|
378 | 378 | $ cd .. |
|
379 | 379 | |
|
380 | 380 | backout should not back out subsequent changesets |
|
381 | 381 | |
|
382 | 382 | $ hg init onecs |
|
383 | 383 | $ cd onecs |
|
384 | 384 | $ echo 1 > a |
|
385 | 385 | $ hg commit -d '0 0' -A -m a |
|
386 | 386 | adding a |
|
387 | 387 | $ echo 2 >> a |
|
388 | 388 | $ hg commit -d '1 0' -m b |
|
389 | 389 | $ echo 1 > b |
|
390 | 390 | $ hg commit -d '2 0' -A -m c |
|
391 | 391 | adding b |
|
392 | 392 | $ hg summary |
|
393 | 393 | parent: 2:882396649954 tip |
|
394 | 394 | c |
|
395 | 395 | branch: default |
|
396 | 396 | commit: (clean) |
|
397 | 397 | update: (current) |
|
398 | 398 | phases: 3 draft |
|
399 | 399 | |
|
400 | 400 | without --merge |
|
401 | 401 | $ hg backout --no-commit -d '3 0' 1 --tool=true |
|
402 | 402 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
403 | 403 | changeset 22bca4c721e5 backed out, don't forget to commit. |
|
404 | 404 | $ hg locate b |
|
405 | 405 | b |
|
406 | 406 | $ hg update -C tip |
|
407 | 407 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
408 | 408 | $ hg locate b |
|
409 | 409 | b |
|
410 | 410 | $ hg summary |
|
411 | 411 | parent: 2:882396649954 tip |
|
412 | 412 | c |
|
413 | 413 | branch: default |
|
414 | 414 | commit: (clean) |
|
415 | 415 | update: (current) |
|
416 | 416 | phases: 3 draft |
|
417 | 417 | |
|
418 | 418 | with --merge |
|
419 | 419 | $ hg backout --merge -d '3 0' 1 --tool=true |
|
420 | 420 | reverting a |
|
421 | 421 | created new head |
|
422 | 422 | changeset 3:3202beb76721 backs out changeset 1:22bca4c721e5 |
|
423 | 423 | merging with changeset 3:3202beb76721 |
|
424 | 424 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
425 | 425 | (branch merge, don't forget to commit) |
|
426 | 426 | $ hg locate b |
|
427 | 427 | b |
|
428 | 428 | $ hg update -C tip |
|
429 | 429 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
430 | 430 | $ hg locate b |
|
431 | 431 | [1] |
|
432 | 432 | |
|
433 | 433 | $ cd .. |
|
434 | 434 | $ hg init m |
|
435 | 435 | $ cd m |
|
436 | 436 | $ echo a > a |
|
437 | 437 | $ hg commit -d '0 0' -A -m a |
|
438 | 438 | adding a |
|
439 | 439 | $ echo b > b |
|
440 | 440 | $ hg commit -d '1 0' -A -m b |
|
441 | 441 | adding b |
|
442 | 442 | $ echo c > c |
|
443 | 443 | $ hg commit -d '2 0' -A -m b |
|
444 | 444 | adding c |
|
445 | 445 | $ hg update 1 |
|
446 | 446 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
447 | 447 | $ echo d > d |
|
448 | 448 | $ hg commit -d '3 0' -A -m c |
|
449 | 449 | adding d |
|
450 | 450 | created new head |
|
451 | 451 | $ hg merge 2 |
|
452 | 452 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
453 | 453 | (branch merge, don't forget to commit) |
|
454 | 454 | $ hg commit -d '4 0' -A -m d |
|
455 | 455 | $ hg summary |
|
456 | 456 | parent: 4:b2f3bb92043e tip |
|
457 | 457 | d |
|
458 | 458 | branch: default |
|
459 | 459 | commit: (clean) |
|
460 | 460 | update: (current) |
|
461 | 461 | phases: 5 draft |
|
462 | 462 | |
|
463 | 463 | backout of merge should fail |
|
464 | 464 | |
|
465 | 465 | $ hg backout 4 |
|
466 | 466 | abort: cannot backout a merge changeset |
|
467 | 467 | [255] |
|
468 | 468 | |
|
469 | 469 | backout of merge with bad parent should fail |
|
470 | 470 | |
|
471 | 471 | $ hg backout --parent 0 4 |
|
472 | 472 | abort: cb9a9f314b8b is not a parent of b2f3bb92043e |
|
473 | 473 | [255] |
|
474 | 474 | |
|
475 | 475 | backout of non-merge with parent should fail |
|
476 | 476 | |
|
477 | 477 | $ hg backout --parent 0 3 |
|
478 | 478 | abort: cannot use --parent on non-merge changeset |
|
479 | 479 | [255] |
|
480 | 480 | |
|
481 | 481 | backout with valid parent should be ok |
|
482 | 482 | |
|
483 | 483 | $ hg backout -d '5 0' --parent 2 4 --tool=true |
|
484 | 484 | removing d |
|
485 | 485 | changeset 5:10e5328c8435 backs out changeset 4:b2f3bb92043e |
|
486 | 486 | $ hg summary |
|
487 | 487 | parent: 5:10e5328c8435 tip |
|
488 | 488 | Backed out changeset b2f3bb92043e |
|
489 | 489 | branch: default |
|
490 | 490 | commit: (clean) |
|
491 | 491 | update: (current) |
|
492 | 492 | phases: 6 draft |
|
493 | 493 | |
|
494 | 494 | $ hg rollback |
|
495 | 495 | repository tip rolled back to revision 4 (undo commit) |
|
496 | 496 | working directory now based on revision 4 |
|
497 | 497 | $ hg update -C |
|
498 | 498 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
499 | 499 | $ hg summary |
|
500 | 500 | parent: 4:b2f3bb92043e tip |
|
501 | 501 | d |
|
502 | 502 | branch: default |
|
503 | 503 | commit: (clean) |
|
504 | 504 | update: (current) |
|
505 | 505 | phases: 5 draft |
|
506 | 506 | |
|
507 | 507 | $ hg backout -d '6 0' --parent 3 4 --tool=true |
|
508 | 508 | removing c |
|
509 | 509 | changeset 5:033590168430 backs out changeset 4:b2f3bb92043e |
|
510 | 510 | $ hg summary |
|
511 | 511 | parent: 5:033590168430 tip |
|
512 | 512 | Backed out changeset b2f3bb92043e |
|
513 | 513 | branch: default |
|
514 | 514 | commit: (clean) |
|
515 | 515 | update: (current) |
|
516 | 516 | phases: 6 draft |
|
517 | 517 | |
|
518 | 518 | $ cd .. |
|
519 | 519 | |
|
520 | 520 | named branches |
|
521 | 521 | |
|
522 | 522 | $ hg init named_branches |
|
523 | 523 | $ cd named_branches |
|
524 | 524 | |
|
525 | 525 | $ echo default > default |
|
526 | 526 | $ hg ci -d '0 0' -Am default |
|
527 | 527 | adding default |
|
528 | 528 | $ hg branch branch1 |
|
529 | 529 | marked working directory as branch branch1 |
|
530 | 530 | (branches are permanent and global, did you want a bookmark?) |
|
531 | 531 | $ echo branch1 > file1 |
|
532 | 532 | $ hg ci -d '1 0' -Am file1 |
|
533 | 533 | adding file1 |
|
534 | 534 | $ hg branch branch2 |
|
535 | 535 | marked working directory as branch branch2 |
|
536 | 536 | $ echo branch2 > file2 |
|
537 | 537 | $ hg ci -d '2 0' -Am file2 |
|
538 | 538 | adding file2 |
|
539 | 539 | |
|
540 | 540 | without --merge |
|
541 | 541 | $ hg backout --no-commit -r 1 --tool=true |
|
542 | 542 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
543 | 543 | changeset bf1602f437f3 backed out, don't forget to commit. |
|
544 | 544 | $ hg branch |
|
545 | 545 | branch2 |
|
546 | 546 | $ hg status -A |
|
547 | 547 | R file1 |
|
548 | 548 | C default |
|
549 | 549 | C file2 |
|
550 | 550 | $ hg summary |
|
551 | 551 | parent: 2:45bbcd363bf0 tip |
|
552 | 552 | file2 |
|
553 | 553 | branch: branch2 |
|
554 | 554 | commit: 1 removed |
|
555 | 555 | update: (current) |
|
556 | 556 | phases: 3 draft |
|
557 | 557 | |
|
558 | 558 | with --merge |
|
559 | 559 | (this also tests that editor is invoked if '--edit' is specified |
|
560 | 560 | explicitly regardless of '--message') |
|
561 | 561 | |
|
562 | 562 | $ hg update -qC |
|
563 | 563 | $ HGEDITOR=cat hg backout --merge -d '3 0' -r 1 -m 'backout on branch1' --tool=true --edit |
|
564 | 564 | removing file1 |
|
565 | 565 | backout on branch1 |
|
566 | 566 | |
|
567 | 567 | |
|
568 | 568 | HG: Enter commit message. Lines beginning with 'HG:' are removed. |
|
569 | 569 | HG: Leave message empty to abort commit. |
|
570 | 570 | HG: -- |
|
571 | 571 | HG: user: test |
|
572 | 572 | HG: branch 'branch2' |
|
573 | 573 | HG: removed file1 |
|
574 | 574 | created new head |
|
575 | 575 | changeset 3:d4e8f6db59fb backs out changeset 1:bf1602f437f3 |
|
576 | 576 | merging with changeset 3:d4e8f6db59fb |
|
577 | 577 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
578 | 578 | (branch merge, don't forget to commit) |
|
579 | 579 | $ hg summary |
|
580 | 580 | parent: 2:45bbcd363bf0 |
|
581 | 581 | file2 |
|
582 | 582 | parent: 3:d4e8f6db59fb tip |
|
583 | 583 | backout on branch1 |
|
584 | 584 | branch: branch2 |
|
585 | 585 | commit: 1 removed (merge) |
|
586 | 586 | update: (current) |
|
587 | 587 | phases: 4 draft |
|
588 | 588 | $ hg update -q -C 2 |
|
589 | 589 | |
|
590 | 590 | on branch2 with branch1 not merged, so file1 should still exist: |
|
591 | 591 | |
|
592 | 592 | $ hg id |
|
593 | 593 | 45bbcd363bf0 (branch2) |
|
594 | 594 | $ hg st -A |
|
595 | 595 | C default |
|
596 | 596 | C file1 |
|
597 | 597 | C file2 |
|
598 | 598 | $ hg summary |
|
599 | 599 | parent: 2:45bbcd363bf0 |
|
600 | 600 | file2 |
|
601 | 601 | branch: branch2 |
|
602 | 602 | commit: (clean) |
|
603 | 603 | update: 1 new changesets, 2 branch heads (merge) |
|
604 | 604 | phases: 4 draft |
|
605 | 605 | |
|
606 | 606 | on branch2 with branch1 merged, so file1 should be gone: |
|
607 | 607 | |
|
608 | 608 | $ hg merge |
|
609 | 609 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
610 | 610 | (branch merge, don't forget to commit) |
|
611 | 611 | $ hg ci -d '4 0' -m 'merge backout of branch1' |
|
612 | 612 | $ hg id |
|
613 | 613 | d97a8500a969 (branch2) tip |
|
614 | 614 | $ hg st -A |
|
615 | 615 | C default |
|
616 | 616 | C file2 |
|
617 | 617 | $ hg summary |
|
618 | 618 | parent: 4:d97a8500a969 tip |
|
619 | 619 | merge backout of branch1 |
|
620 | 620 | branch: branch2 |
|
621 | 621 | commit: (clean) |
|
622 | 622 | update: (current) |
|
623 | 623 | phases: 5 draft |
|
624 | 624 | |
|
625 | 625 | on branch1, so no file1 and file2: |
|
626 | 626 | |
|
627 | 627 | $ hg co -C branch1 |
|
628 | 628 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
629 | 629 | $ hg id |
|
630 | 630 | bf1602f437f3 (branch1) |
|
631 | 631 | $ hg st -A |
|
632 | 632 | C default |
|
633 | 633 | C file1 |
|
634 | 634 | $ hg summary |
|
635 | 635 | parent: 1:bf1602f437f3 |
|
636 | 636 | file1 |
|
637 | 637 | branch: branch1 |
|
638 | 638 | commit: (clean) |
|
639 | 639 | update: (current) |
|
640 | 640 | phases: 5 draft |
|
641 | 641 | |
|
642 | 642 | $ cd .. |
|
643 | 643 | |
|
644 | 644 | backout of empty changeset (issue4190) |
|
645 | 645 | |
|
646 | 646 | $ hg init emptycommit |
|
647 | 647 | $ cd emptycommit |
|
648 | 648 | |
|
649 | 649 | $ touch file1 |
|
650 | 650 | $ hg ci -Aqm file1 |
|
651 | 651 | $ hg branch -q branch1 |
|
652 | 652 | $ hg ci -qm branch1 |
|
653 | 653 | $ hg backout -v 1 |
|
654 | 654 | resolving manifests |
|
655 | 655 | nothing changed |
|
656 | 656 | [1] |
|
657 | 657 | |
|
658 | 658 | $ cd .. |
|
659 | 659 | |
|
660 | 660 | |
|
661 | 661 | Test usage of `hg resolve` in case of conflict |
|
662 | 662 | (issue4163) |
|
663 | 663 | |
|
664 | 664 | $ hg init issue4163 |
|
665 | 665 | $ cd issue4163 |
|
666 | 666 | $ touch foo |
|
667 | 667 | $ hg add foo |
|
668 | 668 | $ cat > foo << EOF |
|
669 | 669 | > one |
|
670 | 670 | > two |
|
671 | 671 | > three |
|
672 | 672 | > four |
|
673 | 673 | > five |
|
674 | 674 | > six |
|
675 | 675 | > seven |
|
676 | 676 | > height |
|
677 | 677 | > nine |
|
678 | 678 | > ten |
|
679 | 679 | > EOF |
|
680 | 680 | $ hg ci -m 'initial' |
|
681 | 681 | $ cat > foo << EOF |
|
682 | 682 | > one |
|
683 | 683 | > two |
|
684 | 684 | > THREE |
|
685 | 685 | > four |
|
686 | 686 | > five |
|
687 | 687 | > six |
|
688 | 688 | > seven |
|
689 | 689 | > height |
|
690 | 690 | > nine |
|
691 | 691 | > ten |
|
692 | 692 | > EOF |
|
693 | 693 | $ hg ci -m 'capital three' |
|
694 | 694 | $ cat > foo << EOF |
|
695 | 695 | > one |
|
696 | 696 | > two |
|
697 | 697 | > THREE |
|
698 | 698 | > four |
|
699 | 699 | > five |
|
700 | 700 | > six |
|
701 | 701 | > seven |
|
702 | 702 | > height |
|
703 | 703 | > nine |
|
704 | 704 | > TEN |
|
705 | 705 | > EOF |
|
706 | 706 | $ hg ci -m 'capital ten' |
|
707 | 707 | $ hg backout -r 'desc("capital three")' --tool internal:fail |
|
708 | 708 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
709 | 709 | use 'hg resolve' to retry unresolved file merges |
|
710 | 710 | [1] |
|
711 | 711 | $ hg status |
|
712 | 712 | $ hg debugmergestate -v |
|
713 | 713 | v1 and v2 states match: using v2 |
|
714 | 714 | local: b71750c4b0fdf719734971e3ef90dbeab5919a2d |
|
715 | 715 | other: a30dd8addae3ce71b8667868478542bc417439e6 |
|
716 | 716 | file: foo (state "u") |
|
717 | 717 | local path: foo (hash 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33, flags "") |
|
718 | 718 | ancestor path: foo (node f89532f44c247a0e993d63e3a734dd781ab04708) |
|
719 | 719 | other path: foo (node f50039b486d6fa1a90ae51778388cad161f425ee) |
|
720 | 720 | extra: ancestorlinknode = 91360952243723bd5b1138d5f26bd8c8564cb553 |
|
721 | 721 | $ mv .hg/merge/state2 .hg/merge/state2-moved |
|
722 | 722 | $ hg debugmergestate -v |
|
723 | 723 | no version 2 merge state |
|
724 | 724 | local: b71750c4b0fdf719734971e3ef90dbeab5919a2d |
|
725 | 725 | other: b71750c4b0fdf719734971e3ef90dbeab5919a2d |
|
726 | 726 | file: foo (state "u") |
|
727 | 727 | local path: foo (hash 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33, flags "") |
|
728 | 728 | ancestor path: foo (node f89532f44c247a0e993d63e3a734dd781ab04708) |
|
729 | 729 | other path: (node foo) |
|
730 | 730 | $ mv .hg/merge/state2-moved .hg/merge/state2 |
|
731 | 731 | $ hg resolve -l # still unresolved |
|
732 | 732 | U foo |
|
733 | 733 | $ hg summary |
|
734 | 734 | parent: 2:b71750c4b0fd tip |
|
735 | 735 | capital ten |
|
736 | 736 | branch: default |
|
737 | 737 | commit: 1 unresolved (clean) |
|
738 | 738 | update: (current) |
|
739 | 739 | phases: 3 draft |
|
740 | 740 | $ hg log -G |
|
741 | 741 | @ changeset: 2:b71750c4b0fd |
|
742 | 742 | | tag: tip |
|
743 | 743 | | user: test |
|
744 | 744 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
745 | 745 | | summary: capital ten |
|
746 | 746 | | |
|
747 | 747 | o changeset: 1:913609522437 |
|
748 | 748 | | user: test |
|
749 | 749 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
750 | 750 | | summary: capital three |
|
751 | 751 | | |
|
752 | 752 | % changeset: 0:a30dd8addae3 |
|
753 | 753 | user: test |
|
754 | 754 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
755 | 755 | summary: initial |
|
756 | 756 | |
|
757 | 757 | $ hg resolve --all --debug |
|
758 | 758 | picked tool ':merge' for foo (binary False symlink False changedelete False) |
|
759 | 759 | merging foo |
|
760 | 760 | my foo@b71750c4b0fd+ other foo@a30dd8addae3 ancestor foo@913609522437 |
|
761 | 761 | premerge successful |
|
762 | 762 | (no more unresolved files) |
|
763 | 763 | continue: hg commit |
|
764 | 764 | $ hg status |
|
765 | 765 | M foo |
|
766 | 766 | ? foo.orig |
|
767 | 767 | $ hg resolve -l |
|
768 | 768 | R foo |
|
769 | 769 | $ hg summary |
|
770 | 770 | parent: 2:b71750c4b0fd tip |
|
771 | 771 | capital ten |
|
772 | 772 | branch: default |
|
773 | 773 | commit: 1 modified, 1 unknown |
|
774 | 774 | update: (current) |
|
775 | 775 | phases: 3 draft |
|
776 | 776 | $ cat foo |
|
777 | 777 | one |
|
778 | 778 | two |
|
779 | 779 | three |
|
780 | 780 | four |
|
781 | 781 | five |
|
782 | 782 | six |
|
783 | 783 | seven |
|
784 | 784 | height |
|
785 | 785 | nine |
|
786 | 786 | TEN |
|
787 | 787 | |
|
788 | 788 | --no-commit shouldn't commit |
|
789 | 789 | |
|
790 | 790 | $ hg init a |
|
791 | 791 | $ cd a |
|
792 | 792 | $ for i in 1 2 3; do |
|
793 | 793 | > touch $i |
|
794 | 794 | > hg ci -Am $i |
|
795 | 795 | > done |
|
796 | 796 | adding 1 |
|
797 | 797 | adding 2 |
|
798 | 798 | adding 3 |
|
799 | 799 | $ hg backout --no-commit . |
|
800 | 800 | removing 3 |
|
801 | 801 | changeset cccc23d9d68f backed out, don't forget to commit. |
|
802 | 802 | $ hg revert -aq |
|
803 | 803 | |
|
804 | 804 | --no-commit can't be used with --merge |
|
805 | 805 | |
|
806 | 806 | $ hg backout --merge --no-commit 2 |
|
807 | 807 | abort: cannot specify both --no-commit and --merge |
|
808 | 808 | [255] |
|
809 | 809 | |
|
810 | 810 | Ensure that backout out the same changeset twice performs correctly: |
|
811 | 811 | |
|
812 | 812 | $ hg backout 2 |
|
813 | 813 | removing 3 |
|
814 | 814 | changeset 3:8f188de730d9 backs out changeset 2:cccc23d9d68f |
|
815 | 815 | $ echo 4 > 4 |
|
816 | 816 | $ hg ci -A -m 4 |
|
817 | 817 | adding 4 |
|
818 | 818 | $ hg up 2 |
|
819 | 819 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
820 | 820 | $ hg backout 2 |
|
821 | 821 | removing 3 |
|
822 | created new head | |
|
822 | warning: commit already existed in the repository! | |
|
823 | 823 | changeset 3:8f188de730d9 backs out changeset 2:cccc23d9d68f |
@@ -1,2091 +1,2092 b'' | |||
|
1 | 1 | test merge-tools configuration - mostly exercising filemerge.py |
|
2 | 2 | |
|
3 | 3 | $ unset HGMERGE # make sure HGMERGE doesn't interfere with the test |
|
4 | 4 | $ cat >> $HGRCPATH << EOF |
|
5 | 5 | > [ui] |
|
6 | 6 | > merge= |
|
7 | 7 | > [commands] |
|
8 | 8 | > merge.require-rev=True |
|
9 | 9 | > EOF |
|
10 | 10 | $ hg init repo |
|
11 | 11 | $ cd repo |
|
12 | 12 | |
|
13 | 13 | revision 0 |
|
14 | 14 | |
|
15 | 15 | $ echo "revision 0" > f |
|
16 | 16 | $ echo "space" >> f |
|
17 | 17 | $ hg commit -Am "revision 0" |
|
18 | 18 | adding f |
|
19 | 19 | |
|
20 | 20 | revision 1 |
|
21 | 21 | |
|
22 | 22 | $ echo "revision 1" > f |
|
23 | 23 | $ echo "space" >> f |
|
24 | 24 | $ hg commit -Am "revision 1" |
|
25 | 25 | $ hg update 0 > /dev/null |
|
26 | 26 | |
|
27 | 27 | revision 2 |
|
28 | 28 | |
|
29 | 29 | $ echo "revision 2" > f |
|
30 | 30 | $ echo "space" >> f |
|
31 | 31 | $ hg commit -Am "revision 2" |
|
32 | 32 | created new head |
|
33 | 33 | $ hg update 0 > /dev/null |
|
34 | 34 | |
|
35 | 35 | revision 3 - simple to merge |
|
36 | 36 | |
|
37 | 37 | $ echo "revision 3" >> f |
|
38 | 38 | $ hg commit -Am "revision 3" |
|
39 | 39 | created new head |
|
40 | 40 | |
|
41 | 41 | revision 4 - hard to merge |
|
42 | 42 | |
|
43 | 43 | $ hg update 0 > /dev/null |
|
44 | 44 | $ echo "revision 4" > f |
|
45 | 45 | $ hg commit -Am "revision 4" |
|
46 | 46 | created new head |
|
47 | 47 | |
|
48 | 48 | $ echo "[merge-tools]" > .hg/hgrc |
|
49 | 49 | |
|
50 | 50 | $ beforemerge() { |
|
51 | 51 | > cat .hg/hgrc |
|
52 | 52 | > echo "# hg update -C 1" |
|
53 | 53 | > hg update -C 1 > /dev/null |
|
54 | 54 | > } |
|
55 | 55 | $ aftermerge() { |
|
56 | 56 | > echo "# cat f" |
|
57 | 57 | > cat f |
|
58 | 58 | > echo "# hg stat" |
|
59 | 59 | > hg stat |
|
60 | 60 | > echo "# hg resolve --list" |
|
61 | 61 | > hg resolve --list |
|
62 | 62 | > rm -f f.orig |
|
63 | 63 | > } |
|
64 | 64 | |
|
65 | 65 | Tool selection |
|
66 | 66 | |
|
67 | 67 | default is internal merge: |
|
68 | 68 | |
|
69 | 69 | $ beforemerge |
|
70 | 70 | [merge-tools] |
|
71 | 71 | # hg update -C 1 |
|
72 | 72 | |
|
73 | 73 | hg merge -r 2 |
|
74 | 74 | override $PATH to ensure hgmerge not visible; use $PYTHON in case we're |
|
75 | 75 | running from a devel copy, not a temp installation |
|
76 | 76 | |
|
77 | 77 | $ PATH="/usr/sbin" "$PYTHON" "$BINDIR"/hg merge -r 2 |
|
78 | 78 | merging f |
|
79 | 79 | warning: conflicts while merging f! (edit, then use 'hg resolve --mark') |
|
80 | 80 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
81 | 81 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
82 | 82 | [1] |
|
83 | 83 | $ aftermerge |
|
84 | 84 | # cat f |
|
85 | 85 | <<<<<<< working copy: ef83787e2614 - test: revision 1 |
|
86 | 86 | revision 1 |
|
87 | 87 | ======= |
|
88 | 88 | revision 2 |
|
89 | 89 | >>>>>>> merge rev: 0185f4e0cf02 - test: revision 2 |
|
90 | 90 | space |
|
91 | 91 | # hg stat |
|
92 | 92 | M f |
|
93 | 93 | ? f.orig |
|
94 | 94 | # hg resolve --list |
|
95 | 95 | U f |
|
96 | 96 | |
|
97 | 97 | simplest hgrc using false for merge: |
|
98 | 98 | |
|
99 | 99 | $ echo "false.whatever=" >> .hg/hgrc |
|
100 | 100 | $ beforemerge |
|
101 | 101 | [merge-tools] |
|
102 | 102 | false.whatever= |
|
103 | 103 | # hg update -C 1 |
|
104 | 104 | $ hg merge -r 2 |
|
105 | 105 | merging f |
|
106 | 106 | merging f failed! |
|
107 | 107 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
108 | 108 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
109 | 109 | [1] |
|
110 | 110 | $ aftermerge |
|
111 | 111 | # cat f |
|
112 | 112 | revision 1 |
|
113 | 113 | space |
|
114 | 114 | # hg stat |
|
115 | 115 | M f |
|
116 | 116 | ? f.orig |
|
117 | 117 | # hg resolve --list |
|
118 | 118 | U f |
|
119 | 119 | |
|
120 | 120 | #if unix-permissions |
|
121 | 121 | |
|
122 | 122 | unexecutable file in $PATH shouldn't be found: |
|
123 | 123 | |
|
124 | 124 | $ echo "echo fail" > false |
|
125 | 125 | $ hg up -qC 1 |
|
126 | 126 | $ PATH="`pwd`:/usr/sbin" "$PYTHON" "$BINDIR"/hg merge -r 2 |
|
127 | 127 | merging f |
|
128 | 128 | warning: conflicts while merging f! (edit, then use 'hg resolve --mark') |
|
129 | 129 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
130 | 130 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
131 | 131 | [1] |
|
132 | 132 | $ rm false |
|
133 | 133 | |
|
134 | 134 | #endif |
|
135 | 135 | |
|
136 | 136 | executable directory in $PATH shouldn't be found: |
|
137 | 137 | |
|
138 | 138 | $ mkdir false |
|
139 | 139 | $ hg up -qC 1 |
|
140 | 140 | $ PATH="`pwd`:/usr/sbin" "$PYTHON" "$BINDIR"/hg merge -r 2 |
|
141 | 141 | merging f |
|
142 | 142 | warning: conflicts while merging f! (edit, then use 'hg resolve --mark') |
|
143 | 143 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
144 | 144 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
145 | 145 | [1] |
|
146 | 146 | $ rmdir false |
|
147 | 147 | |
|
148 | 148 | true with higher .priority gets precedence: |
|
149 | 149 | |
|
150 | 150 | $ echo "true.priority=1" >> .hg/hgrc |
|
151 | 151 | $ beforemerge |
|
152 | 152 | [merge-tools] |
|
153 | 153 | false.whatever= |
|
154 | 154 | true.priority=1 |
|
155 | 155 | # hg update -C 1 |
|
156 | 156 | $ hg merge -r 2 |
|
157 | 157 | merging f |
|
158 | 158 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
159 | 159 | (branch merge, don't forget to commit) |
|
160 | 160 | $ aftermerge |
|
161 | 161 | # cat f |
|
162 | 162 | revision 1 |
|
163 | 163 | space |
|
164 | 164 | # hg stat |
|
165 | 165 | M f |
|
166 | 166 | # hg resolve --list |
|
167 | 167 | R f |
|
168 | 168 | |
|
169 | 169 | unless lowered on command line: |
|
170 | 170 | |
|
171 | 171 | $ beforemerge |
|
172 | 172 | [merge-tools] |
|
173 | 173 | false.whatever= |
|
174 | 174 | true.priority=1 |
|
175 | 175 | # hg update -C 1 |
|
176 | 176 | $ hg merge -r 2 --config merge-tools.true.priority=-7 |
|
177 | 177 | merging f |
|
178 | 178 | merging f failed! |
|
179 | 179 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
180 | 180 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
181 | 181 | [1] |
|
182 | 182 | $ aftermerge |
|
183 | 183 | # cat f |
|
184 | 184 | revision 1 |
|
185 | 185 | space |
|
186 | 186 | # hg stat |
|
187 | 187 | M f |
|
188 | 188 | ? f.orig |
|
189 | 189 | # hg resolve --list |
|
190 | 190 | U f |
|
191 | 191 | |
|
192 | 192 | or false set higher on command line: |
|
193 | 193 | |
|
194 | 194 | $ beforemerge |
|
195 | 195 | [merge-tools] |
|
196 | 196 | false.whatever= |
|
197 | 197 | true.priority=1 |
|
198 | 198 | # hg update -C 1 |
|
199 | 199 | $ hg merge -r 2 --config merge-tools.false.priority=117 |
|
200 | 200 | merging f |
|
201 | 201 | merging f failed! |
|
202 | 202 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
203 | 203 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
204 | 204 | [1] |
|
205 | 205 | $ aftermerge |
|
206 | 206 | # cat f |
|
207 | 207 | revision 1 |
|
208 | 208 | space |
|
209 | 209 | # hg stat |
|
210 | 210 | M f |
|
211 | 211 | ? f.orig |
|
212 | 212 | # hg resolve --list |
|
213 | 213 | U f |
|
214 | 214 | |
|
215 | 215 | or true set to disabled: |
|
216 | 216 | $ beforemerge |
|
217 | 217 | [merge-tools] |
|
218 | 218 | false.whatever= |
|
219 | 219 | true.priority=1 |
|
220 | 220 | # hg update -C 1 |
|
221 | 221 | $ hg merge -r 2 --config merge-tools.true.disabled=yes |
|
222 | 222 | merging f |
|
223 | 223 | merging f failed! |
|
224 | 224 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
225 | 225 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
226 | 226 | [1] |
|
227 | 227 | $ aftermerge |
|
228 | 228 | # cat f |
|
229 | 229 | revision 1 |
|
230 | 230 | space |
|
231 | 231 | # hg stat |
|
232 | 232 | M f |
|
233 | 233 | ? f.orig |
|
234 | 234 | # hg resolve --list |
|
235 | 235 | U f |
|
236 | 236 | |
|
237 | 237 | or true.executable not found in PATH: |
|
238 | 238 | |
|
239 | 239 | $ beforemerge |
|
240 | 240 | [merge-tools] |
|
241 | 241 | false.whatever= |
|
242 | 242 | true.priority=1 |
|
243 | 243 | # hg update -C 1 |
|
244 | 244 | $ hg merge -r 2 --config merge-tools.true.executable=nonexistentmergetool |
|
245 | 245 | merging f |
|
246 | 246 | merging f failed! |
|
247 | 247 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
248 | 248 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
249 | 249 | [1] |
|
250 | 250 | $ aftermerge |
|
251 | 251 | # cat f |
|
252 | 252 | revision 1 |
|
253 | 253 | space |
|
254 | 254 | # hg stat |
|
255 | 255 | M f |
|
256 | 256 | ? f.orig |
|
257 | 257 | # hg resolve --list |
|
258 | 258 | U f |
|
259 | 259 | |
|
260 | 260 | or true.executable with bogus path: |
|
261 | 261 | |
|
262 | 262 | $ beforemerge |
|
263 | 263 | [merge-tools] |
|
264 | 264 | false.whatever= |
|
265 | 265 | true.priority=1 |
|
266 | 266 | # hg update -C 1 |
|
267 | 267 | $ hg merge -r 2 --config merge-tools.true.executable=/nonexistent/mergetool |
|
268 | 268 | merging f |
|
269 | 269 | merging f failed! |
|
270 | 270 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
271 | 271 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
272 | 272 | [1] |
|
273 | 273 | $ aftermerge |
|
274 | 274 | # cat f |
|
275 | 275 | revision 1 |
|
276 | 276 | space |
|
277 | 277 | # hg stat |
|
278 | 278 | M f |
|
279 | 279 | ? f.orig |
|
280 | 280 | # hg resolve --list |
|
281 | 281 | U f |
|
282 | 282 | |
|
283 | 283 | but true.executable set to cat found in PATH works: |
|
284 | 284 | |
|
285 | 285 | $ echo "true.executable=cat" >> .hg/hgrc |
|
286 | 286 | $ beforemerge |
|
287 | 287 | [merge-tools] |
|
288 | 288 | false.whatever= |
|
289 | 289 | true.priority=1 |
|
290 | 290 | true.executable=cat |
|
291 | 291 | # hg update -C 1 |
|
292 | 292 | $ hg merge -r 2 |
|
293 | 293 | merging f |
|
294 | 294 | revision 1 |
|
295 | 295 | space |
|
296 | 296 | revision 0 |
|
297 | 297 | space |
|
298 | 298 | revision 2 |
|
299 | 299 | space |
|
300 | 300 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
301 | 301 | (branch merge, don't forget to commit) |
|
302 | 302 | $ aftermerge |
|
303 | 303 | # cat f |
|
304 | 304 | revision 1 |
|
305 | 305 | space |
|
306 | 306 | # hg stat |
|
307 | 307 | M f |
|
308 | 308 | # hg resolve --list |
|
309 | 309 | R f |
|
310 | 310 | |
|
311 | 311 | and true.executable set to cat with path works: |
|
312 | 312 | |
|
313 | 313 | $ beforemerge |
|
314 | 314 | [merge-tools] |
|
315 | 315 | false.whatever= |
|
316 | 316 | true.priority=1 |
|
317 | 317 | true.executable=cat |
|
318 | 318 | # hg update -C 1 |
|
319 | 319 | $ hg merge -r 2 --config merge-tools.true.executable=cat |
|
320 | 320 | merging f |
|
321 | 321 | revision 1 |
|
322 | 322 | space |
|
323 | 323 | revision 0 |
|
324 | 324 | space |
|
325 | 325 | revision 2 |
|
326 | 326 | space |
|
327 | 327 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
328 | 328 | (branch merge, don't forget to commit) |
|
329 | 329 | $ aftermerge |
|
330 | 330 | # cat f |
|
331 | 331 | revision 1 |
|
332 | 332 | space |
|
333 | 333 | # hg stat |
|
334 | 334 | M f |
|
335 | 335 | # hg resolve --list |
|
336 | 336 | R f |
|
337 | 337 | |
|
338 | 338 | executable set to python script that succeeds: |
|
339 | 339 | |
|
340 | 340 | $ cat > "$TESTTMP/myworkingmerge.py" <<EOF |
|
341 | 341 | > def myworkingmergefn(ui, repo, args, **kwargs): |
|
342 | 342 | > return False |
|
343 | 343 | > EOF |
|
344 | 344 | $ beforemerge |
|
345 | 345 | [merge-tools] |
|
346 | 346 | false.whatever= |
|
347 | 347 | true.priority=1 |
|
348 | 348 | true.executable=cat |
|
349 | 349 | # hg update -C 1 |
|
350 | 350 | $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/myworkingmerge.py:myworkingmergefn" |
|
351 | 351 | merging f |
|
352 | 352 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
353 | 353 | (branch merge, don't forget to commit) |
|
354 | 354 | $ aftermerge |
|
355 | 355 | # cat f |
|
356 | 356 | revision 1 |
|
357 | 357 | space |
|
358 | 358 | # hg stat |
|
359 | 359 | M f |
|
360 | 360 | # hg resolve --list |
|
361 | 361 | R f |
|
362 | 362 | |
|
363 | 363 | executable set to python script that fails: |
|
364 | 364 | |
|
365 | 365 | $ cat > "$TESTTMP/mybrokenmerge.py" <<EOF |
|
366 | 366 | > def mybrokenmergefn(ui, repo, args, **kwargs): |
|
367 | 367 | > ui.write(b"some fail message\n") |
|
368 | 368 | > return True |
|
369 | 369 | > EOF |
|
370 | 370 | $ beforemerge |
|
371 | 371 | [merge-tools] |
|
372 | 372 | false.whatever= |
|
373 | 373 | true.priority=1 |
|
374 | 374 | true.executable=cat |
|
375 | 375 | # hg update -C 1 |
|
376 | 376 | $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/mybrokenmerge.py:mybrokenmergefn" |
|
377 | 377 | merging f |
|
378 | 378 | some fail message |
|
379 | 379 | abort: $TESTTMP/mybrokenmerge.py hook failed |
|
380 | 380 | [255] |
|
381 | 381 | $ aftermerge |
|
382 | 382 | # cat f |
|
383 | 383 | revision 1 |
|
384 | 384 | space |
|
385 | 385 | # hg stat |
|
386 | 386 | ? f.orig |
|
387 | 387 | # hg resolve --list |
|
388 | 388 | U f |
|
389 | 389 | |
|
390 | 390 | executable set to python script that is missing function: |
|
391 | 391 | |
|
392 | 392 | $ beforemerge |
|
393 | 393 | [merge-tools] |
|
394 | 394 | false.whatever= |
|
395 | 395 | true.priority=1 |
|
396 | 396 | true.executable=cat |
|
397 | 397 | # hg update -C 1 |
|
398 | 398 | $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/myworkingmerge.py:missingFunction" |
|
399 | 399 | merging f |
|
400 | 400 | abort: $TESTTMP/myworkingmerge.py does not have function: missingFunction |
|
401 | 401 | [255] |
|
402 | 402 | $ aftermerge |
|
403 | 403 | # cat f |
|
404 | 404 | revision 1 |
|
405 | 405 | space |
|
406 | 406 | # hg stat |
|
407 | 407 | ? f.orig |
|
408 | 408 | # hg resolve --list |
|
409 | 409 | U f |
|
410 | 410 | |
|
411 | 411 | executable set to missing python script: |
|
412 | 412 | |
|
413 | 413 | $ beforemerge |
|
414 | 414 | [merge-tools] |
|
415 | 415 | false.whatever= |
|
416 | 416 | true.priority=1 |
|
417 | 417 | true.executable=cat |
|
418 | 418 | # hg update -C 1 |
|
419 | 419 | $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/missingpythonscript.py:mergefn" |
|
420 | 420 | merging f |
|
421 | 421 | abort: loading python merge script failed: $TESTTMP/missingpythonscript.py |
|
422 | 422 | [255] |
|
423 | 423 | $ aftermerge |
|
424 | 424 | # cat f |
|
425 | 425 | revision 1 |
|
426 | 426 | space |
|
427 | 427 | # hg stat |
|
428 | 428 | ? f.orig |
|
429 | 429 | # hg resolve --list |
|
430 | 430 | U f |
|
431 | 431 | |
|
432 | 432 | executable set to python script but callable function is missing: |
|
433 | 433 | |
|
434 | 434 | $ beforemerge |
|
435 | 435 | [merge-tools] |
|
436 | 436 | false.whatever= |
|
437 | 437 | true.priority=1 |
|
438 | 438 | true.executable=cat |
|
439 | 439 | # hg update -C 1 |
|
440 | 440 | $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/myworkingmerge.py" |
|
441 | 441 | abort: invalid 'python:' syntax: python:$TESTTMP/myworkingmerge.py |
|
442 | 442 | [255] |
|
443 | 443 | $ aftermerge |
|
444 | 444 | # cat f |
|
445 | 445 | revision 1 |
|
446 | 446 | space |
|
447 | 447 | # hg stat |
|
448 | 448 | # hg resolve --list |
|
449 | 449 | U f |
|
450 | 450 | |
|
451 | 451 | executable set to python script but callable function is empty string: |
|
452 | 452 | |
|
453 | 453 | $ beforemerge |
|
454 | 454 | [merge-tools] |
|
455 | 455 | false.whatever= |
|
456 | 456 | true.priority=1 |
|
457 | 457 | true.executable=cat |
|
458 | 458 | # hg update -C 1 |
|
459 | 459 | $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/myworkingmerge.py:" |
|
460 | 460 | abort: invalid 'python:' syntax: python:$TESTTMP/myworkingmerge.py: |
|
461 | 461 | [255] |
|
462 | 462 | $ aftermerge |
|
463 | 463 | # cat f |
|
464 | 464 | revision 1 |
|
465 | 465 | space |
|
466 | 466 | # hg stat |
|
467 | 467 | # hg resolve --list |
|
468 | 468 | U f |
|
469 | 469 | |
|
470 | 470 | executable set to python script but callable function is missing and path contains colon: |
|
471 | 471 | |
|
472 | 472 | $ beforemerge |
|
473 | 473 | [merge-tools] |
|
474 | 474 | false.whatever= |
|
475 | 475 | true.priority=1 |
|
476 | 476 | true.executable=cat |
|
477 | 477 | # hg update -C 1 |
|
478 | 478 | $ hg merge -r 2 --config merge-tools.true.executable="python:$TESTTMP/some:dir/myworkingmerge.py" |
|
479 | 479 | abort: invalid 'python:' syntax: python:$TESTTMP/some:dir/myworkingmerge.py |
|
480 | 480 | [255] |
|
481 | 481 | $ aftermerge |
|
482 | 482 | # cat f |
|
483 | 483 | revision 1 |
|
484 | 484 | space |
|
485 | 485 | # hg stat |
|
486 | 486 | # hg resolve --list |
|
487 | 487 | U f |
|
488 | 488 | |
|
489 | 489 | executable set to python script filename that contains spaces: |
|
490 | 490 | |
|
491 | 491 | $ mkdir -p "$TESTTMP/my path" |
|
492 | 492 | $ cat > "$TESTTMP/my path/my working merge with spaces in filename.py" <<EOF |
|
493 | 493 | > def myworkingmergefn(ui, repo, args, **kwargs): |
|
494 | 494 | > return False |
|
495 | 495 | > EOF |
|
496 | 496 | $ beforemerge |
|
497 | 497 | [merge-tools] |
|
498 | 498 | false.whatever= |
|
499 | 499 | true.priority=1 |
|
500 | 500 | true.executable=cat |
|
501 | 501 | # hg update -C 1 |
|
502 | 502 | $ hg merge -r 2 --config "merge-tools.true.executable=python:$TESTTMP/my path/my working merge with spaces in filename.py:myworkingmergefn" |
|
503 | 503 | merging f |
|
504 | 504 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
505 | 505 | (branch merge, don't forget to commit) |
|
506 | 506 | $ aftermerge |
|
507 | 507 | # cat f |
|
508 | 508 | revision 1 |
|
509 | 509 | space |
|
510 | 510 | # hg stat |
|
511 | 511 | M f |
|
512 | 512 | # hg resolve --list |
|
513 | 513 | R f |
|
514 | 514 | |
|
515 | 515 | #if unix-permissions |
|
516 | 516 | |
|
517 | 517 | environment variables in true.executable are handled: |
|
518 | 518 | |
|
519 | 519 | $ echo 'echo "custom merge tool"' > .hg/merge.sh |
|
520 | 520 | $ beforemerge |
|
521 | 521 | [merge-tools] |
|
522 | 522 | false.whatever= |
|
523 | 523 | true.priority=1 |
|
524 | 524 | true.executable=cat |
|
525 | 525 | # hg update -C 1 |
|
526 | 526 | $ hg --config merge-tools.true.executable='sh' \ |
|
527 | 527 | > --config merge-tools.true.args=.hg/merge.sh \ |
|
528 | 528 | > merge -r 2 |
|
529 | 529 | merging f |
|
530 | 530 | custom merge tool |
|
531 | 531 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
532 | 532 | (branch merge, don't forget to commit) |
|
533 | 533 | $ aftermerge |
|
534 | 534 | # cat f |
|
535 | 535 | revision 1 |
|
536 | 536 | space |
|
537 | 537 | # hg stat |
|
538 | 538 | M f |
|
539 | 539 | # hg resolve --list |
|
540 | 540 | R f |
|
541 | 541 | |
|
542 | 542 | #endif |
|
543 | 543 | |
|
544 | 544 | Tool selection and merge-patterns |
|
545 | 545 | |
|
546 | 546 | merge-patterns specifies new tool false: |
|
547 | 547 | |
|
548 | 548 | $ beforemerge |
|
549 | 549 | [merge-tools] |
|
550 | 550 | false.whatever= |
|
551 | 551 | true.priority=1 |
|
552 | 552 | true.executable=cat |
|
553 | 553 | # hg update -C 1 |
|
554 | 554 | $ hg merge -r 2 --config merge-patterns.f=false |
|
555 | 555 | merging f |
|
556 | 556 | merging f failed! |
|
557 | 557 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
558 | 558 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
559 | 559 | [1] |
|
560 | 560 | $ aftermerge |
|
561 | 561 | # cat f |
|
562 | 562 | revision 1 |
|
563 | 563 | space |
|
564 | 564 | # hg stat |
|
565 | 565 | M f |
|
566 | 566 | ? f.orig |
|
567 | 567 | # hg resolve --list |
|
568 | 568 | U f |
|
569 | 569 | |
|
570 | 570 | merge-patterns specifies executable not found in PATH and gets warning: |
|
571 | 571 | |
|
572 | 572 | $ beforemerge |
|
573 | 573 | [merge-tools] |
|
574 | 574 | false.whatever= |
|
575 | 575 | true.priority=1 |
|
576 | 576 | true.executable=cat |
|
577 | 577 | # hg update -C 1 |
|
578 | 578 | $ hg merge -r 2 --config merge-patterns.f=true --config merge-tools.true.executable=nonexistentmergetool |
|
579 | 579 | couldn't find merge tool true (for pattern f) |
|
580 | 580 | merging f |
|
581 | 581 | couldn't find merge tool true (for pattern f) |
|
582 | 582 | merging f failed! |
|
583 | 583 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
584 | 584 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
585 | 585 | [1] |
|
586 | 586 | $ aftermerge |
|
587 | 587 | # cat f |
|
588 | 588 | revision 1 |
|
589 | 589 | space |
|
590 | 590 | # hg stat |
|
591 | 591 | M f |
|
592 | 592 | ? f.orig |
|
593 | 593 | # hg resolve --list |
|
594 | 594 | U f |
|
595 | 595 | |
|
596 | 596 | merge-patterns specifies executable with bogus path and gets warning: |
|
597 | 597 | |
|
598 | 598 | $ beforemerge |
|
599 | 599 | [merge-tools] |
|
600 | 600 | false.whatever= |
|
601 | 601 | true.priority=1 |
|
602 | 602 | true.executable=cat |
|
603 | 603 | # hg update -C 1 |
|
604 | 604 | $ hg merge -r 2 --config merge-patterns.f=true --config merge-tools.true.executable=/nonexistent/mergetool |
|
605 | 605 | couldn't find merge tool true (for pattern f) |
|
606 | 606 | merging f |
|
607 | 607 | couldn't find merge tool true (for pattern f) |
|
608 | 608 | merging f failed! |
|
609 | 609 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
610 | 610 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
611 | 611 | [1] |
|
612 | 612 | $ aftermerge |
|
613 | 613 | # cat f |
|
614 | 614 | revision 1 |
|
615 | 615 | space |
|
616 | 616 | # hg stat |
|
617 | 617 | M f |
|
618 | 618 | ? f.orig |
|
619 | 619 | # hg resolve --list |
|
620 | 620 | U f |
|
621 | 621 | |
|
622 | 622 | ui.merge overrules priority |
|
623 | 623 | |
|
624 | 624 | ui.merge specifies false: |
|
625 | 625 | |
|
626 | 626 | $ beforemerge |
|
627 | 627 | [merge-tools] |
|
628 | 628 | false.whatever= |
|
629 | 629 | true.priority=1 |
|
630 | 630 | true.executable=cat |
|
631 | 631 | # hg update -C 1 |
|
632 | 632 | $ hg merge -r 2 --config ui.merge=false |
|
633 | 633 | merging f |
|
634 | 634 | merging f failed! |
|
635 | 635 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
636 | 636 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
637 | 637 | [1] |
|
638 | 638 | $ aftermerge |
|
639 | 639 | # cat f |
|
640 | 640 | revision 1 |
|
641 | 641 | space |
|
642 | 642 | # hg stat |
|
643 | 643 | M f |
|
644 | 644 | ? f.orig |
|
645 | 645 | # hg resolve --list |
|
646 | 646 | U f |
|
647 | 647 | |
|
648 | 648 | ui.merge specifies internal:fail: |
|
649 | 649 | |
|
650 | 650 | $ beforemerge |
|
651 | 651 | [merge-tools] |
|
652 | 652 | false.whatever= |
|
653 | 653 | true.priority=1 |
|
654 | 654 | true.executable=cat |
|
655 | 655 | # hg update -C 1 |
|
656 | 656 | $ hg merge -r 2 --config ui.merge=internal:fail |
|
657 | 657 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
658 | 658 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
659 | 659 | [1] |
|
660 | 660 | $ aftermerge |
|
661 | 661 | # cat f |
|
662 | 662 | revision 1 |
|
663 | 663 | space |
|
664 | 664 | # hg stat |
|
665 | 665 | M f |
|
666 | 666 | # hg resolve --list |
|
667 | 667 | U f |
|
668 | 668 | |
|
669 | 669 | ui.merge specifies :local (without internal prefix): |
|
670 | 670 | |
|
671 | 671 | $ beforemerge |
|
672 | 672 | [merge-tools] |
|
673 | 673 | false.whatever= |
|
674 | 674 | true.priority=1 |
|
675 | 675 | true.executable=cat |
|
676 | 676 | # hg update -C 1 |
|
677 | 677 | $ hg merge -r 2 --config ui.merge=:local |
|
678 | 678 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
679 | 679 | (branch merge, don't forget to commit) |
|
680 | 680 | $ aftermerge |
|
681 | 681 | # cat f |
|
682 | 682 | revision 1 |
|
683 | 683 | space |
|
684 | 684 | # hg stat |
|
685 | 685 | M f |
|
686 | 686 | # hg resolve --list |
|
687 | 687 | R f |
|
688 | 688 | |
|
689 | 689 | ui.merge specifies internal:other: |
|
690 | 690 | |
|
691 | 691 | $ beforemerge |
|
692 | 692 | [merge-tools] |
|
693 | 693 | false.whatever= |
|
694 | 694 | true.priority=1 |
|
695 | 695 | true.executable=cat |
|
696 | 696 | # hg update -C 1 |
|
697 | 697 | $ hg merge -r 2 --config ui.merge=internal:other |
|
698 | 698 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
699 | 699 | (branch merge, don't forget to commit) |
|
700 | 700 | $ aftermerge |
|
701 | 701 | # cat f |
|
702 | 702 | revision 2 |
|
703 | 703 | space |
|
704 | 704 | # hg stat |
|
705 | 705 | M f |
|
706 | 706 | # hg resolve --list |
|
707 | 707 | R f |
|
708 | 708 | |
|
709 | 709 | ui.merge specifies internal:prompt: |
|
710 | 710 | |
|
711 | 711 | $ beforemerge |
|
712 | 712 | [merge-tools] |
|
713 | 713 | false.whatever= |
|
714 | 714 | true.priority=1 |
|
715 | 715 | true.executable=cat |
|
716 | 716 | # hg update -C 1 |
|
717 | 717 | $ hg merge -r 2 --config ui.merge=internal:prompt |
|
718 | 718 | file 'f' needs to be resolved. |
|
719 | 719 | You can keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved. |
|
720 | 720 | What do you want to do? u |
|
721 | 721 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
722 | 722 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
723 | 723 | [1] |
|
724 | 724 | $ aftermerge |
|
725 | 725 | # cat f |
|
726 | 726 | revision 1 |
|
727 | 727 | space |
|
728 | 728 | # hg stat |
|
729 | 729 | M f |
|
730 | 730 | # hg resolve --list |
|
731 | 731 | U f |
|
732 | 732 | |
|
733 | 733 | ui.merge specifies :prompt, with 'leave unresolved' chosen |
|
734 | 734 | |
|
735 | 735 | $ beforemerge |
|
736 | 736 | [merge-tools] |
|
737 | 737 | false.whatever= |
|
738 | 738 | true.priority=1 |
|
739 | 739 | true.executable=cat |
|
740 | 740 | # hg update -C 1 |
|
741 | 741 | $ hg merge -r 2 --config ui.merge=:prompt --config ui.interactive=True << EOF |
|
742 | 742 | > u |
|
743 | 743 | > EOF |
|
744 | 744 | file 'f' needs to be resolved. |
|
745 | 745 | You can keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved. |
|
746 | 746 | What do you want to do? u |
|
747 | 747 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
748 | 748 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
749 | 749 | [1] |
|
750 | 750 | $ aftermerge |
|
751 | 751 | # cat f |
|
752 | 752 | revision 1 |
|
753 | 753 | space |
|
754 | 754 | # hg stat |
|
755 | 755 | M f |
|
756 | 756 | # hg resolve --list |
|
757 | 757 | U f |
|
758 | 758 | |
|
759 | 759 | prompt with EOF |
|
760 | 760 | |
|
761 | 761 | $ beforemerge |
|
762 | 762 | [merge-tools] |
|
763 | 763 | false.whatever= |
|
764 | 764 | true.priority=1 |
|
765 | 765 | true.executable=cat |
|
766 | 766 | # hg update -C 1 |
|
767 | 767 | $ hg merge -r 2 --config ui.merge=internal:prompt --config ui.interactive=true |
|
768 | 768 | file 'f' needs to be resolved. |
|
769 | 769 | You can keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved. |
|
770 | 770 | What do you want to do? |
|
771 | 771 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
772 | 772 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
773 | 773 | [1] |
|
774 | 774 | $ aftermerge |
|
775 | 775 | # cat f |
|
776 | 776 | revision 1 |
|
777 | 777 | space |
|
778 | 778 | # hg stat |
|
779 | 779 | M f |
|
780 | 780 | # hg resolve --list |
|
781 | 781 | U f |
|
782 | 782 | $ hg resolve --all --config ui.merge=internal:prompt --config ui.interactive=true |
|
783 | 783 | file 'f' needs to be resolved. |
|
784 | 784 | You can keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved. |
|
785 | 785 | What do you want to do? |
|
786 | 786 | [1] |
|
787 | 787 | $ aftermerge |
|
788 | 788 | # cat f |
|
789 | 789 | revision 1 |
|
790 | 790 | space |
|
791 | 791 | # hg stat |
|
792 | 792 | M f |
|
793 | 793 | ? f.orig |
|
794 | 794 | # hg resolve --list |
|
795 | 795 | U f |
|
796 | 796 | $ rm f |
|
797 | 797 | $ hg resolve --all --config ui.merge=internal:prompt --config ui.interactive=true |
|
798 | 798 | file 'f' needs to be resolved. |
|
799 | 799 | You can keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved. |
|
800 | 800 | What do you want to do? |
|
801 | 801 | [1] |
|
802 | 802 | $ aftermerge |
|
803 | 803 | # cat f |
|
804 | 804 | revision 1 |
|
805 | 805 | space |
|
806 | 806 | # hg stat |
|
807 | 807 | M f |
|
808 | 808 | # hg resolve --list |
|
809 | 809 | U f |
|
810 | 810 | $ hg resolve --all --config ui.merge=internal:prompt |
|
811 | 811 | file 'f' needs to be resolved. |
|
812 | 812 | You can keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved. |
|
813 | 813 | What do you want to do? u |
|
814 | 814 | [1] |
|
815 | 815 | $ aftermerge |
|
816 | 816 | # cat f |
|
817 | 817 | revision 1 |
|
818 | 818 | space |
|
819 | 819 | # hg stat |
|
820 | 820 | M f |
|
821 | 821 | ? f.orig |
|
822 | 822 | # hg resolve --list |
|
823 | 823 | U f |
|
824 | 824 | |
|
825 | 825 | ui.merge specifies internal:dump: |
|
826 | 826 | |
|
827 | 827 | $ beforemerge |
|
828 | 828 | [merge-tools] |
|
829 | 829 | false.whatever= |
|
830 | 830 | true.priority=1 |
|
831 | 831 | true.executable=cat |
|
832 | 832 | # hg update -C 1 |
|
833 | 833 | $ hg merge -r 2 --config ui.merge=internal:dump |
|
834 | 834 | merging f |
|
835 | 835 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
836 | 836 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
837 | 837 | [1] |
|
838 | 838 | $ aftermerge |
|
839 | 839 | # cat f |
|
840 | 840 | revision 1 |
|
841 | 841 | space |
|
842 | 842 | # hg stat |
|
843 | 843 | M f |
|
844 | 844 | ? f.base |
|
845 | 845 | ? f.local |
|
846 | 846 | ? f.orig |
|
847 | 847 | ? f.other |
|
848 | 848 | # hg resolve --list |
|
849 | 849 | U f |
|
850 | 850 | |
|
851 | 851 | f.base: |
|
852 | 852 | |
|
853 | 853 | $ cat f.base |
|
854 | 854 | revision 0 |
|
855 | 855 | space |
|
856 | 856 | |
|
857 | 857 | f.local: |
|
858 | 858 | |
|
859 | 859 | $ cat f.local |
|
860 | 860 | revision 1 |
|
861 | 861 | space |
|
862 | 862 | |
|
863 | 863 | f.other: |
|
864 | 864 | |
|
865 | 865 | $ cat f.other |
|
866 | 866 | revision 2 |
|
867 | 867 | space |
|
868 | 868 | $ rm f.base f.local f.other |
|
869 | 869 | |
|
870 | 870 | check that internal:dump doesn't dump files if premerge runs |
|
871 | 871 | successfully |
|
872 | 872 | |
|
873 | 873 | $ beforemerge |
|
874 | 874 | [merge-tools] |
|
875 | 875 | false.whatever= |
|
876 | 876 | true.priority=1 |
|
877 | 877 | true.executable=cat |
|
878 | 878 | # hg update -C 1 |
|
879 | 879 | $ hg merge -r 3 --config ui.merge=internal:dump |
|
880 | 880 | merging f |
|
881 | 881 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
882 | 882 | (branch merge, don't forget to commit) |
|
883 | 883 | |
|
884 | 884 | $ aftermerge |
|
885 | 885 | # cat f |
|
886 | 886 | revision 1 |
|
887 | 887 | space |
|
888 | 888 | revision 3 |
|
889 | 889 | # hg stat |
|
890 | 890 | M f |
|
891 | 891 | # hg resolve --list |
|
892 | 892 | R f |
|
893 | 893 | |
|
894 | 894 | check that internal:forcedump dumps files, even if local and other can |
|
895 | 895 | be merged easily |
|
896 | 896 | |
|
897 | 897 | $ beforemerge |
|
898 | 898 | [merge-tools] |
|
899 | 899 | false.whatever= |
|
900 | 900 | true.priority=1 |
|
901 | 901 | true.executable=cat |
|
902 | 902 | # hg update -C 1 |
|
903 | 903 | $ hg merge -r 3 --config ui.merge=internal:forcedump |
|
904 | 904 | merging f |
|
905 | 905 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
906 | 906 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
907 | 907 | [1] |
|
908 | 908 | $ aftermerge |
|
909 | 909 | # cat f |
|
910 | 910 | revision 1 |
|
911 | 911 | space |
|
912 | 912 | # hg stat |
|
913 | 913 | M f |
|
914 | 914 | ? f.base |
|
915 | 915 | ? f.local |
|
916 | 916 | ? f.orig |
|
917 | 917 | ? f.other |
|
918 | 918 | # hg resolve --list |
|
919 | 919 | U f |
|
920 | 920 | |
|
921 | 921 | $ cat f.base |
|
922 | 922 | revision 0 |
|
923 | 923 | space |
|
924 | 924 | |
|
925 | 925 | $ cat f.local |
|
926 | 926 | revision 1 |
|
927 | 927 | space |
|
928 | 928 | |
|
929 | 929 | $ cat f.other |
|
930 | 930 | revision 0 |
|
931 | 931 | space |
|
932 | 932 | revision 3 |
|
933 | 933 | |
|
934 | 934 | $ rm -f f.base f.local f.other |
|
935 | 935 | |
|
936 | 936 | ui.merge specifies internal:other but is overruled by pattern for false: |
|
937 | 937 | |
|
938 | 938 | $ beforemerge |
|
939 | 939 | [merge-tools] |
|
940 | 940 | false.whatever= |
|
941 | 941 | true.priority=1 |
|
942 | 942 | true.executable=cat |
|
943 | 943 | # hg update -C 1 |
|
944 | 944 | $ hg merge -r 2 --config ui.merge=internal:other --config merge-patterns.f=false |
|
945 | 945 | merging f |
|
946 | 946 | merging f failed! |
|
947 | 947 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
948 | 948 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
949 | 949 | [1] |
|
950 | 950 | $ aftermerge |
|
951 | 951 | # cat f |
|
952 | 952 | revision 1 |
|
953 | 953 | space |
|
954 | 954 | # hg stat |
|
955 | 955 | M f |
|
956 | 956 | ? f.orig |
|
957 | 957 | # hg resolve --list |
|
958 | 958 | U f |
|
959 | 959 | |
|
960 | 960 | Premerge |
|
961 | 961 | |
|
962 | 962 | ui.merge specifies internal:other but is overruled by --tool=false |
|
963 | 963 | |
|
964 | 964 | $ beforemerge |
|
965 | 965 | [merge-tools] |
|
966 | 966 | false.whatever= |
|
967 | 967 | true.priority=1 |
|
968 | 968 | true.executable=cat |
|
969 | 969 | # hg update -C 1 |
|
970 | 970 | $ hg merge -r 2 --config ui.merge=internal:other --tool=false |
|
971 | 971 | merging f |
|
972 | 972 | merging f failed! |
|
973 | 973 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
974 | 974 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
975 | 975 | [1] |
|
976 | 976 | $ aftermerge |
|
977 | 977 | # cat f |
|
978 | 978 | revision 1 |
|
979 | 979 | space |
|
980 | 980 | # hg stat |
|
981 | 981 | M f |
|
982 | 982 | ? f.orig |
|
983 | 983 | # hg resolve --list |
|
984 | 984 | U f |
|
985 | 985 | |
|
986 | 986 | HGMERGE specifies internal:other but is overruled by --tool=false |
|
987 | 987 | |
|
988 | 988 | $ HGMERGE=internal:other ; export HGMERGE |
|
989 | 989 | $ beforemerge |
|
990 | 990 | [merge-tools] |
|
991 | 991 | false.whatever= |
|
992 | 992 | true.priority=1 |
|
993 | 993 | true.executable=cat |
|
994 | 994 | # hg update -C 1 |
|
995 | 995 | $ hg merge -r 2 --tool=false |
|
996 | 996 | merging f |
|
997 | 997 | merging f failed! |
|
998 | 998 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
999 | 999 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
1000 | 1000 | [1] |
|
1001 | 1001 | $ aftermerge |
|
1002 | 1002 | # cat f |
|
1003 | 1003 | revision 1 |
|
1004 | 1004 | space |
|
1005 | 1005 | # hg stat |
|
1006 | 1006 | M f |
|
1007 | 1007 | ? f.orig |
|
1008 | 1008 | # hg resolve --list |
|
1009 | 1009 | U f |
|
1010 | 1010 | |
|
1011 | 1011 | $ unset HGMERGE # make sure HGMERGE doesn't interfere with remaining tests |
|
1012 | 1012 | |
|
1013 | 1013 | update is a merge ... |
|
1014 | 1014 | |
|
1015 | 1015 | (this also tests that files reverted with '--rev REV' are treated as |
|
1016 | 1016 | "modified", even if none of mode, size and timestamp of them isn't |
|
1017 | 1017 | changed on the filesystem (see also issue4583)) |
|
1018 | 1018 | |
|
1019 | 1019 | $ cat >> $HGRCPATH <<EOF |
|
1020 | 1020 | > [fakedirstatewritetime] |
|
1021 | 1021 | > # emulate invoking dirstate.write() via repo.status() |
|
1022 | 1022 | > # at 2000-01-01 00:00 |
|
1023 | 1023 | > fakenow = 200001010000 |
|
1024 | 1024 | > EOF |
|
1025 | 1025 | |
|
1026 | 1026 | $ beforemerge |
|
1027 | 1027 | [merge-tools] |
|
1028 | 1028 | false.whatever= |
|
1029 | 1029 | true.priority=1 |
|
1030 | 1030 | true.executable=cat |
|
1031 | 1031 | # hg update -C 1 |
|
1032 | 1032 | $ hg update -q 0 |
|
1033 | 1033 | $ f -s f |
|
1034 | 1034 | f: size=17 |
|
1035 | 1035 | $ touch -t 200001010000 f |
|
1036 | 1036 | $ hg debugrebuildstate |
|
1037 | 1037 | $ cat >> $HGRCPATH <<EOF |
|
1038 | 1038 | > [extensions] |
|
1039 | 1039 | > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py |
|
1040 | 1040 | > EOF |
|
1041 | 1041 | $ hg revert -q -r 1 . |
|
1042 | 1042 | $ cat >> $HGRCPATH <<EOF |
|
1043 | 1043 | > [extensions] |
|
1044 | 1044 | > fakedirstatewritetime = ! |
|
1045 | 1045 | > EOF |
|
1046 | 1046 | $ f -s f |
|
1047 | 1047 | f: size=17 |
|
1048 | 1048 | $ touch -t 200001010000 f |
|
1049 | 1049 | $ hg status f |
|
1050 | 1050 | M f |
|
1051 | 1051 | $ hg update -r 2 |
|
1052 | 1052 | merging f |
|
1053 | 1053 | revision 1 |
|
1054 | 1054 | space |
|
1055 | 1055 | revision 0 |
|
1056 | 1056 | space |
|
1057 | 1057 | revision 2 |
|
1058 | 1058 | space |
|
1059 | 1059 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1060 | 1060 | $ aftermerge |
|
1061 | 1061 | # cat f |
|
1062 | 1062 | revision 1 |
|
1063 | 1063 | space |
|
1064 | 1064 | # hg stat |
|
1065 | 1065 | M f |
|
1066 | 1066 | # hg resolve --list |
|
1067 | 1067 | R f |
|
1068 | 1068 | |
|
1069 | 1069 | update should also have --tool |
|
1070 | 1070 | |
|
1071 | 1071 | $ beforemerge |
|
1072 | 1072 | [merge-tools] |
|
1073 | 1073 | false.whatever= |
|
1074 | 1074 | true.priority=1 |
|
1075 | 1075 | true.executable=cat |
|
1076 | 1076 | # hg update -C 1 |
|
1077 | 1077 | $ hg update -q 0 |
|
1078 | 1078 | $ f -s f |
|
1079 | 1079 | f: size=17 |
|
1080 | 1080 | $ touch -t 200001010000 f |
|
1081 | 1081 | $ hg debugrebuildstate |
|
1082 | 1082 | $ cat >> $HGRCPATH <<EOF |
|
1083 | 1083 | > [extensions] |
|
1084 | 1084 | > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py |
|
1085 | 1085 | > EOF |
|
1086 | 1086 | $ hg revert -q -r 1 . |
|
1087 | 1087 | $ cat >> $HGRCPATH <<EOF |
|
1088 | 1088 | > [extensions] |
|
1089 | 1089 | > fakedirstatewritetime = ! |
|
1090 | 1090 | > EOF |
|
1091 | 1091 | $ f -s f |
|
1092 | 1092 | f: size=17 |
|
1093 | 1093 | $ touch -t 200001010000 f |
|
1094 | 1094 | $ hg status f |
|
1095 | 1095 | M f |
|
1096 | 1096 | $ hg update -r 2 --tool false |
|
1097 | 1097 | merging f |
|
1098 | 1098 | merging f failed! |
|
1099 | 1099 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
1100 | 1100 | use 'hg resolve' to retry unresolved file merges |
|
1101 | 1101 | [1] |
|
1102 | 1102 | $ aftermerge |
|
1103 | 1103 | # cat f |
|
1104 | 1104 | revision 1 |
|
1105 | 1105 | space |
|
1106 | 1106 | # hg stat |
|
1107 | 1107 | M f |
|
1108 | 1108 | ? f.orig |
|
1109 | 1109 | # hg resolve --list |
|
1110 | 1110 | U f |
|
1111 | 1111 | |
|
1112 | 1112 | Default is silent simplemerge: |
|
1113 | 1113 | |
|
1114 | 1114 | $ beforemerge |
|
1115 | 1115 | [merge-tools] |
|
1116 | 1116 | false.whatever= |
|
1117 | 1117 | true.priority=1 |
|
1118 | 1118 | true.executable=cat |
|
1119 | 1119 | # hg update -C 1 |
|
1120 | 1120 | $ hg merge -r 3 |
|
1121 | 1121 | merging f |
|
1122 | 1122 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1123 | 1123 | (branch merge, don't forget to commit) |
|
1124 | 1124 | $ aftermerge |
|
1125 | 1125 | # cat f |
|
1126 | 1126 | revision 1 |
|
1127 | 1127 | space |
|
1128 | 1128 | revision 3 |
|
1129 | 1129 | # hg stat |
|
1130 | 1130 | M f |
|
1131 | 1131 | # hg resolve --list |
|
1132 | 1132 | R f |
|
1133 | 1133 | |
|
1134 | 1134 | .premerge=True is same: |
|
1135 | 1135 | |
|
1136 | 1136 | $ beforemerge |
|
1137 | 1137 | [merge-tools] |
|
1138 | 1138 | false.whatever= |
|
1139 | 1139 | true.priority=1 |
|
1140 | 1140 | true.executable=cat |
|
1141 | 1141 | # hg update -C 1 |
|
1142 | 1142 | $ hg merge -r 3 --config merge-tools.true.premerge=True |
|
1143 | 1143 | merging f |
|
1144 | 1144 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1145 | 1145 | (branch merge, don't forget to commit) |
|
1146 | 1146 | $ aftermerge |
|
1147 | 1147 | # cat f |
|
1148 | 1148 | revision 1 |
|
1149 | 1149 | space |
|
1150 | 1150 | revision 3 |
|
1151 | 1151 | # hg stat |
|
1152 | 1152 | M f |
|
1153 | 1153 | # hg resolve --list |
|
1154 | 1154 | R f |
|
1155 | 1155 | |
|
1156 | 1156 | .premerge=False executes merge-tool: |
|
1157 | 1157 | |
|
1158 | 1158 | $ beforemerge |
|
1159 | 1159 | [merge-tools] |
|
1160 | 1160 | false.whatever= |
|
1161 | 1161 | true.priority=1 |
|
1162 | 1162 | true.executable=cat |
|
1163 | 1163 | # hg update -C 1 |
|
1164 | 1164 | $ hg merge -r 3 --config merge-tools.true.premerge=False |
|
1165 | 1165 | merging f |
|
1166 | 1166 | revision 1 |
|
1167 | 1167 | space |
|
1168 | 1168 | revision 0 |
|
1169 | 1169 | space |
|
1170 | 1170 | revision 0 |
|
1171 | 1171 | space |
|
1172 | 1172 | revision 3 |
|
1173 | 1173 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1174 | 1174 | (branch merge, don't forget to commit) |
|
1175 | 1175 | $ aftermerge |
|
1176 | 1176 | # cat f |
|
1177 | 1177 | revision 1 |
|
1178 | 1178 | space |
|
1179 | 1179 | # hg stat |
|
1180 | 1180 | M f |
|
1181 | 1181 | # hg resolve --list |
|
1182 | 1182 | R f |
|
1183 | 1183 | |
|
1184 | 1184 | premerge=keep keeps conflict markers in: |
|
1185 | 1185 | |
|
1186 | 1186 | $ beforemerge |
|
1187 | 1187 | [merge-tools] |
|
1188 | 1188 | false.whatever= |
|
1189 | 1189 | true.priority=1 |
|
1190 | 1190 | true.executable=cat |
|
1191 | 1191 | # hg update -C 1 |
|
1192 | 1192 | $ hg merge -r 4 --config merge-tools.true.premerge=keep |
|
1193 | 1193 | merging f |
|
1194 | 1194 | <<<<<<< working copy: ef83787e2614 - test: revision 1 |
|
1195 | 1195 | revision 1 |
|
1196 | 1196 | space |
|
1197 | 1197 | ======= |
|
1198 | 1198 | revision 4 |
|
1199 | 1199 | >>>>>>> merge rev: 81448d39c9a0 - test: revision 4 |
|
1200 | 1200 | revision 0 |
|
1201 | 1201 | space |
|
1202 | 1202 | revision 4 |
|
1203 | 1203 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1204 | 1204 | (branch merge, don't forget to commit) |
|
1205 | 1205 | $ aftermerge |
|
1206 | 1206 | # cat f |
|
1207 | 1207 | <<<<<<< working copy: ef83787e2614 - test: revision 1 |
|
1208 | 1208 | revision 1 |
|
1209 | 1209 | space |
|
1210 | 1210 | ======= |
|
1211 | 1211 | revision 4 |
|
1212 | 1212 | >>>>>>> merge rev: 81448d39c9a0 - test: revision 4 |
|
1213 | 1213 | # hg stat |
|
1214 | 1214 | M f |
|
1215 | 1215 | # hg resolve --list |
|
1216 | 1216 | R f |
|
1217 | 1217 | |
|
1218 | 1218 | premerge=keep-merge3 keeps conflict markers with base content: |
|
1219 | 1219 | |
|
1220 | 1220 | $ beforemerge |
|
1221 | 1221 | [merge-tools] |
|
1222 | 1222 | false.whatever= |
|
1223 | 1223 | true.priority=1 |
|
1224 | 1224 | true.executable=cat |
|
1225 | 1225 | # hg update -C 1 |
|
1226 | 1226 | $ hg merge -r 4 --config merge-tools.true.premerge=keep-merge3 |
|
1227 | 1227 | merging f |
|
1228 | 1228 | <<<<<<< working copy: ef83787e2614 - test: revision 1 |
|
1229 | 1229 | revision 1 |
|
1230 | 1230 | space |
|
1231 | 1231 | ||||||| base |
|
1232 | 1232 | revision 0 |
|
1233 | 1233 | space |
|
1234 | 1234 | ======= |
|
1235 | 1235 | revision 4 |
|
1236 | 1236 | >>>>>>> merge rev: 81448d39c9a0 - test: revision 4 |
|
1237 | 1237 | revision 0 |
|
1238 | 1238 | space |
|
1239 | 1239 | revision 4 |
|
1240 | 1240 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1241 | 1241 | (branch merge, don't forget to commit) |
|
1242 | 1242 | $ aftermerge |
|
1243 | 1243 | # cat f |
|
1244 | 1244 | <<<<<<< working copy: ef83787e2614 - test: revision 1 |
|
1245 | 1245 | revision 1 |
|
1246 | 1246 | space |
|
1247 | 1247 | ||||||| base |
|
1248 | 1248 | revision 0 |
|
1249 | 1249 | space |
|
1250 | 1250 | ======= |
|
1251 | 1251 | revision 4 |
|
1252 | 1252 | >>>>>>> merge rev: 81448d39c9a0 - test: revision 4 |
|
1253 | 1253 | # hg stat |
|
1254 | 1254 | M f |
|
1255 | 1255 | # hg resolve --list |
|
1256 | 1256 | R f |
|
1257 | 1257 | |
|
1258 | 1258 | premerge=keep respects ui.mergemarkers=basic: |
|
1259 | 1259 | |
|
1260 | 1260 | $ beforemerge |
|
1261 | 1261 | [merge-tools] |
|
1262 | 1262 | false.whatever= |
|
1263 | 1263 | true.priority=1 |
|
1264 | 1264 | true.executable=cat |
|
1265 | 1265 | # hg update -C 1 |
|
1266 | 1266 | $ hg merge -r 4 --config merge-tools.true.premerge=keep --config ui.mergemarkers=basic |
|
1267 | 1267 | merging f |
|
1268 | 1268 | <<<<<<< working copy |
|
1269 | 1269 | revision 1 |
|
1270 | 1270 | space |
|
1271 | 1271 | ======= |
|
1272 | 1272 | revision 4 |
|
1273 | 1273 | >>>>>>> merge rev |
|
1274 | 1274 | revision 0 |
|
1275 | 1275 | space |
|
1276 | 1276 | revision 4 |
|
1277 | 1277 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1278 | 1278 | (branch merge, don't forget to commit) |
|
1279 | 1279 | $ aftermerge |
|
1280 | 1280 | # cat f |
|
1281 | 1281 | <<<<<<< working copy |
|
1282 | 1282 | revision 1 |
|
1283 | 1283 | space |
|
1284 | 1284 | ======= |
|
1285 | 1285 | revision 4 |
|
1286 | 1286 | >>>>>>> merge rev |
|
1287 | 1287 | # hg stat |
|
1288 | 1288 | M f |
|
1289 | 1289 | # hg resolve --list |
|
1290 | 1290 | R f |
|
1291 | 1291 | |
|
1292 | 1292 | premerge=keep ignores ui.mergemarkers=basic if true.mergemarkers=detailed: |
|
1293 | 1293 | |
|
1294 | 1294 | $ beforemerge |
|
1295 | 1295 | [merge-tools] |
|
1296 | 1296 | false.whatever= |
|
1297 | 1297 | true.priority=1 |
|
1298 | 1298 | true.executable=cat |
|
1299 | 1299 | # hg update -C 1 |
|
1300 | 1300 | $ hg merge -r 4 --config merge-tools.true.premerge=keep \ |
|
1301 | 1301 | > --config ui.mergemarkers=basic \ |
|
1302 | 1302 | > --config merge-tools.true.mergemarkers=detailed |
|
1303 | 1303 | merging f |
|
1304 | 1304 | <<<<<<< working copy: ef83787e2614 - test: revision 1 |
|
1305 | 1305 | revision 1 |
|
1306 | 1306 | space |
|
1307 | 1307 | ======= |
|
1308 | 1308 | revision 4 |
|
1309 | 1309 | >>>>>>> merge rev: 81448d39c9a0 - test: revision 4 |
|
1310 | 1310 | revision 0 |
|
1311 | 1311 | space |
|
1312 | 1312 | revision 4 |
|
1313 | 1313 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1314 | 1314 | (branch merge, don't forget to commit) |
|
1315 | 1315 | $ aftermerge |
|
1316 | 1316 | # cat f |
|
1317 | 1317 | <<<<<<< working copy: ef83787e2614 - test: revision 1 |
|
1318 | 1318 | revision 1 |
|
1319 | 1319 | space |
|
1320 | 1320 | ======= |
|
1321 | 1321 | revision 4 |
|
1322 | 1322 | >>>>>>> merge rev: 81448d39c9a0 - test: revision 4 |
|
1323 | 1323 | # hg stat |
|
1324 | 1324 | M f |
|
1325 | 1325 | # hg resolve --list |
|
1326 | 1326 | R f |
|
1327 | 1327 | |
|
1328 | 1328 | premerge=keep respects ui.mergemarkertemplate instead of |
|
1329 | 1329 | true.mergemarkertemplate if true.mergemarkers=basic: |
|
1330 | 1330 | |
|
1331 | 1331 | $ beforemerge |
|
1332 | 1332 | [merge-tools] |
|
1333 | 1333 | false.whatever= |
|
1334 | 1334 | true.priority=1 |
|
1335 | 1335 | true.executable=cat |
|
1336 | 1336 | # hg update -C 1 |
|
1337 | 1337 | $ hg merge -r 4 --config merge-tools.true.premerge=keep \ |
|
1338 | 1338 | > --config ui.mergemarkertemplate='uitmpl {rev}' \ |
|
1339 | 1339 | > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' |
|
1340 | 1340 | merging f |
|
1341 | 1341 | <<<<<<< working copy: uitmpl 1 |
|
1342 | 1342 | revision 1 |
|
1343 | 1343 | space |
|
1344 | 1344 | ======= |
|
1345 | 1345 | revision 4 |
|
1346 | 1346 | >>>>>>> merge rev: uitmpl 4 |
|
1347 | 1347 | revision 0 |
|
1348 | 1348 | space |
|
1349 | 1349 | revision 4 |
|
1350 | 1350 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1351 | 1351 | (branch merge, don't forget to commit) |
|
1352 | 1352 | $ aftermerge |
|
1353 | 1353 | # cat f |
|
1354 | 1354 | <<<<<<< working copy: uitmpl 1 |
|
1355 | 1355 | revision 1 |
|
1356 | 1356 | space |
|
1357 | 1357 | ======= |
|
1358 | 1358 | revision 4 |
|
1359 | 1359 | >>>>>>> merge rev: uitmpl 4 |
|
1360 | 1360 | # hg stat |
|
1361 | 1361 | M f |
|
1362 | 1362 | # hg resolve --list |
|
1363 | 1363 | R f |
|
1364 | 1364 | |
|
1365 | 1365 | premerge=keep respects true.mergemarkertemplate instead of |
|
1366 | 1366 | true.mergemarkertemplate if true.mergemarkers=detailed: |
|
1367 | 1367 | |
|
1368 | 1368 | $ beforemerge |
|
1369 | 1369 | [merge-tools] |
|
1370 | 1370 | false.whatever= |
|
1371 | 1371 | true.priority=1 |
|
1372 | 1372 | true.executable=cat |
|
1373 | 1373 | # hg update -C 1 |
|
1374 | 1374 | $ hg merge -r 4 --config merge-tools.true.premerge=keep \ |
|
1375 | 1375 | > --config ui.mergemarkertemplate='uitmpl {rev}' \ |
|
1376 | 1376 | > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \ |
|
1377 | 1377 | > --config merge-tools.true.mergemarkers=detailed |
|
1378 | 1378 | merging f |
|
1379 | 1379 | <<<<<<< working copy: tooltmpl ef83787e2614 |
|
1380 | 1380 | revision 1 |
|
1381 | 1381 | space |
|
1382 | 1382 | ======= |
|
1383 | 1383 | revision 4 |
|
1384 | 1384 | >>>>>>> merge rev: tooltmpl 81448d39c9a0 |
|
1385 | 1385 | revision 0 |
|
1386 | 1386 | space |
|
1387 | 1387 | revision 4 |
|
1388 | 1388 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1389 | 1389 | (branch merge, don't forget to commit) |
|
1390 | 1390 | $ aftermerge |
|
1391 | 1391 | # cat f |
|
1392 | 1392 | <<<<<<< working copy: tooltmpl ef83787e2614 |
|
1393 | 1393 | revision 1 |
|
1394 | 1394 | space |
|
1395 | 1395 | ======= |
|
1396 | 1396 | revision 4 |
|
1397 | 1397 | >>>>>>> merge rev: tooltmpl 81448d39c9a0 |
|
1398 | 1398 | # hg stat |
|
1399 | 1399 | M f |
|
1400 | 1400 | # hg resolve --list |
|
1401 | 1401 | R f |
|
1402 | 1402 | |
|
1403 | 1403 | Tool execution |
|
1404 | 1404 | |
|
1405 | 1405 | set tools.args explicit to include $base $local $other $output: |
|
1406 | 1406 | |
|
1407 | 1407 | $ beforemerge |
|
1408 | 1408 | [merge-tools] |
|
1409 | 1409 | false.whatever= |
|
1410 | 1410 | true.priority=1 |
|
1411 | 1411 | true.executable=cat |
|
1412 | 1412 | # hg update -C 1 |
|
1413 | 1413 | $ hg merge -r 2 --config merge-tools.true.executable=head --config merge-tools.true.args='$base $local $other $output' \ |
|
1414 | 1414 | > | sed 's,==> .* <==,==> ... <==,g' |
|
1415 | 1415 | merging f |
|
1416 | 1416 | ==> ... <== |
|
1417 | 1417 | revision 0 |
|
1418 | 1418 | space |
|
1419 | 1419 | |
|
1420 | 1420 | ==> ... <== |
|
1421 | 1421 | revision 1 |
|
1422 | 1422 | space |
|
1423 | 1423 | |
|
1424 | 1424 | ==> ... <== |
|
1425 | 1425 | revision 2 |
|
1426 | 1426 | space |
|
1427 | 1427 | |
|
1428 | 1428 | ==> ... <== |
|
1429 | 1429 | revision 1 |
|
1430 | 1430 | space |
|
1431 | 1431 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1432 | 1432 | (branch merge, don't forget to commit) |
|
1433 | 1433 | $ aftermerge |
|
1434 | 1434 | # cat f |
|
1435 | 1435 | revision 1 |
|
1436 | 1436 | space |
|
1437 | 1437 | # hg stat |
|
1438 | 1438 | M f |
|
1439 | 1439 | # hg resolve --list |
|
1440 | 1440 | R f |
|
1441 | 1441 | |
|
1442 | 1442 | Merge with "echo mergeresult > $local": |
|
1443 | 1443 | |
|
1444 | 1444 | $ beforemerge |
|
1445 | 1445 | [merge-tools] |
|
1446 | 1446 | false.whatever= |
|
1447 | 1447 | true.priority=1 |
|
1448 | 1448 | true.executable=cat |
|
1449 | 1449 | # hg update -C 1 |
|
1450 | 1450 | $ hg merge -r 2 --config merge-tools.true.executable=echo --config merge-tools.true.args='mergeresult > $local' |
|
1451 | 1451 | merging f |
|
1452 | 1452 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1453 | 1453 | (branch merge, don't forget to commit) |
|
1454 | 1454 | $ aftermerge |
|
1455 | 1455 | # cat f |
|
1456 | 1456 | mergeresult |
|
1457 | 1457 | # hg stat |
|
1458 | 1458 | M f |
|
1459 | 1459 | # hg resolve --list |
|
1460 | 1460 | R f |
|
1461 | 1461 | |
|
1462 | 1462 | - and $local is the file f: |
|
1463 | 1463 | |
|
1464 | 1464 | $ beforemerge |
|
1465 | 1465 | [merge-tools] |
|
1466 | 1466 | false.whatever= |
|
1467 | 1467 | true.priority=1 |
|
1468 | 1468 | true.executable=cat |
|
1469 | 1469 | # hg update -C 1 |
|
1470 | 1470 | $ hg merge -r 2 --config merge-tools.true.executable=echo --config merge-tools.true.args='mergeresult > f' |
|
1471 | 1471 | merging f |
|
1472 | 1472 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1473 | 1473 | (branch merge, don't forget to commit) |
|
1474 | 1474 | $ aftermerge |
|
1475 | 1475 | # cat f |
|
1476 | 1476 | mergeresult |
|
1477 | 1477 | # hg stat |
|
1478 | 1478 | M f |
|
1479 | 1479 | # hg resolve --list |
|
1480 | 1480 | R f |
|
1481 | 1481 | |
|
1482 | 1482 | Merge with "echo mergeresult > $output" - the variable is a bit magic: |
|
1483 | 1483 | |
|
1484 | 1484 | $ beforemerge |
|
1485 | 1485 | [merge-tools] |
|
1486 | 1486 | false.whatever= |
|
1487 | 1487 | true.priority=1 |
|
1488 | 1488 | true.executable=cat |
|
1489 | 1489 | # hg update -C 1 |
|
1490 | 1490 | $ hg merge -r 2 --config merge-tools.true.executable=echo --config merge-tools.true.args='mergeresult > $output' |
|
1491 | 1491 | merging f |
|
1492 | 1492 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1493 | 1493 | (branch merge, don't forget to commit) |
|
1494 | 1494 | $ aftermerge |
|
1495 | 1495 | # cat f |
|
1496 | 1496 | mergeresult |
|
1497 | 1497 | # hg stat |
|
1498 | 1498 | M f |
|
1499 | 1499 | # hg resolve --list |
|
1500 | 1500 | R f |
|
1501 | 1501 | |
|
1502 | 1502 | Merge using tool with a path that must be quoted: |
|
1503 | 1503 | |
|
1504 | 1504 | $ beforemerge |
|
1505 | 1505 | [merge-tools] |
|
1506 | 1506 | false.whatever= |
|
1507 | 1507 | true.priority=1 |
|
1508 | 1508 | true.executable=cat |
|
1509 | 1509 | # hg update -C 1 |
|
1510 | 1510 | $ cat <<EOF > 'my merge tool' |
|
1511 | 1511 | > cat "\$1" "\$2" "\$3" > "\$4" |
|
1512 | 1512 | > EOF |
|
1513 | 1513 | $ hg --config merge-tools.true.executable='sh' \ |
|
1514 | 1514 | > --config merge-tools.true.args='"./my merge tool" $base $local $other $output' \ |
|
1515 | 1515 | > merge -r 2 |
|
1516 | 1516 | merging f |
|
1517 | 1517 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1518 | 1518 | (branch merge, don't forget to commit) |
|
1519 | 1519 | $ rm -f 'my merge tool' |
|
1520 | 1520 | $ aftermerge |
|
1521 | 1521 | # cat f |
|
1522 | 1522 | revision 0 |
|
1523 | 1523 | space |
|
1524 | 1524 | revision 1 |
|
1525 | 1525 | space |
|
1526 | 1526 | revision 2 |
|
1527 | 1527 | space |
|
1528 | 1528 | # hg stat |
|
1529 | 1529 | M f |
|
1530 | 1530 | # hg resolve --list |
|
1531 | 1531 | R f |
|
1532 | 1532 | |
|
1533 | 1533 | Merge using a tool that supports labellocal, labelother, and labelbase, checking |
|
1534 | 1534 | that they're quoted properly as well. This is using the default 'basic' |
|
1535 | 1535 | mergemarkers even though ui.mergemarkers is 'detailed', so it's ignoring both |
|
1536 | 1536 | mergemarkertemplate settings: |
|
1537 | 1537 | |
|
1538 | 1538 | $ beforemerge |
|
1539 | 1539 | [merge-tools] |
|
1540 | 1540 | false.whatever= |
|
1541 | 1541 | true.priority=1 |
|
1542 | 1542 | true.executable=cat |
|
1543 | 1543 | # hg update -C 1 |
|
1544 | 1544 | $ cat <<EOF > printargs_merge_tool |
|
1545 | 1545 | > while test \$# -gt 0; do echo arg: \"\$1\"; shift; done |
|
1546 | 1546 | > EOF |
|
1547 | 1547 | $ hg --config merge-tools.true.executable='sh' \ |
|
1548 | 1548 | > --config merge-tools.true.args='./printargs_merge_tool ll:$labellocal lo: $labelother lb:$labelbase": "$base' \ |
|
1549 | 1549 | > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \ |
|
1550 | 1550 | > --config ui.mergemarkertemplate='uitmpl {rev}' \ |
|
1551 | 1551 | > --config ui.mergemarkers=detailed \ |
|
1552 | 1552 | > merge -r 2 |
|
1553 | 1553 | merging f |
|
1554 | 1554 | arg: "ll:working copy" |
|
1555 | 1555 | arg: "lo:" |
|
1556 | 1556 | arg: "merge rev" |
|
1557 | 1557 | arg: "lb:base: */f~base.*" (glob) |
|
1558 | 1558 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1559 | 1559 | (branch merge, don't forget to commit) |
|
1560 | 1560 | $ rm -f 'printargs_merge_tool' |
|
1561 | 1561 | |
|
1562 | 1562 | Same test with experimental.mergetempdirprefix set: |
|
1563 | 1563 | |
|
1564 | 1564 | $ beforemerge |
|
1565 | 1565 | [merge-tools] |
|
1566 | 1566 | false.whatever= |
|
1567 | 1567 | true.priority=1 |
|
1568 | 1568 | true.executable=cat |
|
1569 | 1569 | # hg update -C 1 |
|
1570 | 1570 | $ cat <<EOF > printargs_merge_tool |
|
1571 | 1571 | > while test \$# -gt 0; do echo arg: \"\$1\"; shift; done |
|
1572 | 1572 | > EOF |
|
1573 | 1573 | $ hg --config experimental.mergetempdirprefix=$TESTTMP/hgmerge. \ |
|
1574 | 1574 | > --config merge-tools.true.executable='sh' \ |
|
1575 | 1575 | > --config merge-tools.true.args='./printargs_merge_tool ll:$labellocal lo: $labelother lb:$labelbase": "$base' \ |
|
1576 | 1576 | > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \ |
|
1577 | 1577 | > --config ui.mergemarkertemplate='uitmpl {rev}' \ |
|
1578 | 1578 | > --config ui.mergemarkers=detailed \ |
|
1579 | 1579 | > merge -r 2 |
|
1580 | 1580 | merging f |
|
1581 | 1581 | arg: "ll:working copy" |
|
1582 | 1582 | arg: "lo:" |
|
1583 | 1583 | arg: "merge rev" |
|
1584 | 1584 | arg: "lb:base: */hgmerge.*/f~base" (glob) |
|
1585 | 1585 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1586 | 1586 | (branch merge, don't forget to commit) |
|
1587 | 1587 | $ rm -f 'printargs_merge_tool' |
|
1588 | 1588 | |
|
1589 | 1589 | Merge using a tool that supports labellocal, labelother, and labelbase, checking |
|
1590 | 1590 | that they're quoted properly as well. This is using 'detailed' mergemarkers, |
|
1591 | 1591 | even though ui.mergemarkers is 'basic', and using the tool's |
|
1592 | 1592 | mergemarkertemplate: |
|
1593 | 1593 | |
|
1594 | 1594 | $ beforemerge |
|
1595 | 1595 | [merge-tools] |
|
1596 | 1596 | false.whatever= |
|
1597 | 1597 | true.priority=1 |
|
1598 | 1598 | true.executable=cat |
|
1599 | 1599 | # hg update -C 1 |
|
1600 | 1600 | $ cat <<EOF > printargs_merge_tool |
|
1601 | 1601 | > while test \$# -gt 0; do echo arg: \"\$1\"; shift; done |
|
1602 | 1602 | > EOF |
|
1603 | 1603 | $ hg --config merge-tools.true.executable='sh' \ |
|
1604 | 1604 | > --config merge-tools.true.args='./printargs_merge_tool ll:$labellocal lo: $labelother lb:$labelbase": "$base' \ |
|
1605 | 1605 | > --config merge-tools.true.mergemarkers=detailed \ |
|
1606 | 1606 | > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \ |
|
1607 | 1607 | > --config ui.mergemarkertemplate='uitmpl {rev}' \ |
|
1608 | 1608 | > --config ui.mergemarkers=basic \ |
|
1609 | 1609 | > merge -r 2 |
|
1610 | 1610 | merging f |
|
1611 | 1611 | arg: "ll:working copy: tooltmpl ef83787e2614" |
|
1612 | 1612 | arg: "lo:" |
|
1613 | 1613 | arg: "merge rev: tooltmpl 0185f4e0cf02" |
|
1614 | 1614 | arg: "lb:base: */f~base.*" (glob) |
|
1615 | 1615 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1616 | 1616 | (branch merge, don't forget to commit) |
|
1617 | 1617 | $ rm -f 'printargs_merge_tool' |
|
1618 | 1618 | |
|
1619 | 1619 | The merge tool still gets labellocal and labelother as 'basic' even when |
|
1620 | 1620 | premerge=keep is used and has 'detailed' markers: |
|
1621 | 1621 | |
|
1622 | 1622 | $ beforemerge |
|
1623 | 1623 | [merge-tools] |
|
1624 | 1624 | false.whatever= |
|
1625 | 1625 | true.priority=1 |
|
1626 | 1626 | true.executable=cat |
|
1627 | 1627 | # hg update -C 1 |
|
1628 | 1628 | $ cat <<EOF > mytool |
|
1629 | 1629 | > echo labellocal: \"\$1\" |
|
1630 | 1630 | > echo labelother: \"\$2\" |
|
1631 | 1631 | > echo "output (arg)": \"\$3\" |
|
1632 | 1632 | > echo "output (contents)": |
|
1633 | 1633 | > cat "\$3" |
|
1634 | 1634 | > EOF |
|
1635 | 1635 | $ hg --config merge-tools.true.executable='sh' \ |
|
1636 | 1636 | > --config merge-tools.true.args='mytool $labellocal $labelother $output' \ |
|
1637 | 1637 | > --config merge-tools.true.premerge=keep \ |
|
1638 | 1638 | > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \ |
|
1639 | 1639 | > --config ui.mergemarkertemplate='uitmpl {rev}' \ |
|
1640 | 1640 | > --config ui.mergemarkers=detailed \ |
|
1641 | 1641 | > merge -r 2 |
|
1642 | 1642 | merging f |
|
1643 | 1643 | labellocal: "working copy" |
|
1644 | 1644 | labelother: "merge rev" |
|
1645 | 1645 | output (arg): "$TESTTMP/repo/f" |
|
1646 | 1646 | output (contents): |
|
1647 | 1647 | <<<<<<< working copy: uitmpl 1 |
|
1648 | 1648 | revision 1 |
|
1649 | 1649 | ======= |
|
1650 | 1650 | revision 2 |
|
1651 | 1651 | >>>>>>> merge rev: uitmpl 2 |
|
1652 | 1652 | space |
|
1653 | 1653 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1654 | 1654 | (branch merge, don't forget to commit) |
|
1655 | 1655 | $ rm -f 'mytool' |
|
1656 | 1656 | |
|
1657 | 1657 | premerge=keep uses the *tool's* mergemarkertemplate if tool's |
|
1658 | 1658 | mergemarkers=detailed; labellocal and labelother also use the tool's template |
|
1659 | 1659 | |
|
1660 | 1660 | $ beforemerge |
|
1661 | 1661 | [merge-tools] |
|
1662 | 1662 | false.whatever= |
|
1663 | 1663 | true.priority=1 |
|
1664 | 1664 | true.executable=cat |
|
1665 | 1665 | # hg update -C 1 |
|
1666 | 1666 | $ cat <<EOF > mytool |
|
1667 | 1667 | > echo labellocal: \"\$1\" |
|
1668 | 1668 | > echo labelother: \"\$2\" |
|
1669 | 1669 | > echo "output (arg)": \"\$3\" |
|
1670 | 1670 | > echo "output (contents)": |
|
1671 | 1671 | > cat "\$3" |
|
1672 | 1672 | > EOF |
|
1673 | 1673 | $ hg --config merge-tools.true.executable='sh' \ |
|
1674 | 1674 | > --config merge-tools.true.args='mytool $labellocal $labelother $output' \ |
|
1675 | 1675 | > --config merge-tools.true.premerge=keep \ |
|
1676 | 1676 | > --config merge-tools.true.mergemarkers=detailed \ |
|
1677 | 1677 | > --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \ |
|
1678 | 1678 | > --config ui.mergemarkertemplate='uitmpl {rev}' \ |
|
1679 | 1679 | > --config ui.mergemarkers=detailed \ |
|
1680 | 1680 | > merge -r 2 |
|
1681 | 1681 | merging f |
|
1682 | 1682 | labellocal: "working copy: tooltmpl ef83787e2614" |
|
1683 | 1683 | labelother: "merge rev: tooltmpl 0185f4e0cf02" |
|
1684 | 1684 | output (arg): "$TESTTMP/repo/f" |
|
1685 | 1685 | output (contents): |
|
1686 | 1686 | <<<<<<< working copy: tooltmpl ef83787e2614 |
|
1687 | 1687 | revision 1 |
|
1688 | 1688 | ======= |
|
1689 | 1689 | revision 2 |
|
1690 | 1690 | >>>>>>> merge rev: tooltmpl 0185f4e0cf02 |
|
1691 | 1691 | space |
|
1692 | 1692 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1693 | 1693 | (branch merge, don't forget to commit) |
|
1694 | 1694 | $ rm -f 'mytool' |
|
1695 | 1695 | |
|
1696 | 1696 | Issue3581: Merging a filename that needs to be quoted |
|
1697 | 1697 | (This test doesn't work on Windows filesystems even on Linux, so check |
|
1698 | 1698 | for Unix-like permission) |
|
1699 | 1699 | |
|
1700 | 1700 | #if unix-permissions |
|
1701 | 1701 | $ beforemerge |
|
1702 | 1702 | [merge-tools] |
|
1703 | 1703 | false.whatever= |
|
1704 | 1704 | true.priority=1 |
|
1705 | 1705 | true.executable=cat |
|
1706 | 1706 | # hg update -C 1 |
|
1707 | 1707 | $ echo "revision 5" > '"; exit 1; echo "' |
|
1708 | 1708 | $ hg commit -Am "revision 5" |
|
1709 | 1709 | adding "; exit 1; echo " |
|
1710 | 1710 | warning: filename contains '"', which is reserved on Windows: '"; exit 1; echo "' |
|
1711 | 1711 | $ hg update -C 1 > /dev/null |
|
1712 | 1712 | $ echo "revision 6" > '"; exit 1; echo "' |
|
1713 | 1713 | $ hg commit -Am "revision 6" |
|
1714 | 1714 | adding "; exit 1; echo " |
|
1715 | 1715 | warning: filename contains '"', which is reserved on Windows: '"; exit 1; echo "' |
|
1716 | 1716 | created new head |
|
1717 | 1717 | $ hg merge --config merge-tools.true.executable="true" -r 5 |
|
1718 | 1718 | merging "; exit 1; echo " |
|
1719 | 1719 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1720 | 1720 | (branch merge, don't forget to commit) |
|
1721 | 1721 | $ hg update -C 1 > /dev/null |
|
1722 | 1722 | |
|
1723 | 1723 | #else |
|
1724 | 1724 | |
|
1725 | 1725 | Match the non-portable filename commits above for test stability |
|
1726 | 1726 | |
|
1727 | 1727 | $ hg import --bypass -q - << EOF |
|
1728 | 1728 | > # HG changeset patch |
|
1729 | 1729 | > revision 5 |
|
1730 | 1730 | > |
|
1731 | 1731 | > diff --git a/"; exit 1; echo " b/"; exit 1; echo " |
|
1732 | 1732 | > new file mode 100644 |
|
1733 | 1733 | > --- /dev/null |
|
1734 | 1734 | > +++ b/"; exit 1; echo " |
|
1735 | 1735 | > @@ -0,0 +1,1 @@ |
|
1736 | 1736 | > +revision 5 |
|
1737 | 1737 | > EOF |
|
1738 | 1738 | |
|
1739 | 1739 | $ hg import --bypass -q - << EOF |
|
1740 | 1740 | > # HG changeset patch |
|
1741 | 1741 | > revision 6 |
|
1742 | 1742 | > |
|
1743 | 1743 | > diff --git a/"; exit 1; echo " b/"; exit 1; echo " |
|
1744 | 1744 | > new file mode 100644 |
|
1745 | 1745 | > --- /dev/null |
|
1746 | 1746 | > +++ b/"; exit 1; echo " |
|
1747 | 1747 | > @@ -0,0 +1,1 @@ |
|
1748 | 1748 | > +revision 6 |
|
1749 | 1749 | > EOF |
|
1750 | 1750 | |
|
1751 | 1751 | #endif |
|
1752 | 1752 | |
|
1753 | 1753 | Merge post-processing |
|
1754 | 1754 | |
|
1755 | 1755 | cat is a bad merge-tool and doesn't change: |
|
1756 | 1756 | |
|
1757 | 1757 | $ beforemerge |
|
1758 | 1758 | [merge-tools] |
|
1759 | 1759 | false.whatever= |
|
1760 | 1760 | true.priority=1 |
|
1761 | 1761 | true.executable=cat |
|
1762 | 1762 | # hg update -C 1 |
|
1763 | 1763 | $ hg merge -y -r 2 --config merge-tools.true.checkchanged=1 |
|
1764 | 1764 | merging f |
|
1765 | 1765 | revision 1 |
|
1766 | 1766 | space |
|
1767 | 1767 | revision 0 |
|
1768 | 1768 | space |
|
1769 | 1769 | revision 2 |
|
1770 | 1770 | space |
|
1771 | 1771 | output file f appears unchanged |
|
1772 | 1772 | was merge successful (yn)? n |
|
1773 | 1773 | merging f failed! |
|
1774 | 1774 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
1775 | 1775 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
1776 | 1776 | [1] |
|
1777 | 1777 | $ aftermerge |
|
1778 | 1778 | # cat f |
|
1779 | 1779 | revision 1 |
|
1780 | 1780 | space |
|
1781 | 1781 | # hg stat |
|
1782 | 1782 | M f |
|
1783 | 1783 | ? f.orig |
|
1784 | 1784 | # hg resolve --list |
|
1785 | 1785 | U f |
|
1786 | 1786 | |
|
1787 | 1787 | missingbinary is a merge-tool that doesn't exist: |
|
1788 | 1788 | |
|
1789 | 1789 | $ echo "missingbinary.executable=doesnotexist" >> .hg/hgrc |
|
1790 | 1790 | $ beforemerge |
|
1791 | 1791 | [merge-tools] |
|
1792 | 1792 | false.whatever= |
|
1793 | 1793 | true.priority=1 |
|
1794 | 1794 | true.executable=cat |
|
1795 | 1795 | missingbinary.executable=doesnotexist |
|
1796 | 1796 | # hg update -C 1 |
|
1797 | 1797 | $ hg merge -y -r 2 --config ui.merge=missingbinary |
|
1798 | 1798 | couldn't find merge tool missingbinary (for pattern f) |
|
1799 | 1799 | merging f |
|
1800 | 1800 | couldn't find merge tool missingbinary (for pattern f) |
|
1801 | 1801 | revision 1 |
|
1802 | 1802 | space |
|
1803 | 1803 | revision 0 |
|
1804 | 1804 | space |
|
1805 | 1805 | revision 2 |
|
1806 | 1806 | space |
|
1807 | 1807 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1808 | 1808 | (branch merge, don't forget to commit) |
|
1809 | 1809 | |
|
1810 | 1810 | $ hg update -q -C 1 |
|
1811 | 1811 | $ rm f |
|
1812 | 1812 | |
|
1813 | 1813 | internal merge cannot handle symlinks and shouldn't try: |
|
1814 | 1814 | |
|
1815 | 1815 | #if symlink |
|
1816 | 1816 | |
|
1817 | 1817 | $ ln -s symlink f |
|
1818 | 1818 | $ hg commit -qm 'f is symlink' |
|
1819 | 1819 | |
|
1820 | 1820 | #else |
|
1821 | 1821 | |
|
1822 | 1822 | $ hg import --bypass -q - << EOF |
|
1823 | 1823 | > # HG changeset patch |
|
1824 | 1824 | > f is symlink |
|
1825 | 1825 | > |
|
1826 | 1826 | > diff --git a/f b/f |
|
1827 | 1827 | > old mode 100644 |
|
1828 | 1828 | > new mode 120000 |
|
1829 | 1829 | > --- a/f |
|
1830 | 1830 | > +++ b/f |
|
1831 | 1831 | > @@ -1,2 +1,1 @@ |
|
1832 | 1832 | > -revision 1 |
|
1833 | 1833 | > -space |
|
1834 | 1834 | > +symlink |
|
1835 | 1835 | > \ No newline at end of file |
|
1836 | 1836 | > EOF |
|
1837 | 1837 | |
|
1838 | 1838 | Resolve 'other [destination] changed f which local [working copy] deleted' prompt |
|
1839 | 1839 | $ hg up -q -C --config ui.interactive=True << EOF |
|
1840 | 1840 | > c |
|
1841 | 1841 | > EOF |
|
1842 | 1842 | |
|
1843 | 1843 | #endif |
|
1844 | 1844 | |
|
1845 | 1845 | $ hg merge -r 2 --tool internal:merge |
|
1846 | 1846 | merging f |
|
1847 | 1847 | warning: internal :merge cannot merge symlinks for f |
|
1848 | 1848 | warning: conflicts while merging f! (edit, then use 'hg resolve --mark') |
|
1849 | 1849 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
1850 | 1850 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
1851 | 1851 | [1] |
|
1852 | 1852 | |
|
1853 | 1853 | Verify naming of temporary files and that extension is preserved: |
|
1854 | 1854 | |
|
1855 | 1855 | $ hg update -q -C 1 |
|
1856 | 1856 | $ hg mv f f.txt |
|
1857 | 1857 | $ hg ci -qm "f.txt" |
|
1858 | 1858 | $ hg update -q -C 2 |
|
1859 | 1859 | $ hg merge -y -r tip --tool echo --config merge-tools.echo.args='$base $local $other $output' |
|
1860 | 1860 | merging f and f.txt to f.txt |
|
1861 | 1861 | */f~base.* */f~local.*.txt */f~other.*.txt $TESTTMP/repo/f.txt (glob) |
|
1862 | 1862 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1863 | 1863 | (branch merge, don't forget to commit) |
|
1864 | 1864 | |
|
1865 | 1865 | Verify naming of temporary files and that extension is preserved |
|
1866 | 1866 | (experimental.mergetempdirprefix version): |
|
1867 | 1867 | |
|
1868 | 1868 | $ hg update -q -C 1 |
|
1869 | 1869 | $ hg mv f f.txt |
|
1870 | 1870 | $ hg ci -qm "f.txt" |
|
1871 | warning: commit already existed in the repository! | |
|
1871 | 1872 | $ hg update -q -C 2 |
|
1872 | 1873 | $ hg merge -y -r tip --tool echo \ |
|
1873 | 1874 | > --config merge-tools.echo.args='$base $local $other $output' \ |
|
1874 | 1875 | > --config experimental.mergetempdirprefix=$TESTTMP/hgmerge. |
|
1875 | 1876 | merging f and f.txt to f.txt |
|
1876 | 1877 | $TESTTMP/hgmerge.*/f~base $TESTTMP/hgmerge.*/f~local.txt $TESTTMP/hgmerge.*/f~other.txt $TESTTMP/repo/f.txt (glob) |
|
1877 | 1878 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1878 | 1879 | (branch merge, don't forget to commit) |
|
1879 | 1880 | |
|
1880 | 1881 | Binary files capability checking |
|
1881 | 1882 | |
|
1882 | 1883 | $ hg update -q -C 0 |
|
1883 | 1884 | $ python <<EOF |
|
1884 | 1885 | > with open('b', 'wb') as fp: |
|
1885 | 1886 | > fp.write(b'\x00\x01\x02\x03') |
|
1886 | 1887 | > EOF |
|
1887 | 1888 | $ hg add b |
|
1888 | 1889 | $ hg commit -qm "add binary file (#1)" |
|
1889 | 1890 | |
|
1890 | 1891 | $ hg update -q -C 0 |
|
1891 | 1892 | $ python <<EOF |
|
1892 | 1893 | > with open('b', 'wb') as fp: |
|
1893 | 1894 | > fp.write(b'\x03\x02\x01\x00') |
|
1894 | 1895 | > EOF |
|
1895 | 1896 | $ hg add b |
|
1896 | 1897 | $ hg commit -qm "add binary file (#2)" |
|
1897 | 1898 | |
|
1898 | 1899 | By default, binary files capability of internal merge tools is not |
|
1899 | 1900 | checked strictly. |
|
1900 | 1901 | |
|
1901 | 1902 | (for merge-patterns, chosen unintentionally) |
|
1902 | 1903 | |
|
1903 | 1904 | $ hg merge 9 \ |
|
1904 | 1905 | > --config merge-patterns.b=:merge-other \ |
|
1905 | 1906 | > --config merge-patterns.re:[a-z]=:other |
|
1906 | 1907 | warning: check merge-patterns configurations, if ':merge-other' for binary file 'b' is unintentional |
|
1907 | 1908 | (see 'hg help merge-tools' for binary files capability) |
|
1908 | 1909 | merging b |
|
1909 | 1910 | warning: b looks like a binary file. |
|
1910 | 1911 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
1911 | 1912 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
1912 | 1913 | [1] |
|
1913 | 1914 | (Testing that commands.merge.require-rev doesn't break --abort) |
|
1914 | 1915 | $ hg merge --abort -q |
|
1915 | 1916 | |
|
1916 | 1917 | (for ui.merge, ignored unintentionally) |
|
1917 | 1918 | |
|
1918 | 1919 | $ hg merge 9 \ |
|
1919 | 1920 | > --config merge-tools.:other.binary=true \ |
|
1920 | 1921 | > --config ui.merge=:other |
|
1921 | 1922 | tool :other (for pattern b) can't handle binary |
|
1922 | 1923 | tool true can't handle binary |
|
1923 | 1924 | tool :other can't handle binary |
|
1924 | 1925 | tool false can't handle binary |
|
1925 | 1926 | no tool found to merge b |
|
1926 | 1927 | file 'b' needs to be resolved. |
|
1927 | 1928 | You can keep (l)ocal [working copy], take (o)ther [merge rev], or leave (u)nresolved. |
|
1928 | 1929 | What do you want to do? u |
|
1929 | 1930 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
1930 | 1931 | use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon |
|
1931 | 1932 | [1] |
|
1932 | 1933 | $ hg merge --abort -q |
|
1933 | 1934 | |
|
1934 | 1935 | With merge.strict-capability-check=true, binary files capability of |
|
1935 | 1936 | internal merge tools is checked strictly. |
|
1936 | 1937 | |
|
1937 | 1938 | $ f --hexdump b |
|
1938 | 1939 | b: |
|
1939 | 1940 | 0000: 03 02 01 00 |....| |
|
1940 | 1941 | |
|
1941 | 1942 | (for merge-patterns) |
|
1942 | 1943 | |
|
1943 | 1944 | $ hg merge 9 --config merge.strict-capability-check=true \ |
|
1944 | 1945 | > --config merge-tools.:merge-other.binary=true \ |
|
1945 | 1946 | > --config merge-patterns.b=:merge-other \ |
|
1946 | 1947 | > --config merge-patterns.re:[a-z]=:other |
|
1947 | 1948 | tool :merge-other (for pattern b) can't handle binary |
|
1948 | 1949 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1949 | 1950 | (branch merge, don't forget to commit) |
|
1950 | 1951 | $ f --hexdump b |
|
1951 | 1952 | b: |
|
1952 | 1953 | 0000: 00 01 02 03 |....| |
|
1953 | 1954 | $ hg merge --abort -q |
|
1954 | 1955 | |
|
1955 | 1956 | (for ui.merge) |
|
1956 | 1957 | |
|
1957 | 1958 | $ hg merge 9 --config merge.strict-capability-check=true \ |
|
1958 | 1959 | > --config ui.merge=:other |
|
1959 | 1960 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1960 | 1961 | (branch merge, don't forget to commit) |
|
1961 | 1962 | $ f --hexdump b |
|
1962 | 1963 | b: |
|
1963 | 1964 | 0000: 00 01 02 03 |....| |
|
1964 | 1965 | $ hg merge --abort -q |
|
1965 | 1966 | |
|
1966 | 1967 | Check that the extra information is printed correctly |
|
1967 | 1968 | |
|
1968 | 1969 | $ hg merge 9 \ |
|
1969 | 1970 | > --config merge-tools.testecho.executable='echo' \ |
|
1970 | 1971 | > --config merge-tools.testecho.args='merge runs here ...' \ |
|
1971 | 1972 | > --config merge-tools.testecho.binary=True \ |
|
1972 | 1973 | > --config ui.merge=testecho \ |
|
1973 | 1974 | > --config ui.pre-merge-tool-output-template='\n{label("extmerge.running_merge_tool", "Running merge tool for {path} ({toolpath}):")}\n{separate("\n", extmerge_section(local), extmerge_section(base), extmerge_section(other))}\n' \ |
|
1974 | 1975 | > --config 'templatealias.extmerge_section(sect)="- {pad("{sect.name} ({sect.label})", 20, left=True)}: {revset(sect.node)%"{rev}:{shortest(node,8)} {desc|firstline} {separate(" ", tags, bookmarks, branch)}"}"' |
|
1975 | 1976 | merging b |
|
1976 | 1977 | |
|
1977 | 1978 | Running merge tool for b ("*/bin/echo.exe"): (glob) (windows !) |
|
1978 | 1979 | Running merge tool for b (*/bin/echo): (glob) (no-windows !) |
|
1979 | 1980 | - local (working copy): 10:2d1f533d add binary file (#2) tip default |
|
1980 | 1981 | - base (base): -1:00000000 default |
|
1981 | 1982 | - other (merge rev): 9:1e7ad7d7 add binary file (#1) default |
|
1982 | 1983 | merge runs here ... |
|
1983 | 1984 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
1984 | 1985 | (branch merge, don't forget to commit) |
|
1985 | 1986 | |
|
1986 | 1987 | Check that debugpicktool examines which merge tool is chosen for |
|
1987 | 1988 | specified file as expected |
|
1988 | 1989 | |
|
1989 | 1990 | $ beforemerge |
|
1990 | 1991 | [merge-tools] |
|
1991 | 1992 | false.whatever= |
|
1992 | 1993 | true.priority=1 |
|
1993 | 1994 | true.executable=cat |
|
1994 | 1995 | missingbinary.executable=doesnotexist |
|
1995 | 1996 | # hg update -C 1 |
|
1996 | 1997 | |
|
1997 | 1998 | (default behavior: checking files in the working parent context) |
|
1998 | 1999 | |
|
1999 | 2000 | $ hg manifest |
|
2000 | 2001 | f |
|
2001 | 2002 | $ hg debugpickmergetool |
|
2002 | 2003 | f = true |
|
2003 | 2004 | |
|
2004 | 2005 | (-X/-I and file patterns limmit examination targets) |
|
2005 | 2006 | |
|
2006 | 2007 | $ hg debugpickmergetool -X f |
|
2007 | 2008 | $ hg debugpickmergetool unknown |
|
2008 | 2009 | unknown: no such file in rev ef83787e2614 |
|
2009 | 2010 | |
|
2010 | 2011 | (--changedelete emulates merging change and delete) |
|
2011 | 2012 | |
|
2012 | 2013 | $ hg debugpickmergetool --changedelete |
|
2013 | 2014 | f = :prompt |
|
2014 | 2015 | |
|
2015 | 2016 | (-r REV causes checking files in specified revision) |
|
2016 | 2017 | |
|
2017 | 2018 | $ hg manifest -r 8 |
|
2018 | 2019 | f.txt |
|
2019 | 2020 | $ hg debugpickmergetool -r 8 |
|
2020 | 2021 | f.txt = true |
|
2021 | 2022 | |
|
2022 | 2023 | #if symlink |
|
2023 | 2024 | |
|
2024 | 2025 | (symlink causes chosing :prompt) |
|
2025 | 2026 | |
|
2026 | 2027 | $ hg debugpickmergetool -r 6d00b3726f6e |
|
2027 | 2028 | f = :prompt |
|
2028 | 2029 | |
|
2029 | 2030 | (by default, it is assumed that no internal merge tools has symlinks |
|
2030 | 2031 | capability) |
|
2031 | 2032 | |
|
2032 | 2033 | $ hg debugpickmergetool \ |
|
2033 | 2034 | > -r 6d00b3726f6e \ |
|
2034 | 2035 | > --config merge-tools.:merge-other.symlink=true \ |
|
2035 | 2036 | > --config merge-patterns.f=:merge-other \ |
|
2036 | 2037 | > --config merge-patterns.re:[f]=:merge-local \ |
|
2037 | 2038 | > --config merge-patterns.re:[a-z]=:other |
|
2038 | 2039 | f = :prompt |
|
2039 | 2040 | |
|
2040 | 2041 | $ hg debugpickmergetool \ |
|
2041 | 2042 | > -r 6d00b3726f6e \ |
|
2042 | 2043 | > --config merge-tools.:other.symlink=true \ |
|
2043 | 2044 | > --config ui.merge=:other |
|
2044 | 2045 | f = :prompt |
|
2045 | 2046 | |
|
2046 | 2047 | (with strict-capability-check=true, actual symlink capabilities are |
|
2047 | 2048 | checked striclty) |
|
2048 | 2049 | |
|
2049 | 2050 | $ hg debugpickmergetool --config merge.strict-capability-check=true \ |
|
2050 | 2051 | > -r 6d00b3726f6e \ |
|
2051 | 2052 | > --config merge-tools.:merge-other.symlink=true \ |
|
2052 | 2053 | > --config merge-patterns.f=:merge-other \ |
|
2053 | 2054 | > --config merge-patterns.re:[f]=:merge-local \ |
|
2054 | 2055 | > --config merge-patterns.re:[a-z]=:other |
|
2055 | 2056 | f = :other |
|
2056 | 2057 | |
|
2057 | 2058 | $ hg debugpickmergetool --config merge.strict-capability-check=true \ |
|
2058 | 2059 | > -r 6d00b3726f6e \ |
|
2059 | 2060 | > --config ui.merge=:other |
|
2060 | 2061 | f = :other |
|
2061 | 2062 | |
|
2062 | 2063 | $ hg debugpickmergetool --config merge.strict-capability-check=true \ |
|
2063 | 2064 | > -r 6d00b3726f6e \ |
|
2064 | 2065 | > --config merge-tools.:merge-other.symlink=true \ |
|
2065 | 2066 | > --config ui.merge=:merge-other |
|
2066 | 2067 | f = :prompt |
|
2067 | 2068 | |
|
2068 | 2069 | #endif |
|
2069 | 2070 | |
|
2070 | 2071 | (--verbose shows some configurations) |
|
2071 | 2072 | |
|
2072 | 2073 | $ hg debugpickmergetool --tool foobar -v |
|
2073 | 2074 | with --tool 'foobar' |
|
2074 | 2075 | f = foobar |
|
2075 | 2076 | |
|
2076 | 2077 | $ HGMERGE=false hg debugpickmergetool -v |
|
2077 | 2078 | with HGMERGE='false' |
|
2078 | 2079 | f = false |
|
2079 | 2080 | |
|
2080 | 2081 | $ hg debugpickmergetool --config ui.merge=false -v |
|
2081 | 2082 | with ui.merge='false' |
|
2082 | 2083 | f = false |
|
2083 | 2084 | |
|
2084 | 2085 | (--debug shows errors detected intermediately) |
|
2085 | 2086 | |
|
2086 | 2087 | $ hg debugpickmergetool --config merge-patterns.f=true --config merge-tools.true.executable=nonexistentmergetool --debug f |
|
2087 | 2088 | couldn't find merge tool true (for pattern f) |
|
2088 | 2089 | couldn't find merge tool true |
|
2089 | 2090 | f = false |
|
2090 | 2091 | |
|
2091 | 2092 | $ cd .. |
@@ -1,1053 +1,1054 b'' | |||
|
1 | 1 | $ cat > $TESTTMP/hook.sh << 'EOF' |
|
2 | 2 | > echo "test-hook-close-phase: $HG_NODE: $HG_OLDPHASE -> $HG_PHASE" |
|
3 | 3 | > EOF |
|
4 | 4 | |
|
5 | 5 | $ cat >> $HGRCPATH << EOF |
|
6 | 6 | > [extensions] |
|
7 | 7 | > phasereport=$TESTDIR/testlib/ext-phase-report.py |
|
8 | 8 | > [hooks] |
|
9 | 9 | > txnclose-phase.test = sh $TESTTMP/hook.sh |
|
10 | 10 | > EOF |
|
11 | 11 | |
|
12 | 12 | $ hglog() { hg log --template "{rev} {phaseidx} {desc}\n" $*; } |
|
13 | 13 | $ mkcommit() { |
|
14 | 14 | > echo "$1" > "$1" |
|
15 | 15 | > hg add "$1" |
|
16 | 16 | > message="$1" |
|
17 | 17 | > shift |
|
18 | 18 | > hg ci -m "$message" $* |
|
19 | 19 | > } |
|
20 | 20 | |
|
21 | 21 | $ hg init initialrepo |
|
22 | 22 | $ cd initialrepo |
|
23 | 23 | |
|
24 | 24 | Cannot change null revision phase |
|
25 | 25 | |
|
26 | 26 | $ hg phase --force --secret null |
|
27 | 27 | abort: cannot change null revision phase |
|
28 | 28 | [255] |
|
29 | 29 | $ hg phase null |
|
30 | 30 | -1: public |
|
31 | 31 | |
|
32 | 32 | $ mkcommit A |
|
33 | 33 | test-debug-phase: new rev 0: x -> 1 |
|
34 | 34 | test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: -> draft |
|
35 | 35 | |
|
36 | 36 | New commit are draft by default |
|
37 | 37 | |
|
38 | 38 | $ hglog |
|
39 | 39 | 0 1 A |
|
40 | 40 | |
|
41 | 41 | Following commit are draft too |
|
42 | 42 | |
|
43 | 43 | $ mkcommit B |
|
44 | 44 | test-debug-phase: new rev 1: x -> 1 |
|
45 | 45 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: -> draft |
|
46 | 46 | |
|
47 | 47 | $ hglog |
|
48 | 48 | 1 1 B |
|
49 | 49 | 0 1 A |
|
50 | 50 | |
|
51 | 51 | Working directory phase is secret when its parent is secret. |
|
52 | 52 | |
|
53 | 53 | $ hg phase --force --secret . |
|
54 | 54 | test-debug-phase: move rev 0: 1 -> 2 |
|
55 | 55 | test-debug-phase: move rev 1: 1 -> 2 |
|
56 | 56 | test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: draft -> secret |
|
57 | 57 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: draft -> secret |
|
58 | 58 | $ hg log -r 'wdir()' -T '{phase}\n' |
|
59 | 59 | secret |
|
60 | 60 | $ hg log -r 'wdir() and public()' -T '{phase}\n' |
|
61 | 61 | $ hg log -r 'wdir() and draft()' -T '{phase}\n' |
|
62 | 62 | $ hg log -r 'wdir() and secret()' -T '{phase}\n' |
|
63 | 63 | secret |
|
64 | 64 | |
|
65 | 65 | Working directory phase is draft when its parent is draft. |
|
66 | 66 | |
|
67 | 67 | $ hg phase --draft . |
|
68 | 68 | test-debug-phase: move rev 1: 2 -> 1 |
|
69 | 69 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: secret -> draft |
|
70 | 70 | $ hg log -r 'wdir()' -T '{phase}\n' |
|
71 | 71 | draft |
|
72 | 72 | $ hg log -r 'wdir() and public()' -T '{phase}\n' |
|
73 | 73 | $ hg log -r 'wdir() and draft()' -T '{phase}\n' |
|
74 | 74 | draft |
|
75 | 75 | $ hg log -r 'wdir() and secret()' -T '{phase}\n' |
|
76 | 76 | |
|
77 | 77 | Working directory phase is secret when a new commit will be created as secret, |
|
78 | 78 | even if the parent is draft. |
|
79 | 79 | |
|
80 | 80 | $ hg log -r 'wdir() and secret()' -T '{phase}\n' \ |
|
81 | 81 | > --config phases.new-commit='secret' |
|
82 | 82 | secret |
|
83 | 83 | |
|
84 | 84 | Working directory phase is draft when its parent is public. |
|
85 | 85 | |
|
86 | 86 | $ hg phase --public . |
|
87 | 87 | test-debug-phase: move rev 0: 1 -> 0 |
|
88 | 88 | test-debug-phase: move rev 1: 1 -> 0 |
|
89 | 89 | test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: draft -> public |
|
90 | 90 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: draft -> public |
|
91 | 91 | $ hg log -r 'wdir()' -T '{phase}\n' |
|
92 | 92 | draft |
|
93 | 93 | $ hg log -r 'wdir() and public()' -T '{phase}\n' |
|
94 | 94 | $ hg log -r 'wdir() and draft()' -T '{phase}\n' |
|
95 | 95 | draft |
|
96 | 96 | $ hg log -r 'wdir() and secret()' -T '{phase}\n' |
|
97 | 97 | $ hg log -r 'wdir() and secret()' -T '{phase}\n' \ |
|
98 | 98 | > --config phases.new-commit='secret' |
|
99 | 99 | secret |
|
100 | 100 | |
|
101 | 101 | Draft commit are properly created over public one: |
|
102 | 102 | |
|
103 | 103 | $ hg phase |
|
104 | 104 | 1: public |
|
105 | 105 | $ hglog |
|
106 | 106 | 1 0 B |
|
107 | 107 | 0 0 A |
|
108 | 108 | |
|
109 | 109 | $ mkcommit C |
|
110 | 110 | test-debug-phase: new rev 2: x -> 1 |
|
111 | 111 | test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757: -> draft |
|
112 | 112 | $ mkcommit D |
|
113 | 113 | test-debug-phase: new rev 3: x -> 1 |
|
114 | 114 | test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: -> draft |
|
115 | 115 | |
|
116 | 116 | $ hglog |
|
117 | 117 | 3 1 D |
|
118 | 118 | 2 1 C |
|
119 | 119 | 1 0 B |
|
120 | 120 | 0 0 A |
|
121 | 121 | |
|
122 | 122 | Test creating changeset as secret |
|
123 | 123 | |
|
124 | 124 | $ mkcommit E --config phases.new-commit='secret' |
|
125 | 125 | test-debug-phase: new rev 4: x -> 2 |
|
126 | 126 | test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde: -> secret |
|
127 | 127 | $ hglog |
|
128 | 128 | 4 2 E |
|
129 | 129 | 3 1 D |
|
130 | 130 | 2 1 C |
|
131 | 131 | 1 0 B |
|
132 | 132 | 0 0 A |
|
133 | 133 | |
|
134 | 134 | Test the secret property is inherited |
|
135 | 135 | |
|
136 | 136 | $ mkcommit H |
|
137 | 137 | test-debug-phase: new rev 5: x -> 2 |
|
138 | 138 | test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8: -> secret |
|
139 | 139 | $ hglog |
|
140 | 140 | 5 2 H |
|
141 | 141 | 4 2 E |
|
142 | 142 | 3 1 D |
|
143 | 143 | 2 1 C |
|
144 | 144 | 1 0 B |
|
145 | 145 | 0 0 A |
|
146 | 146 | |
|
147 | 147 | Even on merge |
|
148 | 148 | |
|
149 | 149 | $ hg up -q 1 |
|
150 | 150 | $ mkcommit "B'" |
|
151 | 151 | test-debug-phase: new rev 6: x -> 1 |
|
152 | 152 | created new head |
|
153 | 153 | test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519: -> draft |
|
154 | 154 | $ hglog |
|
155 | 155 | 6 1 B' |
|
156 | 156 | 5 2 H |
|
157 | 157 | 4 2 E |
|
158 | 158 | 3 1 D |
|
159 | 159 | 2 1 C |
|
160 | 160 | 1 0 B |
|
161 | 161 | 0 0 A |
|
162 | 162 | $ hg merge 4 # E |
|
163 | 163 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
164 | 164 | (branch merge, don't forget to commit) |
|
165 | 165 | $ hg phase |
|
166 | 166 | 6: draft |
|
167 | 167 | 4: secret |
|
168 | 168 | $ hg ci -m "merge B' and E" |
|
169 | 169 | test-debug-phase: new rev 7: x -> 2 |
|
170 | 170 | test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af: -> secret |
|
171 | 171 | |
|
172 | 172 | $ hglog |
|
173 | 173 | 7 2 merge B' and E |
|
174 | 174 | 6 1 B' |
|
175 | 175 | 5 2 H |
|
176 | 176 | 4 2 E |
|
177 | 177 | 3 1 D |
|
178 | 178 | 2 1 C |
|
179 | 179 | 1 0 B |
|
180 | 180 | 0 0 A |
|
181 | 181 | |
|
182 | 182 | Test secret changeset are not pushed |
|
183 | 183 | |
|
184 | 184 | $ hg init ../push-dest |
|
185 | 185 | $ cat > ../push-dest/.hg/hgrc << EOF |
|
186 | 186 | > [phases] |
|
187 | 187 | > publish=False |
|
188 | 188 | > EOF |
|
189 | 189 | $ hg outgoing ../push-dest --template='{rev} {phase} {desc|firstline}\n' |
|
190 | 190 | comparing with ../push-dest |
|
191 | 191 | searching for changes |
|
192 | 192 | 0 public A |
|
193 | 193 | 1 public B |
|
194 | 194 | 2 draft C |
|
195 | 195 | 3 draft D |
|
196 | 196 | 6 draft B' |
|
197 | 197 | $ hg outgoing -r 'branch(default)' ../push-dest --template='{rev} {phase} {desc|firstline}\n' |
|
198 | 198 | comparing with ../push-dest |
|
199 | 199 | searching for changes |
|
200 | 200 | 0 public A |
|
201 | 201 | 1 public B |
|
202 | 202 | 2 draft C |
|
203 | 203 | 3 draft D |
|
204 | 204 | 6 draft B' |
|
205 | 205 | |
|
206 | 206 | $ hg push ../push-dest -f # force because we push multiple heads |
|
207 | 207 | pushing to ../push-dest |
|
208 | 208 | searching for changes |
|
209 | 209 | adding changesets |
|
210 | 210 | adding manifests |
|
211 | 211 | adding file changes |
|
212 | 212 | added 5 changesets with 5 changes to 5 files (+1 heads) |
|
213 | 213 | test-debug-phase: new rev 0: x -> 0 |
|
214 | 214 | test-debug-phase: new rev 1: x -> 0 |
|
215 | 215 | test-debug-phase: new rev 2: x -> 1 |
|
216 | 216 | test-debug-phase: new rev 3: x -> 1 |
|
217 | 217 | test-debug-phase: new rev 4: x -> 1 |
|
218 | 218 | test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: -> public |
|
219 | 219 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: -> public |
|
220 | 220 | test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757: -> draft |
|
221 | 221 | test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: -> draft |
|
222 | 222 | test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519: -> draft |
|
223 | 223 | $ hglog |
|
224 | 224 | 7 2 merge B' and E |
|
225 | 225 | 6 1 B' |
|
226 | 226 | 5 2 H |
|
227 | 227 | 4 2 E |
|
228 | 228 | 3 1 D |
|
229 | 229 | 2 1 C |
|
230 | 230 | 1 0 B |
|
231 | 231 | 0 0 A |
|
232 | 232 | $ cd ../push-dest |
|
233 | 233 | $ hglog |
|
234 | 234 | 4 1 B' |
|
235 | 235 | 3 1 D |
|
236 | 236 | 2 1 C |
|
237 | 237 | 1 0 B |
|
238 | 238 | 0 0 A |
|
239 | 239 | |
|
240 | 240 | (Issue3303) |
|
241 | 241 | Check that remote secret changeset are ignore when checking creation of remote heads |
|
242 | 242 | |
|
243 | 243 | We add a secret head into the push destination. This secret head shadows a |
|
244 | 244 | visible shared between the initial repo and the push destination. |
|
245 | 245 | |
|
246 | 246 | $ hg up -q 4 # B' |
|
247 | 247 | $ mkcommit Z --config phases.new-commit=secret |
|
248 | 248 | test-debug-phase: new rev 5: x -> 2 |
|
249 | 249 | test-hook-close-phase: 2713879da13d6eea1ff22b442a5a87cb31a7ce6a: -> secret |
|
250 | 250 | $ hg phase . |
|
251 | 251 | 5: secret |
|
252 | 252 | |
|
253 | 253 | We now try to push a new public changeset that descend from the common public |
|
254 | 254 | head shadowed by the remote secret head. |
|
255 | 255 | |
|
256 | 256 | $ cd ../initialrepo |
|
257 | 257 | $ hg up -q 6 #B' |
|
258 | 258 | $ mkcommit I |
|
259 | 259 | test-debug-phase: new rev 8: x -> 1 |
|
260 | 260 | created new head |
|
261 | 261 | test-hook-close-phase: 6d6770faffce199f1fddd1cf87f6f026138cf061: -> draft |
|
262 | 262 | $ hg push ../push-dest |
|
263 | 263 | pushing to ../push-dest |
|
264 | 264 | searching for changes |
|
265 | 265 | adding changesets |
|
266 | 266 | adding manifests |
|
267 | 267 | adding file changes |
|
268 | 268 | added 1 changesets with 1 changes to 1 files (+1 heads) |
|
269 | 269 | test-debug-phase: new rev 6: x -> 1 |
|
270 | 270 | test-hook-close-phase: 6d6770faffce199f1fddd1cf87f6f026138cf061: -> draft |
|
271 | 271 | |
|
272 | 272 | :note: The "(+1 heads)" is wrong as we do not had any visible head |
|
273 | 273 | |
|
274 | 274 | check that branch cache with "served" filter are properly computed and stored |
|
275 | 275 | |
|
276 | 276 | $ ls ../push-dest/.hg/cache/branch2* |
|
277 | 277 | ../push-dest/.hg/cache/branch2-base |
|
278 | 278 | ../push-dest/.hg/cache/branch2-served |
|
279 | 279 | $ cat ../push-dest/.hg/cache/branch2-served |
|
280 | 280 | 6d6770faffce199f1fddd1cf87f6f026138cf061 6 465891ffab3c47a3c23792f7dc84156e19a90722 |
|
281 | 281 | b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default |
|
282 | 282 | 6d6770faffce199f1fddd1cf87f6f026138cf061 o default |
|
283 | 283 | $ hg heads -R ../push-dest --template '{rev}:{node} {phase}\n' #update visible cache too |
|
284 | 284 | 6:6d6770faffce199f1fddd1cf87f6f026138cf061 draft |
|
285 | 285 | 5:2713879da13d6eea1ff22b442a5a87cb31a7ce6a secret |
|
286 | 286 | 3:b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e draft |
|
287 | 287 | $ ls ../push-dest/.hg/cache/branch2* |
|
288 | 288 | ../push-dest/.hg/cache/branch2-base |
|
289 | 289 | ../push-dest/.hg/cache/branch2-served |
|
290 | 290 | ../push-dest/.hg/cache/branch2-visible |
|
291 | 291 | $ cat ../push-dest/.hg/cache/branch2-served |
|
292 | 292 | 6d6770faffce199f1fddd1cf87f6f026138cf061 6 465891ffab3c47a3c23792f7dc84156e19a90722 |
|
293 | 293 | b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default |
|
294 | 294 | 6d6770faffce199f1fddd1cf87f6f026138cf061 o default |
|
295 | 295 | $ cat ../push-dest/.hg/cache/branch2-visible |
|
296 | 296 | 6d6770faffce199f1fddd1cf87f6f026138cf061 6 |
|
297 | 297 | b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default |
|
298 | 298 | 2713879da13d6eea1ff22b442a5a87cb31a7ce6a o default |
|
299 | 299 | 6d6770faffce199f1fddd1cf87f6f026138cf061 o default |
|
300 | 300 | |
|
301 | 301 | |
|
302 | 302 | Restore condition prior extra insertion. |
|
303 | 303 | $ hg -q --config extensions.mq= strip . |
|
304 | 304 | $ hg up -q 7 |
|
305 | 305 | $ cd .. |
|
306 | 306 | |
|
307 | 307 | Test secret changeset are not pull |
|
308 | 308 | |
|
309 | 309 | $ hg init pull-dest |
|
310 | 310 | $ cd pull-dest |
|
311 | 311 | $ hg pull ../initialrepo |
|
312 | 312 | pulling from ../initialrepo |
|
313 | 313 | requesting all changes |
|
314 | 314 | adding changesets |
|
315 | 315 | adding manifests |
|
316 | 316 | adding file changes |
|
317 | 317 | added 5 changesets with 5 changes to 5 files (+1 heads) |
|
318 | 318 | new changesets 4a2df7238c3b:cf9fe039dfd6 |
|
319 | 319 | test-debug-phase: new rev 0: x -> 0 |
|
320 | 320 | test-debug-phase: new rev 1: x -> 0 |
|
321 | 321 | test-debug-phase: new rev 2: x -> 0 |
|
322 | 322 | test-debug-phase: new rev 3: x -> 0 |
|
323 | 323 | test-debug-phase: new rev 4: x -> 0 |
|
324 | 324 | test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: -> public |
|
325 | 325 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: -> public |
|
326 | 326 | test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757: -> public |
|
327 | 327 | test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: -> public |
|
328 | 328 | test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519: -> public |
|
329 | 329 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
330 | 330 | $ hglog |
|
331 | 331 | 4 0 B' |
|
332 | 332 | 3 0 D |
|
333 | 333 | 2 0 C |
|
334 | 334 | 1 0 B |
|
335 | 335 | 0 0 A |
|
336 | 336 | $ cd .. |
|
337 | 337 | |
|
338 | 338 | But secret can still be bundled explicitly |
|
339 | 339 | |
|
340 | 340 | $ cd initialrepo |
|
341 | 341 | $ hg bundle --base '4^' -r 'children(4)' ../secret-bundle.hg |
|
342 | 342 | 4 changesets found |
|
343 | 343 | $ cd .. |
|
344 | 344 | |
|
345 | 345 | Test secret changeset are not cloned |
|
346 | 346 | (during local clone) |
|
347 | 347 | |
|
348 | 348 | $ hg clone -qU initialrepo clone-dest |
|
349 | 349 | test-debug-phase: new rev 0: x -> 0 |
|
350 | 350 | test-debug-phase: new rev 1: x -> 0 |
|
351 | 351 | test-debug-phase: new rev 2: x -> 0 |
|
352 | 352 | test-debug-phase: new rev 3: x -> 0 |
|
353 | 353 | test-debug-phase: new rev 4: x -> 0 |
|
354 | 354 | test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: -> public |
|
355 | 355 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: -> public |
|
356 | 356 | test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757: -> public |
|
357 | 357 | test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: -> public |
|
358 | 358 | test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519: -> public |
|
359 | 359 | $ hglog -R clone-dest |
|
360 | 360 | 4 0 B' |
|
361 | 361 | 3 0 D |
|
362 | 362 | 2 0 C |
|
363 | 363 | 1 0 B |
|
364 | 364 | 0 0 A |
|
365 | 365 | |
|
366 | 366 | Test summary |
|
367 | 367 | |
|
368 | 368 | $ hg summary -R clone-dest --verbose |
|
369 | 369 | parent: -1:000000000000 (no revision checked out) |
|
370 | 370 | branch: default |
|
371 | 371 | commit: (clean) |
|
372 | 372 | update: 5 new changesets (update) |
|
373 | 373 | $ hg summary -R initialrepo |
|
374 | 374 | parent: 7:17a481b3bccb tip |
|
375 | 375 | merge B' and E |
|
376 | 376 | branch: default |
|
377 | 377 | commit: (clean) (secret) |
|
378 | 378 | update: 1 new changesets, 2 branch heads (merge) |
|
379 | 379 | phases: 3 draft, 3 secret |
|
380 | 380 | $ hg summary -R initialrepo --quiet |
|
381 | 381 | parent: 7:17a481b3bccb tip |
|
382 | 382 | update: 1 new changesets, 2 branch heads (merge) |
|
383 | 383 | |
|
384 | 384 | Test revset |
|
385 | 385 | |
|
386 | 386 | $ cd initialrepo |
|
387 | 387 | $ hglog -r 'public()' |
|
388 | 388 | 0 0 A |
|
389 | 389 | 1 0 B |
|
390 | 390 | $ hglog -r 'draft()' |
|
391 | 391 | 2 1 C |
|
392 | 392 | 3 1 D |
|
393 | 393 | 6 1 B' |
|
394 | 394 | $ hglog -r 'secret()' |
|
395 | 395 | 4 2 E |
|
396 | 396 | 5 2 H |
|
397 | 397 | 7 2 merge B' and E |
|
398 | 398 | |
|
399 | 399 | test that phase are displayed in log at debug level |
|
400 | 400 | |
|
401 | 401 | $ hg log --debug |
|
402 | 402 | changeset: 7:17a481b3bccb796c0521ae97903d81c52bfee4af |
|
403 | 403 | tag: tip |
|
404 | 404 | phase: secret |
|
405 | 405 | parent: 6:cf9fe039dfd67e829edf6522a45de057b5c86519 |
|
406 | 406 | parent: 4:a603bfb5a83e312131cebcd05353c217d4d21dde |
|
407 | 407 | manifest: 7:5e724ffacba267b2ab726c91fc8b650710deaaa8 |
|
408 | 408 | user: test |
|
409 | 409 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
410 | 410 | files+: C D E |
|
411 | 411 | extra: branch=default |
|
412 | 412 | description: |
|
413 | 413 | merge B' and E |
|
414 | 414 | |
|
415 | 415 | |
|
416 | 416 | changeset: 6:cf9fe039dfd67e829edf6522a45de057b5c86519 |
|
417 | 417 | phase: draft |
|
418 | 418 | parent: 1:27547f69f25460a52fff66ad004e58da7ad3fb56 |
|
419 | 419 | parent: -1:0000000000000000000000000000000000000000 |
|
420 | 420 | manifest: 6:ab8bfef2392903058bf4ebb9e7746e8d7026b27a |
|
421 | 421 | user: test |
|
422 | 422 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
423 | 423 | files+: B' |
|
424 | 424 | extra: branch=default |
|
425 | 425 | description: |
|
426 | 426 | B' |
|
427 | 427 | |
|
428 | 428 | |
|
429 | 429 | changeset: 5:a030c6be5127abc010fcbff1851536552e6951a8 |
|
430 | 430 | phase: secret |
|
431 | 431 | parent: 4:a603bfb5a83e312131cebcd05353c217d4d21dde |
|
432 | 432 | parent: -1:0000000000000000000000000000000000000000 |
|
433 | 433 | manifest: 5:5c710aa854874fe3d5fa7192e77bdb314cc08b5a |
|
434 | 434 | user: test |
|
435 | 435 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
436 | 436 | files+: H |
|
437 | 437 | extra: branch=default |
|
438 | 438 | description: |
|
439 | 439 | H |
|
440 | 440 | |
|
441 | 441 | |
|
442 | 442 | changeset: 4:a603bfb5a83e312131cebcd05353c217d4d21dde |
|
443 | 443 | phase: secret |
|
444 | 444 | parent: 3:b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e |
|
445 | 445 | parent: -1:0000000000000000000000000000000000000000 |
|
446 | 446 | manifest: 4:7173fd1c27119750b959e3a0f47ed78abe75d6dc |
|
447 | 447 | user: test |
|
448 | 448 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
449 | 449 | files+: E |
|
450 | 450 | extra: branch=default |
|
451 | 451 | description: |
|
452 | 452 | E |
|
453 | 453 | |
|
454 | 454 | |
|
455 | 455 | changeset: 3:b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e |
|
456 | 456 | phase: draft |
|
457 | 457 | parent: 2:f838bfaca5c7226600ebcfd84f3c3c13a28d3757 |
|
458 | 458 | parent: -1:0000000000000000000000000000000000000000 |
|
459 | 459 | manifest: 3:6e1f4c47ecb533ffd0c8e52cdc88afb6cd39e20c |
|
460 | 460 | user: test |
|
461 | 461 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
462 | 462 | files+: D |
|
463 | 463 | extra: branch=default |
|
464 | 464 | description: |
|
465 | 465 | D |
|
466 | 466 | |
|
467 | 467 | |
|
468 | 468 | changeset: 2:f838bfaca5c7226600ebcfd84f3c3c13a28d3757 |
|
469 | 469 | phase: draft |
|
470 | 470 | parent: 1:27547f69f25460a52fff66ad004e58da7ad3fb56 |
|
471 | 471 | parent: -1:0000000000000000000000000000000000000000 |
|
472 | 472 | manifest: 2:66a5a01817fdf5239c273802b5b7618d051c89e4 |
|
473 | 473 | user: test |
|
474 | 474 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
475 | 475 | files+: C |
|
476 | 476 | extra: branch=default |
|
477 | 477 | description: |
|
478 | 478 | C |
|
479 | 479 | |
|
480 | 480 | |
|
481 | 481 | changeset: 1:27547f69f25460a52fff66ad004e58da7ad3fb56 |
|
482 | 482 | phase: public |
|
483 | 483 | parent: 0:4a2df7238c3b48766b5e22fafbb8a2f506ec8256 |
|
484 | 484 | parent: -1:0000000000000000000000000000000000000000 |
|
485 | 485 | manifest: 1:cb5cbbc1bfbf24cc34b9e8c16914e9caa2d2a7fd |
|
486 | 486 | user: test |
|
487 | 487 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
488 | 488 | files+: B |
|
489 | 489 | extra: branch=default |
|
490 | 490 | description: |
|
491 | 491 | B |
|
492 | 492 | |
|
493 | 493 | |
|
494 | 494 | changeset: 0:4a2df7238c3b48766b5e22fafbb8a2f506ec8256 |
|
495 | 495 | phase: public |
|
496 | 496 | parent: -1:0000000000000000000000000000000000000000 |
|
497 | 497 | parent: -1:0000000000000000000000000000000000000000 |
|
498 | 498 | manifest: 0:007d8c9d88841325f5c6b06371b35b4e8a2b1a83 |
|
499 | 499 | user: test |
|
500 | 500 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
501 | 501 | files+: A |
|
502 | 502 | extra: branch=default |
|
503 | 503 | description: |
|
504 | 504 | A |
|
505 | 505 | |
|
506 | 506 | |
|
507 | 507 | |
|
508 | 508 | |
|
509 | 509 | (Issue3707) |
|
510 | 510 | test invalid phase name |
|
511 | 511 | |
|
512 | 512 | $ mkcommit I --config phases.new-commit='babar' |
|
513 | 513 | transaction abort! |
|
514 | 514 | rollback completed |
|
515 | 515 | abort: phases.new-commit: not a valid phase name ('babar') |
|
516 | 516 | [255] |
|
517 | 517 | Test phase command |
|
518 | 518 | =================== |
|
519 | 519 | |
|
520 | 520 | initial picture |
|
521 | 521 | |
|
522 | 522 | $ hg log -G --template "{rev} {phase} {desc}\n" |
|
523 | 523 | @ 7 secret merge B' and E |
|
524 | 524 | |\ |
|
525 | 525 | | o 6 draft B' |
|
526 | 526 | | | |
|
527 | 527 | +---o 5 secret H |
|
528 | 528 | | | |
|
529 | 529 | o | 4 secret E |
|
530 | 530 | | | |
|
531 | 531 | o | 3 draft D |
|
532 | 532 | | | |
|
533 | 533 | o | 2 draft C |
|
534 | 534 | |/ |
|
535 | 535 | o 1 public B |
|
536 | 536 | | |
|
537 | 537 | o 0 public A |
|
538 | 538 | |
|
539 | 539 | |
|
540 | 540 | display changesets phase |
|
541 | 541 | |
|
542 | 542 | (mixing -r and plain rev specification) |
|
543 | 543 | |
|
544 | 544 | $ hg phase 1::4 -r 7 |
|
545 | 545 | 1: public |
|
546 | 546 | 2: draft |
|
547 | 547 | 3: draft |
|
548 | 548 | 4: secret |
|
549 | 549 | 7: secret |
|
550 | 550 | |
|
551 | 551 | |
|
552 | 552 | move changeset forward |
|
553 | 553 | |
|
554 | 554 | (with -r option) |
|
555 | 555 | |
|
556 | 556 | $ hg phase --public -r 2 |
|
557 | 557 | test-debug-phase: move rev 2: 1 -> 0 |
|
558 | 558 | test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757: draft -> public |
|
559 | 559 | $ hg log -G --template "{rev} {phase} {desc}\n" |
|
560 | 560 | @ 7 secret merge B' and E |
|
561 | 561 | |\ |
|
562 | 562 | | o 6 draft B' |
|
563 | 563 | | | |
|
564 | 564 | +---o 5 secret H |
|
565 | 565 | | | |
|
566 | 566 | o | 4 secret E |
|
567 | 567 | | | |
|
568 | 568 | o | 3 draft D |
|
569 | 569 | | | |
|
570 | 570 | o | 2 public C |
|
571 | 571 | |/ |
|
572 | 572 | o 1 public B |
|
573 | 573 | | |
|
574 | 574 | o 0 public A |
|
575 | 575 | |
|
576 | 576 | |
|
577 | 577 | move changeset backward |
|
578 | 578 | |
|
579 | 579 | (without -r option) |
|
580 | 580 | |
|
581 | 581 | $ hg phase --draft --force 2 |
|
582 | 582 | test-debug-phase: move rev 2: 0 -> 1 |
|
583 | 583 | test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757: public -> draft |
|
584 | 584 | $ hg log -G --template "{rev} {phase} {desc}\n" |
|
585 | 585 | @ 7 secret merge B' and E |
|
586 | 586 | |\ |
|
587 | 587 | | o 6 draft B' |
|
588 | 588 | | | |
|
589 | 589 | +---o 5 secret H |
|
590 | 590 | | | |
|
591 | 591 | o | 4 secret E |
|
592 | 592 | | | |
|
593 | 593 | o | 3 draft D |
|
594 | 594 | | | |
|
595 | 595 | o | 2 draft C |
|
596 | 596 | |/ |
|
597 | 597 | o 1 public B |
|
598 | 598 | | |
|
599 | 599 | o 0 public A |
|
600 | 600 | |
|
601 | 601 | |
|
602 | 602 | move changeset forward and backward |
|
603 | 603 | |
|
604 | 604 | $ hg phase --draft --force 1::4 |
|
605 | 605 | test-debug-phase: move rev 1: 0 -> 1 |
|
606 | 606 | test-debug-phase: move rev 4: 2 -> 1 |
|
607 | 607 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: public -> draft |
|
608 | 608 | test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde: secret -> draft |
|
609 | 609 | $ hg log -G --template "{rev} {phase} {desc}\n" |
|
610 | 610 | @ 7 secret merge B' and E |
|
611 | 611 | |\ |
|
612 | 612 | | o 6 draft B' |
|
613 | 613 | | | |
|
614 | 614 | +---o 5 secret H |
|
615 | 615 | | | |
|
616 | 616 | o | 4 draft E |
|
617 | 617 | | | |
|
618 | 618 | o | 3 draft D |
|
619 | 619 | | | |
|
620 | 620 | o | 2 draft C |
|
621 | 621 | |/ |
|
622 | 622 | o 1 draft B |
|
623 | 623 | | |
|
624 | 624 | o 0 public A |
|
625 | 625 | |
|
626 | 626 | test partial failure |
|
627 | 627 | |
|
628 | 628 | $ hg phase --public 7 |
|
629 | 629 | test-debug-phase: move rev 1: 1 -> 0 |
|
630 | 630 | test-debug-phase: move rev 2: 1 -> 0 |
|
631 | 631 | test-debug-phase: move rev 3: 1 -> 0 |
|
632 | 632 | test-debug-phase: move rev 4: 1 -> 0 |
|
633 | 633 | test-debug-phase: move rev 6: 1 -> 0 |
|
634 | 634 | test-debug-phase: move rev 7: 2 -> 0 |
|
635 | 635 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: draft -> public |
|
636 | 636 | test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757: draft -> public |
|
637 | 637 | test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: draft -> public |
|
638 | 638 | test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde: draft -> public |
|
639 | 639 | test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519: draft -> public |
|
640 | 640 | test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af: secret -> public |
|
641 | 641 | $ hg phase --draft '5 or 7' |
|
642 | 642 | test-debug-phase: move rev 5: 2 -> 1 |
|
643 | 643 | test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8: secret -> draft |
|
644 | 644 | cannot move 1 changesets to a higher phase, use --force |
|
645 | 645 | phase changed for 1 changesets |
|
646 | 646 | [1] |
|
647 | 647 | $ hg log -G --template "{rev} {phase} {desc}\n" |
|
648 | 648 | @ 7 public merge B' and E |
|
649 | 649 | |\ |
|
650 | 650 | | o 6 public B' |
|
651 | 651 | | | |
|
652 | 652 | +---o 5 draft H |
|
653 | 653 | | | |
|
654 | 654 | o | 4 public E |
|
655 | 655 | | | |
|
656 | 656 | o | 3 public D |
|
657 | 657 | | | |
|
658 | 658 | o | 2 public C |
|
659 | 659 | |/ |
|
660 | 660 | o 1 public B |
|
661 | 661 | | |
|
662 | 662 | o 0 public A |
|
663 | 663 | |
|
664 | 664 | |
|
665 | 665 | test complete failure |
|
666 | 666 | |
|
667 | 667 | $ hg phase --draft 7 |
|
668 | 668 | cannot move 1 changesets to a higher phase, use --force |
|
669 | 669 | no phases changed |
|
670 | 670 | [1] |
|
671 | 671 | |
|
672 | 672 | $ cd .. |
|
673 | 673 | |
|
674 | 674 | test hidden changeset are not cloned as public (issue3935) |
|
675 | 675 | |
|
676 | 676 | $ cd initialrepo |
|
677 | 677 | |
|
678 | 678 | (enabling evolution) |
|
679 | 679 | $ cat >> $HGRCPATH << EOF |
|
680 | 680 | > [experimental] |
|
681 | 681 | > evolution.createmarkers=True |
|
682 | 682 | > EOF |
|
683 | 683 | |
|
684 | 684 | (making a changeset hidden; H in that case) |
|
685 | 685 | $ hg debugobsolete `hg id --debug -r 5` |
|
686 | 686 | 1 new obsolescence markers |
|
687 | 687 | obsoleted 1 changesets |
|
688 | 688 | |
|
689 | 689 | $ cd .. |
|
690 | 690 | $ hg clone initialrepo clonewithobs |
|
691 | 691 | requesting all changes |
|
692 | 692 | adding changesets |
|
693 | 693 | adding manifests |
|
694 | 694 | adding file changes |
|
695 | 695 | added 7 changesets with 6 changes to 6 files |
|
696 | 696 | new changesets 4a2df7238c3b:17a481b3bccb |
|
697 | 697 | test-debug-phase: new rev 0: x -> 0 |
|
698 | 698 | test-debug-phase: new rev 1: x -> 0 |
|
699 | 699 | test-debug-phase: new rev 2: x -> 0 |
|
700 | 700 | test-debug-phase: new rev 3: x -> 0 |
|
701 | 701 | test-debug-phase: new rev 4: x -> 0 |
|
702 | 702 | test-debug-phase: new rev 5: x -> 0 |
|
703 | 703 | test-debug-phase: new rev 6: x -> 0 |
|
704 | 704 | test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: -> public |
|
705 | 705 | test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56: -> public |
|
706 | 706 | test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757: -> public |
|
707 | 707 | test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: -> public |
|
708 | 708 | test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde: -> public |
|
709 | 709 | test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519: -> public |
|
710 | 710 | test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af: -> public |
|
711 | 711 | updating to branch default |
|
712 | 712 | 6 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
713 | 713 | $ cd clonewithobs |
|
714 | 714 | $ hg log -G --template "{rev} {phase} {desc}\n" |
|
715 | 715 | @ 6 public merge B' and E |
|
716 | 716 | |\ |
|
717 | 717 | | o 5 public B' |
|
718 | 718 | | | |
|
719 | 719 | o | 4 public E |
|
720 | 720 | | | |
|
721 | 721 | o | 3 public D |
|
722 | 722 | | | |
|
723 | 723 | o | 2 public C |
|
724 | 724 | |/ |
|
725 | 725 | o 1 public B |
|
726 | 726 | | |
|
727 | 727 | o 0 public A |
|
728 | 728 | |
|
729 | 729 | |
|
730 | 730 | test verify repo containing hidden changesets, which should not abort just |
|
731 | 731 | because repo.cancopy() is False |
|
732 | 732 | |
|
733 | 733 | $ cd ../initialrepo |
|
734 | 734 | $ hg verify |
|
735 | 735 | checking changesets |
|
736 | 736 | checking manifests |
|
737 | 737 | crosschecking files in changesets and manifests |
|
738 | 738 | checking files |
|
739 | 739 | checked 8 changesets with 7 changes to 7 files |
|
740 | 740 | |
|
741 | 741 | $ cd .. |
|
742 | 742 | |
|
743 | 743 | check whether HG_PENDING makes pending changes only in related |
|
744 | 744 | repositories visible to an external hook. |
|
745 | 745 | |
|
746 | 746 | (emulate a transaction running concurrently by copied |
|
747 | 747 | .hg/phaseroots.pending in subsequent test) |
|
748 | 748 | |
|
749 | 749 | $ cat > $TESTTMP/savepending.sh <<EOF |
|
750 | 750 | > cp .hg/store/phaseroots.pending .hg/store/phaseroots.pending.saved |
|
751 | 751 | > exit 1 # to avoid changing phase for subsequent tests |
|
752 | 752 | > EOF |
|
753 | 753 | $ cd push-dest |
|
754 | 754 | $ hg phase 6 |
|
755 | 755 | 6: draft |
|
756 | 756 | $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" phase -f -s 6 |
|
757 | 757 | transaction abort! |
|
758 | 758 | rollback completed |
|
759 | 759 | abort: pretxnclose hook exited with status 1 |
|
760 | 760 | [255] |
|
761 | 761 | $ cp .hg/store/phaseroots.pending.saved .hg/store/phaseroots.pending |
|
762 | 762 | |
|
763 | 763 | (check (in)visibility of phaseroot while transaction running in repo) |
|
764 | 764 | |
|
765 | 765 | $ cat > $TESTTMP/checkpending.sh <<EOF |
|
766 | 766 | > echo '@initialrepo' |
|
767 | 767 | > hg -R "$TESTTMP/initialrepo" phase 7 |
|
768 | 768 | > echo '@push-dest' |
|
769 | 769 | > hg -R "$TESTTMP/push-dest" phase 6 |
|
770 | 770 | > exit 1 # to avoid changing phase for subsequent tests |
|
771 | 771 | > EOF |
|
772 | 772 | $ cd ../initialrepo |
|
773 | 773 | $ hg phase 7 |
|
774 | 774 | 7: public |
|
775 | 775 | $ hg --config hooks.pretxnclose="sh $TESTTMP/checkpending.sh" phase -f -s 7 |
|
776 | 776 | @initialrepo |
|
777 | 777 | 7: secret |
|
778 | 778 | @push-dest |
|
779 | 779 | 6: draft |
|
780 | 780 | transaction abort! |
|
781 | 781 | rollback completed |
|
782 | 782 | abort: pretxnclose hook exited with status 1 |
|
783 | 783 | [255] |
|
784 | 784 | |
|
785 | 785 | Check that pretxnclose-phase hook can control phase movement |
|
786 | 786 | |
|
787 | 787 | $ hg phase --force b3325c91a4d9 --secret |
|
788 | 788 | test-debug-phase: move rev 3: 0 -> 2 |
|
789 | 789 | test-debug-phase: move rev 4: 0 -> 2 |
|
790 | 790 | test-debug-phase: move rev 5: 1 -> 2 |
|
791 | 791 | test-debug-phase: move rev 7: 0 -> 2 |
|
792 | 792 | test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: public -> secret |
|
793 | 793 | test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde: public -> secret |
|
794 | 794 | test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8: draft -> secret |
|
795 | 795 | test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af: public -> secret |
|
796 | 796 | $ hg log -G -T phases |
|
797 | 797 | @ changeset: 7:17a481b3bccb |
|
798 | 798 | |\ tag: tip |
|
799 | 799 | | | phase: secret |
|
800 | 800 | | | parent: 6:cf9fe039dfd6 |
|
801 | 801 | | | parent: 4:a603bfb5a83e |
|
802 | 802 | | | user: test |
|
803 | 803 | | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
804 | 804 | | | summary: merge B' and E |
|
805 | 805 | | | |
|
806 | 806 | | o changeset: 6:cf9fe039dfd6 |
|
807 | 807 | | | phase: public |
|
808 | 808 | | | parent: 1:27547f69f254 |
|
809 | 809 | | | user: test |
|
810 | 810 | | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
811 | 811 | | | summary: B' |
|
812 | 812 | | | |
|
813 | 813 | o | changeset: 4:a603bfb5a83e |
|
814 | 814 | | | phase: secret |
|
815 | 815 | | | user: test |
|
816 | 816 | | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
817 | 817 | | | summary: E |
|
818 | 818 | | | |
|
819 | 819 | o | changeset: 3:b3325c91a4d9 |
|
820 | 820 | | | phase: secret |
|
821 | 821 | | | user: test |
|
822 | 822 | | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
823 | 823 | | | summary: D |
|
824 | 824 | | | |
|
825 | 825 | o | changeset: 2:f838bfaca5c7 |
|
826 | 826 | |/ phase: public |
|
827 | 827 | | user: test |
|
828 | 828 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
829 | 829 | | summary: C |
|
830 | 830 | | |
|
831 | 831 | o changeset: 1:27547f69f254 |
|
832 | 832 | | phase: public |
|
833 | 833 | | user: test |
|
834 | 834 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
835 | 835 | | summary: B |
|
836 | 836 | | |
|
837 | 837 | o changeset: 0:4a2df7238c3b |
|
838 | 838 | phase: public |
|
839 | 839 | user: test |
|
840 | 840 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
841 | 841 | summary: A |
|
842 | 842 | |
|
843 | 843 | |
|
844 | 844 | Install a hook that prevent b3325c91a4d9 to become public |
|
845 | 845 | |
|
846 | 846 | $ cat >> .hg/hgrc << EOF |
|
847 | 847 | > [hooks] |
|
848 | 848 | > pretxnclose-phase.nopublish_D = sh -c "(echo \$HG_NODE| grep -v b3325c91a4d9>/dev/null) || [ 'public' != \$HG_PHASE ]" |
|
849 | 849 | > EOF |
|
850 | 850 | |
|
851 | 851 | Try various actions. only the draft move should succeed |
|
852 | 852 | |
|
853 | 853 | $ hg phase --public b3325c91a4d9 |
|
854 | 854 | transaction abort! |
|
855 | 855 | rollback completed |
|
856 | 856 | abort: pretxnclose-phase.nopublish_D hook exited with status 1 |
|
857 | 857 | [255] |
|
858 | 858 | $ hg phase --public a603bfb5a83e |
|
859 | 859 | transaction abort! |
|
860 | 860 | rollback completed |
|
861 | 861 | abort: pretxnclose-phase.nopublish_D hook exited with status 1 |
|
862 | 862 | [255] |
|
863 | 863 | $ hg phase --draft 17a481b3bccb |
|
864 | 864 | test-debug-phase: move rev 3: 2 -> 1 |
|
865 | 865 | test-debug-phase: move rev 4: 2 -> 1 |
|
866 | 866 | test-debug-phase: move rev 7: 2 -> 1 |
|
867 | 867 | test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: secret -> draft |
|
868 | 868 | test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde: secret -> draft |
|
869 | 869 | test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af: secret -> draft |
|
870 | 870 | $ hg phase --public 17a481b3bccb |
|
871 | 871 | transaction abort! |
|
872 | 872 | rollback completed |
|
873 | 873 | abort: pretxnclose-phase.nopublish_D hook exited with status 1 |
|
874 | 874 | [255] |
|
875 | 875 | |
|
876 | 876 | $ cd .. |
|
877 | 877 | |
|
878 | 878 | Test for the "internal" phase |
|
879 | 879 | ============================= |
|
880 | 880 | |
|
881 | 881 | Check we deny its usage on older repository |
|
882 | 882 | |
|
883 | 883 | $ hg init no-internal-phase --config format.internal-phase=no |
|
884 | 884 | $ cd no-internal-phase |
|
885 | 885 | $ cat .hg/requires |
|
886 | 886 | dotencode |
|
887 | 887 | fncache |
|
888 | 888 | generaldelta |
|
889 | 889 | revlogv1 |
|
890 | 890 | sparserevlog |
|
891 | 891 | store |
|
892 | 892 | $ echo X > X |
|
893 | 893 | $ hg add X |
|
894 | 894 | $ hg status |
|
895 | 895 | A X |
|
896 | 896 | $ hg --config "phases.new-commit=internal" commit -m "my test internal commit" 2>&1 | grep ProgrammingError |
|
897 | 897 | ** ProgrammingError: this repository does not support the internal phase |
|
898 | 898 | raise error.ProgrammingError(msg) |
|
899 | 899 | *ProgrammingError: this repository does not support the internal phase (glob) |
|
900 | 900 | $ hg --config "phases.new-commit=archived" commit -m "my test archived commit" 2>&1 | grep ProgrammingError |
|
901 | 901 | ** ProgrammingError: this repository does not support the archived phase |
|
902 | 902 | raise error.ProgrammingError(msg) |
|
903 | 903 | *ProgrammingError: this repository does not support the archived phase (glob) |
|
904 | 904 | |
|
905 | 905 | $ cd .. |
|
906 | 906 | |
|
907 | 907 | Check it works fine with repository that supports it. |
|
908 | 908 | |
|
909 | 909 | $ hg init internal-phase --config format.internal-phase=yes |
|
910 | 910 | $ cd internal-phase |
|
911 | 911 | $ cat .hg/requires |
|
912 | 912 | dotencode |
|
913 | 913 | fncache |
|
914 | 914 | generaldelta |
|
915 | 915 | internal-phase |
|
916 | 916 | revlogv1 |
|
917 | 917 | sparserevlog |
|
918 | 918 | store |
|
919 | 919 | $ mkcommit A |
|
920 | 920 | test-debug-phase: new rev 0: x -> 1 |
|
921 | 921 | test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: -> draft |
|
922 | 922 | |
|
923 | 923 | Commit an internal changesets |
|
924 | 924 | |
|
925 | 925 | $ echo B > B |
|
926 | 926 | $ hg add B |
|
927 | 927 | $ hg status |
|
928 | 928 | A B |
|
929 | 929 | $ hg --config "phases.new-commit=internal" commit -m "my test internal commit" |
|
930 | 930 | test-debug-phase: new rev 1: x -> 96 |
|
931 | 931 | test-hook-close-phase: c01c42dffc7f81223397e99652a0703f83e1c5ea: -> internal |
|
932 | 932 | |
|
933 | 933 | The changeset is a working parent descendant. |
|
934 | 934 | Per the usual visibility rules, it is made visible. |
|
935 | 935 | |
|
936 | 936 | $ hg log -G -l 3 |
|
937 | 937 | @ changeset: 1:c01c42dffc7f |
|
938 | 938 | | tag: tip |
|
939 | 939 | | user: test |
|
940 | 940 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
941 | 941 | | summary: my test internal commit |
|
942 | 942 | | |
|
943 | 943 | o changeset: 0:4a2df7238c3b |
|
944 | 944 | user: test |
|
945 | 945 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
946 | 946 | summary: A |
|
947 | 947 | |
|
948 | 948 | |
|
949 | 949 | Commit is hidden as expected |
|
950 | 950 | |
|
951 | 951 | $ hg up 0 |
|
952 | 952 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
953 | 953 | $ hg log -G |
|
954 | 954 | @ changeset: 0:4a2df7238c3b |
|
955 | 955 | tag: tip |
|
956 | 956 | user: test |
|
957 | 957 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
958 | 958 | summary: A |
|
959 | 959 | |
|
960 | 960 | |
|
961 | 961 | Test for archived phase |
|
962 | 962 | ----------------------- |
|
963 | 963 | |
|
964 | 964 | Commit an archived changesets |
|
965 | 965 | |
|
966 | 966 | $ echo B > B |
|
967 | 967 | $ hg add B |
|
968 | 968 | $ hg status |
|
969 | 969 | A B |
|
970 | 970 | $ hg --config "phases.new-commit=archived" commit -m "my test archived commit" |
|
971 | 971 | test-debug-phase: new rev 2: x -> 32 |
|
972 | 972 | test-hook-close-phase: 8df5997c3361518f733d1ae67cd3adb9b0eaf125: -> archived |
|
973 | 973 | |
|
974 | 974 | The changeset is a working parent descendant. |
|
975 | 975 | Per the usual visibility rules, it is made visible. |
|
976 | 976 | |
|
977 | 977 | $ hg log -G -l 3 |
|
978 | 978 | @ changeset: 2:8df5997c3361 |
|
979 | 979 | | tag: tip |
|
980 | 980 | | parent: 0:4a2df7238c3b |
|
981 | 981 | | user: test |
|
982 | 982 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
983 | 983 | | summary: my test archived commit |
|
984 | 984 | | |
|
985 | 985 | o changeset: 0:4a2df7238c3b |
|
986 | 986 | user: test |
|
987 | 987 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
988 | 988 | summary: A |
|
989 | 989 | |
|
990 | 990 | |
|
991 | 991 | Commit is hidden as expected |
|
992 | 992 | |
|
993 | 993 | $ hg up 0 |
|
994 | 994 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
995 | 995 | $ hg log -G |
|
996 | 996 | @ changeset: 0:4a2df7238c3b |
|
997 | 997 | tag: tip |
|
998 | 998 | user: test |
|
999 | 999 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
1000 | 1000 | summary: A |
|
1001 | 1001 | |
|
1002 | 1002 | $ cd .. |
|
1003 | 1003 | |
|
1004 | 1004 | Recommitting an exact match of a public commit shouldn't change it to |
|
1005 | 1005 | draft: |
|
1006 | 1006 | |
|
1007 | 1007 | $ cd initialrepo |
|
1008 | 1008 | $ hg phase -r 2 |
|
1009 | 1009 | 2: public |
|
1010 | 1010 | $ hg up -C 1 |
|
1011 | 1011 | 0 files updated, 0 files merged, 4 files removed, 0 files unresolved |
|
1012 | 1012 | $ mkcommit C |
|
1013 | created new head | |
|
1013 | warning: commit already existed in the repository! | |
|
1014 | 1014 | $ hg phase -r 2 |
|
1015 | 1015 | 2: public |
|
1016 | 1016 | |
|
1017 | 1017 | Same, but for secret: |
|
1018 | 1018 | |
|
1019 | 1019 | $ hg up 7 |
|
1020 | 1020 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
1021 | 1021 | $ mkcommit F -s |
|
1022 | 1022 | test-debug-phase: new rev 8: x -> 2 |
|
1023 | 1023 | test-hook-close-phase: de414268ec5ce2330c590b942fbb5ff0b0ca1a0a: -> secret |
|
1024 | 1024 | $ hg up 7 |
|
1025 | 1025 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
1026 | 1026 | $ hg phase |
|
1027 | 1027 | 7: draft |
|
1028 | 1028 | $ mkcommit F |
|
1029 | 1029 | test-debug-phase: new rev 8: x -> 2 |
|
1030 | warning: commit already existed in the repository! | |
|
1030 | 1031 | test-hook-close-phase: de414268ec5ce2330c590b942fbb5ff0b0ca1a0a: -> secret |
|
1031 | 1032 | $ hg phase -r tip |
|
1032 | 1033 | 8: secret |
|
1033 | 1034 | |
|
1034 | 1035 | But what about obsoleted changesets? |
|
1035 | 1036 | |
|
1036 | 1037 | $ hg up 4 |
|
1037 | 1038 | 0 files updated, 0 files merged, 2 files removed, 0 files unresolved |
|
1038 | 1039 | $ mkcommit H |
|
1039 | 1040 | test-debug-phase: new rev 5: x -> 2 |
|
1040 | created new head | |
|
1041 | warning: commit already existed in the repository! | |
|
1041 | 1042 | test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8: -> secret |
|
1042 | 1043 | $ hg phase -r 5 |
|
1043 | 1044 | 5: secret |
|
1044 | 1045 | $ hg par |
|
1045 | 1046 | changeset: 5:a030c6be5127 |
|
1046 | 1047 | user: test |
|
1047 | 1048 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
1048 | 1049 | obsolete: pruned |
|
1049 | 1050 | summary: H |
|
1050 | 1051 | |
|
1051 | 1052 | $ hg up tip |
|
1052 | 1053 | 2 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
1053 | 1054 | $ cd .. |
@@ -1,208 +1,209 b'' | |||
|
1 | 1 | #require no-windows |
|
2 | 2 | |
|
3 | 3 | $ . "$TESTDIR/remotefilelog-library.sh" |
|
4 | 4 | |
|
5 | 5 | $ hg init master |
|
6 | 6 | $ cd master |
|
7 | 7 | $ cat >> .hg/hgrc <<EOF |
|
8 | 8 | > [remotefilelog] |
|
9 | 9 | > server=True |
|
10 | 10 | > EOF |
|
11 | 11 | $ echo x > x |
|
12 | 12 | $ echo y > y |
|
13 | 13 | $ echo z > z |
|
14 | 14 | $ hg commit -qAm xy |
|
15 | 15 | |
|
16 | 16 | $ cd .. |
|
17 | 17 | |
|
18 | 18 | $ hgcloneshallow ssh://user@dummy/master shallow -q |
|
19 | 19 | 3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over *s (glob) |
|
20 | 20 | $ cd shallow |
|
21 | 21 | |
|
22 | 22 | # status |
|
23 | 23 | |
|
24 | 24 | $ clearcache |
|
25 | 25 | $ echo xx > x |
|
26 | 26 | $ echo yy > y |
|
27 | 27 | $ touch a |
|
28 | 28 | $ hg status |
|
29 | 29 | M x |
|
30 | 30 | M y |
|
31 | 31 | ? a |
|
32 | 32 | 1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
|
33 | 33 | $ hg add a |
|
34 | 34 | $ hg status |
|
35 | 35 | M x |
|
36 | 36 | M y |
|
37 | 37 | A a |
|
38 | 38 | |
|
39 | 39 | # diff |
|
40 | 40 | |
|
41 | 41 | $ hg debugrebuilddirstate # fixes dirstate non-determinism |
|
42 | 42 | $ hg add a |
|
43 | 43 | $ clearcache |
|
44 | 44 | $ hg diff |
|
45 | 45 | diff -r f3d0bb0d1e48 x |
|
46 | 46 | --- a/x* (glob) |
|
47 | 47 | +++ b/x* (glob) |
|
48 | 48 | @@ -1,1 +1,1 @@ |
|
49 | 49 | -x |
|
50 | 50 | +xx |
|
51 | 51 | diff -r f3d0bb0d1e48 y |
|
52 | 52 | --- a/y* (glob) |
|
53 | 53 | +++ b/y* (glob) |
|
54 | 54 | @@ -1,1 +1,1 @@ |
|
55 | 55 | -y |
|
56 | 56 | +yy |
|
57 | 57 | 3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over *s (glob) |
|
58 | 58 | |
|
59 | 59 | # local commit |
|
60 | 60 | |
|
61 | 61 | $ clearcache |
|
62 | 62 | $ echo a > a |
|
63 | 63 | $ echo xxx > x |
|
64 | 64 | $ echo yyy > y |
|
65 | 65 | $ hg commit -m a |
|
66 | 66 | ? files fetched over 1 fetches - (? misses, 0.00% hit ratio) over *s (glob) |
|
67 | 67 | |
|
68 | 68 | # local commit where the dirstate is clean -- ensure that we do just one fetch |
|
69 | 69 | # (update to a commit on the server first) |
|
70 | 70 | |
|
71 | 71 | $ hg --config debug.dirstate.delaywrite=1 up 0 |
|
72 | 72 | 2 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
73 | 73 | $ clearcache |
|
74 | 74 | $ hg debugdirstate |
|
75 | 75 | n 644 2 * x (glob) |
|
76 | 76 | n 644 2 * y (glob) |
|
77 | 77 | n 644 2 * z (glob) |
|
78 | 78 | $ echo xxxx > x |
|
79 | 79 | $ echo yyyy > y |
|
80 | 80 | $ hg commit -m x |
|
81 | 81 | created new head |
|
82 | 82 | 2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) |
|
83 | 83 | |
|
84 | 84 | # restore state for future tests |
|
85 | 85 | |
|
86 | 86 | $ hg -q strip . |
|
87 | 87 | $ hg -q up tip |
|
88 | 88 | |
|
89 | 89 | # rebase |
|
90 | 90 | |
|
91 | 91 | $ clearcache |
|
92 | 92 | $ cd ../master |
|
93 | 93 | $ echo w > w |
|
94 | 94 | $ hg commit -qAm w |
|
95 | 95 | |
|
96 | 96 | $ cd ../shallow |
|
97 | 97 | $ hg pull |
|
98 | 98 | pulling from ssh://user@dummy/master |
|
99 | 99 | searching for changes |
|
100 | 100 | adding changesets |
|
101 | 101 | adding manifests |
|
102 | 102 | adding file changes |
|
103 | 103 | added 1 changesets with 0 changes to 0 files (+1 heads) |
|
104 | 104 | new changesets fed61014d323 |
|
105 | 105 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
106 | 106 | |
|
107 | 107 | $ hg rebase -d tip |
|
108 | 108 | rebasing 1:9abfe7bca547 "a" |
|
109 | 109 | saved backup bundle to $TESTTMP/shallow/.hg/strip-backup/9abfe7bca547-8b11e5ff-rebase.hg (glob) |
|
110 | 110 | 3 files fetched over 2 fetches - (3 misses, 0.00% hit ratio) over *s (glob) |
|
111 | 111 | |
|
112 | 112 | # strip |
|
113 | 113 | |
|
114 | 114 | $ clearcache |
|
115 | 115 | $ hg debugrebuilddirstate # fixes dirstate non-determinism |
|
116 | 116 | $ hg strip -r . |
|
117 | 117 | 2 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
118 | 118 | saved backup bundle to $TESTTMP/shallow/.hg/strip-backup/19edf50f4de7-df3d0f74-backup.hg (glob) |
|
119 | 119 | 4 files fetched over 2 fetches - (4 misses, 0.00% hit ratio) over *s (glob) |
|
120 | 120 | |
|
121 | 121 | # unbundle |
|
122 | 122 | |
|
123 | 123 | $ clearcache |
|
124 | 124 | $ ls -A |
|
125 | 125 | .hg |
|
126 | 126 | w |
|
127 | 127 | x |
|
128 | 128 | y |
|
129 | 129 | z |
|
130 | 130 | |
|
131 | 131 | $ hg debugrebuilddirstate # fixes dirstate non-determinism |
|
132 | 132 | $ hg unbundle .hg/strip-backup/19edf50f4de7-df3d0f74-backup.hg |
|
133 | 133 | adding changesets |
|
134 | 134 | adding manifests |
|
135 | 135 | adding file changes |
|
136 | 136 | added 1 changesets with 0 changes to 0 files |
|
137 | 137 | new changesets 19edf50f4de7 (1 drafts) |
|
138 | 138 | (run 'hg update' to get a working copy) |
|
139 | 139 | |
|
140 | 140 | $ hg up |
|
141 | 141 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
142 | 142 | 4 files fetched over 1 fetches - (4 misses, 0.00% hit ratio) over *s (glob) |
|
143 | 143 | $ cat a |
|
144 | 144 | a |
|
145 | 145 | |
|
146 | 146 | # revert |
|
147 | 147 | |
|
148 | 148 | $ clearcache |
|
149 | 149 | $ hg revert -r .~2 y z |
|
150 | 150 | no changes needed to z |
|
151 | 151 | 2 files fetched over 2 fetches - (2 misses, 0.00% hit ratio) over *s (glob) |
|
152 | 152 | $ hg checkout -C -r . -q |
|
153 | 153 | |
|
154 | 154 | # explicit bundle should produce full bundle file |
|
155 | 155 | |
|
156 | 156 | $ hg bundle -r 2 --base 1 ../local.bundle |
|
157 | 157 | 1 changesets found |
|
158 | 158 | 1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
|
159 | 159 | $ cd .. |
|
160 | 160 | |
|
161 | 161 | $ hgcloneshallow ssh://user@dummy/master shallow2 -q |
|
162 | 162 | 1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
|
163 | 163 | $ cd shallow2 |
|
164 | 164 | $ hg unbundle ../local.bundle |
|
165 | 165 | adding changesets |
|
166 | 166 | adding manifests |
|
167 | 167 | adding file changes |
|
168 | 168 | added 1 changesets with 3 changes to 3 files |
|
169 | 169 | new changesets 19edf50f4de7 (1 drafts) |
|
170 | 170 | (run 'hg update' to get a working copy) |
|
171 | 171 | |
|
172 | 172 | $ hg log -r 2 --stat |
|
173 | 173 | changeset: 2:19edf50f4de7 |
|
174 | 174 | tag: tip |
|
175 | 175 | user: test |
|
176 | 176 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
177 | 177 | summary: a |
|
178 | 178 | |
|
179 | 179 | a | 1 + |
|
180 | 180 | x | 2 +- |
|
181 | 181 | y | 2 +- |
|
182 | 182 | 3 files changed, 3 insertions(+), 2 deletions(-) |
|
183 | 183 | |
|
184 | 184 | # Merge |
|
185 | 185 | |
|
186 | 186 | $ echo merge >> w |
|
187 | 187 | $ hg commit -m w |
|
188 | 188 | created new head |
|
189 | 189 | $ hg merge 2 |
|
190 | 190 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
191 | 191 | (branch merge, don't forget to commit) |
|
192 | 192 | $ hg commit -m merge |
|
193 | 193 | $ hg strip -q -r ".^" |
|
194 | 194 | |
|
195 | 195 | # commit without producing new node |
|
196 | 196 | |
|
197 | 197 | $ cd $TESTTMP |
|
198 | 198 | $ hgcloneshallow ssh://user@dummy/master shallow3 -q |
|
199 | 199 | $ cd shallow3 |
|
200 | 200 | $ echo 1 > A |
|
201 | 201 | $ hg commit -m foo -A A |
|
202 | 202 | $ hg log -r . -T '{node}\n' |
|
203 | 203 | 383ce605500277f879b7460a16ba620eb6930b7f |
|
204 | 204 | $ hg update -r '.^' -q |
|
205 | 205 | $ echo 1 > A |
|
206 | 206 | $ hg commit -m foo -A A |
|
207 | warning: commit already existed in the repository! | |
|
207 | 208 | $ hg log -r . -T '{node}\n' |
|
208 | 209 | 383ce605500277f879b7460a16ba620eb6930b7f |
@@ -1,419 +1,421 b'' | |||
|
1 | 1 | Test for command `hg unamend` which lives in uncommit extension |
|
2 | 2 | =============================================================== |
|
3 | 3 | |
|
4 | 4 | $ cat >> $HGRCPATH << EOF |
|
5 | 5 | > [alias] |
|
6 | 6 | > glog = log -G -T '{rev}:{node|short} {desc}' |
|
7 | 7 | > [experimental] |
|
8 | 8 | > evolution = createmarkers, allowunstable |
|
9 | 9 | > [extensions] |
|
10 | 10 | > rebase = |
|
11 | 11 | > amend = |
|
12 | 12 | > uncommit = |
|
13 | 13 | > EOF |
|
14 | 14 | |
|
15 | 15 | Repo Setup |
|
16 | 16 | |
|
17 | 17 | $ hg init repo |
|
18 | 18 | $ cd repo |
|
19 | 19 | $ for ch in a b c d e f g h; do touch $ch; echo "foo" >> $ch; hg ci -Aqm "Added "$ch; done |
|
20 | 20 | |
|
21 | 21 | $ hg glog |
|
22 | 22 | @ 7:ec2426147f0e Added h |
|
23 | 23 | | |
|
24 | 24 | o 6:87d6d6676308 Added g |
|
25 | 25 | | |
|
26 | 26 | o 5:825660c69f0c Added f |
|
27 | 27 | | |
|
28 | 28 | o 4:aa98ab95a928 Added e |
|
29 | 29 | | |
|
30 | 30 | o 3:62615734edd5 Added d |
|
31 | 31 | | |
|
32 | 32 | o 2:28ad74487de9 Added c |
|
33 | 33 | | |
|
34 | 34 | o 1:29becc82797a Added b |
|
35 | 35 | | |
|
36 | 36 | o 0:18d04c59bb5d Added a |
|
37 | 37 | |
|
38 | 38 | Trying to unamend when there was no amend done |
|
39 | 39 | |
|
40 | 40 | $ hg unamend |
|
41 | 41 | abort: changeset must have one predecessor, found 0 predecessors |
|
42 | 42 | [255] |
|
43 | 43 | |
|
44 | 44 | Unamend on clean wdir and tip |
|
45 | 45 | |
|
46 | 46 | $ echo "bar" >> h |
|
47 | 47 | $ hg amend |
|
48 | 48 | |
|
49 | 49 | $ hg exp |
|
50 | 50 | # HG changeset patch |
|
51 | 51 | # User test |
|
52 | 52 | # Date 0 0 |
|
53 | 53 | # Thu Jan 01 00:00:00 1970 +0000 |
|
54 | 54 | # Node ID c9fa1a715c1b7661c0fafb362a9f30bd75878d7d |
|
55 | 55 | # Parent 87d6d66763085b629e6d7ed56778c79827273022 |
|
56 | 56 | Added h |
|
57 | 57 | |
|
58 | 58 | diff -r 87d6d6676308 -r c9fa1a715c1b h |
|
59 | 59 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
60 | 60 | +++ b/h Thu Jan 01 00:00:00 1970 +0000 |
|
61 | 61 | @@ -0,0 +1,2 @@ |
|
62 | 62 | +foo |
|
63 | 63 | +bar |
|
64 | 64 | |
|
65 | 65 | $ hg glog --hidden |
|
66 | 66 | @ 8:c9fa1a715c1b Added h |
|
67 | 67 | | |
|
68 | 68 | | x 7:ec2426147f0e Added h |
|
69 | 69 | |/ |
|
70 | 70 | o 6:87d6d6676308 Added g |
|
71 | 71 | | |
|
72 | 72 | o 5:825660c69f0c Added f |
|
73 | 73 | | |
|
74 | 74 | o 4:aa98ab95a928 Added e |
|
75 | 75 | | |
|
76 | 76 | o 3:62615734edd5 Added d |
|
77 | 77 | | |
|
78 | 78 | o 2:28ad74487de9 Added c |
|
79 | 79 | | |
|
80 | 80 | o 1:29becc82797a Added b |
|
81 | 81 | | |
|
82 | 82 | o 0:18d04c59bb5d Added a |
|
83 | 83 | |
|
84 | 84 | $ hg unamend |
|
85 | 85 | $ hg glog --hidden |
|
86 | 86 | @ 9:46d02d47eec6 Added h |
|
87 | 87 | | |
|
88 | 88 | | x 8:c9fa1a715c1b Added h |
|
89 | 89 | |/ |
|
90 | 90 | | x 7:ec2426147f0e Added h |
|
91 | 91 | |/ |
|
92 | 92 | o 6:87d6d6676308 Added g |
|
93 | 93 | | |
|
94 | 94 | o 5:825660c69f0c Added f |
|
95 | 95 | | |
|
96 | 96 | o 4:aa98ab95a928 Added e |
|
97 | 97 | | |
|
98 | 98 | o 3:62615734edd5 Added d |
|
99 | 99 | | |
|
100 | 100 | o 2:28ad74487de9 Added c |
|
101 | 101 | | |
|
102 | 102 | o 1:29becc82797a Added b |
|
103 | 103 | | |
|
104 | 104 | o 0:18d04c59bb5d Added a |
|
105 | 105 | |
|
106 | 106 | $ hg diff |
|
107 | 107 | diff -r 46d02d47eec6 h |
|
108 | 108 | --- a/h Thu Jan 01 00:00:00 1970 +0000 |
|
109 | 109 | +++ b/h Thu Jan 01 00:00:00 1970 +0000 |
|
110 | 110 | @@ -1,1 +1,2 @@ |
|
111 | 111 | foo |
|
112 | 112 | +bar |
|
113 | 113 | |
|
114 | 114 | $ hg exp |
|
115 | 115 | # HG changeset patch |
|
116 | 116 | # User test |
|
117 | 117 | # Date 0 0 |
|
118 | 118 | # Thu Jan 01 00:00:00 1970 +0000 |
|
119 | 119 | # Node ID 46d02d47eec6ca096b8dcab3f8f5579c40c3dd9a |
|
120 | 120 | # Parent 87d6d66763085b629e6d7ed56778c79827273022 |
|
121 | 121 | Added h |
|
122 | 122 | |
|
123 | 123 | diff -r 87d6d6676308 -r 46d02d47eec6 h |
|
124 | 124 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
125 | 125 | +++ b/h Thu Jan 01 00:00:00 1970 +0000 |
|
126 | 126 | @@ -0,0 +1,1 @@ |
|
127 | 127 | +foo |
|
128 | 128 | |
|
129 | 129 | $ hg status |
|
130 | 130 | M h |
|
131 | 131 | |
|
132 | 132 | $ hg log -r . -T '{extras % "{extra}\n"}' --config alias.log=log |
|
133 | 133 | branch=default |
|
134 | 134 | unamend_source=c9fa1a715c1b7661c0fafb362a9f30bd75878d7d |
|
135 | 135 | |
|
136 | 136 | Using unamend to undo an unamed (intentional) |
|
137 | 137 | |
|
138 | 138 | $ hg unamend |
|
139 | 139 | $ hg exp |
|
140 | 140 | # HG changeset patch |
|
141 | 141 | # User test |
|
142 | 142 | # Date 0 0 |
|
143 | 143 | # Thu Jan 01 00:00:00 1970 +0000 |
|
144 | 144 | # Node ID 850ddfc1bc662997ec6094ada958f01f0cc8070a |
|
145 | 145 | # Parent 87d6d66763085b629e6d7ed56778c79827273022 |
|
146 | 146 | Added h |
|
147 | 147 | |
|
148 | 148 | diff -r 87d6d6676308 -r 850ddfc1bc66 h |
|
149 | 149 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
150 | 150 | +++ b/h Thu Jan 01 00:00:00 1970 +0000 |
|
151 | 151 | @@ -0,0 +1,2 @@ |
|
152 | 152 | +foo |
|
153 | 153 | +bar |
|
154 | 154 | $ hg diff |
|
155 | 155 | |
|
156 | 156 | Unamend on a dirty working directory |
|
157 | 157 | |
|
158 | 158 | $ echo "bar" >> a |
|
159 | 159 | $ hg amend |
|
160 | 160 | $ echo "foobar" >> a |
|
161 | 161 | $ echo "bar" >> b |
|
162 | 162 | $ hg status |
|
163 | 163 | M a |
|
164 | 164 | M b |
|
165 | 165 | |
|
166 | 166 | $ hg unamend |
|
167 | 167 | |
|
168 | 168 | $ hg status |
|
169 | 169 | M a |
|
170 | 170 | M b |
|
171 | 171 | |
|
172 | 172 | $ hg diff |
|
173 | 173 | diff -r ec338db45d51 a |
|
174 | 174 | --- a/a Thu Jan 01 00:00:00 1970 +0000 |
|
175 | 175 | +++ b/a Thu Jan 01 00:00:00 1970 +0000 |
|
176 | 176 | @@ -1,1 +1,3 @@ |
|
177 | 177 | foo |
|
178 | 178 | +bar |
|
179 | 179 | +foobar |
|
180 | 180 | diff -r ec338db45d51 b |
|
181 | 181 | --- a/b Thu Jan 01 00:00:00 1970 +0000 |
|
182 | 182 | +++ b/b Thu Jan 01 00:00:00 1970 +0000 |
|
183 | 183 | @@ -1,1 +1,2 @@ |
|
184 | 184 | foo |
|
185 | 185 | +bar |
|
186 | 186 | |
|
187 | 187 | Unamending an added file |
|
188 | 188 | |
|
189 | 189 | $ hg ci -m "Added things to a and b" |
|
190 | 190 | $ echo foo > bar |
|
191 | 191 | $ hg add bar |
|
192 | 192 | $ hg amend |
|
193 | 193 | |
|
194 | 194 | $ hg unamend |
|
195 | 195 | $ hg status |
|
196 | 196 | A bar |
|
197 | 197 | |
|
198 | 198 | $ hg revert --all |
|
199 | 199 | forgetting bar |
|
200 | 200 | |
|
201 | 201 | Unamending a removed file |
|
202 | 202 | |
|
203 | 203 | $ hg remove a |
|
204 | 204 | $ hg amend |
|
205 | 205 | |
|
206 | 206 | $ hg unamend |
|
207 | 207 | $ hg status |
|
208 | 208 | R a |
|
209 | 209 | ? bar |
|
210 | 210 | |
|
211 | 211 | $ hg revert --all |
|
212 | 212 | undeleting a |
|
213 | 213 | |
|
214 | 214 | Unamending an added file with dirty wdir status |
|
215 | 215 | |
|
216 | 216 | $ hg add bar |
|
217 | 217 | $ hg amend |
|
218 | 218 | $ echo bar >> bar |
|
219 | 219 | $ hg status |
|
220 | 220 | M bar |
|
221 | 221 | |
|
222 | 222 | $ hg unamend |
|
223 | 223 | $ hg status |
|
224 | 224 | A bar |
|
225 | 225 | $ hg diff |
|
226 | 226 | diff -r 7f79409af972 bar |
|
227 | 227 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
228 | 228 | +++ b/bar Thu Jan 01 00:00:00 1970 +0000 |
|
229 | 229 | @@ -0,0 +1,2 @@ |
|
230 | 230 | +foo |
|
231 | 231 | +bar |
|
232 | 232 | |
|
233 | 233 | $ hg revert --all |
|
234 | 234 | forgetting bar |
|
235 | 235 | $ rm bar |
|
236 | 236 | |
|
237 | 237 | Unamending in middle of a stack |
|
238 | 238 | |
|
239 | 239 | $ hg glog |
|
240 | 240 | @ 19:7f79409af972 Added things to a and b |
|
241 | 241 | | |
|
242 | 242 | o 12:ec338db45d51 Added h |
|
243 | 243 | | |
|
244 | 244 | o 6:87d6d6676308 Added g |
|
245 | 245 | | |
|
246 | 246 | o 5:825660c69f0c Added f |
|
247 | 247 | | |
|
248 | 248 | o 4:aa98ab95a928 Added e |
|
249 | 249 | | |
|
250 | 250 | o 3:62615734edd5 Added d |
|
251 | 251 | | |
|
252 | 252 | o 2:28ad74487de9 Added c |
|
253 | 253 | | |
|
254 | 254 | o 1:29becc82797a Added b |
|
255 | 255 | | |
|
256 | 256 | o 0:18d04c59bb5d Added a |
|
257 | 257 | |
|
258 | 258 | $ hg up 5 |
|
259 | 259 | 2 files updated, 0 files merged, 2 files removed, 0 files unresolved |
|
260 | 260 | $ echo bar >> f |
|
261 | 261 | $ hg amend |
|
262 | 262 | 3 new orphan changesets |
|
263 | 263 | $ hg rebase -s 6 -d . -q |
|
264 | 264 | |
|
265 | 265 | $ hg glog |
|
266 | 266 | o 23:03ddd6fc5af1 Added things to a and b |
|
267 | 267 | | |
|
268 | 268 | o 22:3e7b64ee157b Added h |
|
269 | 269 | | |
|
270 | 270 | o 21:49635b68477e Added g |
|
271 | 271 | | |
|
272 | 272 | @ 20:93f0e8ffab32 Added f |
|
273 | 273 | | |
|
274 | 274 | o 4:aa98ab95a928 Added e |
|
275 | 275 | | |
|
276 | 276 | o 3:62615734edd5 Added d |
|
277 | 277 | | |
|
278 | 278 | o 2:28ad74487de9 Added c |
|
279 | 279 | | |
|
280 | 280 | o 1:29becc82797a Added b |
|
281 | 281 | | |
|
282 | 282 | o 0:18d04c59bb5d Added a |
|
283 | 283 | |
|
284 | 284 | |
|
285 | 285 | $ hg --config experimental.evolution=createmarkers unamend |
|
286 | 286 | abort: cannot unamend changeset with children |
|
287 | 287 | [255] |
|
288 | 288 | |
|
289 | 289 | $ hg unamend |
|
290 | 290 | 3 new orphan changesets |
|
291 | 291 | |
|
292 | 292 | Trying to unamend a public changeset |
|
293 | 293 | |
|
294 | 294 | $ hg up -C 23 |
|
295 | 295 | 5 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
296 | 296 | $ hg phase -r . -p |
|
297 | 297 | 1 new phase-divergent changesets |
|
298 | 298 | $ hg unamend |
|
299 | 299 | abort: cannot unamend public changesets |
|
300 | 300 | (see 'hg help phases' for details) |
|
301 | 301 | [255] |
|
302 | 302 | |
|
303 | 303 | Testing whether unamend retains copies or not |
|
304 | 304 | |
|
305 | 305 | $ hg status |
|
306 | 306 | |
|
307 | 307 | $ hg mv a foo |
|
308 | 308 | |
|
309 | 309 | $ hg ci -m "Moved a to foo" |
|
310 | 310 | $ hg exp --git |
|
311 | 311 | # HG changeset patch |
|
312 | 312 | # User test |
|
313 | 313 | # Date 0 0 |
|
314 | 314 | # Thu Jan 01 00:00:00 1970 +0000 |
|
315 | 315 | # Node ID cfef290346fbee5126313d7e1aab51d877679b09 |
|
316 | 316 | # Parent 03ddd6fc5af19e028c44a2fd6d790dd22712f231 |
|
317 | 317 | Moved a to foo |
|
318 | 318 | |
|
319 | 319 | diff --git a/a b/foo |
|
320 | 320 | rename from a |
|
321 | 321 | rename to foo |
|
322 | 322 | |
|
323 | 323 | $ hg mv b foobar |
|
324 | 324 | $ hg diff --git |
|
325 | 325 | diff --git a/b b/foobar |
|
326 | 326 | rename from b |
|
327 | 327 | rename to foobar |
|
328 | 328 | $ hg amend |
|
329 | 329 | |
|
330 | 330 | $ hg exp --git |
|
331 | 331 | # HG changeset patch |
|
332 | 332 | # User test |
|
333 | 333 | # Date 0 0 |
|
334 | 334 | # Thu Jan 01 00:00:00 1970 +0000 |
|
335 | 335 | # Node ID eca050985275bb271ce3092b54e56ea5c85d29a3 |
|
336 | 336 | # Parent 03ddd6fc5af19e028c44a2fd6d790dd22712f231 |
|
337 | 337 | Moved a to foo |
|
338 | 338 | |
|
339 | 339 | diff --git a/a b/foo |
|
340 | 340 | rename from a |
|
341 | 341 | rename to foo |
|
342 | 342 | diff --git a/b b/foobar |
|
343 | 343 | rename from b |
|
344 | 344 | rename to foobar |
|
345 | 345 | |
|
346 | 346 | $ hg mv c wat |
|
347 | 347 | $ hg unamend |
|
348 | 348 | |
|
349 | 349 | $ hg verify -v |
|
350 | 350 | repository uses revlog format 1 |
|
351 | 351 | checking changesets |
|
352 | 352 | checking manifests |
|
353 | 353 | crosschecking files in changesets and manifests |
|
354 | 354 | checking files |
|
355 | 355 | checked 28 changesets with 16 changes to 11 files |
|
356 | 356 | |
|
357 | 357 | Retained copies in new prdecessor commit |
|
358 | 358 | |
|
359 | 359 | $ hg exp --git |
|
360 | 360 | # HG changeset patch |
|
361 | 361 | # User test |
|
362 | 362 | # Date 0 0 |
|
363 | 363 | # Thu Jan 01 00:00:00 1970 +0000 |
|
364 | 364 | # Node ID 552e3af4f01f620f88ca27be1f898316235b736a |
|
365 | 365 | # Parent 03ddd6fc5af19e028c44a2fd6d790dd22712f231 |
|
366 | 366 | Moved a to foo |
|
367 | 367 | |
|
368 | 368 | diff --git a/a b/foo |
|
369 | 369 | rename from a |
|
370 | 370 | rename to foo |
|
371 | 371 | |
|
372 | 372 | Retained copies in working directoy |
|
373 | 373 | |
|
374 | 374 | $ hg diff --git |
|
375 | 375 | diff --git a/b b/foobar |
|
376 | 376 | rename from b |
|
377 | 377 | rename to foobar |
|
378 | 378 | diff --git a/c b/wat |
|
379 | 379 | rename from c |
|
380 | 380 | rename to wat |
|
381 | 381 | $ hg revert -qa |
|
382 | 382 | $ rm foobar wat |
|
383 | 383 | |
|
384 | 384 | Rename a->b, then amend b->c. After unamend, should look like b->c. |
|
385 | 385 | |
|
386 | 386 | $ hg co -q 0 |
|
387 | 387 | $ hg mv a b |
|
388 | 388 | $ hg ci -qm 'move to a b' |
|
389 | 389 | $ hg mv b c |
|
390 | 390 | $ hg amend |
|
391 | 391 | $ hg unamend |
|
392 | 392 | $ hg st --copies --change . |
|
393 | 393 | A b |
|
394 | 394 | a |
|
395 | 395 | R a |
|
396 | 396 | $ hg st --copies |
|
397 | 397 | A c |
|
398 | 398 | b |
|
399 | 399 | R b |
|
400 | 400 | $ hg revert -qa |
|
401 | 401 | $ rm c |
|
402 | 402 | |
|
403 | 403 | Rename a->b, then amend b->c, and working copy change c->d. After unamend, should look like b->d |
|
404 | 404 | |
|
405 | 405 | $ hg co -q 0 |
|
406 | 406 | $ hg mv a b |
|
407 | 407 | $ hg ci -qm 'move to a b' |
|
408 | warning: commit already existed in the repository! | |
|
408 | 409 | $ hg mv b c |
|
409 | 410 | $ hg amend |
|
411 | warning: commit already existed in the repository! | |
|
410 | 412 | $ hg mv c d |
|
411 | 413 | $ hg unamend |
|
412 | 414 | $ hg st --copies --change . |
|
413 | 415 | A b |
|
414 | 416 | a |
|
415 | 417 | R a |
|
416 | 418 | $ hg st --copies |
|
417 | 419 | A d |
|
418 | 420 | b |
|
419 | 421 | R b |
General Comments 0
You need to be logged in to leave comments.
Login now