[PATCH 4/5] support reading uncompressed loose object
From: Liu Yubao <hidden>
Date: 2016-06-15 22:45:43
Subsystem:
the rest · Maintainer:
Linus Torvalds
Signed-off-by: Liu Yubao <redacted> --- sha1_file.c | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 79062f0..05a9fa3 100644
--- a/sha1_file.c
+++ b/sha1_file.c@@ -1985,6 +1985,16 @@ static int sha1_loose_object_info(const unsigned char *sha1, unsigned long *size map = map_sha1_file(sha1, &mapsize); if (!map) return error("unable to find %s", sha1_to_hex(sha1)); + + /* + * Is it an uncompressed loose objects? + */ + if ((status = parse_sha1_header(map, mapsize, &size)) >= 0) { + if (sizep) + *sizep = size; + goto L_leave; + } + if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) status = error("unable to unpack %s header", sha1_to_hex(sha1));
@@ -1993,6 +2003,8 @@ static int sha1_loose_object_info(const unsigned char *sha1, unsigned long *size else if (sizep) *sizep = size; inflateEnd(&stream); + +L_leave: munmap(map, mapsize); return status; }
@@ -2124,7 +2136,13 @@ void *read_object(const unsigned char *sha1, enum object_type *type, return buf; map = map_sha1_file(sha1, &mapsize); if (map) { - buf = unpack_sha1_file(map, mapsize, type, size, sha1); + /* + * Is it an uncompressed loose object? + */ + if ((*type = parse_sha1_header(map, mapsize, size)) >= 0) + buf = xmemdupz(map + strlen(map) + 1, *size); + else + buf = unpack_sha1_file(map, mapsize, type, size, sha1); munmap(map, mapsize); return buf; }
--
1.6.1.rc1.5.gde86c