dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00147
[PATCH 6/9] pack: Factor out write_pack_header.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: Id3c5e492b5c2db547e6e13bf91ba2d352fc17150
---
NEWS | 2 ++
dulwich/pack.py | 20 ++++++++++++++------
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/NEWS b/NEWS
index ae97990..379d3bd 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,8 @@
* ObjectStore.iter_tree_contents can optionally yield tree objects as well.
(Dave Borowitz).
+ * New public function dulwich.pack.write_pack_header. (Dave Borowitz)
+
0.6.1 2010-07-22
diff --git a/dulwich/pack.py b/dulwich/pack.py
index 5bba811..59f27c9 100644
--- a/dulwich/pack.py
+++ b/dulwich/pack.py
@@ -1061,11 +1061,21 @@ def write_pack(filename, objects, num_objects):
f.close()
+def write_pack_header(f, num_objects):
+ """Write a pack header for the given number of objects."""
+ f.write('PACK') # Pack header
+ f.write(struct.pack('>L', 2)) # Pack version
+ f.write(struct.pack('>L', num_objects)) # Number of objects in pack
+
+
def write_pack_data(f, objects, num_objects, window=10):
- """Write a new pack file.
+ """Write a new pack data file.
- :param filename: The filename of the new pack file.
- :param objects: List of objects to write (tuples with object and path)
+ :param f: File to write to
+ :param objects: Iterable over (object, path) tuples to write
+ :param num_objects: Number of objects to write
+ :param window: Sliding window size for searching for deltas; currently
+ unimplemented
:return: List with (name, offset, crc32 checksum) entries, pack checksum
"""
recency = list(objects)
@@ -1085,9 +1095,7 @@ def write_pack_data(f, objects, num_objects, window=10):
# Write the pack
entries = []
f = SHA1Writer(f)
- f.write("PACK") # Pack header
- f.write(struct.pack(">L", 2)) # Pack version
- f.write(struct.pack(">L", num_objects)) # Number of objects in pack
+ write_pack_header(f, num_objects)
for o, path in recency:
sha1 = o.sha().digest()
orig_t = o.type_num
--
1.7.1
References