712 if cmd and util.safehasattr(fn, 'shell'): |
712 if cmd and util.safehasattr(fn, 'shell'): |
713 d = lambda: fn(ui, *args[1:]) |
713 d = lambda: fn(ui, *args[1:]) |
714 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, |
714 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, |
715 [], {}) |
715 [], {}) |
716 |
716 |
717 def _cmdattr(ui, cmd, func, attr): |
|
718 try: |
|
719 return getattr(func, attr) |
|
720 except AttributeError: |
|
721 ui.deprecwarn("missing attribute '%s', use @command decorator " |
|
722 "to register '%s'" % (attr, cmd), '3.8') |
|
723 return False |
|
724 |
|
725 _loaded = set() |
717 _loaded = set() |
726 |
718 |
727 # list of (objname, loadermod, loadername) tuple: |
719 # list of (objname, loadermod, loadername) tuple: |
728 # - objname is the name of an object in extension module, from which |
720 # - objname is the name of an object in extension module, from which |
729 # extra information is loaded |
721 # extra information is loaded |
852 return commands.help_(ui, 'shortlist') |
844 return commands.help_(ui, 'shortlist') |
853 |
845 |
854 with profiling.maybeprofile(lui): |
846 with profiling.maybeprofile(lui): |
855 repo = None |
847 repo = None |
856 cmdpats = args[:] |
848 cmdpats = args[:] |
857 if not _cmdattr(ui, cmd, func, 'norepo'): |
849 if not func.norepo: |
858 # use the repo from the request only if we don't have -R |
850 # use the repo from the request only if we don't have -R |
859 if not rpath and not cwd: |
851 if not rpath and not cwd: |
860 repo = req.repo |
852 repo = req.repo |
861 |
853 |
862 if repo: |
854 if repo: |
875 except error.RequirementError: |
867 except error.RequirementError: |
876 raise |
868 raise |
877 except error.RepoError: |
869 except error.RepoError: |
878 if rpath and rpath[-1]: # invalid -R path |
870 if rpath and rpath[-1]: # invalid -R path |
879 raise |
871 raise |
880 if not _cmdattr(ui, cmd, func, 'optionalrepo'): |
872 if not func.optionalrepo: |
881 if (_cmdattr(ui, cmd, func, 'inferrepo') and |
873 if func.inferrepo and args and not path: |
882 args and not path): |
|
883 # try to infer -R from command args |
874 # try to infer -R from command args |
884 repos = map(cmdutil.findrepo, args) |
875 repos = map(cmdutil.findrepo, args) |
885 guess = repos[0] |
876 guess = repos[0] |
886 if guess and repos.count(guess) == len(repos): |
877 if guess and repos.count(guess) == len(repos): |
887 req.args = ['--repository', guess] + fullargs |
878 req.args = ['--repository', guess] + fullargs |