Skip to content

Commit a66fc22

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c44beea commit a66fc22

File tree

5 files changed

+17
-50
lines changed

5 files changed

+17
-50
lines changed

builtin/ls-tree.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ int cmd_ls_tree(int argc,
373373
OPT_END()
374374
};
375375
struct ls_tree_cmdmode_to_fmt *m2f = ls_tree_cmdmode_format;
376-
struct object_context obj_context = {0};
377376
int ret;
378377

379378
repo_config(the_repository, git_default_config, NULL);
@@ -405,9 +404,8 @@ int cmd_ls_tree(int argc,
405404
ls_tree_usage, ls_tree_options);
406405
if (argc < 1)
407406
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))
411409
die("Not a valid object name %s", argv[0]);
412410

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

448446
ret = !!read_tree(the_repository, tree, &options.pathspec, fn, &options);
449447
clear_pathspec(&options.pathspec);
450-
object_context_release(&obj_context);
451448
return ret;
452449
}

builtin/rev-parse.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ int cmd_rev_parse(int argc,
708708
struct object_id oid;
709709
unsigned int flags = 0;
710710
const char *name = NULL;
711-
struct object_context unused;
712711
struct strbuf buf = STRBUF_INIT;
713712
int seen_end_of_options = 0;
714713
enum format_type format = FORMAT_DEFAULT;
@@ -1141,9 +1140,8 @@ int cmd_rev_parse(int argc,
11411140
name++;
11421141
type = REVERSED;
11431142
}
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)) {
11471145
if (output_algo)
11481146
repo_oid_to_algop(the_repository, &oid,
11491147
output_algo, &oid);
@@ -1153,7 +1151,6 @@ int cmd_rev_parse(int argc,
11531151
show_rev(type, &oid, name);
11541152
continue;
11551153
}
1156-
object_context_release(&unused);
11571154
if (verify)
11581155
die_no_single_rev(quiet);
11591156
if (has_dashdash)

builtin/stash.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,6 @@ static int store_stash(int argc, const char **argv, const char *prefix,
10881088
int quiet = 0;
10891089
const char *stash_msg = NULL;
10901090
struct object_id obj;
1091-
struct object_context dummy = {0};
10921091
struct option options[] = {
10931092
OPT__QUIET(&quiet, N_("be quiet")),
10941093
OPT_STRING('m', "message", &stash_msg, "message",
@@ -1108,9 +1107,8 @@ static int store_stash(int argc, const char **argv, const char *prefix,
11081107
return -1;
11091108
}
11101109

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)) {
11141112
if (!quiet)
11151113
fprintf_ln(stderr, _("Cannot update %s with %s"),
11161114
ref_stash, argv[0]);
@@ -1121,7 +1119,6 @@ static int store_stash(int argc, const char **argv, const char *prefix,
11211119
ret = do_store_stash(&obj, stash_msg, quiet);
11221120

11231121
out:
1124-
object_context_release(&dummy);
11251122
return ret;
11261123
}
11271124

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

22692265
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)) {
22732269
res = error(_("unable to find stash entry %s"), argv[i]);
22742270
goto out;
22752271
}

list-objects-filter.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,11 @@ static void filter_sparse_oid__init(
524524
struct filter *filter)
525525
{
526526
struct filter_sparse_data *d = xcalloc(1, sizeof(*d));
527-
struct object_context oc;
528527
struct object_id sparse_oid;
529528

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))
533532
die(_("unable to access sparse blob in '%s'"),
534533
filter_options->sparse_oid_name);
535534
if (add_patterns_from_blob_to_list(&sparse_oid, "", 0, &d->pl) < 0)
@@ -544,8 +543,6 @@ static void filter_sparse_oid__init(
544543
filter->filter_data = d;
545544
filter->filter_object_fn = filter_sparse;
546545
filter->free_fn = filter_sparse_free;
547-
548-
object_context_release(&oc);
549546
}
550547

551548
/*

object-name.c

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,55 +1857,35 @@ int repo_get_oid_committish(struct repository *r,
18571857
const char *name,
18581858
struct object_id *oid)
18591859
{
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);
18651861
}
18661862

18671863
int repo_get_oid_treeish(struct repository *r,
18681864
const char *name,
18691865
struct object_id *oid)
18701866
{
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);
18761868
}
18771869

18781870
int repo_get_oid_commit(struct repository *r,
18791871
const char *name,
18801872
struct object_id *oid)
18811873
{
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);
18871875
}
18881876

18891877
int repo_get_oid_tree(struct repository *r,
18901878
const char *name,
18911879
struct object_id *oid)
18921880
{
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);
18981882
}
18991883

19001884
int repo_get_oid_blob(struct repository *r,
19011885
const char *name,
19021886
struct object_id *oid)
19031887
{
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);
19091889
}
19101890

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

0 commit comments

Comments
 (0)