From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Taylor Blau <me@ttaylorr.com>, James Liu <james@jamesliu.io>,
Jeff King <peff@peff.net>
Subject: [PATCH v2 1/5] refs: introduce missing functions that accept a `struct ref_store`
Date: Tue, 7 May 2024 09:11:39 +0200 [thread overview]
Message-ID: <dba5df086d9dbbc2801f946abef47714b41d3750.1715065736.git.ps@pks.im> (raw)
In-Reply-To: <cover.1715065736.git.ps@pks.im>
[-- Attachment #1: Type: text/plain, Size: 7391 bytes --]
While most of the functions in "refs.h" have a variant that accepts a
`struct ref_store`, some don't. Callers of these functions are thus
forced to implicitly rely on `the_repository` to figure out the ref
store that is to be used.
Introduce those missing functions to address this shortcoming.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
refs.c | 65 +++++++++++++++++++++++++++++++++++++++++++++-------------
refs.h | 13 ++++++++++++
2 files changed, 64 insertions(+), 14 deletions(-)
diff --git a/refs.c b/refs.c
index 55d2e0b2cb..7cafda1c25 100644
--- a/refs.c
+++ b/refs.c
@@ -400,19 +400,29 @@ struct for_each_ref_filter {
void *cb_data;
};
-int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
+int refs_read_ref_full(struct ref_store *refs, const char *refname,
+ int resolve_flags, struct object_id *oid, int *flags)
{
- struct ref_store *refs = get_main_ref_store(the_repository);
-
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags,
oid, flags))
return 0;
return -1;
}
+int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
+{
+ return refs_read_ref_full(get_main_ref_store(the_repository), refname,
+ resolve_flags, oid, flags);
+}
+
+int refs_read_ref(struct ref_store *refs, const char *refname, struct object_id *oid)
+{
+ return refs_read_ref_full(refs, refname, RESOLVE_REF_READING, oid, NULL);
+}
+
int read_ref(const char *refname, struct object_id *oid)
{
- return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
+ return refs_read_ref(get_main_ref_store(the_repository), refname, oid);
}
int refs_ref_exists(struct ref_store *refs, const char *refname)
@@ -542,7 +552,7 @@ int for_each_remote_ref(each_ref_fn fn, void *cb_data)
return refs_for_each_remote_ref(get_main_ref_store(the_repository), fn, cb_data);
}
-int head_ref_namespaced(each_ref_fn fn, void *cb_data)
+int refs_head_ref_namespaced(struct ref_store *refs, each_ref_fn fn, void *cb_data)
{
struct strbuf buf = STRBUF_INIT;
int ret = 0;
@@ -550,13 +560,19 @@ int head_ref_namespaced(each_ref_fn fn, void *cb_data)
int flag;
strbuf_addf(&buf, "%sHEAD", get_git_namespace());
- if (!read_ref_full(buf.buf, RESOLVE_REF_READING, &oid, &flag))
+ if (!refs_read_ref_full(refs, buf.buf, RESOLVE_REF_READING, &oid, &flag))
ret = fn(buf.buf, &oid, flag, cb_data);
strbuf_release(&buf);
return ret;
}
+int head_ref_namespaced(each_ref_fn fn, void *cb_data)
+{
+ return refs_head_ref_namespaced(get_main_ref_store(the_repository),
+ fn, cb_data);
+}
+
void normalize_glob_ref(struct string_list_item *item, const char *prefix,
const char *pattern)
{
@@ -583,8 +599,8 @@ void normalize_glob_ref(struct string_list_item *item, const char *prefix,
strbuf_release(&normalized_pattern);
}
-int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
- const char *prefix, void *cb_data)
+int refs_for_each_glob_ref_in(struct ref_store *refs, each_ref_fn fn,
+ const char *pattern, const char *prefix, void *cb_data)
{
struct strbuf real_pattern = STRBUF_INIT;
struct for_each_ref_filter filter;
@@ -607,15 +623,29 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
filter.prefix = prefix;
filter.fn = fn;
filter.cb_data = cb_data;
- ret = for_each_ref(for_each_filter_refs, &filter);
+ ret = refs_for_each_ref(refs, for_each_filter_refs, &filter);
strbuf_release(&real_pattern);
return ret;
}
+int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
+ const char *prefix, void *cb_data)
+{
+ return refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
+ fn, pattern, prefix, cb_data);
+}
+
+int refs_for_each_glob_ref(struct ref_store *refs, each_ref_fn fn,
+ const char *pattern, void *cb_data)
+{
+ return refs_for_each_glob_ref_in(refs, fn, pattern, NULL, cb_data);
+}
+
int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
{
- return for_each_glob_ref_in(fn, pattern, NULL, cb_data);
+ return refs_for_each_glob_ref(get_main_ref_store(the_repository),
+ fn, pattern, cb_data);
}
const char *prettify_refname(const char *name)
@@ -1733,18 +1763,25 @@ int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_dat
DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
}
-int for_each_namespaced_ref(const char **exclude_patterns,
- each_ref_fn fn, void *cb_data)
+int refs_for_each_namespaced_ref(struct ref_store *refs,
+ const char **exclude_patterns,
+ each_ref_fn fn, void *cb_data)
{
struct strbuf buf = STRBUF_INIT;
int ret;
strbuf_addf(&buf, "%srefs/", get_git_namespace());
- ret = do_for_each_ref(get_main_ref_store(the_repository),
- buf.buf, exclude_patterns, fn, 0, 0, cb_data);
+ ret = do_for_each_ref(refs, buf.buf, exclude_patterns, fn, 0, 0, cb_data);
strbuf_release(&buf);
return ret;
}
+int for_each_namespaced_ref(const char **exclude_patterns,
+ each_ref_fn fn, void *cb_data)
+{
+ return refs_for_each_namespaced_ref(get_main_ref_store(the_repository),
+ exclude_patterns, fn, cb_data);
+}
+
int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
{
return do_for_each_ref(refs, "", NULL, fn, 0,
diff --git a/refs.h b/refs.h
index d278775e08..10982dcf03 100644
--- a/refs.h
+++ b/refs.h
@@ -81,8 +81,12 @@ char *refs_resolve_refdup(struct ref_store *refs,
char *resolve_refdup(const char *refname, int resolve_flags,
struct object_id *oid, int *flags);
+int refs_read_ref_full(struct ref_store *refs, const char *refname,
+ int resolve_flags, struct object_id *oid, int *flags);
int read_ref_full(const char *refname, int resolve_flags,
struct object_id *oid, int *flags);
+
+int refs_read_ref(struct ref_store *refs, const char *refname, struct object_id *oid);
int read_ref(const char *refname, struct object_id *oid);
int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
@@ -375,16 +379,25 @@ int for_each_remote_ref(each_ref_fn fn, void *cb_data);
int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data);
/* iterates all refs that match the specified glob pattern. */
+int refs_for_each_glob_ref(struct ref_store *refs, each_ref_fn fn,
+ const char *pattern, void *cb_data);
int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data);
+int refs_for_each_glob_ref_in(struct ref_store *refs, each_ref_fn fn,
+ const char *pattern, const char *prefix, void *cb_data);
int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
const char *prefix, void *cb_data);
+int refs_head_ref_namespaced(struct ref_store *refs, each_ref_fn fn, void *cb_data);
int head_ref_namespaced(each_ref_fn fn, void *cb_data);
+
/*
* references matching any pattern in "exclude_patterns" are omitted from the
* result set on a best-effort basis.
*/
+int refs_for_each_namespaced_ref(struct ref_store *refs,
+ const char **exclude_patterns,
+ each_ref_fn fn, void *cb_data);
int for_each_namespaced_ref(const char **exclude_patterns,
each_ref_fn fn, void *cb_data);
--
2.45.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-05-07 7:11 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 6:27 [PATCH 0/5] refs: remove functions without ref store Patrick Steinhardt
2024-05-03 6:27 ` [PATCH 1/5] refs: introduce missing functions that accept a `struct ref_store` Patrick Steinhardt
2024-05-03 17:11 ` Junio C Hamano
2024-05-03 6:28 ` [PATCH 2/5] refs: add `exclude_patterns` parameter to `for_each_fullref_in()` Patrick Steinhardt
2024-05-03 18:44 ` Taylor Blau
2024-05-03 6:28 ` [PATCH 3/5] cocci: introduce rules to transform "refs" to pass ref store Patrick Steinhardt
2024-05-03 6:28 ` [PATCH 4/5] cocci: apply rules to rewrite callers of "refs" interfaces Patrick Steinhardt
2024-05-03 18:48 ` Taylor Blau
2024-05-03 19:20 ` Junio C Hamano
2024-05-06 6:35 ` Patrick Steinhardt
2024-05-03 6:28 ` [PATCH 5/5] refs: remove functions without ref store Patrick Steinhardt
2024-05-06 1:15 ` James Liu
2024-05-03 17:24 ` [PATCH 0/5] " Junio C Hamano
2024-05-03 17:35 ` Jeff King
2024-05-03 18:24 ` Junio C Hamano
2024-05-06 6:44 ` Patrick Steinhardt
2024-05-06 16:14 ` Junio C Hamano
2024-05-07 5:56 ` Patrick Steinhardt
2024-05-07 6:20 ` Junio C Hamano
2024-05-07 6:30 ` Patrick Steinhardt
2024-05-07 15:46 ` Junio C Hamano
2024-05-09 16:55 ` Jeff King
2024-05-10 5:54 ` Patrick Steinhardt
2024-05-03 18:58 ` Taylor Blau
2024-05-03 19:35 ` Junio C Hamano
2024-05-07 7:11 ` [PATCH v2 " Patrick Steinhardt
2024-05-07 7:11 ` Patrick Steinhardt [this message]
2024-05-07 7:11 ` [PATCH v2 2/5] refs: add `exclude_patterns` parameter to `for_each_fullref_in()` Patrick Steinhardt
2024-05-07 7:11 ` [PATCH v2 3/5] cocci: introduce rules to transform "refs" to pass ref store Patrick Steinhardt
2024-05-07 7:11 ` [PATCH v2 4/5] cocci: apply rules to rewrite callers of "refs" interfaces Patrick Steinhardt
2024-05-07 7:11 ` [PATCH v2 5/5] refs: remove functions without ref store Patrick Steinhardt
2024-05-07 17:27 ` [PATCH v2 0/5] " Taylor Blau
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=dba5df086d9dbbc2801f946abef47714b41d3750.1715065736.git.ps@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=james@jamesliu.io \
--cc=me@ttaylorr.com \
--cc=peff@peff.net \
/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).