git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 13/17] cocci: apply the "refs.h" part of "the_repository.pending"
Date: Fri, 17 Mar 2023 16:35:17 +0100	[thread overview]
Message-ID: <patch-13.17-aae743233ab-20230317T152724Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.17-00000000000-20230317T152724Z-avarab@gmail.com>

Apply the part of "the_repository.pending.cocci" pertaining to
"refs.h".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 archive.c                                       | 5 +++--
 branch.c                                        | 3 ++-
 builtin/checkout.c                              | 6 ++++--
 builtin/fast-export.c                           | 3 ++-
 builtin/log.c                                   | 3 ++-
 builtin/merge.c                                 | 3 ++-
 builtin/reset.c                                 | 3 ++-
 builtin/rev-parse.c                             | 4 +++-
 builtin/show-branch.c                           | 3 ++-
 builtin/stash.c                                 | 3 ++-
 bundle.c                                        | 3 ++-
 commit.c                                        | 3 ++-
 contrib/coccinelle/the_repository.cocci         | 4 ++++
 contrib/coccinelle/the_repository.pending.cocci | 4 ----
 refs.h                                          | 6 ------
 remote.c                                        | 5 +++--
 wt-status.c                                     | 3 ++-
 17 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/archive.c b/archive.c
index d43687a5c44..716a18567bc 100644
--- 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))
diff --git a/branch.c b/branch.c
index 2efb5fbaa5f..a01e465b114 100644
--- 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)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 1d1f33e33e7..cb7cd315b34 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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))
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 6515bd2ad8b..550f078a8ed 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -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) {
diff --git a/builtin/log.c b/builtin/log.c
index 3dde77bde27..acf3faecd81 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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);
diff --git a/builtin/merge.c b/builtin/merge.c
index 197e152aba9..69666546ca2 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -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);
diff --git a/builtin/reset.c b/builtin/reset.c
index 75b447ffdc6..b65f379440b 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -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);
 
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 5685cf0ea7d..663f282c5f7 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -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
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index d60e536a53b..af680485d58 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -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? */
diff --git a/builtin/stash.c b/builtin/stash.c
index 6c062e52048..364273f1012 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -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 */
diff --git a/bundle.c b/bundle.c
index 9b57bade7a6..dca96e51ee0 100644
--- 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;
diff --git a/commit.c b/commit.c
index dd22e76c3e1..0e2fc7dbab8 100644
--- 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:
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index d5b644a8687..b20a3e70845 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -105,6 +105,10 @@
 |
 - has_promisor_remote
 + repo_has_promisor_remote
+// refs.h
+|
+- dwim_ref
++ repo_dwim_ref
 )
   (
 + the_repository,
diff --git a/contrib/coccinelle/the_repository.pending.cocci b/contrib/coccinelle/the_repository.pending.cocci
index e17a60198c5..8bf30798a04 100644
--- a/contrib/coccinelle/the_repository.pending.cocci
+++ b/contrib/coccinelle/the_repository.pending.cocci
@@ -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 935cdd1ece3..2998244b615 100644
--- 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);
 
 /*
diff --git a/remote.c b/remote.c
index 12f6bea6252..a03b03e467e 100644
--- 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]);
diff --git a/wt-status.c b/wt-status.c
index c55c51b1924..dcd1d0cee4c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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 */
-- 
2.40.0.rc1.1034.g5867a1b10c5


  parent reply	other threads:[~2023-03-17 15:36 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-17 15:35 [PATCH 00/17] cocci: remove "the_index" wrapper macros Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 01/17] cocci: remove dead rule from "the_repository.pending.cocci" Ævar Arnfjörð Bjarmason
2023-03-17 16:14   ` Eric Sunshine
2023-03-19  5:53   ` Elijah Newren
2023-03-17 15:35 ` [PATCH 02/17] cocci: fix incorrect & verbose "the_repository" rules Ævar Arnfjörð Bjarmason
2023-03-19  5:55   ` Elijah Newren
2023-03-22 22:46   ` Glen Choo
2023-03-26  5:02     ` Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 03/17] cocci: sort "the_repository" rules by header Ævar Arnfjörð Bjarmason
2023-03-19  5:59   ` Elijah Newren
2023-03-17 15:35 ` [PATCH 04/17] cocci: add missing "the_repository" macros to "pending" Ævar Arnfjörð Bjarmason
2023-03-19  6:04   ` Elijah Newren
2023-03-17 15:35 ` [PATCH 05/17] cocci: apply the "cache.h" part of "the_repository.pending" Ævar Arnfjörð Bjarmason
2023-03-19  6:06   ` Elijah Newren
2023-03-22 23:17   ` Glen Choo
2023-03-17 15:35 ` [PATCH 06/17] cocci: apply the "commit-reach.h" " Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 07/17] cocci: apply the "commit.h" " Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 08/17] cocci: apply the "diff.h" " Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 09/17] cocci: apply the "object-store.h" " Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 10/17] cocci: apply the "pretty.h" " Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 11/17] cocci: apply the "packfile.h" " Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 12/17] cocci: apply the "promisor-remote.h" " Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` Ævar Arnfjörð Bjarmason [this message]
2023-03-17 15:35 ` [PATCH 14/17] cocci: apply the "rerere.h" " Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 15/17] cocci: apply the "revision.h" " Ævar Arnfjörð Bjarmason
2023-03-22 23:38   ` Glen Choo
2023-03-22 23:53     ` Glen Choo
2023-03-26  4:59       ` Ævar Arnfjörð Bjarmason
2023-03-17 15:35 ` [PATCH 16/17] post-cocci: adjust comments for recent repo_* migration Ævar Arnfjörð Bjarmason
2023-03-19  6:12   ` Elijah Newren
2023-03-17 15:35 ` [PATCH 17/17] libs: use "struct repository *" argument, not "the_repository" Ævar Arnfjörð Bjarmason
2023-03-19  6:19   ` Elijah Newren
2023-03-28 10:53     ` Ævar Arnfjörð Bjarmason
2023-03-17 19:22 ` [PATCH 00/17] cocci: remove "the_index" wrapper macros Junio C Hamano
2023-03-28 13:58 ` [PATCH v2 00/17] cocci: remove "the_repository" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 01/17] cocci: remove dead rule from "the_repository.pending.cocci" Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 02/17] cocci: fix incorrect & verbose "the_repository" rules Ævar Arnfjörð Bjarmason
2023-03-29 20:35     ` Taylor Blau
2023-03-28 13:58   ` [PATCH v2 03/17] cocci: sort "the_repository" rules by header Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 04/17] cocci: add missing "the_repository" macros to "pending" Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 05/17] cocci: apply the "cache.h" part of "the_repository.pending" Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 06/17] cocci: apply the "commit-reach.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 07/17] cocci: apply the "commit.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 08/17] cocci: apply the "diff.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 09/17] cocci: apply the "object-store.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 10/17] cocci: apply the "pretty.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 11/17] cocci: apply the "packfile.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 12/17] cocci: apply the "promisor-remote.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 13/17] cocci: apply the "refs.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 14/17] cocci: apply the "rerere.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 15/17] cocci: apply the "revision.h" " Ævar Arnfjörð Bjarmason
2023-03-28 13:58   ` [PATCH v2 16/17] post-cocci: adjust comments for recent repo_* migration Ævar Arnfjörð Bjarmason
2023-03-29 20:50     ` Taylor Blau
2023-03-28 13:58   ` [PATCH v2 17/17] libs: use "struct repository *" argument, not "the_repository" Ævar Arnfjörð Bjarmason
2023-03-28 14:09   ` [PATCH v2 00/17] cocci: remove "the_repository" wrapper macros Junio C Hamano
2023-03-28 14:34     ` Junio C Hamano
2023-03-29 19:02   ` Junio C Hamano
2023-03-29 22:04     ` Taylor Blau
2023-03-30  3:55     ` Elijah Newren
2023-03-30 18:08     ` Glen Choo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-13.17-aae743233ab-20230317T152724Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).