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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
/*
* Copyright (C) 2013, Gunnar Wagenknecht
* Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com>
* Copyright (C) 2009, Christian Halstrick <christian.halstrick@sap.com>
* Copyright (C) 2009, Google Inc.
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.lib;
import static java.util.zip.Deflater.DEFAULT_COMPRESSION;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Config.SectionParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class keeps git repository core parameters.
*/
public class CoreConfig {
private static final Logger LOG = LoggerFactory.getLogger(CoreConfig.class);
/** Key for {@link Config#get(SectionParser)}. */
public static final Config.SectionParser<CoreConfig> KEY = CoreConfig::new;
/** Permissible values for {@code core.autocrlf}. */
public enum AutoCRLF {
/** Automatic CRLF->LF conversion is disabled. */
FALSE,
/** Automatic CRLF->LF conversion is enabled. */
TRUE,
/** CRLF->LF performed, but no LF->CRLF. */
INPUT;
}
/**
* Permissible values for {@code core.eol}.
* <p>
* https://git-scm.com/docs/gitattributes
*
* @since 4.3
*/
public enum EOL {
/** Check in with LF, check out with CRLF. */
CRLF,
/** Check in with LF, check out without conversion. */
LF,
/** Use the platform's native line ending. */
NATIVE;
}
/**
* EOL stream conversion protocol.
*
* @since 4.3
*/
public enum EolStreamType {
/** Convert to CRLF without binary detection. */
TEXT_CRLF,
/** Convert to LF without binary detection. */
TEXT_LF,
/** Convert to CRLF with binary detection. */
AUTO_CRLF,
/** Convert to LF with binary detection. */
AUTO_LF,
/** Do not convert. */
DIRECT;
}
/**
* Permissible values for {@code core.checkstat}.
*
* @since 3.0
*/
public enum CheckStat {
/**
* Only check the size and whole second part of time stamp when
* comparing the stat info in the dircache with actual file stat info.
*/
MINIMAL,
/**
* Check as much of the dircache stat info as possible. Implementation
* limits may apply.
*/
DEFAULT
}
/**
* Permissible values for {@code core.logAllRefUpdates}.
*
* @since 5.6
*/
public enum LogRefUpdates {
/** Don't create ref logs; default for bare repositories. */
FALSE,
/**
* Create ref logs for refs/heads/**, refs/remotes/**, refs/notes/**,
* and for HEAD. Default for non-bare repositories.
*/
TRUE,
/** Create ref logs for all refs/** and for HEAD. */
ALWAYS
}
/**
* Default value of commit graph enable option: {@value}
*
* @since 6.5
*/
public static final boolean DEFAULT_COMMIT_GRAPH_ENABLE = false;
/**
* Permissible values for {@code core.trustPackedRefsStat}.
*
* @since 6.1.1
* @deprecated use {@link TrustStat} instead
*/
@Deprecated(since = "7.2", forRemoval = true)
public enum TrustPackedRefsStat {
/** Do not trust file attributes of the packed-refs file. */
NEVER,
/** Trust file attributes of the packed-refs file. */
ALWAYS,
/**
* Open and close the packed-refs file to refresh its file attributes
* and then trust it.
*/
AFTER_OPEN,
/**
* {@code core.trustPackedRefsStat} defaults to this when it is not set
*/
UNSET
}
/**
* Permissible values for {@code core.trustLooseRefStat}.
*
* @since 6.9
* @deprecated use {@link TrustStat} instead
*/
@Deprecated(since = "7.2", forRemoval = true)
public enum TrustLooseRefStat {
/** Trust file attributes of the loose ref. */
ALWAYS,
/**
* Open and close parent directories of the loose ref file until the
* repository root to refresh its file attributes and then trust it.
*/
AFTER_OPEN,
}
/**
* Values for {@code core.trustXXX} options.
*
* @since 7.2
*/
public enum TrustStat {
/** Do not trust file attributes of a File. */
NEVER,
/** Always trust file attributes of a File. */
ALWAYS,
/** Open and close the File to refresh its file attributes
* and then trust it. */
AFTER_OPEN,
/**
* Used for specific options to inherit value from value set for
* core.trustStat.
*/
INHERIT
}
private final int compression;
private final int packIndexVersion;
private final String excludesfile;
private final String attributesfile;
private final boolean commitGraph;
private final TrustStat trustStat;
private final TrustStat trustPackedRefsStat;
private final TrustStat trustLooseRefStat;
private final TrustStat trustPackStat;
private final TrustStat trustLooseObjectStat;
private final TrustStat trustTablesListStat;
/**
* Options for symlink handling
*
* @since 3.3
*/
public enum SymLinks {
/** Check out symbolic links as plain files . */
FALSE,
/** Check out symbolic links as links. */
TRUE
}
/**
* Options for hiding files whose names start with a period.
*
* @since 3.5
*/
public enum HideDotFiles {
/** Do not hide .files. */
FALSE,
/** Hide add .files. */
TRUE,
/** Hide only .git. */
DOTGITONLY
}
/**
* Create a new core configuration from the passed configuration.
*
* @param rc
* git configuration
*/
CoreConfig(Config rc) {
compression = rc.getInt(ConfigConstants.CONFIG_CORE_SECTION,
ConfigConstants.CONFIG_KEY_COMPRESSION, DEFAULT_COMPRESSION);
packIndexVersion = rc.getInt(ConfigConstants.CONFIG_PACK_SECTION,
ConfigConstants.CONFIG_KEY_INDEXVERSION, 2);
excludesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_EXCLUDESFILE);
attributesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION,
null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE);
commitGraph = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION,
ConfigConstants.CONFIG_COMMIT_GRAPH,
DEFAULT_COMMIT_GRAPH_ENABLE);
trustStat = parseTrustStat(rc);
trustPackedRefsStat = parseTrustPackedRefsStat(rc);
trustLooseRefStat = parseTrustLooseRefStat(rc);
trustPackStat = parseTrustPackFileStat(rc);
trustLooseObjectStat = parseTrustLooseObjectFileStat(rc);
trustTablesListStat = parseTablesListStat(rc);
}
private static TrustStat parseTrustStat(Config rc) {
Boolean tfs = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION,
ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT);
TrustStat ts = rc.getEnum(TrustStat.values(),
ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_TRUST_STAT);
if (tfs != null) {
if (ts == null) {
LOG.warn(JGitText.get().deprecatedTrustFolderStat);
return tfs.booleanValue() ? TrustStat.ALWAYS : TrustStat.NEVER;
}
LOG.warn(JGitText.get().precedenceTrustConfig);
}
if (ts == null) {
ts = TrustStat.ALWAYS;
} else if (ts == TrustStat.INHERIT) {
LOG.warn(JGitText.get().invalidTrustStat);
ts = TrustStat.ALWAYS;
}
return ts;
}
private TrustStat parseTrustPackedRefsStat(Config rc) {
return inheritParseTrustStat(rc,
ConfigConstants.CONFIG_KEY_TRUST_PACKED_REFS_STAT);
}
private TrustStat parseTrustLooseRefStat(Config rc) {
return inheritParseTrustStat(rc,
ConfigConstants.CONFIG_KEY_TRUST_LOOSE_REF_STAT);
}
private TrustStat parseTrustPackFileStat(Config rc) {
return inheritParseTrustStat(rc,
ConfigConstants.CONFIG_KEY_TRUST_PACK_STAT);
}
private TrustStat parseTrustLooseObjectFileStat(Config rc) {
return inheritParseTrustStat(rc,
ConfigConstants.CONFIG_KEY_TRUST_LOOSE_OBJECT_STAT);
}
private TrustStat inheritParseTrustStat(Config rc, String key) {
TrustStat t = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, key,
TrustStat.INHERIT);
return t == TrustStat.INHERIT ? trustStat : t;
}
private TrustStat parseTablesListStat(Config rc) {
TrustStat t = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_TRUST_TABLESLIST_STAT,
TrustStat.INHERIT);
return t == TrustStat.INHERIT ? trustStat : t;
}
/**
* Get the compression level to use when storing loose objects
*
* @return The compression level to use when storing loose objects
*/
public int getCompression() {
return compression;
}
/**
* Get the preferred pack index file format; 0 for oldest possible.
*
* @return the preferred pack index file format; 0 for oldest possible.
*/
public int getPackIndexVersion() {
return packIndexVersion;
}
/**
* Get path of excludesfile
*
* @return path of excludesfile
*/
public String getExcludesFile() {
return excludesfile;
}
/**
* Get path of attributesfile
*
* @return path of attributesfile
* @since 3.7
*/
public String getAttributesFile() {
return attributesfile;
}
/**
* Whether to read the commit-graph file (if it exists) to parse the graph
* structure of commits. Default to
* {@value org.eclipse.jgit.lib.CoreConfig#DEFAULT_COMMIT_GRAPH_ENABLE}.
*
* @return whether to read the commit-graph file
* @since 6.5
*/
public boolean enableCommitGraph() {
return commitGraph;
}
/**
* Get how far we can trust file attributes of packed-refs file which is
* used to store {@link org.eclipse.jgit.lib.Ref}s in
* {@link org.eclipse.jgit.internal.storage.file.RefDirectory}.
*
* @return how far we can trust file attributes of packed-refs file.
*
* @since 7.2
*/
public TrustStat getTrustPackedRefsStat() {
return trustPackedRefsStat;
}
/**
* Get how far we can trust file attributes of loose ref files which are
* used to store {@link org.eclipse.jgit.lib.Ref}s in
* {@link org.eclipse.jgit.internal.storage.file.RefDirectory}.
*
* @return how far we can trust file attributes of loose ref files.
*
* @since 7.2
*/
public TrustStat getTrustLooseRefStat() {
return trustLooseRefStat;
}
/**
* Get how far we can trust file attributes of packed-refs file which is
* used to store {@link org.eclipse.jgit.lib.Ref}s in
* {@link org.eclipse.jgit.internal.storage.file.RefDirectory}.
*
* @return how far we can trust file attributes of packed-refs file.
*
* @since 7.2
*/
public TrustStat getTrustPackStat() {
return trustPackStat;
}
/**
* Get how far we can trust file attributes of loose ref files which are
* used to store {@link org.eclipse.jgit.lib.Ref}s in
* {@link org.eclipse.jgit.internal.storage.file.RefDirectory}.
*
* @return how far we can trust file attributes of loose ref files.
*
* @since 7.2
*/
public TrustStat getTrustLooseObjectStat() {
return trustLooseObjectStat;
}
/**
* Get how far we can trust file attributes of the "tables.list" file which
* is used to store the list of filenames of the files storing
* {@link org.eclipse.jgit.internal.storage.reftable.Reftable}s in
* {@link org.eclipse.jgit.internal.storage.file.FileReftableDatabase}.
*
* @return how far we can trust file attributes of the "tables.list" file.
*
* @since 7.2
*/
public TrustStat getTrustTablesListStat() {
return trustTablesListStat;
}
}
|