Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: David Aguilar <davvid@gmail.com>
Cc: Dun Peal <dunpealer@gmail.com>, Git ML <git@vger.kernel.org>
Subject: Re: trustExitCode doesn't apply to vimdiff mergetool
Date: Sun, 27 Nov 2016 21:01:28 -0500	[thread overview]
Message-ID: <20161128020128.6jhdpg444xbshtzz@sigill.intra.peff.net> (raw)
In-Reply-To: <20161128014538.GA18691@gmail.com>

On Sun, Nov 27, 2016 at 05:45:38PM -0800, David Aguilar wrote:

> I have a patch that makes it so that none of the tools do the
> check_unchanged logic themselves and instead rely on the
> library code to handle it for them.  This makes the
> implementation uniform across all tools, and allows tools to
> opt-in to trustExitCode=true.
> 
> This means that all of the builtin tools will default to
> trustExitCode=false, and they can opt-in by setting the
> configuration variable.

FWIW, that was the refactoring that came to mind when I looked at the
code yesterday. This is the first time I've looked at the mergetool
code, though, so you can take that with the appropriate grain of salt.

Your patch looks mostly good to me. One minor comment:

>  	merge_cmd () {
> -		trust_exit_code=$(git config --bool \
> -			"mergetool.$1.trustExitCode" || echo false)
> -		if test "$trust_exit_code" = "false"
> -		then
> -			touch "$BACKUP"
> -			( eval $merge_tool_cmd )
> -			check_unchanged
> -		else
> -			( eval $merge_tool_cmd )
> -		fi
> +		( eval $merge_tool_cmd )
>  	}
>  }
>  
> @@ -225,7 +216,20 @@ run_diff_cmd () {
>  
>  # Run a either a configured or built-in merge tool
>  run_merge_cmd () {
> +	touch "$BACKUP"
> +
>  	merge_cmd "$1"
> +	status=$?
> +
> +	trust_exit_code=$(git config --bool \
> +		"mergetool.$1.trustExitCode" || echo false)
> +	if test "$trust_exit_code" = "false"
> +	then
> +		check_unchanged
> +		status=$?
> +	fi
> +

In the original, we only touch $BACKUP if we care about timestamps. I
can't think of a reason it would matter to do the touch in the
trustExitCode=true case, but you could also write it as:

  if test "$trust_exit_code" = "false"
  then
	touch "$BACKUP"
	merge_cmd "$1"
	check_unchanged
  else
	merge_cmd "$1"
  fi

  # now $? is from either merge_cmd or check_unchanged

Yours is arguably less subtle, though, which may be a good thing.

-Peff

  reply	other threads:[~2016-11-28  2:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-27  2:44 trustExitCode doesn't apply to vimdiff mergetool Dun Peal
2016-11-27  5:08 ` Jeff King
2016-11-27 13:46   ` Dun Peal
2016-11-27 16:55     ` Jeff King
2016-11-28  1:45       ` David Aguilar
2016-11-28  2:01         ` Jeff King [this message]
2016-11-28  2:15         ` David Aguilar
2016-11-28 17:17           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161128020128.6jhdpg444xbshtzz@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=davvid@gmail.com \
    --cc=dunpealer@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox