Use GIT_REFLOG_ACTION environment variable instead.

Junio rightly pointed out that the --reflog-action parameter
was starting to get out of control, as most porcelain code
needed to hand it to other porcelain and plumbing alike to
ensure the reflog contained the top-level user action and
not the lower-level actions it invoked.

At Junio's suggestion we are introducing the new set_reflog_action
function to all shell scripts, allowing them to declare early on
what their default reflog name should be, but this setting only
takes effect if the caller has not already set the GIT_REFLOG_ACTION
environment variable.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Shawn O. Pearce 2006-12-28 02:34:48 -05:00 committed by Junio C Hamano
parent b1f5f64fc8
commit f94741324e
7 changed files with 30 additions and 41 deletions

View File

@ -10,7 +10,6 @@ SYNOPSIS
-------- --------
[verse] [verse]
'git-merge' [-n] [--no-commit] [--squash] [-s <strategy>]... 'git-merge' [-n] [--no-commit] [--squash] [-s <strategy>]...
[--reflog-action=<action>]
-m=<msg> <remote> <remote>... -m=<msg> <remote> <remote>...
DESCRIPTION DESCRIPTION
@ -37,11 +36,6 @@ include::merge-options.txt[]
least one <remote>. Specifying more than one <remote> least one <remote>. Specifying more than one <remote>
obviously means you are trying an Octopus. obviously means you are trying an Octopus.
--reflog-action=<action>::
This is used internally when `git-pull` calls this command
to record that the merge was created by `pull` command
in the `ref-log` entry that results from the merge.
include::merge-strategies.txt[] include::merge-strategies.txt[]

View File

@ -6,6 +6,7 @@ USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way]
[--interactive] [--whitespace=<option>] <mbox>... [--interactive] [--whitespace=<option>] <mbox>...
or, when resuming [--skip | --resolved]' or, when resuming [--skip | --resolved]'
. git-sh-setup . git-sh-setup
set_reflog_action am
git var GIT_COMMITTER_IDENT >/dev/null || exit git var GIT_COMMITTER_IDENT >/dev/null || exit
@ -101,7 +102,6 @@ It does not apply to blobs recorded in its index."
} }
prec=4 prec=4
rloga=am
dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= ws= resolvemsg= dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= ws= resolvemsg=
while case "$#" in 0) break;; esac while case "$#" in 0) break;; esac
@ -141,9 +141,6 @@ do
--resolvemsg=*) --resolvemsg=*)
resolvemsg=$(echo "$1" | sed -e "s/^--resolvemsg=//"); shift ;; resolvemsg=$(echo "$1" | sed -e "s/^--resolvemsg=//"); shift ;;
--reflog-action=*)
rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`; shift ;;
--) --)
shift; break ;; shift; break ;;
-*) -*)
@ -452,7 +449,7 @@ do
parent=$(git-rev-parse --verify HEAD) && parent=$(git-rev-parse --verify HEAD) &&
commit=$(git-commit-tree $tree -p $parent <"$dotest/final-commit") && commit=$(git-commit-tree $tree -p $parent <"$dotest/final-commit") &&
echo Committed: $commit && echo Committed: $commit &&
git-update-ref -m "$rloga: $SUBJECT" HEAD $commit $parent || git-update-ref -m "$GIT_REFLOG_ACTION: $SUBJECT" HEAD $commit $parent ||
stop_here $this stop_here $this
if test -x "$GIT_DIR"/hooks/post-applypatch if test -x "$GIT_DIR"/hooks/post-applypatch

View File

@ -4,6 +4,8 @@
USAGE='<fetch-options> <repository> <refspec>...' USAGE='<fetch-options> <repository> <refspec>...'
SUBDIRECTORY_OK=Yes SUBDIRECTORY_OK=Yes
. git-sh-setup . git-sh-setup
set_reflog_action "fetch $*"
TOP=$(git-rev-parse --show-cdup) TOP=$(git-rev-parse --show-cdup)
if test ! -z "$TOP" if test ! -z "$TOP"
then then
@ -17,7 +19,6 @@ LF='
' '
IFS="$LF" IFS="$LF"
rloga=fetch
no_tags= no_tags=
tags= tags=
append= append=
@ -59,9 +60,6 @@ do
-k|--k|--ke|--kee|--keep) -k|--k|--ke|--kee|--keep)
keep='-k -k' keep='-k -k'
;; ;;
--reflog-action=*)
rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
;;
-*) -*)
usage usage
;; ;;
@ -86,9 +84,6 @@ refs=
rref= rref=
rsync_slurped_objects= rsync_slurped_objects=
rloga="$rloga $remote_nick"
test "$remote_nick" = "$remote" || rloga="$rloga $remote"
if test "" = "$append" if test "" = "$append"
then then
: >"$GIT_DIR/FETCH_HEAD" : >"$GIT_DIR/FETCH_HEAD"
@ -172,12 +167,12 @@ update_local_ref () {
else else
echo >&2 "* $1: updating with $3" echo >&2 "* $1: updating with $3"
echo >&2 " $label_: $newshort_" echo >&2 " $label_: $newshort_"
git-update-ref -m "$rloga: updating tag" "$1" "$2" git-update-ref -m "$GIT_REFLOG_ACTION: updating tag" "$1" "$2"
fi fi
else else
echo >&2 "* $1: storing $3" echo >&2 "* $1: storing $3"
echo >&2 " $label_: $newshort_" echo >&2 " $label_: $newshort_"
git-update-ref -m "$rloga: storing tag" "$1" "$2" git-update-ref -m "$GIT_REFLOG_ACTION: storing tag" "$1" "$2"
fi fi
;; ;;
@ -200,7 +195,7 @@ update_local_ref () {
*,$local) *,$local)
echo >&2 "* $1: fast forward to $3" echo >&2 "* $1: fast forward to $3"
echo >&2 " old..new: $oldshort_..$newshort_" echo >&2 " old..new: $oldshort_..$newshort_"
git-update-ref -m "$rloga: fast-forward" "$1" "$2" "$local" git-update-ref -m "$GIT_REFLOG_ACTION: fast-forward" "$1" "$2" "$local"
;; ;;
*) *)
false false
@ -210,7 +205,7 @@ update_local_ref () {
*,t,*) *,t,*)
echo >&2 "* $1: forcing update to non-fast forward $3" echo >&2 "* $1: forcing update to non-fast forward $3"
echo >&2 " old...new: $oldshort_...$newshort_" echo >&2 " old...new: $oldshort_...$newshort_"
git-update-ref -m "$rloga: forced-update" "$1" "$2" "$local" git-update-ref -m "$GIT_REFLOG_ACTION: forced-update" "$1" "$2" "$local"
;; ;;
*) *)
echo >&2 "* $1: not updating to non-fast forward $3" echo >&2 "* $1: not updating to non-fast forward $3"
@ -222,7 +217,7 @@ update_local_ref () {
else else
echo >&2 "* $1: storing $3" echo >&2 "* $1: storing $3"
echo >&2 " $label_: $newshort_" echo >&2 " $label_: $newshort_"
git-update-ref -m "$rloga: storing head" "$1" "$2" git-update-ref -m "$GIT_REFLOG_ACTION: storing head" "$1" "$2"
fi fi
;; ;;
esac esac
@ -465,7 +460,7 @@ case "$orig_head" in
if test "$curr_head" != "$orig_head" if test "$curr_head" != "$orig_head"
then then
git-update-ref \ git-update-ref \
-m "$rloga: Undoing incorrectly fetched HEAD." \ -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
HEAD "$orig_head" HEAD "$orig_head"
die "Cannot fetch into the current branch." die "Cannot fetch into the current branch."
fi fi

View File

@ -3,9 +3,10 @@
# Copyright (c) 2005 Junio C Hamano # Copyright (c) 2005 Junio C Hamano
# #
USAGE='[-n] [--no-commit] [--squash] [-s <strategy>] [--reflog-action=<action>] [-m=<merge-message>] <commit>+' USAGE='[-n] [--no-commit] [--squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
. git-sh-setup . git-sh-setup
set_reflog_action "merge $*"
LF=' LF='
' '
@ -57,10 +58,10 @@ squash_message () {
finish () { finish () {
if test '' = "$2" if test '' = "$2"
then then
rlogm="$rloga" rlogm="$GIT_REFLOG_ACTION"
else else
echo "$2" echo "$2"
rlogm="$rloga: $2" rlogm="$GIT_REFLOG_ACTION: $2"
fi fi
case "$squash" in case "$squash" in
t) t)
@ -109,7 +110,7 @@ merge_name () {
case "$#" in 0) usage ;; esac case "$#" in 0) usage ;; esac
rloga= have_message= have_message=
while case "$#" in 0) break ;; esac while case "$#" in 0) break ;; esac
do do
case "$1" in case "$1" in
@ -139,9 +140,6 @@ do
die "available strategies are: $all_strategies" ;; die "available strategies are: $all_strategies" ;;
esac esac
;; ;;
--reflog-action=*)
rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
;;
-m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*) -m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
merge_msg=`expr "z$1" : 'z-[^=]*=\(.*\)'` merge_msg=`expr "z$1" : 'z-[^=]*=\(.*\)'`
have_message=t have_message=t
@ -213,7 +211,6 @@ head=$(git-rev-parse --verify "$head_arg"^0) || usage
# All the rest are remote heads # All the rest are remote heads
test "$#" = 0 && usage ;# we need at least one remote head. test "$#" = 0 && usage ;# we need at least one remote head.
test "$rloga" = '' && rloga="merge: $@"
remoteheads= remoteheads=
for remote for remote

View File

@ -7,6 +7,7 @@
USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...' USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...'
LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.' LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
. git-sh-setup . git-sh-setup
set_reflog_action "pull $*"
strategy_args= no_summary= no_commit= squash= strategy_args= no_summary= no_commit= squash=
while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
@ -45,7 +46,7 @@ do
done done
orig_head=$(git-rev-parse --verify HEAD 2>/dev/null) orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
git-fetch --update-head-ok --reflog-action=pull "$@" || exit 1 git-fetch --update-head-ok "$@" || exit 1
curr_head=$(git-rev-parse --verify HEAD 2>/dev/null) curr_head=$(git-rev-parse --verify HEAD 2>/dev/null)
if test "$curr_head" != "$orig_head" if test "$curr_head" != "$orig_head"
@ -118,6 +119,5 @@ case "$strategy_args" in
esac esac
merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
git-merge "--reflog-action=pull $*" \ git-merge $no_summary $no_commit $squash $strategy_args \
$no_summary $no_commit $squash $strategy_args \
"$merge_name" HEAD $merge_head "$merge_name" HEAD $merge_head

View File

@ -28,6 +28,7 @@ Example: git-rebase master~1 topic
D---E---F---G master D---E---F---G master D---E---F---G master D---E---F---G master
' '
. git-sh-setup . git-sh-setup
set_reflog_action rebase
RESOLVEMSG=" RESOLVEMSG="
When you have resolved this problem run \"git rebase --continue\". When you have resolved this problem run \"git rebase --continue\".
@ -132,8 +133,7 @@ do
finish_rb_merge finish_rb_merge
exit exit
fi fi
git am --resolved --3way --resolvemsg="$RESOLVEMSG" \ git am --resolved --3way --resolvemsg="$RESOLVEMSG"
--reflog-action=rebase
exit exit
;; ;;
--skip) --skip)
@ -156,8 +156,7 @@ do
finish_rb_merge finish_rb_merge
exit exit
fi fi
git am -3 --skip --resolvemsg="$RESOLVEMSG" \ git am -3 --skip --resolvemsg="$RESOLVEMSG"
--reflog-action=rebase
exit exit
;; ;;
--abort) --abort)
@ -306,8 +305,7 @@ fi
if test -z "$do_merge" if test -z "$do_merge"
then then
git-format-patch -k --stdout --full-index --ignore-if-in-upstream "$upstream"..ORIG_HEAD | git-format-patch -k --stdout --full-index --ignore-if-in-upstream "$upstream"..ORIG_HEAD |
git am --binary -3 -k --resolvemsg="$RESOLVEMSG" \ git am --binary -3 -k --resolvemsg="$RESOLVEMSG"
--reflog-action=rebase
exit $? exit $?
fi fi

View File

@ -20,6 +20,14 @@ usage() {
die "Usage: $0 $USAGE" die "Usage: $0 $USAGE"
} }
set_reflog_action() {
if [ -z "${GIT_REFLOG_ACTION:+set}" ]
then
GIT_REFLOG_ACTION="$*"
export GIT_REFLOG_ACTION
fi
}
if [ -z "$LONG_USAGE" ] if [ -z "$LONG_USAGE" ]
then then
LONG_USAGE="Usage: $0 $USAGE" LONG_USAGE="Usage: $0 $USAGE"