tag: stop using the_repository
cover tag: stop using the_repository
Push the use of the_repository and the_hash_algo from the tag functions to their callers. Also converts some cases of implicit use, which seem unintended.
tag: use algo of repo parameter in parse_tag_buffer()
tag: support arbitrary repositories in gpg_verify_tag()
tag: support arbitrary repositories in parse_tag()
tag: stop using the_repository
builtin/describe.c | 6 +++--- builtin/pack-objects.c | 2 +- builtin/tag.c | 2 +- builtin/verify-tag.c | 2 +- fsck.c | 2 +- object-name.c | 2 +- ref-filter.c | 2 +- tag.c | 27 ++++++++++++++------------- tag.h | 4 ++-- walker.c | 2 +- 10 files changed, 26 insertions(+), 25 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/4 tag: use algo of repo parameter in parse_tag_buffer()
Stop using "the_hash_algo" explicitly and implictly via parse_oid_hex() and instead use the "hash_algo" member of the passed in repository, which is more correct.
--- tag.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tag.c +4 -2
@@ -148,9 +148,11 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, uFREE_AND_NULL (item->tag); } -if (size < the_hash_algo->hexsz +24 ) +if (size < r->hash_algo->hexsz +24 )return -1 ; -if (memcmp ("object " , bufptr,7 ) ||parse_oid_hex (bufptr +7 , &oid, &bufptr) || *bufptr++ !='\n' ) +if (memcmp ("object " , bufptr,7 ) || +parse_oid_hex_algop (bufptr +7 , &oid, &bufptr, r->hash_algo) || + *bufptr++ !='\n' )return -1 ;if (!starts_with (bufptr,"type " ))
Signature · 1 line
2.52.0
Re: [PATCH 1/4] tag: use algo of repo parameter in parse_tag_buffer()
Quoted 1 line · René Scharfe
Stop using "
the_hash_algo" explicitly and implictly viaparse_oid_hex()
s/implictly/implicitly/
Quoted 5 lines
and instead use the "
hash_algo" member of the passed in repository, which is more correct.Signed-off-by René Scharfe <[email protected]>[snip]
PATCH 2/4 tag: support arbitrary repositories in gpg_verify_tag()
In reply to René ScharfeAllow callers of gpg_verify_tag() specify the repository to use by providing a parameter for that. One of the two has not been using the_repository since 43a8391977 (builtin/verify-tag: stop using the_repository, 2025-03-08); let it pass in the correct repository. The other simply passes the_repository to get the same result as before.
--- builtin/tag.c | 2 +- builtin/verify-tag.c | 2 +- tag.c | 12 ++++++------ tag.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-)
builtin/tag.c +1 -1
@@ -149,7 +149,7 @@ static int verify_tag(const char *name, const char *ref UNUSED,if (format->format) flags =GPG_VERIFY_OMIT_STATUS ; -if (gpg_verify_tag (oid, name, flags)) +if (gpg_verify_tag (the_repository, oid, name, flags))return -1 ;if (format->format)
builtin/verify-tag.c +1 -1
@@ -61,7 +61,7 @@ int cmd_verify_tag(int argc,continue ; } -if (gpg_verify_tag (&oid, name, flags)) { +if (gpg_verify_tag (repo, &oid, name, flags)) { had_error =1 ;continue ; }
tag.c +6 -6
@@ -44,28 +44,28 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return ret; } -int gpg_verify_tag (const struct object_id *oid,const char *name_to_report, -unsigned flags) +int gpg_verify_tag (struct repository *r,const struct object_id *oid, +const char *name_to_report,unsigned flags) {enum object_type type;char *buf;unsigned long size;int ret; - type =odb_read_object_info (the_repository->objects, oid,NULL ); + type =odb_read_object_info (r->objects, oid,NULL );if (type !=OBJ_TAG )return error ("%s: cannot verify a non-tag object of type %s." , name_to_report ? name_to_report : -repo_find_unique_abbrev (the_repository, oid,DEFAULT_ABBREV ), +repo_find_unique_abbrev (r, oid,DEFAULT_ABBREV ),type_name (type)); - buf =odb_read_object (the_repository->objects, oid, &type, &size); + buf =odb_read_object (r->objects, oid, &type, &size);if (!buf)return error ("%s: unable to read file." , name_to_report ? name_to_report : -repo_find_unique_abbrev (the_repository, oid,DEFAULT_ABBREV )); +repo_find_unique_abbrev (r, oid,DEFAULT_ABBREV )); ret =run_gpg_verify (buf, size, flags);
tag.h +1 -1
@@ -16,7 +16,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, uint parse_tag (struct tag *item);void release_tag_memory (struct tag *t);struct object *deref_tag (struct repository *r,struct object *,const char *,int ); -int gpg_verify_tag (const struct object_id *oid, +int gpg_verify_tag (struct repository *r,const struct object_id *oid,const char *name_to_report,unsigned flags);struct object_id *get_tagged_oid (struct tag *tag);
Signature · 1 line
2.52.0
PATCH 3/4 tag: support arbitrary repositories in parse_tag()
In reply to René ScharfeAllow callers of parse_tag() pass in the repository to use. Let most of them pass in the_repository to get the same result as before. One of them has stopped using the_repository in ef9b0370da (sha1-name.c: store and use repo in struct disambiguate_state, 2019-04-16); let it pass in its stored repository.
--- builtin/describe.c | 6 +++--- builtin/pack-objects.c | 2 +- fsck.c | 2 +- object-name.c | 2 +- ref-filter.c | 2 +- tag.c | 8 ++++---- tag.h | 2 +- walker.c | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-)
builtin/describe.c +3 -3
@@ -112,13 +112,13 @@ static int replace_name(struct commit_name *e,if (!e->tag) { t =lookup_tag (the_repository, &e->oid); -if (!t ||parse_tag (t)) +if (!t ||parse_tag (the_repository, t))return 1 ; e->tag = t; } t =lookup_tag (the_repository, oid); -if (!t ||parse_tag (t)) +if (!t ||parse_tag (the_repository, t))return 0 ; *tag = t;
@@ -335,7 +335,7 @@ static void append_name(struct commit_name *n, struct strbuf *dst) {if (n->prio ==2 && !n->tag) { n->tag =lookup_tag (the_repository, &n->oid); -if (!n->tag ||parse_tag (n->tag)) +if (!n->tag ||parse_tag (the_repository, n->tag))die (_ ("annotated tag %s not available" ), n->path); }if (n->tag && !n->name_checked) {
builtin/pack-objects.c +1 -1
@@ -3293,7 +3293,7 @@ static void add_tag_chain(const struct object_id *oid) tag =lookup_tag (the_repository, oid);while (1 ) { -if (!tag ||parse_tag (tag) || !tag->tagged) +if (!tag ||parse_tag (the_repository, tag) || !tag->tagged)die (_ ("unable to pack objects reachable from tag %s" ),oid_to_hex (oid));
fsck.c +1 -1
@@ -474,7 +474,7 @@ static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *optio {const char *name =fsck_get_object_name (options, &tag->object.oid); -if (parse_tag (tag)) +if (parse_tag (the_repository, tag))return -1 ;if (name)fsck_put_object_name (options, &tag->tagged->oid,"%s" , name);
object-name.c +1 -1
@@ -449,7 +449,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data) }else if (type ==OBJ_TAG ) {struct tag *tag =lookup_tag (ds->repo, oid); -if (!parse_tag (tag) && tag->tag) { +if (!parse_tag (ds->repo, tag) && tag->tag) {/* * TRANSLATORS: This is a line of ambiguous * tag object output. E.g.:
ref-filter.c +1 -1
@@ -2866,7 +2866,7 @@ static int match_points_at(struct oid_array *points_at,while (obj && obj->type ==OBJ_TAG ) {struct tag *tag = (struct tag *)obj; -if (parse_tag (tag) <0 ) { +if (parse_tag (the_repository, tag) <0 ) { obj =NULL ;break ; }
tag.c +4 -4
@@ -13,6 +13,7 @@#include "gpg-interface.h" #include "hex.h" #include "packfile.h" +#include "repository.h" const char *tag_type ="tag" ;
@@ -203,7 +204,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, ureturn 0 ; } -int parse_tag (struct tag *item) +int parse_tag (struct repository *r,struct tag *item) {enum object_type type;void *data;
@@ -212,8 +213,7 @@ int parse_tag(struct tag *item)if (item->object.parsed)return 0 ; - data =odb_read_object (the_repository->objects, &item->object.oid, - &type, &size); + data =odb_read_object (r->objects, &item->object.oid, &type, &size);if (!data)return error ("Could not read %s" ,oid_to_hex (&item->object.oid));
@@ -222,7 +222,7 @@ int parse_tag(struct tag *item)return error ("Object %s not a tag" ,oid_to_hex (&item->object.oid)); } - ret =parse_tag_buffer (the_repository, item, data, size); + ret =parse_tag_buffer (r, item, data, size);free (data);return ret; }
tag.h +1 -1
@@ -13,7 +13,7 @@ struct tag { };struct tag *lookup_tag (struct repository *r,const struct object_id *oid);int parse_tag_buffer (struct repository *r,struct tag *item,const void *data,unsigned long size); -int parse_tag (struct tag *item); +int parse_tag (struct repository *r,struct tag *item);void release_tag_memory (struct tag *t);struct object *deref_tag (struct repository *r,struct object *,const char *,int ); int gpg_verify_tag(struct repository *r, const struct object_id *oid,
walker.c +1 -1
@@ -115,7 +115,7 @@ static int process_commit(struct walker *walker, struct commit *commit)static int process_tag (struct walker *walker,struct tag *tag) { -if (parse_tag (tag)) +if (parse_tag (the_repository, tag))return -1 ;return process (walker, tag->tagged); }
Signature · 1 line
2.52.0
PATCH 4/4 tag: stop using the_repository
In reply to René Scharfegpg_verify_tag() shows the passed in object name on error. Both callers provide one. It falls back to abbreviated hashes for future callers that pass in a NULL name. DEFAULT_ABBREV is default_abbrev, which in turn is a global variable that's populated by git_default_config() and only available with USE_THE_REPOSITORY_VARIABLE.
Don't let that hypothetical hold us back from getting rid of the_repository in tag.c. Fall back to full hashes, which are more appropriate for error messages anyway. This allows us to stop setting USE_THE_REPOSITORY_VARIABLE.
--- tag.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tag.c +2 -3
@@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #define DISABLE_SIGN_COMPARE_WARNINGS #include "git-compat-util.h"
@@ -58,7 +57,7 @@ int gpg_verify_tag(struct repository *r, const struct object_id *oid,return error ("%s: cannot verify a non-tag object of type %s." , name_to_report ? name_to_report : -repo_find_unique_abbrev (r, oid,DEFAULT_ABBREV ), +oid_to_hex (oid),type_name (type)); buf =odb_read_object (r->objects, oid, &type, &size);
@@ -66,7 +65,7 @@ int gpg_verify_tag(struct repository *r, const struct object_id *oid,return error ("%s: unable to read file." , name_to_report ? name_to_report : -repo_find_unique_abbrev (r, oid,DEFAULT_ABBREV )); +oid_to_hex (oid)); ret =run_gpg_verify (buf, size, flags);
Signature · 1 line
2.52.0