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>
brian m. carlson committed
Mar 26, 2017 at 16:01 UTC
365c27fbffd9a1e08ac5f1e423c99ece6c27d22e
1 file changed
+6
-5
fsck.c
+6
-5
@@ -134,8 +134,8 @@ static void init_skiplist(struct fsck_options *options, const char *path)
134
{
135
static struct sha1_array skiplist = SHA1_ARRAY_INIT;
136
int sorted, fd;
137
- char buffer[41];
138
- unsigned char sha1[20];
137
+ char buffer[GIT_MAX_HEXSZ + 1];
138
+ struct object_id oid;
139
140
if (options->skiplist)
141
sorted = options->skiplist->sorted;
@@ -148,17 +148,18 @@ static void init_skiplist(struct fsck_options *options, const char *path)
148
if (fd < 0)
149
die("Could not open skip list: %s", path);
150
for (;;) {
151
+ const char *p;
152
int result = read_in_full(fd, buffer, sizeof(buffer));
153
if (result < 0)
154
die_errno("Could not read '%s'", path);
155
if (!result)
156
break;
156
- if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
157
+ if (parse_oid_hex(buffer, &oid, &p) || *p != '\n')
158
die("Invalid SHA-1: %s", buffer);
158
- sha1_array_append(&skiplist, sha1);
159
+ sha1_array_append(&skiplist, oid.hash);
160
if (sorted && skiplist.nr > 1 &&
161
hashcmp(skiplist.sha1[skiplist.nr - 2],
161
- sha1) > 0)
162
+ oid.hash) > 0)
163
sorted = 0;
164
}
165
close(fd);