fsck: convert init_skiplist to struct object_id
Convert a hardcoded constant buffer size to a use of GIT_MAX_HEXSZ, and use parse_oid_hex to reduce the dependency on the size of the hash. This function is a caller of sha1_array_append, which will be converted later. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9c44ea4403
commit
365c27fbff
11
fsck.c
11
fsck.c
@ -134,8 +134,8 @@ static void init_skiplist(struct fsck_options *options, const char *path)
|
|||||||
{
|
{
|
||||||
static struct sha1_array skiplist = SHA1_ARRAY_INIT;
|
static struct sha1_array skiplist = SHA1_ARRAY_INIT;
|
||||||
int sorted, fd;
|
int sorted, fd;
|
||||||
char buffer[41];
|
char buffer[GIT_MAX_HEXSZ + 1];
|
||||||
unsigned char sha1[20];
|
struct object_id oid;
|
||||||
|
|
||||||
if (options->skiplist)
|
if (options->skiplist)
|
||||||
sorted = options->skiplist->sorted;
|
sorted = options->skiplist->sorted;
|
||||||
@ -148,17 +148,18 @@ static void init_skiplist(struct fsck_options *options, const char *path)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
die("Could not open skip list: %s", path);
|
die("Could not open skip list: %s", path);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
const char *p;
|
||||||
int result = read_in_full(fd, buffer, sizeof(buffer));
|
int result = read_in_full(fd, buffer, sizeof(buffer));
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
die_errno("Could not read '%s'", path);
|
die_errno("Could not read '%s'", path);
|
||||||
if (!result)
|
if (!result)
|
||||||
break;
|
break;
|
||||||
if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
|
if (parse_oid_hex(buffer, &oid, &p) || *p != '\n')
|
||||||
die("Invalid SHA-1: %s", buffer);
|
die("Invalid SHA-1: %s", buffer);
|
||||||
sha1_array_append(&skiplist, sha1);
|
sha1_array_append(&skiplist, oid.hash);
|
||||||
if (sorted && skiplist.nr > 1 &&
|
if (sorted && skiplist.nr > 1 &&
|
||||||
hashcmp(skiplist.sha1[skiplist.nr - 2],
|
hashcmp(skiplist.sha1[skiplist.nr - 2],
|
||||||
sha1) > 0)
|
oid.hash) > 0)
|
||||||
sorted = 0;
|
sorted = 0;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user