# HG changeset patch # User Martin von Zweigbergk # Date 2019-07-15 06:21:28 # Node ID c7d236b55a3ebc82b527d759cd41550e689b6e39 # Parent 862f6bddacceebb771024ee9b30a3d581aac7fc1 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 diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -121,6 +121,12 @@ def _unknownnode(node): """ 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 @@ class branchcache(object): 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 @@ class branchcache(object): 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 @@ class branchcache(object): 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) diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t --- a/tests/test-blackbox.t +++ b/tests/test-blackbox.t @@ -125,8 +125,8 @@ clone, commit, pull (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 @@ backup bundles get logged $ 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 @@ log rotation 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 diff --git a/tests/test-branch-change.t b/tests/test-branch-change.t --- a/tests/test-branch-change.t +++ b/tests/test-branch-change.t @@ -181,7 +181,7 @@ Make sure bookmark movement is correct 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 diff --git a/tests/test-rebase-conflicts.t b/tests/test-rebase-conflicts.t --- a/tests/test-rebase-conflicts.t +++ b/tests/test-rebase-conflicts.t @@ -324,8 +324,8 @@ Check that the right ancestors is used w 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 diff --git a/tests/test-strip.t b/tests/test-strip.t --- a/tests/test-strip.t +++ b/tests/test-strip.t @@ -861,7 +861,7 @@ check strip behavior 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