D2165: githelp: cast commands to bytes

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Mon Feb 12 02:36:22 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is more compatible with Python 3.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2165

AFFECTED FILES
  hgext/githelp.py

CHANGE DETAILS

diff --git a/hgext/githelp.py b/hgext/githelp.py
--- a/hgext/githelp.py
+++ b/hgext/githelp.py
@@ -109,7 +109,7 @@
         self.args = []
         self.opts = {}
 
-    def __str__(self):
+    def __bytes__(self):
         cmd = "hg " + self.name
         if self.opts:
             for k, values in sorted(self.opts.iteritems()):
@@ -123,6 +123,8 @@
             cmd += " ".join(self.args)
         return cmd
 
+    __str__ = __bytes__
+
     def append(self, value):
         self.args.append(value)
 
@@ -167,14 +169,14 @@
             ui.status(_("note: use hg addremove to remove files that have "
                         "been deleted.\n\n"))
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def am(ui, repo, *args, **kwargs):
     cmdoptions=[
     ]
     args, opts = parseoptions(ui, cmdoptions, args)
     cmd = Command('import')
-    ui.status(str(cmd), "\n")
+    ui.status(bytes(cmd), "\n")
 
 def apply(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -187,7 +189,7 @@
         cmd['-p'] = opts.get('p')
     cmd.extend(args)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def bisect(ui, repo, *args, **kwargs):
     ui.status(_("See 'hg help bisect' for how to use bisect.\n\n"))
@@ -198,7 +200,7 @@
     args, opts = parseoptions(ui, cmdoptions, args)
     cmd = Command('annotate -udl')
     cmd.extend([convert(v) for v in args])
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def branch(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -239,7 +241,7 @@
             cmd.append(args[0])
         elif len(args) == 1:
             cmd.append(args[0])
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def ispath(repo, string):
     """
@@ -330,7 +332,7 @@
     else:
         raise error.Abort("a commit must be specified")
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def cherrypick(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -352,7 +354,7 @@
     else:
         cmd.extend(args)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def clean(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -367,7 +369,7 @@
         cmd['--all'] = None
     cmd.extend(args)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def clone(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -397,7 +399,7 @@
         cocmd.append(opts.get('branch'))
         cmd = cmd & cocmd
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def commit(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -445,7 +447,7 @@
 
     cmd.extend(args)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def deprecated(ui, repo, *args, **kwargs):
     ui.warn(_('This command has been deprecated in the git project, ' +
@@ -476,7 +478,7 @@
         except Exception:
             cmd.append(a)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def difftool(ui, repo, *args, **kwargs):
     ui.status(_('Mercurial does not enable external difftool by default. You '
@@ -509,7 +511,7 @@
                 else:
                     cmd['-r'] = v
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def grep(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -522,7 +524,7 @@
     # pattern first, followed by paths.
     cmd.extend(args)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def init(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -534,7 +536,7 @@
     if len(args) > 0:
         cmd.append(args[0])
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def log(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -588,7 +590,7 @@
             del args[0]
         cmd.extend(args)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def lsfiles(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -624,7 +626,7 @@
     for include in args:
         cmd['-I'] = util.shellquote(include)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def merge(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -636,7 +638,7 @@
     if len(args) > 0:
         cmd.append(args[len(args) - 1])
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def mergebase(ui, repo, *args, **kwargs):
     cmdoptions = []
@@ -650,7 +652,7 @@
 
     ui.status(_('NOTE: ancestors() is part of the revset language.\n'),
               _("Learn more about revsets with 'hg help revsets'\n\n"))
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def mergetool(ui, repo, *args, **kwargs):
     cmdoptions = []
@@ -661,7 +663,7 @@
     if len(args) == 0:
         cmd['--all'] = None
     cmd.extend(args)
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def mv(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -675,7 +677,7 @@
     if opts.get('force'):
         cmd['-f'] = None
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def pull(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -701,7 +703,7 @@
                 else:
                     cmd['-r'] = v
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def push(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -728,7 +730,7 @@
     if opts.get('force'):
         cmd['-f'] = None
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def rebase(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -748,12 +750,12 @@
         if len(args) > 0:
             ui.status(_("also note: 'hg histedit' will automatically detect"
                       " your stack, so no second argument is necessary.\n\n"))
-        ui.status((str(cmd)), "\n")
+        ui.status((bytes(cmd)), "\n")
         return
 
     if opts.get('skip'):
         cmd = Command('revert --all -r .')
-        ui.status((str(cmd)), "\n")
+        ui.status((bytes(cmd)), "\n")
 
     cmd = Command('rebase')
 
@@ -777,7 +779,7 @@
             cmd['-d'] = convert(args[0])
             cmd['-b'] = convert(args[1])
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def reflog(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -791,7 +793,7 @@
     if len(args) > 0:
         cmd.append(args[0])
 
-    ui.status(str(cmd), "\n\n")
+    ui.status(bytes(cmd), "\n\n")
     ui.status(_("note: in hg commits can be deleted from repo but we always"
               " have backups.\n"))
 
@@ -819,7 +821,7 @@
 
     cmd.append(commit)
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def revert(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -834,7 +836,7 @@
     if args:
         cmd.append(args[0])
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def revparse(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -847,7 +849,7 @@
         cmd = Command('root')
         if opts.get('show_cdup'):
             ui.status(_("note: hg root prints the root of the repository\n\n"))
-        ui.status((str(cmd)), "\n")
+        ui.status((bytes(cmd)), "\n")
     else:
         ui.status(_("note: see hg help revset for how to refer to commits\n"))
 
@@ -866,7 +868,7 @@
     if opts.get('dry_run'):
         cmd['-n'] = None
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def show(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -898,7 +900,7 @@
     else:
         cmd = Command('export')
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def stash(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -934,7 +936,7 @@
             elif len(args) > 1:
                 cmd['--name'] = args[1]
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def status(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -948,7 +950,7 @@
     if opts.get('ignored'):
         cmd['-i'] = None
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def svn(ui, repo, *args, **kwargs):
     svncmd = args[0]
@@ -965,7 +967,7 @@
 
     cmd = Command('push')
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def svnfetch(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -975,7 +977,7 @@
     cmd = Command('pull')
     cmd.append('default-push')
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def svnfindrev(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -985,7 +987,7 @@
     cmd = Command('log')
     cmd['-r'] = args[0]
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def svnrebase(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -1000,7 +1002,7 @@
 
     cmd = pullcmd & rebasecmd
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 def tag(ui, repo, *args, **kwargs):
     cmdoptions = [
@@ -1024,7 +1026,7 @@
         if opts.get('force'):
             cmd['-f'] = None
 
-    ui.status((str(cmd)), "\n")
+    ui.status((bytes(cmd)), "\n")
 
 gitcommands = {
     'add': add,



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list