@matheusbsbs / matheus-bagliano / commits / 2464456a6a
Fork 0

contrib/difftool: use a separate config namespace for difftool commands

Some users have different mergetool and difftool settings, so teach difftool to read config vars from the difftool.* namespace. This allows having distinct configurations for the diff and merge scenarios. We don't want to force existing users to set new values for no reason so difftool falls back to existing mergetool config variables when the difftool equivalents are not defined. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Mar 9, 2009 at 02:12 UTC 2464456a6ac9216d59d9e2cf0d86fee072f63cf8
3 files changed +32 -23
contrib/difftool/git-difftool
+3 -3
@@ -4,7 +4,7 @@
4 # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
5 # git-difftool-helper script. This script exports
6 # GIT_EXTERNAL_DIFF and GIT_PAGER for use by git, and
7 -# GIT_DIFFTOOL_NO_PROMPT and GIT_MERGE_TOOL for use by git-difftool-helper.
7 +# GIT_DIFFTOOL_NO_PROMPT and GIT_DIFF_TOOL for use by git-difftool-helper.
8 # Any arguments that are unknown to this script are forwarded to 'git diff'.
9
10 use strict;
@@ -49,12 +49,12 @@ sub generate_command
49 }
50 if ($arg eq '-t' or $arg eq '--tool') {
51 usage() if $#ARGV <= $idx;
52 - $ENV{GIT_MERGE_TOOL} = $ARGV[$idx + 1];
52 + $ENV{GIT_DIFF_TOOL} = $ARGV[$idx + 1];
53 $skip_next = 1;
54 next;
55 }
56 if ($arg =~ /^--tool=/) {
57 - $ENV{GIT_MERGE_TOOL} = substr($arg, 7);
57 + $ENV{GIT_DIFF_TOOL} = substr($arg, 7);
58 next;
59 }
60 if ($arg eq '--no-prompt') {
contrib/difftool/git-difftool-helper
+14 -5
@@ -128,8 +128,10 @@ launch_merge_tool () {
128 cleanup_temp_files
129 }
130
131 -# Verifies that mergetool.<tool>.cmd exists
131 +# Verifies that (difftool|mergetool).<tool>.cmd exists
132 valid_custom_tool() {
133 + merge_tool_cmd="$(git config difftool.$1.cmd)"
134 + test -z "$merge_tool_cmd" &&
135 merge_tool_cmd="$(git config mergetool.$1.cmd)"
136 test -n "$merge_tool_cmd"
137 }
@@ -150,8 +152,11 @@ valid_tool() {
152 }
153
154 # Sets up the merge_tool_path variable.
153 -# This handles the mergetool.<tool>.path configuration.
155 +# This handles the difftool.<tool>.path configuration.
156 +# This also falls back to mergetool defaults.
157 init_merge_tool_path() {
158 + merge_tool_path=$(git config difftool."$1".path)
159 + test -z "$merge_tool_path" &&
160 merge_tool_path=$(git config mergetool."$1".path)
161 if test -z "$merge_tool_path"; then
162 case "$1" in
@@ -165,15 +170,19 @@ init_merge_tool_path() {
170 fi
171 }
172
168 -# Allow the GIT_MERGE_TOOL variable to provide a default value
173 +# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
174 test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
175 +test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
176
171 -# If not merge tool was specified then use the merge.tool
177 +# If merge tool was not specified then use the diff.tool
178 # configuration variable. If that's invalid then reset merge_tool.
179 +# Fallback to merge.tool.
180 if test -z "$merge_tool"; then
181 + merge_tool=$(git config diff.tool)
182 + test -z "$merge_tool" &&
183 merge_tool=$(git config merge.tool)
184 if test -n "$merge_tool" && ! valid_tool "$merge_tool"; then
176 - echo >&2 "git config option merge.tool set to unknown tool: $merge_tool"
185 + echo >&2 "git config option diff.tool set to unknown tool: $merge_tool"
186 echo >&2 "Resetting to default..."
187 unset merge_tool
188 fi
contrib/difftool/git-difftool.txt
+15 -15
@@ -32,23 +32,23 @@ OPTIONS
32 vimdiff, gvimdiff, ecmerge, and opendiff
33 +
34 If a merge resolution program is not specified, 'git-difftool'
35 -will use the configuration variable `merge.tool`. If the
36 -configuration variable `merge.tool` is not set, 'git difftool'
35 +will use the configuration variable `diff.tool`. If the
36 +configuration variable `diff.tool` is not set, 'git-difftool'
37 will pick a suitable default.
38 +
39 You can explicitly provide a full path to the tool by setting the
40 -configuration variable `mergetool.<tool>.path`. For example, you
40 +configuration variable `difftool.<tool>.path`. For example, you
41 can configure the absolute path to kdiff3 by setting
42 -`mergetool.kdiff3.path`. Otherwise, 'git-difftool' assumes the
42 +`difftool.kdiff3.path`. Otherwise, 'git-difftool' assumes the
43 tool is available in PATH.
44 +
45 Instead of running one of the known merge tool programs,
46 'git-difftool' can be customized to run an alternative program
47 by specifying the command line to invoke in a configuration
48 -variable `mergetool.<tool>.cmd`.
48 +variable `difftool.<tool>.cmd`.
49 +
50 When 'git-difftool' is invoked with this tool (either through the
51 -`-t` or `--tool` option or the `merge.tool` configuration variable)
51 +`-t` or `--tool` option or the `diff.tool` configuration variable)
52 the configured command line will be invoked with the following
53 variables available: `$LOCAL` is set to the name of the temporary
54 file containing the contents of the diff pre-image and `$REMOTE`
@@ -61,24 +61,24 @@ with custom merge tool commands and has the same value as `$LOCAL`.
61
62 CONFIG VARIABLES
63 ----------------
64 -merge.tool::
65 - The default merge tool to use.
66 -+
67 -See the `--tool=<tool>` option above for more details.
64 +'git-difftool' falls back to 'git-mergetool' config variables when the
65 +difftool equivalents have not been defined.
66
69 -merge.keepBackup::
70 - The original, unedited file content can be saved to a file with
71 - a `.orig` extension. Defaults to `true` (i.e. keep the backup files).
67 +diff.tool::
68 + The default merge tool to use.
69
73 -mergetool.<tool>.path::
70 +difftool.<tool>.path::
71 Override the path for the given tool. This is useful in case
72 your tool is not in the PATH.
73
77 -mergetool.<tool>.cmd::
74 +difftool.<tool>.cmd::
75 Specify the command to invoke the specified merge tool.
76 +
77 See the `--tool=<tool>` option above for more details.
78
79 +merge.keepBackup::
80 + The original, unedited file content can be saved to a file with
81 + a `.orig` extension. Defaults to `true` (i.e. keep the backup files).
82
83 SEE ALSO
84 --------