# [Outreachy PATCH] notes-utils: use the passed repository for notes refs

10 messages from 2026-10-31 to 2026-11-03. Participants: Okhuomon Ajayi, Patrick Steinhardt, Karthik Nayak, Junio C Hamano.
Thread: https://gitlist.dev/t/66725

## Okhuomon Ajayi, 2026-10-31 10:45

Subject: [Outreachy PATCH] notes-utils: use the passed repository for notes refs
Message-ID: <20261031104526.46711-1-okhuomonajayi54@gmail.com>
URL: https://gitlist.dev/e/20261031104526.46711-1-okhuomonajayi54%40gmail.com

```
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);
 

base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
-- 
2.56.0



```

## Patrick Steinhardt, 2026-11-02 11:01

Subject: Re: [Outreachy PATCH] notes-utils: use the passed repository for notes refs
Message-ID: <auhtiZ86trLamccS@pks.im>
URL: https://gitlist.dev/e/auhtiZ86trLamccS%40pks.im
In-Reply-To: <20261031104526.46711-1-okhuomonajayi54@gmail.com>

```
On Sat, Oct 31, 2026 at 11:45:26AM +0100, Okhuomon Ajayi wrote:
> 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.

I don't quite understand patches like this. They are _so_ close to
getting rid of `USE_THE_REPOSITORY_VARIABLE`, but then they just skip on
the final change that would make them work. I've already asked about
this on one of your preceding patches.

Also, could you maybe reduce the frequency a bit with which you send new
topics? There's a ton of in-flight patch series by you in this vicinity,
and it gets a bit overwhelming. May I ask you to maybe batch related
patches into bigger series (maybe 5-10 commits) so that the reviewer can
focus on way fewer patch series overall, and then have less series in
flight at the same point in time?

Thanks!

Patrick


```

## Okhuomon Ajayi, 2026-11-02 11:10

Subject: Re: [Outreachy PATCH] notes-utils: use the passed repository for notes refs
Message-ID: <CAFpMFfCkMNvFWOUsDJgRkhadd=jZX=ByavgsiYiCCuAsxiFNFA@mail.gmail.com>
URL: https://gitlist.dev/e/CAFpMFfCkMNvFWOUsDJgRkhadd%3DjZX%3DByavgsiYiCCuAsxiFNFA%40mail.gmail.com
In-Reply-To: <auhtiZ86trLamccS@pks.im>

```
On Mon, Nov 2, 2026 at 12:01 PM Patrick Steinhardt <ps@pks.im> wrote:
> I don't quite understand patches like this. They are _so_ close to
> getting rid of `USE_THE_REPOSITORY_VARIABLE`, but then they just skip on
> the final change that would make them work. I've already asked about
> this on one of your preceding patches.

Thanks, Patrick. You're right, I should have gone the full way here
after your comment on bundle-uri.

I'll send a v2 that also passes the repository to
init_copy_notes_for_rewrite() and updates its callers, so that
notes-utils.c can drop USE_THE_REPOSITORY_VARIABLE.

> Also, could you maybe reduce the frequency a bit with which you send new
> topics? There's a ton of in-flight patch series by you in this vicinity,
> and it gets a bit overwhelming. May I ask you to maybe batch related
> patches into bigger series (maybe 5-10 commits) so that the reviewer can
> focus on way fewer patch series overall, and then have less series in
> flight at the same point in time?

Sorry about that. I'll stop sending new topics for now, and batch
related conversions into one series from now on.

Thanks,
Okhuomon

On Mon, Nov 2, 2026 at 12:01 PM Patrick Steinhardt <ps@pks.im> wrote:
>
> On Sat, Oct 31, 2026 at 11:45:26AM +0100, Okhuomon Ajayi wrote:
> > 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.
>
> I don't quite understand patches like this. They are _so_ close to
> getting rid of `USE_THE_REPOSITORY_VARIABLE`, but then they just skip on
> the final change that would make them work. I've already asked about
> this on one of your preceding patches.
>
> Also, could you maybe reduce the frequency a bit with which you send new
> topics? There's a ton of in-flight patch series by you in this vicinity,
> and it gets a bit overwhelming. May I ask you to maybe batch related
> patches into bigger series (maybe 5-10 commits) so that the reviewer can
> focus on way fewer patch series overall, and then have less series in
> flight at the same point in time?
>
> Thanks!
>
> Patrick


```

## Okhuomon Ajayi, 2026-11-03 08:49

Subject: [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository
Message-ID: <20261103084930.15532-1-okhuomonajayi54@gmail.com>
URL: https://gitlist.dev/e/20261103084930.15532-1-okhuomonajayi54%40gmail.com
In-Reply-To: <20261031104526.46711-1-okhuomonajayi54@gmail.com>

```
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.

Okhuomon Ajayi (2):
  notes-utils: use the passed repository for notes refs
  notes-utils: pass the repository to init_copy_notes_for_rewrite()

 builtin/am.c    |  2 +-
 builtin/notes.c |  2 +-
 notes-utils.c   | 11 +++++------
 notes-utils.h   |  3 ++-
 sequencer.c     |  2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)


base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
-- 
2.56.0



```

## Okhuomon Ajayi, 2026-11-03 08:49

Subject: [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs
Message-ID: <20261103084930.15532-2-okhuomonajayi54@gmail.com>
URL: https://gitlist.dev/e/20261103084930.15532-2-okhuomonajayi54%40gmail.com
In-Reply-To: <20261103084930.15532-1-okhuomonajayi54@gmail.com>

```
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



```

## Okhuomon Ajayi, 2026-11-03 08:49

Subject: [Outreachy PATCH v2 2/2] notes-utils: pass the repository to init_copy_notes_for_rewrite()
Message-ID: <20261103084930.15532-3-okhuomonajayi54@gmail.com>
URL: https://gitlist.dev/e/20261103084930.15532-3-okhuomonajayi54%40gmail.com
In-Reply-To: <20261103084930.15532-1-okhuomonajayi54@gmail.com>

```
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



```

## Karthik Nayak, 2026-11-03 09:45

Subject: Re: [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs
Message-ID: <CAOLa=ZSPHDWAUmqUev9PRdEB03cUW=NWrbXHjRyma6yUmV7Yng@mail.gmail.com>
URL: https://gitlist.dev/e/CAOLa%3DZSPHDWAUmqUev9PRdEB03cUW%3DNWrbXHjRyma6yUmV7Yng%40mail.gmail.com
In-Reply-To: <20261103084930.15532-2-okhuomonajayi54@gmail.com>

```
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.

```

## Karthik Nayak, 2026-11-03 09:48

Subject: Re: [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository
Message-ID: <CAOLa=ZTAEVcKj-Y5QCGsAFAMUSh665E1fmQrEnuuufTLLbn3Wg@mail.gmail.com>
URL: https://gitlist.dev/e/CAOLa%3DZTAEVcKj-Y5QCGsAFAMUSh665E1fmQrEnuuufTLLbn3Wg%40mail.gmail.com
In-Reply-To: <20261103084930.15532-1-okhuomonajayi54@gmail.com>

```
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]

```

## Patrick Steinhardt, 2026-11-03 10:27

Subject: Re: [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository
Message-ID: <aum29zvhcsj41yHz@pks.im>
URL: https://gitlist.dev/e/aum29zvhcsj41yHz%40pks.im
In-Reply-To: <CAOLa=ZTAEVcKj-Y5QCGsAFAMUSh665E1fmQrEnuuufTLLbn3Wg@mail.gmail.com>

```
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


```

## Junio C Hamano, 2026-11-03 18:01

Subject: Re: [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs
Message-ID: <xmqqjymt94l3.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqjymt94l3.fsf%40gitster.g
In-Reply-To: <CAOLa=ZSPHDWAUmqUev9PRdEB03cUW=NWrbXHjRyma6yUmV7Yng@mail.gmail.com>

```
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


```
