cocci: apply the "refs.h" part of "the_repository.pending"
Apply the part of "the_repository.pending.cocci" pertaining to "refs.h". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 28, 2023 at 15:58 UTC
12cb1c10a64170a5d600dd1c6c8abfeec105fb6b
17 files changed
+37
-27
archive.c
+3
-2
@@ -456,10 +456,11 @@ static void parse_treeish_arg(const char **argv,
456
const char *colon = strchrnul(name, ':');
457
int refnamelen = colon - name;
458
459
- if (!dwim_ref(name, refnamelen, &oid, &ref, 0))
459
+ if (!repo_dwim_ref(the_repository, name, refnamelen, &oid, &ref, 0))
460
die(_("no such ref: %.*s"), refnamelen, name);
461
} else {
462
- dwim_ref(name, strlen(name), &oid, &ref, 0);
462
+ repo_dwim_ref(the_repository, name, strlen(name), &oid, &ref,
463
+ 0);
464
}
465
466
if (repo_get_oid(the_repository, name, &oid))
branch.c
+2
-1
@@ -541,7 +541,8 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
541
die(_("not a valid object name: '%s'"), start_name);
542
}
543
544
- switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref, 0)) {
544
+ switch (repo_dwim_ref(the_repository, start_name, strlen(start_name),
545
+ &oid, &real_ref, 0)) {
546
case 0:
547
/* Not branching from any existing branch */
548
if (explicit_tracking)
builtin/checkout.c
+4
-2
@@ -703,7 +703,8 @@ static void setup_branch_path(struct branch_info *branch)
703
* If this is a ref, resolve it; otherwise, look up the OID for our
704
* expression. Failure here is okay.
705
*/
706
- if (!dwim_ref(branch->name, strlen(branch->name), &branch->oid, &branch->refname, 0))
706
+ if (!repo_dwim_ref(the_repository, branch->name, strlen(branch->name),
707
+ &branch->oid, &branch->refname, 0))
708
repo_get_oid_committish(the_repository, branch->name, &branch->oid);
709
710
strbuf_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
@@ -1424,7 +1425,8 @@ static void die_expecting_a_branch(const struct branch_info *branch_info)
1425
char *to_free;
1426
int code;
1427
1427
- if (dwim_ref(branch_info->name, strlen(branch_info->name), &oid, &to_free, 0) == 1) {
1428
+ if (repo_dwim_ref(the_repository, branch_info->name,
1429
+ strlen(branch_info->name), &oid, &to_free, 0) == 1) {
1430
const char *ref = to_free;
1431
1432
if (skip_prefix(ref, "refs/tags/", &ref))
builtin/fast-export.c
+2
-1
@@ -918,7 +918,8 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
918
if (e->flags & UNINTERESTING)
919
continue;
920
921
- if (dwim_ref(e->name, strlen(e->name), &oid, &full_name, 0) != 1)
921
+ if (repo_dwim_ref(the_repository, e->name, strlen(e->name),
922
+ &oid, &full_name, 0) != 1)
923
continue;
924
925
if (refspecs.nr) {
builtin/log.c
+2
-1
@@ -1204,7 +1204,8 @@ static char *find_branch_name(struct rev_info *rev)
1204
return NULL;
1205
ref = rev->cmdline.rev[positive].name;
1206
tip_oid = &rev->cmdline.rev[positive].item->oid;
1207
- if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref, 0) &&
1207
+ if (repo_dwim_ref(the_repository, ref, strlen(ref), &branch_oid,
1208
+ &full_ref, 0) &&
1209
skip_prefix(full_ref, "refs/heads/", &v) &&
1210
oideq(tip_oid, &branch_oid))
1211
branch = xstrdup(v);
builtin/merge.c
+2
-1
@@ -517,7 +517,8 @@ static void merge_name(const char *remote, struct strbuf *msg)
517
if (!remote_head)
518
die(_("'%s' does not point to a commit"), remote);
519
520
- if (dwim_ref(remote, strlen(remote), &branch_head, &found_ref, 0) > 0) {
520
+ if (repo_dwim_ref(the_repository, remote, strlen(remote), &branch_head,
521
+ &found_ref, 0) > 0) {
522
if (starts_with(found_ref, "refs/heads/")) {
523
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
524
oid_to_hex(&branch_head), remote);
builtin/reset.c
+2
-1
@@ -465,7 +465,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
465
char *ref = NULL;
466
int err;
467
468
- dwim_ref(rev, strlen(rev), &dummy, &ref, 0);
468
+ repo_dwim_ref(the_repository, rev, strlen(rev),
469
+ &dummy, &ref, 0);
470
if (ref && !starts_with(ref, "refs/"))
471
FREE_AND_NULL(ref);
472
builtin/rev-parse.c
+3
-1
@@ -136,7 +136,9 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
136
struct object_id discard;
137
char *full;
138
139
- switch (dwim_ref(name, strlen(name), &discard, &full, 0)) {
139
+ switch (repo_dwim_ref(the_repository, name,
140
+ strlen(name), &discard, &full,
141
+ 0)) {
142
case 0:
143
/*
144
* Not found -- not a ref. We could
builtin/show-branch.c
+2
-1
@@ -746,7 +746,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
746
die(Q_("only %d entry can be shown at one time.",
747
"only %d entries can be shown at one time.",
748
MAX_REVS), MAX_REVS);
749
- if (!dwim_ref(*av, strlen(*av), &oid, &ref, 0))
749
+ if (!repo_dwim_ref(the_repository, *av, strlen(*av), &oid,
750
+ &ref, 0))
751
die(_("no such ref %s"), *av);
752
753
/* Has the base been specified? */
builtin/stash.c
+2
-1
@@ -211,7 +211,8 @@ static int get_stash_info(struct stash_info *info, int argc, const char **argv)
211
end_of_rev = strchrnul(revision, '@');
212
strbuf_add(&symbolic, revision, end_of_rev - revision);
213
214
- ret = dwim_ref(symbolic.buf, symbolic.len, &dummy, &expanded_ref, 0);
214
+ ret = repo_dwim_ref(the_repository, symbolic.buf, symbolic.len,
215
+ &dummy, &expanded_ref, 0);
216
strbuf_release(&symbolic);
217
switch (ret) {
218
case 0: /* Not found, but valid ref */
bundle.c
+2
-1
@@ -382,7 +382,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
382
383
if (e->item->flags & UNINTERESTING)
384
continue;
385
- if (dwim_ref(e->name, strlen(e->name), &oid, &ref, 0) != 1)
385
+ if (repo_dwim_ref(the_repository, e->name, strlen(e->name),
386
+ &oid, &ref, 0) != 1)
387
goto skip_write_ref;
388
if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
389
flag = 0;
commit.c
+2
-1
@@ -996,7 +996,8 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
996
struct commit *ret = NULL;
997
char *full_refname;
998
999
- switch (dwim_ref(refname, strlen(refname), &oid, &full_refname, 0)) {
999
+ switch (repo_dwim_ref(the_repository, refname, strlen(refname), &oid,
1000
+ &full_refname, 0)) {
1001
case 0:
1002
die("No such ref: '%s'", refname);
1003
case 1:
contrib/coccinelle/the_repository.cocci
+4
@@ -105,6 +105,10 @@
105
|
106
- has_promisor_remote
107
+ repo_has_promisor_remote
108
+// refs.h
109
+|
110
+- dwim_ref
111
++ repo_dwim_ref
112
)
113
(
114
+ the_repository,
contrib/coccinelle/the_repository.pending.cocci
-4
@@ -5,11 +5,7 @@
5
@@
6
@@
7
(
8
-// refs.h
9
-- dwim_ref
10
-+ repo_dwim_ref
8
// rerere.h
12
-|
9
- rerere
10
+ repo_rerere
11
// revision.h
refs.h
-6
@@ -159,12 +159,6 @@ int expand_ref(struct repository *r, const char *str, int len, struct object_id
159
int repo_dwim_ref(struct repository *r, const char *str, int len,
160
struct object_id *oid, char **ref, int nonfatal_dangling_mark);
161
int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
162
-static inline int dwim_ref(const char *str, int len, struct object_id *oid,
163
- char **ref, int nonfatal_dangling_mark)
164
-{
165
- return repo_dwim_ref(the_repository, str, len, oid, ref,
166
- nonfatal_dangling_mark);
167
-}
162
int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
163
164
/*
remote.c
+3
-2
@@ -1808,8 +1808,9 @@ static void set_merge(struct remote_state *remote_state, struct branch *ret)
1808
if (!remote_find_tracking(remote, ret->merge[i]) ||
1809
strcmp(ret->remote_name, "."))
1810
continue;
1811
- if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
1812
- &oid, &ref, 0) == 1)
1811
+ if (repo_dwim_ref(the_repository, ret->merge_name[i],
1812
+ strlen(ret->merge_name[i]), &oid, &ref,
1813
+ 0) == 1)
1814
ret->merge[i]->dst = ref;
1815
else
1816
ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
wt-status.c
+2
-1
@@ -1664,7 +1664,8 @@ static void wt_status_get_detached_from(struct repository *r,
1664
return;
1665
}
1666
1667
- if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref, 1) == 1 &&
1667
+ if (repo_dwim_ref(the_repository, cb.buf.buf, cb.buf.len, &oid, &ref,
1668
+ 1) == 1 &&
1669
/* oid is a commit? match without further lookup */
1670
(oideq(&cb.noid, &oid) ||
1671
/* perhaps oid is a tag, try to dereference to a commit */