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

[PATCH v4 11/11] notes: add shorthand --ref to override GIT_NOTES_REF

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 22, 2010, 00:10 UTC
Message-ID
<4517b10981339e33231966f44e1063848ecfda0e.1266797028.git.trast@student.ethz.ch>
In-Reply-To
<cover.1266797028.git.trast@student.ethz.ch>

Adds a shorthand option that overrides the GIT_NOTES_REF variable, and hence determines the notes tree that will be manipulated. It also DWIMs a refs/notes/ prefix.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

Changed since v3: refs/notes/ is now implied, instead of erroring out if it is not there.

 Documentation/git-notes.txt |    4 ++++
 builtin-notes.c             |   16 ++++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 92f1249..dcdcc95 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -115,6 +115,10 @@ OPTIONS
 	Like '-C', but with '-c' the editor is invoked, so that
 	the user can further edit the note message.
 
+--ref <ref>::
+	Manipulate the notes tree in <ref>.  This overrides both
+	GIT_NOTES_REF and the "core.notesRef" configuration.
+
 Author
 ------
 Written by Johannes Schindelin <johannes.schindelin@gmx.de> and
diff --git a/builtin-notes.c b/builtin-notes.c
index 8c65709..0300efa 100644
--- a/builtin-notes.c
+++ b/builtin-notes.c
@@ -447,6 +447,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
 	int given_object = 0, i = 1, retval = 0;
 	struct msg_arg msg = { 0, 0, STRBUF_INIT };
 	const char *rewrite_cmd = NULL;
+	const char *override_notes_ref = NULL;
 	struct option options[] = {
 		OPT_GROUP("Notes options"),
 		OPT_CALLBACK('m', "message", &msg, "MSG",
@@ -459,6 +460,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
 			   "reuse specified note object", parse_reuse_arg),
 		OPT_BOOLEAN('f', "force", &force, "replace existing notes"),
 		OPT_BOOLEAN(0, "stdin", &from_stdin, "read objects from stdin"),
+		OPT_STRING(0, "ref", &override_notes_ref, "notes_ref",
+			   "use notes from <notes_ref>"),
 		OPT_STRING(0, "for-rewrite", &rewrite_cmd, "command",
 			   "load rewriting config for <command> (implies --stdin)"),
 		OPT_END()
@@ -468,6 +471,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, options, git_notes_usage, 0);
 
+	if (override_notes_ref) {
+		struct strbuf sb = STRBUF_INIT;
+		if (!prefixcmp(override_notes_ref, "refs/notes/"))
+			/* we're happy */;
+		else if (!prefixcmp(override_notes_ref, "notes/"))
+			strbuf_addstr(&sb, "refs/");
+		else
+			strbuf_addstr(&sb, "refs/notes/");
+		strbuf_addstr(&sb, override_notes_ref);
+		setenv("GIT_NOTES_REF", sb.buf, 1);
+		strbuf_release(&sb);
+	}
+
 	if (argc && !strcmp(argv[0], "list"))
 		list = 1;
 	else if (argc && !strcmp(argv[0], "add"))
-- 
1.7.0.147.g5aeb9
Previous: Thomas RastNext: Junio C Hamano
Message 15 of 17 in “several notes refs, post-rewrite, notes rewriting”
  1. 00/11 several notes refs, post-rewrite, notes rewritingThomas Rast, Feb 22, 2010
  2. 01/11 test-lib: unset GIT_NOTES_REF to stop it from influencing testsThomas Rast, Feb 22, 2010
  3. 02/11 Support showing notes from more than one notes treeThomas Rast, Feb 22, 2010
  4. Junio C HamanoFeb 22, 2010
  5. Thomas RastFeb 22, 2010
  6. Junio C HamanoFeb 23, 2010
  7. 03/11 Documentation: document post-rewrite hookThomas Rast, Feb 22, 2010
  8. 04/11 commit --amend: invoke post-rewrite hookThomas Rast, Feb 22, 2010
  9. 05/11 rebase: invoke post-rewrite hookThomas Rast, Feb 22, 2010
  10. 06/11 rebase -i: invoke post-rewrite hookThomas Rast, Feb 22, 2010
  11. 07/11 notes: implement 'git notes copy --stdin'Thomas Rast, Feb 22, 2010
  12. 08/11 notes: implement helpers needed for note copying during rewriteThomas Rast, Feb 22, 2010
  13. 09/11 rebase: support automatic notes copyingThomas Rast, Feb 22, 2010
  14. 10/11 commit --amend: copy notes to the new commitThomas Rast, Feb 22, 2010
  15. 11/11 notes: add shorthand --ref to override GIT_NOTES_REFThomas Rast, Feb 22, 2010
  16. Junio C HamanoFeb 22, 2010
  17. Thomas RastFeb 22, 2010

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.