1 /*
2 * Copyright (C) 2013, Gunnar Wagenknecht
3 * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com>
4 * Copyright (C) 2009, Christian Halstrick <christian.halstrick@sap.com>
5 * Copyright (C) 2009, Google Inc.
6 * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
7 * Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> and others
8 *
9 * This program and the accompanying materials are made available under the
10 * terms of the Eclipse Distribution License v. 1.0 which is available at
11 * https://www.eclipse.org/org/documents/edl-v10.php.
12 *
13 * SPDX-License-Identifier: BSD-3-Clause
14 */
15
16 package org.eclipse.jgit.lib;
17
18 import static java.util.zip.Deflater.DEFAULT_COMPRESSION;
19
20 import org.eclipse.jgit.lib.Config.SectionParser;
21
22 /**
23 * This class keeps git repository core parameters.
24 */
25 public class CoreConfig {
26 /** Key for {@link Config#get(SectionParser)}. */
27 public static final Config.SectionParser<CoreConfig> KEY = CoreConfig::new;
28
29 /** Permissible values for {@code core.autocrlf}. */
30 public enum AutoCRLF {
31 /** Automatic CRLF->LF conversion is disabled. */
32 FALSE,
33
34 /** Automatic CRLF->LF conversion is enabled. */
35 TRUE,
36
37 /** CRLF->LF performed, but no LF->CRLF. */
38 INPUT;
39 }
40
41 /**
42 * Permissible values for {@code core.eol}.
43 * <p>
44 * https://git-scm.com/docs/gitattributes
45 *
46 * @since 4.3
47 */
48 public enum EOL {
49 /** Check in with LF, check out with CRLF. */
50 CRLF,
51
52 /** Check in with LF, check out without conversion. */
53 LF,
54
55 /** Use the platform's native line ending. */
56 NATIVE;
57 }
58
59 /**
60 * EOL stream conversion protocol.
61 *
62 * @since 4.3
63 */
64 public enum EolStreamType {
65 /** Convert to CRLF without binary detection. */
66 TEXT_CRLF,
67
68 /** Convert to LF without binary detection. */
69 TEXT_LF,
70
71 /** Convert to CRLF with binary detection. */
72 AUTO_CRLF,
73
74 /** Convert to LF with binary detection. */
75 AUTO_LF,
76
77 /** Do not convert. */
78 DIRECT;
79 }
80
81 /**
82 * Permissible values for {@code core.checkstat}.
83 *
84 * @since 3.0
85 */
86 public enum CheckStat {
87 /**
88 * Only check the size and whole second part of time stamp when
89 * comparing the stat info in the dircache with actual file stat info.
90 */
91 MINIMAL,
92
93 /**
94 * Check as much of the dircache stat info as possible. Implementation
95 * limits may apply.
96 */
97 DEFAULT
98 }
99
100 /**
101 * Permissible values for {@code core.logAllRefUpdates}.
102 *
103 * @since 5.6
104 */
105 public enum LogRefUpdates {
106 /** Don't create ref logs; default for bare repositories. */
107 FALSE,
108
109 /**
110 * Create ref logs for refs/heads/**, refs/remotes/**, refs/notes/**,
111 * and for HEAD. Default for non-bare repositories.
112 */
113 TRUE,
114
115 /** Create ref logs for all refs/** and for HEAD. */
116 ALWAYS
117 }
118
119 private final int compression;
120
121 private final int packIndexVersion;
122
123 private final LogRefUpdates logAllRefUpdates;
124
125 private final String excludesfile;
126
127 private final String attributesfile;
128
129 /**
130 * Options for symlink handling
131 *
132 * @since 3.3
133 */
134 public enum SymLinks {
135 /** Check out symbolic links as plain files . */
136 FALSE,
137
138 /** Check out symbolic links as links. */
139 TRUE
140 }
141
142 /**
143 * Options for hiding files whose names start with a period.
144 *
145 * @since 3.5
146 */
147 public enum HideDotFiles {
148 /** Do not hide .files. */
149 FALSE,
150
151 /** Hide add .files. */
152 TRUE,
153
154 /** Hide only .git. */
155 DOTGITONLY
156 }
157
158 private CoreConfig(Config rc) {
159 compression = rc.getInt(ConfigConstants.CONFIG_CORE_SECTION,
160 ConfigConstants.CONFIG_KEY_COMPRESSION, DEFAULT_COMPRESSION);
161 packIndexVersion = rc.getInt(ConfigConstants.CONFIG_PACK_SECTION,
162 ConfigConstants.CONFIG_KEY_INDEXVERSION, 2);
163 logAllRefUpdates = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
164 ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES,
165 LogRefUpdates.TRUE);
166 excludesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION, null,
167 ConfigConstants.CONFIG_KEY_EXCLUDESFILE);
168 attributesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION,
169 null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE);
170 }
171
172 /**
173 * Get the compression level to use when storing loose objects
174 *
175 * @return The compression level to use when storing loose objects
176 */
177 public int getCompression() {
178 return compression;
179 }
180
181 /**
182 * Get the preferred pack index file format; 0 for oldest possible.
183 *
184 * @return the preferred pack index file format; 0 for oldest possible.
185 */
186 public int getPackIndexVersion() {
187 return packIndexVersion;
188 }
189
190 /**
191 * Whether to log all refUpdates
192 *
193 * @return whether to log all refUpdates
194 * @deprecated since 5.6; default value depends on whether the repository is
195 * bare. Use
196 * {@link Config#getEnum(String, String, String, Enum)}
197 * directly.
198 */
199 @Deprecated
200 public boolean isLogAllRefUpdates() {
201 return !LogRefUpdates.FALSE.equals(logAllRefUpdates);
202 }
203
204 /**
205 * Get path of excludesfile
206 *
207 * @return path of excludesfile
208 */
209 public String getExcludesFile() {
210 return excludesfile;
211 }
212
213 /**
214 * Get path of attributesfile
215 *
216 * @return path of attributesfile
217 * @since 3.7
218 */
219 public String getAttributesFile() {
220 return attributesfile;
221 }
222 }