From 1e4085a05d7a486920afcd995bb0c1737d54c670 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:02 +0000 Subject: 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 Signed-off-by: Junio C Hamano --- tag.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tag.c') diff --git a/tag.c b/tag.c index 243d1fdbbc..625f5cd71e 100644 --- a/tag.c +++ b/tag.c @@ -116,7 +116,7 @@ static unsigned long parse_tag_date(const char *buf, const char *tail) int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) { - unsigned char sha1[20]; + struct object_id oid; char type[20]; const char *bufptr = data; const char *tail = bufptr + size; @@ -126,11 +126,10 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) return 0; item->object.parsed = 1; - if (size < 64) + if (size < GIT_SHA1_HEXSZ + 24) return -1; - if (memcmp("object ", bufptr, 7) || get_sha1_hex(bufptr + 7, sha1) || bufptr[47] != '\n') + if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\n') return -1; - bufptr += 48; /* "object " + sha1 + "\n" */ if (!starts_with(bufptr, "type ")) return -1; @@ -143,13 +142,13 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) bufptr = nl + 1; if (!strcmp(type, blob_type)) { - item->tagged = &lookup_blob(sha1)->object; + item->tagged = &lookup_blob(oid.hash)->object; } else if (!strcmp(type, tree_type)) { - item->tagged = &lookup_tree(sha1)->object; + item->tagged = &lookup_tree(oid.hash)->object; } else if (!strcmp(type, commit_type)) { - item->tagged = &lookup_commit(sha1)->object; + item->tagged = &lookup_commit(oid.hash)->object; } else if (!strcmp(type, tag_type)) { - item->tagged = &lookup_tag(sha1)->object; + item->tagged = &lookup_tag(oid.hash)->object; } else { error("Unknown type %s", type); item->tagged = NULL; -- cgit v1.2.3 From bc83266abe36905cade4719cbaeb8a62d0a382da Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:10 +0000 Subject: Convert lookup_commit* to struct object_id Convert lookup_commit, lookup_commit_or_die, lookup_commit_reference, and lookup_commit_reference_gently to take struct object_id arguments. Introduce a temporary in parse_object buffer in order to convert this function. This is required since in order to convert parse_object and parse_object_buffer, lookup_commit_reference_gently and lookup_commit_or_die would need to be converted. Not introducing a temporary would therefore require that lookup_commit_or_die take a struct object_id *, but lookup_commit would take unsigned char *, leaving a confusing and hard-to-use interface. parse_object_buffer will lose this temporary in a later patch. This commit was created with manual changes to commit.c, commit.h, and object.c, plus the following semantic patch: @@ expression E1, E2; @@ - lookup_commit_reference_gently(E1.hash, E2) + lookup_commit_reference_gently(&E1, E2) @@ expression E1, E2; @@ - lookup_commit_reference_gently(E1->hash, E2) + lookup_commit_reference_gently(E1, E2) @@ expression E1; @@ - lookup_commit_reference(E1.hash) + lookup_commit_reference(&E1) @@ expression E1; @@ - lookup_commit_reference(E1->hash) + lookup_commit_reference(E1) @@ expression E1; @@ - lookup_commit(E1.hash) + lookup_commit(&E1) @@ expression E1; @@ - lookup_commit(E1->hash) + lookup_commit(E1) @@ expression E1, E2; @@ - lookup_commit_or_die(E1.hash, E2) + lookup_commit_or_die(&E1, E2) @@ expression E1, E2; @@ - lookup_commit_or_die(E1->hash, E2) + lookup_commit_or_die(E1, E2) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tag.c') diff --git a/tag.c b/tag.c index 625f5cd71e..79b78d3583 100644 --- a/tag.c +++ b/tag.c @@ -146,7 +146,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) } else if (!strcmp(type, tree_type)) { item->tagged = &lookup_tree(oid.hash)->object; } else if (!strcmp(type, commit_type)) { - item->tagged = &lookup_commit(oid.hash)->object; + item->tagged = &lookup_commit(&oid)->object; } else if (!strcmp(type, tag_type)) { item->tagged = &lookup_tag(oid.hash)->object; } else { -- cgit v1.2.3 From 3aca1fc6c9c69fbfce0e6312fc8e3087cb6334a4 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:14 +0000 Subject: Convert lookup_blob to struct object_id Convert lookup_blob to take a pointer to struct object_id. The commit was created with manual changes to blob.c and blob.h, plus the following semantic patch: @@ expression E1; @@ - lookup_blob(E1.hash) + lookup_blob(&E1) @@ expression E1; @@ - lookup_blob(E1->hash) + lookup_blob(E1) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tag.c') diff --git a/tag.c b/tag.c index 79b78d3583..dff251673e 100644 --- a/tag.c +++ b/tag.c @@ -142,7 +142,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) bufptr = nl + 1; if (!strcmp(type, blob_type)) { - item->tagged = &lookup_blob(oid.hash)->object; + item->tagged = &lookup_blob(&oid)->object; } else if (!strcmp(type, tree_type)) { item->tagged = &lookup_tree(oid.hash)->object; } else if (!strcmp(type, commit_type)) { -- cgit v1.2.3 From 740ee055c6178fc2dd43c5ccfbd367c4c64d6e0d Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:17 +0000 Subject: Convert lookup_tree to struct object_id Convert the lookup_tree function to take a pointer to struct object_id. The commit was created with manual changes to tree.c, tree.h, and object.c, plus the following semantic patch: @@ @@ - lookup_tree(EMPTY_TREE_SHA1_BIN) + lookup_tree(&empty_tree_oid) @@ expression E1; @@ - lookup_tree(E1.hash) + lookup_tree(&E1) @@ expression E1; @@ - lookup_tree(E1->hash) + lookup_tree(E1) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tag.c') diff --git a/tag.c b/tag.c index dff251673e..062516b405 100644 --- a/tag.c +++ b/tag.c @@ -144,7 +144,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) if (!strcmp(type, blob_type)) { item->tagged = &lookup_blob(&oid)->object; } else if (!strcmp(type, tree_type)) { - item->tagged = &lookup_tree(oid.hash)->object; + item->tagged = &lookup_tree(&oid)->object; } else if (!strcmp(type, commit_type)) { item->tagged = &lookup_commit(&oid)->object; } else if (!strcmp(type, tag_type)) { -- cgit v1.2.3 From d3101b533d365825f52d8e5e52328702acbc8e3a Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:19 +0000 Subject: Convert lookup_tag to struct object_id Convert lookup_tag to take a pointer to struct object_id. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- tag.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tag.c') diff --git a/tag.c b/tag.c index 062516b405..571798519f 100644 --- a/tag.c +++ b/tag.c @@ -89,11 +89,11 @@ struct object *deref_tag_noverify(struct object *o) return o; } -struct tag *lookup_tag(const unsigned char *sha1) +struct tag *lookup_tag(const struct object_id *oid) { - struct object *obj = lookup_object(sha1); + struct object *obj = lookup_object(oid->hash); if (!obj) - return create_object(sha1, alloc_tag_node()); + return create_object(oid->hash, alloc_tag_node()); return object_as_type(obj, OBJ_TAG, 0); } @@ -148,7 +148,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) } else if (!strcmp(type, commit_type)) { item->tagged = &lookup_commit(&oid)->object; } else if (!strcmp(type, tag_type)) { - item->tagged = &lookup_tag(oid.hash)->object; + item->tagged = &lookup_tag(&oid)->object; } else { error("Unknown type %s", type); item->tagged = NULL; -- cgit v1.2.3 From c251c83df276dc0bff4d008433268ad59b7a8df2 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:38 +0000 Subject: object: convert parse_object* to take struct object_id Make parse_object, parse_object_or_die, and parse_object_buffer take a pointer to struct object_id. Remove the temporary variables inserted earlier, since they are no longer necessary. Transform all of the callers using the following semantic patch: @@ expression E1; @@ - parse_object(E1.hash) + parse_object(&E1) @@ expression E1; @@ - parse_object(E1->hash) + parse_object(E1) @@ expression E1, E2; @@ - parse_object_or_die(E1.hash, E2) + parse_object_or_die(&E1, E2) @@ expression E1, E2; @@ - parse_object_or_die(E1->hash, E2) + parse_object_or_die(E1, E2) @@ expression E1, E2, E3, E4, E5; @@ - parse_object_buffer(E1.hash, E2, E3, E4, E5) + parse_object_buffer(&E1, E2, E3, E4, E5) @@ expression E1, E2, E3, E4, E5; @@ - parse_object_buffer(E1->hash, E2, E3, E4, E5) + parse_object_buffer(E1, E2, E3, E4, E5) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- tag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tag.c') diff --git a/tag.c b/tag.c index 571798519f..eb7b146f4a 100644 --- a/tag.c +++ b/tag.c @@ -66,7 +66,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen) { while (o && o->type == OBJ_TAG) if (((struct tag *)o)->tagged) - o = parse_object(((struct tag *)o)->tagged->oid.hash); + o = parse_object(&((struct tag *)o)->tagged->oid); else o = NULL; if (!o && warn) { @@ -80,7 +80,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen) struct object *deref_tag_noverify(struct object *o) { while (o && o->type == OBJ_TAG) { - o = parse_object(o->oid.hash); + o = parse_object(&o->oid); if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged) o = ((struct tag *)o)->tagged; else -- cgit v1.2.3