Remove hash in git-describe in favor of util slot.
[gitweb.git] / git-revert.sh
index 066e67753e939c3697082d48d6caee6e4b303796..71cbcbc2b886b2770c61c4b3a496db913ef56d9d 100755 (executable)
@@ -7,18 +7,25 @@
 case "$0" in
 *-revert* )
        test -t 0 && edit=-e
+       replay=
        me=revert
        USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
 *-cherry-pick* )
+       replay=t
        edit=
        me=cherry-pick
-       USAGE='[--edit] [-n] [-r] <commit-ish>'  ;;
+       USAGE='[--edit] [-n] [-r] [-x] <commit-ish>'  ;;
 * )
-       die "What are you talking about?" ;;
+       echo >&2 "What are you talking about?"
+       exit 1 ;;
 esac
+
+SUBDIRECTORY_OK=Yes ;# we will cd up
 . git-sh-setup
+require_work_tree
+cd_to_toplevel
 
-no_commit= replay=
+no_commit=
 while case "$#" in 0) break ;; esac
 do
        case "$1" in
@@ -32,8 +39,10 @@ do
        --n|--no|--no-|--no-e|--no-ed|--no-edi|--no-edit)
                edit=
                ;;
-       -r|--r|--re|--rep|--repl|--repla|--replay)
-               replay=t
+       -r)
+               : no-op ;;
+       -x|--i-really-want-to-expose-my-private-commit-object-name)
+               replay=
                ;;
        -*)
                usage
@@ -72,6 +81,8 @@ prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) ||
 git-rev-parse --verify "$commit^2" >/dev/null 2>&1 &&
        die "Cannot run $me a multi-parent commit."
 
+encoding=$(git repo-config i18n.commitencoding || echo UTF-8)
+
 # "commit" is an existing commit.  We would want to apply
 # the difference it introduces since its first parent "prev"
 # on top of the current HEAD if we are cherry-pick.  Or the
@@ -79,10 +90,11 @@ git-rev-parse --verify "$commit^2" >/dev/null 2>&1 &&
 
 case "$me" in
 revert)
-       git-rev-list --pretty=oneline --max-count=1 $commit |
+       git show -s --pretty=oneline --encoding="$encoding" $commit |
        sed -e '
                s/^[^ ]* /Revert "/
-               s/$/"/'
+               s/$/"/
+       '
        echo
        echo "This reverts commit $commit."
        test "$rev" = "$commit" ||
@@ -111,17 +123,20 @@ cherry-pick)
 
                q
        }'
-       set_author_env=`git-cat-file commit "$commit" |
+
+       logmsg=`git show -s --pretty=raw --encoding="$encoding" "$commit"`
+       set_author_env=`echo "$logmsg" |
        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
 
-       git-cat-file commit $commit | sed -e '1,/^$/d'
+       echo "$logmsg" |
+       sed -e '1,/^$/d' -e 's/^    //'
        case "$replay" in
        '')
-               echo "(cherry picked from $commit commit)"
+               echo "(cherry picked from commit $commit)"
                test "$rev" = "$commit" ||
                echo "(original 'git cherry-pick' arguments: $@)"
                ;;
@@ -151,7 +166,7 @@ Conflicts:
                uniq
            } >>"$GIT_DIR/MERGE_MSG"
            echo >&2 "Automatic $me failed.  After resolving the conflicts,"
-           echo >&2 "mark the corrected paths with 'git-update-index <paths>'"
+           echo >&2 "mark the corrected paths with 'git-add <paths>'"
            echo >&2 "and commit the result."
            case "$me" in
            cherry-pick)