git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 3, 2026, 18:01 UTC
Message-ID
<xmqqjymt94l3.fsf@gitster.g>
In-Reply-To
<CAOLa=ZSPHDWAUmqUev9PRdEB03cUW=NWrbXHjRyma6yUmV7Yng@mail.gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
>> Keep USE_THE_REPOSITORY_VARIABLE because
>> init_copy_notes_for_rewrite() still uses the_repository.
Unfortunately, this is a highly misleading comment to leave here.

The next person would be misled into thinking that it would be just a matter of giving a "struct repository *r" argument to that function to lift the USE_THE_REPOSITORY_VARIABLE declaration from there.

Looking at what <notes-utils.h> exports, the file has quite some way to go to be free from the_repository.

 * create_notes_commit() takes "struct repository *" to pretend as
   if it can work with any repository, but the first function it
   calls is write_notes_tree() that eventually calls into
   odb_write_object() with hardcoded the_repository->objects.
 * commit_notes() calls the above create_notes_commit() and shares
   the same problem.
 * init_copy_notes_for_rewrite(), in addition to having its own
   reference to the_repository, calls load_notes_trees() that makes
   calls to init_notes() that works only on the_repository.
 * copy_note_for_rewrite() calls copy_note() which calls add_note(),
   which eventually calls into load_subtree() that can only work
   with the_repository.

In short, I think adding "struct repository *" to anything in <notes-utils.h> is not yet a productive exercise at this point, before cleaning up what is in the underlying things exported from <notes.h>.

This is a tangent but there are precedents to mark the functions that still work only on the_repository or the_hash_algo:

    $ git grep 'ifdef *USE_THE' \*.h
    environment.h:# ifdef USE_THE_REPOSITORY_VARIABLE
    hash.h:#ifdef USE_THE_REPOSITORY_VARIABLE
    hex.h:#ifdef USE_THE_REPOSITORY_VARIABLE
    path.h:# ifdef USE_THE_REPOSITORY_VARIABLE
    repository.h:#ifdef USE_THE_REPOSITORY_VARIABLE

Perhaps we need similar protection to forbid use of these functions that still assume the_repository is available in this file?

 notes-utils.h | 4 ++++
 1 file changed, 4 insertions(+)
diff --git c/notes-utils.h w/notes-utils.h
index c54b1fe141..1503991cf6 100644
--- c/notes-utils.h
+++ w/notes-utils.h
@@ -7,6 +7,9 @@ struct commit_list;
 struct object_id;
 struct repository;
 
+/* most of the things in notes.h still only work with the_repository */
+# ifdef USE_THE_REPOSITORY_VARIABLE
+
 /*
  * Create new notes commit from the given notes tree
  *
@@ -52,4 +55,5 @@ void finish_copy_notes_for_rewrite(struct repository *r,
 				   struct notes_rewrite_cfg *c,
 				   const char *msg);
 
+# endif
 #endif
Previous: Karthik NayakNext: Okhuomon Ajayi
Message 7 of 10 in “notes-utils: use the passed repository for notes refs”
  1. notes-utils: use the passed repository for notes refsOkhuomon Ajayi, Oct 31, 2026
  2. Patrick SteinhardtNov 2, 2026
  3. Okhuomon AjayiNov 2, 2026
  4. 0/2 notes-utils: stop using the_repositoryOkhuomon Ajayi, Nov 3, 2026
  5. 1/2 notes-utils: use the passed repository for notes refsOkhuomon Ajayi, Nov 3, 2026
  6. Karthik NayakNov 3, 2026
  7. Junio C HamanoNov 3, 2026
  8. 2/2 notes-utils: pass the repository to init_copy_notes_for_rewrite()Okhuomon Ajayi, Nov 3, 2026
  9. Karthik NayakNov 3, 2026
  10. Patrick SteinhardtNov 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.