소스 검색

Write index file SHA1s.

Jelmer Vernooij 16 년 전
부모
커밋
b62e2d4382
1개의 변경된 파일10개의 추가작업 그리고 3개의 파일을 삭제
  1. 10 3
      dulwich/index.py

+ 10 - 3
dulwich/index.py

@@ -27,6 +27,10 @@ from dulwich.objects import (
     hex_to_sha,
     hex_to_sha,
     sha_to_hex,
     sha_to_hex,
     )
     )
+from dulwich.pack import (
+    SHA1Reader,
+    SHA1Writer,
+    )
 
 
 
 
 def read_cache_time(f):
 def read_cache_time(f):
@@ -59,7 +63,7 @@ def read_cache_entry(f):
         char = f.read(1)
         char = f.read(1)
     # Padding:
     # Padding:
     real_size = ((f.tell() - beginoffset + 7) & ~7)
     real_size = ((f.tell() - beginoffset + 7) & ~7)
-    f.seek(beginoffset + real_size)
+    f.read((beginoffset + real_size) - f.tell())
     return (name, ctime, mtime, ino, dev, mode, uid, gid, size, 
     return (name, ctime, mtime, ino, dev, mode, uid, gid, size, 
             sha_to_hex(sha), flags)
             sha_to_hex(sha), flags)
 
 
@@ -149,18 +153,21 @@ class Index(object):
 
 
     def write(self):
     def write(self):
         """Write current contents of index to disk."""
         """Write current contents of index to disk."""
-        f = open(self._filename, 'w')
+        f = open(self._filename, 'wb')
         try:
         try:
+            f = SHA1Writer(f)
             write_index_dict(f, self._byname)
             write_index_dict(f, self._byname)
         finally:
         finally:
             f.close()
             f.close()
 
 
     def read(self):
     def read(self):
         """Read current contents of index from disk."""
         """Read current contents of index from disk."""
-        f = open(self._filename, 'r')
+        f = open(self._filename, 'rb')
         try:
         try:
+            f = SHA1Reader(f)
             for x in read_index(f):
             for x in read_index(f):
                 self[x[0]] = tuple(x[1:])
                 self[x[0]] = tuple(x[1:])
+            f.check_sha()
         finally:
         finally:
             f.close()
             f.close()