git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PROBE] cg-commit: show and enable editing of changes with --review
@ 2005-11-30  0:01 Jonas Fonseca
  2005-11-30  0:30 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Jonas Fonseca @ 2005-11-30  0:01 UTC (permalink / raw
  To: Petr Baudis; +Cc: git

Show changes being commited as a patch appended to the commit message
buffer. If the original patch is different from the patch extracted from
the commit message file the original patch will be reverted and the edited
patch applied before completing the commit.

Due to limitations with cg-patch this can only be used when commiting
from the project root directory. The error handling if the either the
original patch or the edited patch does not apply is not optimal, since
cg-patch will not report errors properly.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

---
commit 5031c74c4716793784314f836f4ceb6bcfa6698a
tree d01b7a66054352a89c637d58c7ab6454a26ba700
parent dd872816a04f6462686e282b00d3e1523e3ecf4c
author Jonas Fonseca <fonseca@diku.dk> Wed, 30 Nov 2005 00:41:06 +0100
committer Jonas Fonseca <fonseca@antimatter.localdomain> Wed, 30 Nov 2005 00:41:06 +0100

 TODO      |    4 ----
 cg-commit |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/TODO b/TODO
index 777c728..cffa753 100644
--- a/TODO
+++ b/TODO
@@ -79,10 +79,6 @@ cg-*patch should be pre-1.0.)
 		  whitespace errors and stuff; hooks are good for this too,
 		  but I think it's good to have internal support for the
 		  basic stuff.
-	-- post 1.0 --
-	* Patch-altering cg-commit
-		You can already alter the list of files to be committed,
-		let's optionally show the patch and let you alter it, too.
 
 * cg-push over HTTP
 
diff --git a/cg-commit b/cg-commit
index 9f8d5d5..1a3c361 100755
--- a/cg-commit
+++ b/cg-commit
@@ -63,6 +63,12 @@
 #	Optionally, specify the exact name and email to sign off with by
 #	passing: `--signoff="Author Name <user@example.com>"`.
 #
+# --review:: Show and enable editing of changes being committed
+#	Show changes being commited as a patch appended to the commit message
+#	buffer. Changes made to the patch will be reapplied before completing
+#	the commit. Only makes sense with interactive commit message editing.
+#	Note, can only be used when commiting from the project root directory.
+#
 # FILES
 # -----
 # $GIT_DIR/author::
@@ -153,6 +159,7 @@ ignorecache=
 infoonly=
 commitalways=
 missingok=
+review=
 signoff=
 copy_commit=
 msgs=()
@@ -172,6 +179,9 @@ while optparse; do
 		force=1
 	elif optparse -q; then
 		quiet=1
+	elif optparse --review; then
+		[ "$_git_relpath" ] && die "--review can only be used when run from project root"
+		review=1
 	elif optparse -s || optparse --signoff; then
 		[ "$signoff" ] || signoff="$(git-var GIT_AUTHOR_IDENT | sed 's/> .*/>/')"
 	elif optparse --signoff=; then
@@ -187,6 +197,11 @@ done
 
 [ "$ignorecache" ] || cg-object-id HEAD >/dev/null 2>&1 || die "no previous commit; use -C for the initial commit"
 
+if [ "$review" ]; then
+	PATCH=$(mktemp -t gitci.XXXXXX)
+	PATCH2=$(mktemp -t gitci.XXXXXX)
+fi
+
 if [ "$ARGS" -o "$_git_relpath" ]; then
 	[ "$ignorecache" ] && die "-C and listing files to commit does not make sense"
 	[ -s $_git/merging ] && die "cannot commit individual files when merging"
@@ -201,6 +216,7 @@ if [ "$ARGS" -o "$_git_relpath" ]; then
 		sed 's/^\([^	]*\)\(.	.*\)\(	.*\)*$/"\2"/'))
 	customfiles=1
 
+	[ "$review" ] && < $filter | path_xargs git-diff-index -r -p HEAD > $PATCH
 	rm $filter
 
 else
@@ -227,6 +243,8 @@ else
 		fi
 	fi
 
+	[ "$review" ] && git-diff-index -r -p HEAD > $PATCH
+
 	merging=
 	[ -s $_git/merging ] && merging=$(cat $_git/merging | sed 's/^/-p /')
 fi
@@ -347,7 +365,21 @@ if [ ! "$ignorecache" ]; then
 	fi
 fi
 echo "CG: -----------------------------------------------------------------------" >>$LOGMSG
-echo "CG: vim: textwidth=75" >>$LOGMSG
+
+if [ "$review" ]; then
+	{
+		echo "CG:"
+		echo "CG: Change summary:"
+		echo "CG:"
+		git-apply --stat --summary < $PATCH | sed 's/^/CG: /'
+		echo "CG:"
+		cat $PATCH
+	} >>$LOGMSG
+
+	ftdiff="filetype=diff"
+fi
+
+echo "CG: vim: textwidth=75 $ftdiff" >>$LOGMSG
 
 cp $LOGMSG $LOGMSG2
 if tty -s; then
@@ -359,6 +391,7 @@ if tty -s; then
 				read -p 'Abort or commit? [ac] ' choice
 				if [ "$choice" = "a" ] || [ "$choice" = "q" ]; then
 					rm $LOGMSG $LOGMSG2
+					[ "$review" ] && rm $PATCH $PATCH2
 					echo "Commit message not modified, commit aborted" >&2
 					if [ "$merging" ]; then
 						cat >&2 <<__END__
@@ -400,9 +433,35 @@ else
 	cat >$LOGMSG2
 fi
 # Remove heading and trailing blank lines.
-grep -v ^CG: $LOGMSG2 | git-stripspace >$LOGMSG
+if [ ! "$review" ]; then
+	grep -v ^CG: $LOGMSG2 | git-stripspace >$LOGMSG
+else
+	sed '/^CG: Change summary:/,$d' < $LOGMSG2 | grep -v ^CG: | git-stripspace >$LOGMSG
+	sed -n '/^CG: Change summary:/,$p' < $LOGMSG2 | grep -v ^CG: > $PATCH2
+fi
 rm $LOGMSG2
 
+if [ "$review" ]; then
+	error_msg=
+	if ! cmp -s $PATCH $PATCH2; then
+		echo "Updating changes to edited patch"
+		# FIXME: Can only be run from the top level
+		# FIXME: Is very 'fragile' error handling. We should probably
+		# save the original patch in a local file for recovery?
+		if ! cg-patch -R < $PATCH; then
+			backup=$(mktemp commit-backup.XXXXXX)
+			cp $PATCH $backup
+			error_msg="unable to revert original patch, backup saved to $backup"
+		elif ! cg-patch < $PATCH2; then
+			backup=$(mktemp commit-backup.XXXXXX)
+			cp $PATCH2 $backup
+			error_msg="unable to apply edited patch, backup saved to $backup"
+		fi
+	fi
+	rm $PATCH $PATCH2
+	[ "$error_msg" ] && { rm $LOGMSG; die "$error_msg" }
+fi
+
 
 precommit_update()
 {

-- 
Jonas Fonseca

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

* Re: [PROBE] cg-commit: show and enable editing of changes with --review
  2005-11-30  0:01 [PROBE] cg-commit: show and enable editing of changes with --review Jonas Fonseca
@ 2005-11-30  0:30 ` Junio C Hamano
  2005-12-01 13:20   ` Jonas Fonseca
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2005-11-30  0:30 UTC (permalink / raw
  To: Jonas Fonseca; +Cc: git

Jonas Fonseca <fonseca@diku.dk> writes:

> Show changes being commited as a patch appended to the commit message
> buffer. If the original patch is different from the patch extracted from
> the commit message file the original patch will be reverted and the edited
> patch applied before completing the commit.
>
> Due to limitations with cg-patch this can only be used when commiting
> from the project root directory. The error handling if the either the
> original patch or the edited patch does not apply is not optimal, since
> cg-patch will not report errors properly.

I do not do Porcelains, I am not a Cogito user, and I generally
do not like encouraging people who are playing an individual
developer role to commit something that has never existed in
their working tree (hence by definition never been tested),
but...

> +		echo "Updating changes to edited patch"
> +		# FIXME: Can only be run from the top level
> +		# FIXME: Is very 'fragile' error handling. We should probably
> +		# save the original patch in a local file for recovery?
> +		if ! cg-patch -R < $PATCH; then
> +			backup=$(mktemp commit-backup.XXXXXX)
> +			cp $PATCH $backup
> +			error_msg="unable to revert original patch, backup saved to $backup"

I suspect at least you should be able to use checkout-index for
the first one instead of cg-patch.

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

* Re: [PROBE] cg-commit: show and enable editing of changes with --review
  2005-11-30  0:30 ` Junio C Hamano
@ 2005-12-01 13:20   ` Jonas Fonseca
  0 siblings, 0 replies; 3+ messages in thread
From: Jonas Fonseca @ 2005-12-01 13:20 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

Junio C Hamano <junkio@cox.net> wrote Tue, Nov 29, 2005:
> Jonas Fonseca <fonseca@diku.dk> writes:
> 
> > Show changes being commited as a patch appended to the commit message
> > buffer. If the original patch is different from the patch extracted from
> > the commit message file the original patch will be reverted and the edited
> > patch applied before completing the commit.
> >
> > Due to limitations with cg-patch this can only be used when commiting
> > from the project root directory. The error handling if the either the
> > original patch or the edited patch does not apply is not optimal, since
> > cg-patch will not report errors properly.
> 
> I do not do Porcelains,

I am curious since you have also used this phrase in the past: didn't
you do your own jit porcelain once and are you saying that git does not
ship with it's own porcelain?

> I am not a Cogito user, and I generally
> do not like encouraging people who are playing an individual
> developer role to commit something that has never existed in
> their working tree (hence by definition never been tested),
> but...

I see your point. I mostly intend to use it for fixing small typos in
comments and documentation. It can help to cure some "post-commit
stress".  Also I hope you will agree that it is always a good idea to
review your changes one more time although I agree it might be a little
silly.

> > +		echo "Updating changes to edited patch"
> > +		# FIXME: Can only be run from the top level
> > +		# FIXME: Is very 'fragile' error handling. We should probably
> > +		# save the original patch in a local file for recovery?
> > +		if ! cg-patch -R < $PATCH; then
> > +			backup=$(mktemp commit-backup.XXXXXX)
> > +			cp $PATCH $backup
> > +			error_msg="unable to revert original patch, backup saved to $backup"
> 
> I suspect at least you should be able to use checkout-index for
> the first one instead of cg-patch.

Oh, great, thanks. I guess I should work some more on the git docs to
get to know these kind of things.

-- 
Jonas Fonseca

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

end of thread, other threads:[~2005-12-01 13:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-30  0:01 [PROBE] cg-commit: show and enable editing of changes with --review Jonas Fonseca
2005-11-30  0:30 ` Junio C Hamano
2005-12-01 13:20   ` Jonas Fonseca

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).