Browse Source

Simplify Repo.stage a bit by using index_entry_from_stat.

Jelmer Vernooij 13 years ago
parent
commit
cb0a9533b2
3 changed files with 11 additions and 9 deletions
  1. 4 1
      dulwich/index.py
  2. 6 7
      dulwich/repo.py
  3. 1 1
      dulwich/tests/test_index.py

+ 4 - 1
dulwich/index.py

@@ -193,6 +193,9 @@ class Index(object):
         self.clear()
         self.read()
 
+    def __repr__(self):
+        return "%s(%r)" % (self.__class__.__name__, self._filename)
+
     def write(self):
         """Write current contents of index to disk."""
         f = GitFile(self._filename, 'wb')
@@ -380,7 +383,7 @@ def index_entry_from_stat(stat_val, hex_sha, flags, mode=None):
     :param flags: Index flags
     """
     if mode is None:
-        mode = stat_val.st_mode
+        mode = cleanup_mode(stat_val.st_mode)
     return (stat_val.st_ctime, stat_val.st_mtime, stat_val.st_dev,
             stat_val.st_ino, mode, stat_val.st_uid,
             stat_val.st_gid, stat_val.st_size, hex_sha, flags)

+ 6 - 7
dulwich/repo.py

@@ -1251,11 +1251,12 @@ class Repo(BaseRepo):
 
         :param paths: List of paths, relative to the repository path
         """
-        from dulwich.index import cleanup_mode
+        if isinstance(paths, basestring):
+            paths = [paths]
+        from dulwich.index import index_entry_from_stat
         index = self.open_index()
         for path in paths:
             full_path = os.path.join(self.path, path)
-            blob = Blob()
             try:
                 st = os.stat(full_path)
             except OSError:
@@ -1263,18 +1264,16 @@ class Repo(BaseRepo):
                 try:
                     del index[path]
                 except KeyError:
-                    pass  # Doesn't exist in the index either
+                    pass # already removed
             else:
+                blob = Blob()
                 f = open(full_path, 'rb')
                 try:
                     blob.data = f.read()
                 finally:
                     f.close()
                 self.object_store.add_object(blob)
-                # XXX: Cleanup some of the other file properties as well?
-                index[path] = (st.st_ctime, st.st_mtime, st.st_dev, st.st_ino,
-                    cleanup_mode(st.st_mode), st.st_uid, st.st_gid, st.st_size,
-                    blob.id, 0)
+                index[path] = index_entry_from_stat(st, blob.id, 0)
         index.write()
 
     def clone(self, target_path, mkdir=True, bare=False,

+ 1 - 1
dulwich/tests/test_index.py

@@ -185,7 +185,7 @@ class IndexEntryFromStatTests(TestCase):
             1324180496,
             64769L,
             131078,
-            16877,
+            16384,
             1000,
             1000,
             12288,