py3: fix formatting of branchmap log messages with repo.filtername=None
authorMartin von Zweigbergk <martinvonz@google.com>
Sun, 14 Jul 2019 23:21:28 -0700
changeset 42602 c7d236b55a3e
parent 42601 862f6bddacce
child 42603 3018749a71bb
py3: fix formatting of branchmap log messages with repo.filtername=None `"%s" % None` does not work on py3. I've extracted a little function for producing a formatted message given the filter name. Differential Revision: https://phab.mercurial-scm.org/D6644
mercurial/branchmap.py
tests/test-blackbox.t
tests/test-branch-change.t
tests/test-rebase-conflicts.t
tests/test-strip.t
--- a/mercurial/branchmap.py	Sun Jul 14 01:31:42 2019 -0400
+++ b/mercurial/branchmap.py	Sun Jul 14 23:21:28 2019 -0700
@@ -121,6 +121,12 @@
     """
     raise ValueError(r'node %s does not exist' % pycompat.sysstr(hex(node)))
 
+def _branchcachedesc(repo):
+    if repo.filtername is not None:
+        return 'branch cache (%s)' % repo.filtername
+    else:
+        return 'branch cache'
+
 class branchcache(object):
     """A dict like object that hold branches heads cache.
 
@@ -241,11 +247,9 @@
 
         except Exception as inst:
             if repo.ui.debugflag:
-                msg = 'invalid branchheads cache'
-                if repo.filtername is not None:
-                    msg += ' (%s)' % repo.filtername
-                msg += ': %s\n'
-                repo.ui.debug(msg % pycompat.bytestr(inst))
+                msg = 'invalid %s: %s\n'
+                repo.ui.debug(msg % (_branchcachedesc(repo),
+                                     pycompat.bytestr(inst)))
             bcache = None
 
         finally:
@@ -351,9 +355,8 @@
                         state = 'o'
                     f.write("%s %s %s\n" % (hex(node), state, label))
             f.close()
-            repo.ui.log('branchcache',
-                        'wrote %s branch cache with %d labels and %d nodes\n',
-                        repo.filtername, len(self._entries), nodecount)
+            repo.ui.log('branchcache', 'wrote %s with %d labels and %d nodes\n',
+                        _branchcachedesc(repo), len(self._entries), nodecount)
         except (IOError, OSError, error.Abort) as inst:
             # Abort may be raised by read only opener, so log and continue
             repo.ui.debug("couldn't write branch cache: %s\n" %
@@ -424,8 +427,8 @@
         self.filteredhash = scmutil.filteredhash(repo, self.tiprev)
 
         duration = util.timer() - starttime
-        repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n',
-                    repo.filtername or b'None', duration)
+        repo.ui.log('branchcache', 'updated %s in %.4f seconds\n',
+                    _branchcachedesc(repo), duration)
 
         self.write(repo)
 
--- a/tests/test-blackbox.t	Sun Jul 14 01:31:42 2019 -0400
+++ b/tests/test-blackbox.t	Sun Jul 14 23:21:28 2019 -0700
@@ -125,8 +125,8 @@
   (run 'hg update' to get a working copy)
   $ hg blackbox -l 6
   1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> pull
-  1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> updated served branch cache in * seconds (glob)
-  1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> wrote served branch cache with 1 labels and 2 nodes
+  1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> updated branch cache (served) in * seconds (glob)
+  1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> wrote branch cache (served) with 1 labels and 2 nodes
   1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> 1 incoming changes - new heads: d02f48003e62
   1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> pull exited 0 after * seconds (glob)
   1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> blackbox -l 6
@@ -189,8 +189,8 @@
   $ hg blackbox -l 6
   1970/01/01 00:00:00 bob @73f6ee326b27d820b0472f1a825e3a50f3dc489b (5000)> strip tip
   1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> saved backup bundle to $TESTTMP/blackboxtest2/.hg/strip-backup/73f6ee326b27-7612e004-backup.hg
-  1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> updated base branch cache in * seconds (glob)
-  1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> wrote base branch cache with 1 labels and 2 nodes
+  1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> updated branch cache (base) in * seconds (glob)
+  1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> wrote branch cache (base) with 1 labels and 2 nodes
   1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> strip tip exited 0 after * seconds (glob)
   1970/01/01 00:00:00 bob @6563da9dcf87b1949716e38ff3e3dfaa3198eb06 (5000)> blackbox -l 6
 
@@ -303,8 +303,8 @@
   result: 0
   $ hg blackbox
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> updating the branch cache
-  1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> updated served branch cache in * seconds (glob)
-  1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> wrote served branch cache with 1 labels and 1 nodes
+  1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> updated branch cache (served) in * seconds (glob)
+  1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> wrote branch cache (served) with 1 labels and 1 nodes
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> --debug commit -m commit2 -d 2000-01-02 foo exited 0 after *.?? seconds (glob)
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> --debug log -r 0
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> writing .hg/cache/tags2-visible with 0 tags
--- a/tests/test-branch-change.t	Sun Jul 14 01:31:42 2019 -0400
+++ b/tests/test-branch-change.t	Sun Jul 14 23:21:28 2019 -0700
@@ -181,7 +181,7 @@
   starting 4 threads for background file closing (?)
   changed branch on 2 changesets
   updating the branch cache
-  invalid branchheads cache (served): tip differs
+  invalid branch cache (served): tip differs
 
   $ hg glog -r '(.^)::'
   @  9:de1404b45a69 Added e
--- a/tests/test-rebase-conflicts.t	Sun Jul 14 01:31:42 2019 -0400
+++ b/tests/test-rebase-conflicts.t	Sun Jul 14 23:21:28 2019 -0700
@@ -324,8 +324,8 @@
   bundle2-input-part: total payload size 24
   bundle2-input-bundle: 2 parts total
   updating the branch cache
-  invalid branchheads cache (served): tip differs
-  invalid branchheads cache (served.hidden): tip differs
+  invalid branch cache (served): tip differs
+  invalid branch cache (served.hidden): tip differs
   rebase completed
 
 Test minimization of merge conflicts
--- a/tests/test-strip.t	Sun Jul 14 01:31:42 2019 -0400
+++ b/tests/test-strip.t	Sun Jul 14 23:21:28 2019 -0700
@@ -861,7 +861,7 @@
   bundle2-output-part: "phase-heads" 24 bytes payload
   saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/6625a5168474-345bb43d-backup.hg
   updating the branch cache
-  invalid branchheads cache (served): tip differs
+  invalid branch cache (served): tip differs
   $ hg log -G
   o  changeset:   2:5c51d8d6557d
   |  tag:         tip