* [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs
2026-11-03 8:49 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Okhuomon Ajayi
@ 2026-11-03 8:49 ` Okhuomon Ajayi
2026-11-03 9:45 ` Karthik Nayak
2026-11-03 8:49 ` [Outreachy PATCH v2 2/2] notes-utils: pass the repository to init_copy_notes_for_rewrite() Okhuomon Ajayi
2026-11-03 9:48 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Karthik Nayak
2 siblings, 1 reply; 10+ messages in thread
From: Okhuomon Ajayi @ 2026-11-03 8:49 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, Okhuomon Ajayi
create_notes_commit() and commit_notes() receive a repository,
but read and update the notes ref in the_repository.
Use the repository they are given.
Keep USE_THE_REPOSITORY_VARIABLE because
init_copy_notes_for_rewrite() still uses the_repository.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes-utils.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..d4606bc576 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -26,7 +26,7 @@ void create_notes_commit(struct repository *r,
if (!parents) {
/* Deduce parent commit from t->ref */
struct object_id parent_oid;
- if (!refs_read_ref(get_main_ref_store(the_repository), t->ref, &parent_oid)) {
+ if (!refs_read_ref(get_main_ref_store(r), t->ref, &parent_oid)) {
struct commit *parent = lookup_commit(r, &parent_oid);
if (repo_parse_commit(r, parent))
die("Failed to find/parse commit %s", t->ref);
@@ -61,7 +61,7 @@ void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
strbuf_insertstr(&buf, 0, "notes: ");
- refs_update_ref(get_main_ref_store(the_repository), buf.buf,
+ refs_update_ref(get_main_ref_store(r), buf.buf,
t->update_ref, &commit_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs
2026-11-03 8:49 ` [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
@ 2026-11-03 9:45 ` Karthik Nayak
2026-11-03 18:01 ` Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Karthik Nayak @ 2026-11-03 9:45 UTC (permalink / raw)
To: Okhuomon Ajayi, git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps
[-- Attachment #1: Type: text/plain, Size: 2158 bytes --]
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> create_notes_commit() and commit_notes() receive a repository,
> but read and update the notes ref in the_repository.
>
> Use the repository they are given.
>
Nit: It would also be nice to talk about why this is the same repository
and if its safe to do this swap.
Sometimes it's also useful to look at the history and argue about why it
is the way it is.
For this file, all `the_repository` usages were removed first in
1d18d7581c (notes-utils.c: remove the_repository references,
2019-01-12), then it was added back in 2e5c4758b7 (cocci: apply rules to
rewrite callers of "refs" interfaces, 2024-05-07). So seems like the
latter was an automated addition of `the_repository`.
> Keep USE_THE_REPOSITORY_VARIABLE because
> init_copy_notes_for_rewrite() still uses the_repository.
>
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> ---
> notes-utils.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/notes-utils.c b/notes-utils.c
> index 5c1c75d5b8..d4606bc576 100644
> --- a/notes-utils.c
> +++ b/notes-utils.c
> @@ -26,7 +26,7 @@ void create_notes_commit(struct repository *r,
> if (!parents) {
> /* Deduce parent commit from t->ref */
> struct object_id parent_oid;
> - if (!refs_read_ref(get_main_ref_store(the_repository), t->ref, &parent_oid)) {
> + if (!refs_read_ref(get_main_ref_store(r), t->ref, &parent_oid)) {
Here, the repository we read the reference from and the commit from
should be the same. So r == the_repository.
> struct commit *parent = lookup_commit(r, &parent_oid);
> if (repo_parse_commit(r, parent))
> die("Failed to find/parse commit %s", t->ref);
> @@ -61,7 +61,7 @@ void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
>
> create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
> strbuf_insertstr(&buf, 0, "notes: ");
> - refs_update_ref(get_main_ref_store(the_repository), buf.buf,
> + refs_update_ref(get_main_ref_store(r), buf.buf,
> t->update_ref, &commit_oid, NULL, 0,
> UPDATE_REFS_DIE_ON_ERR);
>
Similar here.
> --
> 2.56.0
The patch looks good.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs
2026-11-03 9:45 ` Karthik Nayak
@ 2026-11-03 18:01 ` Junio C Hamano
0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2026-11-03 18:01 UTC (permalink / raw)
To: Karthik Nayak
Cc: Okhuomon Ajayi, git, christian.couder, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, ps
Karthik Nayak <karthik.188@gmail.com> writes:
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
>> Keep USE_THE_REPOSITORY_VARIABLE because
>> init_copy_notes_for_rewrite() still uses the_repository.
Unfortunately, this is a highly misleading comment to leave here.
The next person would be misled into thinking that it would be just
a matter of giving a "struct repository *r" argument to that
function to lift the USE_THE_REPOSITORY_VARIABLE declaration from
there.
Looking at what <notes-utils.h> exports, the file has quite some way
to go to be free from the_repository.
* create_notes_commit() takes "struct repository *" to pretend as
if it can work with any repository, but the first function it
calls is write_notes_tree() that eventually calls into
odb_write_object() with hardcoded the_repository->objects.
* commit_notes() calls the above create_notes_commit() and shares
the same problem.
* init_copy_notes_for_rewrite(), in addition to having its own
reference to the_repository, calls load_notes_trees() that makes
calls to init_notes() that works only on the_repository.
* copy_note_for_rewrite() calls copy_note() which calls add_note(),
which eventually calls into load_subtree() that can only work
with the_repository.
In short, I think adding "struct repository *" to anything in
<notes-utils.h> is not yet a productive exercise at this point,
before cleaning up what is in the underlying things exported from
<notes.h>.
This is a tangent but there are precedents to mark the functions
that still work only on the_repository or the_hash_algo:
$ git grep 'ifdef *USE_THE' \*.h
environment.h:# ifdef USE_THE_REPOSITORY_VARIABLE
hash.h:#ifdef USE_THE_REPOSITORY_VARIABLE
hex.h:#ifdef USE_THE_REPOSITORY_VARIABLE
path.h:# ifdef USE_THE_REPOSITORY_VARIABLE
repository.h:#ifdef USE_THE_REPOSITORY_VARIABLE
Perhaps we need similar protection to forbid use of these functions
that still assume the_repository is available in this file?
notes-utils.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git c/notes-utils.h w/notes-utils.h
index c54b1fe141..1503991cf6 100644
--- c/notes-utils.h
+++ w/notes-utils.h
@@ -7,6 +7,9 @@ struct commit_list;
struct object_id;
struct repository;
+/* most of the things in notes.h still only work with the_repository */
+# ifdef USE_THE_REPOSITORY_VARIABLE
+
/*
* Create new notes commit from the given notes tree
*
@@ -52,4 +55,5 @@ void finish_copy_notes_for_rewrite(struct repository *r,
struct notes_rewrite_cfg *c,
const char *msg);
+# endif
#endif
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Outreachy PATCH v2 2/2] notes-utils: pass the repository to init_copy_notes_for_rewrite()
2026-11-03 8:49 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Okhuomon Ajayi
2026-11-03 8:49 ` [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
@ 2026-11-03 8:49 ` Okhuomon Ajayi
2026-11-03 9:48 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Karthik Nayak
2 siblings, 0 replies; 10+ messages in thread
From: Okhuomon Ajayi @ 2026-11-03 8:49 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, Okhuomon Ajayi
init_copy_notes_for_rewrite() reads the notes.rewrite* config from
the_repository, as it is not given a repository. This is the last
use of the_repository in notes-utils.c.
Add a repository parameter to it. commit_post_rewrite() in sequencer.c
already has one and passes it on. The callers in builtin/am.c and
builtin/notes.c still use the_repository, so pass that for now.
Drop USE_THE_REPOSITORY_VARIABLE, as notes-utils.c no longer uses
the_repository.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
builtin/am.c | 2 +-
builtin/notes.c | 2 +-
notes-utils.c | 7 +++----
notes-utils.h | 3 ++-
sequencer.c | 2 +-
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index e9623b8307..daa4b601b6 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -536,7 +536,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
assert(state->rebasing);
- c = init_copy_notes_for_rewrite("rebase");
+ c = init_copy_notes_for_rewrite(the_repository, "rebase");
if (!c)
return 0;
diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..20f7bb8377 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -366,7 +366,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
const char *msg = "Notes added by 'git notes copy'";
if (rewrite_cmd) {
- c = init_copy_notes_for_rewrite(rewrite_cmd);
+ c = init_copy_notes_for_rewrite(the_repository, rewrite_cmd);
if (!c)
return 0;
} else {
diff --git a/notes-utils.c b/notes-utils.c
index d4606bc576..3a3b84f79c 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
@@ -134,7 +132,8 @@ static int notes_rewrite_config(const char *k, const char *v,
}
-struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
+struct notes_rewrite_cfg *init_copy_notes_for_rewrite(struct repository *r,
+ const char *cmd)
{
struct notes_rewrite_cfg *c = xmalloc(sizeof(struct notes_rewrite_cfg));
const char *rewrite_mode_env = getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT);
@@ -162,7 +161,7 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
c->refs_from_env = 1;
string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env);
}
- repo_config(the_repository, notes_rewrite_config, c);
+ repo_config(r, notes_rewrite_config, c);
if (!c->enabled || !c->refs->nr) {
string_list_clear(c->refs, 0);
free(c->refs);
diff --git a/notes-utils.h b/notes-utils.h
index c54b1fe141..ef3c0f6732 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -45,7 +45,8 @@ struct notes_rewrite_cfg {
};
int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
-struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
+struct notes_rewrite_cfg *init_copy_notes_for_rewrite(struct repository *r,
+ const char *cmd);
int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
const struct object_id *from_obj, const struct object_id *to_obj);
void finish_copy_notes_for_rewrite(struct repository *r,
diff --git a/sequencer.c b/sequencer.c
index 508ec71792..a40243c56b 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1366,7 +1366,7 @@ void commit_post_rewrite(struct repository *r,
{
struct notes_rewrite_cfg *cfg;
- cfg = init_copy_notes_for_rewrite("amend");
+ cfg = init_copy_notes_for_rewrite(r, "amend");
if (cfg) {
/* we are amending, so old_head is not NULL */
copy_note_for_rewrite(cfg, &old_head->object.oid, new_head);
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository
2026-11-03 8:49 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Okhuomon Ajayi
2026-11-03 8:49 ` [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
2026-11-03 8:49 ` [Outreachy PATCH v2 2/2] notes-utils: pass the repository to init_copy_notes_for_rewrite() Okhuomon Ajayi
@ 2026-11-03 9:48 ` Karthik Nayak
2026-11-03 10:27 ` Patrick Steinhardt
2 siblings, 1 reply; 10+ messages in thread
From: Karthik Nayak @ 2026-11-03 9:48 UTC (permalink / raw)
To: Okhuomon Ajayi, git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps
[-- Attachment #1: Type: text/plain, Size: 641 bytes --]
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> This series removes the_repository from notes-utils.c.
>
> Changes since v1:
> - Add patch 2, which passes a repository to
> init_copy_notes_for_rewrite() and drops USE_THE_REPOSITORY_VARIABLE
> from notes-utils.c, as Patrick suggested. v1 stopped one step short
> of that.
>
> The callers in builtin/am.c and builtin/notes.c pass the_repository,
> as those files still use it everywhere. copy() in builtin/notes.c
> does receive a repo that could be passed down instead, if that is
> preferred.
>
> Thanks, Patrick, for the review.
>
Overall the patches look good to me.
[snip]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository
2026-11-03 9:48 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Karthik Nayak
@ 2026-11-03 10:27 ` Patrick Steinhardt
0 siblings, 0 replies; 10+ messages in thread
From: Patrick Steinhardt @ 2026-11-03 10:27 UTC (permalink / raw)
To: Karthik Nayak
Cc: Okhuomon Ajayi, git, christian.couder, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam
On Tue, Nov 03, 2026 at 03:48:01AM -0600, Karthik Nayak wrote:
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > This series removes the_repository from notes-utils.c.
> >
> > Changes since v1:
> > - Add patch 2, which passes a repository to
> > init_copy_notes_for_rewrite() and drops USE_THE_REPOSITORY_VARIABLE
> > from notes-utils.c, as Patrick suggested. v1 stopped one step short
> > of that.
> >
> > The callers in builtin/am.c and builtin/notes.c pass the_repository,
> > as those files still use it everywhere. copy() in builtin/notes.c
> > does receive a repo that could be passed down instead, if that is
> > preferred.
> >
> > Thanks, Patrick, for the review.
> >
>
> Overall the patches look good to me.
Agreed, the patches look good to me, too.
Patrick
^ permalink raw reply [flat|nested] 10+ messages in thread