浏览代码

Fix regression in handling of tags. (#302).

Jelmer Vernooij 10 年之前
父节点
当前提交
0959a6f85c
共有 2 个文件被更改,包括 20 次插入3 次删除
  1. 4 3
      dulwich/refs.py
  2. 16 0
      dulwich/tests/test_refs.py

+ 4 - 3
dulwich/refs.py

@@ -23,13 +23,13 @@
 """
 import errno
 import os
+import sys
 
 from dulwich.errors import (
     PackedRefsException,
     RefFormatError,
     )
 from dulwich.objects import (
-    hex_to_sha,
     git_line,
     valid_hexsha,
     )
@@ -416,7 +416,7 @@ class DiskRefsContainer(RefsContainer):
         for root, dirs, files in os.walk(self.refpath(b'refs')):
             dir = root[len(path):].strip(os.path.sep).replace(os.path.sep, "/")
             for filename in files:
-                refname = ("%s/%s" % (dir, filename)).strip("/").encode('ascii')
+                refname = ("%s/%s" % (dir, filename)).encode(sys.getfilesystemencoding())
                 if check_ref_format(refname):
                     allkeys.add(refname)
         allkeys.update(self.get_packed_refs())
@@ -426,7 +426,8 @@ class DiskRefsContainer(RefsContainer):
         """Return the disk path of a ref.
 
         """
-        name = name.decode('ascii')
+        if getattr(self.path, "encode", None) and getattr(name, "decode", None):
+            name = name.decode(sys.getfilesystemencoding())
         if os.path.sep != "/":
             name = name.replace("/", os.path.sep)
         return os.path.join(self.path, name)

+ 16 - 0
dulwich/tests/test_refs.py

@@ -1,4 +1,5 @@
 # test_refs.py -- tests for refs.py
+# encoding: utf-8
 # Copyright (C) 2013 Jelmer Vernooij <jelmer@samba.org>
 #
 # This program is free software; you can redistribute it and/or
@@ -21,6 +22,7 @@
 
 from io import BytesIO
 import os
+import sys
 import tempfile
 
 from dulwich import errors
@@ -39,6 +41,7 @@ from dulwich.refs import (
 from dulwich.repo import Repo
 
 from dulwich.tests import (
+    skipIf,
     TestCase,
     )
 
@@ -435,6 +438,19 @@ class DiskRefsContainerTests(RefsContainerTests, TestCase):
                          self._refs.read_ref(b'refs/heads/packed'))
         self.assertEqual(None, self._refs.read_ref(b'nonexistant'))
 
+    @skipIf(sys.getfilesystemencoding() == 'ascii',
+            "filesystem encoding doesn't support non-ascii characters")
+    def test_non_ascii(self):
+        p = os.path.join(self._repo.path, 'refs', 'tags', 'schön')
+        with open(p, 'w') as f:
+            f.write('00' * 20)
+
+        expected_refs = dict(_TEST_REFS)
+        encoded_ref = u'refs/tags/schön'.encode(sys.getfilesystemencoding())
+        expected_refs[encoded_ref] = b'00' * 20
+
+        self.assertEqual(expected_refs, self._repo.get_refs())
+
 
 _TEST_REFS_SERIALIZED = (
     b'42d06bd4b77fed026b154d16493e5deab78f02ec\trefs/heads/40-char-ref-aaaaaaaaaaaaaaaaaa\n'