D10293: blackbox: fix type error on log rotation on read-only filesystem

valentin.gatienbaron (Valentin Gatien-Baron) phabricator at mercurial-scm.org
Wed Mar 31 22:11:43 UTC 2021


valentin.gatienbaron created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Grepping around, the code uses either encoding.strtolocal or
  stringutil.forcebytestr in this situation. No idea which is best.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/loggingutil.py
  tests/test-blackbox.t

CHANGE DETAILS

diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -317,6 +317,17 @@
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> --debug log -r tip exited 0 after *.?? seconds (glob)
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> blackbox
 
+Skip rotation if the .hg is read-only
+
+#if unix-permissions
+  $ chmod -w .hg
+  $ hg log -r. -T '{rev}\n' --config blackbox.maxsize=1 --debug
+  warning: cannot rename '$TESTTMP/blackboxtest3/.hg/blackbox.log.1' to '$TESTTMP/blackboxtest3/.hg/blackbox.log': Permission denied
+  warning: cannot write to blackbox.log: Permission denied
+  1
+  $ chmod +w .hg
+#endif
+
 Test log recursion from dirty status check
 
   $ cat > ../r.py <<EOF
diff --git a/mercurial/loggingutil.py b/mercurial/loggingutil.py
--- a/mercurial/loggingutil.py
+++ b/mercurial/loggingutil.py
@@ -10,7 +10,10 @@
 
 import errno
 
-from . import pycompat
+from . import (
+    encoding,
+    pycompat,
+)
 
 from .utils import (
     dateutil,
@@ -32,7 +35,7 @@
             if err.errno != errno.ENOENT:
                 ui.debug(
                     b"warning: cannot remove '%s': %s\n"
-                    % (newpath, err.strerror)
+                    % (newpath, encoding.strtolocal(err.strerror))
                 )
         try:
             if newpath:
@@ -41,7 +44,7 @@
             if err.errno != errno.ENOENT:
                 ui.debug(
                     b"warning: cannot rename '%s' to '%s': %s\n"
-                    % (newpath, oldpath, err.strerror)
+                    % (newpath, oldpath, encoding.strtolocal(err.strerror))
                 )
 
     if maxsize > 0:



To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list