]> arthur.barton.de Git - bup.git/commitdiff
Add "do nothing" path_msg to centralize path conversions
authorRob Browning <rlb@defaultvalue.org>
Thu, 26 Dec 2019 18:27:07 +0000 (12:27 -0600)
committerRob Browning <rlb@defaultvalue.org>
Fri, 17 Jan 2020 18:54:13 +0000 (12:54 -0600)
Add path_msg(p) and use it in cmd/bup (as a start).  The intent is to
centralize the encoding of all path values that are to be included in
strings intended for "display" (e.g. stderr, which appears to have to
be a text stream in python 3).

For now, the function will do nothing -- i.e. given the currently
enforced iso-8859-1 encoding we'll just continue to produce the
original path bytes on stderr, but we may well want to make this
configurable at some point (perhaps git's quotePath algorithm might
provide a likely option), and if nothing else, using path_msg()
everywhere makes it much easier to identify and adapt the relevant
code, whatever we decide.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/bup
lib/bup/io.py

diff --git a/cmd/bup b/cmd/bup
index e8462dffdb406ac2db6909a09ab38ebe14908f62..f696449babcd88f98176a9a8995c52ea4b89bd48 100755 (executable)
--- a/cmd/bup
+++ b/cmd/bup
@@ -20,6 +20,7 @@ import errno, getopt, os, re, select, signal, subprocess, sys
 from subprocess import PIPE
 
 from bup.compat import environ, restore_lc_env
+from bup.io import path_msg
 
 if sys.version_info[0] != 2 \
    and not environ.get(b'BUP_ALLOW_UNEXPECTED_PYTHON_VERSION') == b'true':
@@ -127,7 +128,7 @@ def subpath(s):
 
 subcmd[0] = subpath(subcmd_name)
 if not os.path.exists(subcmd[0]):
-    usage('error: unknown command "%s"' % subcmd_name)
+    usage('error: unknown command "%s"' % path_msg(subcmd_name))
 
 already_fixed = atoi(os.environ.get('BUP_FORCE_TTY'))
 if subcmd_name in ['mux', 'ftp', 'help']:
index 6f4cca7e10aa1cff0bf47575d1bbfbe137956b48..571e9b9102d76fa43b42c7fb283d722b17b0f618 100644 (file)
@@ -10,3 +10,15 @@ if compat.py_maj > 2:
 else:
     def byte_stream(file):
         return file
+
+
+def path_msg(x):
+    """Return a string representation of a path.
+
+    For now, assume that the destination encoding is going to be
+    ISO-8859-1, which it should be, for the primary current
+    destination, stderr, given the current bup-python.
+
+    """
+    # FIXME: configurability (might git-config quotePath be involved?)
+    return x.decode(encoding='iso-8859-1')