{"thread":{"id":"943","subject":"[PATCH 1/2] Reorganization of git-commit-script","startedAt":"2005-06-15T05:45:30Z","lastAt":"2005-06-15T05:45:30Z","messageCount":1,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"4964","messageId":"20050615054530.9963.qmail@blackcubes.dyndns.org","threadId":"943","inReplyTo":null,"subject":"[PATCH 1/2] Reorganization of git-commit-script","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2005-06-15T05:45:30Z","receivedAt":"2005-06-15T05:45:30Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"\nThis change re-organizes git-commit-script to break out\nthe different phases of execution into separate bash\nfunctions.\n\nThe main body is now:\n\nif ! print_status > .editmsg; then\n\t# error handling\nfi\n\nif edit_message .editmsg .cmitmsg; then\n\texec_commit .cmitmsg\n\t# cleanup\nfi\n\nThe subsequent patch in this series adds support for\nan optional .nextmsg file to enable the pre-population\nof commit message text by external tools.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n\n git-commit-script |  100 ++++++++++++++++++++++++++++++++++-------------------\n 1 files changed, 65 insertions(+), 35 deletions(-)\n\ndiff --git a/git-commit-script b/git-commit-script\nold mode 100644\nnew mode 100755\n--- a/git-commit-script\n+++ b/git-commit-script\n@@ -1,44 +1,74 @@\n #!/bin/sh\n+\n+print_status() {\n+\tif [ ! -r $GIT_DIR/HEAD ]; then\n+\t\tif [ -z \"$(git-ls-files)\" ]; then\n+\t\t\techo Nothing to commit 1>&2\n+\t\t\treturn 1\n+\t\tfi\n+cat <<EOF\n+#\n+# Initial commit\n+# \n+$(git-ls-files | sed s/^/# New file: )\n+#\n+EOF\n+\telif [ -f $GIT_DIR/MERGE_HEAD ]; then\n+cat <<EOF\n+#\n+# It looks like your may be committing a MERGE.\n+# If this is not correct, please remove the file\n+# $GIT_DIR/MERGE_HEAD\n+# and try again\n+#\n+EOF\n+\tfi\n+\tgit-status-script\n+}\n+\n+edit_message() {\n+\tstatus=$1\n+\tmsg=$2\n+\n+\t:> $msg\n+\t${VISUAL:-${EDITOR:-vi}} \"$status\"\n+\tgrep -v '^#' < $status | git-stripspace >$msg\n+\t[ -s $msg ]\n+\treturn $?\n+}\n+\n+commit_parents() {\n+\t[ -f $GIT_DIR/HEAD ] &&\n+\techo -n \"-p HEAD\" &&\n+\t[ -f $GIT_DIR/MERGE_HEAD ] &&\n+\techo -n \"-p MERGE_HEAD\"\n+\techo \"\"\n+}\n+\n+exec_commit() {\n+\tmsg=$1\n+\ttree=$(git-write-tree) || exit 1\n+\tparents=$(commit_parents) || exit 1\n+\tcommit=$(cat $msg | git-commit-tree $tree $parents) || exit 1\n+\techo $commit > $GIT_DIR/HEAD\n+\trm -f -- $GIT_DIR/MERGE_HEAD\n+}\n+\n+SENTINEL=\"#SENTINEL - delete this line to confirm the commit\"\n : ${GIT_DIR=.git}\n if [ ! -d $GIT_DIR ]; then\n \techo Not a git directory 1>&2\n \texit 1\n fi\n-PARENTS=\"-p HEAD\"\n-if [ ! -r $GIT_DIR/HEAD ]; then\n-\tif [ -z \"$(git-ls-files)\" ]; then\n-\t\techo Nothing to commit 1>&2\n-\t\texit 1\n-\tfi\n-\t(\n-\t\techo \"#\"\n-\t\techo \"# Initial commit\"\n-\t\techo \"#\"\n-\t\tgit-ls-files | sed 's/^/# New file: /'\n-\t\techo \"#\"\n-\t) > .editmsg\n-\tPARENTS=\"\"\n-else\n-\tif [ -f $GIT_DIR/MERGE_HEAD ]; then\n-\t\techo \"#\"\n-\t\techo \"# It looks like your may be committing a MERGE.\"\n-\t\techo \"# If this is not correct, please remove the file\"\n-\t\techo \"#\t$GIT_DIR/MERGE_HEAD\"\n-\t\techo \"# and try again\"\n-\t\techo \"#\"\n-\t\tPARENTS=\"-p HEAD -p MERGE_HEAD\"\n-\tfi > .editmsg\n-\tgit-status-script >> .editmsg\n-fi\n-if [ \"$?\" != \"0\" ]\n-then\n+\n+if ! print_status > .editmsg; then\n \tcat .editmsg\n+\trm .editmsg\n \texit 1\n fi\n-${VISUAL:-${EDITOR:-vi}} .editmsg\n-grep -v '^#' < .editmsg | git-stripspace > .cmitmsg\n-[ -s .cmitmsg ] || exit 1\n-tree=$(git-write-tree) || exit 1\n-commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) || exit 1\n-echo $commit > $GIT_DIR/HEAD\n-rm -f -- $GIT_DIR/MERGE_HEAD\n+\n+if edit_message .editmsg .cmitmsg; then\n+\texec_commit .cmitmsg\n+\t[ -f .editmsg ] && rm .editmsg\n+\t[ -f .cmitmsg ] && rm .cmitmsg\n+fi\n------------\n"}]}