mercurial/commands.py
changeset 2971 63c3a1921a67
parent 2966 3b7626b861f8
child 2977 f63667f694de
equal deleted inserted replaced
2970:12d1475b48df 2971:63c3a1921a67
   505 
   505 
   506     def helpcmd(name):
   506     def helpcmd(name):
   507         if with_version:
   507         if with_version:
   508             show_version(ui)
   508             show_version(ui)
   509             ui.write('\n')
   509             ui.write('\n')
   510         aliases, i = findcmd(name)
   510         aliases, i = findcmd(ui, name)
   511         # synopsis
   511         # synopsis
   512         ui.write("%s\n\n" % i[2])
   512         ui.write("%s\n\n" % i[2])
   513 
   513 
   514         # description
   514         # description
   515         doc = i[0].__doc__
   515         doc = i[0].__doc__
  1152 
  1152 
  1153     if opts['options']:
  1153     if opts['options']:
  1154         options = []
  1154         options = []
  1155         otables = [globalopts]
  1155         otables = [globalopts]
  1156         if cmd:
  1156         if cmd:
  1157             aliases, entry = findcmd(cmd)
  1157             aliases, entry = findcmd(ui, cmd)
  1158             otables.append(entry[1])
  1158             otables.append(entry[1])
  1159         for t in otables:
  1159         for t in otables:
  1160             for o in t:
  1160             for o in t:
  1161                 if o[0]:
  1161                 if o[0]:
  1162                     options.append('-%s' % o[0])
  1162                     options.append('-%s' % o[0])
  1163                 options.append('--%s' % o[1])
  1163                 options.append('--%s' % o[1])
  1164         ui.write("%s\n" % "\n".join(options))
  1164         ui.write("%s\n" % "\n".join(options))
  1165         return
  1165         return
  1166 
  1166 
  1167     clist = findpossible(cmd).keys()
  1167     clist = findpossible(ui, cmd).keys()
  1168     clist.sort()
  1168     clist.sort()
  1169     ui.write("%s\n" % "\n".join(clist))
  1169     ui.write("%s\n" % "\n".join(clist))
  1170 
  1170 
  1171 def debugrebuildstate(ui, repo, rev=None):
  1171 def debugrebuildstate(ui, repo, rev=None):
  1172     """rebuild the dirstate as it would look like for the given revision"""
  1172     """rebuild the dirstate as it would look like for the given revision"""
  3147 
  3147 
  3148 norepo = ("clone init version help debugancestor debugcomplete debugdata"
  3148 norepo = ("clone init version help debugancestor debugcomplete debugdata"
  3149           " debugindex debugindexdot")
  3149           " debugindex debugindexdot")
  3150 optionalrepo = ("paths serve debugconfig")
  3150 optionalrepo = ("paths serve debugconfig")
  3151 
  3151 
  3152 def findpossible(cmd):
  3152 def findpossible(ui, cmd):
  3153     """
  3153     """
  3154     Return cmd -> (aliases, command table entry)
  3154     Return cmd -> (aliases, command table entry)
  3155     for each matching command.
  3155     for each matching command.
  3156     Return debug commands (or their aliases) only if no normal command matches.
  3156     Return debug commands (or their aliases) only if no normal command matches.
  3157     """
  3157     """
  3160     for e in table.keys():
  3160     for e in table.keys():
  3161         aliases = e.lstrip("^").split("|")
  3161         aliases = e.lstrip("^").split("|")
  3162         found = None
  3162         found = None
  3163         if cmd in aliases:
  3163         if cmd in aliases:
  3164             found = cmd
  3164             found = cmd
  3165         else:
  3165         elif not ui.config("ui", "strict"):
  3166             for a in aliases:
  3166             for a in aliases:
  3167                 if a.startswith(cmd):
  3167                 if a.startswith(cmd):
  3168                     found = a
  3168                     found = a
  3169                     break
  3169                     break
  3170         if found is not None:
  3170         if found is not None:
  3176     if not choice and debugchoice:
  3176     if not choice and debugchoice:
  3177         choice = debugchoice
  3177         choice = debugchoice
  3178 
  3178 
  3179     return choice
  3179     return choice
  3180 
  3180 
  3181 def findcmd(cmd):
  3181 def findcmd(ui, cmd):
  3182     """Return (aliases, command table entry) for command string."""
  3182     """Return (aliases, command table entry) for command string."""
  3183     choice = findpossible(cmd)
  3183     choice = findpossible(ui, cmd)
  3184 
  3184 
  3185     if choice.has_key(cmd):
  3185     if choice.has_key(cmd):
  3186         return choice[cmd]
  3186         return choice[cmd]
  3187 
  3187 
  3188     if len(choice) > 1:
  3188     if len(choice) > 1:
  3213     except fancyopts.getopt.GetoptError, inst:
  3213     except fancyopts.getopt.GetoptError, inst:
  3214         raise ParseError(None, inst)
  3214         raise ParseError(None, inst)
  3215 
  3215 
  3216     if args:
  3216     if args:
  3217         cmd, args = args[0], args[1:]
  3217         cmd, args = args[0], args[1:]
  3218         aliases, i = findcmd(cmd)
  3218         aliases, i = findcmd(ui, cmd)
  3219         cmd = aliases[0]
  3219         cmd = aliases[0]
  3220         defaults = ui.config("defaults", cmd)
  3220         defaults = ui.config("defaults", cmd)
  3221         if defaults:
  3221         if defaults:
  3222             args = defaults.split() + args
  3222             args = defaults.split() + args
  3223         c = list(i[1])
  3223         c = list(i[1])