* [Outreachy PATCH] notes-utils: use the passed repository for notes refs
@ 2026-10-31 10:45 Okhuomon Ajayi
2026-11-02 11:01 ` Patrick Steinhardt
2026-11-03 8:49 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Okhuomon Ajayi
0 siblings, 2 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-10-31 10:45 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, 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);
base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
--
2.56.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [Outreachy PATCH] notes-utils: use the passed repository for notes refs
2026-10-31 10:45 [Outreachy PATCH] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
@ 2026-11-02 11:01 ` Patrick Steinhardt
2026-11-02 11:10 ` Okhuomon Ajayi
2026-11-03 8:49 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Okhuomon Ajayi
1 sibling, 1 reply; 21+ messages in thread
From: Patrick Steinhardt @ 2026-11-02 11:01 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
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
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Outreachy PATCH] notes-utils: use the passed repository for notes refs
2026-11-02 11:01 ` Patrick Steinhardt
@ 2026-11-02 11:10 ` Okhuomon Ajayi
0 siblings, 0 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-02 11:10 UTC (permalink / raw)
To: Patrick Steinhardt
Cc: git, christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
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
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository
2026-10-31 10:45 [Outreachy PATCH] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
2026-11-02 11:01 ` Patrick Steinhardt
@ 2026-11-03 8:49 ` Okhuomon Ajayi
2026-11-03 8:49 ` [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
` (2 more replies)
1 sibling, 3 replies; 21+ 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
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
^ permalink raw reply [flat|nested] 21+ messages in thread
* [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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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
2026-11-05 7:43 ` [Outreachy PATCH] notes-utils: hide functions that still need the_repository Okhuomon Ajayi
0 siblings, 1 reply; 21+ 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] 21+ messages in thread
* [Outreachy PATCH] notes-utils: hide functions that still need the_repository
2026-11-03 18:01 ` Junio C Hamano
@ 2026-11-05 7:43 ` Okhuomon Ajayi
2026-11-05 14:22 ` Patrick Steinhardt
0 siblings, 1 reply; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 7:43 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, karthik.188, ps, Okhuomon Ajayi, Junio C Hamano
The helpers declared in notes-utils.h call into notes.c, which
still only works on the_repository. write_notes_tree() writes
its tree into the_repository->objects.
Passing a repository argument does not make these helpers work
on another repository yet. Guard them with
USE_THE_REPOSITORY_VARIABLE, as environment.h and repository.h
do, so code that has dropped the global cannot call them by
mistake.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
This replaces my notes-utils series [1], which I'm dropping after
Junio pointed out that the functions underneath, in notes.c, still
only work on the_repository.
The guard also hides the enum and struct that notes-merge.h uses.
All current users define USE_THE_REPOSITORY_VARIABLE, so nothing
breaks today.
[1] https://lore.kernel.org/git/20261103084930.15532-1-okhuomonajayi54@gmail.com/
notes-utils.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/notes-utils.h b/notes-utils.h
index c54b1fe141..1503991cf6 100644
--- a/notes-utils.h
+++ b/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
base-commit: 0ffa3e35c7c82ab8d0de226149fb03b3f7674d05
--
2.56.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [Outreachy PATCH] notes-utils: hide functions that still need the_repository
2026-11-05 7:43 ` [Outreachy PATCH] notes-utils: hide functions that still need the_repository Okhuomon Ajayi
@ 2026-11-05 14:22 ` Patrick Steinhardt
2026-11-05 14:47 ` Okhuomon Ajayi
2026-11-05 17:56 ` Junio C Hamano
0 siblings, 2 replies; 21+ messages in thread
From: Patrick Steinhardt @ 2026-11-05 14:22 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, karthik.188, Junio C Hamano
On Thu, Nov 05, 2026 at 08:43:33AM +0100, Okhuomon Ajayi wrote:
> The helpers declared in notes-utils.h call into notes.c, which
> still only works on the_repository. write_notes_tree() writes
> its tree into the_repository->objects.
>
> Passing a repository argument does not make these helpers work
> on another repository yet. Guard them with
> USE_THE_REPOSITORY_VARIABLE, as environment.h and repository.h
> do, so code that has dropped the global cannot call them by
> mistake.
>
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> ---
> This replaces my notes-utils series [1], which I'm dropping after
> Junio pointed out that the functions underneath, in notes.c, still
> only work on the_repository.
>
> The guard also hides the enum and struct that notes-merge.h uses.
> All current users define USE_THE_REPOSITORY_VARIABLE, so nothing
> breaks today.
Hmm. Wouldn't the better course of actions be to instead fix "notes.c"?
It feels a bit weird to me to just make the whole header a pointless
include, and we don't do that for other headers, either. We have tons of
subsystems that still depend on `the_repository`, so what makes
"notes-utils.h" so special that we need to drop all of its functions?
What we indeed do sometimes is to mark some very small subset of
functions in a header as depending on `the_repository` in case the blast
radius of fixing all users is simply too big to do it in a single patch
series.
So I'm not sure whether this patch goes into a sensible direction.
Patrick
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Outreachy PATCH] notes-utils: hide functions that still need the_repository
2026-11-05 14:22 ` Patrick Steinhardt
@ 2026-11-05 14:47 ` Okhuomon Ajayi
2026-11-05 17:56 ` Junio C Hamano
1 sibling, 0 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 14:47 UTC (permalink / raw)
To: Patrick Steinhardt
Cc: git, christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, karthik.188, Junio C Hamano
On Thu, Nov 5, 2026 at 3:22 PM Patrick Steinhardt <ps@pks.im> wrote:
> Hmm. Wouldn't the better course of actions be to instead fix "notes.c"?
Fair point. I'll drop this patch and instead make notes.c to use
the repository stored in struct notes_tree, then remove
USE_THE_REPOSITORY_VARIABLE from notes-utils.c in the same series.
I'll send that as one series rather than several small topics.
Thanks,
Okhuomon
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Outreachy PATCH] notes-utils: hide functions that still need the_repository
2026-11-05 14:22 ` Patrick Steinhardt
2026-11-05 14:47 ` Okhuomon Ajayi
@ 2026-11-05 17:56 ` Junio C Hamano
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
1 sibling, 1 reply; 21+ messages in thread
From: Junio C Hamano @ 2026-11-05 17:56 UTC (permalink / raw)
To: Patrick Steinhardt
Cc: Okhuomon Ajayi, git, christian.couder, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, karthik.188
Patrick Steinhardt <ps@pks.im> writes:
> Hmm. Wouldn't the better course of actions be to instead fix "notes.c"?
> It feels a bit weird to me to just make the whole header a pointless
> include, and we don't do that for other headers, either. We have tons of
> subsystems that still depend on `the_repository`, so what makes
> "notes-utils.h" so special that we need to drop all of its functions?
Because it invites people into removing the_repository from
notes-utils.c and think they are done, when they call helpers from
notes.c liberally if we do not.
> What we indeed do sometimes is to mark some very small subset of
> functions in a header as depending on `the_repository` in case the blast
> radius of fixing all users is simply too big to do it in a single patch
> series.
Absolutely, in the ideal world.
In this case, however, I initialy thought there was only just one or
two functions that depend on the_repository, but it turns out that
everything calls things that only work with the_repository from
notes.c and that is how this patch ended up covering almost all of
this header X-<.
So...
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree
2026-11-05 17:56 ` Junio C Hamano
@ 2026-11-05 20:33 ` Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 1/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
` (5 more replies)
0 siblings, 6 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 20:33 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, gitster, karthik.188
Patrick suggested fixing notes.c instead of hiding notes-utils.h [1],
and Junio pointed out that removing the_repository from notes-utils.c
is not enough while the notes.c helpers it calls still use it [2].
This series stores the repository in struct notes_tree when the tree
is initialized, and uses it in notes.c wherever a tree is available:
reading and writing notes, pruning, and the combine_notes callbacks.
The ref glob helpers take the repository as an argument. With that,
notes-utils.c can use the repository it is given and drop
USE_THE_REPOSITORY_VARIABLE.
notes.c itself still needs the_repository for the display notes
code (load_display_notes() and the default notes tree),
expand_loose_notes_ref(), and a few uses of the_hash_algo for
sizes. Most callers outside notes.c still pass the_repository.
This replaces my patch "notes-utils: hide functions that still need
the_repository" and the earlier notes-utils series.
[1] https://lore.kernel.org/git/auyRGpaHb5rdVP0d@pks.im/
[2] https://lore.kernel.org/git/xmqq1p8zw49g.fsf@gitster.g/
Okhuomon Ajayi (6):
notes: store the repository in struct notes_tree
notes: use the tree's repository when reading notes
notes: use the tree's repository when writing and pruning
notes: pass the repository to the ref glob helpers
notes: pass the repository to the combine_notes callbacks
notes-utils: use the given repository
builtin/am.c | 2 +-
builtin/notes.c | 10 +--
notes-cache.c | 3 +-
notes-utils.c | 20 +++---
notes-utils.h | 4 +-
notes.c | 160 ++++++++++++++++++++++++++++--------------------
notes.h | 38 +++++++-----
sequencer.c | 2 +-
8 files changed, 141 insertions(+), 98 deletions(-)
base-commit: 0ffa3e35c7c82ab8d0de226149fb03b3f7674d05
--
2.56.0
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Outreachy PATCH 1/6] notes: store the repository in struct notes_tree
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
@ 2026-11-05 20:33 ` Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 2/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
` (4 subsequent siblings)
5 siblings, 0 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 20:33 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, gitster, karthik.188
A notes tree is always read from one repository, but the tree
does not record which one. Later code has to fall back to
the_repository.
Store the repository on the tree. init_notes() and
load_notes_trees() take it as their first argument, and
init_notes() saves it in t->repo. notes_cache_init() passes
the repository it was given. Other callers pass
the_repository for now.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
builtin/notes.c | 8 +++++---
notes-cache.c | 3 ++-
notes-utils.c | 3 ++-
notes.c | 26 +++++++++++++++-----------
notes.h | 9 ++++++---
5 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..7e7dff6672 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -370,7 +370,8 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
if (!c)
return 0;
} else {
- init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
+ init_notes(the_repository, NULL, NULL, NULL,
+ NOTES_INIT_WRITABLE);
t = &default_notes_tree;
}
@@ -420,7 +421,7 @@ static struct notes_tree *init_notes_check(const char *subcommand,
{
struct notes_tree *t;
const char *ref;
- init_notes(NULL, NULL, NULL, flags);
+ init_notes(the_repository, NULL, NULL, NULL, flags);
t = &default_notes_tree;
ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref;
@@ -841,7 +842,8 @@ static int merge_commit(struct notes_merge_options *o)
else
oidclr(&parent_oid, the_repository->hash_algo);
- init_notes(&t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
+ init_notes(the_repository, &t, "NOTES_MERGE_PARTIAL",
+ combine_notes_overwrite, 0);
o->local_ref = local_ref_to_free =
refs_resolve_refdup(get_main_ref_store(the_repository),
diff --git a/notes-cache.c b/notes-cache.c
index 74cef802bd..7c35ebe64b 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -50,7 +50,8 @@ void notes_cache_init(struct repository *r, struct notes_cache *c,
strbuf_addf(&ref, "refs/notes/%s", name);
if (!notes_cache_match_validity(r, ref.buf, validity))
flags |= NOTES_INIT_EMPTY;
- init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
+ init_notes(r, &c->tree, ref.buf,
+ combine_notes_overwrite, flags);
strbuf_release(&ref);
}
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..404e9a5eea 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -169,7 +169,8 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
free(c);
return NULL;
}
- c->trees = load_notes_trees(c->refs, NOTES_INIT_WRITABLE);
+ c->trees = load_notes_trees(the_repository, c->refs,
+ NOTES_INIT_WRITABLE);
string_list_clear(c->refs, 0);
free(c->refs);
return c;
diff --git a/notes.c b/notes.c
index ec9c2cb150..4ab3d45d7c 100644
--- a/notes.c
+++ b/notes.c
@@ -1012,8 +1012,9 @@ char *default_notes_ref(struct repository *repo)
return notes_ref;
}
-void init_notes(struct notes_tree *t, const char *notes_ref,
- combine_notes_fn combine_notes, int flags)
+void init_notes(struct repository *r, struct notes_tree *t,
+ const char *notes_ref, combine_notes_fn combine_notes,
+ int flags)
{
struct object_id oid, object_oid;
unsigned short mode;
@@ -1025,7 +1026,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
assert(!t->initialized);
if (!notes_ref)
- notes_ref = to_free = default_notes_ref(the_repository);
+ notes_ref = to_free = default_notes_ref(r);
update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref));
if (!combine_notes)
@@ -1034,6 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
t->first_non_note = NULL;
t->prev_non_note = NULL;
+ t->repo = r;
t->ref = xstrdup(notes_ref);
t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL;
t->combine_notes = combine_notes;
@@ -1041,15 +1043,15 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
t->dirty = 0;
if (flags & NOTES_INIT_EMPTY ||
- repo_get_oid_treeish(the_repository, notes_ref, &object_oid))
+ repo_get_oid_treeish(r, notes_ref, &object_oid))
goto out;
- if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid))
+ if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(r), notes_ref, &object_oid))
die("Cannot use notes ref %s", notes_ref);
- if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
+ if (get_tree_entry(r, &object_oid, "", &oid, &mode))
die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid));
- oidclr(&root_tree.key_oid, the_repository->hash_algo);
+ oidclr(&root_tree.key_oid, r->hash_algo);
oidcpy(&root_tree.val_oid, &oid);
load_subtree(t, &root_tree, t->root, 0);
@@ -1057,7 +1059,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
free(to_free);
}
-struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
+struct notes_tree **load_notes_trees(struct repository *r,
+ struct string_list *refs, int flags)
{
struct string_list_item *item;
int counter = 0;
@@ -1065,7 +1068,7 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
ALLOC_ARRAY(trees, refs->nr + 1);
for_each_string_list_item(item, refs) {
struct notes_tree *t = xcalloc(1, sizeof(struct notes_tree));
- init_notes(t, item->string, combine_notes_ignore, flags);
+ init_notes(r, t, item->string, combine_notes_ignore, flags);
trees[counter++] = t;
}
trees[counter] = NULL;
@@ -1136,7 +1139,8 @@ void load_display_notes(struct display_notes_opt *opt)
item->string);
}
- display_notes_trees = load_notes_trees(&display_notes_refs, 0);
+ display_notes_trees = load_notes_trees(the_repository,
+ &display_notes_refs, 0);
string_list_clear(&display_notes_refs, 0);
}
@@ -1290,7 +1294,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!t)
t = &default_notes_tree;
if (!t->initialized)
- init_notes(t, NULL, NULL, 0);
+ init_notes(the_repository, t, NULL, NULL, 0);
oid = get_note(t, object_oid);
if (!oid)
diff --git a/notes.h b/notes.h
index 6dc6d7b265..0f50020816 100644
--- a/notes.h
+++ b/notes.h
@@ -50,6 +50,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
* simultaneously.
*/
extern struct notes_tree {
+ struct repository *repo;
struct int_node *root;
struct non_note *first_non_note, *prev_non_note;
char *ref;
@@ -107,8 +108,9 @@ char *default_notes_ref(struct repository *repo);
* Precondition: The notes_tree structure is zeroed (this can be achieved with
* memset(t, 0, sizeof(struct notes_tree)))
*/
-void init_notes(struct notes_tree *t, const char *notes_ref,
- combine_notes_fn combine_notes, int flags);
+void init_notes(struct repository *r, struct notes_tree *t,
+ const char *notes_ref, combine_notes_fn combine_notes,
+ int flags);
/*
* Add the given note object to the given notes_tree structure
@@ -319,7 +321,8 @@ void format_display_notes(const struct object_id *object_oid,
* Load the notes tree from each ref listed in 'refs'. The output is
* an array of notes_tree*, terminated by a NULL.
*/
-struct notes_tree **load_notes_trees(struct string_list *refs, int flags);
+struct notes_tree **load_notes_trees(struct repository *r,
+ struct string_list *refs, int flags);
/*
* Add all refs that match 'glob' to the 'list'.
--
2.56.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Outreachy PATCH 2/6] notes: use the tree's repository when reading notes
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 1/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
@ 2026-11-05 20:33 ` Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 3/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
` (3 subsequent siblings)
5 siblings, 0 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 20:33 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, gitster, karthik.188
note_tree_find(), add_non_note(), load_subtree(), remove_note()
and format_note() already have the notes tree, but still read
objects and hash algorithms from the_repository.
Read them from t->repo, the repository stored on the tree.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/notes.c b/notes.c
index 4ab3d45d7c..5c2e8815f8 100644
--- a/notes.c
+++ b/notes.c
@@ -153,7 +153,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
void **p = note_tree_search(t, &tree, &n, key_sha1);
if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
- if (hasheq(key_sha1, l->key_oid.hash, the_repository->hash_algo))
+ if (hasheq(key_sha1, l->key_oid.hash, t->repo->hash_algo))
return l;
}
return NULL;
@@ -357,7 +357,7 @@ static void add_non_note(struct notes_tree *t, char *path,
n->next = NULL;
n->path = path;
n->mode = mode;
- oidread(&n->oid, sha1, the_repository->hash_algo);
+ oidread(&n->oid, sha1, t->repo->hash_algo);
t->prev_non_note = n;
if (!t->first_non_note) {
@@ -402,9 +402,9 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
void *buf;
struct tree_desc desc;
struct name_entry entry;
- const unsigned hashsz = the_hash_algo->rawsz;
+ const unsigned hashsz = t->repo->hash_algo->rawsz;
- buf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);
+ buf = fill_tree_descriptor(t->repo, &desc, &subtree->val_oid);
if (!buf)
die("Could not read %s for notes-index",
oid_to_hex(&subtree->val_oid));
@@ -462,8 +462,8 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
CALLOC_ARRAY(l, 1);
oidcpy(&l->key_oid, &object_oid);
oidcpy(&l->val_oid, &entry.oid);
- oid_set_algo(&l->key_oid, the_hash_algo);
- oid_set_algo(&l->val_oid, the_hash_algo);
+ oid_set_algo(&l->key_oid, t->repo->hash_algo);
+ oid_set_algo(&l->val_oid, t->repo->hash_algo);
if (note_tree_insert(t, node, n, l, type,
combine_notes_concatenate))
die("Failed to load %s %s into notes tree "
@@ -493,7 +493,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
strbuf_addch(&non_note_path, '/');
}
strbuf_addstr(&non_note_path, entry.path);
- oid_set_algo(&entry.oid, the_hash_algo);
+ oid_set_algo(&entry.oid, t->repo->hash_algo);
add_non_note(t, strbuf_detach(&non_note_path, NULL),
entry.mode, entry.oid.hash);
}
@@ -1168,8 +1168,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
if (!t)
t = &default_notes_tree;
assert(t->initialized);
- oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
- oidclr(&l.val_oid, the_repository->hash_algo);
+ oidread(&l.key_oid, object_sha1, t->repo->hash_algo);
+ oidclr(&l.val_oid, t->repo->hash_algo);
note_tree_remove(t, t->root, 0, &l);
if (is_null_oid(&l.val_oid)) /* no note was removed */
return 1;
@@ -1300,7 +1300,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid)
return;
- if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+ if (!(msg = odb_read_object(t->repo->objects, oid, &type, &msglen)) ||
type != OBJ_BLOB) {
free(msg);
return;
--
2.56.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Outreachy PATCH 3/6] notes: use the tree's repository when writing and pruning
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 1/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 2/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
@ 2026-11-05 20:33 ` Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 4/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
` (2 subsequent siblings)
5 siblings, 0 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 20:33 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, gitster, karthik.188
write_notes_tree() writes the notes tree into the_repository,
and prune_notes() looks for missing objects there too. Both
already have the notes tree.
Write through t->repo. tree_write_stack_finish_subtree() takes
the repository, passed down from the tree. prune_notes() hands
the repository to its callback in a small struct.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 59 ++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 35 insertions(+), 24 deletions(-)
diff --git a/notes.c b/notes.c
index 5c2e8815f8..c83bcc29ad 100644
--- a/notes.c
+++ b/notes.c
@@ -673,16 +673,17 @@ static void tree_write_stack_init_subtree(struct tree_write_stack *tws,
tws->path[1] = path[1];
}
-static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
+static int tree_write_stack_finish_subtree(struct repository *r,
+ struct tree_write_stack *tws)
{
int ret;
struct tree_write_stack *n = tws->next;
struct object_id s;
if (n) {
- ret = tree_write_stack_finish_subtree(n);
+ ret = tree_write_stack_finish_subtree(r, n);
if (ret)
return ret;
- ret = odb_write_object(the_repository->objects, n->buf.buf,
+ ret = odb_write_object(r->objects, n->buf.buf,
n->buf.len, OBJ_TREE, &s);
if (ret)
return ret;
@@ -695,9 +696,10 @@ static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
return 0;
}
-static int write_each_note_helper(struct tree_write_stack *tws,
- const char *path, unsigned int mode,
- const struct object_id *oid)
+static int write_each_note_helper(struct repository *r,
+ struct tree_write_stack *tws,
+ const char *path, unsigned int mode,
+ const struct object_id *oid)
{
size_t path_len = strlen(path);
unsigned int n = 0;
@@ -711,7 +713,7 @@ static int write_each_note_helper(struct tree_write_stack *tws,
}
/* tws point to last matching tree_write_stack entry */
- ret = tree_write_stack_finish_subtree(tws);
+ ret = tree_write_stack_finish_subtree(r, tws);
if (ret)
return ret;
@@ -733,6 +735,7 @@ static int write_each_note_helper(struct tree_write_stack *tws,
}
struct write_each_note_data {
+ struct repository *repo;
struct tree_write_stack *root;
struct non_note **nn_list;
struct non_note *nn_prev;
@@ -748,8 +751,8 @@ static int write_each_non_note_until(const char *note_path,
if (note_path && cmp == 0)
; /* do nothing, prefer note to non-note */
else {
- ret = write_each_note_helper(d->root, n->path, n->mode,
- &n->oid);
+ ret = write_each_note_helper(d->repo, d->root, n->path,
+ n->mode, &n->oid);
if (ret)
return ret;
}
@@ -779,7 +782,8 @@ static int write_each_note(const struct object_id *object_oid UNUSED,
/* Weave non-note entries into note entries */
return write_each_non_note_until(note_path, d) ||
- write_each_note_helper(d->root, note_path, mode, note_oid);
+ write_each_note_helper(d->repo, d->root, note_path, mode,
+ note_oid);
}
struct note_delete_list {
@@ -787,23 +791,28 @@ struct note_delete_list {
const unsigned char *sha1;
};
+struct prune_notes_data {
+ struct repository *repo;
+ struct note_delete_list *list;
+};
+
static int prune_notes_helper(const struct object_id *object_oid,
const struct object_id *note_oid UNUSED,
char *note_path UNUSED,
void *cb_data)
{
- struct note_delete_list **l = (struct note_delete_list **) cb_data;
+ struct prune_notes_data *d = cb_data;
struct note_delete_list *n;
- if (odb_has_object(the_repository->objects, object_oid,
+ if (odb_has_object(d->repo->objects, object_oid,
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))
return 0; /* nothing to do for this note */
/* failed to find object => prune this note */
n = (struct note_delete_list *) xmalloc(sizeof(*n));
- n->next = *l;
+ n->next = d->list;
n->sha1 = object_oid->hash;
- *l = n;
+ d->list = n;
return 0;
}
@@ -1213,6 +1222,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
root.next = NULL; /* last forward entry in list is grounded */
strbuf_init(&root.buf, 256 * (32 + the_hash_algo->hexsz)); /* assume 256 entries */
root.path[0] = root.path[1] = '\0';
+ cb_data.repo = t->repo;
cb_data.root = &root;
cb_data.nn_list = &(t->first_non_note);
cb_data.nn_prev = NULL;
@@ -1222,8 +1232,8 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
FOR_EACH_NOTE_YIELD_SUBTREES;
ret = for_each_note(t, flags, write_each_note, &cb_data) ||
write_each_non_note_until(NULL, &cb_data) ||
- tree_write_stack_finish_subtree(&root) ||
- odb_write_object(the_repository->objects, root.buf.buf,
+ tree_write_stack_finish_subtree(t->repo, &root) ||
+ odb_write_object(t->repo->objects, root.buf.buf,
root.buf.len, OBJ_TREE, result);
strbuf_release(&root.buf);
return ret;
@@ -1231,25 +1241,26 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
void prune_notes(struct notes_tree *t, int flags)
{
- struct note_delete_list *l = NULL;
+ struct prune_notes_data d = { 0 };
if (!t)
t = &default_notes_tree;
assert(t->initialized);
- for_each_note(t, 0, prune_notes_helper, &l);
+ d.repo = t->repo;
+ for_each_note(t, 0, prune_notes_helper, &d);
- while (l) {
+ while (d.list) {
struct note_delete_list *next;
if (flags & NOTES_PRUNE_VERBOSE)
- printf("%s\n", hash_to_hex(l->sha1));
+ printf("%s\n", hash_to_hex(d.list->sha1));
if (!(flags & NOTES_PRUNE_DRYRUN))
- remove_note(t, l->sha1);
+ remove_note(t, d.list->sha1);
- next = l->next;
- free(l);
- l = next;
+ next = d.list->next;
+ free(d.list);
+ d.list = next;
}
}
--
2.56.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Outreachy PATCH 4/6] notes: pass the repository to the ref glob helpers
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
` (2 preceding siblings ...)
2026-11-05 20:33 ` [Outreachy PATCH 3/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
@ 2026-11-05 20:33 ` Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 6/6] notes-utils: use the given repository Okhuomon Ajayi
5 siblings, 0 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 20:33 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, gitster, karthik.188
string_list_add_refs_by_glob() and
string_list_add_refs_from_colon_sep() walk refs in
the_repository. The caller already knows which repository
that is.
Take the repository as their first argument. Callers pass
the_repository for now.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes-utils.c | 6 ++++--
notes.c | 21 +++++++++++++--------
notes.h | 6 ++++--
3 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/notes-utils.c b/notes-utils.c
index 404e9a5eea..70c619269e 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -123,7 +123,8 @@ static int notes_rewrite_config(const char *k, const char *v,
/* note that a refs/ prefix is implied in the
* underlying for_each_glob_ref */
if (starts_with(v, "refs/notes/"))
- string_list_add_refs_by_glob(c->refs, v);
+ string_list_add_refs_by_glob(the_repository,
+ c->refs, v);
else
warning(_("Refusing to rewrite notes in %s"
" (outside of refs/notes/)"), v);
@@ -160,7 +161,8 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
}
if (rewrite_refs_env) {
c->refs_from_env = 1;
- string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env);
+ string_list_add_refs_from_colon_sep(the_repository, c->refs,
+ rewrite_refs_env);
}
repo_config(the_repository, notes_rewrite_config, c);
if (!c->enabled || !c->refs->nr) {
diff --git a/notes.c b/notes.c
index c83bcc29ad..cff63a4410 100644
--- a/notes.c
+++ b/notes.c
@@ -958,25 +958,27 @@ static int string_list_add_one_ref(const struct reference *ref, void *cb)
/*
* The list argument must have strdup_strings set on it.
*/
-void string_list_add_refs_by_glob(struct string_list *list, const char *glob)
+void string_list_add_refs_by_glob(struct repository *r,
+ struct string_list *list, const char *glob)
{
assert(list->strdup_strings);
if (has_glob_specials(glob)) {
struct refs_for_each_ref_options opts = {
.pattern = glob,
};
- refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ refs_for_each_ref_ext(get_main_ref_store(r),
string_list_add_one_ref, list, &opts);
} else {
struct object_id oid;
- if (repo_get_oid(the_repository, glob, &oid))
+ if (repo_get_oid(r, glob, &oid))
warning("notes ref %s is invalid", glob);
if (!unsorted_string_list_has_string(list, glob))
string_list_append(list, glob);
}
}
-void string_list_add_refs_from_colon_sep(struct string_list *list,
+void string_list_add_refs_from_colon_sep(struct repository *r,
+ struct string_list *list,
const char *globs)
{
struct string_list split = STRING_LIST_INIT_NODUP;
@@ -987,7 +989,7 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
STRING_LIST_SPLIT_NONEMPTY);
for (i = 0; i < split.nr; i++)
- string_list_add_refs_by_glob(list, split.items[i].string);
+ string_list_add_refs_by_glob(r, list, split.items[i].string);
string_list_clear(&split, 0);
free(globs_copy);
@@ -1002,7 +1004,8 @@ static int notes_display_config(const char *k, const char *v,
if (*load_refs && !strcmp(k, "notes.displayref")) {
if (!v)
return config_error_nonbool(k);
- string_list_add_refs_by_glob(&display_notes_refs, v);
+ string_list_add_refs_by_glob(the_repository,
+ &display_notes_refs, v);
}
return 0;
@@ -1132,7 +1135,8 @@ void load_display_notes(struct display_notes_opt *opt)
string_list_append_nodup(&display_notes_refs, default_notes_ref(the_repository));
display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
if (display_ref_env) {
- string_list_add_refs_from_colon_sep(&display_notes_refs,
+ string_list_add_refs_from_colon_sep(the_repository,
+ &display_notes_refs,
display_ref_env);
load_config_refs = 0;
} else
@@ -1144,7 +1148,8 @@ void load_display_notes(struct display_notes_opt *opt)
if (opt) {
struct string_list_item *item;
for_each_string_list_item(item, &opt->extra_notes_refs)
- string_list_add_refs_by_glob(&display_notes_refs,
+ string_list_add_refs_by_glob(the_repository,
+ &display_notes_refs,
item->string);
}
diff --git a/notes.h b/notes.h
index 0f50020816..b571ecede4 100644
--- a/notes.h
+++ b/notes.h
@@ -327,14 +327,16 @@ struct notes_tree **load_notes_trees(struct repository *r,
/*
* Add all refs that match 'glob' to the 'list'.
*/
-void string_list_add_refs_by_glob(struct string_list *list, const char *glob);
+void string_list_add_refs_by_glob(struct repository *r,
+ struct string_list *list, const char *glob);
/*
* Add all refs from a colon-separated glob list 'globs' to the end of
* 'list'. Empty components are ignored. This helper is used to
* parse GIT_NOTES_DISPLAY_REF style environment variables.
*/
-void string_list_add_refs_from_colon_sep(struct string_list *list,
+void string_list_add_refs_from_colon_sep(struct repository *r,
+ struct string_list *list,
const char *globs);
/* Expand inplace a note ref like "foo" or "notes/foo" into "refs/notes/foo" */
--
2.56.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
` (3 preceding siblings ...)
2026-11-05 20:33 ` [Outreachy PATCH 4/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
@ 2026-11-05 20:33 ` Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 6/6] notes-utils: use the given repository Okhuomon Ajayi
5 siblings, 0 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 20:33 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, gitster, karthik.188
combine_notes_concatenate() and combine_notes_cat_sort_uniq() read
and write note blobs in the_repository, even when the notes tree
belongs to another repository. The callbacks are only called from
note_tree_insert(), which has the tree.
Pass the tree's repository to all combine_notes callbacks. Also make
copy_note() use the tree's hash algorithm for its null object ID.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 34 ++++++++++++++++++++--------------
notes.h | 23 ++++++++++++++---------
2 files changed, 34 insertions(+), 23 deletions(-)
diff --git a/notes.c b/notes.c
index cff63a4410..d675562bf6 100644
--- a/notes.c
+++ b/notes.c
@@ -279,7 +279,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
return 0;
}
- ret = combine_notes(&l->val_oid,
+ ret = combine_notes(t->repo, &l->val_oid,
&entry->val_oid);
if (!ret && is_null_oid(&l->val_oid))
note_tree_remove(t, tree, n, entry);
@@ -816,7 +816,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
return 0;
}
-int combine_notes_concatenate(struct object_id *cur_oid,
+int combine_notes_concatenate(struct repository *r,
+ struct object_id *cur_oid,
const struct object_id *new_oid)
{
char *cur_msg = NULL, *new_msg = NULL, *buf;
@@ -827,14 +828,14 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* read in both note blob objects */
if (!is_null_oid(new_oid))
- new_msg = odb_read_object(the_repository->objects, new_oid,
+ new_msg = odb_read_object(r->objects, new_oid,
&new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg);
return 0;
}
if (!is_null_oid(cur_oid))
- cur_msg = odb_read_object(the_repository->objects, cur_oid,
+ cur_msg = odb_read_object(r->objects, cur_oid,
&cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg);
@@ -858,20 +859,22 @@ int combine_notes_concatenate(struct object_id *cur_oid,
free(new_msg);
/* create a new blob object from buf */
- ret = odb_write_object(the_repository->objects, buf,
+ ret = odb_write_object(r->objects, buf,
buf_len, OBJ_BLOB, cur_oid);
free(buf);
return ret;
}
-int combine_notes_overwrite(struct object_id *cur_oid,
+int combine_notes_overwrite(struct repository *r UNUSED,
+ struct object_id *cur_oid,
const struct object_id *new_oid)
{
oidcpy(cur_oid, new_oid);
return 0;
}
-int combine_notes_ignore(struct object_id *cur_oid UNUSED,
+int combine_notes_ignore(struct repository *r UNUSED,
+ struct object_id *cur_oid UNUSED,
const struct object_id *new_oid UNUSED)
{
return 0;
@@ -881,7 +884,8 @@ int combine_notes_ignore(struct object_id *cur_oid UNUSED,
* Add the lines from the named object to list, with trailing
* newlines removed.
*/
-static int string_list_add_note_lines(struct string_list *list,
+static int string_list_add_note_lines(struct repository *r,
+ struct string_list *list,
const struct object_id *oid)
{
char *data;
@@ -892,7 +896,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0;
/* read_sha1_file NUL-terminates */
- data = odb_read_object(the_repository->objects, oid, &t, &len);
+ data = odb_read_object(r->objects, oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) {
free(data);
return t != OBJ_BLOB || !data;
@@ -918,7 +922,8 @@ static int string_list_join_lines_helper(struct string_list_item *item,
return 0;
}
-int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
+int combine_notes_cat_sort_uniq(struct repository *r,
+ struct object_id *cur_oid,
const struct object_id *new_oid)
{
struct string_list sort_uniq_list = STRING_LIST_INIT_DUP;
@@ -926,9 +931,9 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
int ret = 1;
/* read both note blob objects into unique_lines */
- if (string_list_add_note_lines(&sort_uniq_list, cur_oid))
+ if (string_list_add_note_lines(r, &sort_uniq_list, cur_oid))
goto out;
- if (string_list_add_note_lines(&sort_uniq_list, new_oid))
+ if (string_list_add_note_lines(r, &sort_uniq_list, new_oid))
goto out;
string_list_remove_empty_items(&sort_uniq_list, 0);
string_list_sort_u(&sort_uniq_list, 0);
@@ -938,7 +943,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
string_list_join_lines_helper, &buf))
goto out;
- ret = odb_write_object(the_repository->objects, buf.buf,
+ ret = odb_write_object(r->objects, buf.buf,
buf.len, OBJ_BLOB, cur_oid);
out:
@@ -1382,7 +1387,8 @@ int copy_note(struct notes_tree *t,
if (note)
return add_note(t, to_obj, note, combine_notes);
else if (existing_note)
- return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes);
+ return add_note(t, to_obj, null_oid(t->repo->hash_algo),
+ combine_notes);
return 0;
}
diff --git a/notes.h b/notes.h
index b571ecede4..6d6f6068d8 100644
--- a/notes.h
+++ b/notes.h
@@ -13,10 +13,10 @@ struct strbuf;
* When adding a new note annotating the same object as an existing note, it is
* up to the caller to decide how to combine the two notes. The decision is
* made by passing in a function of the following form. The function accepts
- * two object_ids -- of the existing note and the new note, respectively. The
- * function then combines the notes in whatever way it sees fit, and writes the
- * resulting oid into the first argument (cur_oid). A non-zero return
- * value indicates failure.
+ * the repository the notes live in and two object_ids -- of the existing
+ * note and the new note, respectively. The function then combines the notes
+ * in whatever way it sees fit, and writes the resulting oid into cur_oid.
+ * A non-zero return value indicates failure.
*
* The two given object_ids shall both be non-NULL and different from each
* other. Either of them (but not both) may be == null_oid, which indicates an
@@ -27,17 +27,22 @@ struct strbuf;
* combine_notes_concatenate(), which appends the contents of the new note to
* the contents of the existing note.
*/
-typedef int (*combine_notes_fn)(struct object_id *cur_oid,
+typedef int (*combine_notes_fn)(struct repository *r,
+ struct object_id *cur_oid,
const struct object_id *new_oid);
/* Common notes combinators */
-int combine_notes_concatenate(struct object_id *cur_oid,
+int combine_notes_concatenate(struct repository *r,
+ struct object_id *cur_oid,
const struct object_id *new_oid);
-int combine_notes_overwrite(struct object_id *cur_oid,
+int combine_notes_overwrite(struct repository *r,
+ struct object_id *cur_oid,
const struct object_id *new_oid);
-int combine_notes_ignore(struct object_id *cur_oid,
+int combine_notes_ignore(struct repository *r,
+ struct object_id *cur_oid,
const struct object_id *new_oid);
-int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
+int combine_notes_cat_sort_uniq(struct repository *r,
+ struct object_id *cur_oid,
const struct object_id *new_oid);
/*
--
2.56.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Outreachy PATCH 6/6] notes-utils: use the given repository
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
` (4 preceding siblings ...)
2026-11-05 20:33 ` [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
@ 2026-11-05 20:33 ` Okhuomon Ajayi
5 siblings, 0 replies; 21+ messages in thread
From: Okhuomon Ajayi @ 2026-11-05 20:33 UTC (permalink / raw)
To: git
Cc: christian.couder, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, ps, gitster, karthik.188
create_notes_commit() and commit_notes() take a repository, but
still read and update the notes ref in the_repository.
init_copy_notes_for_rewrite() does not take a repository at all:
it reads config and loads notes trees from the_repository.
Pass the repository through. The config callback keeps it on
struct notes_rewrite_cfg. The sequencer passes its repository;
am and notes pass the_repository for now. notes-utils.c no
longer uses the_repository, so drop USE_THE_REPOSITORY_VARIABLE.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
builtin/am.c | 2 +-
builtin/notes.c | 2 +-
notes-utils.c | 21 ++++++++++-----------
notes-utils.h | 4 +++-
sequencer.c | 2 +-
5 files changed, 16 insertions(+), 15 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 7e7dff6672..a32af68928 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 70c619269e..7e9262411d 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"
@@ -26,7 +24,8 @@ 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 +60,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);
@@ -123,8 +122,7 @@ static int notes_rewrite_config(const char *k, const char *v,
/* note that a refs/ prefix is implied in the
* underlying for_each_glob_ref */
if (starts_with(v, "refs/notes/"))
- string_list_add_refs_by_glob(the_repository,
- c->refs, v);
+ string_list_add_refs_by_glob(c->repo, c->refs, v);
else
warning(_("Refusing to rewrite notes in %s"
" (outside of refs/notes/)"), v);
@@ -135,11 +133,13 @@ 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);
const char *rewrite_refs_env = getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT);
+ c->repo = r;
c->cmd = cmd;
c->enabled = 1;
c->combine = combine_notes_concatenate;
@@ -161,18 +161,17 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
}
if (rewrite_refs_env) {
c->refs_from_env = 1;
- string_list_add_refs_from_colon_sep(the_repository, c->refs,
+ string_list_add_refs_from_colon_sep(r, 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);
free(c);
return NULL;
}
- c->trees = load_notes_trees(the_repository, c->refs,
- NOTES_INIT_WRITABLE);
+ c->trees = load_notes_trees(r, c->refs, NOTES_INIT_WRITABLE);
string_list_clear(c->refs, 0);
free(c->refs);
return c;
diff --git a/notes-utils.h b/notes-utils.h
index c54b1fe141..14dd16f0ea 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -35,6 +35,7 @@ enum notes_merge_strategy {
};
struct notes_rewrite_cfg {
+ struct repository *repo;
struct notes_tree **trees;
const char *cmd;
int enabled;
@@ -45,7 +46,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] 21+ messages in thread
end of thread, other threads:[~2026-11-05 20:34 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-31 10:45 [Outreachy PATCH] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
2026-11-02 11:01 ` Patrick Steinhardt
2026-11-02 11:10 ` Okhuomon Ajayi
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 9:45 ` Karthik Nayak
2026-11-03 18:01 ` Junio C Hamano
2026-11-05 7:43 ` [Outreachy PATCH] notes-utils: hide functions that still need the_repository Okhuomon Ajayi
2026-11-05 14:22 ` Patrick Steinhardt
2026-11-05 14:47 ` Okhuomon Ajayi
2026-11-05 17:56 ` Junio C Hamano
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 1/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 2/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 3/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 4/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 6/6] notes-utils: use the given repository 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 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Karthik Nayak
2026-11-03 10:27 ` Patrick Steinhardt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.