{"thread":{"id":"39606","subject":"[PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format","startedAt":"2015-06-12T02:23:27Z","lastAt":"2015-06-12T22:36:54Z","messageCount":7,"participants":["Michael Rappazzo","Junio C Hamano","Mike Rappazzo"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"263643","messageId":"1434075808-43453-1-git-send-email-rappazzo@gmail.com","threadId":"39606","inReplyTo":null,"subject":"[PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Michael Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2015-06-12T02:23:27Z","receivedAt":"2015-06-12T02:23:27Z","isPatch":true,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"Difference between v3 and v4 of this patch:\n\n    - cleaned up changes in rearrange_squash() function\n    - consolidated autosquash test \n\nMichael Rappazzo (1):\n  git-rebase--interactive.sh: add config option for custom instruction\n    format\n\n Documentation/git-rebase.txt |  7 +++++++\n git-rebase--interactive.sh   | 20 +++++++++++++++++---\n t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++\n 3 files changed, 45 insertions(+), 3 deletions(-)\n\n-- \n2.4.2\n"},{"id":"263644","messageId":"1434075808-43453-2-git-send-email-rappazzo@gmail.com","threadId":"39606","inReplyTo":"1434075808-43453-1-git-send-email-rappazzo@gmail.com","subject":"[PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Michael Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2015-06-12T02:23:28Z","receivedAt":"2015-06-12T02:23:28Z","isPatch":true,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"A config option 'rebase.instructionFormat' can override the\ndefault 'oneline' format of the rebase instruction list.\n\nSince the list is parsed using the left, right or boundary mark plus\nthe sha1, they are prepended to the instruction format.\n\nSigned-off-by: Michael Rappazzo <rappazzo@gmail.com>\n---\n Documentation/git-rebase.txt |  7 +++++++\n git-rebase--interactive.sh   | 20 +++++++++++++++++---\n t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++\n 3 files changed, 45 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt\nindex 1d01baa..8ddab77 100644\n--- a/Documentation/git-rebase.txt\n+++ b/Documentation/git-rebase.txt\n@@ -213,6 +213,9 @@ rebase.autoSquash::\n rebase.autoStash::\n \tIf set to true enable '--autostash' option by default.\n \n+rebase.instructionFormat::\n+   Custom commit list format to use during an '--interactive' rebase.\n+\n OPTIONS\n -------\n --onto <newbase>::\n@@ -359,6 +362,10 @@ default is `--no-fork-point`, otherwise the default is `--fork-point`.\n \tMake a list of the commits which are about to be rebased.  Let the\n \tuser edit that list before rebasing.  This mode can also be used to\n \tsplit commits (see SPLITTING COMMITS below).\n++\n+The commit list format can be changed by setting the configuration option\n+rebase.instructionFormat.  A customized instruction format will automatically\n+have the long commit hash prepended to the format.\n \n -p::\n --preserve-merges::\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex dc3133f..755f9c1 100644\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -740,10 +740,15 @@ collapse_todo_ids() {\n # \"pick sha1 fixup!/squash! msg\" appears in it so that the latter\n # comes immediately after the former, and change \"pick\" to\n # \"fixup\"/\"squash\".\n+#\n+# Note that if the config has specified a custom instruction format\n+# each log message will be re-retrieved in order to normalize the \n+# autosquash arrangement\n rearrange_squash () {\n \t# extract fixup!/squash! lines and resolve any referenced sha1's\n \twhile read -r pick sha1 message\n \tdo\n+\t\ttest -z \"${format}\" || message=$(git log -n 1 --format=\"%s\" ${sha1})\n \t\tcase \"$message\" in\n \t\t\"squash! \"*|\"fixup! \"*)\n \t\t\taction=\"${message%%!*}\"\n@@ -785,6 +790,7 @@ rearrange_squash () {\n \t\t*\" $sha1 \"*) continue ;;\n \t\tesac\n \t\tprintf '%s\\n' \"$pick $sha1 $message\"\n+\t\ttest -z \"${format}\" || message=$(git log -n 1 --format=\"%s\" ${sha1})\n \t\tused=\"$used$sha1 \"\n \t\twhile read -r squash action msg_prefix msg_content\n \t\tdo\n@@ -802,8 +808,13 @@ rearrange_squash () {\n \t\t\t\tcase \"$message\" in \"$msg_content\"*) emit=1;; esac ;;\n \t\t\tesac\n \t\t\tif test $emit = 1; then\n-\t\t\t\treal_prefix=$(echo \"$msg_prefix\" | sed \"s/,/! /g\")\n-\t\t\t\tprintf '%s\\n' \"$action $squash ${real_prefix}$msg_content\"\n+\t\t\t\tif test -n \"${format}\"\n+\t\t\t\tthen\n+\t\t\t\t\tmsg_content=$(git log -n 1 --format=\"${format}\" ${squash})\n+\t\t\t\telse\n+\t\t\t\t\tmsg_content=\"$(echo \"$msg_prefix\" | sed \"s/,/! /g\")$msg_content\"\n+\t\t\t\tfi\n+\t\t\t\tprintf '%s\\n' \"$action $squash $msg_content\"\n \t\t\t\tused=\"$used$squash \"\n \t\t\tfi\n \t\tdone <\"$1.sq\"\n@@ -977,7 +988,10 @@ else\n \trevisions=$onto...$orig_head\n \tshortrevisions=$shorthead\n fi\n-git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \\\n+format=$(git config --get rebase.instructionFormat)\n+# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse\n+git rev-list $merges_option --format=\"%m%H ${format:-%s}\" \\\n+\t--reverse --left-right --topo-order \\\n \t$revisions ${restrict_revision+^$restrict_revision} | \\\n \tsed -n \"s/^>//p\" |\n while read -r sha1 rest\ndiff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh\nindex 41370ab..10bed4c 100755\n--- a/t/t3415-rebase-autosquash.sh\n+++ b/t/t3415-rebase-autosquash.sh\n@@ -250,4 +250,25 @@ test_expect_success 'squash! fixup!' '\n \ttest_auto_fixup_fixup squash fixup\n '\n \n+test_expect_success 'autosquash with custom inst format matching on sha1' '\n+\tgit reset --hard base &&\n+\tgit config --add rebase.instructionFormat \"[%an @ %ar] %s\"  &&\n+\techo 2 >file1 &&\n+\tgit add -u &&\n+\ttest_tick &&\n+\tgit commit -m \"squash! $(git rev-parse --short HEAD^)\" &&\n+\techo 1 >file1 &&\n+\tgit add -u &&\n+\ttest_tick &&\n+\tgit commit -m \"squash! $(git log -n 1 --format=%s HEAD~2)\" &&\n+\tgit tag final-squash-instFmt &&\n+\ttest_tick &&\n+\tgit rebase --autosquash -i HEAD~4 &&\n+\tgit log --oneline >actual &&\n+\ttest_line_count = 3 actual &&\n+\tgit diff --exit-code final-squash-instFmt &&\n+\ttest 1 = \"$(git cat-file blob HEAD^:file1)\" &&\n+\ttest 2 = $(git cat-file commit HEAD^ | grep squash | wc -l)\n+'\n+\n test_done\n-- \n2.4.2\n"},{"id":"263697","messageId":"xmqqa8w4d4sc.fsf@gitster.dls.corp.google.com","threadId":"39606","inReplyTo":"1434075808-43453-2-git-send-email-rappazzo@gmail.com","subject":"Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-12T20:56:35Z","receivedAt":"2015-06-12T20:56:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Rappazzo <rappazzo@gmail.com> writes:\n\n> A config option 'rebase.instructionFormat' can override the\n> default 'oneline' format of the rebase instruction list.\n>\n> Since the list is parsed using the left, right or boundary mark plus\n> the sha1, they are prepended to the instruction format.\n>\n> Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>\n> ---\n>  Documentation/git-rebase.txt |  7 +++++++\n>  git-rebase--interactive.sh   | 20 +++++++++++++++++---\n>  t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++\n>  3 files changed, 45 insertions(+), 3 deletions(-)\n\nThanks, will replace.\n\nThe autosquash part somehow makes me feel uneasy, though.  The\nfeature fundamentally has to have %s as the first thing in the\nformat to work, but by making the format overridable, you are\npotentially breaking that feature, aren't you?\n"},{"id":"263699","messageId":"CANoM8SW-N6_yJ0kgGDuGWB+RS-0d54D4FtaRbKqhsf0_fSeMdw@mail.gmail.com","threadId":"39606","inReplyTo":"xmqqa8w4d4sc.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Mike Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2015-06-12T21:12:39Z","receivedAt":"2015-06-12T21:12:39Z","isPatch":true,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"It only needs the '%s' for the autosquash when the todo/instruction\nlist order is determined.  For this, in the rearrange_squash function,\nit will re-calculate the message:\n\n+               test -z \"${format}\" || message=$(git log -n 1\n--format=\"%s\" ${sha1})\n\nAdditionally, it may also rerun the log command when preparing the final list.\n\nIt is possible that this could be made more efficient by separating\nthe list arrangement from the list presentation.  I can look into that\nfor a future patch.\n\nI did add a test which uses the instructionFormat config, and then\ninteractively auto-squashes using both a 'squash! <sha1>' and a\n'squash! <comment>'. in the commits.\n\n\nOn Fri, Jun 12, 2015 at 4:56 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Michael Rappazzo <rappazzo@gmail.com> writes:\n>\n>> A config option 'rebase.instructionFormat' can override the\n>> default 'oneline' format of the rebase instruction list.\n>>\n>> Since the list is parsed using the left, right or boundary mark plus\n>> the sha1, they are prepended to the instruction format.\n>>\n>> Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>\n>> ---\n>>  Documentation/git-rebase.txt |  7 +++++++\n>>  git-rebase--interactive.sh   | 20 +++++++++++++++++---\n>>  t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++\n>>  3 files changed, 45 insertions(+), 3 deletions(-)\n>\n> Thanks, will replace.\n>\n> The autosquash part somehow makes me feel uneasy, though.  The\n> feature fundamentally has to have %s as the first thing in the\n> format to work, but by making the format overridable, you are\n> potentially breaking that feature, aren't you?\n"},{"id":"263709","messageId":"xmqqzj44bn1l.fsf@gitster.dls.corp.google.com","threadId":"39606","inReplyTo":"CANoM8SW-N6_yJ0kgGDuGWB+RS-0d54D4FtaRbKqhsf0_fSeMdw@mail.gmail.com","subject":"Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-12T22:05:10Z","receivedAt":"2015-06-12T22:05:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Rappazzo <rappazzo@gmail.com> writes:\n\n> On Fri, Jun 12, 2015 at 4:56 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> ...\n>> The autosquash part somehow makes me feel uneasy, though.  The\n>> feature fundamentally has to have %s as the first thing in the\n>> format to work, but by making the format overridable, you are\n>> potentially breaking that feature, aren't you?\n>\n> It only needs the '%s' for the autosquash when the todo/instruction\n> list order is determined.  For this, in the rearrange_squash function,\n> it will re-calculate the message:\n>\n> +               test -z \"${format}\" || message=$(git log -n 1\n> --format=\"%s\" ${sha1})\n>\n> Additionally, it may also rerun the log command when preparing the final list.\n\nYeah, I noticed that when I took a diff between v3 and v4.  I didn't\nmean by \"break\" that you may end up reorder lines incorrectly.\n\nBut because you overwrite the $message variable you read from the\noriginal insn sheet (which uses the custom format) and compute $rest\nbased on the default \"%s\" and store that in \"$1.sq\", lines in\n\"$1.sq\" do not know anything about the custom format, do they?\n\nAnd then they are injected to appropriate places in \"$1.rearranged\".\nMoved lines in the the rearranged result would end up written in the\ndefault \"%s\" format, no?\n\nThat was the part that made me uneasy.\n\nI do not think that is a bug worth fixing, but I view it as a sign\nthat fundamentally the autosquash and the idea of configurable\nformat do not mesh well with each other.\n"},{"id":"263711","messageId":"CANoM8SXQq_zbRui7SHDDAnrgf2VUdCkkJJ7_RHLu355JUzdNxA@mail.gmail.com","threadId":"39606","inReplyTo":"xmqqzj44bn1l.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Mike Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2015-06-12T22:15:44Z","receivedAt":"2015-06-12T22:15:44Z","isPatch":true,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"On Fri, Jun 12, 2015 at 6:05 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> But because you overwrite the $message variable you read from the\n> original insn sheet (which uses the custom format) and compute $rest\n> based on the default \"%s\" and store that in \"$1.sq\", lines in\n> \"$1.sq\" do not know anything about the custom format, do they?\n>\n> And then they are injected to appropriate places in \"$1.rearranged\".\n> Moved lines in the the rearranged result would end up written in the\n> default \"%s\" format, no?\n>\n> That was the part that made me uneasy.\n>\n> I do not think that is a bug worth fixing, but I view it as a sign\n> that fundamentally the autosquash and the idea of configurable\n> format do not mesh well with each other.\n\nMy understanding of the rearrange_squash function is this:\nThere are two loops.  The first loop collects the commits which should\nbe moved (squashed).  The second loop re-constructs the instruction\nlist using the info from the first loop.\n\nIn the second loop, I changed it to recalculate the presented message\nwhen the re-ordered commit is added:\n\n+       if test -n \"${format}\"\n+       then\n+            msg_content=$(git log -n 1 --format=\"${format}\" ${squash})\n\n\nThat is the \"$rest\".\n\nI have patched my locally installed `git-rebase--interactive` with\nthese changes, and I did see the proper rearrangement of commits with\nthe custom formatted message.\n"},{"id":"263718","messageId":"xmqqeglgblkp.fsf@gitster.dls.corp.google.com","threadId":"39606","inReplyTo":"CANoM8SXQq_zbRui7SHDDAnrgf2VUdCkkJJ7_RHLu355JUzdNxA@mail.gmail.com","subject":"Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-12T22:36:54Z","receivedAt":"2015-06-12T22:36:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Rappazzo <rappazzo@gmail.com> writes:\n\n> In the second loop, I changed it to recalculate the presented message\n> when the re-ordered commit is added:\n>\n> +       if test -n \"${format}\"\n> +       then\n> +            msg_content=$(git log -n 1 --format=\"${format}\" ${squash})\n>\n> That is the \"$rest\".\n\nAhh, yeah, I missed that --format=${format} thing.\n\nThanks.\n"}]}