{"thread":{"id":"25619","subject":"[PATCH v2] Remove restriction on notes ref base","startedAt":"2010-11-02T17:22:12Z","lastAt":"2010-11-02T23:03:18Z","messageCount":2,"participants":["Kenny Root","Sverre Rabbelier"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"154988","messageId":"1288718532-11939-1-git-send-email-kroot@google.com","threadId":"25619","inReplyTo":null,"subject":"[PATCH v2] Remove restriction on notes ref base","fromName":"Kenny Root","fromEmail":"kroot@google.com","sentAt":"2010-11-02T17:22:12Z","receivedAt":"2010-11-02T17:22:12Z","isPatch":true,"sender":{"key":"kroot@google.com","avatar":null},"body":"Git notes were restricted to refs/notes/* in the command line utilities,\nbut setting things like GIT_NOTES_REF to something outside of that\nstructure would work.\n\nThis removes the restrictions on the git notes command line interface\nand adds checks to make sure the branch appears to be a notes branch\nbefore adding notes.\n\nSigned-off-by: Kenny Root <kroot@google.com>\n---\n builtin/notes.c  |   11 ++---------\n notes.c          |   12 ++++++++++++\n t/t3301-notes.sh |   12 ++++++------\n 3 files changed, 20 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 6d07aac..9acce7b 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -343,11 +343,7 @@ static int notes_rewrite_config(const char *k, const char *v, void *cb)\n \t} else if (!c->refs_from_env && !strcmp(k, \"notes.rewriteref\")) {\n \t\t/* note that a refs/ prefix is implied in the\n \t\t * underlying for_each_glob_ref */\n-\t\tif (!prefixcmp(v, \"refs/notes/\"))\n-\t\t\tstring_list_add_refs_by_glob(c->refs, v);\n-\t\telse\n-\t\t\twarning(\"Refusing to rewrite notes in %s\"\n-\t\t\t\t\" (outside of refs/notes/)\", v);\n+\t\tstring_list_add_refs_by_glob(c->refs, v);\n \t\treturn 0;\n \t}\n \n@@ -473,9 +469,6 @@ static struct notes_tree *init_notes_check(const char *subcommand)\n \tinit_notes(NULL, NULL, NULL, 0);\n \tt = &default_notes_tree;\n \n-\tif (prefixcmp(t->ref, \"refs/notes/\"))\n-\t\tdie(\"Refusing to %s notes in %s (outside of refs/notes/)\",\n-\t\t    subcommand, t->ref);\n \treturn t;\n }\n \n@@ -844,7 +837,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)\n \n \tif (override_notes_ref) {\n \t\tstruct strbuf sb = STRBUF_INIT;\n-\t\tif (!prefixcmp(override_notes_ref, \"refs/notes/\"))\n+\t\tif (!prefixcmp(override_notes_ref, \"refs/\"))\n \t\t\t/* we're happy */;\n \t\telse if (!prefixcmp(override_notes_ref, \"notes/\"))\n \t\t\tstrbuf_addstr(&sb, \"refs/\");\ndiff --git a/notes.c b/notes.c\nindex 70d0013..92c9c35 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -940,6 +940,18 @@ void init_notes(struct notes_tree *t, const char *notes_ref,\n \thashclr(root_tree.key_sha1);\n \thashcpy(root_tree.val_sha1, sha1);\n \tload_subtree(t, &root_tree, t->root, 0);\n+\n+\tunsigned int i, empty_tree = 1;\n+\tfor (i = 0; i < 16; i++) {\n+\t\tif (t->root->a[i]) {\n+\t\t\tempty_tree = 0;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\t/* If no notes and >0 non-notes, this is probably not a notes tree */\n+\tif (empty_tree && t->first_non_note)\n+\t\tdie(\"'%s' doesn't look like a valid notes tree\", t->ref);\n }\n \n struct notes_tree **load_notes_trees(struct string_list *refs)\ndiff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\nindex a2b79a0..df98db6 100755\n--- a/t/t3301-notes.sh\n+++ b/t/t3301-notes.sh\n@@ -38,16 +38,16 @@ test_expect_success 'need valid notes ref' '\n \t test_must_fail git notes show)\n '\n \n-test_expect_success 'refusing to add notes in refs/heads/' '\n-\t(MSG=1 GIT_NOTES_REF=refs/heads/bogus &&\n+test_expect_success 'allowing user to add notes outside of refs/notes/' '\n+\t(MSG=1 GIT_NOTES_REF=refs/meta/foo &&\n \t export MSG GIT_NOTES_REF &&\n-\t test_must_fail git notes add)\n+\t git notes add)\n '\n \n-test_expect_success 'refusing to edit notes in refs/remotes/' '\n-\t(MSG=1 GIT_NOTES_REF=refs/remotes/bogus &&\n+test_expect_success 'refusing to add notes to a non-note branch' '\n+\t(MSG=1 GIT_NOTES_REF=refs/heads/master &&\n \t export MSG GIT_NOTES_REF &&\n-\t test_must_fail git notes edit)\n+\t test_must_fail git notes add)\n '\n \n # 1 indicates caught gracefully by die, 128 means git-show barked\n-- \n1.7.3.1\n"},{"id":"155010","messageId":"AANLkTikxjBCAEFNBy0CYaB1fj7EqTGwSQHyuN1mQ8XoR@mail.gmail.com","threadId":"25619","inReplyTo":"1288718532-11939-1-git-send-email-kroot@google.com","subject":"Re: [PATCH v2] Remove restriction on notes ref base","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-11-02T23:03:18Z","receivedAt":"2010-11-02T23:03:18Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Tue, Nov 2, 2010 at 18:22, Kenny Root <kroot@google.com> wrote:\n> +       /* If no notes and >0 non-notes, this is probably not a notes tree */\n> +       if (empty_tree && t->first_non_note)\n> +               die(\"'%s' doesn't look like a valid notes tree\", t->ref);\n\nDo we want a '-f' like functionality to override this?\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}