Browse Source

add a mode argument to index_entry_from_stat.

Jelmer Vernooij 13 năm trước cách đây
mục cha
commit
9fcc0b7862
2 tập tin đã thay đổi với 22 bổ sung2 xóa
  1. 4 2
      dulwich/index.py
  2. 18 0
      dulwich/tests/test_index.py

+ 4 - 2
dulwich/index.py

@@ -372,13 +372,15 @@ def changes_from_tree(names, lookup_entry, object_store, tree,
         yield ((None, name), (None, other_mode), (None, other_sha))
 
 
-def index_entry_from_stat(stat_val, hex_sha, flags):
+def index_entry_from_stat(stat_val, hex_sha, flags, mode=None):
     """Create a new index entry from a stat value.
 
     :param stat_val: POSIX stat_result instance
     :param hex_sha: Hex sha of the object
     :param flags: Index flags
     """
+    if mode is None:
+        mode = stat_val.st_mode
     return (stat_val.st_ctime, stat_val.st_mtime, stat_val.st_dev,
-            stat_val.st_ino, stat_val.st_mode, stat_val.st_uid,
+            stat_val.st_ino, mode, stat_val.st_uid,
             stat_val.st_gid, stat_val.st_size, hex_sha, flags)

+ 18 - 0
dulwich/tests/test_index.py

@@ -191,3 +191,21 @@ class IndexEntryFromStatTests(TestCase):
             12288,
             '2222222222222222222222222222222222222222',
             0))
+
+    def test_override_mode(self):
+        st = posix.stat_result((stat.S_IFREG + 0644, 131078, 64769L,
+                154, 1000, 1000, 12288,
+                1323629595, 1324180496, 1324180496))
+        entry = index_entry_from_stat(st, "22" * 20, 0,
+                mode=stat.S_IFREG + 0755)
+        self.assertEquals(entry, (
+            1324180496,
+            1324180496,
+            64769L,
+            131078,
+            33261,
+            1000,
+            1000,
+            12288,
+            '2222222222222222222222222222222222222222',
+            0))