Git development
 help / color / mirror / Atom feed
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 6/6] notes: pass the repository to the combine_notes callbacks
Date: Thu, 26 Nov 2026 22:33:06 +0100	[thread overview]
Message-ID: <20261126213306.87466-7-okhuomonajayi54@gmail.com> (raw)
In-Reply-To: <20261126213306.87466-1-okhuomonajayi54@gmail.com>

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


  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                     ` [PATCH v6 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
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                     ` Okhuomon Ajayi [this message]
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-7-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