git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Seymour <jon.seymour@gmail.com>
To: git@vger.kernel.org
Cc: jon.seymour@gmail.com
Subject: [PATCH 1/2] Reorganization of git-commit-script [rev 3]
Date: Wed, 15 Jun 2005 17:35:58 +1000	[thread overview]
Message-ID: <20050615073558.25126.qmail@blackcubes.dyndns.org> (raw)


This change re-organizes git-commit-script to break out
the different phases of execution into separate bash
functions.

The main body is now:

if ! print_status > .editmsg; then
	# error handling
fi

if edit_message .editmsg .cmitmsg; then
	exec_commit .cmitmsg
	# cleanup
fi

The subsequent patch in this series adds support for
an optional .nextmsg file to enable the pre-population
of commit message text by external tools.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>

[rev 3] - oops, sorry, forgot to test merge case
---

 git-commit-script |  100 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 65 insertions(+), 35 deletions(-)

diff --git a/git-commit-script b/git-commit-script
old mode 100644
new mode 100755
--- a/git-commit-script
+++ b/git-commit-script
@@ -1,44 +1,74 @@
 #!/bin/sh
+
+print_status() {
+	if [ ! -r $GIT_DIR/HEAD ]; then
+		if [ -z "$(git-ls-files)" ]; then
+			echo Nothing to commit 1>&2
+			return 1
+		fi
+cat <<EOF
+#
+# Initial commit
+# 
+$(git-ls-files | sed s/^/# New file: )
+#
+EOF
+	elif [ -f $GIT_DIR/MERGE_HEAD ]; then
+cat <<EOF
+#
+# It looks like your may be committing a MERGE.
+# If this is not correct, please remove the file
+# $GIT_DIR/MERGE_HEAD
+# and try again
+#
+EOF
+	fi
+	git-status-script
+}
+
+edit_message() {
+	status=$1
+	msg=$2
+
+	:> $msg
+	${VISUAL:-${EDITOR:-vi}} "$status"
+	grep -v '^#' < $status | git-stripspace >$msg
+	[ -s $msg ]
+	return $?
+}
+
+commit_parents() {
+	[ -f $GIT_DIR/HEAD ] &&
+	echo -n "-p HEAD" &&
+	[ -f $GIT_DIR/MERGE_HEAD ] &&
+	echo -n " -p MERGE_HEAD"
+	echo ""
+}
+
+exec_commit() {
+	msg=$1
+	tree=$(git-write-tree) || exit 1
+	parents=$(commit_parents) || exit 1
+	commit=$(cat $msg | git-commit-tree $tree $parents) || exit 1
+	echo $commit > $GIT_DIR/HEAD
+	rm -f -- $GIT_DIR/MERGE_HEAD
+}
+
+SENTINEL="#SENTINEL - delete this line to confirm the commit"
 : ${GIT_DIR=.git}
 if [ ! -d $GIT_DIR ]; then
 	echo Not a git directory 1>&2
 	exit 1
 fi
-PARENTS="-p HEAD"
-if [ ! -r $GIT_DIR/HEAD ]; then
-	if [ -z "$(git-ls-files)" ]; then
-		echo Nothing to commit 1>&2
-		exit 1
-	fi
-	(
-		echo "#"
-		echo "# Initial commit"
-		echo "#"
-		git-ls-files | sed 's/^/# New file: /'
-		echo "#"
-	) > .editmsg
-	PARENTS=""
-else
-	if [ -f $GIT_DIR/MERGE_HEAD ]; then
-		echo "#"
-		echo "# It looks like your may be committing a MERGE."
-		echo "# If this is not correct, please remove the file"
-		echo "#	$GIT_DIR/MERGE_HEAD"
-		echo "# and try again"
-		echo "#"
-		PARENTS="-p HEAD -p MERGE_HEAD"
-	fi > .editmsg
-	git-status-script >> .editmsg
-fi
-if [ "$?" != "0" ]
-then
+
+if ! print_status > .editmsg; then
 	cat .editmsg
+	rm .editmsg
 	exit 1
 fi
-${VISUAL:-${EDITOR:-vi}} .editmsg
-grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
-[ -s .cmitmsg ] || exit 1
-tree=$(git-write-tree) || exit 1
-commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) || exit 1
-echo $commit > $GIT_DIR/HEAD
-rm -f -- $GIT_DIR/MERGE_HEAD
+
+if edit_message .editmsg .cmitmsg; then
+	exec_commit .cmitmsg
+	[ -f .editmsg ] && rm .editmsg
+	[ -f .cmitmsg ] && rm .cmitmsg
+fi
------------

             reply	other threads:[~2005-06-15  7:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15  7:35 Jon Seymour [this message]
2005-06-15  8:05 ` [WITHDRAWN PATCH] Reorganization of git-commit-script [rev 3] etc Jon Seymour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050615073558.25126.qmail@blackcubes.dyndns.org \
    --to=jon.seymour@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).