return !oideq(oid, &real_oid) ? -1 : 0;
}
-int stream_object_signature(struct repository *r, const struct object_id *oid)
+int stream_object_signature(struct repository *r,
+ struct odb_read_stream *st,
+ const struct object_id *oid)
{
struct object_id real_oid;
- struct odb_read_stream *st;
struct git_hash_ctx c;
char hdr[MAX_HEADER_LEN];
int hdrlen;
- st = odb_read_stream_open(r->objects, oid, NULL);
- if (!st)
- return -1;
-
/* Generate the header */
hdrlen = format_object_header(hdr, sizeof(hdr), st->type, st->size);
git_hash_update(&c, buf, readlen);
}
git_hash_final_oid(&real_oid, &c);
- odb_read_stream_close(st);
return !oideq(oid, &real_oid) ? -1 : 0;
}
* Try reading the object named with "oid" using
* the streaming interface and rehash it to do the same.
*/
-int stream_object_signature(struct repository *r, const struct object_id *oid);
+int stream_object_signature(struct repository *r,
+ struct odb_read_stream *stream,
+ const struct object_id *oid);
enum finalize_object_file_flags {
FOF_SKIP_COLLISION_CHECK = 1,
#include "object.h"
#include "replace-object.h"
#include "object-file.h"
+#include "odb/streaming.h"
#include "blob.h"
#include "statinfo.h"
#include "tree.h"
if ((!obj || obj->type == OBJ_NONE || obj->type == OBJ_BLOB) &&
odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
- if (!skip_hash && stream_object_signature(r, repl) < 0) {
- error(_("hash mismatch %s"), oid_to_hex(oid));
- return NULL;
+ if (!skip_hash) {
+ struct odb_read_stream *stream = odb_read_stream_open(r->objects, oid, NULL);
+
+ if (!stream) {
+ error(_("unable to open object stream for %s"), oid_to_hex(oid));
+ return NULL;
+ }
+
+ if (stream_object_signature(r, stream, repl) < 0) {
+ error(_("hash mismatch %s"), oid_to_hex(oid));
+ odb_read_stream_close(stream);
+ return NULL;
+ }
+
+ odb_read_stream_close(stream);
}
parse_blob_buffer(lookup_blob(r, oid));
return lookup_object(r, oid);
#include "packfile.h"
#include "object-file.h"
#include "odb.h"
+#include "odb/streaming.h"
struct idx_entry {
off_t offset;
QSORT(entries, nr_objects, compare_entries);
for (i = 0; i < nr_objects; i++) {
+ struct odb_read_stream *stream = NULL;
void *data;
struct object_id oid;
enum object_type type;
type) < 0)
err = error("packed %s from %s is corrupt",
oid_to_hex(&oid), p->pack_name);
- else if (!data && stream_object_signature(r, &oid) < 0)
+ else if (!data &&
+ (!(stream = odb_read_stream_open(r->objects, &oid, NULL)) ||
+ stream_object_signature(r, stream, &oid) < 0))
err = error("packed %s from %s is corrupt",
oid_to_hex(&oid), p->pack_name);
else if (fn) {
}
if (((base_count + i) & 1023) == 0)
display_progress(progress, base_count + i);
- free(data);
+ if (stream)
+ odb_read_stream_close(stream);
+ free(data);
}
+
display_progress(progress, base_count + i);
free(entries);
-
return err;
}