Changeset bb270f6cff08…
Parent 24ec259c52fa…
by
Changes to 3 files · Browse files at bb270f6cff08 Showing diff from parent 24ec259c52fa Diff from another changeset...
@@ -59,7 +59,7 @@ f.write(struct.pack(">LLLLLL20sH", ino, dev, mode, uid, gid, size, sha, flags))
f.write(name)
f.write(chr(0))
- real_size = ((f.tell() - beginoffset + 8) & ~7)
+ real_size = ((f.tell() - beginoffset + 7) & ~7)
f.write(chr(0) * (f.tell() - (beginoffset + real_size)))
return
@@ -142,6 +142,13 @@ def __getitem__(self, name):
return self._byname[name]
+ def get_sha1(self, path):
+ return self[path][-2]
+
+ def clear(self):
+ self._byname = {}
+ self._entries = []
+
def __setitem__(self, name, x):
# Remove the old entry if any
old_entry = self._byname.get(x[0])
@@ -149,3 +156,7 @@ self._entries.remove(old_entry)
self._entries.append(x)
self._byname[x[0]] = x
+
+ def update(self, entries):
+ for name, value in entries.iteritems():
+ self[name] = value
|
@@ -100,11 +100,13 @@ return None
def _add_shafile(self, sha, o):
- path = self._get_shafile_path(sha)
- f = os.path.open(path, 'w')
+ dir = os.path.join(self.path, sha[:2])
+ if not os.path.isdir(dir):
+ os.mkdir(dir)
+ path = os.path.join(dir, sha[2:])
+ f = open(path, 'w+')
try:
- f.write(o._header())
- f.write(o._text)
+ f.write(o.as_legacy_object())
finally:
f.close()
@@ -211,6 +213,9 @@ self.move_in_pack(path)
return f, commit
+ def add_object(self, obj):
+ self._add_shafile(obj.id, obj)
+
def add_objects(self, objects):
"""Add a set of objects to this object store.
|
@@ -92,6 +92,9 @@ text = text[1:]
object._text = text
return object
+
+ def as_legacy_object(self):
+ return zlib.compress("%s %d\0%s" % (self._type, len(self._text), self._text))
def as_raw_string(self):
return self._num_type, self._text
@@ -106,8 +109,8 @@ try:
object = num_type_map[num_type]()
except KeyError:
- assert False, "Not a known type: %d" % num_type
- while((byte & 0x80) != 0):
+ raise AssertionError("Not a known type: %d" % num_type)
+ while (byte & 0x80) != 0:
byte = ord(map[used])
used += 1
raw = map[used:]
|
Loading...