* [PATCH v3 2/2] rebase -i: save only original commit sha1 to save author information
@ 2009-06-22 4:28 Christian Couder
2009-06-22 7:35 ` Jakub Narebski
0 siblings, 1 reply; 3+ messages in thread
From: Christian Couder @ 2009-06-22 4:28 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski
This is better than saving author information in a shell script,
because it will make it much easier to port "rebase -i" to C.
This also removes some sed regexps and some "eval"s.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
git-rebase--interactive.sh | 69 ++++++++++++++++++++-----------------------
1 files changed, 32 insertions(+), 37 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 92e2523..a7a169e 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -40,6 +40,7 @@ MSG="$DOTEST"/message
SQUASH_MSG="$DOTEST"/message-squash
REWRITTEN="$DOTEST"/rewritten
DROPPED="$DOTEST"/dropped
+SAVED_COMMIT="$DOTEST"/saved-commit
PRESERVE_MERGES=
STRATEGY=
ONTO=
@@ -117,30 +118,25 @@ mark_action_done () {
}
get_author_ident_from_commit () {
- pick_author_script='
- /^author /{
- s/'\''/'\''\\'\'\''/g
- 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
- }
- '
- encoding=$(git config i18n.commitencoding || echo UTF-8)
- git show -s --pretty=raw --encoding="$encoding" "$1" -- |
- LANG=C LC_ALL=C sed -ne "$pick_author_script"
+ encoding=$(git config i18n.commitencoding || echo UTF-8) &&
+ author_ident_name=$(git show -s --pretty="format:%an" \
+ --encoding="$encoding" "$1" --) &&
+ author_ident_email=$(git show -s --pretty="format:%ae" \
+ --encoding="$encoding" "$1" --) &&
+ author_ident_date=$(git show -s --pretty="format:%ai" \
+ --encoding="$encoding" "$1" --)
+}
+
+set_author_ident () {
+ GIT_AUTHOR_NAME="$author_ident_name" &&
+ GIT_AUTHOR_EMAIL="$author_ident_email" &&
+ GIT_AUTHOR_DATE="$author_ident_date"
+}
+
+load_author_ident () {
+ commit=$(cat "$SAVED_COMMIT") &&
+ get_author_ident_from_commit "$commit" &&
+ set_author_ident
}
make_patch () {
@@ -158,8 +154,8 @@ make_patch () {
esac > "$DOTEST"/patch
test -f "$DOTEST"/message ||
git cat-file commit "$1" | sed "1,/^$/d" > "$DOTEST"/message
- test -f "$DOTEST"/author-script ||
- get_author_ident_from_commit "$1" > "$DOTEST"/author-script
+ test -f "$SAVED_COMMIT" ||
+ echo $(git rev-parse --verify "$1") > "$SAVED_COMMIT"
}
die_with_patch () {
@@ -294,8 +290,8 @@ pick_one_preserving_merges () {
test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
# redo merge
- author_script=$(get_author_ident_from_commit $sha1)
- eval "$author_script"
+ get_author_ident_from_commit $sha1
+ set_author_ident
msg="$(git cat-file commit $sha1 | sed -e '1,/^$/d')"
# No point in merging the first parent, that's HEAD
new_parents=${new_parents# $first_parent}
@@ -353,8 +349,7 @@ peek_next_command () {
}
do_next () {
- rm -f "$DOTEST"/message "$DOTEST"/author-script \
- "$DOTEST"/amend || exit
+ rm -f "$DOTEST"/message "$DOTEST"/amend "$SAVED_COMMIT" || exit
read command sha1 rest < "$TODO"
case "$command" in
'#'*|''|noop)
@@ -395,7 +390,8 @@ do_next () {
mark_action_done
make_squash_message $sha1 > "$MSG"
failed=f
- author_script=$(get_author_ident_from_commit HEAD)
+ get_author_ident_from_commit HEAD
+ commit=$(git rev-parse --verify HEAD)
output git reset --soft HEAD^
pick_one -n $sha1 || failed=t
case "$(peek_next_command)" in
@@ -414,14 +410,13 @@ do_next () {
rm -f "$GIT_DIR"/MERGE_MSG || exit
;;
esac
- echo "$author_script" > "$DOTEST"/author-script
+ echo "$commit" > "$SAVED_COMMIT"
if test $failed = f
then
# This is like --amend, but with a different message
- eval "$author_script"
- GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
- GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
- GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE" \
+ GIT_AUTHOR_NAME="$author_ident_name" \
+ GIT_AUTHOR_EMAIL="$author_ident_email" \
+ GIT_AUTHOR_DATE="$author_ident_date" \
$USE_OUTPUT git commit --no-verify \
$MSG_OPT "$EDIT_OR_FILE" || failed=t
fi
@@ -536,7 +531,7 @@ do
then
: Nothing to commit -- skip this
else
- . "$DOTEST"/author-script ||
+ load_author_ident ||
die "Cannot find the author identity"
amend=
if test -f "$DOTEST"/amend
--
1.6.3.GIT
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 2/2] rebase -i: save only original commit sha1 to save author information
2009-06-22 4:28 [PATCH v3 2/2] rebase -i: save only original commit sha1 to save author information Christian Couder
@ 2009-06-22 7:35 ` Jakub Narebski
2009-06-22 9:27 ` Johannes Schindelin
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Narebski @ 2009-06-22 7:35 UTC (permalink / raw)
To: Christian Couder
Cc: Junio C Hamano, git, Johannes Schindelin, Stephan Beyer,
Daniel Barkalow
Christian Couder wrote:
> + GIT_AUTHOR_NAME="$author_ident_name" \
> + GIT_AUTHOR_EMAIL="$author_ident_email" \
> + GIT_AUTHOR_DATE="$author_ident_date" \
> $USE_OUTPUT git commit --no-verify \
> $MSG_OPT "$EDIT_OR_FILE" || failed=t
Why not use 'git commit -C $(cat "$SAVED_COMMIT") ...' ?
--
Jakub Narebski
Poland
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 2/2] rebase -i: save only original commit sha1 to save author information
2009-06-22 7:35 ` Jakub Narebski
@ 2009-06-22 9:27 ` Johannes Schindelin
0 siblings, 0 replies; 3+ messages in thread
From: Johannes Schindelin @ 2009-06-22 9:27 UTC (permalink / raw)
To: Jakub Narebski
Cc: Christian Couder, Junio C Hamano, git, Stephan Beyer,
Daniel Barkalow
[-- Attachment #1: Type: TEXT/PLAIN, Size: 809 bytes --]
Hi,
On Mon, 22 Jun 2009, Jakub Narebski wrote:
> Christian Couder wrote:
>
> > + GIT_AUTHOR_NAME="$author_ident_name" \
> > + GIT_AUTHOR_EMAIL="$author_ident_email" \
> > + GIT_AUTHOR_DATE="$author_ident_date" \
> > $USE_OUTPUT git commit --no-verify \
> > $MSG_OPT "$EDIT_OR_FILE" || failed=t
>
> Why not use 'git commit -C $(cat "$SAVED_COMMIT") ...' ?
Unfortunately, the quoted part lacks context, so I can only guess that the
issue is "squash". You need to retain authorship, but want to present a
message to the user that is in no commit yet. And no, constructing a new
commit for the purpose of passing it to "commit -C" would be way too
shabby coding IMO.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-06-22 9:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-22 4:28 [PATCH v3 2/2] rebase -i: save only original commit sha1 to save author information Christian Couder
2009-06-22 7:35 ` Jakub Narebski
2009-06-22 9:27 ` Johannes Schindelin
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).