Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to