git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 08/21] pack-objects: respect compression level in v4

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 11, 2013, 06:06 UTC
Message-ID
<1378879582-15372-9-git-send-email-pclouds@gmail.com>
In-Reply-To
<1378879582-15372-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/pack-objects.c |  5 +++--
 packv4-create.c        | 17 ++++++++++-------
 packv4-create.h        |  6 ++++--
 test-packv4.c          |  9 +++++----
 4 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 39d1e08..63c9b9e 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -295,7 +295,8 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
 		datalen = size;
 	else if (pack_version == 4 && entry->type == OBJ_COMMIT) {
 		datalen = size;
-		result = pv4_encode_commit(&v4, buf, &datalen);
+		result = pv4_encode_commit(&v4, buf, &datalen,
+					   pack_compression_level);
 		if (result) {
 			free(buf);
 			buf = result;
@@ -857,7 +858,7 @@ static void write_pack_file(void)
 		if (!offset)
 			die_errno("unable to write pack header");
 		if (pack_version == 4)
-			offset += packv4_write_tables(f, &v4);
+			offset += packv4_write_tables(f, &v4, pack_compression_level);
 		nr_written = 0;
 		for (; i < nr_objects; i++) {
 			struct object_entry *e = write_order[i];
diff --git a/packv4-create.c b/packv4-create.c
index 83a6336..3acd10f 100644
--- a/packv4-create.c
+++ b/packv4-create.c
@@ -18,8 +18,6 @@
 #include "packv4-create.h"
 
 
-int pack_compression_seen;
-int pack_compression_level = Z_DEFAULT_COMPRESSION;
 int min_tree_copy = 1;
 
 struct data_entry {
@@ -285,7 +283,8 @@ int encode_sha1ref(const struct packv4_tables *v4,
  * regenerated and produce the same hash.
  */
 void *pv4_encode_commit(const struct packv4_tables *v4,
-			void *buffer, unsigned long *sizep)
+			void *buffer, unsigned long *sizep,
+			int pack_compression_level)
 {
 	unsigned long size = *sizep;
 	char *in, *tail, *end;
@@ -611,7 +610,8 @@ void *pv4_encode_tree(const struct packv4_tables *v4,
 	return buffer;
 }
 
-static unsigned long write_dict_table(struct sha1file *f, struct dict_table *t)
+static unsigned long write_dict_table(struct sha1file *f, struct dict_table *t,
+				      int pack_compression_level)
 {
 	unsigned char buffer[1024];
 	unsigned hdrlen;
@@ -661,7 +661,8 @@ static unsigned long write_dict_table(struct sha1file *f, struct dict_table *t)
 }
 
 unsigned long packv4_write_tables(struct sha1file *f,
-				  const struct packv4_tables *v4)
+				  const struct packv4_tables *v4,
+				  int pack_compression_level)
 {
 	unsigned nr_objects = v4->all_objs_nr;
 	struct pack_idx_entry *objs = v4->all_objs;
@@ -676,10 +677,12 @@ unsigned long packv4_write_tables(struct sha1file *f,
 	written = 20 * nr_objects;
 
 	/* Then the commit dictionary table */
-	written += write_dict_table(f, commit_ident_table);
+	written += write_dict_table(f, commit_ident_table,
+				    pack_compression_level);
 
 	/* Followed by the path component dictionary table */
-	written += write_dict_table(f, tree_path_table);
+	written += write_dict_table(f, tree_path_table,
+				    pack_compression_level);
 
 	return written;
 }
diff --git a/packv4-create.h b/packv4-create.h
index ba4929a..4ac4d71 100644
--- a/packv4-create.h
+++ b/packv4-create.h
@@ -25,9 +25,11 @@ void sort_dict_entries_by_hits(struct dict_table *t);
 int encode_sha1ref(const struct packv4_tables *v4,
 		   const unsigned char *sha1, unsigned char *buf);
 unsigned long packv4_write_tables(struct sha1file *f,
-				  const struct packv4_tables *v4);
+				  const struct packv4_tables *v4,
+				  int pack_compression_level);
 void *pv4_encode_commit(const struct packv4_tables *v4,
-			void *buffer, unsigned long *sizep);
+			void *buffer, unsigned long *sizep,
+			int pack_compression_level);
 void *pv4_encode_tree(const struct packv4_tables *v4,
 		      void *_buffer, unsigned long *sizep,
 		      void *delta, unsigned long delta_size,
diff --git a/test-packv4.c b/test-packv4.c
index 3b0d7a2..b50422a 100644
--- a/test-packv4.c
+++ b/test-packv4.c
@@ -5,8 +5,8 @@
 #include "varint.h"
 #include "packv4-create.h"
 
-extern int pack_compression_seen;
-extern int pack_compression_level;
+static int pack_compression_seen;
+static int pack_compression_level = Z_DEFAULT_COMPRESSION;
 extern int min_tree_copy;
 
 static struct pack_idx_entry *get_packed_object_list(struct packed_git *p)
@@ -291,7 +291,8 @@ static off_t packv4_write_object(struct packv4_tables *v4,
 
 	switch (type) {
 	case OBJ_COMMIT:
-		result = pv4_encode_commit(v4, src, &buf_size);
+		result = pv4_encode_commit(v4, src, &buf_size,
+					   pack_compression_level);
 		break;
 	case OBJ_TREE:
 		if (packed_type != OBJ_TREE) {
@@ -407,7 +408,7 @@ void process_one_pack(struct packv4_tables *v4, char *src_pack, char *dst_pack)
 	if (!f)
 		die("unable to open destination pack");
 	written += packv4_write_header(f, nr_objects);
-	written += packv4_write_tables(f, v4);
+	written += packv4_write_tables(f, v4, pack_compression_level);
 
 	/* Let's write objects out, updating the object index list in place */
 	progress_state = start_progress("Writing objects", nr_objects);
-- 
1.8.2.82.gc24b958
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 15 of 36 in “[PULL REQUEST] initial pack v4 support”
  1. Nicolas PitreSep 9, 2013
  2. Junio C HamanoSep 9, 2013
  3. Junio C HamanoSep 10, 2013
  4. Nicolas PitreSep 10, 2013
  5. Junio C HamanoSep 10, 2013
  6. Nicolas PitreSep 10, 2013
  7. 00/21 np/pack-v4 updatesNguyễn Thái Ngọc Duy, Sep 11, 2013
  8. 01/21 fixup! pack-objects: prepare SHA-1 table in v4Nguyễn Thái Ngọc Duy, Sep 11, 2013
  9. 02/21 fixup! pack-objects: support writing pack v4Nguyễn Thái Ngọc Duy, Sep 11, 2013
  10. 03/21 fixup! pack v4: support "end-of-pack" indicator in index-pack and pack-objectsNguyễn Thái Ngọc Duy, Sep 11, 2013
  11. 04/21 fixup! index-pack: parse v4 header and dictionariesNguyễn Thái Ngọc Duy, Sep 11, 2013
  12. 05/21 fixup! index-pack: record all delta bases in v4 (tree and ref-delta)Nguyễn Thái Ngọc Duy, Sep 11, 2013
  13. 06/21 pack v4: lift dict size check in load_dict()Nguyễn Thái Ngọc Duy, Sep 11, 2013
  14. 07/21 pack v4: move pv4 objhdr parsing code to packv4-parse.cNguyễn Thái Ngọc Duy, Sep 11, 2013
  15. 08/21 pack-objects: respect compression level in v4Nguyễn Thái Ngọc Duy, Sep 11, 2013
  16. 09/21 pack-objects: recognize v4 as pack sourceNguyễn Thái Ngọc Duy, Sep 11, 2013
  17. 10/21 pack v4: add a note that streaming does not support OBJ_PV4_*Nguyễn Thái Ngọc Duy, Sep 11, 2013
  18. 11/21 unpack-objects: report missing object nameNguyễn Thái Ngọc Duy, Sep 11, 2013
  19. 12/21 unpack-objects: recognize end-of-pack in v4 thin packNguyễn Thái Ngọc Duy, Sep 11, 2013
  20. 13/21 unpack-objects: read v4 dictionariesNguyễn Thái Ngọc Duy, Sep 11, 2013
  21. 14/21 unpack-objects: decode v4 object headerNguyễn Thái Ngọc Duy, Sep 11, 2013
  22. 15/21 unpack-objects: decode v4 ref-deltaNguyễn Thái Ngọc Duy, Sep 11, 2013
  23. 16/21 unpack-objects: decode v4 commitsNguyễn Thái Ngọc Duy, Sep 11, 2013
  24. 17/21 unpack-objects: allow to save processed bytes to a bufferNguyễn Thái Ngọc Duy, Sep 11, 2013
  25. 18/21 unpack-objects: decode v4 treesNguyễn Thái Ngọc Duy, Sep 11, 2013
  26. 19/21 index-pack, pack-objects: allow creating .idx v2 with .pack v4Nguyễn Thái Ngọc Duy, Sep 11, 2013
  27. Nicolas PitreSep 11, 2013
  28. 20/21 show-index: acknowledge that it does not read .idx v3Nguyễn Thái Ngọc Duy, Sep 11, 2013
  29. Nicolas PitreSep 11, 2013
  30. 21/21 t1050, t5500: replace the use of "show-index|wc -l" with verify-packNguyễn Thái Ngọc Duy, Sep 11, 2013
  31. Duy NguyenSep 11, 2013
  32. Nicolas PitreSep 11, 2013
  33. Duy NguyenSep 12, 2013
  34. Nicolas PitreSep 12, 2013
  35. Duy NguyenSep 13, 2013
  36. Nicolas PitreSep 11, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.