tag: convert parse_tag_buffer to struct object_id

Specify some constants in terms of GIT_SHA1_HEXSZ, and convert a get_sha1_hex into parse_oid_hex to avoid needing to specify additional constants. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 6, 2017 at 22:10 UTC 1e4085a05d7a486920afcd995bb0c1737d54c670
1 file changed +7 -8
tag.c
+7 -8
@@ -116,7 +116,7 @@ static unsigned long parse_tag_date(const char *buf, const char *tail)
116
117 int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
118 {
119 - unsigned char sha1[20];
119 + struct object_id oid;
120 char type[20];
121 const char *bufptr = data;
122 const char *tail = bufptr + size;
@@ -126,11 +126,10 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
126 return 0;
127 item->object.parsed = 1;
128
129 - if (size < 64)
129 + if (size < GIT_SHA1_HEXSZ + 24)
130 return -1;
131 - if (memcmp("object ", bufptr, 7) || get_sha1_hex(bufptr + 7, sha1) || bufptr[47] != '\n')
131 + if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\n')
132 return -1;
133 - bufptr += 48; /* "object " + sha1 + "\n" */
133
134 if (!starts_with(bufptr, "type "))
135 return -1;
@@ -143,13 +142,13 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
142 bufptr = nl + 1;
143
144 if (!strcmp(type, blob_type)) {
146 - item->tagged = &lookup_blob(sha1)->object;
145 + item->tagged = &lookup_blob(oid.hash)->object;
146 } else if (!strcmp(type, tree_type)) {
148 - item->tagged = &lookup_tree(sha1)->object;
147 + item->tagged = &lookup_tree(oid.hash)->object;
148 } else if (!strcmp(type, commit_type)) {
150 - item->tagged = &lookup_commit(sha1)->object;
149 + item->tagged = &lookup_commit(oid.hash)->object;
150 } else if (!strcmp(type, tag_type)) {
152 - item->tagged = &lookup_tag(sha1)->object;
151 + item->tagged = &lookup_tag(oid.hash)->object;
152 } else {
153 error("Unknown type %s", type);
154 item->tagged = NULL;