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

[PATCH 1/2] notes: don't expand qualified refs in expand_notes_ref

From
Jacob Keller <jacob.e.keller@intel.com>
Date
Sep 16, 2015, 22:06 UTC
Message-ID
<1442441194-5506-2-git-send-email-jacob.e.keller@intel.com>
In-Reply-To
<1442441194-5506-1-git-send-email-jacob.e.keller@intel.com>
From: Jacob Keller <jacob.keller@gmail.com>

The documentation for --refs says that it will treat unqualified refs as under refs/notes. Current behavior is to prefix refs/notes to all strings that do not start with refs/notes or notes/, resulting in performing actions on refs such as "refs/notes/refs/foo/bar" instead of attempting to perform actions on "refs/foo/bar". A future patch will introduce the idea of performing non-writable actions to refs outside of refs/notes. Change the behavior of expand_notes_ref to leave qualified refs under refs/* alone.

In addition, fix git notes merge <ref> to prevent merges from refs which are not under refs/notes, in a similar way to how we already check note refs in init_notes_check. This is required in order to keep current tests passing without change. A future patch will change the behavior of git notes merge so that it can merge from a ref outside of refs/notes.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 builtin/notes.c | 4 ++++
 notes.c         | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 6371d536d164..0f55d38983f0 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -810,6 +810,10 @@ static int merge(int argc, const char **argv, const char *prefix)
 	o.local_ref = default_notes_ref();
 	strbuf_addstr(&remote_ref, argv[0]);
 	expand_notes_ref(&remote_ref);
+	if (!starts_with(remote_ref.buf, "refs/notes"))
+		die("Refusing to merge notes from %s (outside of refs/notes/)",
+		    remote_ref.buf);
+
 	o.remote_ref = remote_ref.buf;
 
 	t = init_notes_check("merge", NOTES_INIT_WRITABLE);
diff --git a/notes.c b/notes.c
index 6ef347ca3ac4..d49168fb3f01 100644
--- a/notes.c
+++ b/notes.c
@@ -1296,8 +1296,8 @@ int copy_note(struct notes_tree *t,
 
 void expand_notes_ref(struct strbuf *sb)
 {
-	if (starts_with(sb->buf, "refs/notes/"))
-		return; /* we're happy */
+	if (starts_with(sb->buf, "refs/"))
+		return; /* fully qualified, so we're happy */
 	else if (starts_with(sb->buf, "notes/"))
 		strbuf_insert(sb, 0, "refs/", 5);
 	else
-- 
2.6.0.rc2.248.g5b5be23
Previous: Jacob KellerNext: Junio C Hamano
Message 2 of 13 in “notes: allow read only notes actions on refs outside of refs/notes”
  1. 0/2 notes: allow read only notes actions on refs outside of refs/notesJacob Keller, Sep 16, 2015
  2. 1/2 notes: don't expand qualified refs in expand_notes_refJacob Keller, Sep 16, 2015
  3. Junio C HamanoSep 16, 2015
  4. Jacob KellerSep 16, 2015
  5. Jacob KellerSep 22, 2015
  6. Junio C HamanoSep 22, 2015
  7. Jacob KellerSep 22, 2015
  8. Jacob KellerSep 22, 2015
  9. Junio C HamanoSep 22, 2015
  10. Jacob KellerSep 22, 2015
  11. 2/2 notes: allow non-writable actions on refs outside of refs/notesJacob Keller, Sep 16, 2015
  12. Mike HommeySep 16, 2015
  13. Jacob KellerSep 16, 2015

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.