From: James Ketrenos <jketreno@linux.intel.com>
To: git@vger.kernel.org
Subject: [PATCH] cogito -- add -c $commit support
Date: Thu, 25 Aug 2005 13:19:55 -0500 [thread overview]
Message-ID: <430E0BCB.5010402@linux.intel.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 3086 bytes --]
Add -c parameter to cg-commit to set commit data based on prior commit.
This will then commit any changes using the author and message from the commit
specified. The actual logic for parsing the old commit values was taken from
git-commit-script.
git-commit-script supports this option via -C, which was already used in cg-commit
for something else.
Signed-off-by: James Ketrenos <jketreno@linux.intel.com>
---
cg-commit | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 1 deletions(-)
b07037397659763271e946fc15c0b3c61a8fcdfa
diff --git a/cg-commit b/cg-commit
--- a/cg-commit
+++ b/cg-commit
@@ -3,6 +3,8 @@
# Commit into a GIT repository.
# Copyright (c) Petr Baudis, 2005
# Based on an example script fragment sent to LKML by Linus Torvalds.
+#
+# -c commit based on code in git-commit-script by Linus Torvalds
#
# Commits changes to a GIT repository. Accepts the commit message from
# `stdin`. If the commit message is not modified the commit will be
@@ -45,6 +47,12 @@
# might not actually _have_ any object database. This option is
# normally not interesting.
#
+# -c::
+# Specifify the commit SHA to inherit the GIT_AUTHOR_* variables and
+# commit message from. The GIT_COMMITTER_* variables will not be
+# inherited from the specified commit. This option is typically used
+# when replaying commits from one lineage or repository to another.
+#
# FILES
# -----
# $GIT_DIR/author::
@@ -112,6 +120,7 @@ ignorecache=
infoonly=
commitalways=
missingok=
+use_commit=
msgs=()
while optparse; do
if optparse -C; then
@@ -128,6 +137,8 @@ while optparse; do
force=1
elif optparse -m=; then
msgs[${#msgs[@]}]="$OPTARG"
+ elif optparse -c=; then
+ use_commit="$OPTARG"
else
optfail
fi
@@ -196,6 +207,39 @@ for msg in "${msgs[@]}"; do
echo "$msg" | fmt -s >>$LOGMSG
written=1
done
+
+if [ "$use_commit" ]; then
+ pick_author_script='
+ /^author /{
+ h
+ s/^author \([^<]*\) <[^>]*> .*$/\1/
+ s/'\''/'\''\'\'\''/g
+ s/.*/GIT_AUTHOR_NAME='\''&'\''/p
+
+ g
+ s/^author [^<]* <\([^>]*\)> .*$/\1/
+ s/'\''/'\''\'\'\''/g
+ s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
+
+ g
+ s/^author [^<]* <[^>]*> \(.*\)$/\1/
+ s/'\''/'\''\'\'\''/g
+ s/.*/GIT_AUTHOR_DATE='\''&'\''/p
+
+ q
+ }
+ '
+ set_author_env=`git-cat-file commit "$use_commit" |
+ sed -ne "$pick_author_script"`
+ eval "$set_author_env"
+ export GIT_AUTHOR_NAME
+ export GIT_AUTHOR_EMAIL
+ export GIT_AUTHOR_DATE
+ git-cat-file commit "$use_commit" |
+ sed -e '1,/^$/d'
+ written=1
+fi >> $LOGMSG
+
# Always have at least one blank line, to ease the editing for
# the poor people whose text editor has no 'O' command.
[ "$written" ] || echo >>$LOGMSG
@@ -239,7 +283,7 @@ echo "CG: vim: textwidth=75" >>$LOGMSG
cp $LOGMSG $LOGMSG2
if tty -s; then
- if ! [ "$msgs" ] || [ "$forceeditor" ]; then
+ if ! ([ "$use_commit" ] || [ "$msgs" ]) || [ "$forceeditor" ]; then
${EDITOR:-vi} $LOGMSG2
if ! [ "$commitalways" ] && ! [ $LOGMSG2 -nt $LOGMSG ]; then
echo "Log message unchanged or not specified" >&2
[-- Attachment #2: 0001-Add-c-parameter-to-cg-commit-to-set-commit-data-based-on-prior-commit.txt --]
[-- Type: text/plain, Size: 3092 bytes --]
[PATCH] Add -c parameter to cg-commit to set commit data based on prior commit.
This will then commit any changes using the author and message from the commit
specified. The actual logic for parsing the old commit values was taken from
git-commit-script.
git-commit-script supports this option via -C, which was already used in cg-commit
for something else.
Signed-off-by: James Ketrenos <jketreno@linux.intel.com>
---
cg-commit | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 1 deletions(-)
b07037397659763271e946fc15c0b3c61a8fcdfa
diff --git a/cg-commit b/cg-commit
--- a/cg-commit
+++ b/cg-commit
@@ -3,6 +3,8 @@
# Commit into a GIT repository.
# Copyright (c) Petr Baudis, 2005
# Based on an example script fragment sent to LKML by Linus Torvalds.
+#
+# -c commit based on code in git-commit-script by Linus Torvalds
#
# Commits changes to a GIT repository. Accepts the commit message from
# `stdin`. If the commit message is not modified the commit will be
@@ -45,6 +47,12 @@
# might not actually _have_ any object database. This option is
# normally not interesting.
#
+# -c::
+# Specifify the commit SHA to inherit the GIT_AUTHOR_* variables and
+# commit message from. The GIT_COMMITTER_* variables will not be
+# inherited from the specified commit. This option is typically used
+# when replaying commits from one lineage or repository to another.
+#
# FILES
# -----
# $GIT_DIR/author::
@@ -112,6 +120,7 @@ ignorecache=
infoonly=
commitalways=
missingok=
+use_commit=
msgs=()
while optparse; do
if optparse -C; then
@@ -128,6 +137,8 @@ while optparse; do
force=1
elif optparse -m=; then
msgs[${#msgs[@]}]="$OPTARG"
+ elif optparse -c=; then
+ use_commit="$OPTARG"
else
optfail
fi
@@ -196,6 +207,39 @@ for msg in "${msgs[@]}"; do
echo "$msg" | fmt -s >>$LOGMSG
written=1
done
+
+if [ "$use_commit" ]; then
+ pick_author_script='
+ /^author /{
+ h
+ s/^author \([^<]*\) <[^>]*> .*$/\1/
+ s/'\''/'\''\'\'\''/g
+ s/.*/GIT_AUTHOR_NAME='\''&'\''/p
+
+ g
+ s/^author [^<]* <\([^>]*\)> .*$/\1/
+ s/'\''/'\''\'\'\''/g
+ s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
+
+ g
+ s/^author [^<]* <[^>]*> \(.*\)$/\1/
+ s/'\''/'\''\'\'\''/g
+ s/.*/GIT_AUTHOR_DATE='\''&'\''/p
+
+ q
+ }
+ '
+ set_author_env=`git-cat-file commit "$use_commit" |
+ sed -ne "$pick_author_script"`
+ eval "$set_author_env"
+ export GIT_AUTHOR_NAME
+ export GIT_AUTHOR_EMAIL
+ export GIT_AUTHOR_DATE
+ git-cat-file commit "$use_commit" |
+ sed -e '1,/^$/d'
+ written=1
+fi >> $LOGMSG
+
# Always have at least one blank line, to ease the editing for
# the poor people whose text editor has no 'O' command.
[ "$written" ] || echo >>$LOGMSG
@@ -239,7 +283,7 @@ echo "CG: vim: textwidth=75" >>$LOGMSG
cp $LOGMSG $LOGMSG2
if tty -s; then
- if ! [ "$msgs" ] || [ "$forceeditor" ]; then
+ if ! ([ "$use_commit" ] || [ "$msgs" ]) || [ "$forceeditor" ]; then
${EDITOR:-vi} $LOGMSG2
if ! [ "$commitalways" ] && ! [ $LOGMSG2 -nt $LOGMSG ]; then
echo "Log message unchanged or not specified" >&2
reply other threads:[~2005-08-25 18:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=430E0BCB.5010402@linux.intel.com \
--to=jketreno@linux.intel.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).