Skip to content

Commit 1e4085a

Browse files
bk2204gitster
authored andcommitted
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>
1 parent eee886c commit 1e4085a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tag.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static unsigned long parse_tag_date(const char *buf, const char *tail)
116116

117117
int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
118118
{
119-
unsigned char sha1[20];
119+
struct object_id oid;
120120
char type[20];
121121
const char *bufptr = data;
122122
const char *tail = bufptr + size;
@@ -126,11 +126,10 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
126126
return 0;
127127
item->object.parsed = 1;
128128

129-
if (size < 64)
129+
if (size < GIT_SHA1_HEXSZ + 24)
130130
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')
132132
return -1;
133-
bufptr += 48; /* "object " + sha1 + "\n" */
134133

135134
if (!starts_with(bufptr, "type "))
136135
return -1;
@@ -143,13 +142,13 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
143142
bufptr = nl + 1;
144143

145144
if (!strcmp(type, blob_type)) {
146-
item->tagged = &lookup_blob(sha1)->object;
145+
item->tagged = &lookup_blob(oid.hash)->object;
147146
} else if (!strcmp(type, tree_type)) {
148-
item->tagged = &lookup_tree(sha1)->object;
147+
item->tagged = &lookup_tree(oid.hash)->object;
149148
} else if (!strcmp(type, commit_type)) {
150-
item->tagged = &lookup_commit(sha1)->object;
149+
item->tagged = &lookup_commit(oid.hash)->object;
151150
} else if (!strcmp(type, tag_type)) {
152-
item->tagged = &lookup_tag(sha1)->object;
151+
item->tagged = &lookup_tag(oid.hash)->object;
153152
} else {
154153
error("Unknown type %s", type);
155154
item->tagged = NULL;

0 commit comments

Comments
 (0)