{"thread":{"id":"64122","subject":"[PATCH] use repo_get_oid_with_flags()","startedAt":"2025-09-10T17:16:35Z","lastAt":"2025-09-15T06:16:50Z","messageCount":2,"participants":["René Scharfe","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"526061","messageId":"906196ac-2fd7-4c07-9e8f-22d67b0b64f9@web.de","threadId":"64122","inReplyTo":null,"subject":"[PATCH] use repo_get_oid_with_flags()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2025-09-10T17:16:30Z","receivedAt":"2025-09-10T17:16:35Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"get_oid_with_context() allows specifying flags and reports object\ndetails via a passed-in struct object_context.  Some callers just want\nto specify flags, but don't need any details back.  Convert them to\nrepo_get_oid_with_flags(), which provides just that and frees them from\ndealing with the context structure.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/ls-tree.c     |  7 ++-----\n builtin/rev-parse.c   |  7 ++-----\n builtin/stash.c       | 14 +++++---------\n list-objects-filter.c |  9 +++------\n object-name.c         | 30 +++++-------------------------\n 5 files changed, 17 insertions(+), 50 deletions(-)\n\ndiff --git a/builtin/ls-tree.c b/builtin/ls-tree.c\nindex 5d55731ca3..ec6940fc7c 100644\n--- a/builtin/ls-tree.c\n+++ b/builtin/ls-tree.c\n@@ -373,7 +373,6 @@ int cmd_ls_tree(int argc,\n \t\tOPT_END()\n \t};\n \tstruct ls_tree_cmdmode_to_fmt *m2f = ls_tree_cmdmode_format;\n-\tstruct object_context obj_context = {0};\n \tint ret;\n \n \trepo_config(the_repository, git_default_config, NULL);\n@@ -405,9 +404,8 @@ int cmd_ls_tree(int argc,\n \t\t\tls_tree_usage, ls_tree_options);\n \tif (argc < 1)\n \t\tusage_with_options(ls_tree_usage, ls_tree_options);\n-\tif (get_oid_with_context(the_repository, argv[0],\n-\t\t\t\t GET_OID_HASH_ANY, &oid,\n-\t\t\t\t &obj_context))\n+\tif (repo_get_oid_with_flags(the_repository, argv[0], &oid,\n+\t\t\t\t    GET_OID_HASH_ANY))\n \t\tdie(\"Not a valid object name %s\", argv[0]);\n \n \t/*\n@@ -447,6 +445,5 @@ int cmd_ls_tree(int argc,\n \n \tret = !!read_tree(the_repository, tree, &options.pathspec, fn, &options);\n \tclear_pathspec(&options.pathspec);\n-\tobject_context_release(&obj_context);\n \treturn ret;\n }\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 44ff1b8342..9da92b990d 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -708,7 +708,6 @@ int cmd_rev_parse(int argc,\n \tstruct object_id oid;\n \tunsigned int flags = 0;\n \tconst char *name = NULL;\n-\tstruct object_context unused;\n \tstruct strbuf buf = STRBUF_INIT;\n \tint seen_end_of_options = 0;\n \tenum format_type format = FORMAT_DEFAULT;\n@@ -1141,9 +1140,8 @@ int cmd_rev_parse(int argc,\n \t\t\tname++;\n \t\t\ttype = REVERSED;\n \t\t}\n-\t\tif (!get_oid_with_context(the_repository, name,\n-\t\t\t\t\t  flags, &oid, &unused)) {\n-\t\t\tobject_context_release(&unused);\n+\t\tif (!repo_get_oid_with_flags(the_repository, name, &oid,\n+\t\t\t\t\t     flags)) {\n \t\t\tif (output_algo)\n \t\t\t\trepo_oid_to_algop(the_repository, &oid,\n \t\t\t\t\t\t  output_algo, &oid);\n@@ -1153,7 +1151,6 @@ int cmd_rev_parse(int argc,\n \t\t\t\tshow_rev(type, &oid, name);\n \t\t\tcontinue;\n \t\t}\n-\t\tobject_context_release(&unused);\n \t\tif (verify)\n \t\t\tdie_no_single_rev(quiet);\n \t\tif (has_dashdash)\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex f5ddee5c7f..87acefb82f 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -1089,7 +1089,6 @@ static int store_stash(int argc, const char **argv, const char *prefix,\n \tint quiet = 0;\n \tconst char *stash_msg = NULL;\n \tstruct object_id obj;\n-\tstruct object_context dummy = {0};\n \tstruct option options[] = {\n \t\tOPT__QUIET(&quiet, N_(\"be quiet\")),\n \t\tOPT_STRING('m', \"message\", &stash_msg, \"message\",\n@@ -1109,9 +1108,8 @@ static int store_stash(int argc, const char **argv, const char *prefix,\n \t\treturn -1;\n \t}\n \n-\tif (get_oid_with_context(the_repository,\n-\t\t\t\t argv[0], quiet ? GET_OID_QUIETLY : 0, &obj,\n-\t\t\t\t &dummy)) {\n+\tif (repo_get_oid_with_flags(the_repository, argv[0], &obj,\n+\t\t\t\t    quiet ? GET_OID_QUIETLY : 0)) {\n \t\tif (!quiet)\n \t\t\tfprintf_ln(stderr, _(\"Cannot update %s with %s\"),\n \t\t\t\t\t     ref_stash, argv[0]);\n@@ -1122,7 +1120,6 @@ static int store_stash(int argc, const char **argv, const char *prefix,\n \tret = do_store_stash(&obj, stash_msg, quiet);\n \n out:\n-\tobject_context_release(&dummy);\n \treturn ret;\n }\n \n@@ -2235,7 +2232,6 @@ static int do_export_stash(struct repository *r,\n \t\t\t   const char **argv)\n {\n \tstruct object_id base;\n-\tstruct object_context unused;\n \tstruct commit *prev;\n \tstruct commit_list *items = NULL, **iter = &items, *cur;\n \tint res = 0;\n@@ -2269,9 +2265,9 @@ static int do_export_stash(struct repository *r,\n \t\t\tstruct commit *stash;\n \n \t\t\tif (parse_stash_revision(&revision, argv[i], 1) ||\n-\t\t\t    get_oid_with_context(r, revision.buf,\n-\t\t\t\t\t\t GET_OID_QUIETLY | GET_OID_GENTLY,\n-\t\t\t\t\t\t &oid, &unused)) {\n+\t\t\t    repo_get_oid_with_flags(r, revision.buf, &oid,\n+\t\t\t\t\t\t    GET_OID_QUIETLY |\n+\t\t\t\t\t\t    GET_OID_GENTLY)) {\n \t\t\t\tres = error(_(\"unable to find stash entry %s\"), argv[i]);\n \t\t\t\tgoto out;\n \t\t\t}\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex 7ecd4d9ef5..acd65ebb73 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -524,12 +524,11 @@ static void filter_sparse_oid__init(\n \tstruct filter *filter)\n {\n \tstruct filter_sparse_data *d = xcalloc(1, sizeof(*d));\n-\tstruct object_context oc;\n \tstruct object_id sparse_oid;\n \n-\tif (get_oid_with_context(the_repository,\n-\t\t\t\t filter_options->sparse_oid_name,\n-\t\t\t\t GET_OID_BLOB, &sparse_oid, &oc))\n+\tif (repo_get_oid_with_flags(the_repository,\n+\t\t\t\t    filter_options->sparse_oid_name,\n+\t\t\t\t    &sparse_oid, GET_OID_BLOB))\n \t\tdie(_(\"unable to access sparse blob in '%s'\"),\n \t\t    filter_options->sparse_oid_name);\n \tif (add_patterns_from_blob_to_list(&sparse_oid, \"\", 0, &d->pl) < 0)\n@@ -544,8 +543,6 @@ static void filter_sparse_oid__init(\n \tfilter->filter_data = d;\n \tfilter->filter_object_fn = filter_sparse;\n \tfilter->free_fn = filter_sparse_free;\n-\n-\tobject_context_release(&oc);\n }\n \n /*\ndiff --git a/object-name.c b/object-name.c\nindex 732056ff5e..52d87348d1 100644\n--- a/object-name.c\n+++ b/object-name.c\n@@ -1858,55 +1858,35 @@ int repo_get_oid_committish(struct repository *r,\n \t\t\t    const char *name,\n \t\t\t    struct object_id *oid)\n {\n-\tstruct object_context unused;\n-\tint ret = get_oid_with_context(r, name, GET_OID_COMMITTISH,\n-\t\t\t\t       oid, &unused);\n-\tobject_context_release(&unused);\n-\treturn ret;\n+\treturn repo_get_oid_with_flags(r, name, oid, GET_OID_COMMITTISH);\n }\n \n int repo_get_oid_treeish(struct repository *r,\n \t\t\t const char *name,\n \t\t\t struct object_id *oid)\n {\n-\tstruct object_context unused;\n-\tint ret = get_oid_with_context(r, name, GET_OID_TREEISH,\n-\t\t\t\t       oid, &unused);\n-\tobject_context_release(&unused);\n-\treturn ret;\n+\treturn repo_get_oid_with_flags(r, name, oid, GET_OID_TREEISH);\n }\n \n int repo_get_oid_commit(struct repository *r,\n \t\t\tconst char *name,\n \t\t\tstruct object_id *oid)\n {\n-\tstruct object_context unused;\n-\tint ret = get_oid_with_context(r, name, GET_OID_COMMIT,\n-\t\t\t\t       oid, &unused);\n-\tobject_context_release(&unused);\n-\treturn ret;\n+\treturn repo_get_oid_with_flags(r, name, oid, GET_OID_COMMIT);\n }\n \n int repo_get_oid_tree(struct repository *r,\n \t\t      const char *name,\n \t\t      struct object_id *oid)\n {\n-\tstruct object_context unused;\n-\tint ret = get_oid_with_context(r, name, GET_OID_TREE,\n-\t\t\t\t       oid, &unused);\n-\tobject_context_release(&unused);\n-\treturn ret;\n+\treturn repo_get_oid_with_flags(r, name, oid, GET_OID_TREE);\n }\n \n int repo_get_oid_blob(struct repository *r,\n \t\t      const char *name,\n \t\t      struct object_id *oid)\n {\n-\tstruct object_context unused;\n-\tint ret = get_oid_with_context(r, name, GET_OID_BLOB,\n-\t\t\t\t       oid, &unused);\n-\tobject_context_release(&unused);\n-\treturn ret;\n+\treturn repo_get_oid_with_flags(r, name, oid, GET_OID_BLOB);\n }\n \n /* Must be called only when object_name:filename doesn't exist. */\n-- \n2.51.0\n"},{"id":"526300","messageId":"aMevTM6YESMDdWPh@pks.im","threadId":"64122","inReplyTo":"906196ac-2fd7-4c07-9e8f-22d67b0b64f9@web.de","subject":"Re: [PATCH] use repo_get_oid_with_flags()","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-09-15T06:16:44Z","receivedAt":"2025-09-15T06:16:50Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Sep 10, 2025 at 07:16:30PM +0200, René Scharfe wrote:\n\nNit: it would probably make sense to add something like a `treewide: `\nprefix to the patch subject.\n\n> get_oid_with_context() allows specifying flags and reports object\n> details via a passed-in struct object_context.  Some callers just want\n> to specify flags, but don't need any details back.  Convert them to\n> repo_get_oid_with_flags(), which provides just that and frees them from\n> dealing with the context structure.\n\nMakes sense. `repo_get_oid_with_flags()` is a mere wrapper around\n`get_oid_with_context()` with an object context. So these two would be\nequivalent to one another.\n\nOne thing that is a bit weird though is that `repo_get_oid_with_flags()`\nreturns an `int` even though it directly returns the result from\n`get_oid_with_context()`, which returns an `enum get_oid_result`. That\nshouldn't impact correctness though, and it's not a new problem.\n\n> diff --git a/object-name.c b/object-name.c\n> index 732056ff5e..52d87348d1 100644\n> --- a/object-name.c\n> +++ b/object-name.c\n> @@ -1858,55 +1858,35 @@ int repo_get_oid_committish(struct repository *r,\n>  \t\t\t    const char *name,\n>  \t\t\t    struct object_id *oid)\n>  {\n> -\tstruct object_context unused;\n> -\tint ret = get_oid_with_context(r, name, GET_OID_COMMITTISH,\n> -\t\t\t\t       oid, &unused);\n> -\tobject_context_release(&unused);\n> -\treturn ret;\n> +\treturn repo_get_oid_with_flags(r, name, oid, GET_OID_COMMITTISH);\n>  }\n\nThe same is true for all these functions. It would feel more sensible if\nthose all returned `enum get_oid_result`. But as said, that's not a new\nproblem and doesn't need fixing in your patch.\n\nOther than that all the conversions look correct to me, thanks!\n\nPatrick\n"}]}