Skip to content

Commit 0cae234

Browse files
dschogitster
authored andcommitted
Move the pick_author code to git-sh-setup
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb5932 commit 0cae234

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

git-commit.sh

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -483,34 +483,8 @@ fi >>"$GIT_DIR"/COMMIT_EDITMSG
483483
# Author
484484
if test '' != "$use_commit"
485485
then
486-
pick_author_script='
487-
/^author /{
488-
s/'\''/'\''\\'\'\''/g
489-
h
490-
s/^author \([^<]*\) <[^>]*> .*$/\1/
491-
s/'\''/'\''\'\'\''/g
492-
s/.*/GIT_AUTHOR_NAME='\''&'\''/p
493-
494-
g
495-
s/^author [^<]* <\([^>]*\)> .*$/\1/
496-
s/'\''/'\''\'\'\''/g
497-
s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
498-
499-
g
500-
s/^author [^<]* <[^>]*> \(.*\)$/\1/
501-
s/'\''/'\''\'\'\''/g
502-
s/.*/GIT_AUTHOR_DATE='\''&'\''/p
503-
504-
q
505-
}
506-
'
507-
encoding=$(git config i18n.commitencoding || echo UTF-8)
508-
set_author_env=`git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
509-
LANG=C LC_ALL=C sed -ne "$pick_author_script"`
510-
eval "$set_author_env"
511-
export GIT_AUTHOR_NAME
512-
export GIT_AUTHOR_EMAIL
513-
export GIT_AUTHOR_DATE
486+
eval "$(get_author_ident_from_commit "$use_commit")"
487+
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
514488
fi
515489
if test '' != "$force_author"
516490
then

git-sh-setup.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ require_work_tree () {
5353
die "fatal: $0 cannot be used without a working tree."
5454
}
5555

56+
get_author_ident_from_commit () {
57+
pick_author_script='
58+
/^author /{
59+
s/'\''/'\''\\'\'\''/g
60+
h
61+
s/^author \([^<]*\) <[^>]*> .*$/\1/
62+
s/'\''/'\''\'\'\''/g
63+
s/.*/GIT_AUTHOR_NAME='\''&'\''/p
64+
65+
g
66+
s/^author [^<]* <\([^>]*\)> .*$/\1/
67+
s/'\''/'\''\'\'\''/g
68+
s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
69+
70+
g
71+
s/^author [^<]* <[^>]*> \(.*\)$/\1/
72+
s/'\''/'\''\'\'\''/g
73+
s/.*/GIT_AUTHOR_DATE='\''&'\''/p
74+
75+
q
76+
}
77+
'
78+
encoding=$(git config i18n.commitencoding || echo UTF-8)
79+
git show -s --pretty=raw --encoding="$encoding" "$1" |
80+
LANG=C LC_ALL=C sed -ne "$pick_author_script"
81+
}
82+
5683
if [ -z "$LONG_USAGE" ]
5784
then
5885
LONG_USAGE="Usage: $0 $USAGE"

0 commit comments

Comments
 (0)