summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-06-27 10:34:06 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-27 22:27:51 (GMT)
commit36e4d74a210ba618e1520f11ce7fc2f8baec5bb8 (patch)
treebbcd071ad589fe301eb7246ede689f8cd9839080 /sha1_file.c
parentc4584ae3fd7cd595a638a07dfd853e9d2745e930 (diff)
downloadgit-36e4d74a210ba618e1520f11ce7fc2f8baec5bb8.zip
git-36e4d74a210ba618e1520f11ce7fc2f8baec5bb8.tar.gz
git-36e4d74a210ba618e1520f11ce7fc2f8baec5bb8.tar.bz2
[PATCH] Enhance sha1_file_size() into sha1_object_info()
This lets us eliminate one use of map_sha1_file() outside sha1_file.c, to bring us one step closer to the packed GIT. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/sha1_file.c b/sha1_file.c
index a12da4e..4225c67 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -409,20 +409,22 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned l
return unpack_sha1_rest(&stream, hdr, *size);
}
-int sha1_file_size(const unsigned char *sha1, unsigned long *sizep)
+int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)
{
- int ret, status;
+ int status;
unsigned long mapsize, size;
void *map;
z_stream stream;
- char hdr[64], type[20];
+ char hdr[128];
map = map_sha1_file(sha1, &mapsize);
if (!map)
- return -1;
- ret = unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr));
- if (ret < Z_OK || parse_sha1_header(hdr, type, &size) < 0)
- status = -1;
+ return error("unable to map %s", sha1_to_hex(sha1));
+ if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
+ status = error("unable to unpack %s header",
+ sha1_to_hex(sha1));
+ if (parse_sha1_header(hdr, type, &size) < 0)
+ status = error("unable to parse %s header", sha1_to_hex(sha1));
else {
status = 0;
*sizep = size;