sha1-file: modernize loose header/stream functions
[gitweb.git] / streaming.c
index d1e6b2dce6877cb1407ac9d38e65d8b2bae25daa..998e6285d7f0def874c53eb1ca0a745e618bd824 100644 (file)
@@ -338,16 +338,16 @@ static struct stream_vtbl loose_vtbl = {
 
 static open_method_decl(loose)
 {
-       st->u.loose.mapped = map_sha1_file(the_repository,
-                                          oid->hash, &st->u.loose.mapsize);
+       st->u.loose.mapped = map_loose_object(the_repository,
+                                             oid, &st->u.loose.mapsize);
        if (!st->u.loose.mapped)
                return -1;
-       if ((unpack_sha1_header(&st->z,
-                               st->u.loose.mapped,
-                               st->u.loose.mapsize,
-                               st->u.loose.hdr,
-                               sizeof(st->u.loose.hdr)) < 0) ||
-           (parse_sha1_header(st->u.loose.hdr, &st->size) < 0)) {
+       if ((unpack_loose_header(&st->z,
+                                st->u.loose.mapped,
+                                st->u.loose.mapsize,
+                                st->u.loose.hdr,
+                                sizeof(st->u.loose.hdr)) < 0) ||
+           (parse_loose_header(st->u.loose.hdr, &st->size) < 0)) {
                git_inflate_end(&st->z);
                munmap(st->u.loose.mapped, st->u.loose.mapsize);
                return -1;
@@ -408,6 +408,15 @@ static read_method_decl(pack_non_delta)
                        st->z_state = z_done;
                        break;
                }
+
+               /*
+                * Unlike the loose object case, we do not have to worry here
+                * about running out of input bytes and spinning infinitely. If
+                * we get Z_BUF_ERROR due to too few input bytes, then we'll
+                * replenish them in the next use_pack() call when we loop. If
+                * we truly hit the end of the pack (i.e., because it's corrupt
+                * or truncated), then use_pack() catches that and will die().
+                */
                if (status != Z_OK && status != Z_BUF_ERROR) {
                        git_inflate_end(&st->z);
                        st->z_state = z_error;