git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Offer to print changes while running git-mergetool

From
Jonathan del Strother <jon.delstrother@bestbefore.tv>
Date
Feb 7, 2009, 12:01 UTC
Message-ID
<57518fd10902070401x14cc7cacrfb8bc88bbf2999cd@mail.gmail.com>
In-Reply-To
<7vr62ay8dh.fsf@gitster.siamese.dyndns.org>
On Sat, Feb 7, 2009 at 8:11 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 134 quoted lines
> Jonathan del Strother <jon.delStrother@bestbefore.tv> writes:
>
>> Add a "Show changes" option to each prompt in mergetool. This prints the
>> conflicted changes on the current file, using 'git log -p --merge
>> <file>'
>
> I think the patch should look like this, given the recent conversation I
> had with you.  It seems that the script thinks the unit of indentation is
> 4-places, and case arms are indented from case/esac (neither of which is
> the standard git shell script convention), and I tried to match that style
> used in the existing code.
>
> No, I didn't test it.
>
> Charles volunteered to take over mergetool, so he is on the Cc: list.
>
>  git-mergetool.sh |   60 ++++++++++++++++++++++++++++++++++++++++++-----------
>  1 files changed, 47 insertions(+), 13 deletions(-)
>
> diff --git c/git-mergetool.sh w/git-mergetool.sh
> index 87fa88a..b8604d6 100755
> --- c/git-mergetool.sh
> +++ w/git-mergetool.sh
> @@ -14,6 +14,13 @@ OPTIONS_SPEC=
>  . git-sh-setup
>  require_work_tree
>
> +if test -f "$GIT_DIR/MERGE_HEAD"
> +then
> +    in_merge=t show_changes=", (s)how changes"
> +else
> +    in_merge=f show_changes=
> +fi
> +
>  # Returns true if the mode reflects a symlink
>  is_symlink () {
>     test "$1" = 120000
> @@ -62,22 +69,28 @@ describe_file () {
>
>  resolve_symlink_merge () {
>     while true; do
> -       printf "Use (l)ocal or (r)emote, or (a)bort? "
> +       printf "Use (l)ocal or (r)emote$show_changes, or (a)bort? "
>        read ans
> -       case "$ans" in
> -           [lL]*)
> +       case "$in_merge,$ans" in
> +           ?,[lL]*)
>                git checkout-index -f --stage=2 -- "$MERGED"
>                git add -- "$MERGED"
>                cleanup_temp_files --save-backup
>                return 0
>                ;;
> -           [rR]*)
> +           ?,[rR]*)
>                git checkout-index -f --stage=3 -- "$MERGED"
>                git add -- "$MERGED"
>                cleanup_temp_files --save-backup
>                return 0
>                ;;
> -           [aA]*)
> +           t,[sS]*)
> +               git log -p --merge "$MERGED"
> +               printf "\n"
> +               resolve_symlink_merge
> +               return
> +               ;;
> +           ?,[aA]*)
>                return 1
>                ;;
>            esac
> @@ -87,23 +100,29 @@ resolve_symlink_merge () {
>  resolve_deleted_merge () {
>     while true; do
>        if base_present; then
> -           printf "Use (m)odified or (d)eleted file, or (a)bort? "
> +           printf "Use (m)odified or (d)eleted file$show_changes, or (a)bort? "
>        else
> -           printf "Use (c)reated or (d)eleted file, or (a)bort? "
> +           printf "Use (c)reated or (d)eleted file$show changes, or (a)bort? "
>        fi
>        read ans
> -       case "$ans" in
> -           [mMcC]*)
> +       case "$in_merge,$ans" in
> +           ?,[mMcC]*)
>                git add -- "$MERGED"
>                cleanup_temp_files --save-backup
>                return 0
>                ;;
> -           [dD]*)
> +           ?,[dD]*)
>                git rm -- "$MERGED" > /dev/null
>                cleanup_temp_files
>                return 0
>                ;;
> -           [aA]*)
> +           t,[sS]*)
> +               git log -p --merge "$MERGED"
> +               printf "\n"
> +               resolve_deleted_merge
> +               return
> +               ;;
> +           ?,[aA]*)
>                return 1
>                ;;
>            esac
> @@ -184,8 +203,23 @@ merge_file () {
>     describe_file "$local_mode" "local" "$LOCAL"
>     describe_file "$remote_mode" "remote" "$REMOTE"
>     if "$prompt" = true; then
> -       printf "Hit return to start merge resolution tool (%s): " "$merge_tool"
> -       read ans
> +       while true; do
> +           case $in_merge in
> +               t)      msg_head="(S)how changes, or h" ;;
> +               f)      msg_head="H" ;;
> +           esac
> +           print "${msg_head}it return to start merge resolution tool (%s): " "$merge_tool"
> +           read ans
> +           case "$in_merge,$ans" in
> +               t,[sS]*)
> +                   git log -p --merge "$MERGED"
> +                   printf "\n"
> +                   ;;
> +               ?,*)
> +                   break
> +                   ;;
> +           esac
> +        done
>     fi
>
>     case "$merge_tool" in
>

Looks good to me, though there's a minor typo on this line : print "${msg_head}it return to start merge resolution tool (%s): " "$merge_tool"

- print should be printf

Cheers, Jonathan

Previous: Junio C HamanoNext: Charles Bailey
Message 7 of 10 in “Offer to print changes while running git-mergetool”
  1. Offer to print changes while running git-mergetoolJonathan del Strother, Feb 6, 2009
  2. Jonathan del StrotherFeb 6, 2009
  3. Junio C HamanoFeb 6, 2009
  4. Jonathan del StrotherFeb 6, 2009
  5. Junio C HamanoFeb 7, 2009
  6. Junio C HamanoFeb 7, 2009
  7. Jonathan del StrotherFeb 7, 2009
  8. Charles BaileyFeb 8, 2009
  9. Jonathan del StrotherFeb 8, 2009
  10. Charles BaileyFeb 8, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.