Skip to content

Commit

Permalink
Use GIT_REFLOG_ACTION environment variable instead.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
spearce authored and Junio C Hamano committed Dec 28, 2006
1 parent b1f5f64 commit f947413
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 41 deletions.
6 changes: 0 additions & 6 deletions Documentation/git-merge.txt
Expand Up @@ -10,7 +10,6 @@ SYNOPSIS
--------
[verse]
'git-merge' [-n] [--no-commit] [--squash] [-s <strategy>]...
[--reflog-action=<action>]
-m=<msg> <remote> <remote>...

DESCRIPTION
Expand All @@ -37,11 +36,6 @@ include::merge-options.txt[]
least one <remote>. Specifying more than one <remote>
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[]


Expand Down
7 changes: 2 additions & 5 deletions git-am.sh
Expand Up @@ -6,6 +6,7 @@ USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way]
[--interactive] [--whitespace=<option>] <mbox>...
or, when resuming [--skip | --resolved]'
. git-sh-setup
set_reflog_action am

git var GIT_COMMITTER_IDENT >/dev/null || exit

Expand Down Expand Up @@ -101,7 +102,6 @@ It does not apply to blobs recorded in its index."
}

prec=4
rloga=am
dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= ws= resolvemsg=

while case "$#" in 0) break;; esac
Expand Down Expand Up @@ -141,9 +141,6 @@ do
--resolvemsg=*)
resolvemsg=$(echo "$1" | sed -e "s/^--resolvemsg=//"); shift ;;

--reflog-action=*)
rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`; shift ;;

--)
shift; break ;;
-*)
Expand Down Expand Up @@ -452,7 +449,7 @@ do
parent=$(git-rev-parse --verify HEAD) &&
commit=$(git-commit-tree $tree -p $parent <"$dotest/final-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

if test -x "$GIT_DIR"/hooks/post-applypatch
Expand Down
21 changes: 8 additions & 13 deletions git-fetch.sh
Expand Up @@ -4,6 +4,8 @@
USAGE='<fetch-options> <repository> <refspec>...'
SUBDIRECTORY_OK=Yes
. git-sh-setup
set_reflog_action "fetch $*"

TOP=$(git-rev-parse --show-cdup)
if test ! -z "$TOP"
then
Expand All @@ -17,7 +19,6 @@ LF='
'
IFS="$LF"

rloga=fetch
no_tags=
tags=
append=
Expand Down Expand Up @@ -59,9 +60,6 @@ do
-k|--k|--ke|--kee|--keep)
keep='-k -k'
;;
--reflog-action=*)
rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
;;
-*)
usage
;;
Expand All @@ -86,9 +84,6 @@ refs=
rref=
rsync_slurped_objects=

rloga="$rloga $remote_nick"
test "$remote_nick" = "$remote" || rloga="$rloga $remote"

if test "" = "$append"
then
: >"$GIT_DIR/FETCH_HEAD"
Expand Down Expand Up @@ -172,12 +167,12 @@ update_local_ref () {
else
echo >&2 "* $1: updating with $3"
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
else
echo >&2 "* $1: storing $3"
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
;;

Expand All @@ -200,7 +195,7 @@ update_local_ref () {
*,$local)
echo >&2 "* $1: fast forward to $3"
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
Expand All @@ -210,7 +205,7 @@ update_local_ref () {
*,t,*)
echo >&2 "* $1: forcing update to non-fast forward $3"
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"
Expand All @@ -222,7 +217,7 @@ update_local_ref () {
else
echo >&2 "* $1: storing $3"
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
;;
esac
Expand Down Expand Up @@ -465,7 +460,7 @@ case "$orig_head" in
if test "$curr_head" != "$orig_head"
then
git-update-ref \
-m "$rloga: Undoing incorrectly fetched HEAD." \
-m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
HEAD "$orig_head"
die "Cannot fetch into the current branch."
fi
Expand Down
13 changes: 5 additions & 8 deletions git-merge.sh
Expand Up @@ -3,9 +3,10 @@
# 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
set_reflog_action "merge $*"

LF='
'
Expand Down Expand Up @@ -57,10 +58,10 @@ squash_message () {
finish () {
if test '' = "$2"
then
rlogm="$rloga"
rlogm="$GIT_REFLOG_ACTION"
else
echo "$2"
rlogm="$rloga: $2"
rlogm="$GIT_REFLOG_ACTION: $2"
fi
case "$squash" in
t)
Expand Down Expand Up @@ -109,7 +110,7 @@ merge_name () {

case "$#" in 0) usage ;; esac

rloga= have_message=
have_message=
while case "$#" in 0) break ;; esac
do
case "$1" in
Expand Down Expand Up @@ -139,9 +140,6 @@ do
die "available strategies are: $all_strategies" ;;
esac
;;
--reflog-action=*)
rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
;;
-m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
merge_msg=`expr "z$1" : 'z-[^=]*=\(.*\)'`
have_message=t
Expand Down Expand Up @@ -213,7 +211,6 @@ head=$(git-rev-parse --verify "$head_arg"^0) || usage

# All the rest are remote heads
test "$#" = 0 && usage ;# we need at least one remote head.
test "$rloga" = '' && rloga="merge: $@"

remoteheads=
for remote
Expand Down
6 changes: 3 additions & 3 deletions git-pull.sh
Expand Up @@ -7,6 +7,7 @@
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.'
. git-sh-setup
set_reflog_action "pull $*"

strategy_args= no_summary= no_commit= squash=
while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
Expand Down Expand Up @@ -45,7 +46,7 @@ do
done

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)
if test "$curr_head" != "$orig_head"
Expand Down Expand Up @@ -118,6 +119,5 @@ case "$strategy_args" in
esac

merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
git-merge "--reflog-action=pull $*" \
$no_summary $no_commit $squash $strategy_args \
git-merge $no_summary $no_commit $squash $strategy_args \
"$merge_name" HEAD $merge_head
10 changes: 4 additions & 6 deletions git-rebase.sh
Expand Up @@ -28,6 +28,7 @@ Example: git-rebase master~1 topic
D---E---F---G master D---E---F---G master
'
. git-sh-setup
set_reflog_action rebase

RESOLVEMSG="
When you have resolved this problem run \"git rebase --continue\".
Expand Down Expand Up @@ -132,8 +133,7 @@ do
finish_rb_merge
exit
fi
git am --resolved --3way --resolvemsg="$RESOLVEMSG" \
--reflog-action=rebase
git am --resolved --3way --resolvemsg="$RESOLVEMSG"
exit
;;
--skip)
Expand All @@ -156,8 +156,7 @@ do
finish_rb_merge
exit
fi
git am -3 --skip --resolvemsg="$RESOLVEMSG" \
--reflog-action=rebase
git am -3 --skip --resolvemsg="$RESOLVEMSG"
exit
;;
--abort)
Expand Down Expand Up @@ -306,8 +305,7 @@ fi
if test -z "$do_merge"
then
git-format-patch -k --stdout --full-index --ignore-if-in-upstream "$upstream"..ORIG_HEAD |
git am --binary -3 -k --resolvemsg="$RESOLVEMSG" \
--reflog-action=rebase
git am --binary -3 -k --resolvemsg="$RESOLVEMSG"
exit $?
fi

Expand Down
8 changes: 8 additions & 0 deletions git-sh-setup.sh
Expand Up @@ -20,6 +20,14 @@ 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" ]
then
LONG_USAGE="Usage: $0 $USAGE"
Expand Down

0 comments on commit f947413

Please sign in to comment.