From: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
To: git@vger.kernel.org
Cc: christian.couder@gmail.com, ps@pks.im, gitster@pobox.com,
usmanakinyemi202@gmail.com, siddharthasthana31@gmail.com,
kaartic.sivaraam@gmail.com, okhuomonajayi54@gmail.com
Subject: [PATCH v6 2/6] notes: store the repository in struct notes_tree
Date: Thu, 26 Nov 2026 22:33:02 +0100 [thread overview]
Message-ID: <20261126213306.87466-3-okhuomonajayi54@gmail.com> (raw)
In-Reply-To: <20261126213306.87466-1-okhuomonajayi54@gmail.com>
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
next prev parent reply other threads:[~2026-11-26 21:33 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 10:45 [Outreachy PATCH] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
2026-11-02 11:01 ` Patrick Steinhardt
2026-11-02 11:10 ` Okhuomon Ajayi
2026-11-03 8:49 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Okhuomon Ajayi
2026-11-03 8:49 ` [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
2026-11-03 9:45 ` Karthik Nayak
2026-11-03 18:01 ` Junio C Hamano
2026-11-05 7:43 ` [Outreachy PATCH] notes-utils: hide functions that still need the_repository Okhuomon Ajayi
2026-11-05 14:22 ` Patrick Steinhardt
2026-11-05 14:47 ` Okhuomon Ajayi
2026-11-05 17:56 ` Junio C Hamano
2026-11-05 20:33 ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 1/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-09 9:18 ` Patrick Steinhardt
2026-11-09 10:27 ` Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 2/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 3/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 4/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-09 9:18 ` Patrick Steinhardt
2026-11-09 10:11 ` Okhuomon Ajayi
2026-11-24 15:28 ` Christian Couder
2026-11-24 16:13 ` Okhuomon Ajayi
2026-11-13 11:40 ` Okhuomon Ajayi
2026-11-23 9:23 ` Okhuomon Ajayi
2026-11-24 15:26 ` Christian Couder
2026-11-24 15:49 ` Okhuomon Ajayi
2026-11-05 20:33 ` [Outreachy PATCH 6/6] notes-utils: use the given repository Okhuomon Ajayi
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-25 0:34 ` Junio C Hamano
2026-11-25 6:39 ` Okhuomon Ajayi
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
2026-11-25 8:25 ` Christian Couder
2026-11-25 18:13 ` Okhuomon Ajayi
2026-11-25 19:09 ` Junio C Hamano
2026-11-25 20:36 ` Okhuomon Ajayi
2026-11-25 17:50 ` Junio C Hamano
2026-11-25 18:19 ` Okhuomon Ajayi
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
2026-11-24 17:21 ` [PATCH v2 4/5] notes: pass the repository to the ref glob helpers 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
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
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-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
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
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
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 ` [PATCH v5 5/6] notes: pass the repository to the ref glob helpers 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
2026-11-26 21:07 ` Okhuomon Ajayi
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 [this message]
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
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 ` [PATCH v6 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
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 ` [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
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 ` [PATCH v7 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
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 ` [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
2026-11-03 8:49 ` [Outreachy PATCH v2 2/2] notes-utils: pass the repository to init_copy_notes_for_rewrite() Okhuomon Ajayi
2026-11-03 9:48 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Karthik Nayak
2026-11-03 10:27 ` Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126213306.87466-3-okhuomonajayi54@gmail.com \
--to=okhuomonajayi54@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kaartic.sivaraam@gmail.com \
--cc=ps@pks.im \
--cc=siddharthasthana31@gmail.com \
--cc=usmanakinyemi202@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox