Patchwork D8210: debugbackupbundle: make py3 fixes and add `test-` prefix to test file

login
register
mail settings
Submitter phabricator
Date March 4, 2020, 9:01 a.m.
Message ID <differential-rev-PHID-DREV-vlb7tmpm257r4fsoyfez-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45445/
State Superseded
Headers show

Comments

phabricator - March 4, 2020, 9:01 a.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This should ideally be amended in 89323f85176e725234bb70b081bc46614ae27589 <https://phab.mercurial-scm.org/rHG89323f85176e725234bb70b081bc46614ae27589>.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/debugcommands.py
  tests/debugbackupbundle.t
  tests/test-debugbackupbundle.t

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - March 4, 2020, 7:24 p.m.
durin42 added a comment.
durin42 added a reviewer: pulkit.
durin42 commandeered this revision.


  Folding into that revision per request.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8210/new/

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

To: durin42, #hg-reviewers, pulkit
Cc: durin42, mercurial-devel

Patch

diff --git a/tests/debugbackupbundle.t b/tests/test-debugbackupbundle.t
rename from tests/debugbackupbundle.t
rename to tests/test-debugbackupbundle.t
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -3428,56 +3428,59 @@ 
     --verbose will print the entire commit message and the bundle path for that
     backup.
     """
-    backups = filter(
-        os.path.isfile, glob.glob(repo.vfs.join("strip-backup") + "/*.hg")
+    backups = list(
+        filter(
+            os.path.isfile, glob.glob(repo.vfs.join(b"strip-backup") + b"/*.hg")
+        )
     )
     backups.sort(key=lambda x: os.path.getmtime(x), reverse=True)
 
-    opts["bundle"] = ""
-    opts["force"] = None
+    opts = pycompat.byteskwargs(opts)
+    opts[b"bundle"] = b""
+    opts[b"force"] = None
     limit = logcmdutil.getlimit(opts)
 
     def display(other, chlist, displayer):
-        if opts.get("newest_first"):
+        if opts.get(b"newest_first"):
             chlist.reverse()
         count = 0
         for n in chlist:
             if limit is not None and count >= limit:
                 break
             parents = [True for p in other.changelog.parents(n) if p != nullid]
-            if opts.get("no_merges") and len(parents) == 2:
+            if opts.get(b"no_merges") and len(parents) == 2:
                 continue
             count += 1
             displayer.show(other[n])
 
-    recovernode = opts.get("recover")
+    recovernode = opts.get(b"recover")
     if recovernode:
         if scmutil.isrevsymbol(repo, recovernode):
-            ui.warn(_("%s already exists in the repo\n") % recovernode)
+            ui.warn(_(b"%s already exists in the repo\n") % recovernode)
             return
     elif backups:
         msg = _(
-            "Recover changesets using: hg debugbackupbundle --recover "
-            "<changeset hash>\n\nAvailable backup changesets:"
+            b"Recover changesets using: hg debugbackupbundle --recover "
+            b"<changeset hash>\n\nAvailable backup changesets:"
         )
-        ui.status(msg, label="status.removed")
+        ui.status(msg, label=b"status.removed")
     else:
-        ui.status(_("no backup changesets found\n"))
+        ui.status(_(b"no backup changesets found\n"))
         return
 
     for backup in backups:
         # Much of this is copied from the hg incoming logic
         source = ui.expandpath(os.path.relpath(backup, encoding.getcwd()))
-        source, branches = hg.parseurl(source, opts.get("branch"))
+        source, branches = hg.parseurl(source, opts.get(b"branch"))
         try:
             other = hg.peer(repo, opts, source)
         except error.LookupError as ex:
-            msg = _("\nwarning: unable to open bundle %s") % source
-            hint = _("\n(missing parent rev %s)\n") % short(ex.name)
+            msg = _(b"\nwarning: unable to open bundle %s") % source
+            hint = _(b"\n(missing parent rev %s)\n") % short(ex.name)
             ui.warn(msg, hint=hint)
             continue
         revs, checkout = hg.addbranchrevs(
-            repo, other, branches, opts.get("rev")
+            repo, other, branches, opts.get(b"rev")
         )
 
         if revs:
@@ -3487,7 +3490,7 @@ 
         try:
             ui.quiet = True
             other, chlist, cleanupfn = bundlerepo.getremotechanges(
-                ui, repo, other, revs, opts["bundle"], opts["force"]
+                ui, repo, other, revs, opts[b"bundle"], opts[b"force"]
             )
         except error.LookupError:
             continue
@@ -3498,9 +3501,9 @@ 
             if not chlist:
                 continue
             if recovernode:
-                with repo.lock(), repo.transaction("unbundle") as tr:
+                with repo.lock(), repo.transaction(b"unbundle") as tr:
                     if scmutil.isrevsymbol(other, recovernode):
-                        ui.status(_("Unbundling %s\n") % (recovernode))
+                        ui.status(_(b"Unbundling %s\n") % (recovernode))
                         f = hg.openpath(ui, source)
                         gen = exchange.readbundle(ui, f, source)
                         if isinstance(gen, bundle2.unbundle20):
@@ -3508,24 +3511,26 @@ 
                                 repo,
                                 gen,
                                 tr,
-                                source="unbundle",
-                                url="bundle:" + source,
+                                source=b"unbundle",
+                                url=b"bundle:" + source,
                             )
                         else:
-                            gen.apply(repo, "unbundle", "bundle:" + source)
+                            gen.apply(repo, b"unbundle", b"bundle:" + source)
                         break
             else:
-                backupdate = time.strftime(
-                    "%a %H:%M, %Y-%m-%d",
-                    time.localtime(os.path.getmtime(source)),
+                backupdate = encoding.strtolocal(
+                    time.strftime(
+                        "%a %H:%M, %Y-%m-%d",
+                        time.localtime(os.path.getmtime(source)),
+                    )
                 )
-                ui.status("\n%s\n" % (backupdate.ljust(50)))
+                ui.status(b"\n%s\n" % (backupdate.ljust(50)))
                 if ui.verbose:
-                    ui.status("%s%s\n" % ("bundle:".ljust(13), source))
+                    ui.status(b"%s%s\n" % (b"bundle:".ljust(13), source))
                 else:
                     opts[
-                        "template"
-                    ] = "{label('status.modified', node|short)} {desc|firstline}\n"
+                        b"template"
+                    ] = b"{label('status.modified', node|short)} {desc|firstline}\n"
                 displayer = logcmdutil.changesetdisplayer(
                     ui, other, opts, False
                 )