Skip to content

Commit

Permalink
Move the pick_author code to git-sh-setup
Browse files Browse the repository at this point in the history
At the moment, only git-commit uses that code, to pick the author name,
email and date from a given commit.

This code will be reused in git rebase --interactive.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jun 25, 2007
1 parent aeb5932 commit 0cae234
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
30 changes: 2 additions & 28 deletions git-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -483,34 +483,8 @@ fi >>"$GIT_DIR"/COMMIT_EDITMSG
# Author
if test '' != "$use_commit"
then
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)
set_author_env=`git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
LANG=C LC_ALL=C sed -ne "$pick_author_script"`
eval "$set_author_env"
export GIT_AUTHOR_NAME
export GIT_AUTHOR_EMAIL
export GIT_AUTHOR_DATE
eval "$(get_author_ident_from_commit "$use_commit")"
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
fi
if test '' != "$force_author"
then
Expand Down
27 changes: 27 additions & 0 deletions git-sh-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ require_work_tree () {
die "fatal: $0 cannot be used without a working tree."
}

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"
}

if [ -z "$LONG_USAGE" ]
then
LONG_USAGE="Usage: $0 $USAGE"
Expand Down

0 comments on commit 0cae234

Please sign in to comment.