From patchwork Wed Apr 24 22:47:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10915863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15BAD13B5 for ; Wed, 24 Apr 2019 22:47:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03F0928ABC for ; Wed, 24 Apr 2019 22:47:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9F4328BE4; Wed, 24 Apr 2019 22:47:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7068828ABC for ; Wed, 24 Apr 2019 22:47:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726959AbfDXWrE (ORCPT ); Wed, 24 Apr 2019 18:47:04 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46460 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfDXWrD (ORCPT ); Wed, 24 Apr 2019 18:47:03 -0400 Received: by mail-pl1-f194.google.com with SMTP id o7so7792856pll.13 for ; Wed, 24 Apr 2019 15:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=XIJbIHQzfHdxfZeP/nTLP6jFXfooj4YrKcl6/kwN2fs=; b=nhLj74srvsxZy4ifiDpUUvo7HVL/yl9amIw0+2rK6wqBC7XDo48lIKVBEfds1OR6l9 HKzLCasoln8/YBk1gmcLcMftpA6+e694JG7qqAebJkBQpLVUG3ey+mXxI36JnYelotIU oKG/TK4Ij1oG61QOzNxSg4KE09TO+oD6ucA6qDyOVdREYhCpPIUn36bhWqlkL4qkFQKu eLx0y/AMdDL+Qt2HB0kH+a2aYOimsufnCb12tyAU3mnI9bWDAMFfKBPCRAg+PfXGo4uC dtksqXbJa2dPGjH5QurclU42+71k7hSltB5++loqg6lCSl5OjWVKddSoyYcns5uWMOHL kbgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=XIJbIHQzfHdxfZeP/nTLP6jFXfooj4YrKcl6/kwN2fs=; b=TqasAYqXq9Dn36pc+PRNpvRaWQXRD5WyfCsnRacqU2GIIEAKOK5YFH5I5QreapTf/t cIRSPdw7/f0jTGPYlEseB6Pd3JJ70Sz3zAeQW+iruePmSeca+JpYVlH1tGYTdhizijx8 jCfDzKpQIeSSTPK+ZmhATfKDVWVml5NTYNRsCDhiv2+Ub1d1Pi4vKoHDQXcJikESvVm6 RHgOPplU3trt8Vv92DZSsRSOFcI989Ig3CYdNSJUtXk5FFT/t5Tn0ZqwHjvNhkCjqJ/q HzAgrgxR89tYUzEwCWFMxH5OIByCtyXmqnw0ZNOCaJbp5oLCr70iPQBGF+NODS37e7jc O0+A== X-Gm-Message-State: APjAAAW7nON+dqeHS4bVVlKu2WaNYmVcwsiH395sk5H/cZgkbEmALz5V 1t/li9afw8ixoD4l7+nqYQzFMgvC X-Google-Smtp-Source: APXvYqx+17mYspqg5cKrpeyk8MvJNpVmEkhIW/7GOvTAipiv9TeKK7+Cexysx3Niwium9gG5CXmpbw== X-Received: by 2002:a17:902:5a8f:: with SMTP id r15mr1440324pli.196.1556146021786; Wed, 24 Apr 2019 15:47:01 -0700 (PDT) Received: from dev-l ([149.28.200.39]) by smtp.gmail.com with ESMTPSA id x8sm22707432pgp.48.2019.04.24.15.47.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 15:47:01 -0700 (PDT) Date: Wed, 24 Apr 2019 15:47:00 -0700 From: Denton Liu To: Git Mailing List Cc: Johannes Schindelin , David Aguilar , Jeff Hostetler , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 3/6] mergetool: use get_merge_tool function Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In git-mergetool, the logic for getting which merge tool to use is duplicated in git-mergetool--lib, except for the fact that it needs to know whether the tool was guessed or not. Rewrite `get_merge_tool` to return whether or not the tool was guessed through the return code and make git-mergetool call this function instead of duplicating the logic. Note that 1 was chosen to be the return code of when a tool is guessed because it seems like a slightly more abnormal condition than getting a tool that's explicitly specified but this is completely arbitrary. Also, let `$GIT_MERGETOOL_GUI` be set to determine whether or not the guitool will be selected. This change is not completely backwards compatible as there may be external users of git-mergetool--lib. However, only one user, git-diffall[1], was found from searching GitHub and Google. It seems very unlikely that there exists an external caller that would take into account the return code of `get_merge_tool` as it would always return 0 before this change so this change probably does not affect any external users. [1]: https://github.com/thenigan/git-diffall Signed-off-by: Denton Liu --- Documentation/git-mergetool--lib.txt | 4 +++- git-difftool--helper.sh | 2 +- git-mergetool--lib.sh | 5 ++++- git-mergetool.sh | 12 ++++-------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Documentation/git-mergetool--lib.txt b/Documentation/git-mergetool--lib.txt index 055550b2bc..4da9d24096 100644 --- a/Documentation/git-mergetool--lib.txt +++ b/Documentation/git-mergetool--lib.txt @@ -28,7 +28,9 @@ to define the operation mode for the functions listed below. FUNCTIONS --------- get_merge_tool:: - returns a merge tool. + returns a merge tool. the return code is 1 if we returned a guessed + merge tool, else 0. '$GIT_MERGETOOL_GUI' may be set to 'true' to + search for the appropriate guitool. get_merge_tool_cmd:: returns the custom command for a merge tool. diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh index 7bfb6737df..46af3e60b7 100755 --- a/git-difftool--helper.sh +++ b/git-difftool--helper.sh @@ -71,7 +71,7 @@ then then merge_tool="$GIT_DIFF_TOOL" else - merge_tool="$(get_merge_tool)" || exit + merge_tool="$(get_merge_tool)" fi fi diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index 83bf52494c..68ff26a0f7 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -403,14 +403,17 @@ get_merge_tool_path () { } get_merge_tool () { + not_guessed=true # Check if a merge tool has been configured - merge_tool=$(get_configured_merge_tool) + merge_tool=$(get_configured_merge_tool $GIT_MERGETOOL_GUI) # Try to guess an appropriate merge tool if no tool has been set. if test -z "$merge_tool" then merge_tool=$(guess_merge_tool) || exit + not_guessed=false fi echo "$merge_tool" + test "$not_guessed" = true } mergetool_find_win32_cmd () { diff --git a/git-mergetool.sh b/git-mergetool.sh index 01b9ad59b2..88fa6a914a 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -389,7 +389,7 @@ print_noop_and_exit () { main () { prompt=$(git config --bool mergetool.prompt) - gui_tool=false + GIT_MERGETOOL_GUI=false guessed_merge_tool=false orderfile= @@ -416,10 +416,10 @@ main () { esac ;; --no-gui) - gui_tool=false + GIT_MERGETOOL_GUI=false ;; -g|--gui) - gui_tool=true + GIT_MERGETOOL_GUI=true ;; -y|--no-prompt) prompt=false @@ -449,12 +449,8 @@ main () { if test -z "$merge_tool" then - # Check if a merge tool has been configured - merge_tool=$(get_configured_merge_tool $gui_tool) - # Try to guess an appropriate merge tool if no tool has been set. - if test -z "$merge_tool" + if ! merge_tool=$(get_merge_tool) then - merge_tool=$(guess_merge_tool) || exit guessed_merge_tool=true fi fi