Browse Source

Don't pass in filesystem encoding.

Jelmer Vernooij 4 years ago
parent
commit
ff6911f4aa
2 changed files with 8 additions and 9 deletions
  1. 2 3
      dulwich/index.py
  2. 6 6
      dulwich/tests/test_index.py

+ 2 - 3
dulwich/index.py

@@ -705,17 +705,16 @@ def _tree_to_fs_path(root_path, tree_path):
     return os.path.join(root_path, sep_corrected_path)
 
 
-def _fs_to_tree_path(fs_path, fs_encoding=None):
+def _fs_to_tree_path(fs_path):
     """Convert a file system path to a git tree path.
 
     Args:
       fs_path: File system path.
-      fs_encoding: File system encoding
 
     Returns:  Git tree path as bytes
     """
     if not isinstance(fs_path, bytes):
-        fs_path_bytes = fs_path.encode(fs_encoding)
+        fs_path_bytes = os.fsencode(fs_path)
     else:
         fs_path_bytes = fs_path
     if os_sep_bytes != b'/':

+ 6 - 6
dulwich/tests/test_index.py

@@ -753,14 +753,14 @@ class TestTreeFSPathConversion(TestCase):
         fs_path = _tree_to_fs_path(b'/prefix/path', tree_path)
         self.assertEqual(
             fs_path,
-            os.path.join(u'/prefix/path', u'délwíçh', u'foo').encode('utf8'))
+            os.fsencode(os.path.join(u'/prefix/path', u'délwíçh', u'foo')))
 
     def test_fs_to_tree_path_str(self):
         fs_path = os.path.join(os.path.join(u'délwíçh', u'foo'))
-        tree_path = _fs_to_tree_path(fs_path, "utf-8")
-        self.assertEqual(tree_path, u'délwíçh/foo'.encode("utf-8"))
+        tree_path = _fs_to_tree_path(fs_path)
+        self.assertEqual(tree_path, u'délwíçh/foo'.encode('utf-8'))
 
     def test_fs_to_tree_path_bytes(self):
-        fs_path = os.path.join(os.path.join(u'délwíçh', u'foo').encode('utf8'))
-        tree_path = _fs_to_tree_path(fs_path, "utf-8")
-        self.assertEqual(tree_path, u'délwíçh/foo'.encode('utf8'))
+        fs_path = os.path.join(os.fsencode(os.path.join(u'délwíçh', u'foo')))
+        tree_path = _fs_to_tree_path(fs_path)
+        self.assertEqual(tree_path, u'délwíçh/foo'.encode('utf-8'))