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>

René Scharfe committed Sep 10, 2025 at 19:16 UTC a66fc22bf9b7f379fc68e23c54d42ac9b7eaa845
5 files changed +17 -50
builtin/ls-tree.c
+2 -5
@@ -373,7 +373,6 @@ int cmd_ls_tree(int argc,
373 OPT_END()
374 };
375 struct ls_tree_cmdmode_to_fmt *m2f = ls_tree_cmdmode_format;
376 - struct object_context obj_context = {0};
376 int ret;
377
378 repo_config(the_repository, git_default_config, NULL);
@@ -405,9 +404,8 @@ int cmd_ls_tree(int argc,
404 ls_tree_usage, ls_tree_options);
405 if (argc < 1)
406 usage_with_options(ls_tree_usage, ls_tree_options);
408 - if (get_oid_with_context(the_repository, argv[0],
409 - GET_OID_HASH_ANY, &oid,
410 - &obj_context))
407 + if (repo_get_oid_with_flags(the_repository, argv[0], &oid,
408 + GET_OID_HASH_ANY))
409 die("Not a valid object name %s", argv[0]);
410
411 /*
@@ -447,6 +445,5 @@ int cmd_ls_tree(int argc,
445
446 ret = !!read_tree(the_repository, tree, &options.pathspec, fn, &options);
447 clear_pathspec(&options.pathspec);
450 - object_context_release(&obj_context);
448 return ret;
449 }
builtin/rev-parse.c
+2 -5
@@ -708,7 +708,6 @@ int cmd_rev_parse(int argc,
708 struct object_id oid;
709 unsigned int flags = 0;
710 const char *name = NULL;
711 - struct object_context unused;
711 struct strbuf buf = STRBUF_INIT;
712 int seen_end_of_options = 0;
713 enum format_type format = FORMAT_DEFAULT;
@@ -1141,9 +1140,8 @@ int cmd_rev_parse(int argc,
1140 name++;
1141 type = REVERSED;
1142 }
1144 - if (!get_oid_with_context(the_repository, name,
1145 - flags, &oid, &unused)) {
1146 - object_context_release(&unused);
1143 + if (!repo_get_oid_with_flags(the_repository, name, &oid,
1144 + flags)) {
1145 if (output_algo)
1146 repo_oid_to_algop(the_repository, &oid,
1147 output_algo, &oid);
@@ -1153,7 +1151,6 @@ int cmd_rev_parse(int argc,
1151 show_rev(type, &oid, name);
1152 continue;
1153 }
1156 - object_context_release(&unused);
1154 if (verify)
1155 die_no_single_rev(quiet);
1156 if (has_dashdash)
builtin/stash.c
+5 -9
@@ -1088,7 +1088,6 @@ static int store_stash(int argc, const char **argv, const char *prefix,
1088 int quiet = 0;
1089 const char *stash_msg = NULL;
1090 struct object_id obj;
1091 - struct object_context dummy = {0};
1091 struct option options[] = {
1092 OPT__QUIET(&quiet, N_("be quiet")),
1093 OPT_STRING('m', "message", &stash_msg, "message",
@@ -1108,9 +1107,8 @@ static int store_stash(int argc, const char **argv, const char *prefix,
1107 return -1;
1108 }
1109
1111 - if (get_oid_with_context(the_repository,
1112 - argv[0], quiet ? GET_OID_QUIETLY : 0, &obj,
1113 - &dummy)) {
1110 + if (repo_get_oid_with_flags(the_repository, argv[0], &obj,
1111 + quiet ? GET_OID_QUIETLY : 0)) {
1112 if (!quiet)
1113 fprintf_ln(stderr, _("Cannot update %s with %s"),
1114 ref_stash, argv[0]);
@@ -1121,7 +1119,6 @@ static int store_stash(int argc, const char **argv, const char *prefix,
1119 ret = do_store_stash(&obj, stash_msg, quiet);
1120
1121 out:
1124 - object_context_release(&dummy);
1122 return ret;
1123 }
1124
@@ -2233,7 +2230,6 @@ static int do_export_stash(struct repository *r,
2230 const char **argv)
2231 {
2232 struct object_id base;
2236 - struct object_context unused;
2233 struct commit *prev;
2234 struct commit_list *items = NULL, **iter = &items, *cur;
2235 int res = 0;
@@ -2267,9 +2263,9 @@ static int do_export_stash(struct repository *r,
2263 struct commit *stash;
2264
2265 if (parse_stash_revision(&revision, argv[i], 1) ||
2270 - get_oid_with_context(r, revision.buf,
2271 - GET_OID_QUIETLY | GET_OID_GENTLY,
2272 - &oid, &unused)) {
2266 + repo_get_oid_with_flags(r, revision.buf, &oid,
2267 + GET_OID_QUIETLY |
2268 + GET_OID_GENTLY)) {
2269 res = error(_("unable to find stash entry %s"), argv[i]);
2270 goto out;
2271 }
list-objects-filter.c
+3 -6
@@ -524,12 +524,11 @@ static void filter_sparse_oid__init(
524 struct filter *filter)
525 {
526 struct filter_sparse_data *d = xcalloc(1, sizeof(*d));
527 - struct object_context oc;
527 struct object_id sparse_oid;
528
530 - if (get_oid_with_context(the_repository,
531 - filter_options->sparse_oid_name,
532 - GET_OID_BLOB, &sparse_oid, &oc))
529 + if (repo_get_oid_with_flags(the_repository,
530 + filter_options->sparse_oid_name,
531 + &sparse_oid, GET_OID_BLOB))
532 die(_("unable to access sparse blob in '%s'"),
533 filter_options->sparse_oid_name);
534 if (add_patterns_from_blob_to_list(&sparse_oid, "", 0, &d->pl) < 0)
@@ -544,8 +543,6 @@ static void filter_sparse_oid__init(
543 filter->filter_data = d;
544 filter->filter_object_fn = filter_sparse;
545 filter->free_fn = filter_sparse_free;
547 -
548 - object_context_release(&oc);
546 }
547
548 /*
object-name.c
+5 -25
@@ -1857,55 +1857,35 @@ int repo_get_oid_committish(struct repository *r,
1857 const char *name,
1858 struct object_id *oid)
1859 {
1860 - struct object_context unused;
1861 - int ret = get_oid_with_context(r, name, GET_OID_COMMITTISH,
1862 - oid, &unused);
1863 - object_context_release(&unused);
1864 - return ret;
1860 + return repo_get_oid_with_flags(r, name, oid, GET_OID_COMMITTISH);
1861 }
1862
1863 int repo_get_oid_treeish(struct repository *r,
1864 const char *name,
1865 struct object_id *oid)
1866 {
1871 - struct object_context unused;
1872 - int ret = get_oid_with_context(r, name, GET_OID_TREEISH,
1873 - oid, &unused);
1874 - object_context_release(&unused);
1875 - return ret;
1867 + return repo_get_oid_with_flags(r, name, oid, GET_OID_TREEISH);
1868 }
1869
1870 int repo_get_oid_commit(struct repository *r,
1871 const char *name,
1872 struct object_id *oid)
1873 {
1882 - struct object_context unused;
1883 - int ret = get_oid_with_context(r, name, GET_OID_COMMIT,
1884 - oid, &unused);
1885 - object_context_release(&unused);
1886 - return ret;
1874 + return repo_get_oid_with_flags(r, name, oid, GET_OID_COMMIT);
1875 }
1876
1877 int repo_get_oid_tree(struct repository *r,
1878 const char *name,
1879 struct object_id *oid)
1880 {
1893 - struct object_context unused;
1894 - int ret = get_oid_with_context(r, name, GET_OID_TREE,
1895 - oid, &unused);
1896 - object_context_release(&unused);
1897 - return ret;
1881 + return repo_get_oid_with_flags(r, name, oid, GET_OID_TREE);
1882 }
1883
1884 int repo_get_oid_blob(struct repository *r,
1885 const char *name,
1886 struct object_id *oid)
1887 {
1904 - struct object_context unused;
1905 - int ret = get_oid_with_context(r, name, GET_OID_BLOB,
1906 - oid, &unused);
1907 - object_context_release(&unused);
1908 - return ret;
1888 + return repo_get_oid_with_flags(r, name, oid, GET_OID_BLOB);
1889 }
1890
1891 /* Must be called only when object_name:filename doesn't exist. */