Message ID | 20201228192919.1195211-5-seth@eseth.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mergetool: add automerge configuration | expand |
Am 28.12.20 um 20:29 schrieb Seth House: > diff --git a/git-mergetool.sh b/git-mergetool.sh > index e3c7d78d1d..929192d0f8 100755 > --- a/git-mergetool.sh > +++ b/git-mergetool.sh > @@ -334,6 +334,8 @@ merge_file () { > checkout_staged_file 2 "$MERGED" "$LOCAL" > checkout_staged_file 3 "$MERGED" "$REMOTE" > > + initialize_merge_tool "$merge_tool" In my earlier review, I was not explicit about the lack of error handling of this invocation, because I hoped that you would notice it yourself. `initialize_merge_tool` does have a few failure modes via `setup_tool` that are not really unlikely; ignoring errors would be wrong, I think. Before this change, the errors would be handled as part of the failing `run_merge_tool` call at the end of function `merge_file`. But now errors are ignored. Just appending `|| return` would not be appropriate at this point because a lot has already happened before the call that has to be rewound. Would it be possible to move the call above the `mergetool_tmpdir_init` call, so that nothing has to be rewound? > + > if test "$( > git config --get --bool "mergetool.$merge_tool.automerge" || > git config --get --bool "mergetool.automerge" || > -- Hannes
On Tue, Dec 29, 2020 at 09:50:44AM +0100, Johannes Sixt wrote: > Would it be possible to move the call above the > `mergetool_tmpdir_init` call, so that nothing has to be rewound? Ah, I see. Good suggestion. Yes, moving that call higher works just fine. E.g.: diff --git a/git-mergetool.sh b/git-mergetool.sh index a44afd3822..36c1920dd6 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -276,6 +276,8 @@ merge_file () { ext= esac + initialize_merge_tool "$merge_tool" || return + mergetool_tmpdir_init if test "$MERGETOOL_TMPDIR" != "." @@ -334,8 +336,6 @@ merge_file () { checkout_staged_file 2 "$MERGED" "$LOCAL" checkout_staged_file 3 "$MERGED" "$REMOTE" - initialize_merge_tool "$merge_tool" - if automerge_enabled && test "$( git config --get --bool "mergetool.$merge_tool.automerge" || git config --get --bool "mergetool.automerge" || Thanks. I'll roll that change into a v10 patch series later today or tomorrow to give a little more time for any other feedback.
diff --git a/Documentation/git-mergetool--lib.txt b/Documentation/git-mergetool--lib.txt index 4da9d24096..3e8f59ac0e 100644 --- a/Documentation/git-mergetool--lib.txt +++ b/Documentation/git-mergetool--lib.txt @@ -38,6 +38,10 @@ get_merge_tool_cmd:: get_merge_tool_path:: returns the custom path for a merge tool. +initialize_merge_tool:: + bring merge tool specific functions into scope so they can be used or + overridden. + run_merge_tool:: launches a merge tool given the tool name and a true/false flag to indicate whether a merge base is present. diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh index 46af3e60b7..234dd6944e 100755 --- a/git-difftool--helper.sh +++ b/git-difftool--helper.sh @@ -61,6 +61,7 @@ launch_merge_tool () { export BASE eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"' else + initialize_merge_tool "$merge_tool" && run_merge_tool "$merge_tool" fi } @@ -79,6 +80,7 @@ if test -n "$GIT_DIFFTOOL_DIRDIFF" then LOCAL="$1" REMOTE="$2" + initialize_merge_tool "$merge_tool" && run_merge_tool "$merge_tool" false else # Launch the merge tool on each path provided by 'git diff' diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index 7225abd811..e059b3559e 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -248,6 +248,10 @@ trust_exit_code () { fi } +initialize_merge_tool () { + # Bring tool-specific functions into scope + setup_tool "$1" || return 1 +} # Entry point for running tools run_merge_tool () { @@ -259,9 +263,6 @@ run_merge_tool () { merge_tool_path=$(get_merge_tool_path "$1") || exit base_present="$2" - # Bring tool-specific functions into scope - setup_tool "$1" || return 1 - if merge_mode then run_merge_cmd "$1" diff --git a/git-mergetool.sh b/git-mergetool.sh index e3c7d78d1d..929192d0f8 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -334,6 +334,8 @@ merge_file () { checkout_staged_file 2 "$MERGED" "$LOCAL" checkout_staged_file 3 "$MERGED" "$REMOTE" + initialize_merge_tool "$merge_tool" + if test "$( git config --get --bool "mergetool.$merge_tool.automerge" || git config --get --bool "mergetool.automerge" ||
This is preparation for the following commit where we need to source the mergetool shell script to look for overrides before `run_merge_tool` is called. Previously `run_merge_tool` both sourced that script and invoked the mergetool. In the case of the following commit, we need the result of the `automerge_enabled` override, if it exists, well before we actually run `run_merge_tool`. A new function `initialize_merge_tool` was chosen for consistency with `run_merge_tool` since `setup_tool` and `setup_user_tool` are not exposed or called directly. Signed-off-by: Seth House <seth@eseth.com> --- Documentation/git-mergetool--lib.txt | 4 ++++ git-difftool--helper.sh | 2 ++ git-mergetool--lib.sh | 7 ++++--- git-mergetool.sh | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-)