fsck: use streaming API for writing lost-found blobs

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2012-03-07 17:54:20 +07:00 committed by Junio C Hamano
parent 74775a09b1
commit 6f7f3beb2d

View file

@ -12,6 +12,7 @@
#include "parse-options.h" #include "parse-options.h"
#include "dir.h" #include "dir.h"
#include "progress.h" #include "progress.h"
#include "streaming.h"
#define REACHABLE 0x0001 #define REACHABLE 0x0001
#define SEEN 0x0002 #define SEEN 0x0002
@ -238,13 +239,8 @@ static void check_unreachable_object(struct object *obj)
if (!(f = fopen(filename, "w"))) if (!(f = fopen(filename, "w")))
die_errno("Could not open '%s'", filename); die_errno("Could not open '%s'", filename);
if (obj->type == OBJ_BLOB) { if (obj->type == OBJ_BLOB) {
enum object_type type; if (stream_blob_to_fd(fileno(f), obj->sha1, NULL, 1))
unsigned long size;
char *buf = read_sha1_file(obj->sha1,
&type, &size);
if (buf && fwrite(buf, 1, size, f) != size)
die_errno("Could not write '%s'", filename); die_errno("Could not write '%s'", filename);
free(buf);
} else } else
fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
if (fclose(f)) if (fclose(f))