Show More
@@ -1,5477 +1,5482 | |||
|
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 difflib |
|
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 | nullrev, |
|
20 | 20 | short, |
|
21 | 21 | ) |
|
22 | 22 | from . import ( |
|
23 | 23 | archival, |
|
24 | 24 | bookmarks, |
|
25 | 25 | bundle2, |
|
26 | 26 | changegroup, |
|
27 | 27 | cmdutil, |
|
28 | 28 | copies, |
|
29 | 29 | debugcommands as debugcommandsmod, |
|
30 | 30 | destutil, |
|
31 | 31 | dirstateguard, |
|
32 | 32 | discovery, |
|
33 | 33 | encoding, |
|
34 | 34 | error, |
|
35 | 35 | exchange, |
|
36 | 36 | extensions, |
|
37 | 37 | graphmod, |
|
38 | 38 | hbisect, |
|
39 | 39 | help, |
|
40 | 40 | hg, |
|
41 | 41 | lock as lockmod, |
|
42 | 42 | merge as mergemod, |
|
43 | 43 | obsolete, |
|
44 | 44 | patch, |
|
45 | 45 | phases, |
|
46 | 46 | pycompat, |
|
47 | 47 | rcutil, |
|
48 | 48 | registrar, |
|
49 | 49 | revsetlang, |
|
50 | 50 | scmutil, |
|
51 | 51 | server, |
|
52 | 52 | sshserver, |
|
53 | 53 | streamclone, |
|
54 | 54 | tags as tagsmod, |
|
55 | 55 | templatekw, |
|
56 | 56 | ui as uimod, |
|
57 | 57 | util, |
|
58 | 58 | ) |
|
59 | 59 | |
|
60 | 60 | release = lockmod.release |
|
61 | 61 | |
|
62 | 62 | table = {} |
|
63 | 63 | table.update(debugcommandsmod.command._table) |
|
64 | 64 | |
|
65 | 65 | command = registrar.command(table) |
|
66 | 66 | |
|
67 | 67 | # label constants |
|
68 | 68 | # until 3.5, bookmarks.current was the advertised name, not |
|
69 | 69 | # bookmarks.active, so we must use both to avoid breaking old |
|
70 | 70 | # custom styles |
|
71 | 71 | activebookmarklabel = 'bookmarks.active bookmarks.current' |
|
72 | 72 | |
|
73 | 73 | # common command options |
|
74 | 74 | |
|
75 | 75 | globalopts = [ |
|
76 | 76 | ('R', 'repository', '', |
|
77 | 77 | _('repository root directory or name of overlay bundle file'), |
|
78 | 78 | _('REPO')), |
|
79 | 79 | ('', 'cwd', '', |
|
80 | 80 | _('change working directory'), _('DIR')), |
|
81 | 81 | ('y', 'noninteractive', None, |
|
82 | 82 | _('do not prompt, automatically pick the first choice for all prompts')), |
|
83 | 83 | ('q', 'quiet', None, _('suppress output')), |
|
84 | 84 | ('v', 'verbose', None, _('enable additional output')), |
|
85 | 85 | ('', 'color', '', |
|
86 | 86 | # i18n: 'always', 'auto', 'never', and 'debug' are keywords |
|
87 | 87 | # and should not be translated |
|
88 | 88 | _("when to colorize (boolean, always, auto, never, or debug)"), |
|
89 | 89 | _('TYPE')), |
|
90 | 90 | ('', 'config', [], |
|
91 | 91 | _('set/override config option (use \'section.name=value\')'), |
|
92 | 92 | _('CONFIG')), |
|
93 | 93 | ('', 'debug', None, _('enable debugging output')), |
|
94 | 94 | ('', 'debugger', None, _('start debugger')), |
|
95 | 95 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), |
|
96 | 96 | _('ENCODE')), |
|
97 | 97 | ('', 'encodingmode', encoding.encodingmode, |
|
98 | 98 | _('set the charset encoding mode'), _('MODE')), |
|
99 | 99 | ('', 'traceback', None, _('always print a traceback on exception')), |
|
100 | 100 | ('', 'time', None, _('time how long the command takes')), |
|
101 | 101 | ('', 'profile', None, _('print command execution profile')), |
|
102 | 102 | ('', 'version', None, _('output version information and exit')), |
|
103 | 103 | ('h', 'help', None, _('display help and exit')), |
|
104 | 104 | ('', 'hidden', False, _('consider hidden changesets')), |
|
105 | 105 | ('', 'pager', 'auto', |
|
106 | 106 | _("when to paginate (boolean, always, auto, or never)"), _('TYPE')), |
|
107 | 107 | ] |
|
108 | 108 | |
|
109 | 109 | dryrunopts = cmdutil.dryrunopts |
|
110 | 110 | remoteopts = cmdutil.remoteopts |
|
111 | 111 | walkopts = cmdutil.walkopts |
|
112 | 112 | commitopts = cmdutil.commitopts |
|
113 | 113 | commitopts2 = cmdutil.commitopts2 |
|
114 | 114 | formatteropts = cmdutil.formatteropts |
|
115 | 115 | templateopts = cmdutil.templateopts |
|
116 | 116 | logopts = cmdutil.logopts |
|
117 | 117 | diffopts = cmdutil.diffopts |
|
118 | 118 | diffwsopts = cmdutil.diffwsopts |
|
119 | 119 | diffopts2 = cmdutil.diffopts2 |
|
120 | 120 | mergetoolopts = cmdutil.mergetoolopts |
|
121 | 121 | similarityopts = cmdutil.similarityopts |
|
122 | 122 | subrepoopts = cmdutil.subrepoopts |
|
123 | 123 | debugrevlogopts = cmdutil.debugrevlogopts |
|
124 | 124 | |
|
125 | 125 | # Commands start here, listed alphabetically |
|
126 | 126 | |
|
127 | 127 | @command('^add', |
|
128 | 128 | walkopts + subrepoopts + dryrunopts, |
|
129 | 129 | _('[OPTION]... [FILE]...'), |
|
130 | 130 | inferrepo=True) |
|
131 | 131 | def add(ui, repo, *pats, **opts): |
|
132 | 132 | """add the specified files on the next commit |
|
133 | 133 | |
|
134 | 134 | Schedule files to be version controlled and added to the |
|
135 | 135 | repository. |
|
136 | 136 | |
|
137 | 137 | The files will be added to the repository at the next commit. To |
|
138 | 138 | undo an add before that, see :hg:`forget`. |
|
139 | 139 | |
|
140 | 140 | If no names are given, add all files to the repository (except |
|
141 | 141 | files matching ``.hgignore``). |
|
142 | 142 | |
|
143 | 143 | .. container:: verbose |
|
144 | 144 | |
|
145 | 145 | Examples: |
|
146 | 146 | |
|
147 | 147 | - New (unknown) files are added |
|
148 | 148 | automatically by :hg:`add`:: |
|
149 | 149 | |
|
150 | 150 | $ ls |
|
151 | 151 | foo.c |
|
152 | 152 | $ hg status |
|
153 | 153 | ? foo.c |
|
154 | 154 | $ hg add |
|
155 | 155 | adding foo.c |
|
156 | 156 | $ hg status |
|
157 | 157 | A foo.c |
|
158 | 158 | |
|
159 | 159 | - Specific files to be added can be specified:: |
|
160 | 160 | |
|
161 | 161 | $ ls |
|
162 | 162 | bar.c foo.c |
|
163 | 163 | $ hg status |
|
164 | 164 | ? bar.c |
|
165 | 165 | ? foo.c |
|
166 | 166 | $ hg add bar.c |
|
167 | 167 | $ hg status |
|
168 | 168 | A bar.c |
|
169 | 169 | ? foo.c |
|
170 | 170 | |
|
171 | 171 | Returns 0 if all files are successfully added. |
|
172 | 172 | """ |
|
173 | 173 | |
|
174 | 174 | m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts)) |
|
175 | 175 | rejected = cmdutil.add(ui, repo, m, "", False, **opts) |
|
176 | 176 | return rejected and 1 or 0 |
|
177 | 177 | |
|
178 | 178 | @command('addremove', |
|
179 | 179 | similarityopts + subrepoopts + walkopts + dryrunopts, |
|
180 | 180 | _('[OPTION]... [FILE]...'), |
|
181 | 181 | inferrepo=True) |
|
182 | 182 | def addremove(ui, repo, *pats, **opts): |
|
183 | 183 | """add all new files, delete all missing files |
|
184 | 184 | |
|
185 | 185 | Add all new files and remove all missing files from the |
|
186 | 186 | repository. |
|
187 | 187 | |
|
188 | 188 | Unless names are given, new files are ignored if they match any of |
|
189 | 189 | the patterns in ``.hgignore``. As with add, these changes take |
|
190 | 190 | effect at the next commit. |
|
191 | 191 | |
|
192 | 192 | Use the -s/--similarity option to detect renamed files. This |
|
193 | 193 | option takes a percentage between 0 (disabled) and 100 (files must |
|
194 | 194 | be identical) as its parameter. With a parameter greater than 0, |
|
195 | 195 | this compares every removed file with every added file and records |
|
196 | 196 | those similar enough as renames. Detecting renamed files this way |
|
197 | 197 | can be expensive. After using this option, :hg:`status -C` can be |
|
198 | 198 | used to check which files were identified as moved or renamed. If |
|
199 | 199 | not specified, -s/--similarity defaults to 100 and only renames of |
|
200 | 200 | identical files are detected. |
|
201 | 201 | |
|
202 | 202 | .. container:: verbose |
|
203 | 203 | |
|
204 | 204 | Examples: |
|
205 | 205 | |
|
206 | 206 | - A number of files (bar.c and foo.c) are new, |
|
207 | 207 | while foobar.c has been removed (without using :hg:`remove`) |
|
208 | 208 | from the repository:: |
|
209 | 209 | |
|
210 | 210 | $ ls |
|
211 | 211 | bar.c foo.c |
|
212 | 212 | $ hg status |
|
213 | 213 | ! foobar.c |
|
214 | 214 | ? bar.c |
|
215 | 215 | ? foo.c |
|
216 | 216 | $ hg addremove |
|
217 | 217 | adding bar.c |
|
218 | 218 | adding foo.c |
|
219 | 219 | removing foobar.c |
|
220 | 220 | $ hg status |
|
221 | 221 | A bar.c |
|
222 | 222 | A foo.c |
|
223 | 223 | R foobar.c |
|
224 | 224 | |
|
225 | 225 | - A file foobar.c was moved to foo.c without using :hg:`rename`. |
|
226 | 226 | Afterwards, it was edited slightly:: |
|
227 | 227 | |
|
228 | 228 | $ ls |
|
229 | 229 | foo.c |
|
230 | 230 | $ hg status |
|
231 | 231 | ! foobar.c |
|
232 | 232 | ? foo.c |
|
233 | 233 | $ hg addremove --similarity 90 |
|
234 | 234 | removing foobar.c |
|
235 | 235 | adding foo.c |
|
236 | 236 | recording removal of foobar.c as rename to foo.c (94% similar) |
|
237 | 237 | $ hg status -C |
|
238 | 238 | A foo.c |
|
239 | 239 | foobar.c |
|
240 | 240 | R foobar.c |
|
241 | 241 | |
|
242 | 242 | Returns 0 if all files are successfully added. |
|
243 | 243 | """ |
|
244 | 244 | opts = pycompat.byteskwargs(opts) |
|
245 | 245 | try: |
|
246 | 246 | sim = float(opts.get('similarity') or 100) |
|
247 | 247 | except ValueError: |
|
248 | 248 | raise error.Abort(_('similarity must be a number')) |
|
249 | 249 | if sim < 0 or sim > 100: |
|
250 | 250 | raise error.Abort(_('similarity must be between 0 and 100')) |
|
251 | 251 | matcher = scmutil.match(repo[None], pats, opts) |
|
252 | 252 | return scmutil.addremove(repo, matcher, "", opts, similarity=sim / 100.0) |
|
253 | 253 | |
|
254 | 254 | @command('^annotate|blame', |
|
255 | 255 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), |
|
256 | 256 | ('', 'follow', None, |
|
257 | 257 | _('follow copies/renames and list the filename (DEPRECATED)')), |
|
258 | 258 | ('', 'no-follow', None, _("don't follow copies and renames")), |
|
259 | 259 | ('a', 'text', None, _('treat all files as text')), |
|
260 | 260 | ('u', 'user', None, _('list the author (long with -v)')), |
|
261 | 261 | ('f', 'file', None, _('list the filename')), |
|
262 | 262 | ('d', 'date', None, _('list the date (short with -q)')), |
|
263 | 263 | ('n', 'number', None, _('list the revision number (default)')), |
|
264 | 264 | ('c', 'changeset', None, _('list the changeset')), |
|
265 | 265 | ('l', 'line-number', None, _('show line number at the first appearance')) |
|
266 | 266 | ] + diffwsopts + walkopts + formatteropts, |
|
267 | 267 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), |
|
268 | 268 | inferrepo=True) |
|
269 | 269 | def annotate(ui, repo, *pats, **opts): |
|
270 | 270 | """show changeset information by line for each file |
|
271 | 271 | |
|
272 | 272 | List changes in files, showing the revision id responsible for |
|
273 | 273 | each line. |
|
274 | 274 | |
|
275 | 275 | This command is useful for discovering when a change was made and |
|
276 | 276 | by whom. |
|
277 | 277 | |
|
278 | 278 | If you include --file, --user, or --date, the revision number is |
|
279 | 279 | suppressed unless you also include --number. |
|
280 | 280 | |
|
281 | 281 | Without the -a/--text option, annotate will avoid processing files |
|
282 | 282 | it detects as binary. With -a, annotate will annotate the file |
|
283 | 283 | anyway, although the results will probably be neither useful |
|
284 | 284 | nor desirable. |
|
285 | 285 | |
|
286 | 286 | Returns 0 on success. |
|
287 | 287 | """ |
|
288 | 288 | opts = pycompat.byteskwargs(opts) |
|
289 | 289 | if not pats: |
|
290 | 290 | raise error.Abort(_('at least one filename or pattern is required')) |
|
291 | 291 | |
|
292 | 292 | if opts.get('follow'): |
|
293 | 293 | # --follow is deprecated and now just an alias for -f/--file |
|
294 | 294 | # to mimic the behavior of Mercurial before version 1.5 |
|
295 | 295 | opts['file'] = True |
|
296 | 296 | |
|
297 | 297 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
298 | 298 | |
|
299 | 299 | fm = ui.formatter('annotate', opts) |
|
300 | 300 | if ui.quiet: |
|
301 | 301 | datefunc = util.shortdate |
|
302 | 302 | else: |
|
303 | 303 | datefunc = util.datestr |
|
304 | 304 | if ctx.rev() is None: |
|
305 | 305 | def hexfn(node): |
|
306 | 306 | if node is None: |
|
307 | 307 | return None |
|
308 | 308 | else: |
|
309 | 309 | return fm.hexfunc(node) |
|
310 | 310 | if opts.get('changeset'): |
|
311 | 311 | # omit "+" suffix which is appended to node hex |
|
312 | 312 | def formatrev(rev): |
|
313 | 313 | if rev is None: |
|
314 | 314 | return '%d' % ctx.p1().rev() |
|
315 | 315 | else: |
|
316 | 316 | return '%d' % rev |
|
317 | 317 | else: |
|
318 | 318 | def formatrev(rev): |
|
319 | 319 | if rev is None: |
|
320 | 320 | return '%d+' % ctx.p1().rev() |
|
321 | 321 | else: |
|
322 | 322 | return '%d ' % rev |
|
323 | 323 | def formathex(hex): |
|
324 | 324 | if hex is None: |
|
325 | 325 | return '%s+' % fm.hexfunc(ctx.p1().node()) |
|
326 | 326 | else: |
|
327 | 327 | return '%s ' % hex |
|
328 | 328 | else: |
|
329 | 329 | hexfn = fm.hexfunc |
|
330 | 330 | formatrev = formathex = str |
|
331 | 331 | |
|
332 | 332 | opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser), |
|
333 | 333 | ('number', ' ', lambda x: x[0].rev(), formatrev), |
|
334 | 334 | ('changeset', ' ', lambda x: hexfn(x[0].node()), formathex), |
|
335 | 335 | ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)), |
|
336 | 336 | ('file', ' ', lambda x: x[0].path(), str), |
|
337 | 337 | ('line_number', ':', lambda x: x[1], str), |
|
338 | 338 | ] |
|
339 | 339 | fieldnamemap = {'number': 'rev', 'changeset': 'node'} |
|
340 | 340 | |
|
341 | 341 | if (not opts.get('user') and not opts.get('changeset') |
|
342 | 342 | and not opts.get('date') and not opts.get('file')): |
|
343 | 343 | opts['number'] = True |
|
344 | 344 | |
|
345 | 345 | linenumber = opts.get('line_number') is not None |
|
346 | 346 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): |
|
347 | 347 | raise error.Abort(_('at least one of -n/-c is required for -l')) |
|
348 | 348 | |
|
349 | 349 | ui.pager('annotate') |
|
350 | 350 | |
|
351 | 351 | if fm.isplain(): |
|
352 | 352 | def makefunc(get, fmt): |
|
353 | 353 | return lambda x: fmt(get(x)) |
|
354 | 354 | else: |
|
355 | 355 | def makefunc(get, fmt): |
|
356 | 356 | return get |
|
357 | 357 | funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap |
|
358 | 358 | if opts.get(op)] |
|
359 | 359 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column |
|
360 | 360 | fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap |
|
361 | 361 | if opts.get(op)) |
|
362 | 362 | |
|
363 | 363 | def bad(x, y): |
|
364 | 364 | raise error.Abort("%s: %s" % (x, y)) |
|
365 | 365 | |
|
366 | 366 | m = scmutil.match(ctx, pats, opts, badfn=bad) |
|
367 | 367 | |
|
368 | 368 | follow = not opts.get('no_follow') |
|
369 | 369 | diffopts = patch.difffeatureopts(ui, opts, section='annotate', |
|
370 | 370 | whitespace=True) |
|
371 | 371 | for abs in ctx.walk(m): |
|
372 | 372 | fctx = ctx[abs] |
|
373 | 373 | if not opts.get('text') and fctx.isbinary(): |
|
374 | 374 | fm.plain(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
|
375 | 375 | continue |
|
376 | 376 | |
|
377 | 377 | lines = fctx.annotate(follow=follow, linenumber=linenumber, |
|
378 | 378 | diffopts=diffopts) |
|
379 | 379 | if not lines: |
|
380 | 380 | continue |
|
381 | 381 | formats = [] |
|
382 | 382 | pieces = [] |
|
383 | 383 | |
|
384 | 384 | for f, sep in funcmap: |
|
385 | 385 | l = [f(n) for n, dummy in lines] |
|
386 | 386 | if fm.isplain(): |
|
387 | 387 | sizes = [encoding.colwidth(x) for x in l] |
|
388 | 388 | ml = max(sizes) |
|
389 | 389 | formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) |
|
390 | 390 | else: |
|
391 | 391 | formats.append(['%s' for x in l]) |
|
392 | 392 | pieces.append(l) |
|
393 | 393 | |
|
394 | 394 | for f, p, l in zip(zip(*formats), zip(*pieces), lines): |
|
395 | 395 | fm.startitem() |
|
396 | 396 | fm.write(fields, "".join(f), *p) |
|
397 | 397 | fm.write('line', ": %s", l[1]) |
|
398 | 398 | |
|
399 | 399 | if not lines[-1][1].endswith('\n'): |
|
400 | 400 | fm.plain('\n') |
|
401 | 401 | |
|
402 | 402 | fm.end() |
|
403 | 403 | |
|
404 | 404 | @command('archive', |
|
405 | 405 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
406 | 406 | ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
407 | 407 | _('PREFIX')), |
|
408 | 408 | ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
409 | 409 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
410 | 410 | ] + subrepoopts + walkopts, |
|
411 | 411 | _('[OPTION]... DEST')) |
|
412 | 412 | def archive(ui, repo, dest, **opts): |
|
413 | 413 | '''create an unversioned archive of a repository revision |
|
414 | 414 | |
|
415 | 415 | By default, the revision used is the parent of the working |
|
416 | 416 | directory; use -r/--rev to specify a different revision. |
|
417 | 417 | |
|
418 | 418 | The archive type is automatically detected based on file |
|
419 | 419 | extension (to override, use -t/--type). |
|
420 | 420 | |
|
421 | 421 | .. container:: verbose |
|
422 | 422 | |
|
423 | 423 | Examples: |
|
424 | 424 | |
|
425 | 425 | - create a zip file containing the 1.0 release:: |
|
426 | 426 | |
|
427 | 427 | hg archive -r 1.0 project-1.0.zip |
|
428 | 428 | |
|
429 | 429 | - create a tarball excluding .hg files:: |
|
430 | 430 | |
|
431 | 431 | hg archive project.tar.gz -X ".hg*" |
|
432 | 432 | |
|
433 | 433 | Valid types are: |
|
434 | 434 | |
|
435 | 435 | :``files``: a directory full of files (default) |
|
436 | 436 | :``tar``: tar archive, uncompressed |
|
437 | 437 | :``tbz2``: tar archive, compressed using bzip2 |
|
438 | 438 | :``tgz``: tar archive, compressed using gzip |
|
439 | 439 | :``uzip``: zip archive, uncompressed |
|
440 | 440 | :``zip``: zip archive, compressed using deflate |
|
441 | 441 | |
|
442 | 442 | The exact name of the destination archive or directory is given |
|
443 | 443 | using a format string; see :hg:`help export` for details. |
|
444 | 444 | |
|
445 | 445 | Each member added to an archive file has a directory prefix |
|
446 | 446 | prepended. Use -p/--prefix to specify a format string for the |
|
447 | 447 | prefix. The default is the basename of the archive, with suffixes |
|
448 | 448 | removed. |
|
449 | 449 | |
|
450 | 450 | Returns 0 on success. |
|
451 | 451 | ''' |
|
452 | 452 | |
|
453 | 453 | opts = pycompat.byteskwargs(opts) |
|
454 | 454 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
455 | 455 | if not ctx: |
|
456 | 456 | raise error.Abort(_('no working directory: please specify a revision')) |
|
457 | 457 | node = ctx.node() |
|
458 | 458 | dest = cmdutil.makefilename(repo, dest, node) |
|
459 | 459 | if os.path.realpath(dest) == repo.root: |
|
460 | 460 | raise error.Abort(_('repository root cannot be destination')) |
|
461 | 461 | |
|
462 | 462 | kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
463 | 463 | prefix = opts.get('prefix') |
|
464 | 464 | |
|
465 | 465 | if dest == '-': |
|
466 | 466 | if kind == 'files': |
|
467 | 467 | raise error.Abort(_('cannot archive plain files to stdout')) |
|
468 | 468 | dest = cmdutil.makefileobj(repo, dest) |
|
469 | 469 | if not prefix: |
|
470 | 470 | prefix = os.path.basename(repo.root) + '-%h' |
|
471 | 471 | |
|
472 | 472 | prefix = cmdutil.makefilename(repo, prefix, node) |
|
473 | 473 | matchfn = scmutil.match(ctx, [], opts) |
|
474 | 474 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
475 | 475 | matchfn, prefix, subrepos=opts.get('subrepos')) |
|
476 | 476 | |
|
477 | 477 | @command('backout', |
|
478 | 478 | [('', 'merge', None, _('merge with old dirstate parent after backout')), |
|
479 | 479 | ('', 'commit', None, |
|
480 | 480 | _('commit if no conflicts were encountered (DEPRECATED)')), |
|
481 | 481 | ('', 'no-commit', None, _('do not commit')), |
|
482 | 482 | ('', 'parent', '', |
|
483 | 483 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), |
|
484 | 484 | ('r', 'rev', '', _('revision to backout'), _('REV')), |
|
485 | 485 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
486 | 486 | ] + mergetoolopts + walkopts + commitopts + commitopts2, |
|
487 | 487 | _('[OPTION]... [-r] REV')) |
|
488 | 488 | def backout(ui, repo, node=None, rev=None, **opts): |
|
489 | 489 | '''reverse effect of earlier changeset |
|
490 | 490 | |
|
491 | 491 | Prepare a new changeset with the effect of REV undone in the |
|
492 | 492 | current working directory. If no conflicts were encountered, |
|
493 | 493 | it will be committed immediately. |
|
494 | 494 | |
|
495 | 495 | If REV is the parent of the working directory, then this new changeset |
|
496 | 496 | is committed automatically (unless --no-commit is specified). |
|
497 | 497 | |
|
498 | 498 | .. note:: |
|
499 | 499 | |
|
500 | 500 | :hg:`backout` cannot be used to fix either an unwanted or |
|
501 | 501 | incorrect merge. |
|
502 | 502 | |
|
503 | 503 | .. container:: verbose |
|
504 | 504 | |
|
505 | 505 | Examples: |
|
506 | 506 | |
|
507 | 507 | - Reverse the effect of the parent of the working directory. |
|
508 | 508 | This backout will be committed immediately:: |
|
509 | 509 | |
|
510 | 510 | hg backout -r . |
|
511 | 511 | |
|
512 | 512 | - Reverse the effect of previous bad revision 23:: |
|
513 | 513 | |
|
514 | 514 | hg backout -r 23 |
|
515 | 515 | |
|
516 | 516 | - Reverse the effect of previous bad revision 23 and |
|
517 | 517 | leave changes uncommitted:: |
|
518 | 518 | |
|
519 | 519 | hg backout -r 23 --no-commit |
|
520 | 520 | hg commit -m "Backout revision 23" |
|
521 | 521 | |
|
522 | 522 | By default, the pending changeset will have one parent, |
|
523 | 523 | maintaining a linear history. With --merge, the pending |
|
524 | 524 | changeset will instead have two parents: the old parent of the |
|
525 | 525 | working directory and a new child of REV that simply undoes REV. |
|
526 | 526 | |
|
527 | 527 | Before version 1.7, the behavior without --merge was equivalent |
|
528 | 528 | to specifying --merge followed by :hg:`update --clean .` to |
|
529 | 529 | cancel the merge and leave the child of REV as a head to be |
|
530 | 530 | merged separately. |
|
531 | 531 | |
|
532 | 532 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
533 | 533 | |
|
534 | 534 | See :hg:`help revert` for a way to restore files to the state |
|
535 | 535 | of another revision. |
|
536 | 536 | |
|
537 | 537 | Returns 0 on success, 1 if nothing to backout or there are unresolved |
|
538 | 538 | files. |
|
539 | 539 | ''' |
|
540 | 540 | wlock = lock = None |
|
541 | 541 | try: |
|
542 | 542 | wlock = repo.wlock() |
|
543 | 543 | lock = repo.lock() |
|
544 | 544 | return _dobackout(ui, repo, node, rev, **opts) |
|
545 | 545 | finally: |
|
546 | 546 | release(lock, wlock) |
|
547 | 547 | |
|
548 | 548 | def _dobackout(ui, repo, node=None, rev=None, **opts): |
|
549 | 549 | opts = pycompat.byteskwargs(opts) |
|
550 | 550 | if opts.get('commit') and opts.get('no_commit'): |
|
551 | 551 | raise error.Abort(_("cannot use --commit with --no-commit")) |
|
552 | 552 | if opts.get('merge') and opts.get('no_commit'): |
|
553 | 553 | raise error.Abort(_("cannot use --merge with --no-commit")) |
|
554 | 554 | |
|
555 | 555 | if rev and node: |
|
556 | 556 | raise error.Abort(_("please specify just one revision")) |
|
557 | 557 | |
|
558 | 558 | if not rev: |
|
559 | 559 | rev = node |
|
560 | 560 | |
|
561 | 561 | if not rev: |
|
562 | 562 | raise error.Abort(_("please specify a revision to backout")) |
|
563 | 563 | |
|
564 | 564 | date = opts.get('date') |
|
565 | 565 | if date: |
|
566 | 566 | opts['date'] = util.parsedate(date) |
|
567 | 567 | |
|
568 | 568 | cmdutil.checkunfinished(repo) |
|
569 | 569 | cmdutil.bailifchanged(repo) |
|
570 | 570 | node = scmutil.revsingle(repo, rev).node() |
|
571 | 571 | |
|
572 | 572 | op1, op2 = repo.dirstate.parents() |
|
573 | 573 | if not repo.changelog.isancestor(node, op1): |
|
574 | 574 | raise error.Abort(_('cannot backout change that is not an ancestor')) |
|
575 | 575 | |
|
576 | 576 | p1, p2 = repo.changelog.parents(node) |
|
577 | 577 | if p1 == nullid: |
|
578 | 578 | raise error.Abort(_('cannot backout a change with no parents')) |
|
579 | 579 | if p2 != nullid: |
|
580 | 580 | if not opts.get('parent'): |
|
581 | 581 | raise error.Abort(_('cannot backout a merge changeset')) |
|
582 | 582 | p = repo.lookup(opts['parent']) |
|
583 | 583 | if p not in (p1, p2): |
|
584 | 584 | raise error.Abort(_('%s is not a parent of %s') % |
|
585 | 585 | (short(p), short(node))) |
|
586 | 586 | parent = p |
|
587 | 587 | else: |
|
588 | 588 | if opts.get('parent'): |
|
589 | 589 | raise error.Abort(_('cannot use --parent on non-merge changeset')) |
|
590 | 590 | parent = p1 |
|
591 | 591 | |
|
592 | 592 | # the backout should appear on the same branch |
|
593 | 593 | branch = repo.dirstate.branch() |
|
594 | 594 | bheads = repo.branchheads(branch) |
|
595 | 595 | rctx = scmutil.revsingle(repo, hex(parent)) |
|
596 | 596 | if not opts.get('merge') and op1 != node: |
|
597 | 597 | dsguard = dirstateguard.dirstateguard(repo, 'backout') |
|
598 | 598 | try: |
|
599 | 599 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
600 | 600 | 'backout') |
|
601 | 601 | stats = mergemod.update(repo, parent, True, True, node, False) |
|
602 | 602 | repo.setparents(op1, op2) |
|
603 | 603 | dsguard.close() |
|
604 | 604 | hg._showstats(repo, stats) |
|
605 | 605 | if stats[3]: |
|
606 | 606 | repo.ui.status(_("use 'hg resolve' to retry unresolved " |
|
607 | 607 | "file merges\n")) |
|
608 | 608 | return 1 |
|
609 | 609 | finally: |
|
610 | 610 | ui.setconfig('ui', 'forcemerge', '', '') |
|
611 | 611 | lockmod.release(dsguard) |
|
612 | 612 | else: |
|
613 | 613 | hg.clean(repo, node, show_stats=False) |
|
614 | 614 | repo.dirstate.setbranch(branch) |
|
615 | 615 | cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) |
|
616 | 616 | |
|
617 | 617 | if opts.get('no_commit'): |
|
618 | 618 | msg = _("changeset %s backed out, " |
|
619 | 619 | "don't forget to commit.\n") |
|
620 | 620 | ui.status(msg % short(node)) |
|
621 | 621 | return 0 |
|
622 | 622 | |
|
623 | 623 | def commitfunc(ui, repo, message, match, opts): |
|
624 | 624 | editform = 'backout' |
|
625 | 625 | e = cmdutil.getcommiteditor(editform=editform, |
|
626 | 626 | **pycompat.strkwargs(opts)) |
|
627 | 627 | if not message: |
|
628 | 628 | # we don't translate commit messages |
|
629 | 629 | message = "Backed out changeset %s" % short(node) |
|
630 | 630 | e = cmdutil.getcommiteditor(edit=True, editform=editform) |
|
631 | 631 | return repo.commit(message, opts.get('user'), opts.get('date'), |
|
632 | 632 | match, editor=e) |
|
633 | 633 | newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) |
|
634 | 634 | if not newnode: |
|
635 | 635 | ui.status(_("nothing changed\n")) |
|
636 | 636 | return 1 |
|
637 | 637 | cmdutil.commitstatus(repo, newnode, branch, bheads) |
|
638 | 638 | |
|
639 | 639 | def nice(node): |
|
640 | 640 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
641 | 641 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
642 | 642 | (nice(repo.changelog.tip()), nice(node))) |
|
643 | 643 | if opts.get('merge') and op1 != node: |
|
644 | 644 | hg.clean(repo, op1, show_stats=False) |
|
645 | 645 | ui.status(_('merging with changeset %s\n') |
|
646 | 646 | % nice(repo.changelog.tip())) |
|
647 | 647 | try: |
|
648 | 648 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
649 | 649 | 'backout') |
|
650 | 650 | return hg.merge(repo, hex(repo.changelog.tip())) |
|
651 | 651 | finally: |
|
652 | 652 | ui.setconfig('ui', 'forcemerge', '', '') |
|
653 | 653 | return 0 |
|
654 | 654 | |
|
655 | 655 | @command('bisect', |
|
656 | 656 | [('r', 'reset', False, _('reset bisect state')), |
|
657 | 657 | ('g', 'good', False, _('mark changeset good')), |
|
658 | 658 | ('b', 'bad', False, _('mark changeset bad')), |
|
659 | 659 | ('s', 'skip', False, _('skip testing changeset')), |
|
660 | 660 | ('e', 'extend', False, _('extend the bisect range')), |
|
661 | 661 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), |
|
662 | 662 | ('U', 'noupdate', False, _('do not update to target'))], |
|
663 | 663 | _("[-gbsr] [-U] [-c CMD] [REV]")) |
|
664 | 664 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
665 | 665 | reset=None, good=None, bad=None, skip=None, extend=None, |
|
666 | 666 | noupdate=None): |
|
667 | 667 | """subdivision search of changesets |
|
668 | 668 | |
|
669 | 669 | This command helps to find changesets which introduce problems. To |
|
670 | 670 | use, mark the earliest changeset you know exhibits the problem as |
|
671 | 671 | bad, then mark the latest changeset which is free from the problem |
|
672 | 672 | as good. Bisect will update your working directory to a revision |
|
673 | 673 | for testing (unless the -U/--noupdate option is specified). Once |
|
674 | 674 | you have performed tests, mark the working directory as good or |
|
675 | 675 | bad, and bisect will either update to another candidate changeset |
|
676 | 676 | or announce that it has found the bad revision. |
|
677 | 677 | |
|
678 | 678 | As a shortcut, you can also use the revision argument to mark a |
|
679 | 679 | revision as good or bad without checking it out first. |
|
680 | 680 | |
|
681 | 681 | If you supply a command, it will be used for automatic bisection. |
|
682 | 682 | The environment variable HG_NODE will contain the ID of the |
|
683 | 683 | changeset being tested. The exit status of the command will be |
|
684 | 684 | used to mark revisions as good or bad: status 0 means good, 125 |
|
685 | 685 | means to skip the revision, 127 (command not found) will abort the |
|
686 | 686 | bisection, and any other non-zero exit status means the revision |
|
687 | 687 | is bad. |
|
688 | 688 | |
|
689 | 689 | .. container:: verbose |
|
690 | 690 | |
|
691 | 691 | Some examples: |
|
692 | 692 | |
|
693 | 693 | - start a bisection with known bad revision 34, and good revision 12:: |
|
694 | 694 | |
|
695 | 695 | hg bisect --bad 34 |
|
696 | 696 | hg bisect --good 12 |
|
697 | 697 | |
|
698 | 698 | - advance the current bisection by marking current revision as good or |
|
699 | 699 | bad:: |
|
700 | 700 | |
|
701 | 701 | hg bisect --good |
|
702 | 702 | hg bisect --bad |
|
703 | 703 | |
|
704 | 704 | - mark the current revision, or a known revision, to be skipped (e.g. if |
|
705 | 705 | that revision is not usable because of another issue):: |
|
706 | 706 | |
|
707 | 707 | hg bisect --skip |
|
708 | 708 | hg bisect --skip 23 |
|
709 | 709 | |
|
710 | 710 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: |
|
711 | 711 | |
|
712 | 712 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" |
|
713 | 713 | |
|
714 | 714 | - forget the current bisection:: |
|
715 | 715 | |
|
716 | 716 | hg bisect --reset |
|
717 | 717 | |
|
718 | 718 | - use 'make && make tests' to automatically find the first broken |
|
719 | 719 | revision:: |
|
720 | 720 | |
|
721 | 721 | hg bisect --reset |
|
722 | 722 | hg bisect --bad 34 |
|
723 | 723 | hg bisect --good 12 |
|
724 | 724 | hg bisect --command "make && make tests" |
|
725 | 725 | |
|
726 | 726 | - see all changesets whose states are already known in the current |
|
727 | 727 | bisection:: |
|
728 | 728 | |
|
729 | 729 | hg log -r "bisect(pruned)" |
|
730 | 730 | |
|
731 | 731 | - see the changeset currently being bisected (especially useful |
|
732 | 732 | if running with -U/--noupdate):: |
|
733 | 733 | |
|
734 | 734 | hg log -r "bisect(current)" |
|
735 | 735 | |
|
736 | 736 | - see all changesets that took part in the current bisection:: |
|
737 | 737 | |
|
738 | 738 | hg log -r "bisect(range)" |
|
739 | 739 | |
|
740 | 740 | - you can even get a nice graph:: |
|
741 | 741 | |
|
742 | 742 | hg log --graph -r "bisect(range)" |
|
743 | 743 | |
|
744 | 744 | See :hg:`help revisions.bisect` for more about the `bisect()` predicate. |
|
745 | 745 | |
|
746 | 746 | Returns 0 on success. |
|
747 | 747 | """ |
|
748 | 748 | # backward compatibility |
|
749 | 749 | if rev in "good bad reset init".split(): |
|
750 | 750 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
751 | 751 | cmd, rev, extra = rev, extra, None |
|
752 | 752 | if cmd == "good": |
|
753 | 753 | good = True |
|
754 | 754 | elif cmd == "bad": |
|
755 | 755 | bad = True |
|
756 | 756 | else: |
|
757 | 757 | reset = True |
|
758 | 758 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: |
|
759 | 759 | raise error.Abort(_('incompatible arguments')) |
|
760 | 760 | |
|
761 | 761 | if reset: |
|
762 | 762 | hbisect.resetstate(repo) |
|
763 | 763 | return |
|
764 | 764 | |
|
765 | 765 | state = hbisect.load_state(repo) |
|
766 | 766 | |
|
767 | 767 | # update state |
|
768 | 768 | if good or bad or skip: |
|
769 | 769 | if rev: |
|
770 | 770 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] |
|
771 | 771 | else: |
|
772 | 772 | nodes = [repo.lookup('.')] |
|
773 | 773 | if good: |
|
774 | 774 | state['good'] += nodes |
|
775 | 775 | elif bad: |
|
776 | 776 | state['bad'] += nodes |
|
777 | 777 | elif skip: |
|
778 | 778 | state['skip'] += nodes |
|
779 | 779 | hbisect.save_state(repo, state) |
|
780 | 780 | if not (state['good'] and state['bad']): |
|
781 | 781 | return |
|
782 | 782 | |
|
783 | 783 | def mayupdate(repo, node, show_stats=True): |
|
784 | 784 | """common used update sequence""" |
|
785 | 785 | if noupdate: |
|
786 | 786 | return |
|
787 | 787 | cmdutil.checkunfinished(repo) |
|
788 | 788 | cmdutil.bailifchanged(repo) |
|
789 | 789 | return hg.clean(repo, node, show_stats=show_stats) |
|
790 | 790 | |
|
791 | 791 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
792 | 792 | |
|
793 | 793 | if command: |
|
794 | 794 | changesets = 1 |
|
795 | 795 | if noupdate: |
|
796 | 796 | try: |
|
797 | 797 | node = state['current'][0] |
|
798 | 798 | except LookupError: |
|
799 | 799 | raise error.Abort(_('current bisect revision is unknown - ' |
|
800 | 800 | 'start a new bisect to fix')) |
|
801 | 801 | else: |
|
802 | 802 | node, p2 = repo.dirstate.parents() |
|
803 | 803 | if p2 != nullid: |
|
804 | 804 | raise error.Abort(_('current bisect revision is a merge')) |
|
805 | 805 | if rev: |
|
806 | 806 | node = repo[scmutil.revsingle(repo, rev, node)].node() |
|
807 | 807 | try: |
|
808 | 808 | while changesets: |
|
809 | 809 | # update state |
|
810 | 810 | state['current'] = [node] |
|
811 | 811 | hbisect.save_state(repo, state) |
|
812 | 812 | status = ui.system(command, environ={'HG_NODE': hex(node)}, |
|
813 | 813 | blockedtag='bisect_check') |
|
814 | 814 | if status == 125: |
|
815 | 815 | transition = "skip" |
|
816 | 816 | elif status == 0: |
|
817 | 817 | transition = "good" |
|
818 | 818 | # status < 0 means process was killed |
|
819 | 819 | elif status == 127: |
|
820 | 820 | raise error.Abort(_("failed to execute %s") % command) |
|
821 | 821 | elif status < 0: |
|
822 | 822 | raise error.Abort(_("%s killed") % command) |
|
823 | 823 | else: |
|
824 | 824 | transition = "bad" |
|
825 | 825 | state[transition].append(node) |
|
826 | 826 | ctx = repo[node] |
|
827 | 827 | ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
828 | 828 | hbisect.checkstate(state) |
|
829 | 829 | # bisect |
|
830 | 830 | nodes, changesets, bgood = hbisect.bisect(repo.changelog, state) |
|
831 | 831 | # update to next check |
|
832 | 832 | node = nodes[0] |
|
833 | 833 | mayupdate(repo, node, show_stats=False) |
|
834 | 834 | finally: |
|
835 | 835 | state['current'] = [node] |
|
836 | 836 | hbisect.save_state(repo, state) |
|
837 | 837 | hbisect.printresult(ui, repo, state, displayer, nodes, bgood) |
|
838 | 838 | return |
|
839 | 839 | |
|
840 | 840 | hbisect.checkstate(state) |
|
841 | 841 | |
|
842 | 842 | # actually bisect |
|
843 | 843 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
844 | 844 | if extend: |
|
845 | 845 | if not changesets: |
|
846 | 846 | extendnode = hbisect.extendrange(repo, state, nodes, good) |
|
847 | 847 | if extendnode is not None: |
|
848 | 848 | ui.write(_("Extending search to changeset %d:%s\n") |
|
849 | 849 | % (extendnode.rev(), extendnode)) |
|
850 | 850 | state['current'] = [extendnode.node()] |
|
851 | 851 | hbisect.save_state(repo, state) |
|
852 | 852 | return mayupdate(repo, extendnode.node()) |
|
853 | 853 | raise error.Abort(_("nothing to extend")) |
|
854 | 854 | |
|
855 | 855 | if changesets == 0: |
|
856 | 856 | hbisect.printresult(ui, repo, state, displayer, nodes, good) |
|
857 | 857 | else: |
|
858 | 858 | assert len(nodes) == 1 # only a single node can be tested next |
|
859 | 859 | node = nodes[0] |
|
860 | 860 | # compute the approximate number of remaining tests |
|
861 | 861 | tests, size = 0, 2 |
|
862 | 862 | while size <= changesets: |
|
863 | 863 | tests, size = tests + 1, size * 2 |
|
864 | 864 | rev = repo.changelog.rev(node) |
|
865 | 865 | ui.write(_("Testing changeset %d:%s " |
|
866 | 866 | "(%d changesets remaining, ~%d tests)\n") |
|
867 | 867 | % (rev, short(node), changesets, tests)) |
|
868 | 868 | state['current'] = [node] |
|
869 | 869 | hbisect.save_state(repo, state) |
|
870 | 870 | return mayupdate(repo, node) |
|
871 | 871 | |
|
872 | 872 | @command('bookmarks|bookmark', |
|
873 | 873 | [('f', 'force', False, _('force')), |
|
874 | 874 | ('r', 'rev', '', _('revision for bookmark action'), _('REV')), |
|
875 | 875 | ('d', 'delete', False, _('delete a given bookmark')), |
|
876 | 876 | ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), |
|
877 | 877 | ('i', 'inactive', False, _('mark a bookmark inactive')), |
|
878 | 878 | ] + formatteropts, |
|
879 | 879 | _('hg bookmarks [OPTIONS]... [NAME]...')) |
|
880 | 880 | def bookmark(ui, repo, *names, **opts): |
|
881 | 881 | '''create a new bookmark or list existing bookmarks |
|
882 | 882 | |
|
883 | 883 | Bookmarks are labels on changesets to help track lines of development. |
|
884 | 884 | Bookmarks are unversioned and can be moved, renamed and deleted. |
|
885 | 885 | Deleting or moving a bookmark has no effect on the associated changesets. |
|
886 | 886 | |
|
887 | 887 | Creating or updating to a bookmark causes it to be marked as 'active'. |
|
888 | 888 | The active bookmark is indicated with a '*'. |
|
889 | 889 | When a commit is made, the active bookmark will advance to the new commit. |
|
890 | 890 | A plain :hg:`update` will also advance an active bookmark, if possible. |
|
891 | 891 | Updating away from a bookmark will cause it to be deactivated. |
|
892 | 892 | |
|
893 | 893 | Bookmarks can be pushed and pulled between repositories (see |
|
894 | 894 | :hg:`help push` and :hg:`help pull`). If a shared bookmark has |
|
895 | 895 | diverged, a new 'divergent bookmark' of the form 'name@path' will |
|
896 | 896 | be created. Using :hg:`merge` will resolve the divergence. |
|
897 | 897 | |
|
898 | 898 | A bookmark named '@' has the special property that :hg:`clone` will |
|
899 | 899 | check it out by default if it exists. |
|
900 | 900 | |
|
901 | 901 | .. container:: verbose |
|
902 | 902 | |
|
903 | 903 | Examples: |
|
904 | 904 | |
|
905 | 905 | - create an active bookmark for a new line of development:: |
|
906 | 906 | |
|
907 | 907 | hg book new-feature |
|
908 | 908 | |
|
909 | 909 | - create an inactive bookmark as a place marker:: |
|
910 | 910 | |
|
911 | 911 | hg book -i reviewed |
|
912 | 912 | |
|
913 | 913 | - create an inactive bookmark on another changeset:: |
|
914 | 914 | |
|
915 | 915 | hg book -r .^ tested |
|
916 | 916 | |
|
917 | 917 | - rename bookmark turkey to dinner:: |
|
918 | 918 | |
|
919 | 919 | hg book -m turkey dinner |
|
920 | 920 | |
|
921 | 921 | - move the '@' bookmark from another branch:: |
|
922 | 922 | |
|
923 | 923 | hg book -f @ |
|
924 | 924 | ''' |
|
925 | 925 | opts = pycompat.byteskwargs(opts) |
|
926 | 926 | force = opts.get('force') |
|
927 | 927 | rev = opts.get('rev') |
|
928 | 928 | delete = opts.get('delete') |
|
929 | 929 | rename = opts.get('rename') |
|
930 | 930 | inactive = opts.get('inactive') |
|
931 | 931 | |
|
932 | 932 | def checkformat(mark): |
|
933 | 933 | mark = mark.strip() |
|
934 | 934 | if not mark: |
|
935 | 935 | raise error.Abort(_("bookmark names cannot consist entirely of " |
|
936 | 936 | "whitespace")) |
|
937 | 937 | scmutil.checknewlabel(repo, mark, 'bookmark') |
|
938 | 938 | return mark |
|
939 | 939 | |
|
940 | 940 | def checkconflict(repo, mark, cur, force=False, target=None): |
|
941 | 941 | if mark in marks and not force: |
|
942 | 942 | if target: |
|
943 | 943 | if marks[mark] == target and target == cur: |
|
944 | 944 | # re-activating a bookmark |
|
945 | 945 | return |
|
946 | 946 | anc = repo.changelog.ancestors([repo[target].rev()]) |
|
947 | 947 | bmctx = repo[marks[mark]] |
|
948 | 948 | divs = [repo[b].node() for b in marks |
|
949 | 949 | if b.split('@', 1)[0] == mark.split('@', 1)[0]] |
|
950 | 950 | |
|
951 | 951 | # allow resolving a single divergent bookmark even if moving |
|
952 | 952 | # the bookmark across branches when a revision is specified |
|
953 | 953 | # that contains a divergent bookmark |
|
954 | 954 | if bmctx.rev() not in anc and target in divs: |
|
955 | 955 | bookmarks.deletedivergent(repo, [target], mark) |
|
956 | 956 | return |
|
957 | 957 | |
|
958 | 958 | deletefrom = [b for b in divs |
|
959 | 959 | if repo[b].rev() in anc or b == target] |
|
960 | 960 | bookmarks.deletedivergent(repo, deletefrom, mark) |
|
961 | 961 | if bookmarks.validdest(repo, bmctx, repo[target]): |
|
962 | 962 | ui.status(_("moving bookmark '%s' forward from %s\n") % |
|
963 | 963 | (mark, short(bmctx.node()))) |
|
964 | 964 | return |
|
965 | 965 | raise error.Abort(_("bookmark '%s' already exists " |
|
966 | 966 | "(use -f to force)") % mark) |
|
967 | 967 | if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) |
|
968 | 968 | and not force): |
|
969 | 969 | raise error.Abort( |
|
970 | 970 | _("a bookmark cannot have the name of an existing branch")) |
|
971 |
if len(mark) > 3 and |
|
|
971 | if len(mark) > 3 and not force: | |
|
972 | try: | |
|
973 | shadowhash = (mark in repo) | |
|
974 | except error.LookupError: # ambiguous identifier | |
|
975 | shadowhash = False | |
|
976 | if shadowhash: | |
|
972 | 977 | repo.ui.warn( |
|
973 | 978 | _("bookmark %s matches a changeset hash\n" |
|
974 |
"(did you leave a -r out of an 'hg bookmark' command?)\n") |
|
|
975 | mark) | |
|
979 | "(did you leave a -r out of an 'hg bookmark' command?)\n") | |
|
980 | % mark) | |
|
976 | 981 | |
|
977 | 982 | if delete and rename: |
|
978 | 983 | raise error.Abort(_("--delete and --rename are incompatible")) |
|
979 | 984 | if delete and rev: |
|
980 | 985 | raise error.Abort(_("--rev is incompatible with --delete")) |
|
981 | 986 | if rename and rev: |
|
982 | 987 | raise error.Abort(_("--rev is incompatible with --rename")) |
|
983 | 988 | if not names and (delete or rev): |
|
984 | 989 | raise error.Abort(_("bookmark name required")) |
|
985 | 990 | |
|
986 | 991 | if delete or rename or names or inactive: |
|
987 | 992 | wlock = lock = tr = None |
|
988 | 993 | try: |
|
989 | 994 | wlock = repo.wlock() |
|
990 | 995 | lock = repo.lock() |
|
991 | 996 | cur = repo.changectx('.').node() |
|
992 | 997 | marks = repo._bookmarks |
|
993 | 998 | if delete: |
|
994 | 999 | tr = repo.transaction('bookmark') |
|
995 | 1000 | for mark in names: |
|
996 | 1001 | if mark not in marks: |
|
997 | 1002 | raise error.Abort(_("bookmark '%s' does not exist") % |
|
998 | 1003 | mark) |
|
999 | 1004 | if mark == repo._activebookmark: |
|
1000 | 1005 | bookmarks.deactivate(repo) |
|
1001 | 1006 | del marks[mark] |
|
1002 | 1007 | |
|
1003 | 1008 | elif rename: |
|
1004 | 1009 | tr = repo.transaction('bookmark') |
|
1005 | 1010 | if not names: |
|
1006 | 1011 | raise error.Abort(_("new bookmark name required")) |
|
1007 | 1012 | elif len(names) > 1: |
|
1008 | 1013 | raise error.Abort(_("only one new bookmark name allowed")) |
|
1009 | 1014 | mark = checkformat(names[0]) |
|
1010 | 1015 | if rename not in marks: |
|
1011 | 1016 | raise error.Abort(_("bookmark '%s' does not exist") |
|
1012 | 1017 | % rename) |
|
1013 | 1018 | checkconflict(repo, mark, cur, force) |
|
1014 | 1019 | marks[mark] = marks[rename] |
|
1015 | 1020 | if repo._activebookmark == rename and not inactive: |
|
1016 | 1021 | bookmarks.activate(repo, mark) |
|
1017 | 1022 | del marks[rename] |
|
1018 | 1023 | elif names: |
|
1019 | 1024 | tr = repo.transaction('bookmark') |
|
1020 | 1025 | newact = None |
|
1021 | 1026 | for mark in names: |
|
1022 | 1027 | mark = checkformat(mark) |
|
1023 | 1028 | if newact is None: |
|
1024 | 1029 | newact = mark |
|
1025 | 1030 | if inactive and mark == repo._activebookmark: |
|
1026 | 1031 | bookmarks.deactivate(repo) |
|
1027 | 1032 | return |
|
1028 | 1033 | tgt = cur |
|
1029 | 1034 | if rev: |
|
1030 | 1035 | tgt = scmutil.revsingle(repo, rev).node() |
|
1031 | 1036 | checkconflict(repo, mark, cur, force, tgt) |
|
1032 | 1037 | marks[mark] = tgt |
|
1033 | 1038 | if not inactive and cur == marks[newact] and not rev: |
|
1034 | 1039 | bookmarks.activate(repo, newact) |
|
1035 | 1040 | elif cur != tgt and newact == repo._activebookmark: |
|
1036 | 1041 | bookmarks.deactivate(repo) |
|
1037 | 1042 | elif inactive: |
|
1038 | 1043 | if len(marks) == 0: |
|
1039 | 1044 | ui.status(_("no bookmarks set\n")) |
|
1040 | 1045 | elif not repo._activebookmark: |
|
1041 | 1046 | ui.status(_("no active bookmark\n")) |
|
1042 | 1047 | else: |
|
1043 | 1048 | bookmarks.deactivate(repo) |
|
1044 | 1049 | if tr is not None: |
|
1045 | 1050 | marks.recordchange(tr) |
|
1046 | 1051 | tr.close() |
|
1047 | 1052 | finally: |
|
1048 | 1053 | lockmod.release(tr, lock, wlock) |
|
1049 | 1054 | else: # show bookmarks |
|
1050 | 1055 | fm = ui.formatter('bookmarks', opts) |
|
1051 | 1056 | hexfn = fm.hexfunc |
|
1052 | 1057 | marks = repo._bookmarks |
|
1053 | 1058 | if len(marks) == 0 and fm.isplain(): |
|
1054 | 1059 | ui.status(_("no bookmarks set\n")) |
|
1055 | 1060 | for bmark, n in sorted(marks.iteritems()): |
|
1056 | 1061 | active = repo._activebookmark |
|
1057 | 1062 | if bmark == active: |
|
1058 | 1063 | prefix, label = '*', activebookmarklabel |
|
1059 | 1064 | else: |
|
1060 | 1065 | prefix, label = ' ', '' |
|
1061 | 1066 | |
|
1062 | 1067 | fm.startitem() |
|
1063 | 1068 | if not ui.quiet: |
|
1064 | 1069 | fm.plain(' %s ' % prefix, label=label) |
|
1065 | 1070 | fm.write('bookmark', '%s', bmark, label=label) |
|
1066 | 1071 | pad = " " * (25 - encoding.colwidth(bmark)) |
|
1067 | 1072 | fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s', |
|
1068 | 1073 | repo.changelog.rev(n), hexfn(n), label=label) |
|
1069 | 1074 | fm.data(active=(bmark == active)) |
|
1070 | 1075 | fm.plain('\n') |
|
1071 | 1076 | fm.end() |
|
1072 | 1077 | |
|
1073 | 1078 | @command('branch', |
|
1074 | 1079 | [('f', 'force', None, |
|
1075 | 1080 | _('set branch name even if it shadows an existing branch')), |
|
1076 | 1081 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
1077 | 1082 | _('[-fC] [NAME]')) |
|
1078 | 1083 | def branch(ui, repo, label=None, **opts): |
|
1079 | 1084 | """set or show the current branch name |
|
1080 | 1085 | |
|
1081 | 1086 | .. note:: |
|
1082 | 1087 | |
|
1083 | 1088 | Branch names are permanent and global. Use :hg:`bookmark` to create a |
|
1084 | 1089 | light-weight bookmark instead. See :hg:`help glossary` for more |
|
1085 | 1090 | information about named branches and bookmarks. |
|
1086 | 1091 | |
|
1087 | 1092 | With no argument, show the current branch name. With one argument, |
|
1088 | 1093 | set the working directory branch name (the branch will not exist |
|
1089 | 1094 | in the repository until the next commit). Standard practice |
|
1090 | 1095 | recommends that primary development take place on the 'default' |
|
1091 | 1096 | branch. |
|
1092 | 1097 | |
|
1093 | 1098 | Unless -f/--force is specified, branch will not let you set a |
|
1094 | 1099 | branch name that already exists. |
|
1095 | 1100 | |
|
1096 | 1101 | Use -C/--clean to reset the working directory branch to that of |
|
1097 | 1102 | the parent of the working directory, negating a previous branch |
|
1098 | 1103 | change. |
|
1099 | 1104 | |
|
1100 | 1105 | Use the command :hg:`update` to switch to an existing branch. Use |
|
1101 | 1106 | :hg:`commit --close-branch` to mark this branch head as closed. |
|
1102 | 1107 | When all heads of a branch are closed, the branch will be |
|
1103 | 1108 | considered closed. |
|
1104 | 1109 | |
|
1105 | 1110 | Returns 0 on success. |
|
1106 | 1111 | """ |
|
1107 | 1112 | opts = pycompat.byteskwargs(opts) |
|
1108 | 1113 | if label: |
|
1109 | 1114 | label = label.strip() |
|
1110 | 1115 | |
|
1111 | 1116 | if not opts.get('clean') and not label: |
|
1112 | 1117 | ui.write("%s\n" % repo.dirstate.branch()) |
|
1113 | 1118 | return |
|
1114 | 1119 | |
|
1115 | 1120 | with repo.wlock(): |
|
1116 | 1121 | if opts.get('clean'): |
|
1117 | 1122 | label = repo[None].p1().branch() |
|
1118 | 1123 | repo.dirstate.setbranch(label) |
|
1119 | 1124 | ui.status(_('reset working directory to branch %s\n') % label) |
|
1120 | 1125 | elif label: |
|
1121 | 1126 | if not opts.get('force') and label in repo.branchmap(): |
|
1122 | 1127 | if label not in [p.branch() for p in repo[None].parents()]: |
|
1123 | 1128 | raise error.Abort(_('a branch of the same name already' |
|
1124 | 1129 | ' exists'), |
|
1125 | 1130 | # i18n: "it" refers to an existing branch |
|
1126 | 1131 | hint=_("use 'hg update' to switch to it")) |
|
1127 | 1132 | scmutil.checknewlabel(repo, label, 'branch') |
|
1128 | 1133 | repo.dirstate.setbranch(label) |
|
1129 | 1134 | ui.status(_('marked working directory as branch %s\n') % label) |
|
1130 | 1135 | |
|
1131 | 1136 | # find any open named branches aside from default |
|
1132 | 1137 | others = [n for n, h, t, c in repo.branchmap().iterbranches() |
|
1133 | 1138 | if n != "default" and not c] |
|
1134 | 1139 | if not others: |
|
1135 | 1140 | ui.status(_('(branches are permanent and global, ' |
|
1136 | 1141 | 'did you want a bookmark?)\n')) |
|
1137 | 1142 | |
|
1138 | 1143 | @command('branches', |
|
1139 | 1144 | [('a', 'active', False, |
|
1140 | 1145 | _('show only branches that have unmerged heads (DEPRECATED)')), |
|
1141 | 1146 | ('c', 'closed', False, _('show normal and closed branches')), |
|
1142 | 1147 | ] + formatteropts, |
|
1143 | 1148 | _('[-c]')) |
|
1144 | 1149 | def branches(ui, repo, active=False, closed=False, **opts): |
|
1145 | 1150 | """list repository named branches |
|
1146 | 1151 | |
|
1147 | 1152 | List the repository's named branches, indicating which ones are |
|
1148 | 1153 | inactive. If -c/--closed is specified, also list branches which have |
|
1149 | 1154 | been marked closed (see :hg:`commit --close-branch`). |
|
1150 | 1155 | |
|
1151 | 1156 | Use the command :hg:`update` to switch to an existing branch. |
|
1152 | 1157 | |
|
1153 | 1158 | Returns 0. |
|
1154 | 1159 | """ |
|
1155 | 1160 | |
|
1156 | 1161 | opts = pycompat.byteskwargs(opts) |
|
1157 | 1162 | ui.pager('branches') |
|
1158 | 1163 | fm = ui.formatter('branches', opts) |
|
1159 | 1164 | hexfunc = fm.hexfunc |
|
1160 | 1165 | |
|
1161 | 1166 | allheads = set(repo.heads()) |
|
1162 | 1167 | branches = [] |
|
1163 | 1168 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): |
|
1164 | 1169 | isactive = not isclosed and bool(set(heads) & allheads) |
|
1165 | 1170 | branches.append((tag, repo[tip], isactive, not isclosed)) |
|
1166 | 1171 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), |
|
1167 | 1172 | reverse=True) |
|
1168 | 1173 | |
|
1169 | 1174 | for tag, ctx, isactive, isopen in branches: |
|
1170 | 1175 | if active and not isactive: |
|
1171 | 1176 | continue |
|
1172 | 1177 | if isactive: |
|
1173 | 1178 | label = 'branches.active' |
|
1174 | 1179 | notice = '' |
|
1175 | 1180 | elif not isopen: |
|
1176 | 1181 | if not closed: |
|
1177 | 1182 | continue |
|
1178 | 1183 | label = 'branches.closed' |
|
1179 | 1184 | notice = _(' (closed)') |
|
1180 | 1185 | else: |
|
1181 | 1186 | label = 'branches.inactive' |
|
1182 | 1187 | notice = _(' (inactive)') |
|
1183 | 1188 | current = (tag == repo.dirstate.branch()) |
|
1184 | 1189 | if current: |
|
1185 | 1190 | label = 'branches.current' |
|
1186 | 1191 | |
|
1187 | 1192 | fm.startitem() |
|
1188 | 1193 | fm.write('branch', '%s', tag, label=label) |
|
1189 | 1194 | rev = ctx.rev() |
|
1190 | 1195 | padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0) |
|
1191 | 1196 | fmt = ' ' * padsize + ' %d:%s' |
|
1192 | 1197 | fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()), |
|
1193 | 1198 | label='log.changeset changeset.%s' % ctx.phasestr()) |
|
1194 | 1199 | fm.context(ctx=ctx) |
|
1195 | 1200 | fm.data(active=isactive, closed=not isopen, current=current) |
|
1196 | 1201 | if not ui.quiet: |
|
1197 | 1202 | fm.plain(notice) |
|
1198 | 1203 | fm.plain('\n') |
|
1199 | 1204 | fm.end() |
|
1200 | 1205 | |
|
1201 | 1206 | @command('bundle', |
|
1202 | 1207 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
1203 | 1208 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), |
|
1204 | 1209 | _('REV')), |
|
1205 | 1210 | ('b', 'branch', [], _('a specific branch you would like to bundle'), |
|
1206 | 1211 | _('BRANCH')), |
|
1207 | 1212 | ('', 'base', [], |
|
1208 | 1213 | _('a base changeset assumed to be available at the destination'), |
|
1209 | 1214 | _('REV')), |
|
1210 | 1215 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
1211 | 1216 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), |
|
1212 | 1217 | ] + remoteopts, |
|
1213 | 1218 | _('[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]')) |
|
1214 | 1219 | def bundle(ui, repo, fname, dest=None, **opts): |
|
1215 | 1220 | """create a bundle file |
|
1216 | 1221 | |
|
1217 | 1222 | Generate a bundle file containing data to be added to a repository. |
|
1218 | 1223 | |
|
1219 | 1224 | To create a bundle containing all changesets, use -a/--all |
|
1220 | 1225 | (or --base null). Otherwise, hg assumes the destination will have |
|
1221 | 1226 | all the nodes you specify with --base parameters. Otherwise, hg |
|
1222 | 1227 | will assume the repository has all the nodes in destination, or |
|
1223 | 1228 | default-push/default if no destination is specified. |
|
1224 | 1229 | |
|
1225 | 1230 | You can change bundle format with the -t/--type option. See |
|
1226 | 1231 | :hg:`help bundlespec` for documentation on this format. By default, |
|
1227 | 1232 | the most appropriate format is used and compression defaults to |
|
1228 | 1233 | bzip2. |
|
1229 | 1234 | |
|
1230 | 1235 | The bundle file can then be transferred using conventional means |
|
1231 | 1236 | and applied to another repository with the unbundle or pull |
|
1232 | 1237 | command. This is useful when direct push and pull are not |
|
1233 | 1238 | available or when exporting an entire repository is undesirable. |
|
1234 | 1239 | |
|
1235 | 1240 | Applying bundles preserves all changeset contents including |
|
1236 | 1241 | permissions, copy/rename information, and revision history. |
|
1237 | 1242 | |
|
1238 | 1243 | Returns 0 on success, 1 if no changes found. |
|
1239 | 1244 | """ |
|
1240 | 1245 | opts = pycompat.byteskwargs(opts) |
|
1241 | 1246 | revs = None |
|
1242 | 1247 | if 'rev' in opts: |
|
1243 | 1248 | revstrings = opts['rev'] |
|
1244 | 1249 | revs = scmutil.revrange(repo, revstrings) |
|
1245 | 1250 | if revstrings and not revs: |
|
1246 | 1251 | raise error.Abort(_('no commits to bundle')) |
|
1247 | 1252 | |
|
1248 | 1253 | bundletype = opts.get('type', 'bzip2').lower() |
|
1249 | 1254 | try: |
|
1250 | 1255 | bcompression, cgversion, params = exchange.parsebundlespec( |
|
1251 | 1256 | repo, bundletype, strict=False) |
|
1252 | 1257 | except error.UnsupportedBundleSpecification as e: |
|
1253 | 1258 | raise error.Abort(str(e), |
|
1254 | 1259 | hint=_("see 'hg help bundlespec' for supported " |
|
1255 | 1260 | "values for --type")) |
|
1256 | 1261 | |
|
1257 | 1262 | # Packed bundles are a pseudo bundle format for now. |
|
1258 | 1263 | if cgversion == 's1': |
|
1259 | 1264 | raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'), |
|
1260 | 1265 | hint=_("use 'hg debugcreatestreamclonebundle'")) |
|
1261 | 1266 | |
|
1262 | 1267 | if opts.get('all'): |
|
1263 | 1268 | if dest: |
|
1264 | 1269 | raise error.Abort(_("--all is incompatible with specifying " |
|
1265 | 1270 | "a destination")) |
|
1266 | 1271 | if opts.get('base'): |
|
1267 | 1272 | ui.warn(_("ignoring --base because --all was specified\n")) |
|
1268 | 1273 | base = ['null'] |
|
1269 | 1274 | else: |
|
1270 | 1275 | base = scmutil.revrange(repo, opts.get('base')) |
|
1271 | 1276 | if cgversion not in changegroup.supportedoutgoingversions(repo): |
|
1272 | 1277 | raise error.Abort(_("repository does not support bundle version %s") % |
|
1273 | 1278 | cgversion) |
|
1274 | 1279 | |
|
1275 | 1280 | if base: |
|
1276 | 1281 | if dest: |
|
1277 | 1282 | raise error.Abort(_("--base is incompatible with specifying " |
|
1278 | 1283 | "a destination")) |
|
1279 | 1284 | common = [repo.lookup(rev) for rev in base] |
|
1280 | 1285 | heads = revs and map(repo.lookup, revs) or None |
|
1281 | 1286 | outgoing = discovery.outgoing(repo, common, heads) |
|
1282 | 1287 | else: |
|
1283 | 1288 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
1284 | 1289 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
1285 | 1290 | other = hg.peer(repo, opts, dest) |
|
1286 | 1291 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) |
|
1287 | 1292 | heads = revs and map(repo.lookup, revs) or revs |
|
1288 | 1293 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
1289 | 1294 | onlyheads=heads, |
|
1290 | 1295 | force=opts.get('force'), |
|
1291 | 1296 | portable=True) |
|
1292 | 1297 | |
|
1293 | 1298 | if not outgoing.missing: |
|
1294 | 1299 | scmutil.nochangesfound(ui, repo, not base and outgoing.excluded) |
|
1295 | 1300 | return 1 |
|
1296 | 1301 | |
|
1297 | 1302 | if cgversion == '01': #bundle1 |
|
1298 | 1303 | if bcompression is None: |
|
1299 | 1304 | bcompression = 'UN' |
|
1300 | 1305 | bversion = 'HG10' + bcompression |
|
1301 | 1306 | bcompression = None |
|
1302 | 1307 | elif cgversion in ('02', '03'): |
|
1303 | 1308 | bversion = 'HG20' |
|
1304 | 1309 | else: |
|
1305 | 1310 | raise error.ProgrammingError( |
|
1306 | 1311 | 'bundle: unexpected changegroup version %s' % cgversion) |
|
1307 | 1312 | |
|
1308 | 1313 | # TODO compression options should be derived from bundlespec parsing. |
|
1309 | 1314 | # This is a temporary hack to allow adjusting bundle compression |
|
1310 | 1315 | # level without a) formalizing the bundlespec changes to declare it |
|
1311 | 1316 | # b) introducing a command flag. |
|
1312 | 1317 | compopts = {} |
|
1313 | 1318 | complevel = ui.configint('experimental', 'bundlecomplevel') |
|
1314 | 1319 | if complevel is not None: |
|
1315 | 1320 | compopts['level'] = complevel |
|
1316 | 1321 | |
|
1317 | 1322 | |
|
1318 | 1323 | contentopts = {'cg.version': cgversion} |
|
1319 | 1324 | bundle2.writenewbundle(ui, repo, 'bundle', fname, bversion, outgoing, |
|
1320 | 1325 | contentopts, compression=bcompression, |
|
1321 | 1326 | compopts=compopts) |
|
1322 | 1327 | |
|
1323 | 1328 | @command('cat', |
|
1324 | 1329 | [('o', 'output', '', |
|
1325 | 1330 | _('print output to file with formatted name'), _('FORMAT')), |
|
1326 | 1331 | ('r', 'rev', '', _('print the given revision'), _('REV')), |
|
1327 | 1332 | ('', 'decode', None, _('apply any matching decode filter')), |
|
1328 | 1333 | ] + walkopts, |
|
1329 | 1334 | _('[OPTION]... FILE...'), |
|
1330 | 1335 | inferrepo=True) |
|
1331 | 1336 | def cat(ui, repo, file1, *pats, **opts): |
|
1332 | 1337 | """output the current or given revision of files |
|
1333 | 1338 | |
|
1334 | 1339 | Print the specified files as they were at the given revision. If |
|
1335 | 1340 | no revision is given, the parent of the working directory is used. |
|
1336 | 1341 | |
|
1337 | 1342 | Output may be to a file, in which case the name of the file is |
|
1338 | 1343 | given using a format string. The formatting rules as follows: |
|
1339 | 1344 | |
|
1340 | 1345 | :``%%``: literal "%" character |
|
1341 | 1346 | :``%s``: basename of file being printed |
|
1342 | 1347 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
1343 | 1348 | :``%p``: root-relative path name of file being printed |
|
1344 | 1349 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1345 | 1350 | :``%R``: changeset revision number |
|
1346 | 1351 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1347 | 1352 | :``%r``: zero-padded changeset revision number |
|
1348 | 1353 | :``%b``: basename of the exporting repository |
|
1349 | 1354 | |
|
1350 | 1355 | Returns 0 on success. |
|
1351 | 1356 | """ |
|
1352 | 1357 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1353 | 1358 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1354 | 1359 | |
|
1355 | 1360 | ui.pager('cat') |
|
1356 | 1361 | return cmdutil.cat(ui, repo, ctx, m, '', **opts) |
|
1357 | 1362 | |
|
1358 | 1363 | @command('^clone', |
|
1359 | 1364 | [('U', 'noupdate', None, _('the clone will include an empty working ' |
|
1360 | 1365 | 'directory (only a repository)')), |
|
1361 | 1366 | ('u', 'updaterev', '', _('revision, tag, or branch to check out'), |
|
1362 | 1367 | _('REV')), |
|
1363 | 1368 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), |
|
1364 | 1369 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), |
|
1365 | 1370 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
1366 | 1371 | ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')), |
|
1367 | 1372 | ] + remoteopts, |
|
1368 | 1373 | _('[OPTION]... SOURCE [DEST]'), |
|
1369 | 1374 | norepo=True) |
|
1370 | 1375 | def clone(ui, source, dest=None, **opts): |
|
1371 | 1376 | """make a copy of an existing repository |
|
1372 | 1377 | |
|
1373 | 1378 | Create a copy of an existing repository in a new directory. |
|
1374 | 1379 | |
|
1375 | 1380 | If no destination directory name is specified, it defaults to the |
|
1376 | 1381 | basename of the source. |
|
1377 | 1382 | |
|
1378 | 1383 | The location of the source is added to the new repository's |
|
1379 | 1384 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
1380 | 1385 | |
|
1381 | 1386 | Only local paths and ``ssh://`` URLs are supported as |
|
1382 | 1387 | destinations. For ``ssh://`` destinations, no working directory or |
|
1383 | 1388 | ``.hg/hgrc`` will be created on the remote side. |
|
1384 | 1389 | |
|
1385 | 1390 | If the source repository has a bookmark called '@' set, that |
|
1386 | 1391 | revision will be checked out in the new repository by default. |
|
1387 | 1392 | |
|
1388 | 1393 | To check out a particular version, use -u/--update, or |
|
1389 | 1394 | -U/--noupdate to create a clone with no working directory. |
|
1390 | 1395 | |
|
1391 | 1396 | To pull only a subset of changesets, specify one or more revisions |
|
1392 | 1397 | identifiers with -r/--rev or branches with -b/--branch. The |
|
1393 | 1398 | resulting clone will contain only the specified changesets and |
|
1394 | 1399 | their ancestors. These options (or 'clone src#rev dest') imply |
|
1395 | 1400 | --pull, even for local source repositories. |
|
1396 | 1401 | |
|
1397 | 1402 | .. note:: |
|
1398 | 1403 | |
|
1399 | 1404 | Specifying a tag will include the tagged changeset but not the |
|
1400 | 1405 | changeset containing the tag. |
|
1401 | 1406 | |
|
1402 | 1407 | .. container:: verbose |
|
1403 | 1408 | |
|
1404 | 1409 | For efficiency, hardlinks are used for cloning whenever the |
|
1405 | 1410 | source and destination are on the same filesystem (note this |
|
1406 | 1411 | applies only to the repository data, not to the working |
|
1407 | 1412 | directory). Some filesystems, such as AFS, implement hardlinking |
|
1408 | 1413 | incorrectly, but do not report errors. In these cases, use the |
|
1409 | 1414 | --pull option to avoid hardlinking. |
|
1410 | 1415 | |
|
1411 | 1416 | In some cases, you can clone repositories and the working |
|
1412 | 1417 | directory using full hardlinks with :: |
|
1413 | 1418 | |
|
1414 | 1419 | $ cp -al REPO REPOCLONE |
|
1415 | 1420 | |
|
1416 | 1421 | This is the fastest way to clone, but it is not always safe. The |
|
1417 | 1422 | operation is not atomic (making sure REPO is not modified during |
|
1418 | 1423 | the operation is up to you) and you have to make sure your |
|
1419 | 1424 | editor breaks hardlinks (Emacs and most Linux Kernel tools do |
|
1420 | 1425 | so). Also, this is not compatible with certain extensions that |
|
1421 | 1426 | place their metadata under the .hg directory, such as mq. |
|
1422 | 1427 | |
|
1423 | 1428 | Mercurial will update the working directory to the first applicable |
|
1424 | 1429 | revision from this list: |
|
1425 | 1430 | |
|
1426 | 1431 | a) null if -U or the source repository has no changesets |
|
1427 | 1432 | b) if -u . and the source repository is local, the first parent of |
|
1428 | 1433 | the source repository's working directory |
|
1429 | 1434 | c) the changeset specified with -u (if a branch name, this means the |
|
1430 | 1435 | latest head of that branch) |
|
1431 | 1436 | d) the changeset specified with -r |
|
1432 | 1437 | e) the tipmost head specified with -b |
|
1433 | 1438 | f) the tipmost head specified with the url#branch source syntax |
|
1434 | 1439 | g) the revision marked with the '@' bookmark, if present |
|
1435 | 1440 | h) the tipmost head of the default branch |
|
1436 | 1441 | i) tip |
|
1437 | 1442 | |
|
1438 | 1443 | When cloning from servers that support it, Mercurial may fetch |
|
1439 | 1444 | pre-generated data from a server-advertised URL. When this is done, |
|
1440 | 1445 | hooks operating on incoming changesets and changegroups may fire twice, |
|
1441 | 1446 | once for the bundle fetched from the URL and another for any additional |
|
1442 | 1447 | data not fetched from this URL. In addition, if an error occurs, the |
|
1443 | 1448 | repository may be rolled back to a partial clone. This behavior may |
|
1444 | 1449 | change in future releases. See :hg:`help -e clonebundles` for more. |
|
1445 | 1450 | |
|
1446 | 1451 | Examples: |
|
1447 | 1452 | |
|
1448 | 1453 | - clone a remote repository to a new directory named hg/:: |
|
1449 | 1454 | |
|
1450 | 1455 | hg clone https://www.mercurial-scm.org/repo/hg/ |
|
1451 | 1456 | |
|
1452 | 1457 | - create a lightweight local clone:: |
|
1453 | 1458 | |
|
1454 | 1459 | hg clone project/ project-feature/ |
|
1455 | 1460 | |
|
1456 | 1461 | - clone from an absolute path on an ssh server (note double-slash):: |
|
1457 | 1462 | |
|
1458 | 1463 | hg clone ssh://user@server//home/projects/alpha/ |
|
1459 | 1464 | |
|
1460 | 1465 | - do a high-speed clone over a LAN while checking out a |
|
1461 | 1466 | specified version:: |
|
1462 | 1467 | |
|
1463 | 1468 | hg clone --uncompressed http://server/repo -u 1.5 |
|
1464 | 1469 | |
|
1465 | 1470 | - create a repository without changesets after a particular revision:: |
|
1466 | 1471 | |
|
1467 | 1472 | hg clone -r 04e544 experimental/ good/ |
|
1468 | 1473 | |
|
1469 | 1474 | - clone (and track) a particular named branch:: |
|
1470 | 1475 | |
|
1471 | 1476 | hg clone https://www.mercurial-scm.org/repo/hg/#stable |
|
1472 | 1477 | |
|
1473 | 1478 | See :hg:`help urls` for details on specifying URLs. |
|
1474 | 1479 | |
|
1475 | 1480 | Returns 0 on success. |
|
1476 | 1481 | """ |
|
1477 | 1482 | opts = pycompat.byteskwargs(opts) |
|
1478 | 1483 | if opts.get('noupdate') and opts.get('updaterev'): |
|
1479 | 1484 | raise error.Abort(_("cannot specify both --noupdate and --updaterev")) |
|
1480 | 1485 | |
|
1481 | 1486 | r = hg.clone(ui, opts, source, dest, |
|
1482 | 1487 | pull=opts.get('pull'), |
|
1483 | 1488 | stream=opts.get('uncompressed'), |
|
1484 | 1489 | rev=opts.get('rev'), |
|
1485 | 1490 | update=opts.get('updaterev') or not opts.get('noupdate'), |
|
1486 | 1491 | branch=opts.get('branch'), |
|
1487 | 1492 | shareopts=opts.get('shareopts')) |
|
1488 | 1493 | |
|
1489 | 1494 | return r is None |
|
1490 | 1495 | |
|
1491 | 1496 | @command('^commit|ci', |
|
1492 | 1497 | [('A', 'addremove', None, |
|
1493 | 1498 | _('mark new/missing files as added/removed before committing')), |
|
1494 | 1499 | ('', 'close-branch', None, |
|
1495 | 1500 | _('mark a branch head as closed')), |
|
1496 | 1501 | ('', 'amend', None, _('amend the parent of the working directory')), |
|
1497 | 1502 | ('s', 'secret', None, _('use the secret phase for committing')), |
|
1498 | 1503 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
1499 | 1504 | ('i', 'interactive', None, _('use interactive mode')), |
|
1500 | 1505 | ] + walkopts + commitopts + commitopts2 + subrepoopts, |
|
1501 | 1506 | _('[OPTION]... [FILE]...'), |
|
1502 | 1507 | inferrepo=True) |
|
1503 | 1508 | def commit(ui, repo, *pats, **opts): |
|
1504 | 1509 | """commit the specified files or all outstanding changes |
|
1505 | 1510 | |
|
1506 | 1511 | Commit changes to the given files into the repository. Unlike a |
|
1507 | 1512 | centralized SCM, this operation is a local operation. See |
|
1508 | 1513 | :hg:`push` for a way to actively distribute your changes. |
|
1509 | 1514 | |
|
1510 | 1515 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1511 | 1516 | will be committed. |
|
1512 | 1517 | |
|
1513 | 1518 | If you are committing the result of a merge, do not provide any |
|
1514 | 1519 | filenames or -I/-X filters. |
|
1515 | 1520 | |
|
1516 | 1521 | If no commit message is specified, Mercurial starts your |
|
1517 | 1522 | configured editor where you can enter a message. In case your |
|
1518 | 1523 | commit fails, you will find a backup of your message in |
|
1519 | 1524 | ``.hg/last-message.txt``. |
|
1520 | 1525 | |
|
1521 | 1526 | The --close-branch flag can be used to mark the current branch |
|
1522 | 1527 | head closed. When all heads of a branch are closed, the branch |
|
1523 | 1528 | will be considered closed and no longer listed. |
|
1524 | 1529 | |
|
1525 | 1530 | The --amend flag can be used to amend the parent of the |
|
1526 | 1531 | working directory with a new commit that contains the changes |
|
1527 | 1532 | in the parent in addition to those currently reported by :hg:`status`, |
|
1528 | 1533 | if there are any. The old commit is stored in a backup bundle in |
|
1529 | 1534 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` |
|
1530 | 1535 | on how to restore it). |
|
1531 | 1536 | |
|
1532 | 1537 | Message, user and date are taken from the amended commit unless |
|
1533 | 1538 | specified. When a message isn't specified on the command line, |
|
1534 | 1539 | the editor will open with the message of the amended commit. |
|
1535 | 1540 | |
|
1536 | 1541 | It is not possible to amend public changesets (see :hg:`help phases`) |
|
1537 | 1542 | or changesets that have children. |
|
1538 | 1543 | |
|
1539 | 1544 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1540 | 1545 | |
|
1541 | 1546 | Returns 0 on success, 1 if nothing changed. |
|
1542 | 1547 | |
|
1543 | 1548 | .. container:: verbose |
|
1544 | 1549 | |
|
1545 | 1550 | Examples: |
|
1546 | 1551 | |
|
1547 | 1552 | - commit all files ending in .py:: |
|
1548 | 1553 | |
|
1549 | 1554 | hg commit --include "set:**.py" |
|
1550 | 1555 | |
|
1551 | 1556 | - commit all non-binary files:: |
|
1552 | 1557 | |
|
1553 | 1558 | hg commit --exclude "set:binary()" |
|
1554 | 1559 | |
|
1555 | 1560 | - amend the current commit and set the date to now:: |
|
1556 | 1561 | |
|
1557 | 1562 | hg commit --amend --date now |
|
1558 | 1563 | """ |
|
1559 | 1564 | wlock = lock = None |
|
1560 | 1565 | try: |
|
1561 | 1566 | wlock = repo.wlock() |
|
1562 | 1567 | lock = repo.lock() |
|
1563 | 1568 | return _docommit(ui, repo, *pats, **opts) |
|
1564 | 1569 | finally: |
|
1565 | 1570 | release(lock, wlock) |
|
1566 | 1571 | |
|
1567 | 1572 | def _docommit(ui, repo, *pats, **opts): |
|
1568 | 1573 | if opts.get(r'interactive'): |
|
1569 | 1574 | opts.pop(r'interactive') |
|
1570 | 1575 | ret = cmdutil.dorecord(ui, repo, commit, None, False, |
|
1571 | 1576 | cmdutil.recordfilter, *pats, |
|
1572 | 1577 | **opts) |
|
1573 | 1578 | # ret can be 0 (no changes to record) or the value returned by |
|
1574 | 1579 | # commit(), 1 if nothing changed or None on success. |
|
1575 | 1580 | return 1 if ret == 0 else ret |
|
1576 | 1581 | |
|
1577 | 1582 | opts = pycompat.byteskwargs(opts) |
|
1578 | 1583 | if opts.get('subrepos'): |
|
1579 | 1584 | if opts.get('amend'): |
|
1580 | 1585 | raise error.Abort(_('cannot amend with --subrepos')) |
|
1581 | 1586 | # Let --subrepos on the command line override config setting. |
|
1582 | 1587 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') |
|
1583 | 1588 | |
|
1584 | 1589 | cmdutil.checkunfinished(repo, commit=True) |
|
1585 | 1590 | |
|
1586 | 1591 | branch = repo[None].branch() |
|
1587 | 1592 | bheads = repo.branchheads(branch) |
|
1588 | 1593 | |
|
1589 | 1594 | extra = {} |
|
1590 | 1595 | if opts.get('close_branch'): |
|
1591 | 1596 | extra['close'] = 1 |
|
1592 | 1597 | |
|
1593 | 1598 | if not bheads: |
|
1594 | 1599 | raise error.Abort(_('can only close branch heads')) |
|
1595 | 1600 | elif opts.get('amend'): |
|
1596 | 1601 | if repo[None].parents()[0].p1().branch() != branch and \ |
|
1597 | 1602 | repo[None].parents()[0].p2().branch() != branch: |
|
1598 | 1603 | raise error.Abort(_('can only close branch heads')) |
|
1599 | 1604 | |
|
1600 | 1605 | if opts.get('amend'): |
|
1601 | 1606 | if ui.configbool('ui', 'commitsubrepos'): |
|
1602 | 1607 | raise error.Abort(_('cannot amend with ui.commitsubrepos enabled')) |
|
1603 | 1608 | |
|
1604 | 1609 | old = repo['.'] |
|
1605 | 1610 | if not old.mutable(): |
|
1606 | 1611 | raise error.Abort(_('cannot amend public changesets')) |
|
1607 | 1612 | if len(repo[None].parents()) > 1: |
|
1608 | 1613 | raise error.Abort(_('cannot amend while merging')) |
|
1609 | 1614 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) |
|
1610 | 1615 | if not allowunstable and old.children(): |
|
1611 | 1616 | raise error.Abort(_('cannot amend changeset with children')) |
|
1612 | 1617 | |
|
1613 | 1618 | # Currently histedit gets confused if an amend happens while histedit |
|
1614 | 1619 | # is in progress. Since we have a checkunfinished command, we are |
|
1615 | 1620 | # temporarily honoring it. |
|
1616 | 1621 | # |
|
1617 | 1622 | # Note: eventually this guard will be removed. Please do not expect |
|
1618 | 1623 | # this behavior to remain. |
|
1619 | 1624 | if not obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
1620 | 1625 | cmdutil.checkunfinished(repo) |
|
1621 | 1626 | |
|
1622 | 1627 | # commitfunc is used only for temporary amend commit by cmdutil.amend |
|
1623 | 1628 | def commitfunc(ui, repo, message, match, opts): |
|
1624 | 1629 | return repo.commit(message, |
|
1625 | 1630 | opts.get('user') or old.user(), |
|
1626 | 1631 | opts.get('date') or old.date(), |
|
1627 | 1632 | match, |
|
1628 | 1633 | extra=extra) |
|
1629 | 1634 | |
|
1630 | 1635 | node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts) |
|
1631 | 1636 | if node == old.node(): |
|
1632 | 1637 | ui.status(_("nothing changed\n")) |
|
1633 | 1638 | return 1 |
|
1634 | 1639 | else: |
|
1635 | 1640 | def commitfunc(ui, repo, message, match, opts): |
|
1636 | 1641 | overrides = {} |
|
1637 | 1642 | if opts.get('secret'): |
|
1638 | 1643 | overrides[('phases', 'new-commit')] = 'secret' |
|
1639 | 1644 | |
|
1640 | 1645 | baseui = repo.baseui |
|
1641 | 1646 | with baseui.configoverride(overrides, 'commit'): |
|
1642 | 1647 | with ui.configoverride(overrides, 'commit'): |
|
1643 | 1648 | editform = cmdutil.mergeeditform(repo[None], |
|
1644 | 1649 | 'commit.normal') |
|
1645 | 1650 | editor = cmdutil.getcommiteditor( |
|
1646 | 1651 | editform=editform, **pycompat.strkwargs(opts)) |
|
1647 | 1652 | return repo.commit(message, |
|
1648 | 1653 | opts.get('user'), |
|
1649 | 1654 | opts.get('date'), |
|
1650 | 1655 | match, |
|
1651 | 1656 | editor=editor, |
|
1652 | 1657 | extra=extra) |
|
1653 | 1658 | |
|
1654 | 1659 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
1655 | 1660 | |
|
1656 | 1661 | if not node: |
|
1657 | 1662 | stat = cmdutil.postcommitstatus(repo, pats, opts) |
|
1658 | 1663 | if stat[3]: |
|
1659 | 1664 | ui.status(_("nothing changed (%d missing files, see " |
|
1660 | 1665 | "'hg status')\n") % len(stat[3])) |
|
1661 | 1666 | else: |
|
1662 | 1667 | ui.status(_("nothing changed\n")) |
|
1663 | 1668 | return 1 |
|
1664 | 1669 | |
|
1665 | 1670 | cmdutil.commitstatus(repo, node, branch, bheads, opts) |
|
1666 | 1671 | |
|
1667 | 1672 | @command('config|showconfig|debugconfig', |
|
1668 | 1673 | [('u', 'untrusted', None, _('show untrusted configuration options')), |
|
1669 | 1674 | ('e', 'edit', None, _('edit user config')), |
|
1670 | 1675 | ('l', 'local', None, _('edit repository config')), |
|
1671 | 1676 | ('g', 'global', None, _('edit global config'))] + formatteropts, |
|
1672 | 1677 | _('[-u] [NAME]...'), |
|
1673 | 1678 | optionalrepo=True) |
|
1674 | 1679 | def config(ui, repo, *values, **opts): |
|
1675 | 1680 | """show combined config settings from all hgrc files |
|
1676 | 1681 | |
|
1677 | 1682 | With no arguments, print names and values of all config items. |
|
1678 | 1683 | |
|
1679 | 1684 | With one argument of the form section.name, print just the value |
|
1680 | 1685 | of that config item. |
|
1681 | 1686 | |
|
1682 | 1687 | With multiple arguments, print names and values of all config |
|
1683 | 1688 | items with matching section names. |
|
1684 | 1689 | |
|
1685 | 1690 | With --edit, start an editor on the user-level config file. With |
|
1686 | 1691 | --global, edit the system-wide config file. With --local, edit the |
|
1687 | 1692 | repository-level config file. |
|
1688 | 1693 | |
|
1689 | 1694 | With --debug, the source (filename and line number) is printed |
|
1690 | 1695 | for each config item. |
|
1691 | 1696 | |
|
1692 | 1697 | See :hg:`help config` for more information about config files. |
|
1693 | 1698 | |
|
1694 | 1699 | Returns 0 on success, 1 if NAME does not exist. |
|
1695 | 1700 | |
|
1696 | 1701 | """ |
|
1697 | 1702 | |
|
1698 | 1703 | opts = pycompat.byteskwargs(opts) |
|
1699 | 1704 | if opts.get('edit') or opts.get('local') or opts.get('global'): |
|
1700 | 1705 | if opts.get('local') and opts.get('global'): |
|
1701 | 1706 | raise error.Abort(_("can't use --local and --global together")) |
|
1702 | 1707 | |
|
1703 | 1708 | if opts.get('local'): |
|
1704 | 1709 | if not repo: |
|
1705 | 1710 | raise error.Abort(_("can't use --local outside a repository")) |
|
1706 | 1711 | paths = [repo.vfs.join('hgrc')] |
|
1707 | 1712 | elif opts.get('global'): |
|
1708 | 1713 | paths = rcutil.systemrcpath() |
|
1709 | 1714 | else: |
|
1710 | 1715 | paths = rcutil.userrcpath() |
|
1711 | 1716 | |
|
1712 | 1717 | for f in paths: |
|
1713 | 1718 | if os.path.exists(f): |
|
1714 | 1719 | break |
|
1715 | 1720 | else: |
|
1716 | 1721 | if opts.get('global'): |
|
1717 | 1722 | samplehgrc = uimod.samplehgrcs['global'] |
|
1718 | 1723 | elif opts.get('local'): |
|
1719 | 1724 | samplehgrc = uimod.samplehgrcs['local'] |
|
1720 | 1725 | else: |
|
1721 | 1726 | samplehgrc = uimod.samplehgrcs['user'] |
|
1722 | 1727 | |
|
1723 | 1728 | f = paths[0] |
|
1724 | 1729 | fp = open(f, "w") |
|
1725 | 1730 | fp.write(samplehgrc) |
|
1726 | 1731 | fp.close() |
|
1727 | 1732 | |
|
1728 | 1733 | editor = ui.geteditor() |
|
1729 | 1734 | ui.system("%s \"%s\"" % (editor, f), |
|
1730 | 1735 | onerr=error.Abort, errprefix=_("edit failed"), |
|
1731 | 1736 | blockedtag='config_edit') |
|
1732 | 1737 | return |
|
1733 | 1738 | ui.pager('config') |
|
1734 | 1739 | fm = ui.formatter('config', opts) |
|
1735 | 1740 | for t, f in rcutil.rccomponents(): |
|
1736 | 1741 | if t == 'path': |
|
1737 | 1742 | ui.debug('read config from: %s\n' % f) |
|
1738 | 1743 | elif t == 'items': |
|
1739 | 1744 | for section, name, value, source in f: |
|
1740 | 1745 | ui.debug('set config by: %s\n' % source) |
|
1741 | 1746 | else: |
|
1742 | 1747 | raise error.ProgrammingError('unknown rctype: %s' % t) |
|
1743 | 1748 | untrusted = bool(opts.get('untrusted')) |
|
1744 | 1749 | if values: |
|
1745 | 1750 | sections = [v for v in values if '.' not in v] |
|
1746 | 1751 | items = [v for v in values if '.' in v] |
|
1747 | 1752 | if len(items) > 1 or items and sections: |
|
1748 | 1753 | raise error.Abort(_('only one config item permitted')) |
|
1749 | 1754 | matched = False |
|
1750 | 1755 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
1751 | 1756 | source = ui.configsource(section, name, untrusted) |
|
1752 | 1757 | value = pycompat.bytestr(value) |
|
1753 | 1758 | if fm.isplain(): |
|
1754 | 1759 | source = source or 'none' |
|
1755 | 1760 | value = value.replace('\n', '\\n') |
|
1756 | 1761 | entryname = section + '.' + name |
|
1757 | 1762 | if values: |
|
1758 | 1763 | for v in values: |
|
1759 | 1764 | if v == section: |
|
1760 | 1765 | fm.startitem() |
|
1761 | 1766 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) |
|
1762 | 1767 | fm.write('name value', '%s=%s\n', entryname, value) |
|
1763 | 1768 | matched = True |
|
1764 | 1769 | elif v == entryname: |
|
1765 | 1770 | fm.startitem() |
|
1766 | 1771 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) |
|
1767 | 1772 | fm.write('value', '%s\n', value) |
|
1768 | 1773 | fm.data(name=entryname) |
|
1769 | 1774 | matched = True |
|
1770 | 1775 | else: |
|
1771 | 1776 | fm.startitem() |
|
1772 | 1777 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) |
|
1773 | 1778 | fm.write('name value', '%s=%s\n', entryname, value) |
|
1774 | 1779 | matched = True |
|
1775 | 1780 | fm.end() |
|
1776 | 1781 | if matched: |
|
1777 | 1782 | return 0 |
|
1778 | 1783 | return 1 |
|
1779 | 1784 | |
|
1780 | 1785 | @command('copy|cp', |
|
1781 | 1786 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
1782 | 1787 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
1783 | 1788 | ] + walkopts + dryrunopts, |
|
1784 | 1789 | _('[OPTION]... [SOURCE]... DEST')) |
|
1785 | 1790 | def copy(ui, repo, *pats, **opts): |
|
1786 | 1791 | """mark files as copied for the next commit |
|
1787 | 1792 | |
|
1788 | 1793 | Mark dest as having copies of source files. If dest is a |
|
1789 | 1794 | directory, copies are put in that directory. If dest is a file, |
|
1790 | 1795 | the source must be a single file. |
|
1791 | 1796 | |
|
1792 | 1797 | By default, this command copies the contents of files as they |
|
1793 | 1798 | exist in the working directory. If invoked with -A/--after, the |
|
1794 | 1799 | operation is recorded, but no copying is performed. |
|
1795 | 1800 | |
|
1796 | 1801 | This command takes effect with the next commit. To undo a copy |
|
1797 | 1802 | before that, see :hg:`revert`. |
|
1798 | 1803 | |
|
1799 | 1804 | Returns 0 on success, 1 if errors are encountered. |
|
1800 | 1805 | """ |
|
1801 | 1806 | opts = pycompat.byteskwargs(opts) |
|
1802 | 1807 | with repo.wlock(False): |
|
1803 | 1808 | return cmdutil.copy(ui, repo, pats, opts) |
|
1804 | 1809 | |
|
1805 | 1810 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) |
|
1806 | 1811 | def debugcommands(ui, cmd='', *args): |
|
1807 | 1812 | """list all available commands and options""" |
|
1808 | 1813 | for cmd, vals in sorted(table.iteritems()): |
|
1809 | 1814 | cmd = cmd.split('|')[0].strip('^') |
|
1810 | 1815 | opts = ', '.join([i[1] for i in vals[1]]) |
|
1811 | 1816 | ui.write('%s: %s\n' % (cmd, opts)) |
|
1812 | 1817 | |
|
1813 | 1818 | @command('debugcomplete', |
|
1814 | 1819 | [('o', 'options', None, _('show the command options'))], |
|
1815 | 1820 | _('[-o] CMD'), |
|
1816 | 1821 | norepo=True) |
|
1817 | 1822 | def debugcomplete(ui, cmd='', **opts): |
|
1818 | 1823 | """returns the completion list associated with the given command""" |
|
1819 | 1824 | |
|
1820 | 1825 | if opts.get('options'): |
|
1821 | 1826 | options = [] |
|
1822 | 1827 | otables = [globalopts] |
|
1823 | 1828 | if cmd: |
|
1824 | 1829 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
1825 | 1830 | otables.append(entry[1]) |
|
1826 | 1831 | for t in otables: |
|
1827 | 1832 | for o in t: |
|
1828 | 1833 | if "(DEPRECATED)" in o[3]: |
|
1829 | 1834 | continue |
|
1830 | 1835 | if o[0]: |
|
1831 | 1836 | options.append('-%s' % o[0]) |
|
1832 | 1837 | options.append('--%s' % o[1]) |
|
1833 | 1838 | ui.write("%s\n" % "\n".join(options)) |
|
1834 | 1839 | return |
|
1835 | 1840 | |
|
1836 | 1841 | cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table) |
|
1837 | 1842 | if ui.verbose: |
|
1838 | 1843 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
1839 | 1844 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
1840 | 1845 | |
|
1841 | 1846 | @command('^diff', |
|
1842 | 1847 | [('r', 'rev', [], _('revision'), _('REV')), |
|
1843 | 1848 | ('c', 'change', '', _('change made by revision'), _('REV')) |
|
1844 | 1849 | ] + diffopts + diffopts2 + walkopts + subrepoopts, |
|
1845 | 1850 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), |
|
1846 | 1851 | inferrepo=True) |
|
1847 | 1852 | def diff(ui, repo, *pats, **opts): |
|
1848 | 1853 | """diff repository (or selected files) |
|
1849 | 1854 | |
|
1850 | 1855 | Show differences between revisions for the specified files. |
|
1851 | 1856 | |
|
1852 | 1857 | Differences between files are shown using the unified diff format. |
|
1853 | 1858 | |
|
1854 | 1859 | .. note:: |
|
1855 | 1860 | |
|
1856 | 1861 | :hg:`diff` may generate unexpected results for merges, as it will |
|
1857 | 1862 | default to comparing against the working directory's first |
|
1858 | 1863 | parent changeset if no revisions are specified. |
|
1859 | 1864 | |
|
1860 | 1865 | When two revision arguments are given, then changes are shown |
|
1861 | 1866 | between those revisions. If only one revision is specified then |
|
1862 | 1867 | that revision is compared to the working directory, and, when no |
|
1863 | 1868 | revisions are specified, the working directory files are compared |
|
1864 | 1869 | to its first parent. |
|
1865 | 1870 | |
|
1866 | 1871 | Alternatively you can specify -c/--change with a revision to see |
|
1867 | 1872 | the changes in that changeset relative to its first parent. |
|
1868 | 1873 | |
|
1869 | 1874 | Without the -a/--text option, diff will avoid generating diffs of |
|
1870 | 1875 | files it detects as binary. With -a, diff will generate a diff |
|
1871 | 1876 | anyway, probably with undesirable results. |
|
1872 | 1877 | |
|
1873 | 1878 | Use the -g/--git option to generate diffs in the git extended diff |
|
1874 | 1879 | format. For more information, read :hg:`help diffs`. |
|
1875 | 1880 | |
|
1876 | 1881 | .. container:: verbose |
|
1877 | 1882 | |
|
1878 | 1883 | Examples: |
|
1879 | 1884 | |
|
1880 | 1885 | - compare a file in the current working directory to its parent:: |
|
1881 | 1886 | |
|
1882 | 1887 | hg diff foo.c |
|
1883 | 1888 | |
|
1884 | 1889 | - compare two historical versions of a directory, with rename info:: |
|
1885 | 1890 | |
|
1886 | 1891 | hg diff --git -r 1.0:1.2 lib/ |
|
1887 | 1892 | |
|
1888 | 1893 | - get change stats relative to the last change on some date:: |
|
1889 | 1894 | |
|
1890 | 1895 | hg diff --stat -r "date('may 2')" |
|
1891 | 1896 | |
|
1892 | 1897 | - diff all newly-added files that contain a keyword:: |
|
1893 | 1898 | |
|
1894 | 1899 | hg diff "set:added() and grep(GNU)" |
|
1895 | 1900 | |
|
1896 | 1901 | - compare a revision and its parents:: |
|
1897 | 1902 | |
|
1898 | 1903 | hg diff -c 9353 # compare against first parent |
|
1899 | 1904 | hg diff -r 9353^:9353 # same using revset syntax |
|
1900 | 1905 | hg diff -r 9353^2:9353 # compare against the second parent |
|
1901 | 1906 | |
|
1902 | 1907 | Returns 0 on success. |
|
1903 | 1908 | """ |
|
1904 | 1909 | |
|
1905 | 1910 | opts = pycompat.byteskwargs(opts) |
|
1906 | 1911 | revs = opts.get('rev') |
|
1907 | 1912 | change = opts.get('change') |
|
1908 | 1913 | stat = opts.get('stat') |
|
1909 | 1914 | reverse = opts.get('reverse') |
|
1910 | 1915 | |
|
1911 | 1916 | if revs and change: |
|
1912 | 1917 | msg = _('cannot specify --rev and --change at the same time') |
|
1913 | 1918 | raise error.Abort(msg) |
|
1914 | 1919 | elif change: |
|
1915 | 1920 | node2 = scmutil.revsingle(repo, change, None).node() |
|
1916 | 1921 | node1 = repo[node2].p1().node() |
|
1917 | 1922 | else: |
|
1918 | 1923 | node1, node2 = scmutil.revpair(repo, revs) |
|
1919 | 1924 | |
|
1920 | 1925 | if reverse: |
|
1921 | 1926 | node1, node2 = node2, node1 |
|
1922 | 1927 | |
|
1923 | 1928 | diffopts = patch.diffallopts(ui, opts) |
|
1924 | 1929 | m = scmutil.match(repo[node2], pats, opts) |
|
1925 | 1930 | ui.pager('diff') |
|
1926 | 1931 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, |
|
1927 | 1932 | listsubrepos=opts.get('subrepos'), |
|
1928 | 1933 | root=opts.get('root')) |
|
1929 | 1934 | |
|
1930 | 1935 | @command('^export', |
|
1931 | 1936 | [('o', 'output', '', |
|
1932 | 1937 | _('print output to file with formatted name'), _('FORMAT')), |
|
1933 | 1938 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
1934 | 1939 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
1935 | 1940 | ] + diffopts, |
|
1936 | 1941 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...')) |
|
1937 | 1942 | def export(ui, repo, *changesets, **opts): |
|
1938 | 1943 | """dump the header and diffs for one or more changesets |
|
1939 | 1944 | |
|
1940 | 1945 | Print the changeset header and diffs for one or more revisions. |
|
1941 | 1946 | If no revision is given, the parent of the working directory is used. |
|
1942 | 1947 | |
|
1943 | 1948 | The information shown in the changeset header is: author, date, |
|
1944 | 1949 | branch name (if non-default), changeset hash, parent(s) and commit |
|
1945 | 1950 | comment. |
|
1946 | 1951 | |
|
1947 | 1952 | .. note:: |
|
1948 | 1953 | |
|
1949 | 1954 | :hg:`export` may generate unexpected diff output for merge |
|
1950 | 1955 | changesets, as it will compare the merge changeset against its |
|
1951 | 1956 | first parent only. |
|
1952 | 1957 | |
|
1953 | 1958 | Output may be to a file, in which case the name of the file is |
|
1954 | 1959 | given using a format string. The formatting rules are as follows: |
|
1955 | 1960 | |
|
1956 | 1961 | :``%%``: literal "%" character |
|
1957 | 1962 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1958 | 1963 | :``%N``: number of patches being generated |
|
1959 | 1964 | :``%R``: changeset revision number |
|
1960 | 1965 | :``%b``: basename of the exporting repository |
|
1961 | 1966 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1962 | 1967 | :``%m``: first line of the commit message (only alphanumeric characters) |
|
1963 | 1968 | :``%n``: zero-padded sequence number, starting at 1 |
|
1964 | 1969 | :``%r``: zero-padded changeset revision number |
|
1965 | 1970 | |
|
1966 | 1971 | Without the -a/--text option, export will avoid generating diffs |
|
1967 | 1972 | of files it detects as binary. With -a, export will generate a |
|
1968 | 1973 | diff anyway, probably with undesirable results. |
|
1969 | 1974 | |
|
1970 | 1975 | Use the -g/--git option to generate diffs in the git extended diff |
|
1971 | 1976 | format. See :hg:`help diffs` for more information. |
|
1972 | 1977 | |
|
1973 | 1978 | With the --switch-parent option, the diff will be against the |
|
1974 | 1979 | second parent. It can be useful to review a merge. |
|
1975 | 1980 | |
|
1976 | 1981 | .. container:: verbose |
|
1977 | 1982 | |
|
1978 | 1983 | Examples: |
|
1979 | 1984 | |
|
1980 | 1985 | - use export and import to transplant a bugfix to the current |
|
1981 | 1986 | branch:: |
|
1982 | 1987 | |
|
1983 | 1988 | hg export -r 9353 | hg import - |
|
1984 | 1989 | |
|
1985 | 1990 | - export all the changesets between two revisions to a file with |
|
1986 | 1991 | rename information:: |
|
1987 | 1992 | |
|
1988 | 1993 | hg export --git -r 123:150 > changes.txt |
|
1989 | 1994 | |
|
1990 | 1995 | - split outgoing changes into a series of patches with |
|
1991 | 1996 | descriptive names:: |
|
1992 | 1997 | |
|
1993 | 1998 | hg export -r "outgoing()" -o "%n-%m.patch" |
|
1994 | 1999 | |
|
1995 | 2000 | Returns 0 on success. |
|
1996 | 2001 | """ |
|
1997 | 2002 | opts = pycompat.byteskwargs(opts) |
|
1998 | 2003 | changesets += tuple(opts.get('rev', [])) |
|
1999 | 2004 | if not changesets: |
|
2000 | 2005 | changesets = ['.'] |
|
2001 | 2006 | revs = scmutil.revrange(repo, changesets) |
|
2002 | 2007 | if not revs: |
|
2003 | 2008 | raise error.Abort(_("export requires at least one changeset")) |
|
2004 | 2009 | if len(revs) > 1: |
|
2005 | 2010 | ui.note(_('exporting patches:\n')) |
|
2006 | 2011 | else: |
|
2007 | 2012 | ui.note(_('exporting patch:\n')) |
|
2008 | 2013 | ui.pager('export') |
|
2009 | 2014 | cmdutil.export(repo, revs, fntemplate=opts.get('output'), |
|
2010 | 2015 | switch_parent=opts.get('switch_parent'), |
|
2011 | 2016 | opts=patch.diffallopts(ui, opts)) |
|
2012 | 2017 | |
|
2013 | 2018 | @command('files', |
|
2014 | 2019 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
2015 | 2020 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
2016 | 2021 | ] + walkopts + formatteropts + subrepoopts, |
|
2017 | 2022 | _('[OPTION]... [FILE]...')) |
|
2018 | 2023 | def files(ui, repo, *pats, **opts): |
|
2019 | 2024 | """list tracked files |
|
2020 | 2025 | |
|
2021 | 2026 | Print files under Mercurial control in the working directory or |
|
2022 | 2027 | specified revision for given files (excluding removed files). |
|
2023 | 2028 | Files can be specified as filenames or filesets. |
|
2024 | 2029 | |
|
2025 | 2030 | If no files are given to match, this command prints the names |
|
2026 | 2031 | of all files under Mercurial control. |
|
2027 | 2032 | |
|
2028 | 2033 | .. container:: verbose |
|
2029 | 2034 | |
|
2030 | 2035 | Examples: |
|
2031 | 2036 | |
|
2032 | 2037 | - list all files under the current directory:: |
|
2033 | 2038 | |
|
2034 | 2039 | hg files . |
|
2035 | 2040 | |
|
2036 | 2041 | - shows sizes and flags for current revision:: |
|
2037 | 2042 | |
|
2038 | 2043 | hg files -vr . |
|
2039 | 2044 | |
|
2040 | 2045 | - list all files named README:: |
|
2041 | 2046 | |
|
2042 | 2047 | hg files -I "**/README" |
|
2043 | 2048 | |
|
2044 | 2049 | - list all binary files:: |
|
2045 | 2050 | |
|
2046 | 2051 | hg files "set:binary()" |
|
2047 | 2052 | |
|
2048 | 2053 | - find files containing a regular expression:: |
|
2049 | 2054 | |
|
2050 | 2055 | hg files "set:grep('bob')" |
|
2051 | 2056 | |
|
2052 | 2057 | - search tracked file contents with xargs and grep:: |
|
2053 | 2058 | |
|
2054 | 2059 | hg files -0 | xargs -0 grep foo |
|
2055 | 2060 | |
|
2056 | 2061 | See :hg:`help patterns` and :hg:`help filesets` for more information |
|
2057 | 2062 | on specifying file patterns. |
|
2058 | 2063 | |
|
2059 | 2064 | Returns 0 if a match is found, 1 otherwise. |
|
2060 | 2065 | |
|
2061 | 2066 | """ |
|
2062 | 2067 | |
|
2063 | 2068 | opts = pycompat.byteskwargs(opts) |
|
2064 | 2069 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
2065 | 2070 | |
|
2066 | 2071 | end = '\n' |
|
2067 | 2072 | if opts.get('print0'): |
|
2068 | 2073 | end = '\0' |
|
2069 | 2074 | fmt = '%s' + end |
|
2070 | 2075 | |
|
2071 | 2076 | m = scmutil.match(ctx, pats, opts) |
|
2072 | 2077 | ui.pager('files') |
|
2073 | 2078 | with ui.formatter('files', opts) as fm: |
|
2074 | 2079 | return cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos')) |
|
2075 | 2080 | |
|
2076 | 2081 | @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) |
|
2077 | 2082 | def forget(ui, repo, *pats, **opts): |
|
2078 | 2083 | """forget the specified files on the next commit |
|
2079 | 2084 | |
|
2080 | 2085 | Mark the specified files so they will no longer be tracked |
|
2081 | 2086 | after the next commit. |
|
2082 | 2087 | |
|
2083 | 2088 | This only removes files from the current branch, not from the |
|
2084 | 2089 | entire project history, and it does not delete them from the |
|
2085 | 2090 | working directory. |
|
2086 | 2091 | |
|
2087 | 2092 | To delete the file from the working directory, see :hg:`remove`. |
|
2088 | 2093 | |
|
2089 | 2094 | To undo a forget before the next commit, see :hg:`add`. |
|
2090 | 2095 | |
|
2091 | 2096 | .. container:: verbose |
|
2092 | 2097 | |
|
2093 | 2098 | Examples: |
|
2094 | 2099 | |
|
2095 | 2100 | - forget newly-added binary files:: |
|
2096 | 2101 | |
|
2097 | 2102 | hg forget "set:added() and binary()" |
|
2098 | 2103 | |
|
2099 | 2104 | - forget files that would be excluded by .hgignore:: |
|
2100 | 2105 | |
|
2101 | 2106 | hg forget "set:hgignore()" |
|
2102 | 2107 | |
|
2103 | 2108 | Returns 0 on success. |
|
2104 | 2109 | """ |
|
2105 | 2110 | |
|
2106 | 2111 | opts = pycompat.byteskwargs(opts) |
|
2107 | 2112 | if not pats: |
|
2108 | 2113 | raise error.Abort(_('no files specified')) |
|
2109 | 2114 | |
|
2110 | 2115 | m = scmutil.match(repo[None], pats, opts) |
|
2111 | 2116 | rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] |
|
2112 | 2117 | return rejected and 1 or 0 |
|
2113 | 2118 | |
|
2114 | 2119 | @command( |
|
2115 | 2120 | 'graft', |
|
2116 | 2121 | [('r', 'rev', [], _('revisions to graft'), _('REV')), |
|
2117 | 2122 | ('c', 'continue', False, _('resume interrupted graft')), |
|
2118 | 2123 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
2119 | 2124 | ('', 'log', None, _('append graft info to log message')), |
|
2120 | 2125 | ('f', 'force', False, _('force graft')), |
|
2121 | 2126 | ('D', 'currentdate', False, |
|
2122 | 2127 | _('record the current date as commit date')), |
|
2123 | 2128 | ('U', 'currentuser', False, |
|
2124 | 2129 | _('record the current user as committer'), _('DATE'))] |
|
2125 | 2130 | + commitopts2 + mergetoolopts + dryrunopts, |
|
2126 | 2131 | _('[OPTION]... [-r REV]... REV...')) |
|
2127 | 2132 | def graft(ui, repo, *revs, **opts): |
|
2128 | 2133 | '''copy changes from other branches onto the current branch |
|
2129 | 2134 | |
|
2130 | 2135 | This command uses Mercurial's merge logic to copy individual |
|
2131 | 2136 | changes from other branches without merging branches in the |
|
2132 | 2137 | history graph. This is sometimes known as 'backporting' or |
|
2133 | 2138 | 'cherry-picking'. By default, graft will copy user, date, and |
|
2134 | 2139 | description from the source changesets. |
|
2135 | 2140 | |
|
2136 | 2141 | Changesets that are ancestors of the current revision, that have |
|
2137 | 2142 | already been grafted, or that are merges will be skipped. |
|
2138 | 2143 | |
|
2139 | 2144 | If --log is specified, log messages will have a comment appended |
|
2140 | 2145 | of the form:: |
|
2141 | 2146 | |
|
2142 | 2147 | (grafted from CHANGESETHASH) |
|
2143 | 2148 | |
|
2144 | 2149 | If --force is specified, revisions will be grafted even if they |
|
2145 | 2150 | are already ancestors of or have been grafted to the destination. |
|
2146 | 2151 | This is useful when the revisions have since been backed out. |
|
2147 | 2152 | |
|
2148 | 2153 | If a graft merge results in conflicts, the graft process is |
|
2149 | 2154 | interrupted so that the current merge can be manually resolved. |
|
2150 | 2155 | Once all conflicts are addressed, the graft process can be |
|
2151 | 2156 | continued with the -c/--continue option. |
|
2152 | 2157 | |
|
2153 | 2158 | .. note:: |
|
2154 | 2159 | |
|
2155 | 2160 | The -c/--continue option does not reapply earlier options, except |
|
2156 | 2161 | for --force. |
|
2157 | 2162 | |
|
2158 | 2163 | .. container:: verbose |
|
2159 | 2164 | |
|
2160 | 2165 | Examples: |
|
2161 | 2166 | |
|
2162 | 2167 | - copy a single change to the stable branch and edit its description:: |
|
2163 | 2168 | |
|
2164 | 2169 | hg update stable |
|
2165 | 2170 | hg graft --edit 9393 |
|
2166 | 2171 | |
|
2167 | 2172 | - graft a range of changesets with one exception, updating dates:: |
|
2168 | 2173 | |
|
2169 | 2174 | hg graft -D "2085::2093 and not 2091" |
|
2170 | 2175 | |
|
2171 | 2176 | - continue a graft after resolving conflicts:: |
|
2172 | 2177 | |
|
2173 | 2178 | hg graft -c |
|
2174 | 2179 | |
|
2175 | 2180 | - show the source of a grafted changeset:: |
|
2176 | 2181 | |
|
2177 | 2182 | hg log --debug -r . |
|
2178 | 2183 | |
|
2179 | 2184 | - show revisions sorted by date:: |
|
2180 | 2185 | |
|
2181 | 2186 | hg log -r "sort(all(), date)" |
|
2182 | 2187 | |
|
2183 | 2188 | See :hg:`help revisions` for more about specifying revisions. |
|
2184 | 2189 | |
|
2185 | 2190 | Returns 0 on successful completion. |
|
2186 | 2191 | ''' |
|
2187 | 2192 | with repo.wlock(): |
|
2188 | 2193 | return _dograft(ui, repo, *revs, **opts) |
|
2189 | 2194 | |
|
2190 | 2195 | def _dograft(ui, repo, *revs, **opts): |
|
2191 | 2196 | opts = pycompat.byteskwargs(opts) |
|
2192 | 2197 | if revs and opts.get('rev'): |
|
2193 | 2198 | ui.warn(_('warning: inconsistent use of --rev might give unexpected ' |
|
2194 | 2199 | 'revision ordering!\n')) |
|
2195 | 2200 | |
|
2196 | 2201 | revs = list(revs) |
|
2197 | 2202 | revs.extend(opts.get('rev')) |
|
2198 | 2203 | |
|
2199 | 2204 | if not opts.get('user') and opts.get('currentuser'): |
|
2200 | 2205 | opts['user'] = ui.username() |
|
2201 | 2206 | if not opts.get('date') and opts.get('currentdate'): |
|
2202 | 2207 | opts['date'] = "%d %d" % util.makedate() |
|
2203 | 2208 | |
|
2204 | 2209 | editor = cmdutil.getcommiteditor(editform='graft', |
|
2205 | 2210 | **pycompat.strkwargs(opts)) |
|
2206 | 2211 | |
|
2207 | 2212 | cont = False |
|
2208 | 2213 | if opts.get('continue'): |
|
2209 | 2214 | cont = True |
|
2210 | 2215 | if revs: |
|
2211 | 2216 | raise error.Abort(_("can't specify --continue and revisions")) |
|
2212 | 2217 | # read in unfinished revisions |
|
2213 | 2218 | try: |
|
2214 | 2219 | nodes = repo.vfs.read('graftstate').splitlines() |
|
2215 | 2220 | revs = [repo[node].rev() for node in nodes] |
|
2216 | 2221 | except IOError as inst: |
|
2217 | 2222 | if inst.errno != errno.ENOENT: |
|
2218 | 2223 | raise |
|
2219 | 2224 | cmdutil.wrongtooltocontinue(repo, _('graft')) |
|
2220 | 2225 | else: |
|
2221 | 2226 | cmdutil.checkunfinished(repo) |
|
2222 | 2227 | cmdutil.bailifchanged(repo) |
|
2223 | 2228 | if not revs: |
|
2224 | 2229 | raise error.Abort(_('no revisions specified')) |
|
2225 | 2230 | revs = scmutil.revrange(repo, revs) |
|
2226 | 2231 | |
|
2227 | 2232 | skipped = set() |
|
2228 | 2233 | # check for merges |
|
2229 | 2234 | for rev in repo.revs('%ld and merge()', revs): |
|
2230 | 2235 | ui.warn(_('skipping ungraftable merge revision %s\n') % rev) |
|
2231 | 2236 | skipped.add(rev) |
|
2232 | 2237 | revs = [r for r in revs if r not in skipped] |
|
2233 | 2238 | if not revs: |
|
2234 | 2239 | return -1 |
|
2235 | 2240 | |
|
2236 | 2241 | # Don't check in the --continue case, in effect retaining --force across |
|
2237 | 2242 | # --continues. That's because without --force, any revisions we decided to |
|
2238 | 2243 | # skip would have been filtered out here, so they wouldn't have made their |
|
2239 | 2244 | # way to the graftstate. With --force, any revisions we would have otherwise |
|
2240 | 2245 | # skipped would not have been filtered out, and if they hadn't been applied |
|
2241 | 2246 | # already, they'd have been in the graftstate. |
|
2242 | 2247 | if not (cont or opts.get('force')): |
|
2243 | 2248 | # check for ancestors of dest branch |
|
2244 | 2249 | crev = repo['.'].rev() |
|
2245 | 2250 | ancestors = repo.changelog.ancestors([crev], inclusive=True) |
|
2246 | 2251 | # XXX make this lazy in the future |
|
2247 | 2252 | # don't mutate while iterating, create a copy |
|
2248 | 2253 | for rev in list(revs): |
|
2249 | 2254 | if rev in ancestors: |
|
2250 | 2255 | ui.warn(_('skipping ancestor revision %d:%s\n') % |
|
2251 | 2256 | (rev, repo[rev])) |
|
2252 | 2257 | # XXX remove on list is slow |
|
2253 | 2258 | revs.remove(rev) |
|
2254 | 2259 | if not revs: |
|
2255 | 2260 | return -1 |
|
2256 | 2261 | |
|
2257 | 2262 | # analyze revs for earlier grafts |
|
2258 | 2263 | ids = {} |
|
2259 | 2264 | for ctx in repo.set("%ld", revs): |
|
2260 | 2265 | ids[ctx.hex()] = ctx.rev() |
|
2261 | 2266 | n = ctx.extra().get('source') |
|
2262 | 2267 | if n: |
|
2263 | 2268 | ids[n] = ctx.rev() |
|
2264 | 2269 | |
|
2265 | 2270 | # check ancestors for earlier grafts |
|
2266 | 2271 | ui.debug('scanning for duplicate grafts\n') |
|
2267 | 2272 | |
|
2268 | 2273 | # The only changesets we can be sure doesn't contain grafts of any |
|
2269 | 2274 | # revs, are the ones that are common ancestors of *all* revs: |
|
2270 | 2275 | for rev in repo.revs('only(%d,ancestor(%ld))', crev, revs): |
|
2271 | 2276 | ctx = repo[rev] |
|
2272 | 2277 | n = ctx.extra().get('source') |
|
2273 | 2278 | if n in ids: |
|
2274 | 2279 | try: |
|
2275 | 2280 | r = repo[n].rev() |
|
2276 | 2281 | except error.RepoLookupError: |
|
2277 | 2282 | r = None |
|
2278 | 2283 | if r in revs: |
|
2279 | 2284 | ui.warn(_('skipping revision %d:%s ' |
|
2280 | 2285 | '(already grafted to %d:%s)\n') |
|
2281 | 2286 | % (r, repo[r], rev, ctx)) |
|
2282 | 2287 | revs.remove(r) |
|
2283 | 2288 | elif ids[n] in revs: |
|
2284 | 2289 | if r is None: |
|
2285 | 2290 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2286 | 2291 | '(%d:%s also has unknown origin %s)\n') |
|
2287 | 2292 | % (ids[n], repo[ids[n]], rev, ctx, n[:12])) |
|
2288 | 2293 | else: |
|
2289 | 2294 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2290 | 2295 | '(%d:%s also has origin %d:%s)\n') |
|
2291 | 2296 | % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])) |
|
2292 | 2297 | revs.remove(ids[n]) |
|
2293 | 2298 | elif ctx.hex() in ids: |
|
2294 | 2299 | r = ids[ctx.hex()] |
|
2295 | 2300 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2296 | 2301 | '(was grafted from %d:%s)\n') % |
|
2297 | 2302 | (r, repo[r], rev, ctx)) |
|
2298 | 2303 | revs.remove(r) |
|
2299 | 2304 | if not revs: |
|
2300 | 2305 | return -1 |
|
2301 | 2306 | |
|
2302 | 2307 | for pos, ctx in enumerate(repo.set("%ld", revs)): |
|
2303 | 2308 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, |
|
2304 | 2309 | ctx.description().split('\n', 1)[0]) |
|
2305 | 2310 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
|
2306 | 2311 | if names: |
|
2307 | 2312 | desc += ' (%s)' % ' '.join(names) |
|
2308 | 2313 | ui.status(_('grafting %s\n') % desc) |
|
2309 | 2314 | if opts.get('dry_run'): |
|
2310 | 2315 | continue |
|
2311 | 2316 | |
|
2312 | 2317 | source = ctx.extra().get('source') |
|
2313 | 2318 | extra = {} |
|
2314 | 2319 | if source: |
|
2315 | 2320 | extra['source'] = source |
|
2316 | 2321 | extra['intermediate-source'] = ctx.hex() |
|
2317 | 2322 | else: |
|
2318 | 2323 | extra['source'] = ctx.hex() |
|
2319 | 2324 | user = ctx.user() |
|
2320 | 2325 | if opts.get('user'): |
|
2321 | 2326 | user = opts['user'] |
|
2322 | 2327 | date = ctx.date() |
|
2323 | 2328 | if opts.get('date'): |
|
2324 | 2329 | date = opts['date'] |
|
2325 | 2330 | message = ctx.description() |
|
2326 | 2331 | if opts.get('log'): |
|
2327 | 2332 | message += '\n(grafted from %s)' % ctx.hex() |
|
2328 | 2333 | |
|
2329 | 2334 | # we don't merge the first commit when continuing |
|
2330 | 2335 | if not cont: |
|
2331 | 2336 | # perform the graft merge with p1(rev) as 'ancestor' |
|
2332 | 2337 | try: |
|
2333 | 2338 | # ui.forcemerge is an internal variable, do not document |
|
2334 | 2339 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
2335 | 2340 | 'graft') |
|
2336 | 2341 | stats = mergemod.graft(repo, ctx, ctx.p1(), |
|
2337 | 2342 | ['local', 'graft']) |
|
2338 | 2343 | finally: |
|
2339 | 2344 | repo.ui.setconfig('ui', 'forcemerge', '', 'graft') |
|
2340 | 2345 | # report any conflicts |
|
2341 | 2346 | if stats and stats[3] > 0: |
|
2342 | 2347 | # write out state for --continue |
|
2343 | 2348 | nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] |
|
2344 | 2349 | repo.vfs.write('graftstate', ''.join(nodelines)) |
|
2345 | 2350 | extra = '' |
|
2346 | 2351 | if opts.get('user'): |
|
2347 | 2352 | extra += ' --user %s' % util.shellquote(opts['user']) |
|
2348 | 2353 | if opts.get('date'): |
|
2349 | 2354 | extra += ' --date %s' % util.shellquote(opts['date']) |
|
2350 | 2355 | if opts.get('log'): |
|
2351 | 2356 | extra += ' --log' |
|
2352 | 2357 | hint=_("use 'hg resolve' and 'hg graft --continue%s'") % extra |
|
2353 | 2358 | raise error.Abort( |
|
2354 | 2359 | _("unresolved conflicts, can't continue"), |
|
2355 | 2360 | hint=hint) |
|
2356 | 2361 | else: |
|
2357 | 2362 | cont = False |
|
2358 | 2363 | |
|
2359 | 2364 | # commit |
|
2360 | 2365 | node = repo.commit(text=message, user=user, |
|
2361 | 2366 | date=date, extra=extra, editor=editor) |
|
2362 | 2367 | if node is None: |
|
2363 | 2368 | ui.warn( |
|
2364 | 2369 | _('note: graft of %d:%s created no changes to commit\n') % |
|
2365 | 2370 | (ctx.rev(), ctx)) |
|
2366 | 2371 | |
|
2367 | 2372 | # remove state when we complete successfully |
|
2368 | 2373 | if not opts.get('dry_run'): |
|
2369 | 2374 | repo.vfs.unlinkpath('graftstate', ignoremissing=True) |
|
2370 | 2375 | |
|
2371 | 2376 | return 0 |
|
2372 | 2377 | |
|
2373 | 2378 | @command('grep', |
|
2374 | 2379 | [('0', 'print0', None, _('end fields with NUL')), |
|
2375 | 2380 | ('', 'all', None, _('print all revisions that match')), |
|
2376 | 2381 | ('a', 'text', None, _('treat all files as text')), |
|
2377 | 2382 | ('f', 'follow', None, |
|
2378 | 2383 | _('follow changeset history,' |
|
2379 | 2384 | ' or file history across copies and renames')), |
|
2380 | 2385 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2381 | 2386 | ('l', 'files-with-matches', None, |
|
2382 | 2387 | _('print only filenames and revisions that match')), |
|
2383 | 2388 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2384 | 2389 | ('r', 'rev', [], |
|
2385 | 2390 | _('only search files changed within revision range'), _('REV')), |
|
2386 | 2391 | ('u', 'user', None, _('list the author (long with -v)')), |
|
2387 | 2392 | ('d', 'date', None, _('list the date (short with -q)')), |
|
2388 | 2393 | ] + formatteropts + walkopts, |
|
2389 | 2394 | _('[OPTION]... PATTERN [FILE]...'), |
|
2390 | 2395 | inferrepo=True) |
|
2391 | 2396 | def grep(ui, repo, pattern, *pats, **opts): |
|
2392 | 2397 | """search revision history for a pattern in specified files |
|
2393 | 2398 | |
|
2394 | 2399 | Search revision history for a regular expression in the specified |
|
2395 | 2400 | files or the entire project. |
|
2396 | 2401 | |
|
2397 | 2402 | By default, grep prints the most recent revision number for each |
|
2398 | 2403 | file in which it finds a match. To get it to print every revision |
|
2399 | 2404 | that contains a change in match status ("-" for a match that becomes |
|
2400 | 2405 | a non-match, or "+" for a non-match that becomes a match), use the |
|
2401 | 2406 | --all flag. |
|
2402 | 2407 | |
|
2403 | 2408 | PATTERN can be any Python (roughly Perl-compatible) regular |
|
2404 | 2409 | expression. |
|
2405 | 2410 | |
|
2406 | 2411 | If no FILEs are specified (and -f/--follow isn't set), all files in |
|
2407 | 2412 | the repository are searched, including those that don't exist in the |
|
2408 | 2413 | current branch or have been deleted in a prior changeset. |
|
2409 | 2414 | |
|
2410 | 2415 | Returns 0 if a match is found, 1 otherwise. |
|
2411 | 2416 | """ |
|
2412 | 2417 | opts = pycompat.byteskwargs(opts) |
|
2413 | 2418 | reflags = re.M |
|
2414 | 2419 | if opts.get('ignore_case'): |
|
2415 | 2420 | reflags |= re.I |
|
2416 | 2421 | try: |
|
2417 | 2422 | regexp = util.re.compile(pattern, reflags) |
|
2418 | 2423 | except re.error as inst: |
|
2419 | 2424 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
2420 | 2425 | return 1 |
|
2421 | 2426 | sep, eol = ':', '\n' |
|
2422 | 2427 | if opts.get('print0'): |
|
2423 | 2428 | sep = eol = '\0' |
|
2424 | 2429 | |
|
2425 | 2430 | getfile = util.lrucachefunc(repo.file) |
|
2426 | 2431 | |
|
2427 | 2432 | def matchlines(body): |
|
2428 | 2433 | begin = 0 |
|
2429 | 2434 | linenum = 0 |
|
2430 | 2435 | while begin < len(body): |
|
2431 | 2436 | match = regexp.search(body, begin) |
|
2432 | 2437 | if not match: |
|
2433 | 2438 | break |
|
2434 | 2439 | mstart, mend = match.span() |
|
2435 | 2440 | linenum += body.count('\n', begin, mstart) + 1 |
|
2436 | 2441 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
2437 | 2442 | begin = body.find('\n', mend) + 1 or len(body) + 1 |
|
2438 | 2443 | lend = begin - 1 |
|
2439 | 2444 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
2440 | 2445 | |
|
2441 | 2446 | class linestate(object): |
|
2442 | 2447 | def __init__(self, line, linenum, colstart, colend): |
|
2443 | 2448 | self.line = line |
|
2444 | 2449 | self.linenum = linenum |
|
2445 | 2450 | self.colstart = colstart |
|
2446 | 2451 | self.colend = colend |
|
2447 | 2452 | |
|
2448 | 2453 | def __hash__(self): |
|
2449 | 2454 | return hash((self.linenum, self.line)) |
|
2450 | 2455 | |
|
2451 | 2456 | def __eq__(self, other): |
|
2452 | 2457 | return self.line == other.line |
|
2453 | 2458 | |
|
2454 | 2459 | def findpos(self): |
|
2455 | 2460 | """Iterate all (start, end) indices of matches""" |
|
2456 | 2461 | yield self.colstart, self.colend |
|
2457 | 2462 | p = self.colend |
|
2458 | 2463 | while p < len(self.line): |
|
2459 | 2464 | m = regexp.search(self.line, p) |
|
2460 | 2465 | if not m: |
|
2461 | 2466 | break |
|
2462 | 2467 | yield m.span() |
|
2463 | 2468 | p = m.end() |
|
2464 | 2469 | |
|
2465 | 2470 | matches = {} |
|
2466 | 2471 | copies = {} |
|
2467 | 2472 | def grepbody(fn, rev, body): |
|
2468 | 2473 | matches[rev].setdefault(fn, []) |
|
2469 | 2474 | m = matches[rev][fn] |
|
2470 | 2475 | for lnum, cstart, cend, line in matchlines(body): |
|
2471 | 2476 | s = linestate(line, lnum, cstart, cend) |
|
2472 | 2477 | m.append(s) |
|
2473 | 2478 | |
|
2474 | 2479 | def difflinestates(a, b): |
|
2475 | 2480 | sm = difflib.SequenceMatcher(None, a, b) |
|
2476 | 2481 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
2477 | 2482 | if tag == 'insert': |
|
2478 | 2483 | for i in xrange(blo, bhi): |
|
2479 | 2484 | yield ('+', b[i]) |
|
2480 | 2485 | elif tag == 'delete': |
|
2481 | 2486 | for i in xrange(alo, ahi): |
|
2482 | 2487 | yield ('-', a[i]) |
|
2483 | 2488 | elif tag == 'replace': |
|
2484 | 2489 | for i in xrange(alo, ahi): |
|
2485 | 2490 | yield ('-', a[i]) |
|
2486 | 2491 | for i in xrange(blo, bhi): |
|
2487 | 2492 | yield ('+', b[i]) |
|
2488 | 2493 | |
|
2489 | 2494 | def display(fm, fn, ctx, pstates, states): |
|
2490 | 2495 | rev = ctx.rev() |
|
2491 | 2496 | if fm.isplain(): |
|
2492 | 2497 | formatuser = ui.shortuser |
|
2493 | 2498 | else: |
|
2494 | 2499 | formatuser = str |
|
2495 | 2500 | if ui.quiet: |
|
2496 | 2501 | datefmt = '%Y-%m-%d' |
|
2497 | 2502 | else: |
|
2498 | 2503 | datefmt = '%a %b %d %H:%M:%S %Y %1%2' |
|
2499 | 2504 | found = False |
|
2500 | 2505 | @util.cachefunc |
|
2501 | 2506 | def binary(): |
|
2502 | 2507 | flog = getfile(fn) |
|
2503 | 2508 | return util.binary(flog.read(ctx.filenode(fn))) |
|
2504 | 2509 | |
|
2505 | 2510 | fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} |
|
2506 | 2511 | if opts.get('all'): |
|
2507 | 2512 | iter = difflinestates(pstates, states) |
|
2508 | 2513 | else: |
|
2509 | 2514 | iter = [('', l) for l in states] |
|
2510 | 2515 | for change, l in iter: |
|
2511 | 2516 | fm.startitem() |
|
2512 | 2517 | fm.data(node=fm.hexfunc(ctx.node())) |
|
2513 | 2518 | cols = [ |
|
2514 | 2519 | ('filename', fn, True), |
|
2515 | 2520 | ('rev', rev, True), |
|
2516 | 2521 | ('linenumber', l.linenum, opts.get('line_number')), |
|
2517 | 2522 | ] |
|
2518 | 2523 | if opts.get('all'): |
|
2519 | 2524 | cols.append(('change', change, True)) |
|
2520 | 2525 | cols.extend([ |
|
2521 | 2526 | ('user', formatuser(ctx.user()), opts.get('user')), |
|
2522 | 2527 | ('date', fm.formatdate(ctx.date(), datefmt), opts.get('date')), |
|
2523 | 2528 | ]) |
|
2524 | 2529 | lastcol = next(name for name, data, cond in reversed(cols) if cond) |
|
2525 | 2530 | for name, data, cond in cols: |
|
2526 | 2531 | field = fieldnamemap.get(name, name) |
|
2527 | 2532 | fm.condwrite(cond, field, '%s', data, label='grep.%s' % name) |
|
2528 | 2533 | if cond and name != lastcol: |
|
2529 | 2534 | fm.plain(sep, label='grep.sep') |
|
2530 | 2535 | if not opts.get('files_with_matches'): |
|
2531 | 2536 | fm.plain(sep, label='grep.sep') |
|
2532 | 2537 | if not opts.get('text') and binary(): |
|
2533 | 2538 | fm.plain(_(" Binary file matches")) |
|
2534 | 2539 | else: |
|
2535 | 2540 | displaymatches(fm.nested('texts'), l) |
|
2536 | 2541 | fm.plain(eol) |
|
2537 | 2542 | found = True |
|
2538 | 2543 | if opts.get('files_with_matches'): |
|
2539 | 2544 | break |
|
2540 | 2545 | return found |
|
2541 | 2546 | |
|
2542 | 2547 | def displaymatches(fm, l): |
|
2543 | 2548 | p = 0 |
|
2544 | 2549 | for s, e in l.findpos(): |
|
2545 | 2550 | if p < s: |
|
2546 | 2551 | fm.startitem() |
|
2547 | 2552 | fm.write('text', '%s', l.line[p:s]) |
|
2548 | 2553 | fm.data(matched=False) |
|
2549 | 2554 | fm.startitem() |
|
2550 | 2555 | fm.write('text', '%s', l.line[s:e], label='grep.match') |
|
2551 | 2556 | fm.data(matched=True) |
|
2552 | 2557 | p = e |
|
2553 | 2558 | if p < len(l.line): |
|
2554 | 2559 | fm.startitem() |
|
2555 | 2560 | fm.write('text', '%s', l.line[p:]) |
|
2556 | 2561 | fm.data(matched=False) |
|
2557 | 2562 | fm.end() |
|
2558 | 2563 | |
|
2559 | 2564 | skip = {} |
|
2560 | 2565 | revfiles = {} |
|
2561 | 2566 | matchfn = scmutil.match(repo[None], pats, opts) |
|
2562 | 2567 | found = False |
|
2563 | 2568 | follow = opts.get('follow') |
|
2564 | 2569 | |
|
2565 | 2570 | def prep(ctx, fns): |
|
2566 | 2571 | rev = ctx.rev() |
|
2567 | 2572 | pctx = ctx.p1() |
|
2568 | 2573 | parent = pctx.rev() |
|
2569 | 2574 | matches.setdefault(rev, {}) |
|
2570 | 2575 | matches.setdefault(parent, {}) |
|
2571 | 2576 | files = revfiles.setdefault(rev, []) |
|
2572 | 2577 | for fn in fns: |
|
2573 | 2578 | flog = getfile(fn) |
|
2574 | 2579 | try: |
|
2575 | 2580 | fnode = ctx.filenode(fn) |
|
2576 | 2581 | except error.LookupError: |
|
2577 | 2582 | continue |
|
2578 | 2583 | |
|
2579 | 2584 | copied = flog.renamed(fnode) |
|
2580 | 2585 | copy = follow and copied and copied[0] |
|
2581 | 2586 | if copy: |
|
2582 | 2587 | copies.setdefault(rev, {})[fn] = copy |
|
2583 | 2588 | if fn in skip: |
|
2584 | 2589 | if copy: |
|
2585 | 2590 | skip[copy] = True |
|
2586 | 2591 | continue |
|
2587 | 2592 | files.append(fn) |
|
2588 | 2593 | |
|
2589 | 2594 | if fn not in matches[rev]: |
|
2590 | 2595 | grepbody(fn, rev, flog.read(fnode)) |
|
2591 | 2596 | |
|
2592 | 2597 | pfn = copy or fn |
|
2593 | 2598 | if pfn not in matches[parent]: |
|
2594 | 2599 | try: |
|
2595 | 2600 | fnode = pctx.filenode(pfn) |
|
2596 | 2601 | grepbody(pfn, parent, flog.read(fnode)) |
|
2597 | 2602 | except error.LookupError: |
|
2598 | 2603 | pass |
|
2599 | 2604 | |
|
2600 | 2605 | ui.pager('grep') |
|
2601 | 2606 | fm = ui.formatter('grep', opts) |
|
2602 | 2607 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
2603 | 2608 | rev = ctx.rev() |
|
2604 | 2609 | parent = ctx.p1().rev() |
|
2605 | 2610 | for fn in sorted(revfiles.get(rev, [])): |
|
2606 | 2611 | states = matches[rev][fn] |
|
2607 | 2612 | copy = copies.get(rev, {}).get(fn) |
|
2608 | 2613 | if fn in skip: |
|
2609 | 2614 | if copy: |
|
2610 | 2615 | skip[copy] = True |
|
2611 | 2616 | continue |
|
2612 | 2617 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
2613 | 2618 | if pstates or states: |
|
2614 | 2619 | r = display(fm, fn, ctx, pstates, states) |
|
2615 | 2620 | found = found or r |
|
2616 | 2621 | if r and not opts.get('all'): |
|
2617 | 2622 | skip[fn] = True |
|
2618 | 2623 | if copy: |
|
2619 | 2624 | skip[copy] = True |
|
2620 | 2625 | del matches[rev] |
|
2621 | 2626 | del revfiles[rev] |
|
2622 | 2627 | fm.end() |
|
2623 | 2628 | |
|
2624 | 2629 | return not found |
|
2625 | 2630 | |
|
2626 | 2631 | @command('heads', |
|
2627 | 2632 | [('r', 'rev', '', |
|
2628 | 2633 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), |
|
2629 | 2634 | ('t', 'topo', False, _('show topological heads only')), |
|
2630 | 2635 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), |
|
2631 | 2636 | ('c', 'closed', False, _('show normal and closed branch heads')), |
|
2632 | 2637 | ] + templateopts, |
|
2633 | 2638 | _('[-ct] [-r STARTREV] [REV]...')) |
|
2634 | 2639 | def heads(ui, repo, *branchrevs, **opts): |
|
2635 | 2640 | """show branch heads |
|
2636 | 2641 | |
|
2637 | 2642 | With no arguments, show all open branch heads in the repository. |
|
2638 | 2643 | Branch heads are changesets that have no descendants on the |
|
2639 | 2644 | same branch. They are where development generally takes place and |
|
2640 | 2645 | are the usual targets for update and merge operations. |
|
2641 | 2646 | |
|
2642 | 2647 | If one or more REVs are given, only open branch heads on the |
|
2643 | 2648 | branches associated with the specified changesets are shown. This |
|
2644 | 2649 | means that you can use :hg:`heads .` to see the heads on the |
|
2645 | 2650 | currently checked-out branch. |
|
2646 | 2651 | |
|
2647 | 2652 | If -c/--closed is specified, also show branch heads marked closed |
|
2648 | 2653 | (see :hg:`commit --close-branch`). |
|
2649 | 2654 | |
|
2650 | 2655 | If STARTREV is specified, only those heads that are descendants of |
|
2651 | 2656 | STARTREV will be displayed. |
|
2652 | 2657 | |
|
2653 | 2658 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
2654 | 2659 | topological heads (changesets with no children) will be shown. |
|
2655 | 2660 | |
|
2656 | 2661 | Returns 0 if matching heads are found, 1 if not. |
|
2657 | 2662 | """ |
|
2658 | 2663 | |
|
2659 | 2664 | opts = pycompat.byteskwargs(opts) |
|
2660 | 2665 | start = None |
|
2661 | 2666 | if 'rev' in opts: |
|
2662 | 2667 | start = scmutil.revsingle(repo, opts['rev'], None).node() |
|
2663 | 2668 | |
|
2664 | 2669 | if opts.get('topo'): |
|
2665 | 2670 | heads = [repo[h] for h in repo.heads(start)] |
|
2666 | 2671 | else: |
|
2667 | 2672 | heads = [] |
|
2668 | 2673 | for branch in repo.branchmap(): |
|
2669 | 2674 | heads += repo.branchheads(branch, start, opts.get('closed')) |
|
2670 | 2675 | heads = [repo[h] for h in heads] |
|
2671 | 2676 | |
|
2672 | 2677 | if branchrevs: |
|
2673 | 2678 | branches = set(repo[br].branch() for br in branchrevs) |
|
2674 | 2679 | heads = [h for h in heads if h.branch() in branches] |
|
2675 | 2680 | |
|
2676 | 2681 | if opts.get('active') and branchrevs: |
|
2677 | 2682 | dagheads = repo.heads(start) |
|
2678 | 2683 | heads = [h for h in heads if h.node() in dagheads] |
|
2679 | 2684 | |
|
2680 | 2685 | if branchrevs: |
|
2681 | 2686 | haveheads = set(h.branch() for h in heads) |
|
2682 | 2687 | if branches - haveheads: |
|
2683 | 2688 | headless = ', '.join(b for b in branches - haveheads) |
|
2684 | 2689 | msg = _('no open branch heads found on branches %s') |
|
2685 | 2690 | if opts.get('rev'): |
|
2686 | 2691 | msg += _(' (started at %s)') % opts['rev'] |
|
2687 | 2692 | ui.warn((msg + '\n') % headless) |
|
2688 | 2693 | |
|
2689 | 2694 | if not heads: |
|
2690 | 2695 | return 1 |
|
2691 | 2696 | |
|
2692 | 2697 | ui.pager('heads') |
|
2693 | 2698 | heads = sorted(heads, key=lambda x: -x.rev()) |
|
2694 | 2699 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2695 | 2700 | for ctx in heads: |
|
2696 | 2701 | displayer.show(ctx) |
|
2697 | 2702 | displayer.close() |
|
2698 | 2703 | |
|
2699 | 2704 | @command('help', |
|
2700 | 2705 | [('e', 'extension', None, _('show only help for extensions')), |
|
2701 | 2706 | ('c', 'command', None, _('show only help for commands')), |
|
2702 | 2707 | ('k', 'keyword', None, _('show topics matching keyword')), |
|
2703 | 2708 | ('s', 'system', [], _('show help for specific platform(s)')), |
|
2704 | 2709 | ], |
|
2705 | 2710 | _('[-ecks] [TOPIC]'), |
|
2706 | 2711 | norepo=True) |
|
2707 | 2712 | def help_(ui, name=None, **opts): |
|
2708 | 2713 | """show help for a given topic or a help overview |
|
2709 | 2714 | |
|
2710 | 2715 | With no arguments, print a list of commands with short help messages. |
|
2711 | 2716 | |
|
2712 | 2717 | Given a topic, extension, or command name, print help for that |
|
2713 | 2718 | topic. |
|
2714 | 2719 | |
|
2715 | 2720 | Returns 0 if successful. |
|
2716 | 2721 | """ |
|
2717 | 2722 | |
|
2718 | 2723 | keep = opts.get(r'system') or [] |
|
2719 | 2724 | if len(keep) == 0: |
|
2720 | 2725 | if pycompat.sysplatform.startswith('win'): |
|
2721 | 2726 | keep.append('windows') |
|
2722 | 2727 | elif pycompat.sysplatform == 'OpenVMS': |
|
2723 | 2728 | keep.append('vms') |
|
2724 | 2729 | elif pycompat.sysplatform == 'plan9': |
|
2725 | 2730 | keep.append('plan9') |
|
2726 | 2731 | else: |
|
2727 | 2732 | keep.append('unix') |
|
2728 | 2733 | keep.append(pycompat.sysplatform.lower()) |
|
2729 | 2734 | if ui.verbose: |
|
2730 | 2735 | keep.append('verbose') |
|
2731 | 2736 | |
|
2732 | 2737 | formatted = help.formattedhelp(ui, name, keep=keep, **opts) |
|
2733 | 2738 | ui.pager('help') |
|
2734 | 2739 | ui.write(formatted) |
|
2735 | 2740 | |
|
2736 | 2741 | |
|
2737 | 2742 | @command('identify|id', |
|
2738 | 2743 | [('r', 'rev', '', |
|
2739 | 2744 | _('identify the specified revision'), _('REV')), |
|
2740 | 2745 | ('n', 'num', None, _('show local revision number')), |
|
2741 | 2746 | ('i', 'id', None, _('show global revision id')), |
|
2742 | 2747 | ('b', 'branch', None, _('show branch')), |
|
2743 | 2748 | ('t', 'tags', None, _('show tags')), |
|
2744 | 2749 | ('B', 'bookmarks', None, _('show bookmarks')), |
|
2745 | 2750 | ] + remoteopts, |
|
2746 | 2751 | _('[-nibtB] [-r REV] [SOURCE]'), |
|
2747 | 2752 | optionalrepo=True) |
|
2748 | 2753 | def identify(ui, repo, source=None, rev=None, |
|
2749 | 2754 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): |
|
2750 | 2755 | """identify the working directory or specified revision |
|
2751 | 2756 | |
|
2752 | 2757 | Print a summary identifying the repository state at REV using one or |
|
2753 | 2758 | two parent hash identifiers, followed by a "+" if the working |
|
2754 | 2759 | directory has uncommitted changes, the branch name (if not default), |
|
2755 | 2760 | a list of tags, and a list of bookmarks. |
|
2756 | 2761 | |
|
2757 | 2762 | When REV is not given, print a summary of the current state of the |
|
2758 | 2763 | repository. |
|
2759 | 2764 | |
|
2760 | 2765 | Specifying a path to a repository root or Mercurial bundle will |
|
2761 | 2766 | cause lookup to operate on that repository/bundle. |
|
2762 | 2767 | |
|
2763 | 2768 | .. container:: verbose |
|
2764 | 2769 | |
|
2765 | 2770 | Examples: |
|
2766 | 2771 | |
|
2767 | 2772 | - generate a build identifier for the working directory:: |
|
2768 | 2773 | |
|
2769 | 2774 | hg id --id > build-id.dat |
|
2770 | 2775 | |
|
2771 | 2776 | - find the revision corresponding to a tag:: |
|
2772 | 2777 | |
|
2773 | 2778 | hg id -n -r 1.3 |
|
2774 | 2779 | |
|
2775 | 2780 | - check the most recent revision of a remote repository:: |
|
2776 | 2781 | |
|
2777 | 2782 | hg id -r tip https://www.mercurial-scm.org/repo/hg/ |
|
2778 | 2783 | |
|
2779 | 2784 | See :hg:`log` for generating more information about specific revisions, |
|
2780 | 2785 | including full hash identifiers. |
|
2781 | 2786 | |
|
2782 | 2787 | Returns 0 if successful. |
|
2783 | 2788 | """ |
|
2784 | 2789 | |
|
2785 | 2790 | opts = pycompat.byteskwargs(opts) |
|
2786 | 2791 | if not repo and not source: |
|
2787 | 2792 | raise error.Abort(_("there is no Mercurial repository here " |
|
2788 | 2793 | "(.hg not found)")) |
|
2789 | 2794 | |
|
2790 | 2795 | if ui.debugflag: |
|
2791 | 2796 | hexfunc = hex |
|
2792 | 2797 | else: |
|
2793 | 2798 | hexfunc = short |
|
2794 | 2799 | default = not (num or id or branch or tags or bookmarks) |
|
2795 | 2800 | output = [] |
|
2796 | 2801 | revs = [] |
|
2797 | 2802 | |
|
2798 | 2803 | if source: |
|
2799 | 2804 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
2800 | 2805 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo |
|
2801 | 2806 | repo = peer.local() |
|
2802 | 2807 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) |
|
2803 | 2808 | |
|
2804 | 2809 | if not repo: |
|
2805 | 2810 | if num or branch or tags: |
|
2806 | 2811 | raise error.Abort( |
|
2807 | 2812 | _("can't query remote revision number, branch, or tags")) |
|
2808 | 2813 | if not rev and revs: |
|
2809 | 2814 | rev = revs[0] |
|
2810 | 2815 | if not rev: |
|
2811 | 2816 | rev = "tip" |
|
2812 | 2817 | |
|
2813 | 2818 | remoterev = peer.lookup(rev) |
|
2814 | 2819 | if default or id: |
|
2815 | 2820 | output = [hexfunc(remoterev)] |
|
2816 | 2821 | |
|
2817 | 2822 | def getbms(): |
|
2818 | 2823 | bms = [] |
|
2819 | 2824 | |
|
2820 | 2825 | if 'bookmarks' in peer.listkeys('namespaces'): |
|
2821 | 2826 | hexremoterev = hex(remoterev) |
|
2822 | 2827 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() |
|
2823 | 2828 | if bmr == hexremoterev] |
|
2824 | 2829 | |
|
2825 | 2830 | return sorted(bms) |
|
2826 | 2831 | |
|
2827 | 2832 | if bookmarks: |
|
2828 | 2833 | output.extend(getbms()) |
|
2829 | 2834 | elif default and not ui.quiet: |
|
2830 | 2835 | # multiple bookmarks for a single parent separated by '/' |
|
2831 | 2836 | bm = '/'.join(getbms()) |
|
2832 | 2837 | if bm: |
|
2833 | 2838 | output.append(bm) |
|
2834 | 2839 | else: |
|
2835 | 2840 | ctx = scmutil.revsingle(repo, rev, None) |
|
2836 | 2841 | |
|
2837 | 2842 | if ctx.rev() is None: |
|
2838 | 2843 | ctx = repo[None] |
|
2839 | 2844 | parents = ctx.parents() |
|
2840 | 2845 | taglist = [] |
|
2841 | 2846 | for p in parents: |
|
2842 | 2847 | taglist.extend(p.tags()) |
|
2843 | 2848 | |
|
2844 | 2849 | changed = "" |
|
2845 | 2850 | if default or id or num: |
|
2846 | 2851 | if (any(repo.status()) |
|
2847 | 2852 | or any(ctx.sub(s).dirty() for s in ctx.substate)): |
|
2848 | 2853 | changed = '+' |
|
2849 | 2854 | if default or id: |
|
2850 | 2855 | output = ["%s%s" % |
|
2851 | 2856 | ('+'.join([hexfunc(p.node()) for p in parents]), changed)] |
|
2852 | 2857 | if num: |
|
2853 | 2858 | output.append("%s%s" % |
|
2854 | 2859 | ('+'.join([str(p.rev()) for p in parents]), changed)) |
|
2855 | 2860 | else: |
|
2856 | 2861 | if default or id: |
|
2857 | 2862 | output = [hexfunc(ctx.node())] |
|
2858 | 2863 | if num: |
|
2859 | 2864 | output.append(str(ctx.rev())) |
|
2860 | 2865 | taglist = ctx.tags() |
|
2861 | 2866 | |
|
2862 | 2867 | if default and not ui.quiet: |
|
2863 | 2868 | b = ctx.branch() |
|
2864 | 2869 | if b != 'default': |
|
2865 | 2870 | output.append("(%s)" % b) |
|
2866 | 2871 | |
|
2867 | 2872 | # multiple tags for a single parent separated by '/' |
|
2868 | 2873 | t = '/'.join(taglist) |
|
2869 | 2874 | if t: |
|
2870 | 2875 | output.append(t) |
|
2871 | 2876 | |
|
2872 | 2877 | # multiple bookmarks for a single parent separated by '/' |
|
2873 | 2878 | bm = '/'.join(ctx.bookmarks()) |
|
2874 | 2879 | if bm: |
|
2875 | 2880 | output.append(bm) |
|
2876 | 2881 | else: |
|
2877 | 2882 | if branch: |
|
2878 | 2883 | output.append(ctx.branch()) |
|
2879 | 2884 | |
|
2880 | 2885 | if tags: |
|
2881 | 2886 | output.extend(taglist) |
|
2882 | 2887 | |
|
2883 | 2888 | if bookmarks: |
|
2884 | 2889 | output.extend(ctx.bookmarks()) |
|
2885 | 2890 | |
|
2886 | 2891 | ui.write("%s\n" % ' '.join(output)) |
|
2887 | 2892 | |
|
2888 | 2893 | @command('import|patch', |
|
2889 | 2894 | [('p', 'strip', 1, |
|
2890 | 2895 | _('directory strip option for patch. This has the same ' |
|
2891 | 2896 | 'meaning as the corresponding patch option'), _('NUM')), |
|
2892 | 2897 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), |
|
2893 | 2898 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
2894 | 2899 | ('f', 'force', None, |
|
2895 | 2900 | _('skip check for outstanding uncommitted changes (DEPRECATED)')), |
|
2896 | 2901 | ('', 'no-commit', None, |
|
2897 | 2902 | _("don't commit, just update the working directory")), |
|
2898 | 2903 | ('', 'bypass', None, |
|
2899 | 2904 | _("apply patch without touching the working directory")), |
|
2900 | 2905 | ('', 'partial', None, |
|
2901 | 2906 | _('commit even if some hunks fail')), |
|
2902 | 2907 | ('', 'exact', None, |
|
2903 | 2908 | _('abort if patch would apply lossily')), |
|
2904 | 2909 | ('', 'prefix', '', |
|
2905 | 2910 | _('apply patch to subdirectory'), _('DIR')), |
|
2906 | 2911 | ('', 'import-branch', None, |
|
2907 | 2912 | _('use any branch information in patch (implied by --exact)'))] + |
|
2908 | 2913 | commitopts + commitopts2 + similarityopts, |
|
2909 | 2914 | _('[OPTION]... PATCH...')) |
|
2910 | 2915 | def import_(ui, repo, patch1=None, *patches, **opts): |
|
2911 | 2916 | """import an ordered set of patches |
|
2912 | 2917 | |
|
2913 | 2918 | Import a list of patches and commit them individually (unless |
|
2914 | 2919 | --no-commit is specified). |
|
2915 | 2920 | |
|
2916 | 2921 | To read a patch from standard input (stdin), use "-" as the patch |
|
2917 | 2922 | name. If a URL is specified, the patch will be downloaded from |
|
2918 | 2923 | there. |
|
2919 | 2924 | |
|
2920 | 2925 | Import first applies changes to the working directory (unless |
|
2921 | 2926 | --bypass is specified), import will abort if there are outstanding |
|
2922 | 2927 | changes. |
|
2923 | 2928 | |
|
2924 | 2929 | Use --bypass to apply and commit patches directly to the |
|
2925 | 2930 | repository, without affecting the working directory. Without |
|
2926 | 2931 | --exact, patches will be applied on top of the working directory |
|
2927 | 2932 | parent revision. |
|
2928 | 2933 | |
|
2929 | 2934 | You can import a patch straight from a mail message. Even patches |
|
2930 | 2935 | as attachments work (to use the body part, it must have type |
|
2931 | 2936 | text/plain or text/x-patch). From and Subject headers of email |
|
2932 | 2937 | message are used as default committer and commit message. All |
|
2933 | 2938 | text/plain body parts before first diff are added to the commit |
|
2934 | 2939 | message. |
|
2935 | 2940 | |
|
2936 | 2941 | If the imported patch was generated by :hg:`export`, user and |
|
2937 | 2942 | description from patch override values from message headers and |
|
2938 | 2943 | body. Values given on command line with -m/--message and -u/--user |
|
2939 | 2944 | override these. |
|
2940 | 2945 | |
|
2941 | 2946 | If --exact is specified, import will set the working directory to |
|
2942 | 2947 | the parent of each patch before applying it, and will abort if the |
|
2943 | 2948 | resulting changeset has a different ID than the one recorded in |
|
2944 | 2949 | the patch. This will guard against various ways that portable |
|
2945 | 2950 | patch formats and mail systems might fail to transfer Mercurial |
|
2946 | 2951 | data or metadata. See :hg:`bundle` for lossless transmission. |
|
2947 | 2952 | |
|
2948 | 2953 | Use --partial to ensure a changeset will be created from the patch |
|
2949 | 2954 | even if some hunks fail to apply. Hunks that fail to apply will be |
|
2950 | 2955 | written to a <target-file>.rej file. Conflicts can then be resolved |
|
2951 | 2956 | by hand before :hg:`commit --amend` is run to update the created |
|
2952 | 2957 | changeset. This flag exists to let people import patches that |
|
2953 | 2958 | partially apply without losing the associated metadata (author, |
|
2954 | 2959 | date, description, ...). |
|
2955 | 2960 | |
|
2956 | 2961 | .. note:: |
|
2957 | 2962 | |
|
2958 | 2963 | When no hunks apply cleanly, :hg:`import --partial` will create |
|
2959 | 2964 | an empty changeset, importing only the patch metadata. |
|
2960 | 2965 | |
|
2961 | 2966 | With -s/--similarity, hg will attempt to discover renames and |
|
2962 | 2967 | copies in the patch in the same way as :hg:`addremove`. |
|
2963 | 2968 | |
|
2964 | 2969 | It is possible to use external patch programs to perform the patch |
|
2965 | 2970 | by setting the ``ui.patch`` configuration option. For the default |
|
2966 | 2971 | internal tool, the fuzz can also be configured via ``patch.fuzz``. |
|
2967 | 2972 | See :hg:`help config` for more information about configuration |
|
2968 | 2973 | files and how to use these options. |
|
2969 | 2974 | |
|
2970 | 2975 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
2971 | 2976 | |
|
2972 | 2977 | .. container:: verbose |
|
2973 | 2978 | |
|
2974 | 2979 | Examples: |
|
2975 | 2980 | |
|
2976 | 2981 | - import a traditional patch from a website and detect renames:: |
|
2977 | 2982 | |
|
2978 | 2983 | hg import -s 80 http://example.com/bugfix.patch |
|
2979 | 2984 | |
|
2980 | 2985 | - import a changeset from an hgweb server:: |
|
2981 | 2986 | |
|
2982 | 2987 | hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa |
|
2983 | 2988 | |
|
2984 | 2989 | - import all the patches in an Unix-style mbox:: |
|
2985 | 2990 | |
|
2986 | 2991 | hg import incoming-patches.mbox |
|
2987 | 2992 | |
|
2988 | 2993 | - import patches from stdin:: |
|
2989 | 2994 | |
|
2990 | 2995 | hg import - |
|
2991 | 2996 | |
|
2992 | 2997 | - attempt to exactly restore an exported changeset (not always |
|
2993 | 2998 | possible):: |
|
2994 | 2999 | |
|
2995 | 3000 | hg import --exact proposed-fix.patch |
|
2996 | 3001 | |
|
2997 | 3002 | - use an external tool to apply a patch which is too fuzzy for |
|
2998 | 3003 | the default internal tool. |
|
2999 | 3004 | |
|
3000 | 3005 | hg import --config ui.patch="patch --merge" fuzzy.patch |
|
3001 | 3006 | |
|
3002 | 3007 | - change the default fuzzing from 2 to a less strict 7 |
|
3003 | 3008 | |
|
3004 | 3009 | hg import --config ui.fuzz=7 fuzz.patch |
|
3005 | 3010 | |
|
3006 | 3011 | Returns 0 on success, 1 on partial success (see --partial). |
|
3007 | 3012 | """ |
|
3008 | 3013 | |
|
3009 | 3014 | opts = pycompat.byteskwargs(opts) |
|
3010 | 3015 | if not patch1: |
|
3011 | 3016 | raise error.Abort(_('need at least one patch to import')) |
|
3012 | 3017 | |
|
3013 | 3018 | patches = (patch1,) + patches |
|
3014 | 3019 | |
|
3015 | 3020 | date = opts.get('date') |
|
3016 | 3021 | if date: |
|
3017 | 3022 | opts['date'] = util.parsedate(date) |
|
3018 | 3023 | |
|
3019 | 3024 | exact = opts.get('exact') |
|
3020 | 3025 | update = not opts.get('bypass') |
|
3021 | 3026 | if not update and opts.get('no_commit'): |
|
3022 | 3027 | raise error.Abort(_('cannot use --no-commit with --bypass')) |
|
3023 | 3028 | try: |
|
3024 | 3029 | sim = float(opts.get('similarity') or 0) |
|
3025 | 3030 | except ValueError: |
|
3026 | 3031 | raise error.Abort(_('similarity must be a number')) |
|
3027 | 3032 | if sim < 0 or sim > 100: |
|
3028 | 3033 | raise error.Abort(_('similarity must be between 0 and 100')) |
|
3029 | 3034 | if sim and not update: |
|
3030 | 3035 | raise error.Abort(_('cannot use --similarity with --bypass')) |
|
3031 | 3036 | if exact: |
|
3032 | 3037 | if opts.get('edit'): |
|
3033 | 3038 | raise error.Abort(_('cannot use --exact with --edit')) |
|
3034 | 3039 | if opts.get('prefix'): |
|
3035 | 3040 | raise error.Abort(_('cannot use --exact with --prefix')) |
|
3036 | 3041 | |
|
3037 | 3042 | base = opts["base"] |
|
3038 | 3043 | wlock = dsguard = lock = tr = None |
|
3039 | 3044 | msgs = [] |
|
3040 | 3045 | ret = 0 |
|
3041 | 3046 | |
|
3042 | 3047 | |
|
3043 | 3048 | try: |
|
3044 | 3049 | wlock = repo.wlock() |
|
3045 | 3050 | |
|
3046 | 3051 | if update: |
|
3047 | 3052 | cmdutil.checkunfinished(repo) |
|
3048 | 3053 | if (exact or not opts.get('force')): |
|
3049 | 3054 | cmdutil.bailifchanged(repo) |
|
3050 | 3055 | |
|
3051 | 3056 | if not opts.get('no_commit'): |
|
3052 | 3057 | lock = repo.lock() |
|
3053 | 3058 | tr = repo.transaction('import') |
|
3054 | 3059 | else: |
|
3055 | 3060 | dsguard = dirstateguard.dirstateguard(repo, 'import') |
|
3056 | 3061 | parents = repo[None].parents() |
|
3057 | 3062 | for patchurl in patches: |
|
3058 | 3063 | if patchurl == '-': |
|
3059 | 3064 | ui.status(_('applying patch from stdin\n')) |
|
3060 | 3065 | patchfile = ui.fin |
|
3061 | 3066 | patchurl = 'stdin' # for error message |
|
3062 | 3067 | else: |
|
3063 | 3068 | patchurl = os.path.join(base, patchurl) |
|
3064 | 3069 | ui.status(_('applying %s\n') % patchurl) |
|
3065 | 3070 | patchfile = hg.openpath(ui, patchurl) |
|
3066 | 3071 | |
|
3067 | 3072 | haspatch = False |
|
3068 | 3073 | for hunk in patch.split(patchfile): |
|
3069 | 3074 | (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, |
|
3070 | 3075 | parents, opts, |
|
3071 | 3076 | msgs, hg.clean) |
|
3072 | 3077 | if msg: |
|
3073 | 3078 | haspatch = True |
|
3074 | 3079 | ui.note(msg + '\n') |
|
3075 | 3080 | if update or exact: |
|
3076 | 3081 | parents = repo[None].parents() |
|
3077 | 3082 | else: |
|
3078 | 3083 | parents = [repo[node]] |
|
3079 | 3084 | if rej: |
|
3080 | 3085 | ui.write_err(_("patch applied partially\n")) |
|
3081 | 3086 | ui.write_err(_("(fix the .rej files and run " |
|
3082 | 3087 | "`hg commit --amend`)\n")) |
|
3083 | 3088 | ret = 1 |
|
3084 | 3089 | break |
|
3085 | 3090 | |
|
3086 | 3091 | if not haspatch: |
|
3087 | 3092 | raise error.Abort(_('%s: no diffs found') % patchurl) |
|
3088 | 3093 | |
|
3089 | 3094 | if tr: |
|
3090 | 3095 | tr.close() |
|
3091 | 3096 | if msgs: |
|
3092 | 3097 | repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
3093 | 3098 | if dsguard: |
|
3094 | 3099 | dsguard.close() |
|
3095 | 3100 | return ret |
|
3096 | 3101 | finally: |
|
3097 | 3102 | if tr: |
|
3098 | 3103 | tr.release() |
|
3099 | 3104 | release(lock, dsguard, wlock) |
|
3100 | 3105 | |
|
3101 | 3106 | @command('incoming|in', |
|
3102 | 3107 | [('f', 'force', None, |
|
3103 | 3108 | _('run even if remote repository is unrelated')), |
|
3104 | 3109 | ('n', 'newest-first', None, _('show newest record first')), |
|
3105 | 3110 | ('', 'bundle', '', |
|
3106 | 3111 | _('file to store the bundles into'), _('FILE')), |
|
3107 | 3112 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3108 | 3113 | ('B', 'bookmarks', False, _("compare bookmarks")), |
|
3109 | 3114 | ('b', 'branch', [], |
|
3110 | 3115 | _('a specific branch you would like to pull'), _('BRANCH')), |
|
3111 | 3116 | ] + logopts + remoteopts + subrepoopts, |
|
3112 | 3117 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) |
|
3113 | 3118 | def incoming(ui, repo, source="default", **opts): |
|
3114 | 3119 | """show new changesets found in source |
|
3115 | 3120 | |
|
3116 | 3121 | Show new changesets found in the specified path/URL or the default |
|
3117 | 3122 | pull location. These are the changesets that would have been pulled |
|
3118 | 3123 | if a pull at the time you issued this command. |
|
3119 | 3124 | |
|
3120 | 3125 | See pull for valid source format details. |
|
3121 | 3126 | |
|
3122 | 3127 | .. container:: verbose |
|
3123 | 3128 | |
|
3124 | 3129 | With -B/--bookmarks, the result of bookmark comparison between |
|
3125 | 3130 | local and remote repositories is displayed. With -v/--verbose, |
|
3126 | 3131 | status is also displayed for each bookmark like below:: |
|
3127 | 3132 | |
|
3128 | 3133 | BM1 01234567890a added |
|
3129 | 3134 | BM2 1234567890ab advanced |
|
3130 | 3135 | BM3 234567890abc diverged |
|
3131 | 3136 | BM4 34567890abcd changed |
|
3132 | 3137 | |
|
3133 | 3138 | The action taken locally when pulling depends on the |
|
3134 | 3139 | status of each bookmark: |
|
3135 | 3140 | |
|
3136 | 3141 | :``added``: pull will create it |
|
3137 | 3142 | :``advanced``: pull will update it |
|
3138 | 3143 | :``diverged``: pull will create a divergent bookmark |
|
3139 | 3144 | :``changed``: result depends on remote changesets |
|
3140 | 3145 | |
|
3141 | 3146 | From the point of view of pulling behavior, bookmark |
|
3142 | 3147 | existing only in the remote repository are treated as ``added``, |
|
3143 | 3148 | even if it is in fact locally deleted. |
|
3144 | 3149 | |
|
3145 | 3150 | .. container:: verbose |
|
3146 | 3151 | |
|
3147 | 3152 | For remote repository, using --bundle avoids downloading the |
|
3148 | 3153 | changesets twice if the incoming is followed by a pull. |
|
3149 | 3154 | |
|
3150 | 3155 | Examples: |
|
3151 | 3156 | |
|
3152 | 3157 | - show incoming changes with patches and full description:: |
|
3153 | 3158 | |
|
3154 | 3159 | hg incoming -vp |
|
3155 | 3160 | |
|
3156 | 3161 | - show incoming changes excluding merges, store a bundle:: |
|
3157 | 3162 | |
|
3158 | 3163 | hg in -vpM --bundle incoming.hg |
|
3159 | 3164 | hg pull incoming.hg |
|
3160 | 3165 | |
|
3161 | 3166 | - briefly list changes inside a bundle:: |
|
3162 | 3167 | |
|
3163 | 3168 | hg in changes.hg -T "{desc|firstline}\\n" |
|
3164 | 3169 | |
|
3165 | 3170 | Returns 0 if there are incoming changes, 1 otherwise. |
|
3166 | 3171 | """ |
|
3167 | 3172 | opts = pycompat.byteskwargs(opts) |
|
3168 | 3173 | if opts.get('graph'): |
|
3169 | 3174 | cmdutil.checkunsupportedgraphflags([], opts) |
|
3170 | 3175 | def display(other, chlist, displayer): |
|
3171 | 3176 | revdag = cmdutil.graphrevs(other, chlist, opts) |
|
3172 | 3177 | cmdutil.displaygraph(ui, repo, revdag, displayer, |
|
3173 | 3178 | graphmod.asciiedges) |
|
3174 | 3179 | |
|
3175 | 3180 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) |
|
3176 | 3181 | return 0 |
|
3177 | 3182 | |
|
3178 | 3183 | if opts.get('bundle') and opts.get('subrepos'): |
|
3179 | 3184 | raise error.Abort(_('cannot combine --bundle and --subrepos')) |
|
3180 | 3185 | |
|
3181 | 3186 | if opts.get('bookmarks'): |
|
3182 | 3187 | source, branches = hg.parseurl(ui.expandpath(source), |
|
3183 | 3188 | opts.get('branch')) |
|
3184 | 3189 | other = hg.peer(repo, opts, source) |
|
3185 | 3190 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3186 | 3191 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3187 | 3192 | return 0 |
|
3188 | 3193 | ui.pager('incoming') |
|
3189 | 3194 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
3190 | 3195 | return bookmarks.incoming(ui, repo, other) |
|
3191 | 3196 | |
|
3192 | 3197 | repo._subtoppath = ui.expandpath(source) |
|
3193 | 3198 | try: |
|
3194 | 3199 | return hg.incoming(ui, repo, source, opts) |
|
3195 | 3200 | finally: |
|
3196 | 3201 | del repo._subtoppath |
|
3197 | 3202 | |
|
3198 | 3203 | |
|
3199 | 3204 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), |
|
3200 | 3205 | norepo=True) |
|
3201 | 3206 | def init(ui, dest=".", **opts): |
|
3202 | 3207 | """create a new repository in the given directory |
|
3203 | 3208 | |
|
3204 | 3209 | Initialize a new repository in the given directory. If the given |
|
3205 | 3210 | directory does not exist, it will be created. |
|
3206 | 3211 | |
|
3207 | 3212 | If no directory is given, the current directory is used. |
|
3208 | 3213 | |
|
3209 | 3214 | It is possible to specify an ``ssh://`` URL as the destination. |
|
3210 | 3215 | See :hg:`help urls` for more information. |
|
3211 | 3216 | |
|
3212 | 3217 | Returns 0 on success. |
|
3213 | 3218 | """ |
|
3214 | 3219 | opts = pycompat.byteskwargs(opts) |
|
3215 | 3220 | hg.peer(ui, opts, ui.expandpath(dest), create=True) |
|
3216 | 3221 | |
|
3217 | 3222 | @command('locate', |
|
3218 | 3223 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
3219 | 3224 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
3220 | 3225 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), |
|
3221 | 3226 | ] + walkopts, |
|
3222 | 3227 | _('[OPTION]... [PATTERN]...')) |
|
3223 | 3228 | def locate(ui, repo, *pats, **opts): |
|
3224 | 3229 | """locate files matching specific patterns (DEPRECATED) |
|
3225 | 3230 | |
|
3226 | 3231 | Print files under Mercurial control in the working directory whose |
|
3227 | 3232 | names match the given patterns. |
|
3228 | 3233 | |
|
3229 | 3234 | By default, this command searches all directories in the working |
|
3230 | 3235 | directory. To search just the current directory and its |
|
3231 | 3236 | subdirectories, use "--include .". |
|
3232 | 3237 | |
|
3233 | 3238 | If no patterns are given to match, this command prints the names |
|
3234 | 3239 | of all files under Mercurial control in the working directory. |
|
3235 | 3240 | |
|
3236 | 3241 | If you want to feed the output of this command into the "xargs" |
|
3237 | 3242 | command, use the -0 option to both this command and "xargs". This |
|
3238 | 3243 | will avoid the problem of "xargs" treating single filenames that |
|
3239 | 3244 | contain whitespace as multiple filenames. |
|
3240 | 3245 | |
|
3241 | 3246 | See :hg:`help files` for a more versatile command. |
|
3242 | 3247 | |
|
3243 | 3248 | Returns 0 if a match is found, 1 otherwise. |
|
3244 | 3249 | """ |
|
3245 | 3250 | opts = pycompat.byteskwargs(opts) |
|
3246 | 3251 | if opts.get('print0'): |
|
3247 | 3252 | end = '\0' |
|
3248 | 3253 | else: |
|
3249 | 3254 | end = '\n' |
|
3250 | 3255 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() |
|
3251 | 3256 | |
|
3252 | 3257 | ret = 1 |
|
3253 | 3258 | ctx = repo[rev] |
|
3254 | 3259 | m = scmutil.match(ctx, pats, opts, default='relglob', |
|
3255 | 3260 | badfn=lambda x, y: False) |
|
3256 | 3261 | |
|
3257 | 3262 | ui.pager('locate') |
|
3258 | 3263 | for abs in ctx.matches(m): |
|
3259 | 3264 | if opts.get('fullpath'): |
|
3260 | 3265 | ui.write(repo.wjoin(abs), end) |
|
3261 | 3266 | else: |
|
3262 | 3267 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
3263 | 3268 | ret = 0 |
|
3264 | 3269 | |
|
3265 | 3270 | return ret |
|
3266 | 3271 | |
|
3267 | 3272 | @command('^log|history', |
|
3268 | 3273 | [('f', 'follow', None, |
|
3269 | 3274 | _('follow changeset history, or file history across copies and renames')), |
|
3270 | 3275 | ('', 'follow-first', None, |
|
3271 | 3276 | _('only follow the first parent of merge changesets (DEPRECATED)')), |
|
3272 | 3277 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), |
|
3273 | 3278 | ('C', 'copies', None, _('show copied files')), |
|
3274 | 3279 | ('k', 'keyword', [], |
|
3275 | 3280 | _('do case-insensitive search for a given text'), _('TEXT')), |
|
3276 | 3281 | ('r', 'rev', [], _('show the specified revision or revset'), _('REV')), |
|
3277 | 3282 | ('', 'removed', None, _('include revisions where files were removed')), |
|
3278 | 3283 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), |
|
3279 | 3284 | ('u', 'user', [], _('revisions committed by user'), _('USER')), |
|
3280 | 3285 | ('', 'only-branch', [], |
|
3281 | 3286 | _('show only changesets within the given named branch (DEPRECATED)'), |
|
3282 | 3287 | _('BRANCH')), |
|
3283 | 3288 | ('b', 'branch', [], |
|
3284 | 3289 | _('show changesets within the given named branch'), _('BRANCH')), |
|
3285 | 3290 | ('P', 'prune', [], |
|
3286 | 3291 | _('do not display revision or any of its ancestors'), _('REV')), |
|
3287 | 3292 | ] + logopts + walkopts, |
|
3288 | 3293 | _('[OPTION]... [FILE]'), |
|
3289 | 3294 | inferrepo=True) |
|
3290 | 3295 | def log(ui, repo, *pats, **opts): |
|
3291 | 3296 | """show revision history of entire repository or files |
|
3292 | 3297 | |
|
3293 | 3298 | Print the revision history of the specified files or the entire |
|
3294 | 3299 | project. |
|
3295 | 3300 | |
|
3296 | 3301 | If no revision range is specified, the default is ``tip:0`` unless |
|
3297 | 3302 | --follow is set, in which case the working directory parent is |
|
3298 | 3303 | used as the starting revision. |
|
3299 | 3304 | |
|
3300 | 3305 | File history is shown without following rename or copy history of |
|
3301 | 3306 | files. Use -f/--follow with a filename to follow history across |
|
3302 | 3307 | renames and copies. --follow without a filename will only show |
|
3303 | 3308 | ancestors or descendants of the starting revision. |
|
3304 | 3309 | |
|
3305 | 3310 | By default this command prints revision number and changeset id, |
|
3306 | 3311 | tags, non-trivial parents, user, date and time, and a summary for |
|
3307 | 3312 | each commit. When the -v/--verbose switch is used, the list of |
|
3308 | 3313 | changed files and full commit message are shown. |
|
3309 | 3314 | |
|
3310 | 3315 | With --graph the revisions are shown as an ASCII art DAG with the most |
|
3311 | 3316 | recent changeset at the top. |
|
3312 | 3317 | 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete, |
|
3313 | 3318 | and '+' represents a fork where the changeset from the lines below is a |
|
3314 | 3319 | parent of the 'o' merge on the same line. |
|
3315 | 3320 | Paths in the DAG are represented with '|', '/' and so forth. ':' in place |
|
3316 | 3321 | of a '|' indicates one or more revisions in a path are omitted. |
|
3317 | 3322 | |
|
3318 | 3323 | .. note:: |
|
3319 | 3324 | |
|
3320 | 3325 | :hg:`log --patch` may generate unexpected diff output for merge |
|
3321 | 3326 | changesets, as it will only compare the merge changeset against |
|
3322 | 3327 | its first parent. Also, only files different from BOTH parents |
|
3323 | 3328 | will appear in files:. |
|
3324 | 3329 | |
|
3325 | 3330 | .. note:: |
|
3326 | 3331 | |
|
3327 | 3332 | For performance reasons, :hg:`log FILE` may omit duplicate changes |
|
3328 | 3333 | made on branches and will not show removals or mode changes. To |
|
3329 | 3334 | see all such changes, use the --removed switch. |
|
3330 | 3335 | |
|
3331 | 3336 | .. container:: verbose |
|
3332 | 3337 | |
|
3333 | 3338 | Some examples: |
|
3334 | 3339 | |
|
3335 | 3340 | - changesets with full descriptions and file lists:: |
|
3336 | 3341 | |
|
3337 | 3342 | hg log -v |
|
3338 | 3343 | |
|
3339 | 3344 | - changesets ancestral to the working directory:: |
|
3340 | 3345 | |
|
3341 | 3346 | hg log -f |
|
3342 | 3347 | |
|
3343 | 3348 | - last 10 commits on the current branch:: |
|
3344 | 3349 | |
|
3345 | 3350 | hg log -l 10 -b . |
|
3346 | 3351 | |
|
3347 | 3352 | - changesets showing all modifications of a file, including removals:: |
|
3348 | 3353 | |
|
3349 | 3354 | hg log --removed file.c |
|
3350 | 3355 | |
|
3351 | 3356 | - all changesets that touch a directory, with diffs, excluding merges:: |
|
3352 | 3357 | |
|
3353 | 3358 | hg log -Mp lib/ |
|
3354 | 3359 | |
|
3355 | 3360 | - all revision numbers that match a keyword:: |
|
3356 | 3361 | |
|
3357 | 3362 | hg log -k bug --template "{rev}\\n" |
|
3358 | 3363 | |
|
3359 | 3364 | - the full hash identifier of the working directory parent:: |
|
3360 | 3365 | |
|
3361 | 3366 | hg log -r . --template "{node}\\n" |
|
3362 | 3367 | |
|
3363 | 3368 | - list available log templates:: |
|
3364 | 3369 | |
|
3365 | 3370 | hg log -T list |
|
3366 | 3371 | |
|
3367 | 3372 | - check if a given changeset is included in a tagged release:: |
|
3368 | 3373 | |
|
3369 | 3374 | hg log -r "a21ccf and ancestor(1.9)" |
|
3370 | 3375 | |
|
3371 | 3376 | - find all changesets by some user in a date range:: |
|
3372 | 3377 | |
|
3373 | 3378 | hg log -k alice -d "may 2008 to jul 2008" |
|
3374 | 3379 | |
|
3375 | 3380 | - summary of all changesets after the last tag:: |
|
3376 | 3381 | |
|
3377 | 3382 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" |
|
3378 | 3383 | |
|
3379 | 3384 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3380 | 3385 | |
|
3381 | 3386 | See :hg:`help revisions` for more about specifying and ordering |
|
3382 | 3387 | revisions. |
|
3383 | 3388 | |
|
3384 | 3389 | See :hg:`help templates` for more about pre-packaged styles and |
|
3385 | 3390 | specifying custom templates. |
|
3386 | 3391 | |
|
3387 | 3392 | Returns 0 on success. |
|
3388 | 3393 | |
|
3389 | 3394 | """ |
|
3390 | 3395 | opts = pycompat.byteskwargs(opts) |
|
3391 | 3396 | if opts.get('follow') and opts.get('rev'): |
|
3392 | 3397 | opts['rev'] = [revsetlang.formatspec('reverse(::%lr)', opts.get('rev'))] |
|
3393 | 3398 | del opts['follow'] |
|
3394 | 3399 | |
|
3395 | 3400 | if opts.get('graph'): |
|
3396 | 3401 | return cmdutil.graphlog(ui, repo, pats, opts) |
|
3397 | 3402 | |
|
3398 | 3403 | revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts) |
|
3399 | 3404 | limit = cmdutil.loglimit(opts) |
|
3400 | 3405 | count = 0 |
|
3401 | 3406 | |
|
3402 | 3407 | getrenamed = None |
|
3403 | 3408 | if opts.get('copies'): |
|
3404 | 3409 | endrev = None |
|
3405 | 3410 | if opts.get('rev'): |
|
3406 | 3411 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 |
|
3407 | 3412 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
3408 | 3413 | |
|
3409 | 3414 | ui.pager('log') |
|
3410 | 3415 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
3411 | 3416 | for rev in revs: |
|
3412 | 3417 | if count == limit: |
|
3413 | 3418 | break |
|
3414 | 3419 | ctx = repo[rev] |
|
3415 | 3420 | copies = None |
|
3416 | 3421 | if getrenamed is not None and rev: |
|
3417 | 3422 | copies = [] |
|
3418 | 3423 | for fn in ctx.files(): |
|
3419 | 3424 | rename = getrenamed(fn, rev) |
|
3420 | 3425 | if rename: |
|
3421 | 3426 | copies.append((fn, rename[0])) |
|
3422 | 3427 | if filematcher: |
|
3423 | 3428 | revmatchfn = filematcher(ctx.rev()) |
|
3424 | 3429 | else: |
|
3425 | 3430 | revmatchfn = None |
|
3426 | 3431 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
3427 | 3432 | if displayer.flush(ctx): |
|
3428 | 3433 | count += 1 |
|
3429 | 3434 | |
|
3430 | 3435 | displayer.close() |
|
3431 | 3436 | |
|
3432 | 3437 | @command('manifest', |
|
3433 | 3438 | [('r', 'rev', '', _('revision to display'), _('REV')), |
|
3434 | 3439 | ('', 'all', False, _("list files from all revisions"))] |
|
3435 | 3440 | + formatteropts, |
|
3436 | 3441 | _('[-r REV]')) |
|
3437 | 3442 | def manifest(ui, repo, node=None, rev=None, **opts): |
|
3438 | 3443 | """output the current or given revision of the project manifest |
|
3439 | 3444 | |
|
3440 | 3445 | Print a list of version controlled files for the given revision. |
|
3441 | 3446 | If no revision is given, the first parent of the working directory |
|
3442 | 3447 | is used, or the null revision if no revision is checked out. |
|
3443 | 3448 | |
|
3444 | 3449 | With -v, print file permissions, symlink and executable bits. |
|
3445 | 3450 | With --debug, print file revision hashes. |
|
3446 | 3451 | |
|
3447 | 3452 | If option --all is specified, the list of all files from all revisions |
|
3448 | 3453 | is printed. This includes deleted and renamed files. |
|
3449 | 3454 | |
|
3450 | 3455 | Returns 0 on success. |
|
3451 | 3456 | """ |
|
3452 | 3457 | opts = pycompat.byteskwargs(opts) |
|
3453 | 3458 | fm = ui.formatter('manifest', opts) |
|
3454 | 3459 | |
|
3455 | 3460 | if opts.get('all'): |
|
3456 | 3461 | if rev or node: |
|
3457 | 3462 | raise error.Abort(_("can't specify a revision with --all")) |
|
3458 | 3463 | |
|
3459 | 3464 | res = [] |
|
3460 | 3465 | prefix = "data/" |
|
3461 | 3466 | suffix = ".i" |
|
3462 | 3467 | plen = len(prefix) |
|
3463 | 3468 | slen = len(suffix) |
|
3464 | 3469 | with repo.lock(): |
|
3465 | 3470 | for fn, b, size in repo.store.datafiles(): |
|
3466 | 3471 | if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: |
|
3467 | 3472 | res.append(fn[plen:-slen]) |
|
3468 | 3473 | ui.pager('manifest') |
|
3469 | 3474 | for f in res: |
|
3470 | 3475 | fm.startitem() |
|
3471 | 3476 | fm.write("path", '%s\n', f) |
|
3472 | 3477 | fm.end() |
|
3473 | 3478 | return |
|
3474 | 3479 | |
|
3475 | 3480 | if rev and node: |
|
3476 | 3481 | raise error.Abort(_("please specify just one revision")) |
|
3477 | 3482 | |
|
3478 | 3483 | if not node: |
|
3479 | 3484 | node = rev |
|
3480 | 3485 | |
|
3481 | 3486 | char = {'l': '@', 'x': '*', '': ''} |
|
3482 | 3487 | mode = {'l': '644', 'x': '755', '': '644'} |
|
3483 | 3488 | ctx = scmutil.revsingle(repo, node) |
|
3484 | 3489 | mf = ctx.manifest() |
|
3485 | 3490 | ui.pager('manifest') |
|
3486 | 3491 | for f in ctx: |
|
3487 | 3492 | fm.startitem() |
|
3488 | 3493 | fl = ctx[f].flags() |
|
3489 | 3494 | fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) |
|
3490 | 3495 | fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) |
|
3491 | 3496 | fm.write('path', '%s\n', f) |
|
3492 | 3497 | fm.end() |
|
3493 | 3498 | |
|
3494 | 3499 | @command('^merge', |
|
3495 | 3500 | [('f', 'force', None, |
|
3496 | 3501 | _('force a merge including outstanding changes (DEPRECATED)')), |
|
3497 | 3502 | ('r', 'rev', '', _('revision to merge'), _('REV')), |
|
3498 | 3503 | ('P', 'preview', None, |
|
3499 | 3504 | _('review revisions to merge (no merge is performed)')) |
|
3500 | 3505 | ] + mergetoolopts, |
|
3501 | 3506 | _('[-P] [[-r] REV]')) |
|
3502 | 3507 | def merge(ui, repo, node=None, **opts): |
|
3503 | 3508 | """merge another revision into working directory |
|
3504 | 3509 | |
|
3505 | 3510 | The current working directory is updated with all changes made in |
|
3506 | 3511 | the requested revision since the last common predecessor revision. |
|
3507 | 3512 | |
|
3508 | 3513 | Files that changed between either parent are marked as changed for |
|
3509 | 3514 | the next commit and a commit must be performed before any further |
|
3510 | 3515 | updates to the repository are allowed. The next commit will have |
|
3511 | 3516 | two parents. |
|
3512 | 3517 | |
|
3513 | 3518 | ``--tool`` can be used to specify the merge tool used for file |
|
3514 | 3519 | merges. It overrides the HGMERGE environment variable and your |
|
3515 | 3520 | configuration files. See :hg:`help merge-tools` for options. |
|
3516 | 3521 | |
|
3517 | 3522 | If no revision is specified, the working directory's parent is a |
|
3518 | 3523 | head revision, and the current branch contains exactly one other |
|
3519 | 3524 | head, the other head is merged with by default. Otherwise, an |
|
3520 | 3525 | explicit revision with which to merge with must be provided. |
|
3521 | 3526 | |
|
3522 | 3527 | See :hg:`help resolve` for information on handling file conflicts. |
|
3523 | 3528 | |
|
3524 | 3529 | To undo an uncommitted merge, use :hg:`update --clean .` which |
|
3525 | 3530 | will check out a clean copy of the original merge parent, losing |
|
3526 | 3531 | all changes. |
|
3527 | 3532 | |
|
3528 | 3533 | Returns 0 on success, 1 if there are unresolved files. |
|
3529 | 3534 | """ |
|
3530 | 3535 | |
|
3531 | 3536 | opts = pycompat.byteskwargs(opts) |
|
3532 | 3537 | if opts.get('rev') and node: |
|
3533 | 3538 | raise error.Abort(_("please specify just one revision")) |
|
3534 | 3539 | if not node: |
|
3535 | 3540 | node = opts.get('rev') |
|
3536 | 3541 | |
|
3537 | 3542 | if node: |
|
3538 | 3543 | node = scmutil.revsingle(repo, node).node() |
|
3539 | 3544 | |
|
3540 | 3545 | if not node: |
|
3541 | 3546 | node = repo[destutil.destmerge(repo)].node() |
|
3542 | 3547 | |
|
3543 | 3548 | if opts.get('preview'): |
|
3544 | 3549 | # find nodes that are ancestors of p2 but not of p1 |
|
3545 | 3550 | p1 = repo.lookup('.') |
|
3546 | 3551 | p2 = repo.lookup(node) |
|
3547 | 3552 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
3548 | 3553 | |
|
3549 | 3554 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
3550 | 3555 | for node in nodes: |
|
3551 | 3556 | displayer.show(repo[node]) |
|
3552 | 3557 | displayer.close() |
|
3553 | 3558 | return 0 |
|
3554 | 3559 | |
|
3555 | 3560 | try: |
|
3556 | 3561 | # ui.forcemerge is an internal variable, do not document |
|
3557 | 3562 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge') |
|
3558 | 3563 | force = opts.get('force') |
|
3559 | 3564 | labels = ['working copy', 'merge rev'] |
|
3560 | 3565 | return hg.merge(repo, node, force=force, mergeforce=force, |
|
3561 | 3566 | labels=labels) |
|
3562 | 3567 | finally: |
|
3563 | 3568 | ui.setconfig('ui', 'forcemerge', '', 'merge') |
|
3564 | 3569 | |
|
3565 | 3570 | @command('outgoing|out', |
|
3566 | 3571 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
3567 | 3572 | ('r', 'rev', [], |
|
3568 | 3573 | _('a changeset intended to be included in the destination'), _('REV')), |
|
3569 | 3574 | ('n', 'newest-first', None, _('show newest record first')), |
|
3570 | 3575 | ('B', 'bookmarks', False, _('compare bookmarks')), |
|
3571 | 3576 | ('b', 'branch', [], _('a specific branch you would like to push'), |
|
3572 | 3577 | _('BRANCH')), |
|
3573 | 3578 | ] + logopts + remoteopts + subrepoopts, |
|
3574 | 3579 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) |
|
3575 | 3580 | def outgoing(ui, repo, dest=None, **opts): |
|
3576 | 3581 | """show changesets not found in the destination |
|
3577 | 3582 | |
|
3578 | 3583 | Show changesets not found in the specified destination repository |
|
3579 | 3584 | or the default push location. These are the changesets that would |
|
3580 | 3585 | be pushed if a push was requested. |
|
3581 | 3586 | |
|
3582 | 3587 | See pull for details of valid destination formats. |
|
3583 | 3588 | |
|
3584 | 3589 | .. container:: verbose |
|
3585 | 3590 | |
|
3586 | 3591 | With -B/--bookmarks, the result of bookmark comparison between |
|
3587 | 3592 | local and remote repositories is displayed. With -v/--verbose, |
|
3588 | 3593 | status is also displayed for each bookmark like below:: |
|
3589 | 3594 | |
|
3590 | 3595 | BM1 01234567890a added |
|
3591 | 3596 | BM2 deleted |
|
3592 | 3597 | BM3 234567890abc advanced |
|
3593 | 3598 | BM4 34567890abcd diverged |
|
3594 | 3599 | BM5 4567890abcde changed |
|
3595 | 3600 | |
|
3596 | 3601 | The action taken when pushing depends on the |
|
3597 | 3602 | status of each bookmark: |
|
3598 | 3603 | |
|
3599 | 3604 | :``added``: push with ``-B`` will create it |
|
3600 | 3605 | :``deleted``: push with ``-B`` will delete it |
|
3601 | 3606 | :``advanced``: push will update it |
|
3602 | 3607 | :``diverged``: push with ``-B`` will update it |
|
3603 | 3608 | :``changed``: push with ``-B`` will update it |
|
3604 | 3609 | |
|
3605 | 3610 | From the point of view of pushing behavior, bookmarks |
|
3606 | 3611 | existing only in the remote repository are treated as |
|
3607 | 3612 | ``deleted``, even if it is in fact added remotely. |
|
3608 | 3613 | |
|
3609 | 3614 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
3610 | 3615 | """ |
|
3611 | 3616 | opts = pycompat.byteskwargs(opts) |
|
3612 | 3617 | if opts.get('graph'): |
|
3613 | 3618 | cmdutil.checkunsupportedgraphflags([], opts) |
|
3614 | 3619 | o, other = hg._outgoing(ui, repo, dest, opts) |
|
3615 | 3620 | if not o: |
|
3616 | 3621 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
3617 | 3622 | return |
|
3618 | 3623 | |
|
3619 | 3624 | revdag = cmdutil.graphrevs(repo, o, opts) |
|
3620 | 3625 | ui.pager('outgoing') |
|
3621 | 3626 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
3622 | 3627 | cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) |
|
3623 | 3628 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
3624 | 3629 | return 0 |
|
3625 | 3630 | |
|
3626 | 3631 | if opts.get('bookmarks'): |
|
3627 | 3632 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
3628 | 3633 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
3629 | 3634 | other = hg.peer(repo, opts, dest) |
|
3630 | 3635 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3631 | 3636 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3632 | 3637 | return 0 |
|
3633 | 3638 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
3634 | 3639 | ui.pager('outgoing') |
|
3635 | 3640 | return bookmarks.outgoing(ui, repo, other) |
|
3636 | 3641 | |
|
3637 | 3642 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') |
|
3638 | 3643 | try: |
|
3639 | 3644 | return hg.outgoing(ui, repo, dest, opts) |
|
3640 | 3645 | finally: |
|
3641 | 3646 | del repo._subtoppath |
|
3642 | 3647 | |
|
3643 | 3648 | @command('parents', |
|
3644 | 3649 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), |
|
3645 | 3650 | ] + templateopts, |
|
3646 | 3651 | _('[-r REV] [FILE]'), |
|
3647 | 3652 | inferrepo=True) |
|
3648 | 3653 | def parents(ui, repo, file_=None, **opts): |
|
3649 | 3654 | """show the parents of the working directory or revision (DEPRECATED) |
|
3650 | 3655 | |
|
3651 | 3656 | Print the working directory's parent revisions. If a revision is |
|
3652 | 3657 | given via -r/--rev, the parent of that revision will be printed. |
|
3653 | 3658 | If a file argument is given, the revision in which the file was |
|
3654 | 3659 | last changed (before the working directory revision or the |
|
3655 | 3660 | argument to --rev if given) is printed. |
|
3656 | 3661 | |
|
3657 | 3662 | This command is equivalent to:: |
|
3658 | 3663 | |
|
3659 | 3664 | hg log -r "p1()+p2()" or |
|
3660 | 3665 | hg log -r "p1(REV)+p2(REV)" or |
|
3661 | 3666 | hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or |
|
3662 | 3667 | hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))" |
|
3663 | 3668 | |
|
3664 | 3669 | See :hg:`summary` and :hg:`help revsets` for related information. |
|
3665 | 3670 | |
|
3666 | 3671 | Returns 0 on success. |
|
3667 | 3672 | """ |
|
3668 | 3673 | |
|
3669 | 3674 | opts = pycompat.byteskwargs(opts) |
|
3670 | 3675 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
3671 | 3676 | |
|
3672 | 3677 | if file_: |
|
3673 | 3678 | m = scmutil.match(ctx, (file_,), opts) |
|
3674 | 3679 | if m.anypats() or len(m.files()) != 1: |
|
3675 | 3680 | raise error.Abort(_('can only specify an explicit filename')) |
|
3676 | 3681 | file_ = m.files()[0] |
|
3677 | 3682 | filenodes = [] |
|
3678 | 3683 | for cp in ctx.parents(): |
|
3679 | 3684 | if not cp: |
|
3680 | 3685 | continue |
|
3681 | 3686 | try: |
|
3682 | 3687 | filenodes.append(cp.filenode(file_)) |
|
3683 | 3688 | except error.LookupError: |
|
3684 | 3689 | pass |
|
3685 | 3690 | if not filenodes: |
|
3686 | 3691 | raise error.Abort(_("'%s' not found in manifest!") % file_) |
|
3687 | 3692 | p = [] |
|
3688 | 3693 | for fn in filenodes: |
|
3689 | 3694 | fctx = repo.filectx(file_, fileid=fn) |
|
3690 | 3695 | p.append(fctx.node()) |
|
3691 | 3696 | else: |
|
3692 | 3697 | p = [cp.node() for cp in ctx.parents()] |
|
3693 | 3698 | |
|
3694 | 3699 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
3695 | 3700 | for n in p: |
|
3696 | 3701 | if n != nullid: |
|
3697 | 3702 | displayer.show(repo[n]) |
|
3698 | 3703 | displayer.close() |
|
3699 | 3704 | |
|
3700 | 3705 | @command('paths', formatteropts, _('[NAME]'), optionalrepo=True) |
|
3701 | 3706 | def paths(ui, repo, search=None, **opts): |
|
3702 | 3707 | """show aliases for remote repositories |
|
3703 | 3708 | |
|
3704 | 3709 | Show definition of symbolic path name NAME. If no name is given, |
|
3705 | 3710 | show definition of all available names. |
|
3706 | 3711 | |
|
3707 | 3712 | Option -q/--quiet suppresses all output when searching for NAME |
|
3708 | 3713 | and shows only the path names when listing all definitions. |
|
3709 | 3714 | |
|
3710 | 3715 | Path names are defined in the [paths] section of your |
|
3711 | 3716 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
3712 | 3717 | repository, ``.hg/hgrc`` is used, too. |
|
3713 | 3718 | |
|
3714 | 3719 | The path names ``default`` and ``default-push`` have a special |
|
3715 | 3720 | meaning. When performing a push or pull operation, they are used |
|
3716 | 3721 | as fallbacks if no location is specified on the command-line. |
|
3717 | 3722 | When ``default-push`` is set, it will be used for push and |
|
3718 | 3723 | ``default`` will be used for pull; otherwise ``default`` is used |
|
3719 | 3724 | as the fallback for both. When cloning a repository, the clone |
|
3720 | 3725 | source is written as ``default`` in ``.hg/hgrc``. |
|
3721 | 3726 | |
|
3722 | 3727 | .. note:: |
|
3723 | 3728 | |
|
3724 | 3729 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
3725 | 3730 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` |
|
3726 | 3731 | and :hg:`bundle`) operations. |
|
3727 | 3732 | |
|
3728 | 3733 | See :hg:`help urls` for more information. |
|
3729 | 3734 | |
|
3730 | 3735 | Returns 0 on success. |
|
3731 | 3736 | """ |
|
3732 | 3737 | |
|
3733 | 3738 | opts = pycompat.byteskwargs(opts) |
|
3734 | 3739 | ui.pager('paths') |
|
3735 | 3740 | if search: |
|
3736 | 3741 | pathitems = [(name, path) for name, path in ui.paths.iteritems() |
|
3737 | 3742 | if name == search] |
|
3738 | 3743 | else: |
|
3739 | 3744 | pathitems = sorted(ui.paths.iteritems()) |
|
3740 | 3745 | |
|
3741 | 3746 | fm = ui.formatter('paths', opts) |
|
3742 | 3747 | if fm.isplain(): |
|
3743 | 3748 | hidepassword = util.hidepassword |
|
3744 | 3749 | else: |
|
3745 | 3750 | hidepassword = str |
|
3746 | 3751 | if ui.quiet: |
|
3747 | 3752 | namefmt = '%s\n' |
|
3748 | 3753 | else: |
|
3749 | 3754 | namefmt = '%s = ' |
|
3750 | 3755 | showsubopts = not search and not ui.quiet |
|
3751 | 3756 | |
|
3752 | 3757 | for name, path in pathitems: |
|
3753 | 3758 | fm.startitem() |
|
3754 | 3759 | fm.condwrite(not search, 'name', namefmt, name) |
|
3755 | 3760 | fm.condwrite(not ui.quiet, 'url', '%s\n', hidepassword(path.rawloc)) |
|
3756 | 3761 | for subopt, value in sorted(path.suboptions.items()): |
|
3757 | 3762 | assert subopt not in ('name', 'url') |
|
3758 | 3763 | if showsubopts: |
|
3759 | 3764 | fm.plain('%s:%s = ' % (name, subopt)) |
|
3760 | 3765 | fm.condwrite(showsubopts, subopt, '%s\n', value) |
|
3761 | 3766 | |
|
3762 | 3767 | fm.end() |
|
3763 | 3768 | |
|
3764 | 3769 | if search and not pathitems: |
|
3765 | 3770 | if not ui.quiet: |
|
3766 | 3771 | ui.warn(_("not found!\n")) |
|
3767 | 3772 | return 1 |
|
3768 | 3773 | else: |
|
3769 | 3774 | return 0 |
|
3770 | 3775 | |
|
3771 | 3776 | @command('phase', |
|
3772 | 3777 | [('p', 'public', False, _('set changeset phase to public')), |
|
3773 | 3778 | ('d', 'draft', False, _('set changeset phase to draft')), |
|
3774 | 3779 | ('s', 'secret', False, _('set changeset phase to secret')), |
|
3775 | 3780 | ('f', 'force', False, _('allow to move boundary backward')), |
|
3776 | 3781 | ('r', 'rev', [], _('target revision'), _('REV')), |
|
3777 | 3782 | ], |
|
3778 | 3783 | _('[-p|-d|-s] [-f] [-r] [REV...]')) |
|
3779 | 3784 | def phase(ui, repo, *revs, **opts): |
|
3780 | 3785 | """set or show the current phase name |
|
3781 | 3786 | |
|
3782 | 3787 | With no argument, show the phase name of the current revision(s). |
|
3783 | 3788 | |
|
3784 | 3789 | With one of -p/--public, -d/--draft or -s/--secret, change the |
|
3785 | 3790 | phase value of the specified revisions. |
|
3786 | 3791 | |
|
3787 | 3792 | Unless -f/--force is specified, :hg:`phase` won't move changeset from a |
|
3788 | 3793 | lower phase to an higher phase. Phases are ordered as follows:: |
|
3789 | 3794 | |
|
3790 | 3795 | public < draft < secret |
|
3791 | 3796 | |
|
3792 | 3797 | Returns 0 on success, 1 if some phases could not be changed. |
|
3793 | 3798 | |
|
3794 | 3799 | (For more information about the phases concept, see :hg:`help phases`.) |
|
3795 | 3800 | """ |
|
3796 | 3801 | opts = pycompat.byteskwargs(opts) |
|
3797 | 3802 | # search for a unique phase argument |
|
3798 | 3803 | targetphase = None |
|
3799 | 3804 | for idx, name in enumerate(phases.phasenames): |
|
3800 | 3805 | if opts[name]: |
|
3801 | 3806 | if targetphase is not None: |
|
3802 | 3807 | raise error.Abort(_('only one phase can be specified')) |
|
3803 | 3808 | targetphase = idx |
|
3804 | 3809 | |
|
3805 | 3810 | # look for specified revision |
|
3806 | 3811 | revs = list(revs) |
|
3807 | 3812 | revs.extend(opts['rev']) |
|
3808 | 3813 | if not revs: |
|
3809 | 3814 | # display both parents as the second parent phase can influence |
|
3810 | 3815 | # the phase of a merge commit |
|
3811 | 3816 | revs = [c.rev() for c in repo[None].parents()] |
|
3812 | 3817 | |
|
3813 | 3818 | revs = scmutil.revrange(repo, revs) |
|
3814 | 3819 | |
|
3815 | 3820 | lock = None |
|
3816 | 3821 | ret = 0 |
|
3817 | 3822 | if targetphase is None: |
|
3818 | 3823 | # display |
|
3819 | 3824 | for r in revs: |
|
3820 | 3825 | ctx = repo[r] |
|
3821 | 3826 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) |
|
3822 | 3827 | else: |
|
3823 | 3828 | tr = None |
|
3824 | 3829 | lock = repo.lock() |
|
3825 | 3830 | try: |
|
3826 | 3831 | tr = repo.transaction("phase") |
|
3827 | 3832 | # set phase |
|
3828 | 3833 | if not revs: |
|
3829 | 3834 | raise error.Abort(_('empty revision set')) |
|
3830 | 3835 | nodes = [repo[r].node() for r in revs] |
|
3831 | 3836 | # moving revision from public to draft may hide them |
|
3832 | 3837 | # We have to check result on an unfiltered repository |
|
3833 | 3838 | unfi = repo.unfiltered() |
|
3834 | 3839 | getphase = unfi._phasecache.phase |
|
3835 | 3840 | olddata = [getphase(unfi, r) for r in unfi] |
|
3836 | 3841 | phases.advanceboundary(repo, tr, targetphase, nodes) |
|
3837 | 3842 | if opts['force']: |
|
3838 | 3843 | phases.retractboundary(repo, tr, targetphase, nodes) |
|
3839 | 3844 | tr.close() |
|
3840 | 3845 | finally: |
|
3841 | 3846 | if tr is not None: |
|
3842 | 3847 | tr.release() |
|
3843 | 3848 | lock.release() |
|
3844 | 3849 | getphase = unfi._phasecache.phase |
|
3845 | 3850 | newdata = [getphase(unfi, r) for r in unfi] |
|
3846 | 3851 | changes = sum(newdata[r] != olddata[r] for r in unfi) |
|
3847 | 3852 | cl = unfi.changelog |
|
3848 | 3853 | rejected = [n for n in nodes |
|
3849 | 3854 | if newdata[cl.rev(n)] < targetphase] |
|
3850 | 3855 | if rejected: |
|
3851 | 3856 | ui.warn(_('cannot move %i changesets to a higher ' |
|
3852 | 3857 | 'phase, use --force\n') % len(rejected)) |
|
3853 | 3858 | ret = 1 |
|
3854 | 3859 | if changes: |
|
3855 | 3860 | msg = _('phase changed for %i changesets\n') % changes |
|
3856 | 3861 | if ret: |
|
3857 | 3862 | ui.status(msg) |
|
3858 | 3863 | else: |
|
3859 | 3864 | ui.note(msg) |
|
3860 | 3865 | else: |
|
3861 | 3866 | ui.warn(_('no phases changed\n')) |
|
3862 | 3867 | return ret |
|
3863 | 3868 | |
|
3864 | 3869 | def postincoming(ui, repo, modheads, optupdate, checkout, brev): |
|
3865 | 3870 | """Run after a changegroup has been added via pull/unbundle |
|
3866 | 3871 | |
|
3867 | 3872 | This takes arguments below: |
|
3868 | 3873 | |
|
3869 | 3874 | :modheads: change of heads by pull/unbundle |
|
3870 | 3875 | :optupdate: updating working directory is needed or not |
|
3871 | 3876 | :checkout: update destination revision (or None to default destination) |
|
3872 | 3877 | :brev: a name, which might be a bookmark to be activated after updating |
|
3873 | 3878 | """ |
|
3874 | 3879 | if modheads == 0: |
|
3875 | 3880 | return |
|
3876 | 3881 | if optupdate: |
|
3877 | 3882 | try: |
|
3878 | 3883 | return hg.updatetotally(ui, repo, checkout, brev) |
|
3879 | 3884 | except error.UpdateAbort as inst: |
|
3880 | 3885 | msg = _("not updating: %s") % str(inst) |
|
3881 | 3886 | hint = inst.hint |
|
3882 | 3887 | raise error.UpdateAbort(msg, hint=hint) |
|
3883 | 3888 | if modheads > 1: |
|
3884 | 3889 | currentbranchheads = len(repo.branchheads()) |
|
3885 | 3890 | if currentbranchheads == modheads: |
|
3886 | 3891 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
3887 | 3892 | elif currentbranchheads > 1: |
|
3888 | 3893 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " |
|
3889 | 3894 | "merge)\n")) |
|
3890 | 3895 | else: |
|
3891 | 3896 | ui.status(_("(run 'hg heads' to see heads)\n")) |
|
3892 | 3897 | else: |
|
3893 | 3898 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
3894 | 3899 | |
|
3895 | 3900 | @command('^pull', |
|
3896 | 3901 | [('u', 'update', None, |
|
3897 | 3902 | _('update to new branch head if changesets were pulled')), |
|
3898 | 3903 | ('f', 'force', None, _('run even when remote repository is unrelated')), |
|
3899 | 3904 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3900 | 3905 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), |
|
3901 | 3906 | ('b', 'branch', [], _('a specific branch you would like to pull'), |
|
3902 | 3907 | _('BRANCH')), |
|
3903 | 3908 | ] + remoteopts, |
|
3904 | 3909 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
|
3905 | 3910 | def pull(ui, repo, source="default", **opts): |
|
3906 | 3911 | """pull changes from the specified source |
|
3907 | 3912 | |
|
3908 | 3913 | Pull changes from a remote repository to a local one. |
|
3909 | 3914 | |
|
3910 | 3915 | This finds all changes from the repository at the specified path |
|
3911 | 3916 | or URL and adds them to a local repository (the current one unless |
|
3912 | 3917 | -R is specified). By default, this does not update the copy of the |
|
3913 | 3918 | project in the working directory. |
|
3914 | 3919 | |
|
3915 | 3920 | Use :hg:`incoming` if you want to see what would have been added |
|
3916 | 3921 | by a pull at the time you issued this command. If you then decide |
|
3917 | 3922 | to add those changes to the repository, you should use :hg:`pull |
|
3918 | 3923 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
3919 | 3924 | |
|
3920 | 3925 | If SOURCE is omitted, the 'default' path will be used. |
|
3921 | 3926 | See :hg:`help urls` for more information. |
|
3922 | 3927 | |
|
3923 | 3928 | Specifying bookmark as ``.`` is equivalent to specifying the active |
|
3924 | 3929 | bookmark's name. |
|
3925 | 3930 | |
|
3926 | 3931 | Returns 0 on success, 1 if an update had unresolved files. |
|
3927 | 3932 | """ |
|
3928 | 3933 | |
|
3929 | 3934 | opts = pycompat.byteskwargs(opts) |
|
3930 | 3935 | if ui.configbool('commands', 'update.requiredest') and opts.get('update'): |
|
3931 | 3936 | msg = _('update destination required by configuration') |
|
3932 | 3937 | hint = _('use hg pull followed by hg update DEST') |
|
3933 | 3938 | raise error.Abort(msg, hint=hint) |
|
3934 | 3939 | |
|
3935 | 3940 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
|
3936 | 3941 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) |
|
3937 | 3942 | other = hg.peer(repo, opts, source) |
|
3938 | 3943 | try: |
|
3939 | 3944 | revs, checkout = hg.addbranchrevs(repo, other, branches, |
|
3940 | 3945 | opts.get('rev')) |
|
3941 | 3946 | |
|
3942 | 3947 | |
|
3943 | 3948 | pullopargs = {} |
|
3944 | 3949 | if opts.get('bookmark'): |
|
3945 | 3950 | if not revs: |
|
3946 | 3951 | revs = [] |
|
3947 | 3952 | # The list of bookmark used here is not the one used to actually |
|
3948 | 3953 | # update the bookmark name. This can result in the revision pulled |
|
3949 | 3954 | # not ending up with the name of the bookmark because of a race |
|
3950 | 3955 | # condition on the server. (See issue 4689 for details) |
|
3951 | 3956 | remotebookmarks = other.listkeys('bookmarks') |
|
3952 | 3957 | pullopargs['remotebookmarks'] = remotebookmarks |
|
3953 | 3958 | for b in opts['bookmark']: |
|
3954 | 3959 | b = repo._bookmarks.expandname(b) |
|
3955 | 3960 | if b not in remotebookmarks: |
|
3956 | 3961 | raise error.Abort(_('remote bookmark %s not found!') % b) |
|
3957 | 3962 | revs.append(remotebookmarks[b]) |
|
3958 | 3963 | |
|
3959 | 3964 | if revs: |
|
3960 | 3965 | try: |
|
3961 | 3966 | # When 'rev' is a bookmark name, we cannot guarantee that it |
|
3962 | 3967 | # will be updated with that name because of a race condition |
|
3963 | 3968 | # server side. (See issue 4689 for details) |
|
3964 | 3969 | oldrevs = revs |
|
3965 | 3970 | revs = [] # actually, nodes |
|
3966 | 3971 | for r in oldrevs: |
|
3967 | 3972 | node = other.lookup(r) |
|
3968 | 3973 | revs.append(node) |
|
3969 | 3974 | if r == checkout: |
|
3970 | 3975 | checkout = node |
|
3971 | 3976 | except error.CapabilityError: |
|
3972 | 3977 | err = _("other repository doesn't support revision lookup, " |
|
3973 | 3978 | "so a rev cannot be specified.") |
|
3974 | 3979 | raise error.Abort(err) |
|
3975 | 3980 | |
|
3976 | 3981 | pullopargs.update(opts.get('opargs', {})) |
|
3977 | 3982 | modheads = exchange.pull(repo, other, heads=revs, |
|
3978 | 3983 | force=opts.get('force'), |
|
3979 | 3984 | bookmarks=opts.get('bookmark', ()), |
|
3980 | 3985 | opargs=pullopargs).cgresult |
|
3981 | 3986 | |
|
3982 | 3987 | # brev is a name, which might be a bookmark to be activated at |
|
3983 | 3988 | # the end of the update. In other words, it is an explicit |
|
3984 | 3989 | # destination of the update |
|
3985 | 3990 | brev = None |
|
3986 | 3991 | |
|
3987 | 3992 | if checkout: |
|
3988 | 3993 | checkout = str(repo.changelog.rev(checkout)) |
|
3989 | 3994 | |
|
3990 | 3995 | # order below depends on implementation of |
|
3991 | 3996 | # hg.addbranchrevs(). opts['bookmark'] is ignored, |
|
3992 | 3997 | # because 'checkout' is determined without it. |
|
3993 | 3998 | if opts.get('rev'): |
|
3994 | 3999 | brev = opts['rev'][0] |
|
3995 | 4000 | elif opts.get('branch'): |
|
3996 | 4001 | brev = opts['branch'][0] |
|
3997 | 4002 | else: |
|
3998 | 4003 | brev = branches[0] |
|
3999 | 4004 | repo._subtoppath = source |
|
4000 | 4005 | try: |
|
4001 | 4006 | ret = postincoming(ui, repo, modheads, opts.get('update'), |
|
4002 | 4007 | checkout, brev) |
|
4003 | 4008 | |
|
4004 | 4009 | finally: |
|
4005 | 4010 | del repo._subtoppath |
|
4006 | 4011 | |
|
4007 | 4012 | finally: |
|
4008 | 4013 | other.close() |
|
4009 | 4014 | return ret |
|
4010 | 4015 | |
|
4011 | 4016 | @command('^push', |
|
4012 | 4017 | [('f', 'force', None, _('force push')), |
|
4013 | 4018 | ('r', 'rev', [], |
|
4014 | 4019 | _('a changeset intended to be included in the destination'), |
|
4015 | 4020 | _('REV')), |
|
4016 | 4021 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), |
|
4017 | 4022 | ('b', 'branch', [], |
|
4018 | 4023 | _('a specific branch you would like to push'), _('BRANCH')), |
|
4019 | 4024 | ('', 'new-branch', False, _('allow pushing a new branch')), |
|
4020 | 4025 | ] + remoteopts, |
|
4021 | 4026 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) |
|
4022 | 4027 | def push(ui, repo, dest=None, **opts): |
|
4023 | 4028 | """push changes to the specified destination |
|
4024 | 4029 | |
|
4025 | 4030 | Push changesets from the local repository to the specified |
|
4026 | 4031 | destination. |
|
4027 | 4032 | |
|
4028 | 4033 | This operation is symmetrical to pull: it is identical to a pull |
|
4029 | 4034 | in the destination repository from the current one. |
|
4030 | 4035 | |
|
4031 | 4036 | By default, push will not allow creation of new heads at the |
|
4032 | 4037 | destination, since multiple heads would make it unclear which head |
|
4033 | 4038 | to use. In this situation, it is recommended to pull and merge |
|
4034 | 4039 | before pushing. |
|
4035 | 4040 | |
|
4036 | 4041 | Use --new-branch if you want to allow push to create a new named |
|
4037 | 4042 | branch that is not present at the destination. This allows you to |
|
4038 | 4043 | only create a new branch without forcing other changes. |
|
4039 | 4044 | |
|
4040 | 4045 | .. note:: |
|
4041 | 4046 | |
|
4042 | 4047 | Extra care should be taken with the -f/--force option, |
|
4043 | 4048 | which will push all new heads on all branches, an action which will |
|
4044 | 4049 | almost always cause confusion for collaborators. |
|
4045 | 4050 | |
|
4046 | 4051 | If -r/--rev is used, the specified revision and all its ancestors |
|
4047 | 4052 | will be pushed to the remote repository. |
|
4048 | 4053 | |
|
4049 | 4054 | If -B/--bookmark is used, the specified bookmarked revision, its |
|
4050 | 4055 | ancestors, and the bookmark will be pushed to the remote |
|
4051 | 4056 | repository. Specifying ``.`` is equivalent to specifying the active |
|
4052 | 4057 | bookmark's name. |
|
4053 | 4058 | |
|
4054 | 4059 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
4055 | 4060 | URLs. If DESTINATION is omitted, a default path will be used. |
|
4056 | 4061 | |
|
4057 | 4062 | Returns 0 if push was successful, 1 if nothing to push. |
|
4058 | 4063 | """ |
|
4059 | 4064 | |
|
4060 | 4065 | opts = pycompat.byteskwargs(opts) |
|
4061 | 4066 | if opts.get('bookmark'): |
|
4062 | 4067 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') |
|
4063 | 4068 | for b in opts['bookmark']: |
|
4064 | 4069 | # translate -B options to -r so changesets get pushed |
|
4065 | 4070 | b = repo._bookmarks.expandname(b) |
|
4066 | 4071 | if b in repo._bookmarks: |
|
4067 | 4072 | opts.setdefault('rev', []).append(b) |
|
4068 | 4073 | else: |
|
4069 | 4074 | # if we try to push a deleted bookmark, translate it to null |
|
4070 | 4075 | # this lets simultaneous -r, -b options continue working |
|
4071 | 4076 | opts.setdefault('rev', []).append("null") |
|
4072 | 4077 | |
|
4073 | 4078 | path = ui.paths.getpath(dest, default=('default-push', 'default')) |
|
4074 | 4079 | if not path: |
|
4075 | 4080 | raise error.Abort(_('default repository not configured!'), |
|
4076 | 4081 | hint=_("see 'hg help config.paths'")) |
|
4077 | 4082 | dest = path.pushloc or path.loc |
|
4078 | 4083 | branches = (path.branch, opts.get('branch') or []) |
|
4079 | 4084 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) |
|
4080 | 4085 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
4081 | 4086 | other = hg.peer(repo, opts, dest) |
|
4082 | 4087 | |
|
4083 | 4088 | if revs: |
|
4084 | 4089 | revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] |
|
4085 | 4090 | if not revs: |
|
4086 | 4091 | raise error.Abort(_("specified revisions evaluate to an empty set"), |
|
4087 | 4092 | hint=_("use different revision arguments")) |
|
4088 | 4093 | elif path.pushrev: |
|
4089 | 4094 | # It doesn't make any sense to specify ancestor revisions. So limit |
|
4090 | 4095 | # to DAG heads to make discovery simpler. |
|
4091 | 4096 | expr = revsetlang.formatspec('heads(%r)', path.pushrev) |
|
4092 | 4097 | revs = scmutil.revrange(repo, [expr]) |
|
4093 | 4098 | revs = [repo[rev].node() for rev in revs] |
|
4094 | 4099 | if not revs: |
|
4095 | 4100 | raise error.Abort(_('default push revset for path evaluates to an ' |
|
4096 | 4101 | 'empty set')) |
|
4097 | 4102 | |
|
4098 | 4103 | repo._subtoppath = dest |
|
4099 | 4104 | try: |
|
4100 | 4105 | # push subrepos depth-first for coherent ordering |
|
4101 | 4106 | c = repo[''] |
|
4102 | 4107 | subs = c.substate # only repos that are committed |
|
4103 | 4108 | for s in sorted(subs): |
|
4104 | 4109 | result = c.sub(s).push(opts) |
|
4105 | 4110 | if result == 0: |
|
4106 | 4111 | return not result |
|
4107 | 4112 | finally: |
|
4108 | 4113 | del repo._subtoppath |
|
4109 | 4114 | pushop = exchange.push(repo, other, opts.get('force'), revs=revs, |
|
4110 | 4115 | newbranch=opts.get('new_branch'), |
|
4111 | 4116 | bookmarks=opts.get('bookmark', ()), |
|
4112 | 4117 | opargs=opts.get('opargs')) |
|
4113 | 4118 | |
|
4114 | 4119 | result = not pushop.cgresult |
|
4115 | 4120 | |
|
4116 | 4121 | if pushop.bkresult is not None: |
|
4117 | 4122 | if pushop.bkresult == 2: |
|
4118 | 4123 | result = 2 |
|
4119 | 4124 | elif not result and pushop.bkresult: |
|
4120 | 4125 | result = 2 |
|
4121 | 4126 | |
|
4122 | 4127 | return result |
|
4123 | 4128 | |
|
4124 | 4129 | @command('recover', []) |
|
4125 | 4130 | def recover(ui, repo): |
|
4126 | 4131 | """roll back an interrupted transaction |
|
4127 | 4132 | |
|
4128 | 4133 | Recover from an interrupted commit or pull. |
|
4129 | 4134 | |
|
4130 | 4135 | This command tries to fix the repository status after an |
|
4131 | 4136 | interrupted operation. It should only be necessary when Mercurial |
|
4132 | 4137 | suggests it. |
|
4133 | 4138 | |
|
4134 | 4139 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
4135 | 4140 | """ |
|
4136 | 4141 | if repo.recover(): |
|
4137 | 4142 | return hg.verify(repo) |
|
4138 | 4143 | return 1 |
|
4139 | 4144 | |
|
4140 | 4145 | @command('^remove|rm', |
|
4141 | 4146 | [('A', 'after', None, _('record delete for missing files')), |
|
4142 | 4147 | ('f', 'force', None, |
|
4143 | 4148 | _('forget added files, delete modified files')), |
|
4144 | 4149 | ] + subrepoopts + walkopts, |
|
4145 | 4150 | _('[OPTION]... FILE...'), |
|
4146 | 4151 | inferrepo=True) |
|
4147 | 4152 | def remove(ui, repo, *pats, **opts): |
|
4148 | 4153 | """remove the specified files on the next commit |
|
4149 | 4154 | |
|
4150 | 4155 | Schedule the indicated files for removal from the current branch. |
|
4151 | 4156 | |
|
4152 | 4157 | This command schedules the files to be removed at the next commit. |
|
4153 | 4158 | To undo a remove before that, see :hg:`revert`. To undo added |
|
4154 | 4159 | files, see :hg:`forget`. |
|
4155 | 4160 | |
|
4156 | 4161 | .. container:: verbose |
|
4157 | 4162 | |
|
4158 | 4163 | -A/--after can be used to remove only files that have already |
|
4159 | 4164 | been deleted, -f/--force can be used to force deletion, and -Af |
|
4160 | 4165 | can be used to remove files from the next revision without |
|
4161 | 4166 | deleting them from the working directory. |
|
4162 | 4167 | |
|
4163 | 4168 | The following table details the behavior of remove for different |
|
4164 | 4169 | file states (columns) and option combinations (rows). The file |
|
4165 | 4170 | states are Added [A], Clean [C], Modified [M] and Missing [!] |
|
4166 | 4171 | (as reported by :hg:`status`). The actions are Warn, Remove |
|
4167 | 4172 | (from branch) and Delete (from disk): |
|
4168 | 4173 | |
|
4169 | 4174 | ========= == == == == |
|
4170 | 4175 | opt/state A C M ! |
|
4171 | 4176 | ========= == == == == |
|
4172 | 4177 | none W RD W R |
|
4173 | 4178 | -f R RD RD R |
|
4174 | 4179 | -A W W W R |
|
4175 | 4180 | -Af R R R R |
|
4176 | 4181 | ========= == == == == |
|
4177 | 4182 | |
|
4178 | 4183 | .. note:: |
|
4179 | 4184 | |
|
4180 | 4185 | :hg:`remove` never deletes files in Added [A] state from the |
|
4181 | 4186 | working directory, not even if ``--force`` is specified. |
|
4182 | 4187 | |
|
4183 | 4188 | Returns 0 on success, 1 if any warnings encountered. |
|
4184 | 4189 | """ |
|
4185 | 4190 | |
|
4186 | 4191 | opts = pycompat.byteskwargs(opts) |
|
4187 | 4192 | after, force = opts.get('after'), opts.get('force') |
|
4188 | 4193 | if not pats and not after: |
|
4189 | 4194 | raise error.Abort(_('no files specified')) |
|
4190 | 4195 | |
|
4191 | 4196 | m = scmutil.match(repo[None], pats, opts) |
|
4192 | 4197 | subrepos = opts.get('subrepos') |
|
4193 | 4198 | return cmdutil.remove(ui, repo, m, "", after, force, subrepos) |
|
4194 | 4199 | |
|
4195 | 4200 | @command('rename|move|mv', |
|
4196 | 4201 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
4197 | 4202 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
4198 | 4203 | ] + walkopts + dryrunopts, |
|
4199 | 4204 | _('[OPTION]... SOURCE... DEST')) |
|
4200 | 4205 | def rename(ui, repo, *pats, **opts): |
|
4201 | 4206 | """rename files; equivalent of copy + remove |
|
4202 | 4207 | |
|
4203 | 4208 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
4204 | 4209 | is a directory, copies are put in that directory. If dest is a |
|
4205 | 4210 | file, there can only be one source. |
|
4206 | 4211 | |
|
4207 | 4212 | By default, this command copies the contents of files as they |
|
4208 | 4213 | exist in the working directory. If invoked with -A/--after, the |
|
4209 | 4214 | operation is recorded, but no copying is performed. |
|
4210 | 4215 | |
|
4211 | 4216 | This command takes effect at the next commit. To undo a rename |
|
4212 | 4217 | before that, see :hg:`revert`. |
|
4213 | 4218 | |
|
4214 | 4219 | Returns 0 on success, 1 if errors are encountered. |
|
4215 | 4220 | """ |
|
4216 | 4221 | opts = pycompat.byteskwargs(opts) |
|
4217 | 4222 | with repo.wlock(False): |
|
4218 | 4223 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
4219 | 4224 | |
|
4220 | 4225 | @command('resolve', |
|
4221 | 4226 | [('a', 'all', None, _('select all unresolved files')), |
|
4222 | 4227 | ('l', 'list', None, _('list state of files needing merge')), |
|
4223 | 4228 | ('m', 'mark', None, _('mark files as resolved')), |
|
4224 | 4229 | ('u', 'unmark', None, _('mark files as unresolved')), |
|
4225 | 4230 | ('n', 'no-status', None, _('hide status prefix'))] |
|
4226 | 4231 | + mergetoolopts + walkopts + formatteropts, |
|
4227 | 4232 | _('[OPTION]... [FILE]...'), |
|
4228 | 4233 | inferrepo=True) |
|
4229 | 4234 | def resolve(ui, repo, *pats, **opts): |
|
4230 | 4235 | """redo merges or set/view the merge status of files |
|
4231 | 4236 | |
|
4232 | 4237 | Merges with unresolved conflicts are often the result of |
|
4233 | 4238 | non-interactive merging using the ``internal:merge`` configuration |
|
4234 | 4239 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
4235 | 4240 | command is used to manage the files involved in a merge, after |
|
4236 | 4241 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
4237 | 4242 | working directory must have two parents). See :hg:`help |
|
4238 | 4243 | merge-tools` for information on configuring merge tools. |
|
4239 | 4244 | |
|
4240 | 4245 | The resolve command can be used in the following ways: |
|
4241 | 4246 | |
|
4242 | 4247 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified |
|
4243 | 4248 | files, discarding any previous merge attempts. Re-merging is not |
|
4244 | 4249 | performed for files already marked as resolved. Use ``--all/-a`` |
|
4245 | 4250 | to select all unresolved files. ``--tool`` can be used to specify |
|
4246 | 4251 | the merge tool used for the given files. It overrides the HGMERGE |
|
4247 | 4252 | environment variable and your configuration files. Previous file |
|
4248 | 4253 | contents are saved with a ``.orig`` suffix. |
|
4249 | 4254 | |
|
4250 | 4255 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
4251 | 4256 | (e.g. after having manually fixed-up the files). The default is |
|
4252 | 4257 | to mark all unresolved files. |
|
4253 | 4258 | |
|
4254 | 4259 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
4255 | 4260 | default is to mark all resolved files. |
|
4256 | 4261 | |
|
4257 | 4262 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
4258 | 4263 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
4259 | 4264 | You can use ``set:unresolved()`` or ``set:resolved()`` to filter |
|
4260 | 4265 | the list. See :hg:`help filesets` for details. |
|
4261 | 4266 | |
|
4262 | 4267 | .. note:: |
|
4263 | 4268 | |
|
4264 | 4269 | Mercurial will not let you commit files with unresolved merge |
|
4265 | 4270 | conflicts. You must use :hg:`resolve -m ...` before you can |
|
4266 | 4271 | commit after a conflicting merge. |
|
4267 | 4272 | |
|
4268 | 4273 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
4269 | 4274 | """ |
|
4270 | 4275 | |
|
4271 | 4276 | opts = pycompat.byteskwargs(opts) |
|
4272 | 4277 | flaglist = 'all mark unmark list no_status'.split() |
|
4273 | 4278 | all, mark, unmark, show, nostatus = \ |
|
4274 | 4279 | [opts.get(o) for o in flaglist] |
|
4275 | 4280 | |
|
4276 | 4281 | if (show and (mark or unmark)) or (mark and unmark): |
|
4277 | 4282 | raise error.Abort(_("too many options specified")) |
|
4278 | 4283 | if pats and all: |
|
4279 | 4284 | raise error.Abort(_("can't specify --all and patterns")) |
|
4280 | 4285 | if not (all or pats or show or mark or unmark): |
|
4281 | 4286 | raise error.Abort(_('no files or directories specified'), |
|
4282 | 4287 | hint=('use --all to re-merge all unresolved files')) |
|
4283 | 4288 | |
|
4284 | 4289 | if show: |
|
4285 | 4290 | ui.pager('resolve') |
|
4286 | 4291 | fm = ui.formatter('resolve', opts) |
|
4287 | 4292 | ms = mergemod.mergestate.read(repo) |
|
4288 | 4293 | m = scmutil.match(repo[None], pats, opts) |
|
4289 | 4294 | for f in ms: |
|
4290 | 4295 | if not m(f): |
|
4291 | 4296 | continue |
|
4292 | 4297 | l = 'resolve.' + {'u': 'unresolved', 'r': 'resolved', |
|
4293 | 4298 | 'd': 'driverresolved'}[ms[f]] |
|
4294 | 4299 | fm.startitem() |
|
4295 | 4300 | fm.condwrite(not nostatus, 'status', '%s ', ms[f].upper(), label=l) |
|
4296 | 4301 | fm.write('path', '%s\n', f, label=l) |
|
4297 | 4302 | fm.end() |
|
4298 | 4303 | return 0 |
|
4299 | 4304 | |
|
4300 | 4305 | with repo.wlock(): |
|
4301 | 4306 | ms = mergemod.mergestate.read(repo) |
|
4302 | 4307 | |
|
4303 | 4308 | if not (ms.active() or repo.dirstate.p2() != nullid): |
|
4304 | 4309 | raise error.Abort( |
|
4305 | 4310 | _('resolve command not applicable when not merging')) |
|
4306 | 4311 | |
|
4307 | 4312 | wctx = repo[None] |
|
4308 | 4313 | |
|
4309 | 4314 | if ms.mergedriver and ms.mdstate() == 'u': |
|
4310 | 4315 | proceed = mergemod.driverpreprocess(repo, ms, wctx) |
|
4311 | 4316 | ms.commit() |
|
4312 | 4317 | # allow mark and unmark to go through |
|
4313 | 4318 | if not mark and not unmark and not proceed: |
|
4314 | 4319 | return 1 |
|
4315 | 4320 | |
|
4316 | 4321 | m = scmutil.match(wctx, pats, opts) |
|
4317 | 4322 | ret = 0 |
|
4318 | 4323 | didwork = False |
|
4319 | 4324 | runconclude = False |
|
4320 | 4325 | |
|
4321 | 4326 | tocomplete = [] |
|
4322 | 4327 | for f in ms: |
|
4323 | 4328 | if not m(f): |
|
4324 | 4329 | continue |
|
4325 | 4330 | |
|
4326 | 4331 | didwork = True |
|
4327 | 4332 | |
|
4328 | 4333 | # don't let driver-resolved files be marked, and run the conclude |
|
4329 | 4334 | # step if asked to resolve |
|
4330 | 4335 | if ms[f] == "d": |
|
4331 | 4336 | exact = m.exact(f) |
|
4332 | 4337 | if mark: |
|
4333 | 4338 | if exact: |
|
4334 | 4339 | ui.warn(_('not marking %s as it is driver-resolved\n') |
|
4335 | 4340 | % f) |
|
4336 | 4341 | elif unmark: |
|
4337 | 4342 | if exact: |
|
4338 | 4343 | ui.warn(_('not unmarking %s as it is driver-resolved\n') |
|
4339 | 4344 | % f) |
|
4340 | 4345 | else: |
|
4341 | 4346 | runconclude = True |
|
4342 | 4347 | continue |
|
4343 | 4348 | |
|
4344 | 4349 | if mark: |
|
4345 | 4350 | ms.mark(f, "r") |
|
4346 | 4351 | elif unmark: |
|
4347 | 4352 | ms.mark(f, "u") |
|
4348 | 4353 | else: |
|
4349 | 4354 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
4350 | 4355 | a = repo.wjoin(f) |
|
4351 | 4356 | try: |
|
4352 | 4357 | util.copyfile(a, a + ".resolve") |
|
4353 | 4358 | except (IOError, OSError) as inst: |
|
4354 | 4359 | if inst.errno != errno.ENOENT: |
|
4355 | 4360 | raise |
|
4356 | 4361 | |
|
4357 | 4362 | try: |
|
4358 | 4363 | # preresolve file |
|
4359 | 4364 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
4360 | 4365 | 'resolve') |
|
4361 | 4366 | complete, r = ms.preresolve(f, wctx) |
|
4362 | 4367 | if not complete: |
|
4363 | 4368 | tocomplete.append(f) |
|
4364 | 4369 | elif r: |
|
4365 | 4370 | ret = 1 |
|
4366 | 4371 | finally: |
|
4367 | 4372 | ui.setconfig('ui', 'forcemerge', '', 'resolve') |
|
4368 | 4373 | ms.commit() |
|
4369 | 4374 | |
|
4370 | 4375 | # replace filemerge's .orig file with our resolve file, but only |
|
4371 | 4376 | # for merges that are complete |
|
4372 | 4377 | if complete: |
|
4373 | 4378 | try: |
|
4374 | 4379 | util.rename(a + ".resolve", |
|
4375 | 4380 | scmutil.origpath(ui, repo, a)) |
|
4376 | 4381 | except OSError as inst: |
|
4377 | 4382 | if inst.errno != errno.ENOENT: |
|
4378 | 4383 | raise |
|
4379 | 4384 | |
|
4380 | 4385 | for f in tocomplete: |
|
4381 | 4386 | try: |
|
4382 | 4387 | # resolve file |
|
4383 | 4388 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
4384 | 4389 | 'resolve') |
|
4385 | 4390 | r = ms.resolve(f, wctx) |
|
4386 | 4391 | if r: |
|
4387 | 4392 | ret = 1 |
|
4388 | 4393 | finally: |
|
4389 | 4394 | ui.setconfig('ui', 'forcemerge', '', 'resolve') |
|
4390 | 4395 | ms.commit() |
|
4391 | 4396 | |
|
4392 | 4397 | # replace filemerge's .orig file with our resolve file |
|
4393 | 4398 | a = repo.wjoin(f) |
|
4394 | 4399 | try: |
|
4395 | 4400 | util.rename(a + ".resolve", scmutil.origpath(ui, repo, a)) |
|
4396 | 4401 | except OSError as inst: |
|
4397 | 4402 | if inst.errno != errno.ENOENT: |
|
4398 | 4403 | raise |
|
4399 | 4404 | |
|
4400 | 4405 | ms.commit() |
|
4401 | 4406 | ms.recordactions() |
|
4402 | 4407 | |
|
4403 | 4408 | if not didwork and pats: |
|
4404 | 4409 | hint = None |
|
4405 | 4410 | if not any([p for p in pats if p.find(':') >= 0]): |
|
4406 | 4411 | pats = ['path:%s' % p for p in pats] |
|
4407 | 4412 | m = scmutil.match(wctx, pats, opts) |
|
4408 | 4413 | for f in ms: |
|
4409 | 4414 | if not m(f): |
|
4410 | 4415 | continue |
|
4411 | 4416 | flags = ''.join(['-%s ' % o[0] for o in flaglist |
|
4412 | 4417 | if opts.get(o)]) |
|
4413 | 4418 | hint = _("(try: hg resolve %s%s)\n") % ( |
|
4414 | 4419 | flags, |
|
4415 | 4420 | ' '.join(pats)) |
|
4416 | 4421 | break |
|
4417 | 4422 | ui.warn(_("arguments do not match paths that need resolving\n")) |
|
4418 | 4423 | if hint: |
|
4419 | 4424 | ui.warn(hint) |
|
4420 | 4425 | elif ms.mergedriver and ms.mdstate() != 's': |
|
4421 | 4426 | # run conclude step when either a driver-resolved file is requested |
|
4422 | 4427 | # or there are no driver-resolved files |
|
4423 | 4428 | # we can't use 'ret' to determine whether any files are unresolved |
|
4424 | 4429 | # because we might not have tried to resolve some |
|
4425 | 4430 | if ((runconclude or not list(ms.driverresolved())) |
|
4426 | 4431 | and not list(ms.unresolved())): |
|
4427 | 4432 | proceed = mergemod.driverconclude(repo, ms, wctx) |
|
4428 | 4433 | ms.commit() |
|
4429 | 4434 | if not proceed: |
|
4430 | 4435 | return 1 |
|
4431 | 4436 | |
|
4432 | 4437 | # Nudge users into finishing an unfinished operation |
|
4433 | 4438 | unresolvedf = list(ms.unresolved()) |
|
4434 | 4439 | driverresolvedf = list(ms.driverresolved()) |
|
4435 | 4440 | if not unresolvedf and not driverresolvedf: |
|
4436 | 4441 | ui.status(_('(no more unresolved files)\n')) |
|
4437 | 4442 | cmdutil.checkafterresolved(repo) |
|
4438 | 4443 | elif not unresolvedf: |
|
4439 | 4444 | ui.status(_('(no more unresolved files -- ' |
|
4440 | 4445 | 'run "hg resolve --all" to conclude)\n')) |
|
4441 | 4446 | |
|
4442 | 4447 | return ret |
|
4443 | 4448 | |
|
4444 | 4449 | @command('revert', |
|
4445 | 4450 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
4446 | 4451 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
4447 | 4452 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), |
|
4448 | 4453 | ('C', 'no-backup', None, _('do not save backup copies of files')), |
|
4449 | 4454 | ('i', 'interactive', None, |
|
4450 | 4455 | _('interactively select the changes (EXPERIMENTAL)')), |
|
4451 | 4456 | ] + walkopts + dryrunopts, |
|
4452 | 4457 | _('[OPTION]... [-r REV] [NAME]...')) |
|
4453 | 4458 | def revert(ui, repo, *pats, **opts): |
|
4454 | 4459 | """restore files to their checkout state |
|
4455 | 4460 | |
|
4456 | 4461 | .. note:: |
|
4457 | 4462 | |
|
4458 | 4463 | To check out earlier revisions, you should use :hg:`update REV`. |
|
4459 | 4464 | To cancel an uncommitted merge (and lose your changes), |
|
4460 | 4465 | use :hg:`update --clean .`. |
|
4461 | 4466 | |
|
4462 | 4467 | With no revision specified, revert the specified files or directories |
|
4463 | 4468 | to the contents they had in the parent of the working directory. |
|
4464 | 4469 | This restores the contents of files to an unmodified |
|
4465 | 4470 | state and unschedules adds, removes, copies, and renames. If the |
|
4466 | 4471 | working directory has two parents, you must explicitly specify a |
|
4467 | 4472 | revision. |
|
4468 | 4473 | |
|
4469 | 4474 | Using the -r/--rev or -d/--date options, revert the given files or |
|
4470 | 4475 | directories to their states as of a specific revision. Because |
|
4471 | 4476 | revert does not change the working directory parents, this will |
|
4472 | 4477 | cause these files to appear modified. This can be helpful to "back |
|
4473 | 4478 | out" some or all of an earlier change. See :hg:`backout` for a |
|
4474 | 4479 | related method. |
|
4475 | 4480 | |
|
4476 | 4481 | Modified files are saved with a .orig suffix before reverting. |
|
4477 | 4482 | To disable these backups, use --no-backup. It is possible to store |
|
4478 | 4483 | the backup files in a custom directory relative to the root of the |
|
4479 | 4484 | repository by setting the ``ui.origbackuppath`` configuration |
|
4480 | 4485 | option. |
|
4481 | 4486 | |
|
4482 | 4487 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4483 | 4488 | |
|
4484 | 4489 | See :hg:`help backout` for a way to reverse the effect of an |
|
4485 | 4490 | earlier changeset. |
|
4486 | 4491 | |
|
4487 | 4492 | Returns 0 on success. |
|
4488 | 4493 | """ |
|
4489 | 4494 | |
|
4490 | 4495 | if opts.get("date"): |
|
4491 | 4496 | if opts.get("rev"): |
|
4492 | 4497 | raise error.Abort(_("you can't specify a revision and a date")) |
|
4493 | 4498 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
4494 | 4499 | |
|
4495 | 4500 | parent, p2 = repo.dirstate.parents() |
|
4496 | 4501 | if not opts.get('rev') and p2 != nullid: |
|
4497 | 4502 | # revert after merge is a trap for new users (issue2915) |
|
4498 | 4503 | raise error.Abort(_('uncommitted merge with no revision specified'), |
|
4499 | 4504 | hint=_("use 'hg update' or see 'hg help revert'")) |
|
4500 | 4505 | |
|
4501 | 4506 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
4502 | 4507 | |
|
4503 | 4508 | if (not (pats or opts.get('include') or opts.get('exclude') or |
|
4504 | 4509 | opts.get('all') or opts.get('interactive'))): |
|
4505 | 4510 | msg = _("no files or directories specified") |
|
4506 | 4511 | if p2 != nullid: |
|
4507 | 4512 | hint = _("uncommitted merge, use --all to discard all changes," |
|
4508 | 4513 | " or 'hg update -C .' to abort the merge") |
|
4509 | 4514 | raise error.Abort(msg, hint=hint) |
|
4510 | 4515 | dirty = any(repo.status()) |
|
4511 | 4516 | node = ctx.node() |
|
4512 | 4517 | if node != parent: |
|
4513 | 4518 | if dirty: |
|
4514 | 4519 | hint = _("uncommitted changes, use --all to discard all" |
|
4515 | 4520 | " changes, or 'hg update %s' to update") % ctx.rev() |
|
4516 | 4521 | else: |
|
4517 | 4522 | hint = _("use --all to revert all files," |
|
4518 | 4523 | " or 'hg update %s' to update") % ctx.rev() |
|
4519 | 4524 | elif dirty: |
|
4520 | 4525 | hint = _("uncommitted changes, use --all to discard all changes") |
|
4521 | 4526 | else: |
|
4522 | 4527 | hint = _("use --all to revert all files") |
|
4523 | 4528 | raise error.Abort(msg, hint=hint) |
|
4524 | 4529 | |
|
4525 | 4530 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) |
|
4526 | 4531 | |
|
4527 | 4532 | @command('rollback', dryrunopts + |
|
4528 | 4533 | [('f', 'force', False, _('ignore safety measures'))]) |
|
4529 | 4534 | def rollback(ui, repo, **opts): |
|
4530 | 4535 | """roll back the last transaction (DANGEROUS) (DEPRECATED) |
|
4531 | 4536 | |
|
4532 | 4537 | Please use :hg:`commit --amend` instead of rollback to correct |
|
4533 | 4538 | mistakes in the last commit. |
|
4534 | 4539 | |
|
4535 | 4540 | This command should be used with care. There is only one level of |
|
4536 | 4541 | rollback, and there is no way to undo a rollback. It will also |
|
4537 | 4542 | restore the dirstate at the time of the last transaction, losing |
|
4538 | 4543 | any dirstate changes since that time. This command does not alter |
|
4539 | 4544 | the working directory. |
|
4540 | 4545 | |
|
4541 | 4546 | Transactions are used to encapsulate the effects of all commands |
|
4542 | 4547 | that create new changesets or propagate existing changesets into a |
|
4543 | 4548 | repository. |
|
4544 | 4549 | |
|
4545 | 4550 | .. container:: verbose |
|
4546 | 4551 | |
|
4547 | 4552 | For example, the following commands are transactional, and their |
|
4548 | 4553 | effects can be rolled back: |
|
4549 | 4554 | |
|
4550 | 4555 | - commit |
|
4551 | 4556 | - import |
|
4552 | 4557 | - pull |
|
4553 | 4558 | - push (with this repository as the destination) |
|
4554 | 4559 | - unbundle |
|
4555 | 4560 | |
|
4556 | 4561 | To avoid permanent data loss, rollback will refuse to rollback a |
|
4557 | 4562 | commit transaction if it isn't checked out. Use --force to |
|
4558 | 4563 | override this protection. |
|
4559 | 4564 | |
|
4560 | 4565 | The rollback command can be entirely disabled by setting the |
|
4561 | 4566 | ``ui.rollback`` configuration setting to false. If you're here |
|
4562 | 4567 | because you want to use rollback and it's disabled, you can |
|
4563 | 4568 | re-enable the command by setting ``ui.rollback`` to true. |
|
4564 | 4569 | |
|
4565 | 4570 | This command is not intended for use on public repositories. Once |
|
4566 | 4571 | changes are visible for pull by other users, rolling a transaction |
|
4567 | 4572 | back locally is ineffective (someone else may already have pulled |
|
4568 | 4573 | the changes). Furthermore, a race is possible with readers of the |
|
4569 | 4574 | repository; for example an in-progress pull from the repository |
|
4570 | 4575 | may fail if a rollback is performed. |
|
4571 | 4576 | |
|
4572 | 4577 | Returns 0 on success, 1 if no rollback data is available. |
|
4573 | 4578 | """ |
|
4574 | 4579 | if not ui.configbool('ui', 'rollback', True): |
|
4575 | 4580 | raise error.Abort(_('rollback is disabled because it is unsafe'), |
|
4576 | 4581 | hint=('see `hg help -v rollback` for information')) |
|
4577 | 4582 | return repo.rollback(dryrun=opts.get(r'dry_run'), |
|
4578 | 4583 | force=opts.get(r'force')) |
|
4579 | 4584 | |
|
4580 | 4585 | @command('root', []) |
|
4581 | 4586 | def root(ui, repo): |
|
4582 | 4587 | """print the root (top) of the current working directory |
|
4583 | 4588 | |
|
4584 | 4589 | Print the root directory of the current repository. |
|
4585 | 4590 | |
|
4586 | 4591 | Returns 0 on success. |
|
4587 | 4592 | """ |
|
4588 | 4593 | ui.write(repo.root + "\n") |
|
4589 | 4594 | |
|
4590 | 4595 | @command('^serve', |
|
4591 | 4596 | [('A', 'accesslog', '', _('name of access log file to write to'), |
|
4592 | 4597 | _('FILE')), |
|
4593 | 4598 | ('d', 'daemon', None, _('run server in background')), |
|
4594 | 4599 | ('', 'daemon-postexec', [], _('used internally by daemon mode')), |
|
4595 | 4600 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), |
|
4596 | 4601 | # use string type, then we can check if something was passed |
|
4597 | 4602 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), |
|
4598 | 4603 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), |
|
4599 | 4604 | _('ADDR')), |
|
4600 | 4605 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), |
|
4601 | 4606 | _('PREFIX')), |
|
4602 | 4607 | ('n', 'name', '', |
|
4603 | 4608 | _('name to show in web pages (default: working directory)'), _('NAME')), |
|
4604 | 4609 | ('', 'web-conf', '', |
|
4605 | 4610 | _("name of the hgweb config file (see 'hg help hgweb')"), _('FILE')), |
|
4606 | 4611 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), |
|
4607 | 4612 | _('FILE')), |
|
4608 | 4613 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), |
|
4609 | 4614 | ('', 'stdio', None, _('for remote clients (ADVANCED)')), |
|
4610 | 4615 | ('', 'cmdserver', '', _('for remote clients (ADVANCED)'), _('MODE')), |
|
4611 | 4616 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), |
|
4612 | 4617 | ('', 'style', '', _('template style to use'), _('STYLE')), |
|
4613 | 4618 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
4614 | 4619 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))] |
|
4615 | 4620 | + subrepoopts, |
|
4616 | 4621 | _('[OPTION]...'), |
|
4617 | 4622 | optionalrepo=True) |
|
4618 | 4623 | def serve(ui, repo, **opts): |
|
4619 | 4624 | """start stand-alone webserver |
|
4620 | 4625 | |
|
4621 | 4626 | Start a local HTTP repository browser and pull server. You can use |
|
4622 | 4627 | this for ad-hoc sharing and browsing of repositories. It is |
|
4623 | 4628 | recommended to use a real web server to serve a repository for |
|
4624 | 4629 | longer periods of time. |
|
4625 | 4630 | |
|
4626 | 4631 | Please note that the server does not implement access control. |
|
4627 | 4632 | This means that, by default, anybody can read from the server and |
|
4628 | 4633 | nobody can write to it by default. Set the ``web.allow_push`` |
|
4629 | 4634 | option to ``*`` to allow everybody to push to the server. You |
|
4630 | 4635 | should use a real web server if you need to authenticate users. |
|
4631 | 4636 | |
|
4632 | 4637 | By default, the server logs accesses to stdout and errors to |
|
4633 | 4638 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
4634 | 4639 | files. |
|
4635 | 4640 | |
|
4636 | 4641 | To have the server choose a free port number to listen on, specify |
|
4637 | 4642 | a port number of 0; in this case, the server will print the port |
|
4638 | 4643 | number it uses. |
|
4639 | 4644 | |
|
4640 | 4645 | Returns 0 on success. |
|
4641 | 4646 | """ |
|
4642 | 4647 | |
|
4643 | 4648 | opts = pycompat.byteskwargs(opts) |
|
4644 | 4649 | if opts["stdio"] and opts["cmdserver"]: |
|
4645 | 4650 | raise error.Abort(_("cannot use --stdio with --cmdserver")) |
|
4646 | 4651 | |
|
4647 | 4652 | if opts["stdio"]: |
|
4648 | 4653 | if repo is None: |
|
4649 | 4654 | raise error.RepoError(_("there is no Mercurial repository here" |
|
4650 | 4655 | " (.hg not found)")) |
|
4651 | 4656 | s = sshserver.sshserver(ui, repo) |
|
4652 | 4657 | s.serve_forever() |
|
4653 | 4658 | |
|
4654 | 4659 | service = server.createservice(ui, repo, opts) |
|
4655 | 4660 | return server.runservice(opts, initfn=service.init, runfn=service.run) |
|
4656 | 4661 | |
|
4657 | 4662 | @command('^status|st', |
|
4658 | 4663 | [('A', 'all', None, _('show status of all files')), |
|
4659 | 4664 | ('m', 'modified', None, _('show only modified files')), |
|
4660 | 4665 | ('a', 'added', None, _('show only added files')), |
|
4661 | 4666 | ('r', 'removed', None, _('show only removed files')), |
|
4662 | 4667 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
4663 | 4668 | ('c', 'clean', None, _('show only files without changes')), |
|
4664 | 4669 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
4665 | 4670 | ('i', 'ignored', None, _('show only ignored files')), |
|
4666 | 4671 | ('n', 'no-status', None, _('hide status prefix')), |
|
4667 | 4672 | ('C', 'copies', None, _('show source of copied files')), |
|
4668 | 4673 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
4669 | 4674 | ('', 'rev', [], _('show difference from revision'), _('REV')), |
|
4670 | 4675 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), |
|
4671 | 4676 | ] + walkopts + subrepoopts + formatteropts, |
|
4672 | 4677 | _('[OPTION]... [FILE]...'), |
|
4673 | 4678 | inferrepo=True) |
|
4674 | 4679 | def status(ui, repo, *pats, **opts): |
|
4675 | 4680 | """show changed files in the working directory |
|
4676 | 4681 | |
|
4677 | 4682 | Show status of files in the repository. If names are given, only |
|
4678 | 4683 | files that match are shown. Files that are clean or ignored or |
|
4679 | 4684 | the source of a copy/move operation, are not listed unless |
|
4680 | 4685 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
4681 | 4686 | Unless options described with "show only ..." are given, the |
|
4682 | 4687 | options -mardu are used. |
|
4683 | 4688 | |
|
4684 | 4689 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
4685 | 4690 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
4686 | 4691 | |
|
4687 | 4692 | .. note:: |
|
4688 | 4693 | |
|
4689 | 4694 | :hg:`status` may appear to disagree with diff if permissions have |
|
4690 | 4695 | changed or a merge has occurred. The standard diff format does |
|
4691 | 4696 | not report permission changes and diff only reports changes |
|
4692 | 4697 | relative to one merge parent. |
|
4693 | 4698 | |
|
4694 | 4699 | If one revision is given, it is used as the base revision. |
|
4695 | 4700 | If two revisions are given, the differences between them are |
|
4696 | 4701 | shown. The --change option can also be used as a shortcut to list |
|
4697 | 4702 | the changed files of a revision from its first parent. |
|
4698 | 4703 | |
|
4699 | 4704 | The codes used to show the status of files are:: |
|
4700 | 4705 | |
|
4701 | 4706 | M = modified |
|
4702 | 4707 | A = added |
|
4703 | 4708 | R = removed |
|
4704 | 4709 | C = clean |
|
4705 | 4710 | ! = missing (deleted by non-hg command, but still tracked) |
|
4706 | 4711 | ? = not tracked |
|
4707 | 4712 | I = ignored |
|
4708 | 4713 | = origin of the previous file (with --copies) |
|
4709 | 4714 | |
|
4710 | 4715 | .. container:: verbose |
|
4711 | 4716 | |
|
4712 | 4717 | Examples: |
|
4713 | 4718 | |
|
4714 | 4719 | - show changes in the working directory relative to a |
|
4715 | 4720 | changeset:: |
|
4716 | 4721 | |
|
4717 | 4722 | hg status --rev 9353 |
|
4718 | 4723 | |
|
4719 | 4724 | - show changes in the working directory relative to the |
|
4720 | 4725 | current directory (see :hg:`help patterns` for more information):: |
|
4721 | 4726 | |
|
4722 | 4727 | hg status re: |
|
4723 | 4728 | |
|
4724 | 4729 | - show all changes including copies in an existing changeset:: |
|
4725 | 4730 | |
|
4726 | 4731 | hg status --copies --change 9353 |
|
4727 | 4732 | |
|
4728 | 4733 | - get a NUL separated list of added files, suitable for xargs:: |
|
4729 | 4734 | |
|
4730 | 4735 | hg status -an0 |
|
4731 | 4736 | |
|
4732 | 4737 | Returns 0 on success. |
|
4733 | 4738 | """ |
|
4734 | 4739 | |
|
4735 | 4740 | opts = pycompat.byteskwargs(opts) |
|
4736 | 4741 | revs = opts.get('rev') |
|
4737 | 4742 | change = opts.get('change') |
|
4738 | 4743 | |
|
4739 | 4744 | if revs and change: |
|
4740 | 4745 | msg = _('cannot specify --rev and --change at the same time') |
|
4741 | 4746 | raise error.Abort(msg) |
|
4742 | 4747 | elif change: |
|
4743 | 4748 | node2 = scmutil.revsingle(repo, change, None).node() |
|
4744 | 4749 | node1 = repo[node2].p1().node() |
|
4745 | 4750 | else: |
|
4746 | 4751 | node1, node2 = scmutil.revpair(repo, revs) |
|
4747 | 4752 | |
|
4748 | 4753 | if pats or ui.configbool('commands', 'status.relative'): |
|
4749 | 4754 | cwd = repo.getcwd() |
|
4750 | 4755 | else: |
|
4751 | 4756 | cwd = '' |
|
4752 | 4757 | |
|
4753 | 4758 | if opts.get('print0'): |
|
4754 | 4759 | end = '\0' |
|
4755 | 4760 | else: |
|
4756 | 4761 | end = '\n' |
|
4757 | 4762 | copy = {} |
|
4758 | 4763 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
4759 | 4764 | show = [k for k in states if opts.get(k)] |
|
4760 | 4765 | if opts.get('all'): |
|
4761 | 4766 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
4762 | 4767 | if not show: |
|
4763 | 4768 | if ui.quiet: |
|
4764 | 4769 | show = states[:4] |
|
4765 | 4770 | else: |
|
4766 | 4771 | show = states[:5] |
|
4767 | 4772 | |
|
4768 | 4773 | m = scmutil.match(repo[node2], pats, opts) |
|
4769 | 4774 | stat = repo.status(node1, node2, m, |
|
4770 | 4775 | 'ignored' in show, 'clean' in show, 'unknown' in show, |
|
4771 | 4776 | opts.get('subrepos')) |
|
4772 | 4777 | changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat) |
|
4773 | 4778 | |
|
4774 | 4779 | if (opts.get('all') or opts.get('copies') |
|
4775 | 4780 | or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): |
|
4776 | 4781 | copy = copies.pathcopies(repo[node1], repo[node2], m) |
|
4777 | 4782 | |
|
4778 | 4783 | ui.pager('status') |
|
4779 | 4784 | fm = ui.formatter('status', opts) |
|
4780 | 4785 | fmt = '%s' + end |
|
4781 | 4786 | showchar = not opts.get('no_status') |
|
4782 | 4787 | |
|
4783 | 4788 | for state, char, files in changestates: |
|
4784 | 4789 | if state in show: |
|
4785 | 4790 | label = 'status.' + state |
|
4786 | 4791 | for f in files: |
|
4787 | 4792 | fm.startitem() |
|
4788 | 4793 | fm.condwrite(showchar, 'status', '%s ', char, label=label) |
|
4789 | 4794 | fm.write('path', fmt, repo.pathto(f, cwd), label=label) |
|
4790 | 4795 | if f in copy: |
|
4791 | 4796 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), |
|
4792 | 4797 | label='status.copied') |
|
4793 | 4798 | fm.end() |
|
4794 | 4799 | |
|
4795 | 4800 | @command('^summary|sum', |
|
4796 | 4801 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') |
|
4797 | 4802 | def summary(ui, repo, **opts): |
|
4798 | 4803 | """summarize working directory state |
|
4799 | 4804 | |
|
4800 | 4805 | This generates a brief summary of the working directory state, |
|
4801 | 4806 | including parents, branch, commit status, phase and available updates. |
|
4802 | 4807 | |
|
4803 | 4808 | With the --remote option, this will check the default paths for |
|
4804 | 4809 | incoming and outgoing changes. This can be time-consuming. |
|
4805 | 4810 | |
|
4806 | 4811 | Returns 0 on success. |
|
4807 | 4812 | """ |
|
4808 | 4813 | |
|
4809 | 4814 | opts = pycompat.byteskwargs(opts) |
|
4810 | 4815 | ui.pager('summary') |
|
4811 | 4816 | ctx = repo[None] |
|
4812 | 4817 | parents = ctx.parents() |
|
4813 | 4818 | pnode = parents[0].node() |
|
4814 | 4819 | marks = [] |
|
4815 | 4820 | |
|
4816 | 4821 | ms = None |
|
4817 | 4822 | try: |
|
4818 | 4823 | ms = mergemod.mergestate.read(repo) |
|
4819 | 4824 | except error.UnsupportedMergeRecords as e: |
|
4820 | 4825 | s = ' '.join(e.recordtypes) |
|
4821 | 4826 | ui.warn( |
|
4822 | 4827 | _('warning: merge state has unsupported record types: %s\n') % s) |
|
4823 | 4828 | unresolved = 0 |
|
4824 | 4829 | else: |
|
4825 | 4830 | unresolved = [f for f in ms if ms[f] == 'u'] |
|
4826 | 4831 | |
|
4827 | 4832 | for p in parents: |
|
4828 | 4833 | # label with log.changeset (instead of log.parent) since this |
|
4829 | 4834 | # shows a working directory parent *changeset*: |
|
4830 | 4835 | # i18n: column positioning for "hg summary" |
|
4831 | 4836 | ui.write(_('parent: %d:%s ') % (p.rev(), p), |
|
4832 | 4837 | label=cmdutil._changesetlabels(p)) |
|
4833 | 4838 | ui.write(' '.join(p.tags()), label='log.tag') |
|
4834 | 4839 | if p.bookmarks(): |
|
4835 | 4840 | marks.extend(p.bookmarks()) |
|
4836 | 4841 | if p.rev() == -1: |
|
4837 | 4842 | if not len(repo): |
|
4838 | 4843 | ui.write(_(' (empty repository)')) |
|
4839 | 4844 | else: |
|
4840 | 4845 | ui.write(_(' (no revision checked out)')) |
|
4841 | 4846 | if p.obsolete(): |
|
4842 | 4847 | ui.write(_(' (obsolete)')) |
|
4843 | 4848 | if p.troubled(): |
|
4844 | 4849 | ui.write(' (' |
|
4845 | 4850 | + ', '.join(ui.label(trouble, 'trouble.%s' % trouble) |
|
4846 | 4851 | for trouble in p.troubles()) |
|
4847 | 4852 | + ')') |
|
4848 | 4853 | ui.write('\n') |
|
4849 | 4854 | if p.description(): |
|
4850 | 4855 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', |
|
4851 | 4856 | label='log.summary') |
|
4852 | 4857 | |
|
4853 | 4858 | branch = ctx.branch() |
|
4854 | 4859 | bheads = repo.branchheads(branch) |
|
4855 | 4860 | # i18n: column positioning for "hg summary" |
|
4856 | 4861 | m = _('branch: %s\n') % branch |
|
4857 | 4862 | if branch != 'default': |
|
4858 | 4863 | ui.write(m, label='log.branch') |
|
4859 | 4864 | else: |
|
4860 | 4865 | ui.status(m, label='log.branch') |
|
4861 | 4866 | |
|
4862 | 4867 | if marks: |
|
4863 | 4868 | active = repo._activebookmark |
|
4864 | 4869 | # i18n: column positioning for "hg summary" |
|
4865 | 4870 | ui.write(_('bookmarks:'), label='log.bookmark') |
|
4866 | 4871 | if active is not None: |
|
4867 | 4872 | if active in marks: |
|
4868 | 4873 | ui.write(' *' + active, label=activebookmarklabel) |
|
4869 | 4874 | marks.remove(active) |
|
4870 | 4875 | else: |
|
4871 | 4876 | ui.write(' [%s]' % active, label=activebookmarklabel) |
|
4872 | 4877 | for m in marks: |
|
4873 | 4878 | ui.write(' ' + m, label='log.bookmark') |
|
4874 | 4879 | ui.write('\n', label='log.bookmark') |
|
4875 | 4880 | |
|
4876 | 4881 | status = repo.status(unknown=True) |
|
4877 | 4882 | |
|
4878 | 4883 | c = repo.dirstate.copies() |
|
4879 | 4884 | copied, renamed = [], [] |
|
4880 | 4885 | for d, s in c.iteritems(): |
|
4881 | 4886 | if s in status.removed: |
|
4882 | 4887 | status.removed.remove(s) |
|
4883 | 4888 | renamed.append(d) |
|
4884 | 4889 | else: |
|
4885 | 4890 | copied.append(d) |
|
4886 | 4891 | if d in status.added: |
|
4887 | 4892 | status.added.remove(d) |
|
4888 | 4893 | |
|
4889 | 4894 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
4890 | 4895 | |
|
4891 | 4896 | labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), |
|
4892 | 4897 | (ui.label(_('%d added'), 'status.added'), status.added), |
|
4893 | 4898 | (ui.label(_('%d removed'), 'status.removed'), status.removed), |
|
4894 | 4899 | (ui.label(_('%d renamed'), 'status.copied'), renamed), |
|
4895 | 4900 | (ui.label(_('%d copied'), 'status.copied'), copied), |
|
4896 | 4901 | (ui.label(_('%d deleted'), 'status.deleted'), status.deleted), |
|
4897 | 4902 | (ui.label(_('%d unknown'), 'status.unknown'), status.unknown), |
|
4898 | 4903 | (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), |
|
4899 | 4904 | (ui.label(_('%d subrepos'), 'status.modified'), subs)] |
|
4900 | 4905 | t = [] |
|
4901 | 4906 | for l, s in labels: |
|
4902 | 4907 | if s: |
|
4903 | 4908 | t.append(l % len(s)) |
|
4904 | 4909 | |
|
4905 | 4910 | t = ', '.join(t) |
|
4906 | 4911 | cleanworkdir = False |
|
4907 | 4912 | |
|
4908 | 4913 | if repo.vfs.exists('graftstate'): |
|
4909 | 4914 | t += _(' (graft in progress)') |
|
4910 | 4915 | if repo.vfs.exists('updatestate'): |
|
4911 | 4916 | t += _(' (interrupted update)') |
|
4912 | 4917 | elif len(parents) > 1: |
|
4913 | 4918 | t += _(' (merge)') |
|
4914 | 4919 | elif branch != parents[0].branch(): |
|
4915 | 4920 | t += _(' (new branch)') |
|
4916 | 4921 | elif (parents[0].closesbranch() and |
|
4917 | 4922 | pnode in repo.branchheads(branch, closed=True)): |
|
4918 | 4923 | t += _(' (head closed)') |
|
4919 | 4924 | elif not (status.modified or status.added or status.removed or renamed or |
|
4920 | 4925 | copied or subs): |
|
4921 | 4926 | t += _(' (clean)') |
|
4922 | 4927 | cleanworkdir = True |
|
4923 | 4928 | elif pnode not in bheads: |
|
4924 | 4929 | t += _(' (new branch head)') |
|
4925 | 4930 | |
|
4926 | 4931 | if parents: |
|
4927 | 4932 | pendingphase = max(p.phase() for p in parents) |
|
4928 | 4933 | else: |
|
4929 | 4934 | pendingphase = phases.public |
|
4930 | 4935 | |
|
4931 | 4936 | if pendingphase > phases.newcommitphase(ui): |
|
4932 | 4937 | t += ' (%s)' % phases.phasenames[pendingphase] |
|
4933 | 4938 | |
|
4934 | 4939 | if cleanworkdir: |
|
4935 | 4940 | # i18n: column positioning for "hg summary" |
|
4936 | 4941 | ui.status(_('commit: %s\n') % t.strip()) |
|
4937 | 4942 | else: |
|
4938 | 4943 | # i18n: column positioning for "hg summary" |
|
4939 | 4944 | ui.write(_('commit: %s\n') % t.strip()) |
|
4940 | 4945 | |
|
4941 | 4946 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
4942 | 4947 | new = len(repo.changelog.findmissing([pctx.node() for pctx in parents], |
|
4943 | 4948 | bheads)) |
|
4944 | 4949 | |
|
4945 | 4950 | if new == 0: |
|
4946 | 4951 | # i18n: column positioning for "hg summary" |
|
4947 | 4952 | ui.status(_('update: (current)\n')) |
|
4948 | 4953 | elif pnode not in bheads: |
|
4949 | 4954 | # i18n: column positioning for "hg summary" |
|
4950 | 4955 | ui.write(_('update: %d new changesets (update)\n') % new) |
|
4951 | 4956 | else: |
|
4952 | 4957 | # i18n: column positioning for "hg summary" |
|
4953 | 4958 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % |
|
4954 | 4959 | (new, len(bheads))) |
|
4955 | 4960 | |
|
4956 | 4961 | t = [] |
|
4957 | 4962 | draft = len(repo.revs('draft()')) |
|
4958 | 4963 | if draft: |
|
4959 | 4964 | t.append(_('%d draft') % draft) |
|
4960 | 4965 | secret = len(repo.revs('secret()')) |
|
4961 | 4966 | if secret: |
|
4962 | 4967 | t.append(_('%d secret') % secret) |
|
4963 | 4968 | |
|
4964 | 4969 | if draft or secret: |
|
4965 | 4970 | ui.status(_('phases: %s\n') % ', '.join(t)) |
|
4966 | 4971 | |
|
4967 | 4972 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
4968 | 4973 | for trouble in ("unstable", "divergent", "bumped"): |
|
4969 | 4974 | numtrouble = len(repo.revs(trouble + "()")) |
|
4970 | 4975 | # We write all the possibilities to ease translation |
|
4971 | 4976 | troublemsg = { |
|
4972 | 4977 | "unstable": _("unstable: %d changesets"), |
|
4973 | 4978 | "divergent": _("divergent: %d changesets"), |
|
4974 | 4979 | "bumped": _("bumped: %d changesets"), |
|
4975 | 4980 | } |
|
4976 | 4981 | if numtrouble > 0: |
|
4977 | 4982 | ui.status(troublemsg[trouble] % numtrouble + "\n") |
|
4978 | 4983 | |
|
4979 | 4984 | cmdutil.summaryhooks(ui, repo) |
|
4980 | 4985 | |
|
4981 | 4986 | if opts.get('remote'): |
|
4982 | 4987 | needsincoming, needsoutgoing = True, True |
|
4983 | 4988 | else: |
|
4984 | 4989 | needsincoming, needsoutgoing = False, False |
|
4985 | 4990 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): |
|
4986 | 4991 | if i: |
|
4987 | 4992 | needsincoming = True |
|
4988 | 4993 | if o: |
|
4989 | 4994 | needsoutgoing = True |
|
4990 | 4995 | if not needsincoming and not needsoutgoing: |
|
4991 | 4996 | return |
|
4992 | 4997 | |
|
4993 | 4998 | def getincoming(): |
|
4994 | 4999 | source, branches = hg.parseurl(ui.expandpath('default')) |
|
4995 | 5000 | sbranch = branches[0] |
|
4996 | 5001 | try: |
|
4997 | 5002 | other = hg.peer(repo, {}, source) |
|
4998 | 5003 | except error.RepoError: |
|
4999 | 5004 | if opts.get('remote'): |
|
5000 | 5005 | raise |
|
5001 | 5006 | return source, sbranch, None, None, None |
|
5002 | 5007 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) |
|
5003 | 5008 | if revs: |
|
5004 | 5009 | revs = [other.lookup(rev) for rev in revs] |
|
5005 | 5010 | ui.debug('comparing with %s\n' % util.hidepassword(source)) |
|
5006 | 5011 | repo.ui.pushbuffer() |
|
5007 | 5012 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) |
|
5008 | 5013 | repo.ui.popbuffer() |
|
5009 | 5014 | return source, sbranch, other, commoninc, commoninc[1] |
|
5010 | 5015 | |
|
5011 | 5016 | if needsincoming: |
|
5012 | 5017 | source, sbranch, sother, commoninc, incoming = getincoming() |
|
5013 | 5018 | else: |
|
5014 | 5019 | source = sbranch = sother = commoninc = incoming = None |
|
5015 | 5020 | |
|
5016 | 5021 | def getoutgoing(): |
|
5017 | 5022 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) |
|
5018 | 5023 | dbranch = branches[0] |
|
5019 | 5024 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
5020 | 5025 | if source != dest: |
|
5021 | 5026 | try: |
|
5022 | 5027 | dother = hg.peer(repo, {}, dest) |
|
5023 | 5028 | except error.RepoError: |
|
5024 | 5029 | if opts.get('remote'): |
|
5025 | 5030 | raise |
|
5026 | 5031 | return dest, dbranch, None, None |
|
5027 | 5032 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) |
|
5028 | 5033 | elif sother is None: |
|
5029 | 5034 | # there is no explicit destination peer, but source one is invalid |
|
5030 | 5035 | return dest, dbranch, None, None |
|
5031 | 5036 | else: |
|
5032 | 5037 | dother = sother |
|
5033 | 5038 | if (source != dest or (sbranch is not None and sbranch != dbranch)): |
|
5034 | 5039 | common = None |
|
5035 | 5040 | else: |
|
5036 | 5041 | common = commoninc |
|
5037 | 5042 | if revs: |
|
5038 | 5043 | revs = [repo.lookup(rev) for rev in revs] |
|
5039 | 5044 | repo.ui.pushbuffer() |
|
5040 | 5045 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, |
|
5041 | 5046 | commoninc=common) |
|
5042 | 5047 | repo.ui.popbuffer() |
|
5043 | 5048 | return dest, dbranch, dother, outgoing |
|
5044 | 5049 | |
|
5045 | 5050 | if needsoutgoing: |
|
5046 | 5051 | dest, dbranch, dother, outgoing = getoutgoing() |
|
5047 | 5052 | else: |
|
5048 | 5053 | dest = dbranch = dother = outgoing = None |
|
5049 | 5054 | |
|
5050 | 5055 | if opts.get('remote'): |
|
5051 | 5056 | t = [] |
|
5052 | 5057 | if incoming: |
|
5053 | 5058 | t.append(_('1 or more incoming')) |
|
5054 | 5059 | o = outgoing.missing |
|
5055 | 5060 | if o: |
|
5056 | 5061 | t.append(_('%d outgoing') % len(o)) |
|
5057 | 5062 | other = dother or sother |
|
5058 | 5063 | if 'bookmarks' in other.listkeys('namespaces'): |
|
5059 | 5064 | counts = bookmarks.summary(repo, other) |
|
5060 | 5065 | if counts[0] > 0: |
|
5061 | 5066 | t.append(_('%d incoming bookmarks') % counts[0]) |
|
5062 | 5067 | if counts[1] > 0: |
|
5063 | 5068 | t.append(_('%d outgoing bookmarks') % counts[1]) |
|
5064 | 5069 | |
|
5065 | 5070 | if t: |
|
5066 | 5071 | # i18n: column positioning for "hg summary" |
|
5067 | 5072 | ui.write(_('remote: %s\n') % (', '.join(t))) |
|
5068 | 5073 | else: |
|
5069 | 5074 | # i18n: column positioning for "hg summary" |
|
5070 | 5075 | ui.status(_('remote: (synced)\n')) |
|
5071 | 5076 | |
|
5072 | 5077 | cmdutil.summaryremotehooks(ui, repo, opts, |
|
5073 | 5078 | ((source, sbranch, sother, commoninc), |
|
5074 | 5079 | (dest, dbranch, dother, outgoing))) |
|
5075 | 5080 | |
|
5076 | 5081 | @command('tag', |
|
5077 | 5082 | [('f', 'force', None, _('force tag')), |
|
5078 | 5083 | ('l', 'local', None, _('make the tag local')), |
|
5079 | 5084 | ('r', 'rev', '', _('revision to tag'), _('REV')), |
|
5080 | 5085 | ('', 'remove', None, _('remove a tag')), |
|
5081 | 5086 | # -l/--local is already there, commitopts cannot be used |
|
5082 | 5087 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
5083 | 5088 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), |
|
5084 | 5089 | ] + commitopts2, |
|
5085 | 5090 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) |
|
5086 | 5091 | def tag(ui, repo, name1, *names, **opts): |
|
5087 | 5092 | """add one or more tags for the current or given revision |
|
5088 | 5093 | |
|
5089 | 5094 | Name a particular revision using <name>. |
|
5090 | 5095 | |
|
5091 | 5096 | Tags are used to name particular revisions of the repository and are |
|
5092 | 5097 | very useful to compare different revisions, to go back to significant |
|
5093 | 5098 | earlier versions or to mark branch points as releases, etc. Changing |
|
5094 | 5099 | an existing tag is normally disallowed; use -f/--force to override. |
|
5095 | 5100 | |
|
5096 | 5101 | If no revision is given, the parent of the working directory is |
|
5097 | 5102 | used. |
|
5098 | 5103 | |
|
5099 | 5104 | To facilitate version control, distribution, and merging of tags, |
|
5100 | 5105 | they are stored as a file named ".hgtags" which is managed similarly |
|
5101 | 5106 | to other project files and can be hand-edited if necessary. This |
|
5102 | 5107 | also means that tagging creates a new commit. The file |
|
5103 | 5108 | ".hg/localtags" is used for local tags (not shared among |
|
5104 | 5109 | repositories). |
|
5105 | 5110 | |
|
5106 | 5111 | Tag commits are usually made at the head of a branch. If the parent |
|
5107 | 5112 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
5108 | 5113 | -f/--force to force the tag commit to be based on a non-head |
|
5109 | 5114 | changeset. |
|
5110 | 5115 | |
|
5111 | 5116 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5112 | 5117 | |
|
5113 | 5118 | Since tag names have priority over branch names during revision |
|
5114 | 5119 | lookup, using an existing branch name as a tag name is discouraged. |
|
5115 | 5120 | |
|
5116 | 5121 | Returns 0 on success. |
|
5117 | 5122 | """ |
|
5118 | 5123 | opts = pycompat.byteskwargs(opts) |
|
5119 | 5124 | wlock = lock = None |
|
5120 | 5125 | try: |
|
5121 | 5126 | wlock = repo.wlock() |
|
5122 | 5127 | lock = repo.lock() |
|
5123 | 5128 | rev_ = "." |
|
5124 | 5129 | names = [t.strip() for t in (name1,) + names] |
|
5125 | 5130 | if len(names) != len(set(names)): |
|
5126 | 5131 | raise error.Abort(_('tag names must be unique')) |
|
5127 | 5132 | for n in names: |
|
5128 | 5133 | scmutil.checknewlabel(repo, n, 'tag') |
|
5129 | 5134 | if not n: |
|
5130 | 5135 | raise error.Abort(_('tag names cannot consist entirely of ' |
|
5131 | 5136 | 'whitespace')) |
|
5132 | 5137 | if opts.get('rev') and opts.get('remove'): |
|
5133 | 5138 | raise error.Abort(_("--rev and --remove are incompatible")) |
|
5134 | 5139 | if opts.get('rev'): |
|
5135 | 5140 | rev_ = opts['rev'] |
|
5136 | 5141 | message = opts.get('message') |
|
5137 | 5142 | if opts.get('remove'): |
|
5138 | 5143 | if opts.get('local'): |
|
5139 | 5144 | expectedtype = 'local' |
|
5140 | 5145 | else: |
|
5141 | 5146 | expectedtype = 'global' |
|
5142 | 5147 | |
|
5143 | 5148 | for n in names: |
|
5144 | 5149 | if not repo.tagtype(n): |
|
5145 | 5150 | raise error.Abort(_("tag '%s' does not exist") % n) |
|
5146 | 5151 | if repo.tagtype(n) != expectedtype: |
|
5147 | 5152 | if expectedtype == 'global': |
|
5148 | 5153 | raise error.Abort(_("tag '%s' is not a global tag") % n) |
|
5149 | 5154 | else: |
|
5150 | 5155 | raise error.Abort(_("tag '%s' is not a local tag") % n) |
|
5151 | 5156 | rev_ = 'null' |
|
5152 | 5157 | if not message: |
|
5153 | 5158 | # we don't translate commit messages |
|
5154 | 5159 | message = 'Removed tag %s' % ', '.join(names) |
|
5155 | 5160 | elif not opts.get('force'): |
|
5156 | 5161 | for n in names: |
|
5157 | 5162 | if n in repo.tags(): |
|
5158 | 5163 | raise error.Abort(_("tag '%s' already exists " |
|
5159 | 5164 | "(use -f to force)") % n) |
|
5160 | 5165 | if not opts.get('local'): |
|
5161 | 5166 | p1, p2 = repo.dirstate.parents() |
|
5162 | 5167 | if p2 != nullid: |
|
5163 | 5168 | raise error.Abort(_('uncommitted merge')) |
|
5164 | 5169 | bheads = repo.branchheads() |
|
5165 | 5170 | if not opts.get('force') and bheads and p1 not in bheads: |
|
5166 | 5171 | raise error.Abort(_('working directory is not at a branch head ' |
|
5167 | 5172 | '(use -f to force)')) |
|
5168 | 5173 | r = scmutil.revsingle(repo, rev_).node() |
|
5169 | 5174 | |
|
5170 | 5175 | if not message: |
|
5171 | 5176 | # we don't translate commit messages |
|
5172 | 5177 | message = ('Added tag %s for changeset %s' % |
|
5173 | 5178 | (', '.join(names), short(r))) |
|
5174 | 5179 | |
|
5175 | 5180 | date = opts.get('date') |
|
5176 | 5181 | if date: |
|
5177 | 5182 | date = util.parsedate(date) |
|
5178 | 5183 | |
|
5179 | 5184 | if opts.get('remove'): |
|
5180 | 5185 | editform = 'tag.remove' |
|
5181 | 5186 | else: |
|
5182 | 5187 | editform = 'tag.add' |
|
5183 | 5188 | editor = cmdutil.getcommiteditor(editform=editform, |
|
5184 | 5189 | **pycompat.strkwargs(opts)) |
|
5185 | 5190 | |
|
5186 | 5191 | # don't allow tagging the null rev |
|
5187 | 5192 | if (not opts.get('remove') and |
|
5188 | 5193 | scmutil.revsingle(repo, rev_).rev() == nullrev): |
|
5189 | 5194 | raise error.Abort(_("cannot tag null revision")) |
|
5190 | 5195 | |
|
5191 | 5196 | tagsmod.tag(repo, names, r, message, opts.get('local'), |
|
5192 | 5197 | opts.get('user'), date, editor=editor) |
|
5193 | 5198 | finally: |
|
5194 | 5199 | release(lock, wlock) |
|
5195 | 5200 | |
|
5196 | 5201 | @command('tags', formatteropts, '') |
|
5197 | 5202 | def tags(ui, repo, **opts): |
|
5198 | 5203 | """list repository tags |
|
5199 | 5204 | |
|
5200 | 5205 | This lists both regular and local tags. When the -v/--verbose |
|
5201 | 5206 | switch is used, a third column "local" is printed for local tags. |
|
5202 | 5207 | When the -q/--quiet switch is used, only the tag name is printed. |
|
5203 | 5208 | |
|
5204 | 5209 | Returns 0 on success. |
|
5205 | 5210 | """ |
|
5206 | 5211 | |
|
5207 | 5212 | opts = pycompat.byteskwargs(opts) |
|
5208 | 5213 | ui.pager('tags') |
|
5209 | 5214 | fm = ui.formatter('tags', opts) |
|
5210 | 5215 | hexfunc = fm.hexfunc |
|
5211 | 5216 | tagtype = "" |
|
5212 | 5217 | |
|
5213 | 5218 | for t, n in reversed(repo.tagslist()): |
|
5214 | 5219 | hn = hexfunc(n) |
|
5215 | 5220 | label = 'tags.normal' |
|
5216 | 5221 | tagtype = '' |
|
5217 | 5222 | if repo.tagtype(t) == 'local': |
|
5218 | 5223 | label = 'tags.local' |
|
5219 | 5224 | tagtype = 'local' |
|
5220 | 5225 | |
|
5221 | 5226 | fm.startitem() |
|
5222 | 5227 | fm.write('tag', '%s', t, label=label) |
|
5223 | 5228 | fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' |
|
5224 | 5229 | fm.condwrite(not ui.quiet, 'rev node', fmt, |
|
5225 | 5230 | repo.changelog.rev(n), hn, label=label) |
|
5226 | 5231 | fm.condwrite(ui.verbose and tagtype, 'type', ' %s', |
|
5227 | 5232 | tagtype, label=label) |
|
5228 | 5233 | fm.plain('\n') |
|
5229 | 5234 | fm.end() |
|
5230 | 5235 | |
|
5231 | 5236 | @command('tip', |
|
5232 | 5237 | [('p', 'patch', None, _('show patch')), |
|
5233 | 5238 | ('g', 'git', None, _('use git extended diff format')), |
|
5234 | 5239 | ] + templateopts, |
|
5235 | 5240 | _('[-p] [-g]')) |
|
5236 | 5241 | def tip(ui, repo, **opts): |
|
5237 | 5242 | """show the tip revision (DEPRECATED) |
|
5238 | 5243 | |
|
5239 | 5244 | The tip revision (usually just called the tip) is the changeset |
|
5240 | 5245 | most recently added to the repository (and therefore the most |
|
5241 | 5246 | recently changed head). |
|
5242 | 5247 | |
|
5243 | 5248 | If you have just made a commit, that commit will be the tip. If |
|
5244 | 5249 | you have just pulled changes from another repository, the tip of |
|
5245 | 5250 | that repository becomes the current tip. The "tip" tag is special |
|
5246 | 5251 | and cannot be renamed or assigned to a different changeset. |
|
5247 | 5252 | |
|
5248 | 5253 | This command is deprecated, please use :hg:`heads` instead. |
|
5249 | 5254 | |
|
5250 | 5255 | Returns 0 on success. |
|
5251 | 5256 | """ |
|
5252 | 5257 | opts = pycompat.byteskwargs(opts) |
|
5253 | 5258 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
5254 | 5259 | displayer.show(repo['tip']) |
|
5255 | 5260 | displayer.close() |
|
5256 | 5261 | |
|
5257 | 5262 | @command('unbundle', |
|
5258 | 5263 | [('u', 'update', None, |
|
5259 | 5264 | _('update to new branch head if changesets were unbundled'))], |
|
5260 | 5265 | _('[-u] FILE...')) |
|
5261 | 5266 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
5262 | 5267 | """apply one or more bundle files |
|
5263 | 5268 | |
|
5264 | 5269 | Apply one or more bundle files generated by :hg:`bundle`. |
|
5265 | 5270 | |
|
5266 | 5271 | Returns 0 on success, 1 if an update has unresolved files. |
|
5267 | 5272 | """ |
|
5268 | 5273 | fnames = (fname1,) + fnames |
|
5269 | 5274 | |
|
5270 | 5275 | with repo.lock(): |
|
5271 | 5276 | for fname in fnames: |
|
5272 | 5277 | f = hg.openpath(ui, fname) |
|
5273 | 5278 | gen = exchange.readbundle(ui, f, fname) |
|
5274 | 5279 | if isinstance(gen, bundle2.unbundle20): |
|
5275 | 5280 | tr = repo.transaction('unbundle') |
|
5276 | 5281 | try: |
|
5277 | 5282 | op = bundle2.applybundle(repo, gen, tr, source='unbundle', |
|
5278 | 5283 | url='bundle:' + fname) |
|
5279 | 5284 | tr.close() |
|
5280 | 5285 | except error.BundleUnknownFeatureError as exc: |
|
5281 | 5286 | raise error.Abort(_('%s: unknown bundle feature, %s') |
|
5282 | 5287 | % (fname, exc), |
|
5283 | 5288 | hint=_("see https://mercurial-scm.org/" |
|
5284 | 5289 | "wiki/BundleFeature for more " |
|
5285 | 5290 | "information")) |
|
5286 | 5291 | finally: |
|
5287 | 5292 | if tr: |
|
5288 | 5293 | tr.release() |
|
5289 | 5294 | changes = [r.get('return', 0) |
|
5290 | 5295 | for r in op.records['changegroup']] |
|
5291 | 5296 | modheads = changegroup.combineresults(changes) |
|
5292 | 5297 | elif isinstance(gen, streamclone.streamcloneapplier): |
|
5293 | 5298 | raise error.Abort( |
|
5294 | 5299 | _('packed bundles cannot be applied with ' |
|
5295 | 5300 | '"hg unbundle"'), |
|
5296 | 5301 | hint=_('use "hg debugapplystreamclonebundle"')) |
|
5297 | 5302 | else: |
|
5298 | 5303 | modheads = gen.apply(repo, 'unbundle', 'bundle:' + fname) |
|
5299 | 5304 | |
|
5300 | 5305 | return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) |
|
5301 | 5306 | |
|
5302 | 5307 | @command('^update|up|checkout|co', |
|
5303 | 5308 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
|
5304 | 5309 | ('c', 'check', None, _('require clean working directory')), |
|
5305 | 5310 | ('m', 'merge', None, _('merge uncommitted changes')), |
|
5306 | 5311 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
5307 | 5312 | ('r', 'rev', '', _('revision'), _('REV')) |
|
5308 | 5313 | ] + mergetoolopts, |
|
5309 | 5314 | _('[-C|-c|-m] [-d DATE] [[-r] REV]')) |
|
5310 | 5315 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False, |
|
5311 | 5316 | merge=None, tool=None): |
|
5312 | 5317 | """update working directory (or switch revisions) |
|
5313 | 5318 | |
|
5314 | 5319 | Update the repository's working directory to the specified |
|
5315 | 5320 | changeset. If no changeset is specified, update to the tip of the |
|
5316 | 5321 | current named branch and move the active bookmark (see :hg:`help |
|
5317 | 5322 | bookmarks`). |
|
5318 | 5323 | |
|
5319 | 5324 | Update sets the working directory's parent revision to the specified |
|
5320 | 5325 | changeset (see :hg:`help parents`). |
|
5321 | 5326 | |
|
5322 | 5327 | If the changeset is not a descendant or ancestor of the working |
|
5323 | 5328 | directory's parent and there are uncommitted changes, the update is |
|
5324 | 5329 | aborted. With the -c/--check option, the working directory is checked |
|
5325 | 5330 | for uncommitted changes; if none are found, the working directory is |
|
5326 | 5331 | updated to the specified changeset. |
|
5327 | 5332 | |
|
5328 | 5333 | .. container:: verbose |
|
5329 | 5334 | |
|
5330 | 5335 | The -C/--clean, -c/--check, and -m/--merge options control what |
|
5331 | 5336 | happens if the working directory contains uncommitted changes. |
|
5332 | 5337 | At most of one of them can be specified. |
|
5333 | 5338 | |
|
5334 | 5339 | 1. If no option is specified, and if |
|
5335 | 5340 | the requested changeset is an ancestor or descendant of |
|
5336 | 5341 | the working directory's parent, the uncommitted changes |
|
5337 | 5342 | are merged into the requested changeset and the merged |
|
5338 | 5343 | result is left uncommitted. If the requested changeset is |
|
5339 | 5344 | not an ancestor or descendant (that is, it is on another |
|
5340 | 5345 | branch), the update is aborted and the uncommitted changes |
|
5341 | 5346 | are preserved. |
|
5342 | 5347 | |
|
5343 | 5348 | 2. With the -m/--merge option, the update is allowed even if the |
|
5344 | 5349 | requested changeset is not an ancestor or descendant of |
|
5345 | 5350 | the working directory's parent. |
|
5346 | 5351 | |
|
5347 | 5352 | 3. With the -c/--check option, the update is aborted and the |
|
5348 | 5353 | uncommitted changes are preserved. |
|
5349 | 5354 | |
|
5350 | 5355 | 4. With the -C/--clean option, uncommitted changes are discarded and |
|
5351 | 5356 | the working directory is updated to the requested changeset. |
|
5352 | 5357 | |
|
5353 | 5358 | To cancel an uncommitted merge (and lose your changes), use |
|
5354 | 5359 | :hg:`update --clean .`. |
|
5355 | 5360 | |
|
5356 | 5361 | Use null as the changeset to remove the working directory (like |
|
5357 | 5362 | :hg:`clone -U`). |
|
5358 | 5363 | |
|
5359 | 5364 | If you want to revert just one file to an older revision, use |
|
5360 | 5365 | :hg:`revert [-r REV] NAME`. |
|
5361 | 5366 | |
|
5362 | 5367 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5363 | 5368 | |
|
5364 | 5369 | Returns 0 on success, 1 if there are unresolved files. |
|
5365 | 5370 | """ |
|
5366 | 5371 | if rev and node: |
|
5367 | 5372 | raise error.Abort(_("please specify just one revision")) |
|
5368 | 5373 | |
|
5369 | 5374 | if ui.configbool('commands', 'update.requiredest'): |
|
5370 | 5375 | if not node and not rev and not date: |
|
5371 | 5376 | raise error.Abort(_('you must specify a destination'), |
|
5372 | 5377 | hint=_('for example: hg update ".::"')) |
|
5373 | 5378 | |
|
5374 | 5379 | if rev is None or rev == '': |
|
5375 | 5380 | rev = node |
|
5376 | 5381 | |
|
5377 | 5382 | if date and rev is not None: |
|
5378 | 5383 | raise error.Abort(_("you can't specify a revision and a date")) |
|
5379 | 5384 | |
|
5380 | 5385 | if len([x for x in (clean, check, merge) if x]) > 1: |
|
5381 | 5386 | raise error.Abort(_("can only specify one of -C/--clean, -c/--check, " |
|
5382 | 5387 | "or -m/merge")) |
|
5383 | 5388 | |
|
5384 | 5389 | updatecheck = None |
|
5385 | 5390 | if check: |
|
5386 | 5391 | updatecheck = 'abort' |
|
5387 | 5392 | elif merge: |
|
5388 | 5393 | updatecheck = 'none' |
|
5389 | 5394 | |
|
5390 | 5395 | with repo.wlock(): |
|
5391 | 5396 | cmdutil.clearunfinished(repo) |
|
5392 | 5397 | |
|
5393 | 5398 | if date: |
|
5394 | 5399 | rev = cmdutil.finddate(ui, repo, date) |
|
5395 | 5400 | |
|
5396 | 5401 | # if we defined a bookmark, we have to remember the original name |
|
5397 | 5402 | brev = rev |
|
5398 | 5403 | rev = scmutil.revsingle(repo, rev, rev).rev() |
|
5399 | 5404 | |
|
5400 | 5405 | repo.ui.setconfig('ui', 'forcemerge', tool, 'update') |
|
5401 | 5406 | |
|
5402 | 5407 | return hg.updatetotally(ui, repo, rev, brev, clean=clean, |
|
5403 | 5408 | updatecheck=updatecheck) |
|
5404 | 5409 | |
|
5405 | 5410 | @command('verify', []) |
|
5406 | 5411 | def verify(ui, repo): |
|
5407 | 5412 | """verify the integrity of the repository |
|
5408 | 5413 | |
|
5409 | 5414 | Verify the integrity of the current repository. |
|
5410 | 5415 | |
|
5411 | 5416 | This will perform an extensive check of the repository's |
|
5412 | 5417 | integrity, validating the hashes and checksums of each entry in |
|
5413 | 5418 | the changelog, manifest, and tracked files, as well as the |
|
5414 | 5419 | integrity of their crosslinks and indices. |
|
5415 | 5420 | |
|
5416 | 5421 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption |
|
5417 | 5422 | for more information about recovery from corruption of the |
|
5418 | 5423 | repository. |
|
5419 | 5424 | |
|
5420 | 5425 | Returns 0 on success, 1 if errors are encountered. |
|
5421 | 5426 | """ |
|
5422 | 5427 | return hg.verify(repo) |
|
5423 | 5428 | |
|
5424 | 5429 | @command('version', [] + formatteropts, norepo=True) |
|
5425 | 5430 | def version_(ui, **opts): |
|
5426 | 5431 | """output version and copyright information""" |
|
5427 | 5432 | opts = pycompat.byteskwargs(opts) |
|
5428 | 5433 | if ui.verbose: |
|
5429 | 5434 | ui.pager('version') |
|
5430 | 5435 | fm = ui.formatter("version", opts) |
|
5431 | 5436 | fm.startitem() |
|
5432 | 5437 | fm.write("ver", _("Mercurial Distributed SCM (version %s)\n"), |
|
5433 | 5438 | util.version()) |
|
5434 | 5439 | license = _( |
|
5435 | 5440 | "(see https://mercurial-scm.org for more information)\n" |
|
5436 | 5441 | "\nCopyright (C) 2005-2017 Matt Mackall and others\n" |
|
5437 | 5442 | "This is free software; see the source for copying conditions. " |
|
5438 | 5443 | "There is NO\nwarranty; " |
|
5439 | 5444 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
5440 | 5445 | ) |
|
5441 | 5446 | if not ui.quiet: |
|
5442 | 5447 | fm.plain(license) |
|
5443 | 5448 | |
|
5444 | 5449 | if ui.verbose: |
|
5445 | 5450 | fm.plain(_("\nEnabled extensions:\n\n")) |
|
5446 | 5451 | # format names and versions into columns |
|
5447 | 5452 | names = [] |
|
5448 | 5453 | vers = [] |
|
5449 | 5454 | isinternals = [] |
|
5450 | 5455 | for name, module in extensions.extensions(): |
|
5451 | 5456 | names.append(name) |
|
5452 | 5457 | vers.append(extensions.moduleversion(module) or None) |
|
5453 | 5458 | isinternals.append(extensions.ismoduleinternal(module)) |
|
5454 | 5459 | fn = fm.nested("extensions") |
|
5455 | 5460 | if names: |
|
5456 | 5461 | namefmt = " %%-%ds " % max(len(n) for n in names) |
|
5457 | 5462 | places = [_("external"), _("internal")] |
|
5458 | 5463 | for n, v, p in zip(names, vers, isinternals): |
|
5459 | 5464 | fn.startitem() |
|
5460 | 5465 | fn.condwrite(ui.verbose, "name", namefmt, n) |
|
5461 | 5466 | if ui.verbose: |
|
5462 | 5467 | fn.plain("%s " % places[p]) |
|
5463 | 5468 | fn.data(bundled=p) |
|
5464 | 5469 | fn.condwrite(ui.verbose and v, "ver", "%s", v) |
|
5465 | 5470 | if ui.verbose: |
|
5466 | 5471 | fn.plain("\n") |
|
5467 | 5472 | fn.end() |
|
5468 | 5473 | fm.end() |
|
5469 | 5474 | |
|
5470 | 5475 | def loadcmdtable(ui, name, cmdtable): |
|
5471 | 5476 | """Load command functions from specified cmdtable |
|
5472 | 5477 | """ |
|
5473 | 5478 | overrides = [cmd for cmd in cmdtable if cmd in table] |
|
5474 | 5479 | if overrides: |
|
5475 | 5480 | ui.warn(_("extension '%s' overrides commands: %s\n") |
|
5476 | 5481 | % (name, " ".join(overrides))) |
|
5477 | 5482 | table.update(cmdtable) |
@@ -1,962 +1,990 | |||
|
1 | 1 | $ hg init repo |
|
2 | 2 | $ cd repo |
|
3 | 3 | |
|
4 | 4 | no bookmarks |
|
5 | 5 | |
|
6 | 6 | $ hg bookmarks |
|
7 | 7 | no bookmarks set |
|
8 | 8 | |
|
9 | 9 | $ hg bookmarks -Tjson |
|
10 | 10 | [ |
|
11 | 11 | ] |
|
12 | 12 | |
|
13 | 13 | bookmark rev -1 |
|
14 | 14 | |
|
15 | 15 | $ hg bookmark X |
|
16 | 16 | |
|
17 | 17 | list bookmarks |
|
18 | 18 | |
|
19 | 19 | $ hg bookmarks |
|
20 | 20 | * X -1:000000000000 |
|
21 | 21 | |
|
22 | 22 | list bookmarks with color |
|
23 | 23 | |
|
24 | 24 | $ hg --config extensions.color= --config color.mode=ansi \ |
|
25 | 25 | > bookmarks --color=always |
|
26 | 26 | \x1b[0;32m * \x1b[0m\x1b[0;32mX\x1b[0m\x1b[0;32m -1:000000000000\x1b[0m (esc) |
|
27 | 27 | |
|
28 | 28 | $ echo a > a |
|
29 | 29 | $ hg add a |
|
30 | 30 | $ hg commit -m 0 |
|
31 | 31 | |
|
32 | 32 | bookmark X moved to rev 0 |
|
33 | 33 | |
|
34 | 34 | $ hg bookmarks |
|
35 | 35 | * X 0:f7b1eb17ad24 |
|
36 | 36 | |
|
37 | 37 | look up bookmark |
|
38 | 38 | |
|
39 | 39 | $ hg log -r X |
|
40 | 40 | changeset: 0:f7b1eb17ad24 |
|
41 | 41 | bookmark: X |
|
42 | 42 | tag: tip |
|
43 | 43 | user: test |
|
44 | 44 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
45 | 45 | summary: 0 |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | second bookmark for rev 0, command should work even with ui.strict on |
|
49 | 49 | |
|
50 | 50 | $ hg --config ui.strict=1 bookmark X2 |
|
51 | 51 | |
|
52 | 52 | bookmark rev -1 again |
|
53 | 53 | |
|
54 | 54 | $ hg bookmark -r null Y |
|
55 | 55 | |
|
56 | 56 | list bookmarks |
|
57 | 57 | |
|
58 | 58 | $ hg bookmarks |
|
59 | 59 | X 0:f7b1eb17ad24 |
|
60 | 60 | * X2 0:f7b1eb17ad24 |
|
61 | 61 | Y -1:000000000000 |
|
62 | 62 | |
|
63 | 63 | $ echo b > b |
|
64 | 64 | $ hg add b |
|
65 | 65 | $ hg commit -m 1 |
|
66 | 66 | |
|
67 | 67 | $ hg bookmarks -Tjson |
|
68 | 68 | [ |
|
69 | 69 | { |
|
70 | 70 | "active": false, |
|
71 | 71 | "bookmark": "X", |
|
72 | 72 | "node": "f7b1eb17ad24730a1651fccd46c43826d1bbc2ac", |
|
73 | 73 | "rev": 0 |
|
74 | 74 | }, |
|
75 | 75 | { |
|
76 | 76 | "active": true, |
|
77 | 77 | "bookmark": "X2", |
|
78 | 78 | "node": "925d80f479bb026b0fb3deb27503780b13f74123", |
|
79 | 79 | "rev": 1 |
|
80 | 80 | }, |
|
81 | 81 | { |
|
82 | 82 | "active": false, |
|
83 | 83 | "bookmark": "Y", |
|
84 | 84 | "node": "0000000000000000000000000000000000000000", |
|
85 | 85 | "rev": -1 |
|
86 | 86 | } |
|
87 | 87 | ] |
|
88 | 88 | |
|
89 | 89 | bookmarks revset |
|
90 | 90 | |
|
91 | 91 | $ hg log -r 'bookmark()' |
|
92 | 92 | changeset: 0:f7b1eb17ad24 |
|
93 | 93 | bookmark: X |
|
94 | 94 | user: test |
|
95 | 95 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
96 | 96 | summary: 0 |
|
97 | 97 | |
|
98 | 98 | changeset: 1:925d80f479bb |
|
99 | 99 | bookmark: X2 |
|
100 | 100 | tag: tip |
|
101 | 101 | user: test |
|
102 | 102 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
103 | 103 | summary: 1 |
|
104 | 104 | |
|
105 | 105 | $ hg log -r 'bookmark(Y)' |
|
106 | 106 | $ hg log -r 'bookmark(X2)' |
|
107 | 107 | changeset: 1:925d80f479bb |
|
108 | 108 | bookmark: X2 |
|
109 | 109 | tag: tip |
|
110 | 110 | user: test |
|
111 | 111 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
112 | 112 | summary: 1 |
|
113 | 113 | |
|
114 | 114 | $ hg log -r 'bookmark("re:X")' |
|
115 | 115 | changeset: 0:f7b1eb17ad24 |
|
116 | 116 | bookmark: X |
|
117 | 117 | user: test |
|
118 | 118 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
119 | 119 | summary: 0 |
|
120 | 120 | |
|
121 | 121 | changeset: 1:925d80f479bb |
|
122 | 122 | bookmark: X2 |
|
123 | 123 | tag: tip |
|
124 | 124 | user: test |
|
125 | 125 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
126 | 126 | summary: 1 |
|
127 | 127 | |
|
128 | 128 | $ hg log -r 'bookmark("literal:X")' |
|
129 | 129 | changeset: 0:f7b1eb17ad24 |
|
130 | 130 | bookmark: X |
|
131 | 131 | user: test |
|
132 | 132 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
133 | 133 | summary: 0 |
|
134 | 134 | |
|
135 | 135 | |
|
136 | 136 | $ hg log -r 'bookmark(unknown)' |
|
137 | 137 | abort: bookmark 'unknown' does not exist! |
|
138 | 138 | [255] |
|
139 | 139 | $ hg log -r 'bookmark("literal:unknown")' |
|
140 | 140 | abort: bookmark 'unknown' does not exist! |
|
141 | 141 | [255] |
|
142 | 142 | $ hg log -r 'bookmark("re:unknown")' |
|
143 | 143 | abort: no bookmarks exist that match 'unknown'! |
|
144 | 144 | [255] |
|
145 | 145 | $ hg log -r 'present(bookmark("literal:unknown"))' |
|
146 | 146 | $ hg log -r 'present(bookmark("re:unknown"))' |
|
147 | 147 | |
|
148 | 148 | $ hg help revsets | grep 'bookmark(' |
|
149 | 149 | "bookmark([name])" |
|
150 | 150 | |
|
151 | 151 | bookmarks X and X2 moved to rev 1, Y at rev -1 |
|
152 | 152 | |
|
153 | 153 | $ hg bookmarks |
|
154 | 154 | X 0:f7b1eb17ad24 |
|
155 | 155 | * X2 1:925d80f479bb |
|
156 | 156 | Y -1:000000000000 |
|
157 | 157 | |
|
158 | 158 | bookmark rev 0 again |
|
159 | 159 | |
|
160 | 160 | $ hg bookmark -r 0 Z |
|
161 | 161 | |
|
162 | 162 | $ hg update X |
|
163 | 163 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
164 | 164 | (activating bookmark X) |
|
165 | 165 | $ echo c > c |
|
166 | 166 | $ hg add c |
|
167 | 167 | $ hg commit -m 2 |
|
168 | 168 | created new head |
|
169 | 169 | |
|
170 | 170 | bookmarks X moved to rev 2, Y at rev -1, Z at rev 0 |
|
171 | 171 | |
|
172 | 172 | $ hg bookmarks |
|
173 | 173 | * X 2:db815d6d32e6 |
|
174 | 174 | X2 1:925d80f479bb |
|
175 | 175 | Y -1:000000000000 |
|
176 | 176 | Z 0:f7b1eb17ad24 |
|
177 | 177 | |
|
178 | 178 | rename nonexistent bookmark |
|
179 | 179 | |
|
180 | 180 | $ hg bookmark -m A B |
|
181 | 181 | abort: bookmark 'A' does not exist |
|
182 | 182 | [255] |
|
183 | 183 | |
|
184 | 184 | rename to existent bookmark |
|
185 | 185 | |
|
186 | 186 | $ hg bookmark -m X Y |
|
187 | 187 | abort: bookmark 'Y' already exists (use -f to force) |
|
188 | 188 | [255] |
|
189 | 189 | |
|
190 | 190 | force rename to existent bookmark |
|
191 | 191 | |
|
192 | 192 | $ hg bookmark -f -m X Y |
|
193 | 193 | |
|
194 | 194 | list bookmarks |
|
195 | 195 | |
|
196 | 196 | $ hg bookmark |
|
197 | 197 | X2 1:925d80f479bb |
|
198 | 198 | * Y 2:db815d6d32e6 |
|
199 | 199 | Z 0:f7b1eb17ad24 |
|
200 | 200 | |
|
201 | 201 | bookmarks from a revset |
|
202 | 202 | $ hg bookmark -r '.^1' REVSET |
|
203 | 203 | $ hg bookmark -r ':tip' TIP |
|
204 | 204 | $ hg up -q TIP |
|
205 | 205 | $ hg bookmarks |
|
206 | 206 | REVSET 0:f7b1eb17ad24 |
|
207 | 207 | * TIP 2:db815d6d32e6 |
|
208 | 208 | X2 1:925d80f479bb |
|
209 | 209 | Y 2:db815d6d32e6 |
|
210 | 210 | Z 0:f7b1eb17ad24 |
|
211 | 211 | |
|
212 | 212 | $ hg bookmark -d REVSET |
|
213 | 213 | $ hg bookmark -d TIP |
|
214 | 214 | |
|
215 | 215 | rename without new name or multiple names |
|
216 | 216 | |
|
217 | 217 | $ hg bookmark -m Y |
|
218 | 218 | abort: new bookmark name required |
|
219 | 219 | [255] |
|
220 | 220 | $ hg bookmark -m Y Y2 Y3 |
|
221 | 221 | abort: only one new bookmark name allowed |
|
222 | 222 | [255] |
|
223 | 223 | |
|
224 | 224 | delete without name |
|
225 | 225 | |
|
226 | 226 | $ hg bookmark -d |
|
227 | 227 | abort: bookmark name required |
|
228 | 228 | [255] |
|
229 | 229 | |
|
230 | 230 | delete nonexistent bookmark |
|
231 | 231 | |
|
232 | 232 | $ hg bookmark -d A |
|
233 | 233 | abort: bookmark 'A' does not exist |
|
234 | 234 | [255] |
|
235 | 235 | |
|
236 | 236 | bookmark name with spaces should be stripped |
|
237 | 237 | |
|
238 | 238 | $ hg bookmark ' x y ' |
|
239 | 239 | |
|
240 | 240 | list bookmarks |
|
241 | 241 | |
|
242 | 242 | $ hg bookmarks |
|
243 | 243 | X2 1:925d80f479bb |
|
244 | 244 | Y 2:db815d6d32e6 |
|
245 | 245 | Z 0:f7b1eb17ad24 |
|
246 | 246 | * x y 2:db815d6d32e6 |
|
247 | 247 | |
|
248 | 248 | look up stripped bookmark name |
|
249 | 249 | |
|
250 | 250 | $ hg log -r '"x y"' |
|
251 | 251 | changeset: 2:db815d6d32e6 |
|
252 | 252 | bookmark: Y |
|
253 | 253 | bookmark: x y |
|
254 | 254 | tag: tip |
|
255 | 255 | parent: 0:f7b1eb17ad24 |
|
256 | 256 | user: test |
|
257 | 257 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
258 | 258 | summary: 2 |
|
259 | 259 | |
|
260 | 260 | |
|
261 | 261 | reject bookmark name with newline |
|
262 | 262 | |
|
263 | 263 | $ hg bookmark ' |
|
264 | 264 | > ' |
|
265 | 265 | abort: bookmark names cannot consist entirely of whitespace |
|
266 | 266 | [255] |
|
267 | 267 | |
|
268 | 268 | $ hg bookmark -m Z ' |
|
269 | 269 | > ' |
|
270 | 270 | abort: bookmark names cannot consist entirely of whitespace |
|
271 | 271 | [255] |
|
272 | 272 | |
|
273 | 273 | bookmark with reserved name |
|
274 | 274 | |
|
275 | 275 | $ hg bookmark tip |
|
276 | 276 | abort: the name 'tip' is reserved |
|
277 | 277 | [255] |
|
278 | 278 | |
|
279 | 279 | $ hg bookmark . |
|
280 | 280 | abort: the name '.' is reserved |
|
281 | 281 | [255] |
|
282 | 282 | |
|
283 | 283 | $ hg bookmark null |
|
284 | 284 | abort: the name 'null' is reserved |
|
285 | 285 | [255] |
|
286 | 286 | |
|
287 | 287 | |
|
288 | 288 | bookmark with existing name |
|
289 | 289 | |
|
290 | 290 | $ hg bookmark X2 |
|
291 | 291 | abort: bookmark 'X2' already exists (use -f to force) |
|
292 | 292 | [255] |
|
293 | 293 | |
|
294 | 294 | $ hg bookmark -m Y Z |
|
295 | 295 | abort: bookmark 'Z' already exists (use -f to force) |
|
296 | 296 | [255] |
|
297 | 297 | |
|
298 | 298 | bookmark with name of branch |
|
299 | 299 | |
|
300 | 300 | $ hg bookmark default |
|
301 | 301 | abort: a bookmark cannot have the name of an existing branch |
|
302 | 302 | [255] |
|
303 | 303 | |
|
304 | 304 | $ hg bookmark -m Y default |
|
305 | 305 | abort: a bookmark cannot have the name of an existing branch |
|
306 | 306 | [255] |
|
307 | 307 | |
|
308 | 308 | bookmark with integer name |
|
309 | 309 | |
|
310 | 310 | $ hg bookmark 10 |
|
311 | 311 | abort: cannot use an integer as a name |
|
312 | 312 | [255] |
|
313 | 313 | |
|
314 | 314 | bookmark with a name that matches a node id |
|
315 | 315 | $ hg bookmark 925d80f479bb db815d6d32e6 |
|
316 | 316 | bookmark 925d80f479bb matches a changeset hash |
|
317 | 317 | (did you leave a -r out of an 'hg bookmark' command?) |
|
318 | 318 | bookmark db815d6d32e6 matches a changeset hash |
|
319 | 319 | (did you leave a -r out of an 'hg bookmark' command?) |
|
320 | 320 | $ hg bookmark -d 925d80f479bb |
|
321 | 321 | $ hg bookmark -d db815d6d32e6 |
|
322 | 322 | |
|
323 | $ cd .. | |
|
324 | ||
|
325 | bookmark with a name that matches an ambiguous node id | |
|
326 | ||
|
327 | $ hg init ambiguous | |
|
328 | $ cd ambiguous | |
|
329 | $ echo 0 > a | |
|
330 | $ hg ci -qAm 0 | |
|
331 | $ for i in 1057 2857 4025; do | |
|
332 | > hg up -q 0 | |
|
333 | > echo $i > a | |
|
334 | > hg ci -qm $i | |
|
335 | > done | |
|
336 | $ hg up -q null | |
|
337 | $ hg log -r0: -T '{rev}:{node}\n' | |
|
338 | 0:b4e73ffab476aa0ee32ed81ca51e07169844bc6a | |
|
339 | 1:c56256a09cd28e5764f32e8e2810d0f01e2e357a | |
|
340 | 2:c5623987d205cd6d9d8389bfc40fff9dbb670b48 | |
|
341 | 3:c562ddd9c94164376c20b86b0b4991636a3bf84f | |
|
342 | ||
|
343 | $ hg bookmark -r0 c562 | |
|
344 | $ hg bookmarks | |
|
345 | c562 0:b4e73ffab476 | |
|
346 | ||
|
347 | $ cd .. | |
|
348 | ||
|
323 | 349 | incompatible options |
|
324 | 350 | |
|
351 | $ cd repo | |
|
352 | ||
|
325 | 353 | $ hg bookmark -m Y -d Z |
|
326 | 354 | abort: --delete and --rename are incompatible |
|
327 | 355 | [255] |
|
328 | 356 | |
|
329 | 357 | $ hg bookmark -r 1 -d Z |
|
330 | 358 | abort: --rev is incompatible with --delete |
|
331 | 359 | [255] |
|
332 | 360 | |
|
333 | 361 | $ hg bookmark -r 1 -m Z Y |
|
334 | 362 | abort: --rev is incompatible with --rename |
|
335 | 363 | [255] |
|
336 | 364 | |
|
337 | 365 | force bookmark with existing name |
|
338 | 366 | |
|
339 | 367 | $ hg bookmark -f X2 |
|
340 | 368 | |
|
341 | 369 | force bookmark back to where it was, should deactivate it |
|
342 | 370 | |
|
343 | 371 | $ hg bookmark -fr1 X2 |
|
344 | 372 | $ hg bookmarks |
|
345 | 373 | X2 1:925d80f479bb |
|
346 | 374 | Y 2:db815d6d32e6 |
|
347 | 375 | Z 0:f7b1eb17ad24 |
|
348 | 376 | x y 2:db815d6d32e6 |
|
349 | 377 | |
|
350 | 378 | forward bookmark to descendant without --force |
|
351 | 379 | |
|
352 | 380 | $ hg bookmark Z |
|
353 | 381 | moving bookmark 'Z' forward from f7b1eb17ad24 |
|
354 | 382 | |
|
355 | 383 | list bookmarks |
|
356 | 384 | |
|
357 | 385 | $ hg bookmark |
|
358 | 386 | X2 1:925d80f479bb |
|
359 | 387 | Y 2:db815d6d32e6 |
|
360 | 388 | * Z 2:db815d6d32e6 |
|
361 | 389 | x y 2:db815d6d32e6 |
|
362 | 390 | |
|
363 | 391 | revision but no bookmark name |
|
364 | 392 | |
|
365 | 393 | $ hg bookmark -r . |
|
366 | 394 | abort: bookmark name required |
|
367 | 395 | [255] |
|
368 | 396 | |
|
369 | 397 | bookmark name with whitespace only |
|
370 | 398 | |
|
371 | 399 | $ hg bookmark ' ' |
|
372 | 400 | abort: bookmark names cannot consist entirely of whitespace |
|
373 | 401 | [255] |
|
374 | 402 | |
|
375 | 403 | $ hg bookmark -m Y ' ' |
|
376 | 404 | abort: bookmark names cannot consist entirely of whitespace |
|
377 | 405 | [255] |
|
378 | 406 | |
|
379 | 407 | invalid bookmark |
|
380 | 408 | |
|
381 | 409 | $ hg bookmark 'foo:bar' |
|
382 | 410 | abort: ':' cannot be used in a name |
|
383 | 411 | [255] |
|
384 | 412 | |
|
385 | 413 | $ hg bookmark 'foo |
|
386 | 414 | > bar' |
|
387 | 415 | abort: '\n' cannot be used in a name |
|
388 | 416 | [255] |
|
389 | 417 | |
|
390 | 418 | the bookmark extension should be ignored now that it is part of core |
|
391 | 419 | |
|
392 | 420 | $ echo "[extensions]" >> $HGRCPATH |
|
393 | 421 | $ echo "bookmarks=" >> $HGRCPATH |
|
394 | 422 | $ hg bookmarks |
|
395 | 423 | X2 1:925d80f479bb |
|
396 | 424 | Y 2:db815d6d32e6 |
|
397 | 425 | * Z 2:db815d6d32e6 |
|
398 | 426 | x y 2:db815d6d32e6 |
|
399 | 427 | |
|
400 | 428 | test summary |
|
401 | 429 | |
|
402 | 430 | $ hg summary |
|
403 | 431 | parent: 2:db815d6d32e6 tip |
|
404 | 432 | 2 |
|
405 | 433 | branch: default |
|
406 | 434 | bookmarks: *Z Y x y |
|
407 | 435 | commit: (clean) |
|
408 | 436 | update: 1 new changesets, 2 branch heads (merge) |
|
409 | 437 | phases: 3 draft |
|
410 | 438 | |
|
411 | 439 | test id |
|
412 | 440 | |
|
413 | 441 | $ hg id |
|
414 | 442 | db815d6d32e6 tip Y/Z/x y |
|
415 | 443 | |
|
416 | 444 | test rollback |
|
417 | 445 | |
|
418 | 446 | $ echo foo > f1 |
|
419 | 447 | $ hg bookmark tmp-rollback |
|
420 | 448 | $ hg ci -Amr |
|
421 | 449 | adding f1 |
|
422 | 450 | $ hg bookmarks |
|
423 | 451 | X2 1:925d80f479bb |
|
424 | 452 | Y 2:db815d6d32e6 |
|
425 | 453 | Z 2:db815d6d32e6 |
|
426 | 454 | * tmp-rollback 3:2bf5cfec5864 |
|
427 | 455 | x y 2:db815d6d32e6 |
|
428 | 456 | $ hg rollback |
|
429 | 457 | repository tip rolled back to revision 2 (undo commit) |
|
430 | 458 | working directory now based on revision 2 |
|
431 | 459 | $ hg bookmarks |
|
432 | 460 | X2 1:925d80f479bb |
|
433 | 461 | Y 2:db815d6d32e6 |
|
434 | 462 | Z 2:db815d6d32e6 |
|
435 | 463 | * tmp-rollback 2:db815d6d32e6 |
|
436 | 464 | x y 2:db815d6d32e6 |
|
437 | 465 | $ hg bookmark -f Z -r 1 |
|
438 | 466 | $ hg rollback |
|
439 | 467 | repository tip rolled back to revision 2 (undo bookmark) |
|
440 | 468 | $ hg bookmarks |
|
441 | 469 | X2 1:925d80f479bb |
|
442 | 470 | Y 2:db815d6d32e6 |
|
443 | 471 | Z 2:db815d6d32e6 |
|
444 | 472 | * tmp-rollback 2:db815d6d32e6 |
|
445 | 473 | x y 2:db815d6d32e6 |
|
446 | 474 | $ hg bookmark -d tmp-rollback |
|
447 | 475 | |
|
448 | 476 | activate bookmark on working dir parent without --force |
|
449 | 477 | |
|
450 | 478 | $ hg bookmark --inactive Z |
|
451 | 479 | $ hg bookmark Z |
|
452 | 480 | |
|
453 | 481 | test clone |
|
454 | 482 | |
|
455 | 483 | $ hg bookmark -r 2 -i @ |
|
456 | 484 | $ hg bookmark -r 2 -i a@ |
|
457 | 485 | $ hg bookmarks |
|
458 | 486 | @ 2:db815d6d32e6 |
|
459 | 487 | X2 1:925d80f479bb |
|
460 | 488 | Y 2:db815d6d32e6 |
|
461 | 489 | * Z 2:db815d6d32e6 |
|
462 | 490 | a@ 2:db815d6d32e6 |
|
463 | 491 | x y 2:db815d6d32e6 |
|
464 | 492 | $ hg clone . cloned-bookmarks |
|
465 | 493 | updating to bookmark @ |
|
466 | 494 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
467 | 495 | $ hg -R cloned-bookmarks bookmarks |
|
468 | 496 | * @ 2:db815d6d32e6 |
|
469 | 497 | X2 1:925d80f479bb |
|
470 | 498 | Y 2:db815d6d32e6 |
|
471 | 499 | Z 2:db815d6d32e6 |
|
472 | 500 | a@ 2:db815d6d32e6 |
|
473 | 501 | x y 2:db815d6d32e6 |
|
474 | 502 | |
|
475 | 503 | test clone with pull protocol |
|
476 | 504 | |
|
477 | 505 | $ hg clone --pull . cloned-bookmarks-pull |
|
478 | 506 | requesting all changes |
|
479 | 507 | adding changesets |
|
480 | 508 | adding manifests |
|
481 | 509 | adding file changes |
|
482 | 510 | added 3 changesets with 3 changes to 3 files (+1 heads) |
|
483 | 511 | updating to bookmark @ |
|
484 | 512 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
485 | 513 | $ hg -R cloned-bookmarks-pull bookmarks |
|
486 | 514 | * @ 2:db815d6d32e6 |
|
487 | 515 | X2 1:925d80f479bb |
|
488 | 516 | Y 2:db815d6d32e6 |
|
489 | 517 | Z 2:db815d6d32e6 |
|
490 | 518 | a@ 2:db815d6d32e6 |
|
491 | 519 | x y 2:db815d6d32e6 |
|
492 | 520 | |
|
493 | 521 | delete multiple bookmarks at once |
|
494 | 522 | |
|
495 | 523 | $ hg bookmark -d @ a@ |
|
496 | 524 | |
|
497 | 525 | test clone with a bookmark named "default" (issue3677) |
|
498 | 526 | |
|
499 | 527 | $ hg bookmark -r 1 -f -i default |
|
500 | 528 | $ hg clone . cloned-bookmark-default |
|
501 | 529 | updating to branch default |
|
502 | 530 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
503 | 531 | $ hg -R cloned-bookmark-default bookmarks |
|
504 | 532 | X2 1:925d80f479bb |
|
505 | 533 | Y 2:db815d6d32e6 |
|
506 | 534 | Z 2:db815d6d32e6 |
|
507 | 535 | default 1:925d80f479bb |
|
508 | 536 | x y 2:db815d6d32e6 |
|
509 | 537 | $ hg -R cloned-bookmark-default parents -q |
|
510 | 538 | 2:db815d6d32e6 |
|
511 | 539 | $ hg bookmark -d default |
|
512 | 540 | |
|
513 | 541 | test clone with a specific revision |
|
514 | 542 | |
|
515 | 543 | $ hg clone -r 925d80 . cloned-bookmarks-rev |
|
516 | 544 | adding changesets |
|
517 | 545 | adding manifests |
|
518 | 546 | adding file changes |
|
519 | 547 | added 2 changesets with 2 changes to 2 files |
|
520 | 548 | updating to branch default |
|
521 | 549 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
522 | 550 | $ hg -R cloned-bookmarks-rev bookmarks |
|
523 | 551 | X2 1:925d80f479bb |
|
524 | 552 | |
|
525 | 553 | test clone with update to a bookmark |
|
526 | 554 | |
|
527 | 555 | $ hg clone -u Z . ../cloned-bookmarks-update |
|
528 | 556 | updating to branch default |
|
529 | 557 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
530 | 558 | $ hg -R ../cloned-bookmarks-update bookmarks |
|
531 | 559 | X2 1:925d80f479bb |
|
532 | 560 | Y 2:db815d6d32e6 |
|
533 | 561 | * Z 2:db815d6d32e6 |
|
534 | 562 | x y 2:db815d6d32e6 |
|
535 | 563 | |
|
536 | 564 | create bundle with two heads |
|
537 | 565 | |
|
538 | 566 | $ hg clone . tobundle |
|
539 | 567 | updating to branch default |
|
540 | 568 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
541 | 569 | $ echo x > tobundle/x |
|
542 | 570 | $ hg -R tobundle add tobundle/x |
|
543 | 571 | $ hg -R tobundle commit -m'x' |
|
544 | 572 | $ hg -R tobundle update -r -2 |
|
545 | 573 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
546 | 574 | $ echo y > tobundle/y |
|
547 | 575 | $ hg -R tobundle branch test |
|
548 | 576 | marked working directory as branch test |
|
549 | 577 | (branches are permanent and global, did you want a bookmark?) |
|
550 | 578 | $ hg -R tobundle add tobundle/y |
|
551 | 579 | $ hg -R tobundle commit -m'y' |
|
552 | 580 | $ hg -R tobundle bundle tobundle.hg |
|
553 | 581 | searching for changes |
|
554 | 582 | 2 changesets found |
|
555 | 583 | $ hg unbundle tobundle.hg |
|
556 | 584 | adding changesets |
|
557 | 585 | adding manifests |
|
558 | 586 | adding file changes |
|
559 | 587 | added 2 changesets with 2 changes to 2 files (+1 heads) |
|
560 | 588 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
561 | 589 | |
|
562 | 590 | update to active bookmark if it's not the parent |
|
563 | 591 | |
|
564 | 592 | $ hg summary |
|
565 | 593 | parent: 2:db815d6d32e6 |
|
566 | 594 | 2 |
|
567 | 595 | branch: default |
|
568 | 596 | bookmarks: *Z Y x y |
|
569 | 597 | commit: 1 added, 1 unknown (new branch head) |
|
570 | 598 | update: 2 new changesets (update) |
|
571 | 599 | phases: 5 draft |
|
572 | 600 | $ hg update |
|
573 | 601 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
574 | 602 | updating bookmark Z |
|
575 | 603 | $ hg bookmarks |
|
576 | 604 | X2 1:925d80f479bb |
|
577 | 605 | Y 2:db815d6d32e6 |
|
578 | 606 | * Z 3:125c9a1d6df6 |
|
579 | 607 | x y 2:db815d6d32e6 |
|
580 | 608 | |
|
581 | 609 | pull --update works the same as pull && update |
|
582 | 610 | |
|
583 | 611 | $ hg bookmark -r3 Y |
|
584 | 612 | moving bookmark 'Y' forward from db815d6d32e6 |
|
585 | 613 | $ cp -R ../cloned-bookmarks-update ../cloned-bookmarks-manual-update |
|
586 | 614 | $ cp -R ../cloned-bookmarks-update ../cloned-bookmarks-manual-update-with-divergence |
|
587 | 615 | |
|
588 | 616 | (manual version) |
|
589 | 617 | |
|
590 | 618 | $ hg -R ../cloned-bookmarks-manual-update update Y |
|
591 | 619 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
592 | 620 | (activating bookmark Y) |
|
593 | 621 | $ hg -R ../cloned-bookmarks-manual-update pull . |
|
594 | 622 | pulling from . |
|
595 | 623 | searching for changes |
|
596 | 624 | adding changesets |
|
597 | 625 | adding manifests |
|
598 | 626 | adding file changes |
|
599 | 627 | added 2 changesets with 2 changes to 2 files (+1 heads) |
|
600 | 628 | updating bookmark Y |
|
601 | 629 | updating bookmark Z |
|
602 | 630 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
603 | 631 | |
|
604 | 632 | (# tests strange but with --date crashing when bookmark have to move) |
|
605 | 633 | |
|
606 | 634 | $ hg -R ../cloned-bookmarks-manual-update update -d 1986 |
|
607 | 635 | abort: revision matching date not found |
|
608 | 636 | [255] |
|
609 | 637 | $ hg -R ../cloned-bookmarks-manual-update update |
|
610 | 638 | updating to active bookmark Y |
|
611 | 639 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
612 | 640 | |
|
613 | 641 | (all in one version) |
|
614 | 642 | |
|
615 | 643 | $ hg -R ../cloned-bookmarks-update update Y |
|
616 | 644 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
617 | 645 | (activating bookmark Y) |
|
618 | 646 | $ hg -R ../cloned-bookmarks-update pull --update . |
|
619 | 647 | pulling from . |
|
620 | 648 | searching for changes |
|
621 | 649 | adding changesets |
|
622 | 650 | adding manifests |
|
623 | 651 | adding file changes |
|
624 | 652 | added 2 changesets with 2 changes to 2 files (+1 heads) |
|
625 | 653 | updating bookmark Y |
|
626 | 654 | updating bookmark Z |
|
627 | 655 | updating to active bookmark Y |
|
628 | 656 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
629 | 657 | |
|
630 | 658 | We warn about divergent during bare update to the active bookmark |
|
631 | 659 | |
|
632 | 660 | $ hg -R ../cloned-bookmarks-manual-update-with-divergence update Y |
|
633 | 661 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
634 | 662 | (activating bookmark Y) |
|
635 | 663 | $ hg -R ../cloned-bookmarks-manual-update-with-divergence bookmarks -r X2 Y@1 |
|
636 | 664 | $ hg -R ../cloned-bookmarks-manual-update-with-divergence bookmarks |
|
637 | 665 | X2 1:925d80f479bb |
|
638 | 666 | * Y 2:db815d6d32e6 |
|
639 | 667 | Y@1 1:925d80f479bb |
|
640 | 668 | Z 2:db815d6d32e6 |
|
641 | 669 | x y 2:db815d6d32e6 |
|
642 | 670 | $ hg -R ../cloned-bookmarks-manual-update-with-divergence pull |
|
643 | 671 | pulling from $TESTTMP/repo (glob) |
|
644 | 672 | searching for changes |
|
645 | 673 | adding changesets |
|
646 | 674 | adding manifests |
|
647 | 675 | adding file changes |
|
648 | 676 | added 2 changesets with 2 changes to 2 files (+1 heads) |
|
649 | 677 | updating bookmark Y |
|
650 | 678 | updating bookmark Z |
|
651 | 679 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
652 | 680 | $ hg -R ../cloned-bookmarks-manual-update-with-divergence update |
|
653 | 681 | updating to active bookmark Y |
|
654 | 682 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
655 | 683 | 1 other divergent bookmarks for "Y" |
|
656 | 684 | |
|
657 | 685 | test wrongly formated bookmark |
|
658 | 686 | |
|
659 | 687 | $ echo '' >> .hg/bookmarks |
|
660 | 688 | $ hg bookmarks |
|
661 | 689 | X2 1:925d80f479bb |
|
662 | 690 | Y 3:125c9a1d6df6 |
|
663 | 691 | * Z 3:125c9a1d6df6 |
|
664 | 692 | x y 2:db815d6d32e6 |
|
665 | 693 | $ echo "Ican'thasformatedlines" >> .hg/bookmarks |
|
666 | 694 | $ hg bookmarks |
|
667 | 695 | malformed line in .hg/bookmarks: "Ican'thasformatedlines" |
|
668 | 696 | X2 1:925d80f479bb |
|
669 | 697 | Y 3:125c9a1d6df6 |
|
670 | 698 | * Z 3:125c9a1d6df6 |
|
671 | 699 | x y 2:db815d6d32e6 |
|
672 | 700 | |
|
673 | 701 | test missing revisions |
|
674 | 702 | |
|
675 | 703 | $ echo "925d80f479bc z" > .hg/bookmarks |
|
676 | 704 | $ hg book |
|
677 | 705 | no bookmarks set |
|
678 | 706 | |
|
679 | 707 | test stripping a non-checked-out but bookmarked revision |
|
680 | 708 | |
|
681 | 709 | $ hg log --graph |
|
682 | 710 | o changeset: 4:9ba5f110a0b3 |
|
683 | 711 | | branch: test |
|
684 | 712 | | tag: tip |
|
685 | 713 | | parent: 2:db815d6d32e6 |
|
686 | 714 | | user: test |
|
687 | 715 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
688 | 716 | | summary: y |
|
689 | 717 | | |
|
690 | 718 | | @ changeset: 3:125c9a1d6df6 |
|
691 | 719 | |/ user: test |
|
692 | 720 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
693 | 721 | | summary: x |
|
694 | 722 | | |
|
695 | 723 | o changeset: 2:db815d6d32e6 |
|
696 | 724 | | parent: 0:f7b1eb17ad24 |
|
697 | 725 | | user: test |
|
698 | 726 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
699 | 727 | | summary: 2 |
|
700 | 728 | | |
|
701 | 729 | | o changeset: 1:925d80f479bb |
|
702 | 730 | |/ user: test |
|
703 | 731 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
704 | 732 | | summary: 1 |
|
705 | 733 | | |
|
706 | 734 | o changeset: 0:f7b1eb17ad24 |
|
707 | 735 | user: test |
|
708 | 736 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
709 | 737 | summary: 0 |
|
710 | 738 | |
|
711 | 739 | $ hg book should-end-on-two |
|
712 | 740 | $ hg co --clean 4 |
|
713 | 741 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
714 | 742 | (leaving bookmark should-end-on-two) |
|
715 | 743 | $ hg book four |
|
716 | 744 | $ hg --config extensions.mq= strip 3 |
|
717 | 745 | saved backup bundle to * (glob) |
|
718 | 746 | should-end-on-two should end up pointing to revision 2, as that's the |
|
719 | 747 | tipmost surviving ancestor of the stripped revision. |
|
720 | 748 | $ hg log --graph |
|
721 | 749 | @ changeset: 3:9ba5f110a0b3 |
|
722 | 750 | | branch: test |
|
723 | 751 | | bookmark: four |
|
724 | 752 | | tag: tip |
|
725 | 753 | | user: test |
|
726 | 754 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
727 | 755 | | summary: y |
|
728 | 756 | | |
|
729 | 757 | o changeset: 2:db815d6d32e6 |
|
730 | 758 | | bookmark: should-end-on-two |
|
731 | 759 | | parent: 0:f7b1eb17ad24 |
|
732 | 760 | | user: test |
|
733 | 761 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
734 | 762 | | summary: 2 |
|
735 | 763 | | |
|
736 | 764 | | o changeset: 1:925d80f479bb |
|
737 | 765 | |/ user: test |
|
738 | 766 | | date: Thu Jan 01 00:00:00 1970 +0000 |
|
739 | 767 | | summary: 1 |
|
740 | 768 | | |
|
741 | 769 | o changeset: 0:f7b1eb17ad24 |
|
742 | 770 | user: test |
|
743 | 771 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
744 | 772 | summary: 0 |
|
745 | 773 | |
|
746 | 774 | |
|
747 | 775 | no-op update doesn't deactivate bookmarks |
|
748 | 776 | |
|
749 | 777 | $ hg bookmarks |
|
750 | 778 | * four 3:9ba5f110a0b3 |
|
751 | 779 | should-end-on-two 2:db815d6d32e6 |
|
752 | 780 | $ hg up four |
|
753 | 781 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
754 | 782 | $ hg up |
|
755 | 783 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
756 | 784 | $ hg sum |
|
757 | 785 | parent: 3:9ba5f110a0b3 tip |
|
758 | 786 | y |
|
759 | 787 | branch: test |
|
760 | 788 | bookmarks: *four |
|
761 | 789 | commit: 2 unknown (clean) |
|
762 | 790 | update: (current) |
|
763 | 791 | phases: 4 draft |
|
764 | 792 | |
|
765 | 793 | test clearing divergent bookmarks of linear ancestors |
|
766 | 794 | |
|
767 | 795 | $ hg bookmark Z -r 0 |
|
768 | 796 | $ hg bookmark Z@1 -r 1 |
|
769 | 797 | $ hg bookmark Z@2 -r 2 |
|
770 | 798 | $ hg bookmark Z@3 -r 3 |
|
771 | 799 | $ hg book |
|
772 | 800 | Z 0:f7b1eb17ad24 |
|
773 | 801 | Z@1 1:925d80f479bb |
|
774 | 802 | Z@2 2:db815d6d32e6 |
|
775 | 803 | Z@3 3:9ba5f110a0b3 |
|
776 | 804 | * four 3:9ba5f110a0b3 |
|
777 | 805 | should-end-on-two 2:db815d6d32e6 |
|
778 | 806 | $ hg bookmark Z |
|
779 | 807 | moving bookmark 'Z' forward from f7b1eb17ad24 |
|
780 | 808 | $ hg book |
|
781 | 809 | * Z 3:9ba5f110a0b3 |
|
782 | 810 | Z@1 1:925d80f479bb |
|
783 | 811 | four 3:9ba5f110a0b3 |
|
784 | 812 | should-end-on-two 2:db815d6d32e6 |
|
785 | 813 | |
|
786 | 814 | test clearing only a single divergent bookmark across branches |
|
787 | 815 | |
|
788 | 816 | $ hg book foo -r 1 |
|
789 | 817 | $ hg book foo@1 -r 0 |
|
790 | 818 | $ hg book foo@2 -r 2 |
|
791 | 819 | $ hg book foo@3 -r 3 |
|
792 | 820 | $ hg book foo -r foo@3 |
|
793 | 821 | $ hg book |
|
794 | 822 | * Z 3:9ba5f110a0b3 |
|
795 | 823 | Z@1 1:925d80f479bb |
|
796 | 824 | foo 3:9ba5f110a0b3 |
|
797 | 825 | foo@1 0:f7b1eb17ad24 |
|
798 | 826 | foo@2 2:db815d6d32e6 |
|
799 | 827 | four 3:9ba5f110a0b3 |
|
800 | 828 | should-end-on-two 2:db815d6d32e6 |
|
801 | 829 | |
|
802 | 830 | pull --update works the same as pull && update (case #2) |
|
803 | 831 | |
|
804 | 832 | It is assumed that "hg pull" itself doesn't update current active |
|
805 | 833 | bookmark ('Y' in tests below). |
|
806 | 834 | |
|
807 | 835 | $ hg pull -q ../cloned-bookmarks-update |
|
808 | 836 | divergent bookmark Z stored as Z@2 |
|
809 | 837 | |
|
810 | 838 | (pulling revision on another named branch with --update updates |
|
811 | 839 | neither the working directory nor current active bookmark: "no-op" |
|
812 | 840 | case) |
|
813 | 841 | |
|
814 | 842 | $ echo yy >> y |
|
815 | 843 | $ hg commit -m yy |
|
816 | 844 | |
|
817 | 845 | $ hg -R ../cloned-bookmarks-update bookmarks | grep ' Y ' |
|
818 | 846 | * Y 3:125c9a1d6df6 |
|
819 | 847 | $ hg -R ../cloned-bookmarks-update pull . --update |
|
820 | 848 | pulling from . |
|
821 | 849 | searching for changes |
|
822 | 850 | adding changesets |
|
823 | 851 | adding manifests |
|
824 | 852 | adding file changes |
|
825 | 853 | added 1 changesets with 1 changes to 1 files |
|
826 | 854 | divergent bookmark Z stored as Z@default |
|
827 | 855 | adding remote bookmark foo |
|
828 | 856 | adding remote bookmark four |
|
829 | 857 | adding remote bookmark should-end-on-two |
|
830 | 858 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
831 | 859 | $ hg -R ../cloned-bookmarks-update parents -T "{rev}:{node|short}\n" |
|
832 | 860 | 3:125c9a1d6df6 |
|
833 | 861 | $ hg -R ../cloned-bookmarks-update bookmarks | grep ' Y ' |
|
834 | 862 | * Y 3:125c9a1d6df6 |
|
835 | 863 | |
|
836 | 864 | (pulling revision on current named/topological branch with --update |
|
837 | 865 | updates the working directory and current active bookmark) |
|
838 | 866 | |
|
839 | 867 | $ hg update -C -q 125c9a1d6df6 |
|
840 | 868 | $ echo xx >> x |
|
841 | 869 | $ hg commit -m xx |
|
842 | 870 | |
|
843 | 871 | $ hg -R ../cloned-bookmarks-update bookmarks | grep ' Y ' |
|
844 | 872 | * Y 3:125c9a1d6df6 |
|
845 | 873 | $ hg -R ../cloned-bookmarks-update pull . --update |
|
846 | 874 | pulling from . |
|
847 | 875 | searching for changes |
|
848 | 876 | adding changesets |
|
849 | 877 | adding manifests |
|
850 | 878 | adding file changes |
|
851 | 879 | added 1 changesets with 1 changes to 1 files |
|
852 | 880 | divergent bookmark Z stored as Z@default |
|
853 | 881 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
854 | 882 | updating bookmark Y |
|
855 | 883 | $ hg -R ../cloned-bookmarks-update parents -T "{rev}:{node|short}\n" |
|
856 | 884 | 6:81dcce76aa0b |
|
857 | 885 | $ hg -R ../cloned-bookmarks-update bookmarks | grep ' Y ' |
|
858 | 886 | * Y 6:81dcce76aa0b |
|
859 | 887 | |
|
860 | 888 | $ cd .. |
|
861 | 889 | |
|
862 | 890 | ensure changelog is written before bookmarks |
|
863 | 891 | $ hg init orderrepo |
|
864 | 892 | $ cd orderrepo |
|
865 | 893 | $ touch a |
|
866 | 894 | $ hg commit -Aqm one |
|
867 | 895 | $ hg book mybook |
|
868 | 896 | $ echo a > a |
|
869 | 897 | |
|
870 | 898 | $ cat > $TESTTMP/pausefinalize.py <<EOF |
|
871 | 899 | > from mercurial import extensions, localrepo |
|
872 | 900 | > import os, time |
|
873 | 901 |
> def transaction(orig, self, desc, report=None |
|
874 | 902 | > tr = orig(self, desc, report) |
|
875 | 903 | > def sleep(*args, **kwargs): |
|
876 | 904 | > retry = 20 |
|
877 | 905 | > while retry > 0 and not os.path.exists("$TESTTMP/unpause"): |
|
878 | 906 | > retry -= 1 |
|
879 | 907 | > time.sleep(0.5) |
|
880 | 908 | > if os.path.exists("$TESTTMP/unpause"): |
|
881 | 909 | > os.remove("$TESTTMP/unpause") |
|
882 | 910 | > # It is important that this finalizer start with 'a', so it runs before |
|
883 | 911 | > # the changelog finalizer appends to the changelog. |
|
884 | 912 | > tr.addfinalize('a-sleep', sleep) |
|
885 | 913 | > return tr |
|
886 | 914 | > |
|
887 | 915 | > def extsetup(ui): |
|
888 | 916 | > # This extension inserts an artifical pause during the transaction |
|
889 | 917 | > # finalizer, so we can run commands mid-transaction-close. |
|
890 | 918 | > extensions.wrapfunction(localrepo.localrepository, 'transaction', |
|
891 | 919 | > transaction) |
|
892 | 920 | > EOF |
|
893 | 921 | $ hg commit -qm two --config extensions.pausefinalize=$TESTTMP/pausefinalize.py & |
|
894 | 922 | $ sleep 2 |
|
895 | 923 | $ hg log -r . |
|
896 | 924 | changeset: 0:867bc5792c8c |
|
897 | 925 | bookmark: mybook |
|
898 | 926 | tag: tip |
|
899 | 927 | user: test |
|
900 | 928 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
901 | 929 | summary: one |
|
902 | 930 | |
|
903 | 931 | $ hg bookmarks |
|
904 | 932 | * mybook 0:867bc5792c8c |
|
905 | 933 | $ touch $TESTTMP/unpause |
|
906 | 934 | |
|
907 | 935 | $ cd .. |
|
908 | 936 | |
|
909 | 937 | check whether HG_PENDING makes pending changes only in related |
|
910 | 938 | repositories visible to an external hook. |
|
911 | 939 | |
|
912 | 940 | (emulate a transaction running concurrently by copied |
|
913 | 941 | .hg/bookmarks.pending in subsequent test) |
|
914 | 942 | |
|
915 | 943 | $ cat > $TESTTMP/savepending.sh <<EOF |
|
916 | 944 | > cp .hg/bookmarks.pending .hg/bookmarks.pending.saved |
|
917 | 945 | > exit 1 # to avoid adding new bookmark for subsequent tests |
|
918 | 946 | > EOF |
|
919 | 947 | |
|
920 | 948 | $ hg init unrelated |
|
921 | 949 | $ cd unrelated |
|
922 | 950 | $ echo a > a |
|
923 | 951 | $ hg add a |
|
924 | 952 | $ hg commit -m '#0' |
|
925 | 953 | $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" bookmarks INVISIBLE |
|
926 | 954 | transaction abort! |
|
927 | 955 | rollback completed |
|
928 | 956 | abort: pretxnclose hook exited with status 1 |
|
929 | 957 | [255] |
|
930 | 958 | $ cp .hg/bookmarks.pending.saved .hg/bookmarks.pending |
|
931 | 959 | |
|
932 | 960 | (check visible bookmarks while transaction running in repo) |
|
933 | 961 | |
|
934 | 962 | $ cat > $TESTTMP/checkpending.sh <<EOF |
|
935 | 963 | > echo "@repo" |
|
936 | 964 | > hg -R "$TESTTMP/repo" bookmarks |
|
937 | 965 | > echo "@unrelated" |
|
938 | 966 | > hg -R "$TESTTMP/unrelated" bookmarks |
|
939 | 967 | > exit 1 # to avoid adding new bookmark for subsequent tests |
|
940 | 968 | > EOF |
|
941 | 969 | |
|
942 | 970 | $ cd ../repo |
|
943 | 971 | $ hg --config hooks.pretxnclose="sh $TESTTMP/checkpending.sh" bookmarks NEW |
|
944 | 972 | @repo |
|
945 | 973 | * NEW 6:81dcce76aa0b |
|
946 | 974 | X2 1:925d80f479bb |
|
947 | 975 | Y 4:125c9a1d6df6 |
|
948 | 976 | Z 5:5fb12f0f2d51 |
|
949 | 977 | Z@1 1:925d80f479bb |
|
950 | 978 | Z@2 4:125c9a1d6df6 |
|
951 | 979 | foo 3:9ba5f110a0b3 |
|
952 | 980 | foo@1 0:f7b1eb17ad24 |
|
953 | 981 | foo@2 2:db815d6d32e6 |
|
954 | 982 | four 3:9ba5f110a0b3 |
|
955 | 983 | should-end-on-two 2:db815d6d32e6 |
|
956 | 984 | x y 2:db815d6d32e6 |
|
957 | 985 | @unrelated |
|
958 | 986 | no bookmarks set |
|
959 | 987 | transaction abort! |
|
960 | 988 | rollback completed |
|
961 | 989 | abort: pretxnclose hook exited with status 1 |
|
962 | 990 | [255] |
General Comments 0
You need to be logged in to leave comments.
Login now