{"thread":{"id":"39617","subject":"[PATCH v5] git-rebase--interactive.sh: add config option for custom instruction format","startedAt":"2015-06-13T16:26:57Z","lastAt":"2015-06-15T18:42:37Z","messageCount":3,"participants":["Michael Rappazzo","Junio C Hamano"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"263736","messageId":"1434212818-94682-1-git-send-email-rappazzo@gmail.com","threadId":"39617","inReplyTo":null,"subject":"[PATCH v5] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Michael Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2015-06-13T16:26:57Z","receivedAt":"2015-06-13T16:26:57Z","isPatch":true,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"Difference between v4 and v5 of this patch:\n\n  - added documention in Documentation/config.txt\n  - renamed the new auto-rebase w/ config test to be less inaccurate\n\nApologies for this, I should have caught these before.\n\n\nMichael Rappazzo (1):\n  git-rebase--interactive.sh: add config option for custom instruction\n    format\n\n Documentation/config.txt     |  5 +++++\n Documentation/git-rebase.txt |  7 +++++++\n git-rebase--interactive.sh   | 20 +++++++++++++++++---\n t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++\n 4 files changed, 50 insertions(+), 3 deletions(-)\n\n-- \n2.4.2\n"},{"id":"263737","messageId":"1434212818-94682-2-git-send-email-rappazzo@gmail.com","threadId":"39617","inReplyTo":"1434212818-94682-1-git-send-email-rappazzo@gmail.com","subject":"[PATCH v5] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Michael Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2015-06-13T16:26:58Z","receivedAt":"2015-06-13T16:26:58Z","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/config.txt     |  5 +++++\n Documentation/git-rebase.txt |  7 +++++++\n git-rebase--interactive.sh   | 20 +++++++++++++++++---\n t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++\n 4 files changed, 50 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 43bb53c..4c271c6 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -2161,6 +2161,11 @@ rebase.autoStash::\n \tsuccessful rebase might result in non-trivial conflicts.\n \tDefaults to false.\n \n+rebase.instructionFormat\n+\tA format string, as specified in linkgit:git-log[1], to be used for \n+\tthe instruction list during an interactive rebase.  The format will automatically\n+\thave the long commit hash prepended to the format.  \n+\n receive.advertiseAtomic::\n \tBy default, git-receive-pack will advertise the atomic push\n \tcapability to its clients. If you don't want to this capability\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..8f53e54 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' '\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":"263881","messageId":"xmqqtwu895k2.fsf@gitster.dls.corp.google.com","threadId":"39617","inReplyTo":"1434212818-94682-2-git-send-email-rappazzo@gmail.com","subject":"Re: [PATCH v5] git-rebase--interactive.sh: add config option for custom instruction format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-15T18:42:37Z","receivedAt":"2015-06-15T18:42:37Z","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> diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt\n> index 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\nFunny indent (no need to resend, as I can locally fix, but I am\npointing it out because it was irritating enough that I had to keep\ncorrecting it every time I replaced this series with a new version).\n\nThanks.\n"}]}