* [PATCH v2 1/5] notes: store the repository in struct notes_tree
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
@ 2026-11-24 17:21 ` Okhuomon Ajayi
2026-11-25 0:34 ` Junio C Hamano
2026-11-24 17:21 ` [PATCH v2 2/5] notes: use the tree's repository when reading notes Okhuomon Ajayi
` (7 subsequent siblings)
8 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-24 17:21 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, okhuomonajayi54
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. Rename init_notes() to
notes_tree_init() and load_notes_trees() to notes_tree_load(),
since every caller changes anyway. notes_tree_init() takes the
tree first and the repository second, and saves the repository
in t->repo. notes_tree_load() takes the repository first.
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 | 30 ++++++++++++++++++------------
notes.h | 11 +++++++----
5 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..725280c785 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);
+ notes_tree_init(NULL, the_repository, 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);
+ notes_tree_init(NULL, the_repository, 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);
+ notes_tree_init(&t, the_repository, "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..b9a2940435 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);
+ notes_tree_init(&c->tree, r, ref.buf,
+ combine_notes_overwrite, flags);
strbuf_release(&ref);
}
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..ea43fedd43 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 = notes_tree_load(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..b79fe65478 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 notes_tree_init(struct notes_tree *t, struct repository *r,
+ 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 **notes_tree_load(struct repository *r,
+ struct string_list *refs, int flags)
{
struct string_list_item *item;
int counter = 0;
@@ -1065,7 +1068,8 @@ 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);
+ notes_tree_init(t, r, item->string,
+ combine_notes_ignore, flags);
trees[counter++] = t;
}
trees[counter] = NULL;
@@ -1136,7 +1140,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 = notes_tree_load(the_repository,
+ &display_notes_refs, 0);
string_list_clear(&display_notes_refs, 0);
}
@@ -1270,7 +1275,8 @@ void free_notes(struct notes_tree *t)
* Fill the given strbuf with the notes associated with the given object.
*
* If the given notes_tree structure is not initialized, it will be auto-
- * initialized to the default value (see documentation for init_notes() above).
+ * initialized to the default value (see documentation for
+ * notes_tree_init() above).
* If the given notes_tree is NULL, the internal/default notes_tree will be
* used instead.
*
@@ -1290,7 +1296,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);
+ notes_tree_init(t, the_repository, NULL, NULL, 0);
oid = get_note(t, object_oid);
if (!oid)
diff --git a/notes.h b/notes.h
index 6dc6d7b265..c81bc99446 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;
@@ -63,7 +64,7 @@ extern struct notes_tree {
* Return the default notes ref.
*
* The default notes ref is the notes ref that is used when notes_ref == NULL
- * is passed to init_notes().
+ * is passed to notes_tree_init().
*
* This the first of the following to be defined:
* 1. The '--ref' option to 'git notes', if given
@@ -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 notes_tree_init(struct notes_tree *t, struct repository *r,
+ 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 **notes_tree_load(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] 86+ messages in thread* Re: [PATCH v2 1/5] notes: store the repository in struct notes_tree
2026-11-24 17:21 ` [PATCH v2 1/5] notes: store the repository in struct notes_tree Okhuomon Ajayi
@ 2026-11-25 0:34 ` Junio C Hamano
2026-11-25 6:39 ` Okhuomon Ajayi
0 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-25 0:34 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> 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. Rename init_notes() to
> notes_tree_init() and load_notes_trees() to notes_tree_load(),
> since every caller changes anyway. notes_tree_init() takes the
> tree first and the repository second, and saves the repository
> in t->repo. notes_tree_load() takes the repository first.
> notes_cache_init() passes the repository it was given. Other
> callers pass the_repository for now.
Keeping 't' first in notes_tree_init() and putting 'r' first in
notes_tree_load() addresses the v1 (or is that v3?) feedback cleanly.
> @@ -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;
Here we set '.repo' before checking NOTES_INIT_EMPTY or calling
repo_get_oid_treeish() makes sure that even an empty or newly created
notes tree records its repository, which is OK. free_notes() already
zeroes the whole struct on teardown.
> @@ -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 notes_tree_init(struct notes_tree *t, struct repository *r,
> + const char *notes_ref, combine_notes_fn combine_notes,
> + int flags);
The comment above this declaration seems incomplete; it talks about 't'
being a notes_tree to be (re)initialized, notes_ref (even though it
replaces the underscore with a space in the explanation), combine_notes
function, but not 'flags'. Now we are adding 'r', so perhaps it is a
good idea to give a brief explanation for that (just say "the repository
that this notes_tree belongs to" or something like that)?
> @@ -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 **notes_tree_load(struct repository *r,
> + struct string_list *refs, int flags);
I trust all existing references to old names are converted correctly
(which should be easy to verify---if not, the result would not compile
or link).
Looking good, so far.
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v2 1/5] notes: store the repository in struct notes_tree
2026-11-25 0:34 ` Junio C Hamano
@ 2026-11-25 6:39 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 6:39 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> The comment above this declaration seems incomplete; it talks about 't'
> being a notes_tree to be (re)initialized, notes_ref [...], combine_notes
> function, but not 'flags'. Now we are adding 'r', so perhaps it is a
> good idea to give a brief explanation for that [...]?
The comment doesn't mention 'flags' either. I'll add a line describing
'r' (the repository this notes_tree belongs to) and one describing 'flags'.
Okhuomon
On Wed, Nov 25, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > 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. Rename init_notes() to
> > notes_tree_init() and load_notes_trees() to notes_tree_load(),
> > since every caller changes anyway. notes_tree_init() takes the
> > tree first and the repository second, and saves the repository
> > in t->repo. notes_tree_load() takes the repository first.
> > notes_cache_init() passes the repository it was given. Other
> > callers pass the_repository for now.
>
> Keeping 't' first in notes_tree_init() and putting 'r' first in
> notes_tree_load() addresses the v1 (or is that v3?) feedback cleanly.
>
> > @@ -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;
>
> Here we set '.repo' before checking NOTES_INIT_EMPTY or calling
> repo_get_oid_treeish() makes sure that even an empty or newly created
> notes tree records its repository, which is OK. free_notes() already
> zeroes the whole struct on teardown.
>
>
> > @@ -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 notes_tree_init(struct notes_tree *t, struct repository *r,
> > + const char *notes_ref, combine_notes_fn combine_notes,
> > + int flags);
>
> The comment above this declaration seems incomplete; it talks about 't'
> being a notes_tree to be (re)initialized, notes_ref (even though it
> replaces the underscore with a space in the explanation), combine_notes
> function, but not 'flags'. Now we are adding 'r', so perhaps it is a
> good idea to give a brief explanation for that (just say "the repository
> that this notes_tree belongs to" or something like that)?
>
> > @@ -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 **notes_tree_load(struct repository *r,
> > + struct string_list *refs, int flags);
>
> I trust all existing references to old names are converted correctly
> (which should be easy to verify---if not, the result would not compile
> or link).
>
> Looking good, so far.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
2026-11-24 17:21 ` [PATCH v2 1/5] notes: store the repository in struct notes_tree Okhuomon Ajayi
@ 2026-11-24 17:21 ` Okhuomon Ajayi
2026-11-25 0:54 ` Junio C Hamano
2026-11-24 17:21 ` [PATCH v2 3/5] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
` (6 subsequent siblings)
8 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-24 17:21 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, okhuomonajayi54
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 b79fe65478..9cf71651ed 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);
}
@@ -1169,8 +1169,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;
@@ -1302,7 +1302,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] 86+ messages in thread* Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-24 17:21 ` [PATCH v2 2/5] notes: use the tree's repository when reading notes Okhuomon Ajayi
@ 2026-11-25 0:54 ` Junio C Hamano
2026-11-25 6:45 ` Okhuomon Ajayi
0 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-25 0:54 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> 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.
Hmph.
Some of these functions like remove_note() and prune_notes() use
default_notes_tree as a stand-in when NULL is passed to 't', and they
also assert t->initialized before accessing t->repo. So it should be
safe to convert them to access t->repo instead of the_repository.
But others? note_tree_find() calls note_tree_search() which by itself
does not touch 't' at all as far as I can tell (which means 't' can
safely be NULL for notes_tree_search() because it does not dereference
it to access t->repo). The conversion in this step would cause them to
dereference t->repo without checking if t is not NULL or t->initialized
member. If they are already dereferencing t in the existing code and
assuming t is initialized, then this conversion is safe. Otherwise, I
am not sure if a mechanical the_repository -> t->repo replacement is
good here.
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-25 0:54 ` Junio C Hamano
@ 2026-11-25 6:45 ` Okhuomon Ajayi
2026-11-25 8:25 ` Christian Couder
2026-11-25 17:50 ` Junio C Hamano
0 siblings, 2 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 6:45 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> But others? note_tree_find() calls note_tree_search() which by itself
> does not touch 't' at all [...] The conversion in this step would cause
> them to dereference t->repo without checking if t is not NULL or
> t->initialized [...]
note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
with &default_notes_tree and asserts t->initialized before passing
t->root down, so 't' is already non-NULL and initialized by the time we
read t->repo. note_tree_search() not touching 't' doesn't matter here,
since get_note() has already dereferenced it.
The other functions this patch converts are safe too, for slightly
different reasons: remove_note() and format_note() guard a NULL 't'
themselves, and add_non_note() and load_subtree() are only reached from
init_notes() (and load_subtree()'s own recursion), where 't' is the tree
being initialized and so is never NULL. So I believe this step is safe
as it stands.
Okhuomon
On Wed, Nov 25, 2026 at 1:54 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > 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.
>
> Hmph.
>
> Some of these functions like remove_note() and prune_notes() use
> default_notes_tree as a stand-in when NULL is passed to 't', and they
> also assert t->initialized before accessing t->repo. So it should be
> safe to convert them to access t->repo instead of the_repository.
>
> But others? note_tree_find() calls note_tree_search() which by itself
> does not touch 't' at all as far as I can tell (which means 't' can
> safely be NULL for notes_tree_search() because it does not dereference
> it to access t->repo). The conversion in this step would cause them to
> dereference t->repo without checking if t is not NULL or t->initialized
> member. If they are already dereferencing t in the existing code and
> assuming t is initialized, then this conversion is safe. Otherwise, I
> am not sure if a mechanical the_repository -> t->repo replacement is
> good here.
>
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-25 6:45 ` Okhuomon Ajayi
@ 2026-11-25 8:25 ` Christian Couder
2026-11-25 18:13 ` Okhuomon Ajayi
2026-11-25 17:50 ` Junio C Hamano
1 sibling, 1 reply; 86+ messages in thread
From: Christian Couder @ 2026-11-25 8:25 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: Junio C Hamano, git, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Wed, Nov 25, 2026 at 7:45 AM Okhuomon Ajayi
<okhuomonajayi54@gmail.com> wrote:
>
> On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> > But others? note_tree_find() calls note_tree_search() which by itself
> > does not touch 't' at all [...] The conversion in this step would cause
> > them to dereference t->repo without checking if t is not NULL or
> > t->initialized [...]
>
> note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
> with &default_notes_tree and asserts t->initialized before passing
> t->root down, so 't' is already non-NULL and initialized by the time we
> read t->repo. note_tree_search() not touching 't' doesn't matter here,
> since get_note() has already dereferenced it.
>
> The other functions this patch converts are safe too, for slightly
> different reasons: remove_note() and format_note() guard a NULL 't'
> themselves, and add_non_note() and load_subtree() are only reached from
> init_notes() (and load_subtree()'s own recursion), where 't' is the tree
> being initialized and so is never NULL. So I believe this step is safe
> as it stands.
It looks like load_subtree() can be reached in other ways, as subtrees
are unpacked on demand, like for example:
get_note() -> note_tree_find() -> note_tree_search() -> load_subtree()
So I think that the real argument why the other functions are safe is
that all the public entry points (add_note(), remove_note(),
get_note(), etc., and the internal format_note()) are safe as they
replace a NULL `t` with `&default_notes_tree` and assert
`t->initialized`.
copy_note() seems to be the only public function that doesn't do that,
which is what Junio found in 3/5.
It would be nice if the commit message of 2/5 in v5 briefly explained this.
Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-25 8:25 ` Christian Couder
@ 2026-11-25 18:13 ` Okhuomon Ajayi
2026-11-25 19:09 ` Junio C Hamano
0 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 18:13 UTC (permalink / raw)
To: Christian Couder
Cc: Junio C Hamano, git, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Wed, Nov 25, 2026 at 8:25 AM Christian Couder
<christian.couder@gmail.com> wrote:
> It looks like load_subtree() can be reached in other ways, as subtrees
> are unpacked on demand, like for example:
> get_note() -> note_tree_find() -> note_tree_search() -> load_subtree()
Ah, right. I was only looking at the init path and missed that
note_tree_search() unpacks subtrees lazily, so load_subtree() (and
add_non_note() under it) gets reached during ordinary lookups too, not
just from init_notes().
So the cleaner way to put it is yours, the safety comes from the entry
points, not the individual helpers. The public ones (add_note(),
remove_note(), get_note()) swap a NULL 't' for &default_notes_tree and
assert t->initialized before anything downstream runs, and the internal
format_note() does the same NULL swap and initializes the tree if it
isn't already. Either way 't' is valid by the time we reach
note_tree_find()/load_subtree(). copy_note() is the only one that reads
t->repo without that guard, which is what 3/5 fixes. I'll fold that into
the 2/5 commit message.
Okhuomon
On Wed, Nov 25, 2026 at 9:25 AM Christian Couder
<christian.couder@gmail.com> wrote:
>
> On Wed, Nov 25, 2026 at 7:45 AM Okhuomon Ajayi
> <okhuomonajayi54@gmail.com> wrote:
> >
> > On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> > > But others? note_tree_find() calls note_tree_search() which by itself
> > > does not touch 't' at all [...] The conversion in this step would cause
> > > them to dereference t->repo without checking if t is not NULL or
> > > t->initialized [...]
> >
> > note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
> > with &default_notes_tree and asserts t->initialized before passing
> > t->root down, so 't' is already non-NULL and initialized by the time we
> > read t->repo. note_tree_search() not touching 't' doesn't matter here,
> > since get_note() has already dereferenced it.
> >
> > The other functions this patch converts are safe too, for slightly
> > different reasons: remove_note() and format_note() guard a NULL 't'
> > themselves, and add_non_note() and load_subtree() are only reached from
> > init_notes() (and load_subtree()'s own recursion), where 't' is the tree
> > being initialized and so is never NULL. So I believe this step is safe
> > as it stands.
>
> It looks like load_subtree() can be reached in other ways, as subtrees
> are unpacked on demand, like for example:
>
> get_note() -> note_tree_find() -> note_tree_search() -> load_subtree()
>
> So I think that the real argument why the other functions are safe is
> that all the public entry points (add_note(), remove_note(),
> get_note(), etc., and the internal format_note()) are safe as they
> replace a NULL `t` with `&default_notes_tree` and assert
> `t->initialized`.
>
> copy_note() seems to be the only public function that doesn't do that,
> which is what Junio found in 3/5.
>
> It would be nice if the commit message of 2/5 in v5 briefly explained this.
>
> Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-25 18:13 ` Okhuomon Ajayi
@ 2026-11-25 19:09 ` Junio C Hamano
2026-11-25 20:36 ` Okhuomon Ajayi
0 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-25 19:09 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: Christian Couder, git, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> So the cleaner way to put it is yours, the safety comes from the entry
> points, not the individual helpers. The public ones (add_note(),
> remove_note(), get_note()) swap a NULL 't' for &default_notes_tree and
> assert t->initialized before anything downstream runs, and the internal
> format_note() does the same NULL swap and initializes the tree if it
> isn't already.
Can we have a single helper function to do this? Instead of repeating
the three-line dance all over, perhaps do
t = helper(t);
where the helper does
static struct notes_tree *helper(struct notes_tree *t)
{
if (!t)
t = &default_notes_tree;
assert(!t->initialized);
return t;
}
or something? Of course the helper must be given a much better name ;-)
Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread* Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-25 19:09 ` Junio C Hamano
@ 2026-11-25 20:36 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 20:36 UTC (permalink / raw)
To: Junio C Hamano
Cc: Christian Couder, git, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Wed, Nov 25, 2026 at 8:09 PM Junio C Hamano <gitster@pobox.com> wrote:
> Can we have a single helper function to do this? Instead of repeating
> the three-line dance all over, perhaps do
>
> t = helper(t);
>
> where the helper does
>
> static struct notes_tree *helper(struct notes_tree *t)
> {
> if (!t)
> t = &default_notes_tree;
> assert(!t->initialized);
> return t;
> }
>
> or something? Of course the helper must be given a much better name ;-)
Good idea, the three lines repeat often enough to be worth a
helper. I'll add one and route add_note(), remove_note(),
get_note(), for_each_note(), write_notes_tree(), prune_notes()
and the new copy_note() through it, as a prep patch at the front
of the series.
I'll keep the assert(t->initialized) the sites already use, and
give it a real name, something like notes_tree_or_default().
Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-25 6:45 ` Okhuomon Ajayi
2026-11-25 8:25 ` Christian Couder
@ 2026-11-25 17:50 ` Junio C Hamano
2026-11-25 18:19 ` Okhuomon Ajayi
1 sibling, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-25 17:50 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
>> But others? note_tree_find() calls note_tree_search() which by itself
>> does not touch 't' at all [...] The conversion in this step would cause
>> them to dereference t->repo without checking if t is not NULL or
>> t->initialized [...]
>
> note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
> with &default_notes_tree and asserts t->initialized before passing
> t->root down, so 't' is already non-NULL and initialized by the time we
> read t->repo. note_tree_search() not touching 't' doesn't matter here,
> since get_note() has already dereferenced it.
OK, I missed the guarantees that these limited number of callers give
these functions being modified.
So copy_notes() in [3/5] is the only unsafe conversion we need to
rework in the next iteration, I guess?
Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
2026-11-25 17:50 ` Junio C Hamano
@ 2026-11-25 18:19 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 18:19 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Tue, Nov 25, 2026 at 1:54 AM Junio C Hamano <gitster@pobox.com> wrote:
> So copy_notes() in [3/5] is the only unsafe conversion we need to
> rework in the next iteration, I guess?
Yes, that's right. copy_note() in 3/5 is the only unsafe one. I'll add
the NULL guard there in v5; the rest of the series stays as it is.
Okhuomon
On Wed, Nov 25, 2026 at 6:50 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> >> But others? note_tree_find() calls note_tree_search() which by itself
> >> does not touch 't' at all [...] The conversion in this step would cause
> >> them to dereference t->repo without checking if t is not NULL or
> >> t->initialized [...]
> >
> > note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
> > with &default_notes_tree and asserts t->initialized before passing
> > t->root down, so 't' is already non-NULL and initialized by the time we
> > read t->repo. note_tree_search() not touching 't' doesn't matter here,
> > since get_note() has already dereferenced it.
>
> OK, I missed the guarantees that these limited number of callers give
> these functions being modified.
>
> So copy_notes() in [3/5] is the only unsafe conversion we need to
> rework in the next iteration, I guess?
>
> Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v2 3/5] notes: use the tree's repository when writing and pruning
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
2026-11-24 17:21 ` [PATCH v2 1/5] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-24 17:21 ` [PATCH v2 2/5] notes: use the tree's repository when reading notes Okhuomon Ajayi
@ 2026-11-24 17:21 ` Okhuomon Ajayi
2026-11-25 0:54 ` Junio C Hamano
2026-11-24 17:21 ` [PATCH v2 4/5] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
` (5 subsequent siblings)
8 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-24 17:21 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, okhuomonajayi54
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.
copy_note() also writes through the tree, by calling add_note(),
so it uses the tree's hash algorithm for its null object ID.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 62 ++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 37 insertions(+), 25 deletions(-)
diff --git a/notes.c b/notes.c
index 9cf71651ed..9d653c757a 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;
}
@@ -1214,6 +1223,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;
@@ -1223,8 +1233,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;
@@ -1232,25 +1242,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;
}
}
@@ -1368,7 +1379,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;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 86+ messages in thread* Re: [PATCH v2 3/5] notes: use the tree's repository when writing and pruning
2026-11-24 17:21 ` [PATCH v2 3/5] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
@ 2026-11-25 0:54 ` Junio C Hamano
2026-11-25 6:48 ` Okhuomon Ajayi
0 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-25 0:54 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> 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.
>
> copy_note() also writes through the tree, by calling add_note(),
> so it uses the tree's hash algorithm for its null object ID.
>
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> ---
> ...
> @@ -1368,7 +1379,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;
> }
Unlike prune_notes() and write_notes_tree(), copy_notes() does not like
to be fed a NULL as 't' and use the default_notes_tree as a stand-in.
The function begins with a call to get_note()
const struct object_id *note = get_note(t, from_obj);
const struct object_id *existing_note = get_note(t, to_obj);
so they can give you note and existing_note back to you safely, but t
copy_note() has may still be NULL, if the caller gave it a NULL.
Dereferencing t->repo->hash_algo here would probably be wrong in such a
case. Instead, this function probably want the same
if (!t)
t = &default_notes_tree();
assert(t->initialized);
dance as the others have.
Together with the earlier review on [2/5], if we were keeping
default_notes_tree support, we probably would want to tighten
how t==NULL is handled by each function on the call graph before
moving forward, I am afraid.
^ permalink raw reply [flat|nested] 86+ messages in thread* Re: [PATCH v2 3/5] notes: use the tree's repository when writing and pruning
2026-11-25 0:54 ` Junio C Hamano
@ 2026-11-25 6:48 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 6:48 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> Unlike prune_notes() and write_notes_tree(), copy_notes() does not like
> to be fed a NULL as 't' and use the default_notes_tree as a stand-in.
> [...] Dereferencing t->repo->hash_algo here would probably be wrong in
> such a case. Instead, this function probably want the same
> if (!t)
> t = &default_notes_tree();
> assert(t->initialized);
> dance as the others have.
You're right. copy_note() reaches t->repo->hash_algo without ever
substituting the default tree, so a NULL 't' would crash where it
didn't before. I'll add the
if (!t)
t = &default_notes_tree;
assert(t->initialized);
dance at the top of copy_note() in v5, matching remove_note() and the
others.
And thank you for the thorough read through the whole series. The
reviews have been genuinely helpful, and I'll roll all of this into v5.
Okhuomon
On Wed, Nov 25, 2026 at 1:54 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > 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.
> >
> > copy_note() also writes through the tree, by calling add_note(),
> > so it uses the tree's hash algorithm for its null object ID.
> >
> > Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> > ---
> > ...
> > @@ -1368,7 +1379,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;
> > }
>
> Unlike prune_notes() and write_notes_tree(), copy_notes() does not like
> to be fed a NULL as 't' and use the default_notes_tree as a stand-in.
> The function begins with a call to get_note()
>
> const struct object_id *note = get_note(t, from_obj);
> const struct object_id *existing_note = get_note(t, to_obj);
>
> so they can give you note and existing_note back to you safely, but t
> copy_note() has may still be NULL, if the caller gave it a NULL.
> Dereferencing t->repo->hash_algo here would probably be wrong in such a
> case. Instead, this function probably want the same
>
> if (!t)
> t = &default_notes_tree();
> assert(t->initialized);
>
> dance as the others have.
>
> Together with the earlier review on [2/5], if we were keeping
> default_notes_tree support, we probably would want to tighten
> how t==NULL is handled by each function on the call graph before
> moving forward, I am afraid.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v2 4/5] notes: pass the repository to the ref glob helpers
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
` (2 preceding siblings ...)
2026-11-24 17:21 ` [PATCH v2 3/5] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
@ 2026-11-24 17:21 ` Okhuomon Ajayi
2026-11-25 5:12 ` Junio C Hamano
2026-11-24 17:21 ` [PATCH v2 5/5] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
` (4 subsequent siblings)
8 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-24 17:21 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, okhuomonajayi54
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 ea43fedd43..9f70366aa9 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 9d653c757a..ed6fc9a1c2 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;
@@ -1133,7 +1136,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
@@ -1145,7 +1149,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 c81bc99446..520a816714 100644
--- a/notes.h
+++ b/notes.h
@@ -327,14 +327,16 @@ struct notes_tree **notes_tree_load(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] 86+ messages in thread* [PATCH v2 5/5] notes: pass the repository to the combine_notes callbacks
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
` (3 preceding siblings ...)
2026-11-24 17:21 ` [PATCH v2 4/5] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
@ 2026-11-24 17:21 ` Okhuomon Ajayi
2026-11-24 22:50 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Junio C Hamano
` (3 subsequent siblings)
8 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-24 17:21 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam, okhuomonajayi54
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.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 31 ++++++++++++++++++-------------
notes.h | 23 ++++++++++++++---------
2 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/notes.c b/notes.c
index ed6fc9a1c2..055ba84b7d 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:
diff --git a/notes.h b/notes.h
index 520a816714..3aa1d3e45e 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] 86+ messages in thread* Re: [PATCH v2 0/5] notes: start passing the repository through notes.[ch]
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
` (4 preceding siblings ...)
2026-11-24 17:21 ` [PATCH v2 5/5] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
@ 2026-11-24 22:50 ` Junio C Hamano
2026-11-25 6:24 ` Okhuomon Ajayi
2026-11-25 1:14 ` Junio C Hamano
` (2 subsequent siblings)
8 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-24 22:50 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> This is a preparatory series.
Whatever it is, this claims to be a "v2", but in the same discussion
thread, there already is a two-patch series labelled "v2" from November
3rd. The original sin was the initial iteration of 6-patch series from
November 5th that did not identify itself as "v3", and calling this one
"v2" again is making things worse. This is breaking automation, e.g.,
"b4 am" gets very confused. I could use the "--no-parent" option, but
I shouldn't have to.
The next one should probably be called "v5", as this is what should have
been "v4", probably?
Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread* Re: [PATCH v2 0/5] notes: start passing the repository through notes.[ch]
2026-11-24 22:50 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Junio C Hamano
@ 2026-11-25 6:24 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 6:24 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Tue, Nov 24, 2026 at 11:50 PM Junio C Hamano <gitster@pobox.com> wrote:
> Whatever it is, this claims to be a "v2", but in the same discussion
> thread, there already is a two-patch series labelled "v2" from November
> 3rd. [...] The next one should probably be called "v5", as this is what
> should have been "v4", probably?
You're right, sorry for the confusion. The Nov 3 notes-utils series was
the v2, and this topic that started on Nov 5 should have continued the
count. I'll send the next iteration as v5 so b4 and the thread stay
consistent.
Okhuomon
On Tue, Nov 24, 2026 at 11:50 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > This is a preparatory series.
>
> Whatever it is, this claims to be a "v2", but in the same discussion
> thread, there already is a two-patch series labelled "v2" from November
> 3rd. The original sin was the initial iteration of 6-patch series from
> November 5th that did not identify itself as "v3", and calling this one
> "v2" again is making things worse. This is breaking automation, e.g.,
> "b4 am" gets very confused. I could use the "--no-parent" option, but
> I shouldn't have to.
>
> The next one should probably be called "v5", as this is what should have
> been "v4", probably?
>
> Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v2 0/5] notes: start passing the repository through notes.[ch]
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
` (5 preceding siblings ...)
2026-11-24 22:50 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Junio C Hamano
@ 2026-11-25 1:14 ` Junio C Hamano
2026-11-25 6:35 ` Okhuomon Ajayi
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
8 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-25 1:14 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> This is a preparatory series. It makes the code in notes.[c,h] and its
> direct callers work on the repository stored in struct notes_tree instead
> of the_repository. It deliberately does not convert the whole notes
> subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
> rest for future series.
Framing this as a preparatory series and splitting out the remaining
work makes the scope very clear.
> What is left for future series:
> - notes.c: the display-notes code keeps its state in globals, and log,
> format-patch, diff-tree and format-rev are given a repository but do
> not pass it on. format_note() still falls back to the global
> default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
> The hash-size helpers are also still on the global.
> - notes-utils.[c,h]: still use the_repository. And the hash-size helpers
> still on the global are reached from here, through create_notes_commit()
> -> write_notes_tree(), so converting notes-utils is tied to converting
> those helpers too.
> - notes-merge.[c,h]: still work on the global repository.
It seems taht notes-cache.c also still uses the_repository in
notes_cache_match_validity(), notes_cache_write(), notes_cache_get(),
and notes_cache_put(), even though notes_cache_init() now passes its
repository parameter to notes_tree_init().
Apart from the NULL check needed in copy_note() on patch 3, the series
looks in good shape.
^ permalink raw reply [flat|nested] 86+ messages in thread* Re: [PATCH v2 0/5] notes: start passing the repository through notes.[ch]
2026-11-25 1:14 ` Junio C Hamano
@ 2026-11-25 6:35 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 6:35 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Tue, Nov 24, 2026 at 11:50 PM Junio C Hamano <gitster@pobox.com> wrote:
> It seems taht notes-cache.c also still uses the_repository in
> notes_cache_match_validity(), notes_cache_write(), notes_cache_get(),
> and notes_cache_put(), even though notes_cache_init() now passes its
> repository parameter to notes_tree_init().
Those four do still read the_repository there, even though
notes_cache_init() now has the repository to hand down. I kept them out
to hold this series to notes.[c,h], but they are the natural next step,
so I will list them in the cover letter under what is left rather than
pull them in here. The copy_note() NULL handling I will sort out in 3/5.
Okhuomon
On Wed, Nov 25, 2026 at 2:14 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > This is a preparatory series. It makes the code in notes.[c,h] and its
> > direct callers work on the repository stored in struct notes_tree instead
> > of the_repository. It deliberately does not convert the whole notes
> > subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
> > rest for future series.
>
> Framing this as a preparatory series and splitting out the remaining
> work makes the scope very clear.
>
> > What is left for future series:
> > - notes.c: the display-notes code keeps its state in globals, and log,
> > format-patch, diff-tree and format-rev are given a repository but do
> > not pass it on. format_note() still falls back to the global
> > default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
> > The hash-size helpers are also still on the global.
> > - notes-utils.[c,h]: still use the_repository. And the hash-size helpers
> > still on the global are reached from here, through create_notes_commit()
> > -> write_notes_tree(), so converting notes-utils is tied to converting
> > those helpers too.
> > - notes-merge.[c,h]: still work on the global repository.
>
> It seems taht notes-cache.c also still uses the_repository in
> notes_cache_match_validity(), notes_cache_write(), notes_cache_get(),
> and notes_cache_put(), even though notes_cache_init() now passes its
> repository parameter to notes_tree_init().
>
> Apart from the NULL check needed in copy_note() on patch 3, the series
> looks in good shape.
>
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v5 0/6] notes: start passing the repository through notes.[ch]
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
` (6 preceding siblings ...)
2026-11-25 1:14 ` Junio C Hamano
@ 2026-11-25 22:02 ` Okhuomon Ajayi
2026-11-25 22:02 ` [PATCH v5 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
` (6 more replies)
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
8 siblings, 7 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 22:02 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
This is a preparatory series. It makes the code in notes.[c,h] and its
direct callers work on the repository stored in struct notes_tree instead
of the_repository. It deliberately does not convert the whole notes
subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
rest for future series.
What it does:
- adds notes_tree_or_default() for the shared NULL-tree check;
- stores the repository in struct notes_tree;
- uses the tree's repository when reading, writing and pruning notes;
- passes the repository to the ref glob helpers and the combine_notes
callbacks.
What is left for future series:
- notes.c: the display-notes code keeps its state in globals, and log,
format-patch, diff-tree and format-rev are given a repository but do
not pass it on. format_note() still falls back to the global
default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
The hash-size helpers are also still on the global.
- notes-utils.[c,h]: still use the_repository. And the hash-size helpers
still on the global are reached from here, through create_notes_commit()
-> write_notes_tree(), so converting notes-utils is tied to converting
those helpers too.
- notes-merge.[c,h]: still work on the global repository.
- notes-cache.c: notes_cache_init() passes its repository through, but
notes_cache_match_validity(), notes_cache_write(), notes_cache_get()
and notes_cache_put() still use the_repository.
The previous round was labeled v2. It should have been v4, so this
reroll is v5.
Changes since v4:
- Add notes_tree_or_default() and use it for the repeated NULL-tree
check. copy_note() uses that helper for its new guard.
- Document 'r' and 'flags' above notes_tree_init().
- Explain in the reading patch why the converted helpers are safe
when the tree is NULL. copy_note() was the exception.
- List notes-cache.c with what is left for a future series.
Okhuomon Ajayi (6):
notes: add notes_tree_or_default()
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
builtin/notes.c | 8 +-
notes-cache.c | 3 +-
notes-utils.c | 9 ++-
notes.c | 205 +++++++++++++++++++++++++++---------------------
notes.h | 44 +++++++----
5 files changed, 159 insertions(+), 110 deletions(-)
Range-diff against v4:
-: ---------- > 1: c9891e887c notes: add notes_tree_or_default()
1: 5ad0f1bd62 ! 2: 831db4c68a notes: store the repository in struct notes_tree
@@ notes.h: extern struct notes_tree {
* This the first of the following to be defined:
* 1. The '--ref' option to 'git notes', if given
@@ notes.h: char *default_notes_ref(struct repository *repo);
+ *
+ * If you pass t == NULL, the default internal notes_tree will be initialized.
+ *
++ * 'r' is the repository that this notes_tree belongs to.
++ *
+ * The combine_notes function that is passed becomes the default combine_notes
+ * function for the given notes_tree. If NULL is passed, the default
+ * combine_notes function is combine_notes_concatenate().
+ *
++ * 'flags' is a combination of the NOTES_INIT_* flags above.
++ *
* Precondition: The notes_tree structure is zeroed (this can be achieved with
* memset(t, 0, sizeof(struct notes_tree)))
*/
2: 1018419720 ! 3: 82f6f6ea7c notes: use the tree's repository when reading notes
@@ Commit message
Read them from t->repo, the repository stored on the tree.
+ note_tree_find(), add_non_note() and load_subtree() do not check
+ for a NULL tree themselves. add_note(), remove_note() and
+ get_note() replace a NULL tree with the default notes tree and
+ assert that it is initialized before those helpers run.
+ format_note() does the same NULL swap, and initializes the tree
+ if it is not already. load_subtree() is also reached when a
+ lookup unpacks a subtree, which is still after that check.
+ copy_note() is the one public function that does not do this;
+ the next patch adds the guard.
+
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
## notes.c ##
@@ notes.c: static void load_subtree(struct notes_tree *t, struct leaf_node *subtre
entry.mode, entry.oid.hash);
}
@@ notes.c: int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ struct leaf_node l;
+
+ t = notes_tree_or_default(t);
- 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);
3: 67a2942c09 ! 4: b35eb50a45 notes: use the tree's repository when writing and pruning
@@ Commit message
copy_note() also writes through the tree, by calling add_note(),
so it uses the tree's hash algorithm for its null object ID.
+ It now takes a NULL tree the same way as the other entry points,
+ through notes_tree_or_default(), before reading the tree's
+ repository.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
@@ notes.c: int write_notes_tree(struct notes_tree *t, struct object_id *result)
- struct note_delete_list *l = NULL;
+ struct prune_notes_data d = { 0 };
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
- for_each_note(t, 0, prune_notes_helper, &l);
+ d.repo = t->repo;
@@ notes.c: int write_notes_tree(struct notes_tree *t, struct object_id *result)
}
}
+@@ notes.c: int copy_note(struct notes_tree *t,
+ const struct object_id *from_obj, const struct object_id *to_obj,
+ int force, combine_notes_fn combine_notes)
+ {
+- const struct object_id *note = get_note(t, from_obj);
+- const struct object_id *existing_note = get_note(t, to_obj);
++ const struct object_id *note;
++ const struct object_id *existing_note;
++
++ t = notes_tree_or_default(t);
++
++ note = get_note(t, from_obj);
++ existing_note = get_note(t, to_obj);
+
+ if (!force && existing_note)
+ return 1;
@@ notes.c: int copy_note(struct notes_tree *t,
if (note)
return add_note(t, to_obj, note, combine_notes);
4: 7ea6c0e5a2 = 5: dcda05343a notes: pass the repository to the ref glob helpers
5: ff8cf4d22a = 6: 69928b58f6 notes: pass the repository to the combine_notes callbacks
--
2.56.0
^ permalink raw reply [flat|nested] 86+ messages in thread* [PATCH v5 1/6] notes: add notes_tree_or_default()
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
@ 2026-11-25 22:02 ` Okhuomon Ajayi
2026-11-26 2:57 ` Junio C Hamano
2026-11-25 22:02 ` [PATCH v5 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
` (5 subsequent siblings)
6 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 22:02 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
Several notes entry points repeat the same check: a NULL tree
means the default notes tree, and the tree must already be
initialized.
Use one helper for that check. notes_tree_init() asserts that
the tree is not yet initialized, free_notes() only frees what is
there, and format_note() initializes the tree when it is not, so
those three keep their own checks.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/notes.c b/notes.c
index ec9c2cb150..a73a51e1a0 100644
--- a/notes.c
+++ b/notes.c
@@ -1140,14 +1140,20 @@ void load_display_notes(struct display_notes_opt *opt)
string_list_clear(&display_notes_refs, 0);
}
+static struct notes_tree *notes_tree_or_default(struct notes_tree *t)
+{
+ if (!t)
+ t = &default_notes_tree;
+ assert(t->initialized);
+ return t;
+}
+
int add_note(struct notes_tree *t, const struct object_id *object_oid,
const struct object_id *note_oid, combine_notes_fn combine_notes)
{
struct leaf_node *l;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
t->dirty = 1;
if (!combine_notes)
combine_notes = t->combine_notes;
@@ -1161,9 +1167,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
{
struct leaf_node l;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
oidclr(&l.val_oid, the_repository->hash_algo);
note_tree_remove(t, t->root, 0, &l);
@@ -1178,9 +1182,7 @@ const struct object_id *get_note(struct notes_tree *t,
{
struct leaf_node *found;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
found = note_tree_find(t, t->root, 0, oid->hash);
return found ? &found->val_oid : NULL;
}
@@ -1188,9 +1190,7 @@ const struct object_id *get_note(struct notes_tree *t,
int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
void *cb_data)
{
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
}
@@ -1201,9 +1201,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
int ret;
int flags;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
/* Prepare for traversal of current notes tree */
root.next = NULL; /* last forward entry in list is grounded */
@@ -1229,9 +1227,7 @@ void prune_notes(struct notes_tree *t, int flags)
{
struct note_delete_list *l = NULL;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
for_each_note(t, 0, prune_notes_helper, &l);
--
2.56.0
^ permalink raw reply related [flat|nested] 86+ messages in thread* Re: [PATCH v5 1/6] notes: add notes_tree_or_default()
2026-11-25 22:02 ` [PATCH v5 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
@ 2026-11-26 2:57 ` Junio C Hamano
2026-11-26 16:57 ` Okhuomon Ajayi
0 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-26 2:57 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> Several notes entry points repeat the same check: a NULL tree
> means the default notes tree, and the tree must already be
> initialized.
>
> Use one helper for that check. notes_tree_init() asserts that
> the tree is not yet initialized, free_notes() only frees what is
> there, and format_note() initializes the tree when it is not, so
> those three keep their own checks.
At this point in the series, the initialization function is still called
init_notes(), as the rename to notes_tree_init() happens in the next
patch.
> diff --git a/notes.c b/notes.c
> index ec9c2cb150..a73a51e1a0 100644
> --- a/notes.c
> +++ b/notes.c
> @@ -1140,14 +1140,20 @@ void load_display_notes(struct display_notes_opt *opt)
> string_list_clear(&display_notes_refs, 0);
> }
>
> +static struct notes_tree *notes_tree_or_default(struct notes_tree *t)
> +{
> + if (!t)
> + t = &default_notes_tree;
> + assert(t->initialized);
> + return t;
> +}
> +
> int add_note(struct notes_tree *t, const struct object_id *object_oid,
> const struct object_id *note_oid, combine_notes_fn combine_notes)
> {
> struct leaf_node *l;
>
> - if (!t)
> - t = &default_notes_tree;
> - assert(t->initialized);
> + t = notes_tree_or_default(t);
I somehow thought you would leave assert() outside the helper, which
might give us a better abstraction in the longer term, but I do not mind
either way.
As a way to prepare for making copy_note() safer in a later step,
keeping this step a pure refactoring makes sense.
^ permalink raw reply [flat|nested] 86+ messages in thread* Re: [PATCH v5 1/6] notes: add notes_tree_or_default()
2026-11-26 2:57 ` Junio C Hamano
@ 2026-11-26 16:57 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 16:57 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Junio C Hamano <gitster@pobox.com> writes:
> At this point in the series, the initialization function is still called
> init_notes(), as the rename to notes_tree_init() happens in the next
> patch.
Right, I'll fix the message to refer to init_notes() at this step.
> I somehow thought you would leave assert() outside the helper, which
> might give us a better abstraction in the longer term, but I do not mind
> either way.
I kept the assert inside so every entry point shares the same
precondition in one place, but I take the point about the thinner
helper. I'll leave as it is for now unless you'd prefer it split out.
Thanks.
On Thu, Nov 26, 2026 at 3:57 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > Several notes entry points repeat the same check: a NULL tree
> > means the default notes tree, and the tree must already be
> > initialized.
> >
> > Use one helper for that check. notes_tree_init() asserts that
> > the tree is not yet initialized, free_notes() only frees what is
> > there, and format_note() initializes the tree when it is not, so
> > those three keep their own checks.
>
> At this point in the series, the initialization function is still called
> init_notes(), as the rename to notes_tree_init() happens in the next
> patch.
>
> > diff --git a/notes.c b/notes.c
> > index ec9c2cb150..a73a51e1a0 100644
> > --- a/notes.c
> > +++ b/notes.c
> > @@ -1140,14 +1140,20 @@ void load_display_notes(struct display_notes_opt *opt)
> > string_list_clear(&display_notes_refs, 0);
> > }
> >
> > +static struct notes_tree *notes_tree_or_default(struct notes_tree *t)
> > +{
> > + if (!t)
> > + t = &default_notes_tree;
> > + assert(t->initialized);
> > + return t;
> > +}
> > +
> > int add_note(struct notes_tree *t, const struct object_id *object_oid,
> > const struct object_id *note_oid, combine_notes_fn combine_notes)
> > {
> > struct leaf_node *l;
> >
> > - if (!t)
> > - t = &default_notes_tree;
> > - assert(t->initialized);
> > + t = notes_tree_or_default(t);
>
> I somehow thought you would leave assert() outside the helper, which
> might give us a better abstraction in the longer term, but I do not mind
> either way.
>
> As a way to prepare for making copy_note() safer in a later step,
> keeping this step a pure refactoring makes sense.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v5 2/6] notes: store the repository in struct notes_tree
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
2026-11-25 22:02 ` [PATCH v5 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
@ 2026-11-25 22:02 ` Okhuomon Ajayi
2026-11-26 3:17 ` Junio C Hamano
2026-11-25 22:02 ` [PATCH v5 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
` (4 subsequent siblings)
6 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 22:02 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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. Rename init_notes() to
notes_tree_init() and load_notes_trees() to notes_tree_load(),
since every caller changes anyway. notes_tree_init() takes the
tree first and the repository second, and saves the repository
in t->repo. notes_tree_load() takes the repository first.
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 | 30 ++++++++++++++++++------------
notes.h | 15 +++++++++++----
5 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..725280c785 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);
+ notes_tree_init(NULL, the_repository, 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);
+ notes_tree_init(NULL, the_repository, 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);
+ notes_tree_init(&t, the_repository, "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..b9a2940435 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);
+ notes_tree_init(&c->tree, r, ref.buf,
+ combine_notes_overwrite, flags);
strbuf_release(&ref);
}
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..ea43fedd43 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 = notes_tree_load(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 a73a51e1a0..6bfe80f176 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 notes_tree_init(struct notes_tree *t, struct repository *r,
+ 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 **notes_tree_load(struct repository *r,
+ struct string_list *refs, int flags)
{
struct string_list_item *item;
int counter = 0;
@@ -1065,7 +1068,8 @@ 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);
+ notes_tree_init(t, r, item->string,
+ combine_notes_ignore, flags);
trees[counter++] = t;
}
trees[counter] = NULL;
@@ -1136,7 +1140,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 = notes_tree_load(the_repository,
+ &display_notes_refs, 0);
string_list_clear(&display_notes_refs, 0);
}
@@ -1266,7 +1271,8 @@ void free_notes(struct notes_tree *t)
* Fill the given strbuf with the notes associated with the given object.
*
* If the given notes_tree structure is not initialized, it will be auto-
- * initialized to the default value (see documentation for init_notes() above).
+ * initialized to the default value (see documentation for
+ * notes_tree_init() above).
* If the given notes_tree is NULL, the internal/default notes_tree will be
* used instead.
*
@@ -1286,7 +1292,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);
+ notes_tree_init(t, the_repository, NULL, NULL, 0);
oid = get_note(t, object_oid);
if (!oid)
diff --git a/notes.h b/notes.h
index 6dc6d7b265..f4d1e31cd8 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;
@@ -63,7 +64,7 @@ extern struct notes_tree {
* Return the default notes ref.
*
* The default notes ref is the notes ref that is used when notes_ref == NULL
- * is passed to init_notes().
+ * is passed to notes_tree_init().
*
* This the first of the following to be defined:
* 1. The '--ref' option to 'git notes', if given
@@ -100,15 +101,20 @@ char *default_notes_ref(struct repository *repo);
*
* If you pass t == NULL, the default internal notes_tree will be initialized.
*
+ * 'r' is the repository that this notes_tree belongs to.
+ *
* The combine_notes function that is passed becomes the default combine_notes
* function for the given notes_tree. If NULL is passed, the default
* combine_notes function is combine_notes_concatenate().
*
+ * 'flags' is a combination of the NOTES_INIT_* flags above.
+ *
* 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 notes_tree_init(struct notes_tree *t, struct repository *r,
+ const char *notes_ref, combine_notes_fn combine_notes,
+ int flags);
/*
* Add the given note object to the given notes_tree structure
@@ -319,7 +325,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 **notes_tree_load(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] 86+ messages in thread* Re: [PATCH v5 2/6] notes: store the repository in struct notes_tree
2026-11-25 22:02 ` [PATCH v5 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
@ 2026-11-26 3:17 ` Junio C Hamano
0 siblings, 0 replies; 86+ messages in thread
From: Junio C Hamano @ 2026-11-26 3:17 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> 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. Rename init_notes() to
> notes_tree_init() and load_notes_trees() to notes_tree_load(),
> since every caller changes anyway. notes_tree_init() takes the
> tree first and the repository second, and saves the repository
> in t->repo. notes_tree_load() takes the repository first.
> 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 | 30 ++++++++++++++++++------------
> notes.h | 15 +++++++++++----
> 5 files changed, 38 insertions(+), 21 deletions(-)
>
> diff --git a/builtin/notes.c b/builtin/notes.c
> index 9f1f0ec840..725280c785 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);
> + notes_tree_init(NULL, the_repository, NULL, NULL,
> + NOTES_INIT_WRITABLE);
We are doing two things (renaming the API function and passing a
repository instance down) in this same patch. Which is not too bad, as
most of the hunks look like the above, passing the_repository to the
renamed function.
> @@ -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;
Assigning '.repo' before checking NOTES_INIT_EMPTY or calling
load_subtree() makes sure both empty trees and trees loaded at init time
record their repository, and free_notes() already zeroes the entire
struct without owning the repository pointer. All callers of the
renamed notes_tree_init() and notes_tree_load() across builtin/notes.c,
notes-cache.c, notes-utils.c, and notes.c are updated, and the header
comment above notes_tree_init() now documents both 'r' and 'flags'.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v5 3/6] notes: use the tree's repository when reading notes
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
2026-11-25 22:02 ` [PATCH v5 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
2026-11-25 22:02 ` [PATCH v5 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
@ 2026-11-25 22:02 ` Okhuomon Ajayi
2026-11-26 3:37 ` Junio C Hamano
2026-11-25 22:02 ` [PATCH v5 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
` (3 subsequent siblings)
6 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 22:02 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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.
note_tree_find(), add_non_note() and load_subtree() do not check
for a NULL tree themselves. add_note(), remove_note() and
get_note() replace a NULL tree with the default notes tree and
assert that it is initialized before those helpers run.
format_note() does the same NULL swap, and initializes the tree
if it is not already. load_subtree() is also reached when a
lookup unpacks a subtree, which is still after that check.
copy_note() is the one public function that does not do this;
the next patch adds the guard.
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 6bfe80f176..da63d35935 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);
}
@@ -1173,8 +1173,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
struct leaf_node l;
t = notes_tree_or_default(t);
- 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;
@@ -1298,7 +1298,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] 86+ messages in thread* Re: [PATCH v5 3/6] notes: use the tree's repository when reading notes
2026-11-25 22:02 ` [PATCH v5 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
@ 2026-11-26 3:37 ` Junio C Hamano
2026-11-26 20:57 ` Okhuomon Ajayi
0 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-26 3:37 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> 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.
>
> note_tree_find(), add_non_note() and load_subtree() do not check
> for a NULL tree themselves. add_note(), remove_note() and
> get_note() replace a NULL tree with the default notes tree and
> assert that it is initialized before those helpers run.
> format_note() does the same NULL swap, and initializes the tree
> if it is not already. load_subtree() is also reached when a
> lookup unpacks a subtree, which is still after that check.
> copy_note() is the one public function that does not do this;
> the next patch adds the guard.
"A, B, and C do not check for NULL, and D, E, and F do." may not be
stating any lies, but such a description gives a very disorganized
feeling, as readers are not directly told where you are going with
it. Make it clear where the entry points are, who calls leaf
helpers that do not use notes_tree_or_default(), and state that
these callers themselves use notes_tree_or_default() to cope with a
NULL tree. Before going there, step back a bit and give a wider
picture, i.e., have you done enough to make sure readers understand
why notes_tree_or_default() matters in the first place?
In the previous step, we added a '.repo' member to a notes tree
object so that you can tell which repository object you are
working with. The notes tree objects are passed around in
various call chains, but many functions like note_tree_find() do
not pay attention to '.repo' and instead use hardcoded
the_repository.
There is a catch in the existing API contract around notes tree
objects. Passing NULL in place of a notes tree object is
allowed, and tells the API to "use the default notes tree
object". Which means a few things.
- An existing call chain may pass notes tree 't' around, but it
may be NULL. You cannot blindly dereference 't->repo'.
- High-level API entry points like add_note() may receive NULL
in their 't' parameter, but they replace NULL with a pointer
to the default notes tree object by calling
notes_tree_or_default() upon entry, so after that, the use of
't->repo' is (almost) always safe.
- Helper functions that are only called from these API entry
point functions may not check the NULL-ness of 't', but rely
entirely on their callers to have turned NULL into the default
notes tree object.
Now, X, Y, and Z, as we saw in patch [1/6], are the high-level
entry points that guarantee their notes tree pointer always
points at a valid notes tree. A, B, and C are helper functions
that can be reached only from X, Y, and Z. We can replace all
uses of the_repository in these functions with '.repo' safely.
There are some cases where such a replacement is not sufficient.
For example, copy_note(), even though it takes a notes tree
object, does not use 't' itself, so it does not bother calling
notes_tree_or_default() to ensure that 't' is a valid notes tree
object. In order to replace its reference to the_repository
with '.repo', we would need to do such and such things, which
will be done in later steps.
or something like that, perhaps.
^ permalink raw reply [flat|nested] 86+ messages in thread* Re: [PATCH v5 3/6] notes: use the tree's repository when reading notes
2026-11-26 3:37 ` Junio C Hamano
@ 2026-11-26 20:57 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 20:57 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Junio C Hamano <gitster@pobox.com> writes:
> "A, B, and C do not check for NULL, and D, E, and F do." [...] step
> back a bit and give a wider picture [...]
Thanks, that's much clearer. I'll rewrite it along those lines for the
next round: the wider picture first, then the entry points versus the
leaf helpers, with copy_note() as the exception.
Thanks for writing it out.
On Thu, Nov 26, 2026 at 4:37 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > 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.
> >
> > note_tree_find(), add_non_note() and load_subtree() do not check
> > for a NULL tree themselves. add_note(), remove_note() and
> > get_note() replace a NULL tree with the default notes tree and
> > assert that it is initialized before those helpers run.
> > format_note() does the same NULL swap, and initializes the tree
> > if it is not already. load_subtree() is also reached when a
> > lookup unpacks a subtree, which is still after that check.
> > copy_note() is the one public function that does not do this;
> > the next patch adds the guard.
>
> "A, B, and C do not check for NULL, and D, E, and F do." may not be
> stating any lies, but such a description gives a very disorganized
> feeling, as readers are not directly told where you are going with
> it. Make it clear where the entry points are, who calls leaf
> helpers that do not use notes_tree_or_default(), and state that
> these callers themselves use notes_tree_or_default() to cope with a
> NULL tree. Before going there, step back a bit and give a wider
> picture, i.e., have you done enough to make sure readers understand
> why notes_tree_or_default() matters in the first place?
>
> In the previous step, we added a '.repo' member to a notes tree
> object so that you can tell which repository object you are
> working with. The notes tree objects are passed around in
> various call chains, but many functions like note_tree_find() do
> not pay attention to '.repo' and instead use hardcoded
> the_repository.
>
> There is a catch in the existing API contract around notes tree
> objects. Passing NULL in place of a notes tree object is
> allowed, and tells the API to "use the default notes tree
> object". Which means a few things.
>
> - An existing call chain may pass notes tree 't' around, but it
> may be NULL. You cannot blindly dereference 't->repo'.
>
> - High-level API entry points like add_note() may receive NULL
> in their 't' parameter, but they replace NULL with a pointer
> to the default notes tree object by calling
> notes_tree_or_default() upon entry, so after that, the use of
> 't->repo' is (almost) always safe.
>
> - Helper functions that are only called from these API entry
> point functions may not check the NULL-ness of 't', but rely
> entirely on their callers to have turned NULL into the default
> notes tree object.
>
> Now, X, Y, and Z, as we saw in patch [1/6], are the high-level
> entry points that guarantee their notes tree pointer always
> points at a valid notes tree. A, B, and C are helper functions
> that can be reached only from X, Y, and Z. We can replace all
> uses of the_repository in these functions with '.repo' safely.
>
> There are some cases where such a replacement is not sufficient.
> For example, copy_note(), even though it takes a notes tree
> object, does not use 't' itself, so it does not bother calling
> notes_tree_or_default() to ensure that 't' is a valid notes tree
> object. In order to replace its reference to the_repository
> with '.repo', we would need to do such and such things, which
> will be done in later steps.
>
> or something like that, perhaps.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v5 4/6] notes: use the tree's repository when writing and pruning
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
` (2 preceding siblings ...)
2026-11-25 22:02 ` [PATCH v5 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
@ 2026-11-25 22:02 ` Okhuomon Ajayi
2026-11-25 22:02 ` [PATCH v5 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
` (2 subsequent siblings)
6 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 22:02 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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.
copy_note() also writes through the tree, by calling add_note(),
so it uses the tree's hash algorithm for its null object ID.
It now takes a NULL tree the same way as the other entry points,
through notes_tree_or_default(), before reading the tree's
repository.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 71 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 44 insertions(+), 27 deletions(-)
diff --git a/notes.c b/notes.c
index da63d35935..1cdf09c81c 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;
}
@@ -1212,6 +1221,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;
@@ -1221,8 +1231,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;
@@ -1230,23 +1240,24 @@ 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 };
t = notes_tree_or_default(t);
- 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;
}
}
@@ -1355,8 +1366,13 @@ int copy_note(struct notes_tree *t,
const struct object_id *from_obj, const struct object_id *to_obj,
int force, combine_notes_fn combine_notes)
{
- const struct object_id *note = get_note(t, from_obj);
- const struct object_id *existing_note = get_note(t, to_obj);
+ const struct object_id *note;
+ const struct object_id *existing_note;
+
+ t = notes_tree_or_default(t);
+
+ note = get_note(t, from_obj);
+ existing_note = get_note(t, to_obj);
if (!force && existing_note)
return 1;
@@ -1364,7 +1380,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;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 86+ messages in thread* [PATCH v5 5/6] notes: pass the repository to the ref glob helpers
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
` (3 preceding siblings ...)
2026-11-25 22:02 ` [PATCH v5 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
@ 2026-11-25 22:02 ` Okhuomon Ajayi
2026-11-25 22:02 ` [PATCH v5 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-26 3:57 ` [PATCH v5 0/6] notes: start passing the repository through notes.[ch] Junio C Hamano
6 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 22:02 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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 ea43fedd43..9f70366aa9 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 1cdf09c81c..f327652994 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;
@@ -1133,7 +1136,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
@@ -1145,7 +1149,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 f4d1e31cd8..30adf0c197 100644
--- a/notes.h
+++ b/notes.h
@@ -331,14 +331,16 @@ struct notes_tree **notes_tree_load(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] 86+ messages in thread* [PATCH v5 6/6] notes: pass the repository to the combine_notes callbacks
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
` (4 preceding siblings ...)
2026-11-25 22:02 ` [PATCH v5 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
@ 2026-11-25 22:02 ` Okhuomon Ajayi
2026-11-26 3:57 ` [PATCH v5 0/6] notes: start passing the repository through notes.[ch] Junio C Hamano
6 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-25 22:02 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 31 ++++++++++++++++++-------------
notes.h | 23 ++++++++++++++---------
2 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/notes.c b/notes.c
index f327652994..25e5873ac2 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:
diff --git a/notes.h b/notes.h
index 30adf0c197..3eb73adf54 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] 86+ messages in thread* Re: [PATCH v5 0/6] notes: start passing the repository through notes.[ch]
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
` (5 preceding siblings ...)
2026-11-25 22:02 ` [PATCH v5 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
@ 2026-11-26 3:57 ` Junio C Hamano
2026-11-26 21:07 ` Okhuomon Ajayi
6 siblings, 1 reply; 86+ messages in thread
From: Junio C Hamano @ 2026-11-26 3:57 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> What is left for future series:
> - notes.c: the display-notes code keeps its state in globals, and log,
> format-patch, diff-tree and format-rev are given a repository but do
> not pass it on. format_note() still falls back to the global
> default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
> The hash-size helpers are also still on the global.
> - notes-utils.[c,h]: still use the_repository. And the hash-size helpers
> still on the global are reached from here, through create_notes_commit()
> -> write_notes_tree(), so converting notes-utils is tied to converting
> those helpers too.
Inside load_subtree(), the KEY_INDEX and SUBTREE_SHA1_PREFIXCMP macros
still derive the prefix-length byte offset from the_hash_algo, even
though hashsz now comes from t->repo->hash_algo, so converting KEY_INDEX
together with the other hash-size helpers will be important before
mixing repositories with different hash algorithms.
^ permalink raw reply [flat|nested] 86+ messages in thread* Re: [PATCH v5 0/6] notes: start passing the repository through notes.[ch]
2026-11-26 3:57 ` [PATCH v5 0/6] notes: start passing the repository through notes.[ch] Junio C Hamano
@ 2026-11-26 21:07 ` Okhuomon Ajayi
0 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 21:07 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, christian.couder, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Junio C Hamano <gitster@pobox.com> writes:
> Inside load_subtree(), the KEY_INDEX and SUBTREE_SHA1_PREFIXCMP macros
> still derive the prefix-length byte offset from the_hash_algo, even
> though hashsz now comes from t->repo->hash_algo, so converting KEY_INDEX
> together with the other hash-size helpers will be important before
> mixing repositories with different hash algorithms.
Right, I'll add the KEY_INDEX and SUBTREE_SHA1_PREFIXCMP macros to the
"what is left" list in the cover letter, since they still read
the_hash_algo and should move together with the hash-size helpers before
a notes tree can mix hash algorithms.
Thanks.
On Thu, Nov 26, 2026 at 4:57 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > What is left for future series:
> > - notes.c: the display-notes code keeps its state in globals, and log,
> > format-patch, diff-tree and format-rev are given a repository but do
> > not pass it on. format_note() still falls back to the global
> > default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
> > The hash-size helpers are also still on the global.
> > - notes-utils.[c,h]: still use the_repository. And the hash-size helpers
> > still on the global are reached from here, through create_notes_commit()
> > -> write_notes_tree(), so converting notes-utils is tied to converting
> > those helpers too.
>
> Inside load_subtree(), the KEY_INDEX and SUBTREE_SHA1_PREFIXCMP macros
> still derive the prefix-length byte offset from the_hash_algo, even
> though hashsz now comes from t->repo->hash_algo, so converting KEY_INDEX
> together with the other hash-size helpers will be important before
> mixing repositories with different hash algorithms.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v6 0/6] notes: start passing the repository through notes.[ch]
2026-11-24 17:21 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
` (7 preceding siblings ...)
2026-11-25 22:02 ` [PATCH v5 0/6] " Okhuomon Ajayi
@ 2026-11-26 21:33 ` Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
` (7 more replies)
8 siblings, 8 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 21:33 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
This is a preparatory series. It makes the code in notes.[c,h] and its
direct callers work on the repository stored in struct notes_tree instead
of the_repository. It deliberately does not convert the whole notes
subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
rest for future series.
What it does:
- stores the repository in struct notes_tree;
- uses the tree's repository when reading, writing and pruning notes;
- passes the repository to the ref glob helpers and the combine_notes
callbacks.
What is left for future series:
- notes.c: the display-notes code keeps its state in globals, and log,
format-patch, diff-tree and format-rev are given a repository but do
not pass it on. format_note() still falls back to the global
default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
The hash-size helpers are also still on the global, and the KEY_INDEX
and SUBTREE_SHA1_PREFIXCMP macros in load_subtree() still derive their
byte offset from the_hash_algo, so they need to move together with
those helpers before a notes tree can mix hash algorithms.
- notes-utils.[c,h]: still use the_repository. And the hash-size helpers
still on the global are reached from here, through create_notes_commit()
-> write_notes_tree(), so converting notes-utils is tied to converting
those helpers too.
- notes-merge.[c,h]: still work on the global repository.
- notes-cache.c: notes_cache_init() passes its repository through, but
notes_cache_match_validity(), notes_cache_write(), notes_cache_get()
and notes_cache_put() still use the_repository.
Changes since v5:
- Rewrite the reading patch's log message to give the wider picture
first (the '.repo' member, the NULL-tree contract, and the entry
points vs. the leaf helpers) rather than listing functions, per
review.
- Fix the helper patch's log message to call the function init_notes()
at that step; the rename to notes_tree_init() lands in the next patch.
- Note the KEY_INDEX and SUBTREE_SHA1_PREFIXCMP macros under what is
left for a future series.
Changes since v4:
- Add notes_tree_or_default() and use it for the repeated NULL-tree
check. copy_note() uses that helper for its new guard.
- Document 'r' and 'flags' above notes_tree_init().
- Explain in the reading patch why the converted helpers are safe when
the tree is NULL. copy_note() was the exception.
- List notes-cache.c with what is left for a future series.
Okhuomon Ajayi (6):
notes: add notes_tree_or_default()
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
builtin/notes.c | 8 +-
notes-cache.c | 3 +-
notes-utils.c | 9 ++-
notes.c | 205 +++++++++++++++++++++++++++---------------------
notes.h | 44 +++++++----
5 files changed, 159 insertions(+), 110 deletions(-)
Range-diff against v5:
1: c9891e887c ! 1: 1d17c6b7db notes: add notes_tree_or_default()
@@ Commit message
means the default notes tree, and the tree must already be
initialized.
- Use one helper for that check. notes_tree_init() asserts that
- the tree is not yet initialized, free_notes() only frees what is
- there, and format_note() initializes the tree when it is not, so
- those three keep their own checks.
+ Use one helper for that check. init_notes() asserts that the tree is
+ not yet initialized, free_notes() only frees what is there, and
+ format_note() initializes the tree when it is not, so those three keep
+ their own checks.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
2: 831db4c68a = 2: 124381fdcc notes: store the repository in struct notes_tree
3: 82f6f6ea7c ! 3: 93afb08fb9 notes: use the tree's repository when reading notes
@@ Metadata
## Commit message ##
notes: use the tree's repository when reading notes
- 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.
+ In the previous step we added a '.repo' member to struct notes_tree
+ so a notes tree records which repository it belongs to. Notes trees
+ are passed down many call chains, but functions like note_tree_find()
+ still read objects and hash algorithms from the_repository.
- Read them from t->repo, the repository stored on the tree.
+ There is a catch in the notes API's NULL contract. Passing NULL in
+ place of a notes tree is allowed and means "use the default notes
+ tree", so a 't' handed around a call chain may be NULL and 't->repo'
+ cannot be dereferenced blindly. The high-level entry points cope with
+ this: add_note(), remove_note() and get_note() replace a NULL 't'
+ with the default notes tree via notes_tree_or_default() on entry, so
+ afterwards 't->repo' is safe. The internal format_note() does the
+ same swap and initializes the tree if needed. The leaf helpers
+ note_tree_find(), add_non_note() and load_subtree() do not check for
+ NULL themselves; they rely on being reached only through those entry
+ points (get_note() -> note_tree_find(), and note_tree_search() lazily
+ unpacking a subtree through load_subtree(), still after the tree has
+ been resolved).
- note_tree_find(), add_non_note() and load_subtree() do not check
- for a NULL tree themselves. add_note(), remove_note() and
- get_note() replace a NULL tree with the default notes tree and
- assert that it is initialized before those helpers run.
- format_note() does the same NULL swap, and initializes the tree
- if it is not already. load_subtree() is also reached when a
- lookup unpacks a subtree, which is still after that check.
- copy_note() is the one public function that does not do this;
- the next patch adds the guard.
+ Given those guarantees, read objects and hash algorithms from t->repo
+ instead of the_repository in note_tree_find(), add_non_note(),
+ load_subtree(), remove_note() and format_note().
+
+ copy_note() also takes a notes tree but does not resolve NULL before
+ using it, so a mechanical the_repository -> t->repo replacement there
+ would be unsafe; it is handled in the next patch.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
4: b35eb50a45 = 4: 1cea119abf notes: use the tree's repository when writing and pruning
5: dcda05343a = 5: 1d2ecbe2a5 notes: pass the repository to the ref glob helpers
6: 69928b58f6 = 6: 8b59b9ba01 notes: pass the repository to the combine_notes callbacks
--
2.56.0
^ permalink raw reply [flat|nested] 86+ messages in thread* [PATCH v6 1/6] notes: add notes_tree_or_default()
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
@ 2026-11-26 21:33 ` Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
` (6 subsequent siblings)
7 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 21:33 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
Several notes entry points repeat the same check: a NULL tree
means the default notes tree, and the tree must already be
initialized.
Use one helper for that check. init_notes() asserts that the tree is
not yet initialized, free_notes() only frees what is there, and
format_note() initializes the tree when it is not, so those three keep
their own checks.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/notes.c b/notes.c
index ec9c2cb150..a73a51e1a0 100644
--- a/notes.c
+++ b/notes.c
@@ -1140,14 +1140,20 @@ void load_display_notes(struct display_notes_opt *opt)
string_list_clear(&display_notes_refs, 0);
}
+static struct notes_tree *notes_tree_or_default(struct notes_tree *t)
+{
+ if (!t)
+ t = &default_notes_tree;
+ assert(t->initialized);
+ return t;
+}
+
int add_note(struct notes_tree *t, const struct object_id *object_oid,
const struct object_id *note_oid, combine_notes_fn combine_notes)
{
struct leaf_node *l;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
t->dirty = 1;
if (!combine_notes)
combine_notes = t->combine_notes;
@@ -1161,9 +1167,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
{
struct leaf_node l;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
oidclr(&l.val_oid, the_repository->hash_algo);
note_tree_remove(t, t->root, 0, &l);
@@ -1178,9 +1182,7 @@ const struct object_id *get_note(struct notes_tree *t,
{
struct leaf_node *found;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
found = note_tree_find(t, t->root, 0, oid->hash);
return found ? &found->val_oid : NULL;
}
@@ -1188,9 +1190,7 @@ const struct object_id *get_note(struct notes_tree *t,
int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
void *cb_data)
{
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
}
@@ -1201,9 +1201,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
int ret;
int flags;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
/* Prepare for traversal of current notes tree */
root.next = NULL; /* last forward entry in list is grounded */
@@ -1229,9 +1227,7 @@ void prune_notes(struct notes_tree *t, int flags)
{
struct note_delete_list *l = NULL;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
for_each_note(t, 0, prune_notes_helper, &l);
--
2.56.0
^ permalink raw reply related [flat|nested] 86+ messages in thread* [PATCH v6 2/6] notes: store the repository in struct notes_tree
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
@ 2026-11-26 21:33 ` Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
` (5 subsequent siblings)
7 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 21:33 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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. Rename init_notes() to
notes_tree_init() and load_notes_trees() to notes_tree_load(),
since every caller changes anyway. notes_tree_init() takes the
tree first and the repository second, and saves the repository
in t->repo. notes_tree_load() takes the repository first.
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 | 30 ++++++++++++++++++------------
notes.h | 15 +++++++++++----
5 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..725280c785 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);
+ notes_tree_init(NULL, the_repository, 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);
+ notes_tree_init(NULL, the_repository, 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);
+ notes_tree_init(&t, the_repository, "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..b9a2940435 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);
+ notes_tree_init(&c->tree, r, ref.buf,
+ combine_notes_overwrite, flags);
strbuf_release(&ref);
}
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..ea43fedd43 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 = notes_tree_load(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 a73a51e1a0..6bfe80f176 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 notes_tree_init(struct notes_tree *t, struct repository *r,
+ 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 **notes_tree_load(struct repository *r,
+ struct string_list *refs, int flags)
{
struct string_list_item *item;
int counter = 0;
@@ -1065,7 +1068,8 @@ 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);
+ notes_tree_init(t, r, item->string,
+ combine_notes_ignore, flags);
trees[counter++] = t;
}
trees[counter] = NULL;
@@ -1136,7 +1140,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 = notes_tree_load(the_repository,
+ &display_notes_refs, 0);
string_list_clear(&display_notes_refs, 0);
}
@@ -1266,7 +1271,8 @@ void free_notes(struct notes_tree *t)
* Fill the given strbuf with the notes associated with the given object.
*
* If the given notes_tree structure is not initialized, it will be auto-
- * initialized to the default value (see documentation for init_notes() above).
+ * initialized to the default value (see documentation for
+ * notes_tree_init() above).
* If the given notes_tree is NULL, the internal/default notes_tree will be
* used instead.
*
@@ -1286,7 +1292,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);
+ notes_tree_init(t, the_repository, NULL, NULL, 0);
oid = get_note(t, object_oid);
if (!oid)
diff --git a/notes.h b/notes.h
index 6dc6d7b265..f4d1e31cd8 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;
@@ -63,7 +64,7 @@ extern struct notes_tree {
* Return the default notes ref.
*
* The default notes ref is the notes ref that is used when notes_ref == NULL
- * is passed to init_notes().
+ * is passed to notes_tree_init().
*
* This the first of the following to be defined:
* 1. The '--ref' option to 'git notes', if given
@@ -100,15 +101,20 @@ char *default_notes_ref(struct repository *repo);
*
* If you pass t == NULL, the default internal notes_tree will be initialized.
*
+ * 'r' is the repository that this notes_tree belongs to.
+ *
* The combine_notes function that is passed becomes the default combine_notes
* function for the given notes_tree. If NULL is passed, the default
* combine_notes function is combine_notes_concatenate().
*
+ * 'flags' is a combination of the NOTES_INIT_* flags above.
+ *
* 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 notes_tree_init(struct notes_tree *t, struct repository *r,
+ const char *notes_ref, combine_notes_fn combine_notes,
+ int flags);
/*
* Add the given note object to the given notes_tree structure
@@ -319,7 +325,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 **notes_tree_load(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] 86+ messages in thread* [PATCH v6 3/6] notes: use the tree's repository when reading notes
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
@ 2026-11-26 21:33 ` Okhuomon Ajayi
2026-11-27 13:13 ` Christian Couder
2026-11-26 21:33 ` [PATCH v6 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
` (4 subsequent siblings)
7 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 21:33 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
In the previous step we added a '.repo' member to struct notes_tree
so a notes tree records which repository it belongs to. Notes trees
are passed down many call chains, but functions like note_tree_find()
still read objects and hash algorithms from the_repository.
There is a catch in the notes API's NULL contract. Passing NULL in
place of a notes tree is allowed and means "use the default notes
tree", so a 't' handed around a call chain may be NULL and 't->repo'
cannot be dereferenced blindly. The high-level entry points cope with
this: add_note(), remove_note() and get_note() replace a NULL 't'
with the default notes tree via notes_tree_or_default() on entry, so
afterwards 't->repo' is safe. The internal format_note() does the
same swap and initializes the tree if needed. The leaf helpers
note_tree_find(), add_non_note() and load_subtree() do not check for
NULL themselves; they rely on being reached only through those entry
points (get_note() -> note_tree_find(), and note_tree_search() lazily
unpacking a subtree through load_subtree(), still after the tree has
been resolved).
Given those guarantees, read objects and hash algorithms from t->repo
instead of the_repository in note_tree_find(), add_non_note(),
load_subtree(), remove_note() and format_note().
copy_note() also takes a notes tree but does not resolve NULL before
using it, so a mechanical the_repository -> t->repo replacement there
would be unsafe; it is handled in the next patch.
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 6bfe80f176..da63d35935 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);
}
@@ -1173,8 +1173,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
struct leaf_node l;
t = notes_tree_or_default(t);
- 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;
@@ -1298,7 +1298,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] 86+ messages in thread* Re: [PATCH v6 3/6] notes: use the tree's repository when reading notes
2026-11-26 21:33 ` [PATCH v6 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
@ 2026-11-27 13:13 ` Christian Couder
0 siblings, 0 replies; 86+ messages in thread
From: Christian Couder @ 2026-11-27 13:13 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, ps, gitster, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Thu, Nov 26, 2026 at 10:33 PM Okhuomon Ajayi
<okhuomonajayi54@gmail.com> wrote:
>
> In the previous step we added a '.repo' member to struct notes_tree
> so a notes tree records which repository it belongs to. Notes trees
> are passed down many call chains, but functions like note_tree_find()
> still read objects and hash algorithms from the_repository.
>
> There is a catch in the notes API's NULL contract. Passing NULL in
> place of a notes tree is allowed and means "use the default notes
> tree", so a 't' handed around a call chain may be NULL and 't->repo'
> cannot be dereferenced blindly.
Looking good so far.
> The high-level entry points cope with
> this: add_note(), remove_note() and get_note() replace a NULL 't'
> with the default notes tree via notes_tree_or_default() on entry, so
> afterwards 't->repo' is safe. The internal format_note() does the
> same swap and initializes the tree if needed.
As notes_tree_or_default() was introduced earlier, I think it would be
simpler and a bit better to just say something like the following
instead:
"A previous commit introduced a notes_tree_or_default() helper to cope
with this, and ensured all the high-level entry points (except
copy_note(), see below), as well as the internal format_note(), call
this helper."
> The leaf helpers
> note_tree_find(), add_non_note() and load_subtree() do not check for
> NULL themselves; they rely on being reached only through those entry
> points (get_note() -> note_tree_find(), and note_tree_search() lazily
Maybe add "for example" before "get_note() -> note_tree_find()" as
these are just examples.
> unpacking a subtree through load_subtree(), still after the tree has
> been resolved).
Otherwise the whole v6 series looks good to me now.
Not sure it's worth sending a v7 for the commit message improvements I
suggested above.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v6 4/6] notes: use the tree's repository when writing and pruning
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
` (2 preceding siblings ...)
2026-11-26 21:33 ` [PATCH v6 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
@ 2026-11-26 21:33 ` Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
` (3 subsequent siblings)
7 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 21:33 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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.
copy_note() also writes through the tree, by calling add_note(),
so it uses the tree's hash algorithm for its null object ID.
It now takes a NULL tree the same way as the other entry points,
through notes_tree_or_default(), before reading the tree's
repository.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 71 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 44 insertions(+), 27 deletions(-)
diff --git a/notes.c b/notes.c
index da63d35935..1cdf09c81c 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;
}
@@ -1212,6 +1221,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;
@@ -1221,8 +1231,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;
@@ -1230,23 +1240,24 @@ 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 };
t = notes_tree_or_default(t);
- 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;
}
}
@@ -1355,8 +1366,13 @@ int copy_note(struct notes_tree *t,
const struct object_id *from_obj, const struct object_id *to_obj,
int force, combine_notes_fn combine_notes)
{
- const struct object_id *note = get_note(t, from_obj);
- const struct object_id *existing_note = get_note(t, to_obj);
+ const struct object_id *note;
+ const struct object_id *existing_note;
+
+ t = notes_tree_or_default(t);
+
+ note = get_note(t, from_obj);
+ existing_note = get_note(t, to_obj);
if (!force && existing_note)
return 1;
@@ -1364,7 +1380,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;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 86+ messages in thread* [PATCH v6 5/6] notes: pass the repository to the ref glob helpers
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
` (3 preceding siblings ...)
2026-11-26 21:33 ` [PATCH v6 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
@ 2026-11-26 21:33 ` Okhuomon Ajayi
2026-11-26 21:33 ` [PATCH v6 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
` (2 subsequent siblings)
7 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 21:33 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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 ea43fedd43..9f70366aa9 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 1cdf09c81c..f327652994 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;
@@ -1133,7 +1136,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
@@ -1145,7 +1149,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 f4d1e31cd8..30adf0c197 100644
--- a/notes.h
+++ b/notes.h
@@ -331,14 +331,16 @@ struct notes_tree **notes_tree_load(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] 86+ messages in thread* [PATCH v6 6/6] notes: pass the repository to the combine_notes callbacks
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
` (4 preceding siblings ...)
2026-11-26 21:33 ` [PATCH v6 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
@ 2026-11-26 21:33 ` Okhuomon Ajayi
2026-11-27 13:22 ` [PATCH v6 0/6] notes: start passing the repository through notes.[ch] Christian Couder
2026-11-27 22:04 ` [PATCH v7 " Okhuomon Ajayi
7 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-26 21:33 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 31 ++++++++++++++++++-------------
notes.h | 23 ++++++++++++++---------
2 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/notes.c b/notes.c
index f327652994..25e5873ac2 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:
diff --git a/notes.h b/notes.h
index 30adf0c197..3eb73adf54 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] 86+ messages in thread* Re: [PATCH v6 0/6] notes: start passing the repository through notes.[ch]
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
` (5 preceding siblings ...)
2026-11-26 21:33 ` [PATCH v6 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
@ 2026-11-27 13:22 ` Christian Couder
2026-11-27 13:52 ` Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 " Okhuomon Ajayi
7 siblings, 1 reply; 86+ messages in thread
From: Christian Couder @ 2026-11-27 13:22 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: git, ps, gitster, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Thu, Nov 26, 2026 at 10:33 PM Okhuomon Ajayi
<okhuomonajayi54@gmail.com> wrote:
> Changes since v5:
> - Rewrite the reading patch's log message to give the wider picture
> first (the '.repo' member, the NULL-tree contract, and the entry
> points vs. the leaf helpers) rather than listing functions, per
> review.
> - Fix the helper patch's log message to call the function init_notes()
> at that step; the rename to notes_tree_init() lands in the next patch.
> - Note the KEY_INDEX and SUBTREE_SHA1_PREFIXCMP macros under what is
> left for a future series.
Except for a few small issues in the commit message of patch 3/6, this
looks good to me. Thanks.
This email has the following "In-Reply-To" header though:
In-Reply-To: <20261124172146.18330-1-okhuomonajayi54@gmail.com>
which is the message ID of the v2 cover letter, instead of the v5 cover letter.
So in case you send a v7, please make sure the "In-Reply-To" of its
cover letter is the message ID of this v6 cover letter.
Thanks.
^ permalink raw reply [flat|nested] 86+ messages in thread* Re: [PATCH v6 0/6] notes: start passing the repository through notes.[ch]
2026-11-27 13:22 ` [PATCH v6 0/6] notes: start passing the repository through notes.[ch] Christian Couder
@ 2026-11-27 13:52 ` Okhuomon Ajayi
2026-11-27 18:19 ` Junio C Hamano
0 siblings, 1 reply; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-27 13:52 UTC (permalink / raw)
To: Christian Couder
Cc: git, ps, gitster, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
On Fri, Nov 27, 2026 at 2:22 PM Christian Couder
<christian.couder@gmail.com> wrote:
> So in case you send a v7, please make sure the "In-Reply-To" of its
> cover letter is the message ID of this v6 cover letter.
Thanks for the review and for pointing this out.
I'll make the necessary corrections to the commit message
and ensure the v7 cover letter is properly threaded under
this v6 cover letter if another revision is needed.
Okhuomon
^ permalink raw reply [flat|nested] 86+ messages in thread
* Re: [PATCH v6 0/6] notes: start passing the repository through notes.[ch]
2026-11-27 13:52 ` Okhuomon Ajayi
@ 2026-11-27 18:19 ` Junio C Hamano
0 siblings, 0 replies; 86+ messages in thread
From: Junio C Hamano @ 2026-11-27 18:19 UTC (permalink / raw)
To: Okhuomon Ajayi
Cc: Christian Couder, git, ps, usmanakinyemi202, siddharthasthana31,
kaartic.sivaraam
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> On Fri, Nov 27, 2026 at 2:22 PM Christian Couder
> <christian.couder@gmail.com> wrote:
>
>> So in case you send a v7, please make sure the "In-Reply-To" of its
>> cover letter is the message ID of this v6 cover letter.
>
> Thanks for the review and for pointing this out.
> I'll make the necessary corrections to the commit message
> and ensure the v7 cover letter is properly threaded under
> this v6 cover letter if another revision is needed.
Thanks for writing and reviewing. Good to see contributors working well
together.
^ permalink raw reply [flat|nested] 86+ messages in thread
* [PATCH v7 0/6] notes: start passing the repository through notes.[ch]
2026-11-26 21:33 ` [PATCH v6 " Okhuomon Ajayi
` (6 preceding siblings ...)
2026-11-27 13:22 ` [PATCH v6 0/6] notes: start passing the repository through notes.[ch] Christian Couder
@ 2026-11-27 22:04 ` Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
` (5 more replies)
7 siblings, 6 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-27 22:04 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
This is a preparatory series. It makes the code in notes.[c,h] and its
direct callers work on the repository stored in struct notes_tree instead
of the_repository. It deliberately does not convert the whole notes
subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
rest for future series.
What it does:
- stores the repository in struct notes_tree;
- uses the tree's repository when reading, writing and pruning notes;
- passes the repository to the ref glob helpers and the combine_notes
callbacks.
What is left for future series:
- notes.c: the display-notes code keeps its state in globals, and log,
format-patch, diff-tree and format-rev are given a repository but do
not pass it on. format_note() still falls back to the global
default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
The hash-size helpers are also still on the global, and the KEY_INDEX
and SUBTREE_SHA1_PREFIXCMP macros in load_subtree() still derive their
byte offset from the_hash_algo, so they need to move together with
those helpers before a notes tree can mix hash algorithms.
- notes-utils.[c,h]: still use the_repository. And the hash-size helpers
still on the global are reached from here, through create_notes_commit()
-> write_notes_tree(), so converting notes-utils is tied to converting
those helpers too.
- notes-merge.[c,h]: still work on the global repository.
- notes-cache.c: notes_cache_init() passes its repository through, but
notes_cache_match_validity(), notes_cache_write(), notes_cache_get()
and notes_cache_put() still use the_repository.
Changes since v6:
- Reword the reading patch's (3/6) log message, per review: describe the
notes_tree_or_default() helper that an earlier patch introduced more
directly, and mark the get_note() -> note_tree_find() call chain as an
example.
Changes since v5:
- Rewrite the reading patch's log message to give the wider picture
first (the '.repo' member, the NULL-tree contract, and the entry
points vs. the leaf helpers) rather than listing functions, per
review.
- Fix the helper patch's log message to call the function init_notes()
at that step; the rename to notes_tree_init() lands in the next patch.
- Note the KEY_INDEX and SUBTREE_SHA1_PREFIXCMP macros under what is
left for a future series.
Okhuomon Ajayi (6):
notes: add notes_tree_or_default()
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
builtin/notes.c | 8 +-
notes-cache.c | 3 +-
notes-utils.c | 9 ++-
notes.c | 205 +++++++++++++++++++++++++++---------------------
notes.h | 44 +++++++----
5 files changed, 159 insertions(+), 110 deletions(-)
Range-diff against v6:
1: 1d17c6b7db = 1: 1d17c6b7db notes: add notes_tree_or_default()
2: 124381fdcc = 2: 124381fdcc notes: store the repository in struct notes_tree
3: 93afb08fb9 ! 3: 0dfe9934ce notes: use the tree's repository when reading notes
@@ Commit message
There is a catch in the notes API's NULL contract. Passing NULL in
place of a notes tree is allowed and means "use the default notes
tree", so a 't' handed around a call chain may be NULL and 't->repo'
- cannot be dereferenced blindly. The high-level entry points cope with
- this: add_note(), remove_note() and get_note() replace a NULL 't'
- with the default notes tree via notes_tree_or_default() on entry, so
- afterwards 't->repo' is safe. The internal format_note() does the
- same swap and initializes the tree if needed. The leaf helpers
+ cannot be dereferenced blindly. A previous commit introduced a
+ notes_tree_or_default() helper to cope with this, and ensured all the
+ high-level entry points (except copy_note(), see below), as well as
+ the internal format_note(), call this helper. The leaf helpers
note_tree_find(), add_non_note() and load_subtree() do not check for
NULL themselves; they rely on being reached only through those entry
- points (get_note() -> note_tree_find(), and note_tree_search() lazily
- unpacking a subtree through load_subtree(), still after the tree has
- been resolved).
+ points (for example get_note() -> note_tree_find(), and
+ note_tree_search() lazily unpacking a subtree through load_subtree(),
+ still after the tree has been resolved).
Given those guarantees, read objects and hash algorithms from t->repo
instead of the_repository in note_tree_find(), add_non_note(),
4: 1cea119abf = 4: 494e142cf8 notes: use the tree's repository when writing and pruning
5: 1d2ecbe2a5 = 5: 2e38f08ca5 notes: pass the repository to the ref glob helpers
6: 8b59b9ba01 = 6: 30e785c788 notes: pass the repository to the combine_notes callbacks
--
2.56.0
^ permalink raw reply [flat|nested] 86+ messages in thread* [PATCH v7 1/6] notes: add notes_tree_or_default()
2026-11-27 22:04 ` [PATCH v7 " Okhuomon Ajayi
@ 2026-11-27 22:04 ` Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
` (4 subsequent siblings)
5 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-27 22:04 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
Several notes entry points repeat the same check: a NULL tree
means the default notes tree, and the tree must already be
initialized.
Use one helper for that check. init_notes() asserts that the tree is
not yet initialized, free_notes() only frees what is there, and
format_note() initializes the tree when it is not, so those three keep
their own checks.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/notes.c b/notes.c
index ec9c2cb150..a73a51e1a0 100644
--- a/notes.c
+++ b/notes.c
@@ -1140,14 +1140,20 @@ void load_display_notes(struct display_notes_opt *opt)
string_list_clear(&display_notes_refs, 0);
}
+static struct notes_tree *notes_tree_or_default(struct notes_tree *t)
+{
+ if (!t)
+ t = &default_notes_tree;
+ assert(t->initialized);
+ return t;
+}
+
int add_note(struct notes_tree *t, const struct object_id *object_oid,
const struct object_id *note_oid, combine_notes_fn combine_notes)
{
struct leaf_node *l;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
t->dirty = 1;
if (!combine_notes)
combine_notes = t->combine_notes;
@@ -1161,9 +1167,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
{
struct leaf_node l;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
oidclr(&l.val_oid, the_repository->hash_algo);
note_tree_remove(t, t->root, 0, &l);
@@ -1178,9 +1182,7 @@ const struct object_id *get_note(struct notes_tree *t,
{
struct leaf_node *found;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
found = note_tree_find(t, t->root, 0, oid->hash);
return found ? &found->val_oid : NULL;
}
@@ -1188,9 +1190,7 @@ const struct object_id *get_note(struct notes_tree *t,
int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
void *cb_data)
{
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
}
@@ -1201,9 +1201,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
int ret;
int flags;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
/* Prepare for traversal of current notes tree */
root.next = NULL; /* last forward entry in list is grounded */
@@ -1229,9 +1227,7 @@ void prune_notes(struct notes_tree *t, int flags)
{
struct note_delete_list *l = NULL;
- if (!t)
- t = &default_notes_tree;
- assert(t->initialized);
+ t = notes_tree_or_default(t);
for_each_note(t, 0, prune_notes_helper, &l);
--
2.56.0
^ permalink raw reply related [flat|nested] 86+ messages in thread* [PATCH v7 2/6] notes: store the repository in struct notes_tree
2026-11-27 22:04 ` [PATCH v7 " Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
@ 2026-11-27 22:04 ` Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
` (3 subsequent siblings)
5 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-27 22:04 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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. Rename init_notes() to
notes_tree_init() and load_notes_trees() to notes_tree_load(),
since every caller changes anyway. notes_tree_init() takes the
tree first and the repository second, and saves the repository
in t->repo. notes_tree_load() takes the repository first.
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 | 30 ++++++++++++++++++------------
notes.h | 15 +++++++++++----
5 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..725280c785 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);
+ notes_tree_init(NULL, the_repository, 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);
+ notes_tree_init(NULL, the_repository, 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);
+ notes_tree_init(&t, the_repository, "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..b9a2940435 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);
+ notes_tree_init(&c->tree, r, ref.buf,
+ combine_notes_overwrite, flags);
strbuf_release(&ref);
}
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..ea43fedd43 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 = notes_tree_load(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 a73a51e1a0..6bfe80f176 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 notes_tree_init(struct notes_tree *t, struct repository *r,
+ 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 **notes_tree_load(struct repository *r,
+ struct string_list *refs, int flags)
{
struct string_list_item *item;
int counter = 0;
@@ -1065,7 +1068,8 @@ 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);
+ notes_tree_init(t, r, item->string,
+ combine_notes_ignore, flags);
trees[counter++] = t;
}
trees[counter] = NULL;
@@ -1136,7 +1140,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 = notes_tree_load(the_repository,
+ &display_notes_refs, 0);
string_list_clear(&display_notes_refs, 0);
}
@@ -1266,7 +1271,8 @@ void free_notes(struct notes_tree *t)
* Fill the given strbuf with the notes associated with the given object.
*
* If the given notes_tree structure is not initialized, it will be auto-
- * initialized to the default value (see documentation for init_notes() above).
+ * initialized to the default value (see documentation for
+ * notes_tree_init() above).
* If the given notes_tree is NULL, the internal/default notes_tree will be
* used instead.
*
@@ -1286,7 +1292,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);
+ notes_tree_init(t, the_repository, NULL, NULL, 0);
oid = get_note(t, object_oid);
if (!oid)
diff --git a/notes.h b/notes.h
index 6dc6d7b265..f4d1e31cd8 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;
@@ -63,7 +64,7 @@ extern struct notes_tree {
* Return the default notes ref.
*
* The default notes ref is the notes ref that is used when notes_ref == NULL
- * is passed to init_notes().
+ * is passed to notes_tree_init().
*
* This the first of the following to be defined:
* 1. The '--ref' option to 'git notes', if given
@@ -100,15 +101,20 @@ char *default_notes_ref(struct repository *repo);
*
* If you pass t == NULL, the default internal notes_tree will be initialized.
*
+ * 'r' is the repository that this notes_tree belongs to.
+ *
* The combine_notes function that is passed becomes the default combine_notes
* function for the given notes_tree. If NULL is passed, the default
* combine_notes function is combine_notes_concatenate().
*
+ * 'flags' is a combination of the NOTES_INIT_* flags above.
+ *
* 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 notes_tree_init(struct notes_tree *t, struct repository *r,
+ const char *notes_ref, combine_notes_fn combine_notes,
+ int flags);
/*
* Add the given note object to the given notes_tree structure
@@ -319,7 +325,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 **notes_tree_load(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] 86+ messages in thread* [PATCH v7 3/6] notes: use the tree's repository when reading notes
2026-11-27 22:04 ` [PATCH v7 " Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
@ 2026-11-27 22:04 ` Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
` (2 subsequent siblings)
5 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-27 22:04 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
In the previous step we added a '.repo' member to struct notes_tree
so a notes tree records which repository it belongs to. Notes trees
are passed down many call chains, but functions like note_tree_find()
still read objects and hash algorithms from the_repository.
There is a catch in the notes API's NULL contract. Passing NULL in
place of a notes tree is allowed and means "use the default notes
tree", so a 't' handed around a call chain may be NULL and 't->repo'
cannot be dereferenced blindly. A previous commit introduced a
notes_tree_or_default() helper to cope with this, and ensured all the
high-level entry points (except copy_note(), see below), as well as
the internal format_note(), call this helper. The leaf helpers
note_tree_find(), add_non_note() and load_subtree() do not check for
NULL themselves; they rely on being reached only through those entry
points (for example get_note() -> note_tree_find(), and
note_tree_search() lazily unpacking a subtree through load_subtree(),
still after the tree has been resolved).
Given those guarantees, read objects and hash algorithms from t->repo
instead of the_repository in note_tree_find(), add_non_note(),
load_subtree(), remove_note() and format_note().
copy_note() also takes a notes tree but does not resolve NULL before
using it, so a mechanical the_repository -> t->repo replacement there
would be unsafe; it is handled in the next patch.
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 6bfe80f176..da63d35935 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);
}
@@ -1173,8 +1173,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
struct leaf_node l;
t = notes_tree_or_default(t);
- 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;
@@ -1298,7 +1298,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] 86+ messages in thread* [PATCH v7 4/6] notes: use the tree's repository when writing and pruning
2026-11-27 22:04 ` [PATCH v7 " Okhuomon Ajayi
` (2 preceding siblings ...)
2026-11-27 22:04 ` [PATCH v7 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
@ 2026-11-27 22:04 ` Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
5 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-27 22:04 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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.
copy_note() also writes through the tree, by calling add_note(),
so it uses the tree's hash algorithm for its null object ID.
It now takes a NULL tree the same way as the other entry points,
through notes_tree_or_default(), before reading the tree's
repository.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 71 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 44 insertions(+), 27 deletions(-)
diff --git a/notes.c b/notes.c
index da63d35935..1cdf09c81c 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;
}
@@ -1212,6 +1221,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;
@@ -1221,8 +1231,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;
@@ -1230,23 +1240,24 @@ 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 };
t = notes_tree_or_default(t);
- 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;
}
}
@@ -1355,8 +1366,13 @@ int copy_note(struct notes_tree *t,
const struct object_id *from_obj, const struct object_id *to_obj,
int force, combine_notes_fn combine_notes)
{
- const struct object_id *note = get_note(t, from_obj);
- const struct object_id *existing_note = get_note(t, to_obj);
+ const struct object_id *note;
+ const struct object_id *existing_note;
+
+ t = notes_tree_or_default(t);
+
+ note = get_note(t, from_obj);
+ existing_note = get_note(t, to_obj);
if (!force && existing_note)
return 1;
@@ -1364,7 +1380,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;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 86+ messages in thread* [PATCH v7 5/6] notes: pass the repository to the ref glob helpers
2026-11-27 22:04 ` [PATCH v7 " Okhuomon Ajayi
` (3 preceding siblings ...)
2026-11-27 22:04 ` [PATCH v7 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
@ 2026-11-27 22:04 ` Okhuomon Ajayi
2026-11-27 22:04 ` [PATCH v7 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
5 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-27 22:04 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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 ea43fedd43..9f70366aa9 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 1cdf09c81c..f327652994 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;
@@ -1133,7 +1136,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
@@ -1145,7 +1149,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 f4d1e31cd8..30adf0c197 100644
--- a/notes.h
+++ b/notes.h
@@ -331,14 +331,16 @@ struct notes_tree **notes_tree_load(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] 86+ messages in thread* [PATCH v7 6/6] notes: pass the repository to the combine_notes callbacks
2026-11-27 22:04 ` [PATCH v7 " Okhuomon Ajayi
` (4 preceding siblings ...)
2026-11-27 22:04 ` [PATCH v7 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
@ 2026-11-27 22:04 ` Okhuomon Ajayi
5 siblings, 0 replies; 86+ messages in thread
From: Okhuomon Ajayi @ 2026-11-27 22:04 UTC (permalink / raw)
To: git
Cc: christian.couder, ps, gitster, usmanakinyemi202,
siddharthasthana31, kaartic.sivaraam, okhuomonajayi54
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.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
notes.c | 31 ++++++++++++++++++-------------
notes.h | 23 ++++++++++++++---------
2 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/notes.c b/notes.c
index f327652994..25e5873ac2 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:
diff --git a/notes.h b/notes.h
index 30adf0c197..3eb73adf54 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] 86+ messages in thread