Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 47055:d55b71393907
node: replace nullid and friends with nodeconstants class
The introduction of 256bit hashes require changes to nullid and other
constant magic values. Start pushing them down from repository and
revlog where sensible.
Differential Revision: https://phab.mercurial-scm.org/D9465
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Mon, 29 Mar 2021 01:52:06 +0200 |
parents | 5d91eeac37ab |
children | 820fe29d0fd8 |
comparison
equal
deleted
inserted
replaced
46992:5fa019ceb499 | 47055:d55b71393907 |
---|---|
13 import sys | 13 import sys |
14 | 14 |
15 from .i18n import _ | 15 from .i18n import _ |
16 from .node import ( | 16 from .node import ( |
17 hex, | 17 hex, |
18 nullid, | |
19 nullrev, | 18 nullrev, |
20 short, | 19 short, |
21 wdirhex, | |
22 wdirrev, | 20 wdirrev, |
23 ) | 21 ) |
24 from .pycompat import open | 22 from .pycompat import open |
25 from . import ( | 23 from . import ( |
26 archival, | 24 archival, |
484 return b'%d+' % ctx.p1().rev() | 482 return b'%d+' % ctx.p1().rev() |
485 else: | 483 else: |
486 return b'%d ' % rev | 484 return b'%d ' % rev |
487 | 485 |
488 def formathex(h): | 486 def formathex(h): |
489 if h == wdirhex: | 487 if h == repo.nodeconstants.wdirhex: |
490 return b'%s+' % shorthex(hex(ctx.p1().node())) | 488 return b'%s+' % shorthex(hex(ctx.p1().node())) |
491 else: | 489 else: |
492 return b'%s ' % shorthex(h) | 490 return b'%s ' % shorthex(h) |
493 | 491 |
494 else: | 492 else: |
807 raise error.InputError( | 805 raise error.InputError( |
808 _(b'cannot backout change that is not an ancestor') | 806 _(b'cannot backout change that is not an ancestor') |
809 ) | 807 ) |
810 | 808 |
811 p1, p2 = repo.changelog.parents(node) | 809 p1, p2 = repo.changelog.parents(node) |
812 if p1 == nullid: | 810 if p1 == repo.nullid: |
813 raise error.InputError(_(b'cannot backout a change with no parents')) | 811 raise error.InputError(_(b'cannot backout a change with no parents')) |
814 if p2 != nullid: | 812 if p2 != repo.nullid: |
815 if not opts.get(b'parent'): | 813 if not opts.get(b'parent'): |
816 raise error.InputError(_(b'cannot backout a merge changeset')) | 814 raise error.InputError(_(b'cannot backout a merge changeset')) |
817 p = repo.lookup(opts[b'parent']) | 815 p = repo.lookup(opts[b'parent']) |
818 if p not in (p1, p2): | 816 if p not in (p1, p2): |
819 raise error.InputError( | 817 raise error.InputError( |
1083 b'start a new bisect to fix' | 1081 b'start a new bisect to fix' |
1084 ) | 1082 ) |
1085 ) | 1083 ) |
1086 else: | 1084 else: |
1087 node, p2 = repo.dirstate.parents() | 1085 node, p2 = repo.dirstate.parents() |
1088 if p2 != nullid: | 1086 if p2 != repo.nullid: |
1089 raise error.StateError(_(b'current bisect revision is a merge')) | 1087 raise error.StateError(_(b'current bisect revision is a merge')) |
1090 if rev: | 1088 if rev: |
1091 if not nodes: | 1089 if not nodes: |
1092 raise error.Abort(_(b'empty revision set')) | 1090 raise error.Abort(_(b'empty revision set')) |
1093 node = repo[nodes[-1]].node() | 1091 node = repo[nodes[-1]].node() |
4845 Returns 0 on success, 1 if there are unresolved files. | 4843 Returns 0 on success, 1 if there are unresolved files. |
4846 """ | 4844 """ |
4847 | 4845 |
4848 opts = pycompat.byteskwargs(opts) | 4846 opts = pycompat.byteskwargs(opts) |
4849 abort = opts.get(b'abort') | 4847 abort = opts.get(b'abort') |
4850 if abort and repo.dirstate.p2() == nullid: | 4848 if abort and repo.dirstate.p2() == repo.nullid: |
4851 cmdutil.wrongtooltocontinue(repo, _(b'merge')) | 4849 cmdutil.wrongtooltocontinue(repo, _(b'merge')) |
4852 cmdutil.check_incompatible_arguments(opts, b'abort', [b'rev', b'preview']) | 4850 cmdutil.check_incompatible_arguments(opts, b'abort', [b'rev', b'preview']) |
4853 if abort: | 4851 if abort: |
4854 state = cmdutil.getunfinishedstate(repo) | 4852 state = cmdutil.getunfinishedstate(repo) |
4855 if state and state._opname != b'merge': | 4853 if state and state._opname != b'merge': |
5070 else: | 5068 else: |
5071 p = [cp.node() for cp in ctx.parents()] | 5069 p = [cp.node() for cp in ctx.parents()] |
5072 | 5070 |
5073 displayer = logcmdutil.changesetdisplayer(ui, repo, opts) | 5071 displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
5074 for n in p: | 5072 for n in p: |
5075 if n != nullid: | 5073 if n != repo.nullid: |
5076 displayer.show(repo[n]) | 5074 displayer.show(repo[n]) |
5077 displayer.close() | 5075 displayer.close() |
5078 | 5076 |
5079 | 5077 |
5080 @command( | 5078 @command( |
6103 return 0 | 6101 return 0 |
6104 | 6102 |
6105 with repo.wlock(): | 6103 with repo.wlock(): |
6106 ms = mergestatemod.mergestate.read(repo) | 6104 ms = mergestatemod.mergestate.read(repo) |
6107 | 6105 |
6108 if not (ms.active() or repo.dirstate.p2() != nullid): | 6106 if not (ms.active() or repo.dirstate.p2() != repo.nullid): |
6109 raise error.StateError( | 6107 raise error.StateError( |
6110 _(b'resolve command not applicable when not merging') | 6108 _(b'resolve command not applicable when not merging') |
6111 ) | 6109 ) |
6112 | 6110 |
6113 wctx = repo[None] | 6111 wctx = repo[None] |
6221 except OSError as inst: | 6219 except OSError as inst: |
6222 if inst.errno != errno.ENOENT: | 6220 if inst.errno != errno.ENOENT: |
6223 raise | 6221 raise |
6224 | 6222 |
6225 ms.commit() | 6223 ms.commit() |
6226 branchmerge = repo.dirstate.p2() != nullid | 6224 branchmerge = repo.dirstate.p2() != repo.nullid |
6227 mergestatemod.recordupdates(repo, ms.actions(), branchmerge, None) | 6225 mergestatemod.recordupdates(repo, ms.actions(), branchmerge, None) |
6228 | 6226 |
6229 if not didwork and pats: | 6227 if not didwork and pats: |
6230 hint = None | 6228 hint = None |
6231 if not any([p for p in pats if p.find(b':') >= 0]): | 6229 if not any([p for p in pats if p.find(b':') >= 0]): |
6313 if opts.get(b"date"): | 6311 if opts.get(b"date"): |
6314 cmdutil.check_incompatible_arguments(opts, b'date', [b'rev']) | 6312 cmdutil.check_incompatible_arguments(opts, b'date', [b'rev']) |
6315 opts[b"rev"] = cmdutil.finddate(ui, repo, opts[b"date"]) | 6313 opts[b"rev"] = cmdutil.finddate(ui, repo, opts[b"date"]) |
6316 | 6314 |
6317 parent, p2 = repo.dirstate.parents() | 6315 parent, p2 = repo.dirstate.parents() |
6318 if not opts.get(b'rev') and p2 != nullid: | 6316 if not opts.get(b'rev') and p2 != repo.nullid: |
6319 # revert after merge is a trap for new users (issue2915) | 6317 # revert after merge is a trap for new users (issue2915) |
6320 raise error.InputError( | 6318 raise error.InputError( |
6321 _(b'uncommitted merge with no revision specified'), | 6319 _(b'uncommitted merge with no revision specified'), |
6322 hint=_(b"use 'hg update' or see 'hg help revert'"), | 6320 hint=_(b"use 'hg update' or see 'hg help revert'"), |
6323 ) | 6321 ) |
6333 or opts.get(b'exclude') | 6331 or opts.get(b'exclude') |
6334 or opts.get(b'all') | 6332 or opts.get(b'all') |
6335 or opts.get(b'interactive') | 6333 or opts.get(b'interactive') |
6336 ): | 6334 ): |
6337 msg = _(b"no files or directories specified") | 6335 msg = _(b"no files or directories specified") |
6338 if p2 != nullid: | 6336 if p2 != repo.nullid: |
6339 hint = _( | 6337 hint = _( |
6340 b"uncommitted merge, use --all to discard all changes," | 6338 b"uncommitted merge, use --all to discard all changes," |
6341 b" or 'hg update -C .' to abort the merge" | 6339 b" or 'hg update -C .' to abort the merge" |
6342 ) | 6340 ) |
6343 raise error.InputError(msg, hint=hint) | 6341 raise error.InputError(msg, hint=hint) |
7394 expectedtype = b'global' | 7392 expectedtype = b'global' |
7395 | 7393 |
7396 for n in names: | 7394 for n in names: |
7397 if repo.tagtype(n) == b'global': | 7395 if repo.tagtype(n) == b'global': |
7398 alltags = tagsmod.findglobaltags(ui, repo) | 7396 alltags = tagsmod.findglobaltags(ui, repo) |
7399 if alltags[n][0] == nullid: | 7397 if alltags[n][0] == repo.nullid: |
7400 raise error.InputError( | 7398 raise error.InputError( |
7401 _(b"tag '%s' is already removed") % n | 7399 _(b"tag '%s' is already removed") % n |
7402 ) | 7400 ) |
7403 if not repo.tagtype(n): | 7401 if not repo.tagtype(n): |
7404 raise error.InputError(_(b"tag '%s' does not exist") % n) | 7402 raise error.InputError(_(b"tag '%s' does not exist") % n) |
7421 raise error.InputError( | 7419 raise error.InputError( |
7422 _(b"tag '%s' already exists (use -f to force)") % n | 7420 _(b"tag '%s' already exists (use -f to force)") % n |
7423 ) | 7421 ) |
7424 if not opts.get(b'local'): | 7422 if not opts.get(b'local'): |
7425 p1, p2 = repo.dirstate.parents() | 7423 p1, p2 = repo.dirstate.parents() |
7426 if p2 != nullid: | 7424 if p2 != repo.nullid: |
7427 raise error.StateError(_(b'uncommitted merge')) | 7425 raise error.StateError(_(b'uncommitted merge')) |
7428 bheads = repo.branchheads() | 7426 bheads = repo.branchheads() |
7429 if not opts.get(b'force') and bheads and p1 not in bheads: | 7427 if not opts.get(b'force') and bheads and p1 not in bheads: |
7430 raise error.InputError( | 7428 raise error.InputError( |
7431 _( | 7429 _( |