git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] cogito -- add -c $commit support
@ 2005-08-25 18:19 James Ketrenos
  0 siblings, 0 replies; only message in thread
From: James Ketrenos @ 2005-08-25 18:19 UTC (permalink / raw
  To: git

[-- 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-08-25 18:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-25 18:19 [PATCH] cogito -- add -c $commit support James Ketrenos

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).