1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.diffmergetool;
12
13 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DIFFTOOL_SECTION;
14 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DIFF_SECTION;
15 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_CMD;
16 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_GUITOOL;
17 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PATH;
18 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PROMPT;
19 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TOOL;
20 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TRUST_EXIT_CODE;
21
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.Set;
25
26 import org.eclipse.jgit.lib.Config;
27 import org.eclipse.jgit.lib.Config.SectionParser;
28 import org.eclipse.jgit.lib.internal.BooleanTriState;
29
30
31
32
33 public class DiffToolConfig {
34
35
36 public static final Config.SectionParser<DiffToolConfig> KEY = DiffToolConfig::new;
37
38 private final String toolName;
39
40 private final String guiToolName;
41
42 private final boolean prompt;
43
44 private final BooleanTriState trustExitCode;
45
46 private final Map<String, ExternalDiffTool> tools;
47
48 private DiffToolConfig(Config rc) {
49 toolName = rc.getString(CONFIG_DIFF_SECTION, null, CONFIG_KEY_TOOL);
50 guiToolName = rc.getString(CONFIG_DIFF_SECTION, null,
51 CONFIG_KEY_GUITOOL);
52 prompt = rc.getBoolean(CONFIG_DIFFTOOL_SECTION, toolName,
53 CONFIG_KEY_PROMPT,
54 true);
55 String trustStr = rc.getString(CONFIG_DIFFTOOL_SECTION, toolName,
56 CONFIG_KEY_TRUST_EXIT_CODE);
57 if (trustStr != null) {
58 trustExitCode = Boolean.parseBoolean(trustStr)
59 ? BooleanTriState.TRUE
60 : BooleanTriState.FALSE;
61 } else {
62 trustExitCode = BooleanTriState.UNSET;
63 }
64 tools = new HashMap<>();
65 Set<String> subsections = rc.getSubsections(CONFIG_DIFFTOOL_SECTION);
66 for (String name : subsections) {
67 String cmd = rc.getString(CONFIG_DIFFTOOL_SECTION, name,
68 CONFIG_KEY_CMD);
69 String path = rc.getString(CONFIG_DIFFTOOL_SECTION, name,
70 CONFIG_KEY_PATH);
71 if ((cmd != null) || (path != null)) {
72 tools.put(name, new UserDefinedDiffTool(name, path, cmd));
73 }
74 }
75 }
76
77
78
79
80 public String getDefaultToolName() {
81 return toolName;
82 }
83
84
85
86
87 public String getDefaultGuiToolName() {
88 return guiToolName;
89 }
90
91
92
93
94 public boolean isPrompt() {
95 return prompt;
96 }
97
98
99
100
101 public boolean isTrustExitCode() {
102 return trustExitCode == BooleanTriState.TRUE;
103 }
104
105
106
107
108 public Map<String, ExternalDiffTool> getTools() {
109 return tools;
110 }
111
112
113
114
115 public Set<String> getToolNames() {
116 return tools.keySet();
117 }
118 }