{"thread":{"id":"53774","subject":"[PATCH 1/4] lib-t6000.sh: write tag using git-update-ref","startedAt":"2020-06-30T12:05:44Z","lastAt":"2020-07-10T21:06:14Z","messageCount":13,"participants":["Han-Wen Nienhuys via GitGitGadget","Junio C Hamano","Junio C Hamano via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"400803","messageId":"b7b2ad8e79efe534c48947da5ac83835df6fb73d.1593518738.git.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.git.1593518738.gitgitgadget@gmail.com","subject":"[PATCH 1/4] lib-t6000.sh: write tag using git-update-ref","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-30T12:05:35Z","receivedAt":"2020-06-30T12:05:44Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"From: Han-Wen Nienhuys <hanwen@google.com>\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n t/lib-t6000.sh | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/t/lib-t6000.sh b/t/lib-t6000.sh\nindex b0ed4767e3..fba6778ca3 100644\n--- a/t/lib-t6000.sh\n+++ b/t/lib-t6000.sh\n@@ -1,7 +1,5 @@\n : included from 6002 and others\n \n-mkdir -p .git/refs/tags\n-\n >sed.script\n \n # Answer the sha1 has associated with the tag. The tag must exist under refs/tags\n@@ -26,7 +24,8 @@ save_tag () {\n \t_tag=$1\n \ttest -n \"$_tag\" || error \"usage: save_tag tag commit-args ...\"\n \tshift 1\n-\t\"$@\" >\".git/refs/tags/$_tag\"\n+\n+\tgit update-ref \"refs/tags/$_tag\" $(\"$@\")\n \n \techo \"s/$(tag $_tag)/$_tag/g\" >sed.script.tmp\n \tcat sed.script >>sed.script.tmp\n-- \ngitgitgadget\n\n"},{"id":"400804","messageId":"pull.669.git.1593518738.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":null,"subject":"[PATCH 0/4] Preliminary fixes for reftable support","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-30T12:05:34Z","receivedAt":"2020-06-30T12:05:44Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"These are assorted small fixes split out from the reftable topic.\n\nHan-Wen Nienhuys (4):\n  lib-t6000.sh: write tag using git-update-ref\n  t3432: use git-reflog to inspect the reflog for HEAD\n  checkout: add '\\n' to reflog message\n  Treat BISECT_HEAD as a pseudo ref\n\n builtin/bisect--helper.c       | 3 +--\n builtin/checkout.c             | 5 +++--\n git-bisect.sh                  | 4 ++--\n t/lib-t6000.sh                 | 5 ++---\n t/t3432-rebase-fast-forward.sh | 7 ++++---\n 5 files changed, 12 insertions(+), 12 deletions(-)\n\n\nbase-commit: f402ea68166bd77f09b176c96005ac7f8886e14b\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-669%2Fhanwen%2Fpreliminaries-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-669/hanwen/preliminaries-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/669\n-- \ngitgitgadget\n"},{"id":"400805","messageId":"f238d1d7f8b59832eda48e47188479a2230a5927.1593518738.git.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.git.1593518738.gitgitgadget@gmail.com","subject":"[PATCH 2/4] t3432: use git-reflog to inspect the reflog for HEAD","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-30T12:05:36Z","receivedAt":"2020-06-30T12:05:46Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"From: Han-Wen Nienhuys <hanwen@google.com>\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n t/t3432-rebase-fast-forward.sh | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh\nindex 6f0452c0ea..22afeb8ccd 100755\n--- a/t/t3432-rebase-fast-forward.sh\n+++ b/t/t3432-rebase-fast-forward.sh\n@@ -60,15 +60,16 @@ test_rebase_same_head_ () {\n \t\tfi &&\n \t\toldhead=\\$(git rev-parse HEAD) &&\n \t\ttest_when_finished 'git reset --hard \\$oldhead' &&\n-\t\tcp .git/logs/HEAD expect &&\n+\t\tgit reflog HEAD > expect &&\n \t\tgit rebase$flag $* >stdout &&\n+\t\tgit reflog HEAD > actual &&\n \t\tif test $what = work\n \t\tthen\n \t\t\told=\\$(wc -l <expect) &&\n-\t\t\ttest_line_count '-gt' \\$old .git/logs/HEAD\n+\t\t\ttest_line_count '-gt' \\$old actual\n \t\telif test $what = noop\n \t\tthen\n-\t\t\ttest_cmp expect .git/logs/HEAD\n+\t\t\ttest_cmp expect actual\n \t\tfi &&\n \t\tnewhead=\\$(git rev-parse HEAD) &&\n \t\tif test $cmp = same\n-- \ngitgitgadget\n\n"},{"id":"400806","messageId":"8a62cc26686b1bb2f04cb01c79e336dca397a330.1593518738.git.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.git.1593518738.gitgitgadget@gmail.com","subject":"[PATCH 3/4] checkout: add '\\n' to reflog message","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-30T12:05:37Z","receivedAt":"2020-06-30T12:05:47Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"From: Han-Wen Nienhuys <hanwen@google.com>\n\nThis makes check consistent with the rest of the git code, which tends to use a\ntrailing '\\n' when writing reflog messages.  (The storage layer adds a '\\n'\nwhen it is missing.)\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n builtin/checkout.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex af849c644f..bb11fcc4e9 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -884,8 +884,9 @@ static void update_refs_for_switch(const struct checkout_opts *opts,\n \n \treflog_msg = getenv(\"GIT_REFLOG_ACTION\");\n \tif (!reflog_msg)\n-\t\tstrbuf_addf(&msg, \"checkout: moving from %s to %s\",\n-\t\t\told_desc ? old_desc : \"(invalid)\", new_branch_info->name);\n+\t\tstrbuf_addf(&msg, \"checkout: moving from %s to %s\\n\",\n+\t\t\t    old_desc ? old_desc : \"(invalid)\",\n+\t\t\t    new_branch_info->name);\n \telse\n \t\tstrbuf_insertstr(&msg, 0, reflog_msg);\n \n-- \ngitgitgadget\n\n"},{"id":"400807","messageId":"2b7eb58c1556971d128fc7596bf8abf7a993432d.1593518738.git.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.git.1593518738.gitgitgadget@gmail.com","subject":"[PATCH 4/4] Treat BISECT_HEAD as a pseudo ref","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-30T12:05:38Z","receivedAt":"2020-06-30T12:05:48Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"From: Han-Wen Nienhuys <hanwen@google.com>\n\nBoth the git-bisect.sh as bisect--helper inspected the file system directly.\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n builtin/bisect--helper.c | 3 +--\n git-bisect.sh            | 4 ++--\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex ec4996282e..73f9324ad7 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -13,7 +13,6 @@ static GIT_PATH_FUNC(git_path_bisect_terms, \"BISECT_TERMS\")\n static GIT_PATH_FUNC(git_path_bisect_expected_rev, \"BISECT_EXPECTED_REV\")\n static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, \"BISECT_ANCESTORS_OK\")\n static GIT_PATH_FUNC(git_path_bisect_start, \"BISECT_START\")\n-static GIT_PATH_FUNC(git_path_bisect_head, \"BISECT_HEAD\")\n static GIT_PATH_FUNC(git_path_bisect_log, \"BISECT_LOG\")\n static GIT_PATH_FUNC(git_path_head_name, \"head-name\")\n static GIT_PATH_FUNC(git_path_bisect_names, \"BISECT_NAMES\")\n@@ -164,7 +163,7 @@ static int bisect_reset(const char *commit)\n \t\tstrbuf_addstr(&branch, commit);\n \t}\n \n-\tif (!file_exists(git_path_bisect_head())) {\n+\tif (!ref_exists(\"BISECT_HEAD\")) {\n \t\tstruct argv_array argv = ARGV_ARRAY_INIT;\n \n \t\targv_array_pushl(&argv, \"checkout\", branch.buf, \"--\", NULL);\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 08a6ed57dd..f03fbb18f0 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -41,7 +41,7 @@ TERM_GOOD=good\n \n bisect_head()\n {\n-\tif test -f \"$GIT_DIR/BISECT_HEAD\"\n+\tif git rev-parse --verify -q BISECT_HEAD > /dev/null\n \tthen\n \t\techo BISECT_HEAD\n \telse\n@@ -153,7 +153,7 @@ bisect_next() {\n \tgit bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit\n \n \t# Perform all bisection computation, display and checkout\n-\tgit bisect--helper --next-all $(test -f \"$GIT_DIR/BISECT_HEAD\" && echo --no-checkout)\n+\tgit bisect--helper --next-all $(git rev-parse --verify -q BISECT_HEAD > /dev/null && echo --no-checkout)\n \tres=$?\n \n \t# Check if we should exit because bisection is finished\n-- \ngitgitgadget\n"},{"id":"401066","messageId":"xmqqmu4c6iqg.fsf@gitster.c.googlers.com","threadId":"53774","inReplyTo":"pull.669.git.1593518738.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/4] Preliminary fixes for reftable support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-07T04:40:07Z","receivedAt":"2020-07-07T04:40:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Han-Wen Nienhuys via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> These are assorted small fixes split out from the reftable topic.\n>\n> Han-Wen Nienhuys (4):\n>   lib-t6000.sh: write tag using git-update-ref\n>   t3432: use git-reflog to inspect the reflog for HEAD\n>   checkout: add '\\n' to reflog message\n>   Treat BISECT_HEAD as a pseudo ref\n>\n>  builtin/bisect--helper.c       | 3 +--\n>  builtin/checkout.c             | 5 +++--\n>  git-bisect.sh                  | 4 ++--\n>  t/lib-t6000.sh                 | 5 ++---\n>  t/t3432-rebase-fast-forward.sh | 7 ++++---\n>  5 files changed, 12 insertions(+), 12 deletions(-)\n\nThanks for splitting these out, and sorry for not being able to get\nto them earlier.\n\nWill queue.\n\n"},{"id":"401355","messageId":"pull.669.v2.git.1594401593.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.git.1593518738.gitgitgadget@gmail.com","subject":"[PATCH v2 0/4] Preliminary fixes for reftable support","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-07-10T17:19:49Z","receivedAt":"2020-07-10T17:19:58Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"These are assorted small fixes split out from the reftable topic.\n\nHan-Wen Nienhuys (3):\n  lib-t6000.sh: write tag using git-update-ref\n  t3432: use git-reflog to inspect the reflog for HEAD\n  Treat BISECT_HEAD as a pseudo ref\n\nJunio C Hamano (1):\n  Cleanse reflog messages in the refs.c layer\n\n builtin/bisect--helper.c       |  3 +-\n git-bisect.sh                  |  4 +--\n refs.c                         | 50 ++++++++++++++++++++++++++++------\n refs/files-backend.c           |  2 +-\n refs/refs-internal.h           |  6 ----\n t/lib-t6000.sh                 |  5 ++--\n t/t3432-rebase-fast-forward.sh |  7 +++--\n 7 files changed, 51 insertions(+), 26 deletions(-)\n\n\nbase-commit: bd42bbe1a46c0fe486fc33e82969275e27e4dc19\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-669%2Fhanwen%2Fpreliminaries-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-669/hanwen/preliminaries-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/669\n\nRange-diff vs v1:\n\n 1:  b7b2ad8e79 = 1:  0f244ed6cb lib-t6000.sh: write tag using git-update-ref\n 2:  f238d1d7f8 ! 2:  123d246edf t3432: use git-reflog to inspect the reflog for HEAD\n     @@ t/t3432-rebase-fast-forward.sh: test_rebase_same_head_ () {\n       \t\toldhead=\\$(git rev-parse HEAD) &&\n       \t\ttest_when_finished 'git reset --hard \\$oldhead' &&\n      -\t\tcp .git/logs/HEAD expect &&\n     -+\t\tgit reflog HEAD > expect &&\n     ++\t\tgit reflog HEAD >expect &&\n       \t\tgit rebase$flag $* >stdout &&\n     -+\t\tgit reflog HEAD > actual &&\n     ++\t\tgit reflog HEAD >actual &&\n       \t\tif test $what = work\n       \t\tthen\n       \t\t\told=\\$(wc -l <expect) &&\n 3:  8a62cc2668 < -:  ---------- checkout: add '\\n' to reflog message\n 4:  2b7eb58c15 = 3:  d4007c2a5b Treat BISECT_HEAD as a pseudo ref\n -:  ---------- > 4:  6ca5b99c8d Cleanse reflog messages in the refs.c layer\n\n-- \ngitgitgadget\n"},{"id":"401356","messageId":"0f244ed6cbddd0673653349b78c3ede31f9bbf71.1594401593.git.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.v2.git.1594401593.gitgitgadget@gmail.com","subject":"[PATCH v2 1/4] lib-t6000.sh: write tag using git-update-ref","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-07-10T17:19:50Z","receivedAt":"2020-07-10T17:20:00Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"From: Han-Wen Nienhuys <hanwen@google.com>\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n t/lib-t6000.sh | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/t/lib-t6000.sh b/t/lib-t6000.sh\nindex b0ed4767e3..fba6778ca3 100644\n--- a/t/lib-t6000.sh\n+++ b/t/lib-t6000.sh\n@@ -1,7 +1,5 @@\n : included from 6002 and others\n \n-mkdir -p .git/refs/tags\n-\n >sed.script\n \n # Answer the sha1 has associated with the tag. The tag must exist under refs/tags\n@@ -26,7 +24,8 @@ save_tag () {\n \t_tag=$1\n \ttest -n \"$_tag\" || error \"usage: save_tag tag commit-args ...\"\n \tshift 1\n-\t\"$@\" >\".git/refs/tags/$_tag\"\n+\n+\tgit update-ref \"refs/tags/$_tag\" $(\"$@\")\n \n \techo \"s/$(tag $_tag)/$_tag/g\" >sed.script.tmp\n \tcat sed.script >>sed.script.tmp\n-- \ngitgitgadget\n\n"},{"id":"401357","messageId":"d4007c2a5b785aac54d3ce7635cd6a50225c1361.1594401593.git.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.v2.git.1594401593.gitgitgadget@gmail.com","subject":"[PATCH v2 3/4] Treat BISECT_HEAD as a pseudo ref","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-07-10T17:19:52Z","receivedAt":"2020-07-10T17:20:02Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"From: Han-Wen Nienhuys <hanwen@google.com>\n\nBoth the git-bisect.sh as bisect--helper inspected the file system directly.\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n builtin/bisect--helper.c | 3 +--\n git-bisect.sh            | 4 ++--\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex ec4996282e..73f9324ad7 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -13,7 +13,6 @@ static GIT_PATH_FUNC(git_path_bisect_terms, \"BISECT_TERMS\")\n static GIT_PATH_FUNC(git_path_bisect_expected_rev, \"BISECT_EXPECTED_REV\")\n static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, \"BISECT_ANCESTORS_OK\")\n static GIT_PATH_FUNC(git_path_bisect_start, \"BISECT_START\")\n-static GIT_PATH_FUNC(git_path_bisect_head, \"BISECT_HEAD\")\n static GIT_PATH_FUNC(git_path_bisect_log, \"BISECT_LOG\")\n static GIT_PATH_FUNC(git_path_head_name, \"head-name\")\n static GIT_PATH_FUNC(git_path_bisect_names, \"BISECT_NAMES\")\n@@ -164,7 +163,7 @@ static int bisect_reset(const char *commit)\n \t\tstrbuf_addstr(&branch, commit);\n \t}\n \n-\tif (!file_exists(git_path_bisect_head())) {\n+\tif (!ref_exists(\"BISECT_HEAD\")) {\n \t\tstruct argv_array argv = ARGV_ARRAY_INIT;\n \n \t\targv_array_pushl(&argv, \"checkout\", branch.buf, \"--\", NULL);\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 08a6ed57dd..f03fbb18f0 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -41,7 +41,7 @@ TERM_GOOD=good\n \n bisect_head()\n {\n-\tif test -f \"$GIT_DIR/BISECT_HEAD\"\n+\tif git rev-parse --verify -q BISECT_HEAD > /dev/null\n \tthen\n \t\techo BISECT_HEAD\n \telse\n@@ -153,7 +153,7 @@ bisect_next() {\n \tgit bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit\n \n \t# Perform all bisection computation, display and checkout\n-\tgit bisect--helper --next-all $(test -f \"$GIT_DIR/BISECT_HEAD\" && echo --no-checkout)\n+\tgit bisect--helper --next-all $(git rev-parse --verify -q BISECT_HEAD > /dev/null && echo --no-checkout)\n \tres=$?\n \n \t# Check if we should exit because bisection is finished\n-- \ngitgitgadget\n\n"},{"id":"401358","messageId":"123d246edf9e3e40c321cfaff81fe96ae3a0c015.1594401593.git.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.v2.git.1594401593.gitgitgadget@gmail.com","subject":"[PATCH v2 2/4] t3432: use git-reflog to inspect the reflog for HEAD","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-07-10T17:19:51Z","receivedAt":"2020-07-10T17:20:03Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"From: Han-Wen Nienhuys <hanwen@google.com>\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n t/t3432-rebase-fast-forward.sh | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh\nindex 6f0452c0ea..a29eda87e9 100755\n--- a/t/t3432-rebase-fast-forward.sh\n+++ b/t/t3432-rebase-fast-forward.sh\n@@ -60,15 +60,16 @@ test_rebase_same_head_ () {\n \t\tfi &&\n \t\toldhead=\\$(git rev-parse HEAD) &&\n \t\ttest_when_finished 'git reset --hard \\$oldhead' &&\n-\t\tcp .git/logs/HEAD expect &&\n+\t\tgit reflog HEAD >expect &&\n \t\tgit rebase$flag $* >stdout &&\n+\t\tgit reflog HEAD >actual &&\n \t\tif test $what = work\n \t\tthen\n \t\t\told=\\$(wc -l <expect) &&\n-\t\t\ttest_line_count '-gt' \\$old .git/logs/HEAD\n+\t\t\ttest_line_count '-gt' \\$old actual\n \t\telif test $what = noop\n \t\tthen\n-\t\t\ttest_cmp expect .git/logs/HEAD\n+\t\t\ttest_cmp expect actual\n \t\tfi &&\n \t\tnewhead=\\$(git rev-parse HEAD) &&\n \t\tif test $cmp = same\n-- \ngitgitgadget\n\n"},{"id":"401359","messageId":"6ca5b99c8d7af1a3f35b3a7d25db284c879a2f10.1594401593.git.gitgitgadget@gmail.com","threadId":"53774","inReplyTo":"pull.669.v2.git.1594401593.gitgitgadget@gmail.com","subject":"[PATCH v2 4/4] Cleanse reflog messages in the refs.c layer","fromName":"Junio C Hamano via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-07-10T17:19:53Z","receivedAt":"2020-07-10T17:20:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\nRegarding reflog messages:\n\n - We expect that a reflog message consists of a single line.  The\n   file format used by the files backend may add a LF after the\n   message as a delimiter, and output by commands like \"git log -g\"\n   may complete such an incomplete line by adding a LF at the end,\n   but philosophically, the terminating LF is not a part of the\n   message.\n\n - We however allow callers of refs API to supply a random sequence\n   of NUL terminated bytes.  We cleanse caller-supplied message by\n   squashing a run of whitespaces into a SP, and by trimming trailing\n   whitespace, before storing the message.  This is how we tolerate,\n   instead of erring out, a message with LF in it (be it at the end,\n   in the middle, or both).\n\nCurrently, the cleansing of the reflog message is done by the files\nbackend, before the log is written out.  This is sufficient with the\ncurrent code, as that is the only backend that writes reflogs.  But\nnew backends can be added that write reflogs, and we'd want the\nresulting log message we would read out of \"log -g\" the same no\nmatter what backend is used.\n\nAn added benefit is that the \"cleansing\" function could be updated\nlater, independent from individual backends, to e.g. allow\nmulti-line log messages if we wanted to, and when that happens, it\nwould help a lot to ensure we covered all bases if the cleansing\nfunction (which would be updated) is called from the generic layer.\n\nSide note: I am not interested in supporting multi-line\nreflog messages right at the moment (nobody is asking for\nit), but I envision that instead of the \"squash a run of\nwhitespaces into a SP and rtrim\" cleansing, we can\n%urlencode problematic bytes in the message *AND* append a\nSP at the end, when a new version of Git that supports\nmulti-line and/or verbatim reflog messages writes a reflog\nrecord.  The reading side can detect the presense of SP at\nthe end (which should have been rtrimmed out if it were\nwritten by existing versions of Git) as a signal that\ndecoding %urlencode recovers the original reflog message.\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n refs.c               | 50 ++++++++++++++++++++++++++++++++++++--------\n refs/files-backend.c |  2 +-\n refs/refs-internal.h |  6 ------\n 3 files changed, 42 insertions(+), 16 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 639cba93b4..89814c7be4 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -902,7 +902,7 @@ int delete_ref(const char *msg, const char *refname,\n \t\t\t       old_oid, flags);\n }\n \n-void copy_reflog_msg(struct strbuf *sb, const char *msg)\n+static void copy_reflog_msg(struct strbuf *sb, const char *msg)\n {\n \tchar c;\n \tint wasspace = 1;\n@@ -919,6 +919,15 @@ void copy_reflog_msg(struct strbuf *sb, const char *msg)\n \tstrbuf_rtrim(sb);\n }\n \n+static char *normalize_reflog_message(const char *msg)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tif (msg && *msg)\n+\t\tcopy_reflog_msg(&sb, msg);\n+\treturn strbuf_detach(&sb, NULL);\n+}\n+\n int should_autocreate_reflog(const char *refname)\n {\n \tswitch (log_all_ref_updates) {\n@@ -1124,7 +1133,7 @@ struct ref_update *ref_transaction_add_update(\n \t\toidcpy(&update->new_oid, new_oid);\n \tif (flags & REF_HAVE_OLD)\n \t\toidcpy(&update->old_oid, old_oid);\n-\tupdate->msg = xstrdup_or_null(msg);\n+\tupdate->msg = normalize_reflog_message(msg);\n \treturn update;\n }\n \n@@ -1983,9 +1992,14 @@ int refs_create_symref(struct ref_store *refs,\n \t\t       const char *refs_heads_master,\n \t\t       const char *logmsg)\n {\n-\treturn refs->be->create_symref(refs, ref_target,\n-\t\t\t\t       refs_heads_master,\n-\t\t\t\t       logmsg);\n+\tchar *msg;\n+\tint retval;\n+\n+\tmsg = normalize_reflog_message(logmsg);\n+\tretval = refs->be->create_symref(refs, ref_target, refs_heads_master,\n+\t\t\t\t\t msg);\n+\tfree(msg);\n+\treturn retval;\n }\n \n int create_symref(const char *ref_target, const char *refs_heads_master,\n@@ -2370,10 +2384,16 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,\n \treturn refs->be->initial_transaction_commit(refs, transaction, err);\n }\n \n-int refs_delete_refs(struct ref_store *refs, const char *msg,\n+int refs_delete_refs(struct ref_store *refs, const char *logmsg,\n \t\t     struct string_list *refnames, unsigned int flags)\n {\n-\treturn refs->be->delete_refs(refs, msg, refnames, flags);\n+\tchar *msg;\n+\tint retval;\n+\n+\tmsg = normalize_reflog_message(logmsg);\n+\tretval = refs->be->delete_refs(refs, msg, refnames, flags);\n+\tfree(msg);\n+\treturn retval;\n }\n \n int delete_refs(const char *msg, struct string_list *refnames,\n@@ -2385,7 +2405,13 @@ int delete_refs(const char *msg, struct string_list *refnames,\n int refs_rename_ref(struct ref_store *refs, const char *oldref,\n \t\t    const char *newref, const char *logmsg)\n {\n-\treturn refs->be->rename_ref(refs, oldref, newref, logmsg);\n+\tchar *msg;\n+\tint retval;\n+\n+\tmsg = normalize_reflog_message(logmsg);\n+\tretval = refs->be->rename_ref(refs, oldref, newref, msg);\n+\tfree(msg);\n+\treturn retval;\n }\n \n int rename_ref(const char *oldref, const char *newref, const char *logmsg)\n@@ -2396,7 +2422,13 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)\n int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,\n \t\t    const char *newref, const char *logmsg)\n {\n-\treturn refs->be->copy_ref(refs, oldref, newref, logmsg);\n+\tchar *msg;\n+\tint retval;\n+\n+\tmsg = normalize_reflog_message(logmsg);\n+\tretval = refs->be->copy_ref(refs, oldref, newref, msg);\n+\tfree(msg);\n+\treturn retval;\n }\n \n int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 6516c7bc8c..e0aba23eb2 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -1629,7 +1629,7 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,\n \n \tstrbuf_addf(&sb, \"%s %s %s\", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);\n \tif (msg && *msg)\n-\t\tcopy_reflog_msg(&sb, msg);\n+\t\tstrbuf_addstr(&sb, msg);\n \tstrbuf_addch(&sb, '\\n');\n \tif (write_in_full(fd, sb.buf, sb.len) < 0)\n \t\tret = -1;\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex 4271362d26..357359a0be 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -96,12 +96,6 @@ enum peel_status {\n  */\n enum peel_status peel_object(const struct object_id *name, struct object_id *oid);\n \n-/*\n- * Copy the reflog message msg to sb while cleaning up the whitespaces.\n- * Especially, convert LF to space, because reflog file is one line per entry.\n- */\n-void copy_reflog_msg(struct strbuf *sb, const char *msg);\n-\n /**\n  * Information needed for a single ref update. Set new_oid to the new\n  * value or to null_oid to delete the ref. To check the old value\n-- \ngitgitgadget\n"},{"id":"401381","messageId":"xmqqy2nrrsuy.fsf@gitster.c.googlers.com","threadId":"53774","inReplyTo":"pull.669.v2.git.1594401593.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 0/4] Preliminary fixes for reftable support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-10T20:57:09Z","receivedAt":"2020-07-10T20:57:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Han-Wen Nienhuys via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> These are assorted small fixes split out from the reftable topic.\n\nWill replace.  I'll retitle the 3/4 and 4/4 to\n\n    bisect: treat BISECT_HEAD as a pseudo ref\n    reflgo: cleanse messages in the refs.c layer\n\nwhile queuing.\n\nThanks.\n\n> Han-Wen Nienhuys (3):\n>   lib-t6000.sh: write tag using git-update-ref\n>   t3432: use git-reflog to inspect the reflog for HEAD\n>   Treat BISECT_HEAD as a pseudo ref\n>\n> Junio C Hamano (1):\n>   Cleanse reflog messages in the refs.c layer\n>\n>  builtin/bisect--helper.c       |  3 +-\n>  git-bisect.sh                  |  4 +--\n>  refs.c                         | 50 ++++++++++++++++++++++++++++------\n>  refs/files-backend.c           |  2 +-\n>  refs/refs-internal.h           |  6 ----\n>  t/lib-t6000.sh                 |  5 ++--\n>  t/t3432-rebase-fast-forward.sh |  7 +++--\n>  7 files changed, 51 insertions(+), 26 deletions(-)\n>\n>\n> base-commit: bd42bbe1a46c0fe486fc33e82969275e27e4dc19\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-669%2Fhanwen%2Fpreliminaries-v2\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-669/hanwen/preliminaries-v2\n> Pull-Request: https://github.com/gitgitgadget/git/pull/669\n>\n> Range-diff vs v1:\n>\n>  1:  b7b2ad8e79 = 1:  0f244ed6cb lib-t6000.sh: write tag using git-update-ref\n>  2:  f238d1d7f8 ! 2:  123d246edf t3432: use git-reflog to inspect the reflog for HEAD\n>      @@ t/t3432-rebase-fast-forward.sh: test_rebase_same_head_ () {\n>        \t\toldhead=\\$(git rev-parse HEAD) &&\n>        \t\ttest_when_finished 'git reset --hard \\$oldhead' &&\n>       -\t\tcp .git/logs/HEAD expect &&\n>      -+\t\tgit reflog HEAD > expect &&\n>      ++\t\tgit reflog HEAD >expect &&\n>        \t\tgit rebase$flag $* >stdout &&\n>      -+\t\tgit reflog HEAD > actual &&\n>      ++\t\tgit reflog HEAD >actual &&\n>        \t\tif test $what = work\n>        \t\tthen\n>        \t\t\told=\\$(wc -l <expect) &&\n>  3:  8a62cc2668 < -:  ---------- checkout: add '\\n' to reflog message\n>  4:  2b7eb58c15 = 3:  d4007c2a5b Treat BISECT_HEAD as a pseudo ref\n>  -:  ---------- > 4:  6ca5b99c8d Cleanse reflog messages in the refs.c layer\n"},{"id":"401382","messageId":"xmqqtuyfrsg0.fsf@gitster.c.googlers.com","threadId":"53774","inReplyTo":"6ca5b99c8d7af1a3f35b3a7d25db284c879a2f10.1594401593.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 4/4] Cleanse reflog messages in the refs.c layer","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-10T21:06:07Z","receivedAt":"2020-07-10T21:06:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Junio C Hamano via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> Currently, the cleansing of the reflog message is done by the files\n> backend, before the log is written out.  This is sufficient with the\n> current code, as that is the only backend that writes reflogs.  But\n> new backends can be added that write reflogs, and we'd want the\n> resulting log message we would read out of \"log -g\" the same no\n> matter what backend is used.\n\nI _think_ there is no correctness impact, but this slightly changes\nthe semantics.  We used to take whatever random string from the\ncaller and at the lowest layer of the files backend, i.e.\n\n>  \tstrbuf_addf(&sb, \"%s %s %s\", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);\n>  \tif (msg && *msg)\n> -\t\tcopy_reflog_msg(&sb, msg);\n> +\t\tstrbuf_addstr(&sb, msg);\n\ncleansed and added the message to strbuf.\n\nWith the updated code, normalize_reflog_message() is defined like so\n\n> +static char *normalize_reflog_message(const char *msg)\n> +{\n> +\tstruct strbuf sb = STRBUF_INIT;\n> +\n> +\tif (msg && *msg)\n> +\t\tcopy_reflog_msg(&sb, msg);\n> +\treturn strbuf_detach(&sb, NULL);\n> +}\n\nto always return a non-NULL but an empty string, even if the caller\ngave us a NULL pointer.  We always pass a non-NULL string around,\nand the updated low-level code avoids calling strbuf_addstr()\nbecause msg is not NULL, but *msg is '\\0'.\n\nWe _might_ be able to optimize by tweaking the normalizer a bit\nfurther, perhaps like so:\n\n    static char *normalize_reflog_message(const char *msg)\n    {\n            struct strbuf sb = STRBUF_INIT;\n\n            if (msg && *msg)\n                    copy_reflog_msg(&sb, msg);\n            if (sb.len) {\n                    return strbuf_detach(&sb, NULL);\n            } else {\n                    strbuf_release(&sb);\n                    return NULL;\n            }\n    }\n\nto avoid allocating 1 byte '\\0' on the heap by strbuf_detach() when\nsb here ends up being truly empty.\n\nBut it would be a premature optimization to worry about such a thing\nat this point, I think.\n\nThanks.\n"}]}