{"thread":{"id":"28462","subject":"[PATCH 1/2] fast-import: don't allow to tag empty branch","startedAt":"2011-09-22T19:47:03Z","lastAt":"2011-09-22T22:29:24Z","messageCount":5,"participants":["Dmitry Ivankov","Sverre Rabbelier"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"176014","messageId":"1316720825-32552-1-git-send-email-divanorama@gmail.com","threadId":"28462","inReplyTo":null,"subject":"[PATCH 0/2] fast-import: empty/reset branch bugs","fromName":"Dmitry Ivankov","fromEmail":"divanorama@gmail.com","sentAt":"2011-09-22T19:47:03Z","receivedAt":"2011-09-22T19:47:03Z","isPatch":true,"sender":{"key":"divanorama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158999?v=4"},"body":"fast-import uses null_sha1 for empty branches. It doesn't make a \nnull_sha1 parent nor writes out a branch with null_sha1 head. But\nfor notemodify and tag commands there is no check for null_sha1\nand so bad tag/notes are produced instead of a error message.\n\nDmitry Ivankov (2):\n  fast-import: don't allow to tag empty branch\n  fast-import: don't allow to note on empty branch\n\n fast-import.c          |    4 ++++\n t/t9300-fast-import.sh |   29 +++++++++++++++++++++++++++++\n 2 files changed, 33 insertions(+), 0 deletions(-)\n\n-- \n1.7.3.4\n"},{"id":"176013","messageId":"1316720825-32552-2-git-send-email-divanorama@gmail.com","threadId":"28462","inReplyTo":"1316720825-32552-1-git-send-email-divanorama@gmail.com","subject":"[PATCH 1/2] fast-import: don't allow to tag empty branch","fromName":"Dmitry Ivankov","fromEmail":"divanorama@gmail.com","sentAt":"2011-09-22T19:47:04Z","receivedAt":"2011-09-22T19:47:04Z","isPatch":true,"sender":{"key":"divanorama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158999?v=4"},"body":"'reset' command makes fast-import start a branch from scratch. It's name\nis kept in lookup table but it's sha1 is null_sha1 (special value).\n'tag' command can be used to tag a branch by it's name. lookup_branch()\nis used it that case and it doesn't check for null_sha1. So fast-import\nwrites a tag for null_sha1 object instead of giving a error.\n\nAdd a check to deny tagging an empty branch and add a corresponding test.\n\nSigned-off-by: Dmitry Ivankov <divanorama@gmail.com>\n---\n fast-import.c          |    2 ++\n t/t9300-fast-import.sh |   12 ++++++++++++\n 2 files changed, 14 insertions(+), 0 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 742e7da..c44cc11 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2717,6 +2717,8 @@ static void parse_new_tag(void)\n \tfrom = strchr(command_buf.buf, ' ') + 1;\n \ts = lookup_branch(from);\n \tif (s) {\n+\t\tif (is_null_sha1(s->sha1))\n+\t\t\tdie(\"Can't tag an empty branch.\");\n \t\thashcpy(sha1, s->sha1);\n \t\ttype = OBJ_COMMIT;\n \t} else if (*from == ':') {\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex 1a6c066..0b97d7a 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -820,6 +820,18 @@ test_expect_success \\\n \t'test 1 = `git rev-list J | wc -l` &&\n \t test 0 = `git ls-tree J | wc -l`'\n \n+cat >input <<INPUT_END\n+reset refs/heads/J2\n+\n+tag wrong_tag\n+from refs/heads/J2\n+data <<EOF\n+Tag branch that was reset.\n+EOF\n+INPUT_END\n+test_expect_success \\\n+\t'J: tag must fail on empty branch' \\\n+\t'test_must_fail git fast-import <input'\n ###\n ### series K\n ###\n-- \n1.7.3.4\n"},{"id":"176015","messageId":"1316720825-32552-3-git-send-email-divanorama@gmail.com","threadId":"28462","inReplyTo":"1316720825-32552-1-git-send-email-divanorama@gmail.com","subject":"[PATCH 2/2] fast-import: don't allow to note on empty branch","fromName":"Dmitry Ivankov","fromEmail":"divanorama@gmail.com","sentAt":"2011-09-22T19:47:05Z","receivedAt":"2011-09-22T19:47:05Z","isPatch":true,"sender":{"key":"divanorama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158999?v=4"},"body":"'reset' command makes fast-import start a branch from scratch. It's name\nis kept in lookup table but it's sha1 is null_sha1 (special value).\n'notemodify' command can be used to add a note on branch head given it's\nname. lookup_branch() is used it that case and it doesn't check for\nnull_sha1. So fast-import writes a note for null_sha1 object instead of\ngiving a error.\n\nAdd a check to deny adding a note on empty branch and add a corresponding\ntest.\n\nSigned-off-by: Dmitry Ivankov <divanorama@gmail.com>\n---\n fast-import.c          |    2 ++\n t/t9300-fast-import.sh |   17 +++++++++++++++++\n 2 files changed, 19 insertions(+), 0 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex c44cc11..a8a3ad1 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2416,6 +2416,8 @@ static void note_change_n(struct branch *b, unsigned char old_fanout)\n \t/* <committish> */\n \ts = lookup_branch(p);\n \tif (s) {\n+\t\tif (is_null_sha1(s->sha1))\n+\t\t\tdie(\"Can't add a note on empty branch.\");\n \t\thashcpy(commit_sha1, s->sha1);\n \t} else if (*p == ':') {\n \t\tuintmax_t commit_mark = strtoumax(p + 1, NULL, 10);\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex 0b97d7a..bd32b91 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -1987,6 +1987,23 @@ test_expect_success \\\n \t'Q: verify second note for second commit' \\\n \t'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'\n \n+cat >input <<EOF\n+reset refs/heads/Q0\n+\n+commit refs/heads/note-Q0\n+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE\n+data <<COMMIT\n+Note for an empty branch.\n+COMMIT\n+\n+N inline refs/heads/Q0\n+data <<NOTE\n+some note\n+NOTE\n+EOF\n+test_expect_success \\\n+\t'Q: deny note on empty branch' \\\n+\t'test_must_fail git fast-import <input'\n ###\n ### series R (feature and option)\n ###\n-- \n1.7.3.4\n"},{"id":"176028","messageId":"CAGdFq_jxDD3_MLWAsv5WtCoSFXDm-EBB0=28aH-MqBdbGhpC3Q@mail.gmail.com","threadId":"28462","inReplyTo":"1316720825-32552-2-git-send-email-divanorama@gmail.com","subject":"Re: [PATCH 1/2] fast-import: don't allow to tag empty branch","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2011-09-22T22:28:59Z","receivedAt":"2011-09-22T22:28:59Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Sep 22, 2011 at 21:47, Dmitry Ivankov <divanorama@gmail.com> wrote:\n> 'reset' command makes fast-import start a branch from scratch. It's name\n> is kept in lookup table but it's sha1 is null_sha1 (special value).\n> 'tag' command can be used to tag a branch by it's name. lookup_branch()\n> is used it that case and it doesn't check for null_sha1. So fast-import\n> writes a tag for null_sha1 object instead of giving a error.\n>\n> Add a check to deny tagging an empty branch and add a corresponding test.\n\nMakes sense to me.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"176029","messageId":"CAGdFq_jDvWveWm5cOXA9QQC+PmaEvwmEs7PmjoACmQXxkdT62g@mail.gmail.com","threadId":"28462","inReplyTo":"1316720825-32552-3-git-send-email-divanorama@gmail.com","subject":"Re: [PATCH 2/2] fast-import: don't allow to note on empty branch","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2011-09-22T22:29:24Z","receivedAt":"2011-09-22T22:29:24Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Sep 22, 2011 at 21:47, Dmitry Ivankov <divanorama@gmail.com> wrote:\n> 'reset' command makes fast-import start a branch from scratch. It's name\n> is kept in lookup table but it's sha1 is null_sha1 (special value).\n> 'notemodify' command can be used to add a note on branch head given it's\n> name. lookup_branch() is used it that case and it doesn't check for\n> null_sha1. So fast-import writes a note for null_sha1 object instead of\n> giving a error.\n>\n> Add a check to deny adding a note on empty branch and add a corresponding\n> test.\n\nMakes sense as well.\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}