Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 packv4-parse.c | 12 ++++++++++++
 packv4-parse.h |  5 +++++
 sha1_file.c    |  9 ++-------
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/packv4-parse.c b/packv4-parse.c
index 80ad6fc..7a43635 100644
--- a/packv4-parse.c
+++ b/packv4-parse.c
@@ -570,3 +570,15 @@ void *pv4_get_tree(struct packed_git *p, struct 
pack_window **w_curs,
        }
        return dst;
 }
+
+unsigned long pv4_unpack_object_header_buffer(const unsigned char *base,
+                                             unsigned long len,
+                                             enum object_type *type,
+                                             unsigned long *sizep)
+{
+       const unsigned char *cp = base;
+       uintmax_t val = decode_varint(&cp);
+       *type = val & 0xf;
+       *sizep = val >> 4;
+       return cp - base;
+}
diff --git a/packv4-parse.h b/packv4-parse.h
index e6719f6..52f52f5 100644
--- a/packv4-parse.h
+++ b/packv4-parse.h
@@ -10,6 +10,11 @@ struct packv4_dict {
 struct packv4_dict *pv4_create_dict(const unsigned char *data, int dict_size);
 void pv4_free_dict(struct packv4_dict *dict);
 
+unsigned long pv4_unpack_object_header_buffer(const unsigned char *base,
+                                             unsigned long len,
+                                             enum object_type *type,
+                                             unsigned long *sizep);
+
 void *pv4_get_commit(struct packed_git *p, struct pack_window **w_curs,
                     off_t offset, unsigned long size);
 void *pv4_get_tree(struct packed_git *p, struct pack_window **w_curs,
diff --git a/sha1_file.c b/sha1_file.c
index 1528e28..038e22e 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1736,13 +1736,8 @@ int unpack_object_header(struct packed_git *p,
        base = use_pack(p, w_curs, *curpos, &left);
        if (p->version < 4) {
                used = unpack_object_header_buffer(base, left, &type, sizep);
-       } else {
-               const unsigned char *cp = base;
-               uintmax_t val = decode_varint(&cp);
-               used = cp - base;
-               type = val & 0xf;
-               *sizep = val >> 4;
-       }
+       } else
+               used = pv4_unpack_object_header_buffer(base, left, &type, 
sizep);
        if (!used) {
                type = OBJ_BAD;
        } else
-- 
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