All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format
@ 2015-06-12  2:23 Michael Rappazzo
  2015-06-12  2:23 ` Michael Rappazzo
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Rappazzo @ 2015-06-12  2:23 UTC (permalink / raw)
  To: gitster, johannes.schindelin; +Cc: git, Michael Rappazzo

Difference between v3 and v4 of this patch:

    - cleaned up changes in rearrange_squash() function
    - consolidated autosquash test 

Michael Rappazzo (1):
  git-rebase--interactive.sh: add config option for custom instruction
    format

 Documentation/git-rebase.txt |  7 +++++++
 git-rebase--interactive.sh   | 20 +++++++++++++++++---
 t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++
 3 files changed, 45 insertions(+), 3 deletions(-)

-- 
2.4.2

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format
  2015-06-12  2:23 [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format Michael Rappazzo
@ 2015-06-12  2:23 ` Michael Rappazzo
  2015-06-12 20:56   ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Rappazzo @ 2015-06-12  2:23 UTC (permalink / raw)
  To: gitster, johannes.schindelin; +Cc: git, Michael Rappazzo

A config option 'rebase.instructionFormat' can override the
default 'oneline' format of the rebase instruction list.

Since the list is parsed using the left, right or boundary mark plus
the sha1, they are prepended to the instruction format.

Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
---
 Documentation/git-rebase.txt |  7 +++++++
 git-rebase--interactive.sh   | 20 +++++++++++++++++---
 t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++
 3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..8ddab77 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,9 @@ rebase.autoSquash::
 rebase.autoStash::
 	If set to true enable '--autostash' option by default.
 
+rebase.instructionFormat::
+   Custom commit list format to use during an '--interactive' rebase.
+
 OPTIONS
 -------
 --onto <newbase>::
@@ -359,6 +362,10 @@ default is `--no-fork-point`, otherwise the default is `--fork-point`.
 	Make a list of the commits which are about to be rebased.  Let the
 	user edit that list before rebasing.  This mode can also be used to
 	split commits (see SPLITTING COMMITS below).
++
+The commit list format can be changed by setting the configuration option
+rebase.instructionFormat.  A customized instruction format will automatically
+have the long commit hash prepended to the format.
 
 -p::
 --preserve-merges::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index dc3133f..755f9c1 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -740,10 +740,15 @@ collapse_todo_ids() {
 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
 # comes immediately after the former, and change "pick" to
 # "fixup"/"squash".
+#
+# Note that if the config has specified a custom instruction format
+# each log message will be re-retrieved in order to normalize the 
+# autosquash arrangement
 rearrange_squash () {
 	# extract fixup!/squash! lines and resolve any referenced sha1's
 	while read -r pick sha1 message
 	do
+		test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
 		case "$message" in
 		"squash! "*|"fixup! "*)
 			action="${message%%!*}"
@@ -785,6 +790,7 @@ rearrange_squash () {
 		*" $sha1 "*) continue ;;
 		esac
 		printf '%s\n' "$pick $sha1 $message"
+		test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
 		used="$used$sha1 "
 		while read -r squash action msg_prefix msg_content
 		do
@@ -802,8 +808,13 @@ rearrange_squash () {
 				case "$message" in "$msg_content"*) emit=1;; esac ;;
 			esac
 			if test $emit = 1; then
-				real_prefix=$(echo "$msg_prefix" | sed "s/,/! /g")
-				printf '%s\n' "$action $squash ${real_prefix}$msg_content"
+				if test -n "${format}"
+				then
+					msg_content=$(git log -n 1 --format="${format}" ${squash})
+				else
+					msg_content="$(echo "$msg_prefix" | sed "s/,/! /g")$msg_content"
+				fi
+				printf '%s\n' "$action $squash $msg_content"
 				used="$used$squash "
 			fi
 		done <"$1.sq"
@@ -977,7 +988,10 @@ else
 	revisions=$onto...$orig_head
 	shortrevisions=$shorthead
 fi
-git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \
+format=$(git config --get rebase.instructionFormat)
+# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
+git rev-list $merges_option --format="%m%H ${format:-%s}" \
+	--reverse --left-right --topo-order \
 	$revisions ${restrict_revision+^$restrict_revision} | \
 	sed -n "s/^>//p" |
 while read -r sha1 rest
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index 41370ab..10bed4c 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -250,4 +250,25 @@ test_expect_success 'squash! fixup!' '
 	test_auto_fixup_fixup squash fixup
 '
 
+test_expect_success 'autosquash with custom inst format matching on sha1' '
+	git reset --hard base &&
+	git config --add rebase.instructionFormat "[%an @ %ar] %s"  &&
+	echo 2 >file1 &&
+	git add -u &&
+	test_tick &&
+	git commit -m "squash! $(git rev-parse --short HEAD^)" &&
+	echo 1 >file1 &&
+	git add -u &&
+	test_tick &&
+	git commit -m "squash! $(git log -n 1 --format=%s HEAD~2)" &&
+	git tag final-squash-instFmt &&
+	test_tick &&
+	git rebase --autosquash -i HEAD~4 &&
+	git log --oneline >actual &&
+	test_line_count = 3 actual &&
+	git diff --exit-code final-squash-instFmt &&
+	test 1 = "$(git cat-file blob HEAD^:file1)" &&
+	test 2 = $(git cat-file commit HEAD^ | grep squash | wc -l)
+'
+
 test_done
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format
  2015-06-12  2:23 ` Michael Rappazzo
@ 2015-06-12 20:56   ` Junio C Hamano
  2015-06-12 21:12     ` Mike Rappazzo
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2015-06-12 20:56 UTC (permalink / raw)
  To: Michael Rappazzo; +Cc: johannes.schindelin, git

Michael Rappazzo <rappazzo@gmail.com> writes:

> A config option 'rebase.instructionFormat' can override the
> default 'oneline' format of the rebase instruction list.
>
> Since the list is parsed using the left, right or boundary mark plus
> the sha1, they are prepended to the instruction format.
>
> Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
> ---
>  Documentation/git-rebase.txt |  7 +++++++
>  git-rebase--interactive.sh   | 20 +++++++++++++++++---
>  t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++
>  3 files changed, 45 insertions(+), 3 deletions(-)

Thanks, will replace.

The autosquash part somehow makes me feel uneasy, though.  The
feature fundamentally has to have %s as the first thing in the
format to work, but by making the format overridable, you are
potentially breaking that feature, aren't you?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format
  2015-06-12 20:56   ` Junio C Hamano
@ 2015-06-12 21:12     ` Mike Rappazzo
  2015-06-12 22:05       ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Rappazzo @ 2015-06-12 21:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, Git List

It only needs the '%s' for the autosquash when the todo/instruction
list order is determined.  For this, in the rearrange_squash function,
it will re-calculate the message:

+               test -z "${format}" || message=$(git log -n 1
--format="%s" ${sha1})

Additionally, it may also rerun the log command when preparing the final list.

It is possible that this could be made more efficient by separating
the list arrangement from the list presentation.  I can look into that
for a future patch.

I did add a test which uses the instructionFormat config, and then
interactively auto-squashes using both a 'squash! <sha1>' and a
'squash! <comment>'. in the commits.


On Fri, Jun 12, 2015 at 4:56 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Michael Rappazzo <rappazzo@gmail.com> writes:
>
>> A config option 'rebase.instructionFormat' can override the
>> default 'oneline' format of the rebase instruction list.
>>
>> Since the list is parsed using the left, right or boundary mark plus
>> the sha1, they are prepended to the instruction format.
>>
>> Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
>> ---
>>  Documentation/git-rebase.txt |  7 +++++++
>>  git-rebase--interactive.sh   | 20 +++++++++++++++++---
>>  t/t3415-rebase-autosquash.sh | 21 +++++++++++++++++++++
>>  3 files changed, 45 insertions(+), 3 deletions(-)
>
> Thanks, will replace.
>
> The autosquash part somehow makes me feel uneasy, though.  The
> feature fundamentally has to have %s as the first thing in the
> format to work, but by making the format overridable, you are
> potentially breaking that feature, aren't you?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format
  2015-06-12 21:12     ` Mike Rappazzo
@ 2015-06-12 22:05       ` Junio C Hamano
  2015-06-12 22:15         ` Mike Rappazzo
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2015-06-12 22:05 UTC (permalink / raw)
  To: Mike Rappazzo; +Cc: Johannes Schindelin, Git List

Mike Rappazzo <rappazzo@gmail.com> writes:

> On Fri, Jun 12, 2015 at 4:56 PM, Junio C Hamano <gitster@pobox.com> wrote:
> ...
>> The autosquash part somehow makes me feel uneasy, though.  The
>> feature fundamentally has to have %s as the first thing in the
>> format to work, but by making the format overridable, you are
>> potentially breaking that feature, aren't you?
>
> It only needs the '%s' for the autosquash when the todo/instruction
> list order is determined.  For this, in the rearrange_squash function,
> it will re-calculate the message:
>
> +               test -z "${format}" || message=$(git log -n 1
> --format="%s" ${sha1})
>
> Additionally, it may also rerun the log command when preparing the final list.

Yeah, I noticed that when I took a diff between v3 and v4.  I didn't
mean by "break" that you may end up reorder lines incorrectly.

But because you overwrite the $message variable you read from the
original insn sheet (which uses the custom format) and compute $rest
based on the default "%s" and store that in "$1.sq", lines in
"$1.sq" do not know anything about the custom format, do they?

And then they are injected to appropriate places in "$1.rearranged".
Moved lines in the the rearranged result would end up written in the
default "%s" format, no?

That was the part that made me uneasy.

I do not think that is a bug worth fixing, but I view it as a sign
that fundamentally the autosquash and the idea of configurable
format do not mesh well with each other.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format
  2015-06-12 22:05       ` Junio C Hamano
@ 2015-06-12 22:15         ` Mike Rappazzo
  2015-06-12 22:36           ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Rappazzo @ 2015-06-12 22:15 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, Git List

On Fri, Jun 12, 2015 at 6:05 PM, Junio C Hamano <gitster@pobox.com> wrote:
> But because you overwrite the $message variable you read from the
> original insn sheet (which uses the custom format) and compute $rest
> based on the default "%s" and store that in "$1.sq", lines in
> "$1.sq" do not know anything about the custom format, do they?
>
> And then they are injected to appropriate places in "$1.rearranged".
> Moved lines in the the rearranged result would end up written in the
> default "%s" format, no?
>
> That was the part that made me uneasy.
>
> I do not think that is a bug worth fixing, but I view it as a sign
> that fundamentally the autosquash and the idea of configurable
> format do not mesh well with each other.

My understanding of the rearrange_squash function is this:
There are two loops.  The first loop collects the commits which should
be moved (squashed).  The second loop re-constructs the instruction
list using the info from the first loop.

In the second loop, I changed it to recalculate the presented message
when the re-ordered commit is added:

+       if test -n "${format}"
+       then
+            msg_content=$(git log -n 1 --format="${format}" ${squash})


That is the "$rest".

I have patched my locally installed `git-rebase--interactive` with
these changes, and I did see the proper rearrangement of commits with
the custom formatted message.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format
  2015-06-12 22:15         ` Mike Rappazzo
@ 2015-06-12 22:36           ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2015-06-12 22:36 UTC (permalink / raw)
  To: Mike Rappazzo; +Cc: Johannes Schindelin, Git List

Mike Rappazzo <rappazzo@gmail.com> writes:

> In the second loop, I changed it to recalculate the presented message
> when the re-ordered commit is added:
>
> +       if test -n "${format}"
> +       then
> +            msg_content=$(git log -n 1 --format="${format}" ${squash})
>
> That is the "$rest".

Ahh, yeah, I missed that --format=${format} thing.

Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-06-12 22:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-12  2:23 [PATCH v4] git-rebase--interactive.sh: add config option for custom instruction format Michael Rappazzo
2015-06-12  2:23 ` Michael Rappazzo
2015-06-12 20:56   ` Junio C Hamano
2015-06-12 21:12     ` Mike Rappazzo
2015-06-12 22:05       ` Junio C Hamano
2015-06-12 22:15         ` Mike Rappazzo
2015-06-12 22:36           ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.