1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.diff;
12
13 import java.text.MessageFormat;
14
15 import org.eclipse.jgit.internal.JGitText;
16 import org.eclipse.jgit.lib.Config;
17 import org.eclipse.jgit.lib.Config.SectionParser;
18 import org.eclipse.jgit.lib.ConfigConstants;
19 import org.eclipse.jgit.util.StringUtils;
20
21
22
23
24 public class DiffConfig {
25
26 public static final Config.SectionParser<DiffConfig> KEY = DiffConfig::new;
27
28
29 public enum RenameDetectionType {
30
31 FALSE,
32
33
34 TRUE,
35
36
37 COPY
38 }
39
40 private final boolean noPrefix;
41
42 private final RenameDetectionType renameDetectionType;
43
44 private final int renameLimit;
45
46 private DiffConfig(Config rc) {
47 noPrefix = rc.getBoolean(ConfigConstants.CONFIG_DIFF_SECTION,
48 ConfigConstants.CONFIG_KEY_NOPREFIX, false);
49 renameDetectionType = parseRenameDetectionType(rc.getString(
50 ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_RENAMES));
51 renameLimit = rc.getInt(ConfigConstants.CONFIG_DIFF_SECTION,
52 ConfigConstants.CONFIG_KEY_RENAMELIMIT, 400);
53 }
54
55
56
57
58
59
60 public boolean isNoPrefix() {
61 return noPrefix;
62 }
63
64
65
66
67
68
69 public boolean isRenameDetectionEnabled() {
70 return renameDetectionType != RenameDetectionType.FALSE;
71 }
72
73
74
75
76
77
78 public RenameDetectionType getRenameDetectionType() {
79 return renameDetectionType;
80 }
81
82
83
84
85
86
87 public int getRenameLimit() {
88 return renameLimit;
89 }
90
91 private static RenameDetectionType parseRenameDetectionType(
92 final String renameString) {
93 if (renameString == null)
94 return RenameDetectionType.FALSE;
95 else if (StringUtils.equalsIgnoreCase(
96 ConfigConstants.CONFIG_RENAMELIMIT_COPY, renameString)
97 || StringUtils
98 .equalsIgnoreCase(
99 ConfigConstants.CONFIG_RENAMELIMIT_COPIES,
100 renameString))
101 return RenameDetectionType.COPY;
102 else {
103 final Boolean renameBoolean = StringUtils
104 .toBooleanOrNull(renameString);
105 if (renameBoolean == null)
106 throw new IllegalArgumentException(MessageFormat.format(
107 JGitText.get().enumValueNotSupported2,
108 ConfigConstants.CONFIG_DIFF_SECTION,
109 ConfigConstants.CONFIG_KEY_RENAMES, renameString));
110 else if (renameBoolean.booleanValue())
111 return RenameDetectionType.TRUE;
112 else
113 return RenameDetectionType.FALSE;
114 }
115 }
116 }