use repo_get_oid_with_flags()

get_oid_with_context() allows specifying flags and reports object
details via a passed-in struct object_context.  Some callers just want
to specify flags, but don't need any details back.  Convert them to
repo_get_oid_with_flags(), which provides just that and frees them from
dealing with the context structure.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
main
René Scharfe 2025-09-10 19:16:30 +02:00 committed by Junio C Hamano
parent c44beea485
commit a66fc22bf9
5 changed files with 17 additions and 50 deletions

View File

@ -373,7 +373,6 @@ int cmd_ls_tree(int argc,
OPT_END() OPT_END()
}; };
struct ls_tree_cmdmode_to_fmt *m2f = ls_tree_cmdmode_format; struct ls_tree_cmdmode_to_fmt *m2f = ls_tree_cmdmode_format;
struct object_context obj_context = {0};
int ret; int ret;


repo_config(the_repository, git_default_config, NULL); repo_config(the_repository, git_default_config, NULL);
@ -405,9 +404,8 @@ int cmd_ls_tree(int argc,
ls_tree_usage, ls_tree_options); ls_tree_usage, ls_tree_options);
if (argc < 1) if (argc < 1)
usage_with_options(ls_tree_usage, ls_tree_options); usage_with_options(ls_tree_usage, ls_tree_options);
if (get_oid_with_context(the_repository, argv[0], if (repo_get_oid_with_flags(the_repository, argv[0], &oid,
GET_OID_HASH_ANY, &oid, GET_OID_HASH_ANY))
&obj_context))
die("Not a valid object name %s", argv[0]); die("Not a valid object name %s", argv[0]);


/* /*
@ -447,6 +445,5 @@ int cmd_ls_tree(int argc,


ret = !!read_tree(the_repository, tree, &options.pathspec, fn, &options); ret = !!read_tree(the_repository, tree, &options.pathspec, fn, &options);
clear_pathspec(&options.pathspec); clear_pathspec(&options.pathspec);
object_context_release(&obj_context);
return ret; return ret;
} }

View File

@ -708,7 +708,6 @@ int cmd_rev_parse(int argc,
struct object_id oid; struct object_id oid;
unsigned int flags = 0; unsigned int flags = 0;
const char *name = NULL; const char *name = NULL;
struct object_context unused;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
int seen_end_of_options = 0; int seen_end_of_options = 0;
enum format_type format = FORMAT_DEFAULT; enum format_type format = FORMAT_DEFAULT;
@ -1141,9 +1140,8 @@ int cmd_rev_parse(int argc,
name++; name++;
type = REVERSED; type = REVERSED;
} }
if (!get_oid_with_context(the_repository, name, if (!repo_get_oid_with_flags(the_repository, name, &oid,
flags, &oid, &unused)) { flags)) {
object_context_release(&unused);
if (output_algo) if (output_algo)
repo_oid_to_algop(the_repository, &oid, repo_oid_to_algop(the_repository, &oid,
output_algo, &oid); output_algo, &oid);
@ -1153,7 +1151,6 @@ int cmd_rev_parse(int argc,
show_rev(type, &oid, name); show_rev(type, &oid, name);
continue; continue;
} }
object_context_release(&unused);
if (verify) if (verify)
die_no_single_rev(quiet); die_no_single_rev(quiet);
if (has_dashdash) if (has_dashdash)

View File

@ -1088,7 +1088,6 @@ static int store_stash(int argc, const char **argv, const char *prefix,
int quiet = 0; int quiet = 0;
const char *stash_msg = NULL; const char *stash_msg = NULL;
struct object_id obj; struct object_id obj;
struct object_context dummy = {0};
struct option options[] = { struct option options[] = {
OPT__QUIET(&quiet, N_("be quiet")), OPT__QUIET(&quiet, N_("be quiet")),
OPT_STRING('m', "message", &stash_msg, "message", OPT_STRING('m', "message", &stash_msg, "message",
@ -1108,9 +1107,8 @@ static int store_stash(int argc, const char **argv, const char *prefix,
return -1; return -1;
} }


if (get_oid_with_context(the_repository, if (repo_get_oid_with_flags(the_repository, argv[0], &obj,
argv[0], quiet ? GET_OID_QUIETLY : 0, &obj, quiet ? GET_OID_QUIETLY : 0)) {
&dummy)) {
if (!quiet) if (!quiet)
fprintf_ln(stderr, _("Cannot update %s with %s"), fprintf_ln(stderr, _("Cannot update %s with %s"),
ref_stash, argv[0]); ref_stash, argv[0]);
@ -1121,7 +1119,6 @@ static int store_stash(int argc, const char **argv, const char *prefix,
ret = do_store_stash(&obj, stash_msg, quiet); ret = do_store_stash(&obj, stash_msg, quiet);


out: out:
object_context_release(&dummy);
return ret; return ret;
} }


@ -2233,7 +2230,6 @@ static int do_export_stash(struct repository *r,
const char **argv) const char **argv)
{ {
struct object_id base; struct object_id base;
struct object_context unused;
struct commit *prev; struct commit *prev;
struct commit_list *items = NULL, **iter = &items, *cur; struct commit_list *items = NULL, **iter = &items, *cur;
int res = 0; int res = 0;
@ -2267,9 +2263,9 @@ static int do_export_stash(struct repository *r,
struct commit *stash; struct commit *stash;


if (parse_stash_revision(&revision, argv[i], 1) || if (parse_stash_revision(&revision, argv[i], 1) ||
get_oid_with_context(r, revision.buf, repo_get_oid_with_flags(r, revision.buf, &oid,
GET_OID_QUIETLY | GET_OID_GENTLY, GET_OID_QUIETLY |
&oid, &unused)) { GET_OID_GENTLY)) {
res = error(_("unable to find stash entry %s"), argv[i]); res = error(_("unable to find stash entry %s"), argv[i]);
goto out; goto out;
} }

View File

@ -524,12 +524,11 @@ static void filter_sparse_oid__init(
struct filter *filter) struct filter *filter)
{ {
struct filter_sparse_data *d = xcalloc(1, sizeof(*d)); struct filter_sparse_data *d = xcalloc(1, sizeof(*d));
struct object_context oc;
struct object_id sparse_oid; struct object_id sparse_oid;


if (get_oid_with_context(the_repository, if (repo_get_oid_with_flags(the_repository,
filter_options->sparse_oid_name, filter_options->sparse_oid_name,
GET_OID_BLOB, &sparse_oid, &oc)) &sparse_oid, GET_OID_BLOB))
die(_("unable to access sparse blob in '%s'"), die(_("unable to access sparse blob in '%s'"),
filter_options->sparse_oid_name); filter_options->sparse_oid_name);
if (add_patterns_from_blob_to_list(&sparse_oid, "", 0, &d->pl) < 0) if (add_patterns_from_blob_to_list(&sparse_oid, "", 0, &d->pl) < 0)
@ -544,8 +543,6 @@ static void filter_sparse_oid__init(
filter->filter_data = d; filter->filter_data = d;
filter->filter_object_fn = filter_sparse; filter->filter_object_fn = filter_sparse;
filter->free_fn = filter_sparse_free; filter->free_fn = filter_sparse_free;

object_context_release(&oc);
} }


/* /*

View File

@ -1857,55 +1857,35 @@ int repo_get_oid_committish(struct repository *r,
const char *name, const char *name,
struct object_id *oid) struct object_id *oid)
{ {
struct object_context unused; return repo_get_oid_with_flags(r, name, oid, GET_OID_COMMITTISH);
int ret = get_oid_with_context(r, name, GET_OID_COMMITTISH,
oid, &unused);
object_context_release(&unused);
return ret;
} }


int repo_get_oid_treeish(struct repository *r, int repo_get_oid_treeish(struct repository *r,
const char *name, const char *name,
struct object_id *oid) struct object_id *oid)
{ {
struct object_context unused; return repo_get_oid_with_flags(r, name, oid, GET_OID_TREEISH);
int ret = get_oid_with_context(r, name, GET_OID_TREEISH,
oid, &unused);
object_context_release(&unused);
return ret;
} }


int repo_get_oid_commit(struct repository *r, int repo_get_oid_commit(struct repository *r,
const char *name, const char *name,
struct object_id *oid) struct object_id *oid)
{ {
struct object_context unused; return repo_get_oid_with_flags(r, name, oid, GET_OID_COMMIT);
int ret = get_oid_with_context(r, name, GET_OID_COMMIT,
oid, &unused);
object_context_release(&unused);
return ret;
} }


int repo_get_oid_tree(struct repository *r, int repo_get_oid_tree(struct repository *r,
const char *name, const char *name,
struct object_id *oid) struct object_id *oid)
{ {
struct object_context unused; return repo_get_oid_with_flags(r, name, oid, GET_OID_TREE);
int ret = get_oid_with_context(r, name, GET_OID_TREE,
oid, &unused);
object_context_release(&unused);
return ret;
} }


int repo_get_oid_blob(struct repository *r, int repo_get_oid_blob(struct repository *r,
const char *name, const char *name,
struct object_id *oid) struct object_id *oid)
{ {
struct object_context unused; return repo_get_oid_with_flags(r, name, oid, GET_OID_BLOB);
int ret = get_oid_with_context(r, name, GET_OID_BLOB,
oid, &unused);
object_context_release(&unused);
return ret;
} }


/* Must be called only when object_name:filename doesn't exist. */ /* Must be called only when object_name:filename doesn't exist. */