1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.transport;
45
46 import java.util.HashMap;
47 import java.util.Map;
48
49 import org.eclipse.jgit.lib.Config;
50 import org.eclipse.jgit.lib.Config.SectionParser;
51 import org.eclipse.jgit.lib.ObjectChecker;
52 import org.eclipse.jgit.lib.Ref;
53 import org.eclipse.jgit.lib.Repository;
54 import org.eclipse.jgit.util.SystemReader;
55
56
57
58
59
60 public class TransferConfig {
61
62 public static final Config.SectionParser<TransferConfig> KEY = new SectionParser<TransferConfig>() {
63 public TransferConfig parse(final Config cfg) {
64 return new TransferConfig(cfg);
65 }
66 };
67
68 private final boolean checkReceivedObjects;
69 private final boolean allowLeadingZeroFileMode;
70 private final boolean allowInvalidPersonIdent;
71 private final boolean safeForWindows;
72 private final boolean safeForMacOS;
73 private final boolean allowTipSha1InWant;
74 private final boolean allowReachableSha1InWant;
75 private final String[] hideRefs;
76
77 TransferConfig(final Repository db) {
78 this(db.getConfig());
79 }
80
81 private TransferConfig(final Config rc) {
82 checkReceivedObjects = rc.getBoolean(
83 "fetch", "fsckobjects",
84 rc.getBoolean("transfer", "fsckobjects", false));
85 allowLeadingZeroFileMode = checkReceivedObjects
86 && rc.getBoolean("fsck", "allowLeadingZeroFileMode", false);
87 allowInvalidPersonIdent = checkReceivedObjects
88 && rc.getBoolean("fsck", "allowInvalidPersonIdent", false);
89 safeForWindows = checkReceivedObjects
90 && rc.getBoolean("fsck", "safeForWindows",
91 SystemReader.getInstance().isWindows());
92 safeForMacOS = checkReceivedObjects
93 && rc.getBoolean("fsck", "safeForMacOS",
94 SystemReader.getInstance().isMacOS());
95
96 allowTipSha1InWant = rc.getBoolean(
97 "uploadpack", "allowtipsha1inwant", false);
98 allowReachableSha1InWant = rc.getBoolean(
99 "uploadpack", "allowreachablesha1inwant", false);
100 hideRefs = rc.getStringList("uploadpack", null, "hiderefs");
101 }
102
103
104
105
106
107
108 public ObjectChecker newObjectChecker() {
109 if (!checkReceivedObjects)
110 return null;
111 return new ObjectChecker()
112 .setAllowLeadingZeroFileMode(allowLeadingZeroFileMode)
113 .setAllowInvalidPersonIdent(allowInvalidPersonIdent)
114 .setSafeForWindows(safeForWindows)
115 .setSafeForMacOS(safeForMacOS);
116 }
117
118
119
120
121
122 public boolean isAllowTipSha1InWant() {
123 return allowTipSha1InWant;
124 }
125
126
127
128
129
130 public boolean isAllowReachableSha1InWant() {
131 return allowReachableSha1InWant;
132 }
133
134
135
136
137
138 public RefFilter getRefFilter() {
139 if (hideRefs.length == 0)
140 return RefFilter.DEFAULT;
141
142 return new RefFilter() {
143 public Map<String, Ref> filter(Map<String, Ref> refs) {
144 Map<String, Ref> result = new HashMap<String, Ref>();
145 for (Map.Entry<String, Ref> e : refs.entrySet()) {
146 boolean add = true;
147 for (String hide : hideRefs) {
148 if (e.getKey().equals(hide) || prefixMatch(hide, e.getKey())) {
149 add = false;
150 break;
151 }
152 }
153 if (add)
154 result.put(e.getKey(), e.getValue());
155 }
156 return result;
157 }
158
159 private boolean prefixMatch(String p, String s) {
160 return p.charAt(p.length() - 1) == '/' && s.startsWith(p);
161 }
162 };
163 }
164 }