]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cocci: apply the "refs.h" part of "the_repository.pending"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 28 Mar 2023 13:58:54 +0000 (15:58 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2023 14:36:46 +0000 (07:36 -0700)
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>
17 files changed:
archive.c
branch.c
builtin/checkout.c
builtin/fast-export.c
builtin/log.c
builtin/merge.c
builtin/reset.c
builtin/rev-parse.c
builtin/show-branch.c
builtin/stash.c
bundle.c
commit.c
contrib/coccinelle/the_repository.cocci
contrib/coccinelle/the_repository.pending.cocci
refs.h
remote.c
wt-status.c

index d43687a5c44976d51c00a5cd5b0b6d7905a06078..716a18567bce8ea536f6bbab5e180be8d57ae935 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -456,10 +456,11 @@ static void parse_treeish_arg(const char **argv,
                const char *colon = strchrnul(name, ':');
                int refnamelen = colon - name;
 
-               if (!dwim_ref(name, refnamelen, &oid, &ref, 0))
+               if (!repo_dwim_ref(the_repository, name, refnamelen, &oid, &ref, 0))
                        die(_("no such ref: %.*s"), refnamelen, name);
        } else {
-               dwim_ref(name, strlen(name), &oid, &ref, 0);
+               repo_dwim_ref(the_repository, name, strlen(name), &oid, &ref,
+                             0);
        }
 
        if (repo_get_oid(the_repository, name, &oid))
index 2efb5fbaa5f660439597ac450f3f0ac832385368..a01e465b11439bb0d690a4a7dccf20392300028a 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -541,7 +541,8 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
                die(_("not a valid object name: '%s'"), start_name);
        }
 
-       switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref, 0)) {
+       switch (repo_dwim_ref(the_repository, start_name, strlen(start_name),
+                             &oid, &real_ref, 0)) {
        case 0:
                /* Not branching from any existing branch */
                if (explicit_tracking)
index 1d1f33e33e7afe49875de920469b1551c6757e46..cb7cd315b3472e57ec825b2a17dedca7429f5ea5 100644 (file)
@@ -703,7 +703,8 @@ static void setup_branch_path(struct branch_info *branch)
         * If this is a ref, resolve it; otherwise, look up the OID for our
         * expression.  Failure here is okay.
         */
-       if (!dwim_ref(branch->name, strlen(branch->name), &branch->oid, &branch->refname, 0))
+       if (!repo_dwim_ref(the_repository, branch->name, strlen(branch->name),
+                          &branch->oid, &branch->refname, 0))
                repo_get_oid_committish(the_repository, branch->name, &branch->oid);
 
        strbuf_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
@@ -1424,7 +1425,8 @@ static void die_expecting_a_branch(const struct branch_info *branch_info)
        char *to_free;
        int code;
 
-       if (dwim_ref(branch_info->name, strlen(branch_info->name), &oid, &to_free, 0) == 1) {
+       if (repo_dwim_ref(the_repository, branch_info->name,
+                         strlen(branch_info->name), &oid, &to_free, 0) == 1) {
                const char *ref = to_free;
 
                if (skip_prefix(ref, "refs/tags/", &ref))
index 6515bd2ad8bff1583aa7b911ae95725ebef95a0f..550f078a8edb2d86b00af0fad7a9833b8339b8bc 100644 (file)
@@ -918,7 +918,8 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
                if (e->flags & UNINTERESTING)
                        continue;
 
-               if (dwim_ref(e->name, strlen(e->name), &oid, &full_name, 0) != 1)
+               if (repo_dwim_ref(the_repository, e->name, strlen(e->name),
+                                 &oid, &full_name, 0) != 1)
                        continue;
 
                if (refspecs.nr) {
index 3dde77bde277a72cb29d0a168129ee7466346d16..acf3faecd81983f30edec278b3517ea3c79b4589 100644 (file)
@@ -1204,7 +1204,8 @@ static char *find_branch_name(struct rev_info *rev)
                return NULL;
        ref = rev->cmdline.rev[positive].name;
        tip_oid = &rev->cmdline.rev[positive].item->oid;
-       if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref, 0) &&
+       if (repo_dwim_ref(the_repository, ref, strlen(ref), &branch_oid,
+                         &full_ref, 0) &&
            skip_prefix(full_ref, "refs/heads/", &v) &&
            oideq(tip_oid, &branch_oid))
                branch = xstrdup(v);
index 197e152aba9fbc91b1db6d2590f5f3e994a27232..69666546ca20aff4d66839a5d1daa641d87e58d7 100644 (file)
@@ -517,7 +517,8 @@ static void merge_name(const char *remote, struct strbuf *msg)
        if (!remote_head)
                die(_("'%s' does not point to a commit"), remote);
 
-       if (dwim_ref(remote, strlen(remote), &branch_head, &found_ref, 0) > 0) {
+       if (repo_dwim_ref(the_repository, remote, strlen(remote), &branch_head,
+                         &found_ref, 0) > 0) {
                if (starts_with(found_ref, "refs/heads/")) {
                        strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
                                    oid_to_hex(&branch_head), remote);
index 75b447ffdc67ed3bd343c27135b3e998c57557de..b65f379440bf5d8c762cee22eed98c5f0db5d43f 100644 (file)
@@ -465,7 +465,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                        char *ref = NULL;
                        int err;
 
-                       dwim_ref(rev, strlen(rev), &dummy, &ref, 0);
+                       repo_dwim_ref(the_repository, rev, strlen(rev),
+                                     &dummy, &ref, 0);
                        if (ref && !starts_with(ref, "refs/"))
                                FREE_AND_NULL(ref);
 
index 5685cf0ea7d1720538203c2e72bcd07724d29134..663f282c5f7ff9b7f7349fc30489b9ec39d33ca3 100644 (file)
@@ -136,7 +136,9 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
                        struct object_id discard;
                        char *full;
 
-                       switch (dwim_ref(name, strlen(name), &discard, &full, 0)) {
+                       switch (repo_dwim_ref(the_repository, name,
+                                             strlen(name), &discard, &full,
+                                             0)) {
                        case 0:
                                /*
                                 * Not found -- not a ref.  We could
index d60e536a53beb11ea55fe983ac58500bd057d5c6..af680485d58f83022cd65832f379898a05e8c649 100644 (file)
@@ -746,7 +746,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                        die(Q_("only %d entry can be shown at one time.",
                               "only %d entries can be shown at one time.",
                               MAX_REVS), MAX_REVS);
-               if (!dwim_ref(*av, strlen(*av), &oid, &ref, 0))
+               if (!repo_dwim_ref(the_repository, *av, strlen(*av), &oid,
+                                  &ref, 0))
                        die(_("no such ref %s"), *av);
 
                /* Has the base been specified? */
index 6c062e5204852755e9f849452eed139f89c9a68b..364273f1012a8cb10936502228f002e49fb2dfa7 100644 (file)
@@ -211,7 +211,8 @@ static int get_stash_info(struct stash_info *info, int argc, const char **argv)
        end_of_rev = strchrnul(revision, '@');
        strbuf_add(&symbolic, revision, end_of_rev - revision);
 
-       ret = dwim_ref(symbolic.buf, symbolic.len, &dummy, &expanded_ref, 0);
+       ret = repo_dwim_ref(the_repository, symbolic.buf, symbolic.len,
+                           &dummy, &expanded_ref, 0);
        strbuf_release(&symbolic);
        switch (ret) {
        case 0: /* Not found, but valid ref */
index 9b57bade7a64921412fc740cb5b7818330e35c82..dca96e51ee0181e617b57e353ed74afbec87bd6d 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -382,7 +382,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
 
                if (e->item->flags & UNINTERESTING)
                        continue;
-               if (dwim_ref(e->name, strlen(e->name), &oid, &ref, 0) != 1)
+               if (repo_dwim_ref(the_repository, e->name, strlen(e->name),
+                                 &oid, &ref, 0) != 1)
                        goto skip_write_ref;
                if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
                        flag = 0;
index dd22e76c3e16851f3a16476d37fe9d5343a6797d..0e2fc7dbab817257a57ef3ff2656616782479366 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -996,7 +996,8 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
        struct commit *ret = NULL;
        char *full_refname;
 
-       switch (dwim_ref(refname, strlen(refname), &oid, &full_refname, 0)) {
+       switch (repo_dwim_ref(the_repository, refname, strlen(refname), &oid,
+                             &full_refname, 0)) {
        case 0:
                die("No such ref: '%s'", refname);
        case 1:
index d5b644a868752d2362c2348dc2c2c0a3065f6dd1..b20a3e7084512e1e84a855b564e805d2ef0af288 100644 (file)
 |
 - has_promisor_remote
 + repo_has_promisor_remote
+// refs.h
+|
+- dwim_ref
++ repo_dwim_ref
 )
   (
 + the_repository,
index e17a60198c5a0d00a58a5df3b2a28d464f6aaa0c..8bf30798a04ec449ecda5cf97d74a86fcbec26b3 100644 (file)
@@ -5,11 +5,7 @@
 @@
 @@
 (
-// refs.h
-- dwim_ref
-+ repo_dwim_ref
 // rerere.h
-|
 - rerere
 + repo_rerere
 // revision.h
diff --git a/refs.h b/refs.h
index 935cdd1ece3db3af483cb2225f204966c0e6cfa5..2998244b6156ff39498924b1946e077ee6ea5a7d 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -159,12 +159,6 @@ int expand_ref(struct repository *r, const char *str, int len, struct object_id
 int repo_dwim_ref(struct repository *r, const char *str, int len,
                  struct object_id *oid, char **ref, int nonfatal_dangling_mark);
 int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
-static inline int dwim_ref(const char *str, int len, struct object_id *oid,
-                          char **ref, int nonfatal_dangling_mark)
-{
-       return repo_dwim_ref(the_repository, str, len, oid, ref,
-                            nonfatal_dangling_mark);
-}
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
 /*
index 12f6bea62524ad43bbb7eb4a08faacfc3b6c98d9..a03b03e467ed08cee7f63dd0cc93f4ffb3dc6dc5 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1808,8 +1808,9 @@ static void set_merge(struct remote_state *remote_state, struct branch *ret)
                if (!remote_find_tracking(remote, ret->merge[i]) ||
                    strcmp(ret->remote_name, "."))
                        continue;
-               if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
-                            &oid, &ref, 0) == 1)
+               if (repo_dwim_ref(the_repository, ret->merge_name[i],
+                                 strlen(ret->merge_name[i]), &oid, &ref,
+                                 0) == 1)
                        ret->merge[i]->dst = ref;
                else
                        ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
index c55c51b19244d728f872e3f49949928f1eba23dd..dcd1d0cee4c812d5686f3aa94306b2e3f363b498 100644 (file)
@@ -1664,7 +1664,8 @@ static void wt_status_get_detached_from(struct repository *r,
                return;
        }
 
-       if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref, 1) == 1 &&
+       if (repo_dwim_ref(the_repository, cb.buf.buf, cb.buf.len, &oid, &ref,
+                         1) == 1 &&
            /* oid is a commit? match without further lookup */
            (oideq(&cb.noid, &oid) ||
             /* perhaps oid is a tag, try to dereference to a commit */