Mercurial > hg
comparison hgext/keyword.py @ 51125:4224b1aa7ad8 stable
branching: merge default into stable for 6.6rc0
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 07 Nov 2023 15:21:11 +0100 |
parents | 18c8c18993f0 |
children | 493034cc3265 |
comparison
equal
deleted
inserted
replaced
51117:f6bb9d1c230c | 51125:4224b1aa7ad8 |
---|---|
86 import os | 86 import os |
87 import re | 87 import re |
88 import weakref | 88 import weakref |
89 | 89 |
90 from mercurial.i18n import _ | 90 from mercurial.i18n import _ |
91 from mercurial.pycompat import getattr | |
92 from mercurial.hgweb import webcommands | 91 from mercurial.hgweb import webcommands |
93 | 92 |
94 from mercurial import ( | 93 from mercurial import ( |
95 cmdutil, | 94 cmdutil, |
96 context, | 95 context, |
129 b'add addremove annotate bundle export grep incoming init log' | 128 b'add addremove annotate bundle export grep incoming init log' |
130 b' outgoing push tip verify convert email glog' | 129 b' outgoing push tip verify convert email glog' |
131 ) | 130 ) |
132 | 131 |
133 # webcommands that do not act on keywords | 132 # webcommands that do not act on keywords |
134 nokwwebcommands = b'annotate changeset rev filediff diff comparison' | 133 nokwwebcommands = 'annotate changeset rev filediff diff comparison' |
135 | 134 |
136 # hg commands that trigger expansion only when writing to working dir, | 135 # hg commands that trigger expansion only when writing to working dir, |
137 # not when reading filelog, and unexpand when reading from working dir | 136 # not when reading filelog, and unexpand when reading from working dir |
138 restricted = ( | 137 restricted = ( |
139 b'merge kwexpand kwshrink record qrecord resolve transplant' | 138 b'merge kwexpand kwshrink record qrecord resolve transplant' |
418 | 417 |
419 def _status(ui, repo, wctx, kwt, *pats, **opts): | 418 def _status(ui, repo, wctx, kwt, *pats, **opts): |
420 """Bails out if [keyword] configuration is not active. | 419 """Bails out if [keyword] configuration is not active. |
421 Returns status of working directory.""" | 420 Returns status of working directory.""" |
422 if kwt: | 421 if kwt: |
423 opts = pycompat.byteskwargs(opts) | |
424 return repo.status( | 422 return repo.status( |
425 match=scmutil.match(wctx, pats, opts), | 423 match=scmutil.match(wctx, pats, pycompat.byteskwargs(opts)), |
426 clean=True, | 424 clean=True, |
427 unknown=opts.get(b'unknown') or opts.get(b'all'), | 425 unknown=opts.get('unknown') or opts.get('all'), |
428 ) | 426 ) |
429 if ui.configitems(b'keyword'): | 427 if ui.configitems(b'keyword'): |
430 raise error.Abort(_(b'[keyword] patterns cannot match')) | 428 raise error.Abort(_(b'[keyword] patterns cannot match')) |
431 raise error.Abort(_(b'no [keyword] patterns configured')) | 429 raise error.Abort(_(b'no [keyword] patterns configured')) |
432 | 430 |
602 if pats: | 600 if pats: |
603 cwd = repo.getcwd() | 601 cwd = repo.getcwd() |
604 else: | 602 else: |
605 cwd = b'' | 603 cwd = b'' |
606 files = [] | 604 files = [] |
607 opts = pycompat.byteskwargs(opts) | 605 |
608 if not opts.get(b'unknown') or opts.get(b'all'): | 606 if not opts.get('unknown') or opts.get('all'): |
609 files = sorted(status.modified + status.added + status.clean) | 607 files = sorted(status.modified + status.added + status.clean) |
610 kwfiles = kwt.iskwfile(files, wctx) | 608 kwfiles = kwt.iskwfile(files, wctx) |
611 kwdeleted = kwt.iskwfile(status.deleted, wctx) | 609 kwdeleted = kwt.iskwfile(status.deleted, wctx) |
612 kwunknown = kwt.iskwfile(status.unknown, wctx) | 610 kwunknown = kwt.iskwfile(status.unknown, wctx) |
613 if not opts.get(b'ignore') or opts.get(b'all'): | 611 if not opts.get('ignore') or opts.get('all'): |
614 showfiles = kwfiles, kwdeleted, kwunknown | 612 showfiles = kwfiles, kwdeleted, kwunknown |
615 else: | 613 else: |
616 showfiles = [], [], [] | 614 showfiles = [], [], [] |
617 if opts.get(b'all') or opts.get(b'ignore'): | 615 if opts.get('all') or opts.get('ignore'): |
618 showfiles += ( | 616 showfiles += ( |
619 [f for f in files if f not in kwfiles], | 617 [f for f in files if f not in kwfiles], |
620 [f for f in status.unknown if f not in kwunknown], | 618 [f for f in status.unknown if f not in kwunknown], |
621 ) | 619 ) |
622 kwlabels = b'enabled deleted enabledunknown ignored ignoredunknown'.split() | 620 kwlabels = b'enabled deleted enabledunknown ignored ignoredunknown'.split() |
623 kwstates = zip(kwlabels, pycompat.bytestr(b'K!kIi'), showfiles) | 621 kwstates = zip(kwlabels, pycompat.bytestr(b'K!kIi'), showfiles) |
624 fm = ui.formatter(b'kwfiles', opts) | 622 fm = ui.formatter(b'kwfiles', pycompat.byteskwargs(opts)) |
625 fmt = b'%.0s%s\n' | 623 fmt = b'%.0s%s\n' |
626 if opts.get(b'all') or ui.verbose: | 624 if opts.get('all') or ui.verbose: |
627 fmt = b'%s %s\n' | 625 fmt = b'%s %s\n' |
628 for kwstate, char, filenames in kwstates: | 626 for kwstate, char, filenames in kwstates: |
629 label = b'kwfiles.' + kwstate | 627 label = b'kwfiles.' + kwstate |
630 for f in filenames: | 628 for f in filenames: |
631 fm.startitem() | 629 fm.startitem() |
804 '''Monkeypatch dispatch._parse to obtain running hg command.''' | 802 '''Monkeypatch dispatch._parse to obtain running hg command.''' |
805 cmd, func, args, options, cmdoptions = orig(ui, args) | 803 cmd, func, args, options, cmdoptions = orig(ui, args) |
806 kwtools[b'hgcmd'] = cmd | 804 kwtools[b'hgcmd'] = cmd |
807 return cmd, func, args, options, cmdoptions | 805 return cmd, func, args, options, cmdoptions |
808 | 806 |
809 extensions.wrapfunction(dispatch, b'_parse', kwdispatch_parse) | 807 extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse) |
810 | 808 |
811 extensions.wrapfunction(context.filectx, b'cmp', kwfilectx_cmp) | 809 extensions.wrapfunction(context.filectx, 'cmp', kwfilectx_cmp) |
812 extensions.wrapfunction(patch.patchfile, b'__init__', kwpatchfile_init) | 810 extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) |
813 extensions.wrapfunction(patch, b'diff', kwdiff) | 811 extensions.wrapfunction(patch, 'diff', kwdiff) |
814 extensions.wrapfunction(cmdutil, b'amend', kw_amend) | 812 extensions.wrapfunction(cmdutil, 'amend', kw_amend) |
815 extensions.wrapfunction(cmdutil, b'copy', kw_copy) | 813 extensions.wrapfunction(cmdutil, 'copy', kw_copy) |
816 extensions.wrapfunction(cmdutil, b'dorecord', kw_dorecord) | 814 extensions.wrapfunction(cmdutil, 'dorecord', kw_dorecord) |
817 for c in nokwwebcommands.split(): | 815 for c in nokwwebcommands.split(): |
818 extensions.wrapfunction(webcommands, c, kwweb_skip) | 816 extensions.wrapfunction(webcommands, c, kwweb_skip) |
819 | 817 |
820 | 818 |
821 def reposetup(ui, repo): | 819 def reposetup(ui, repo): |