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>
8 * and other copyright owners as documented in the project's IP log.
9 *
10 * This program and the accompanying materials are made available
11 * under the terms of the Eclipse Distribution License v1.0 which
12 * accompanies this distribution, is reproduced below, and is
13 * available at http://www.eclipse.org/org/documents/edl-v10.php
14 *
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or
18 * without modification, are permitted provided that the following
19 * conditions are met:
20 *
21 * - Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 *
24 * - Redistributions in binary form must reproduce the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer in the documentation and/or other materials provided
27 * with the distribution.
28 *
29 * - Neither the name of the Eclipse Foundation, Inc. nor the
30 * names of its contributors may be used to endorse or promote
31 * products derived from this software without specific prior
32 * written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
35 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
36 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
39 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
43 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
46 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 */
48
49 package org.eclipse.jgit.lib;
50
51 import static java.util.zip.Deflater.DEFAULT_COMPRESSION;
52
53 import org.eclipse.jgit.lib.Config.SectionParser;
54
55 /**
56 * This class keeps git repository core parameters.
57 */
58 public class CoreConfig {
59 /** Key for {@link Config#get(SectionParser)}. */
60 public static final Config.SectionParser<CoreConfig> KEY = CoreConfig::new;
61
62 /** Permissible values for {@code core.autocrlf}. */
63 public static enum AutoCRLF {
64 /** Automatic CRLF->LF conversion is disabled. */
65 FALSE,
66
67 /** Automatic CRLF->LF conversion is enabled. */
68 TRUE,
69
70 /** CRLF->LF performed, but no LF->CRLF. */
71 INPUT;
72 }
73
74 /**
75 * Permissible values for {@code core.eol}.
76 * <p>
77 * https://git-scm.com/docs/gitattributes
78 *
79 * @since 4.3
80 */
81 public static enum EOL {
82 /** checkin with LF, checkout with CRLF. */
83 CRLF,
84
85 /** checkin with LF, checkout without conversion. */
86 LF,
87
88 /** use the platform's native line ending. */
89 NATIVE;
90 }
91
92 /**
93 * EOL stream conversion protocol
94 *
95 * @since 4.3
96 */
97 public static enum EolStreamType {
98 /** convert to CRLF without binary detection */
99 TEXT_CRLF,
100
101 /** convert to LF without binary detection */
102 TEXT_LF,
103
104 /** convert to CRLF with binary detection */
105 AUTO_CRLF,
106
107 /** convert to LF with binary detection */
108 AUTO_LF,
109
110 /** do not convert */
111 DIRECT;
112 }
113
114 /**
115 * Permissible values for {@code core.checkstat}
116 *
117 * @since 3.0
118 */
119 public static enum CheckStat {
120 /**
121 * Only check the size and whole second part of time stamp when
122 * comparing the stat info in the dircache with actual file stat info.
123 */
124 MINIMAL,
125
126 /**
127 * Check as much of the dircache stat info as possible. Implementation
128 * limits may apply.
129 */
130 DEFAULT
131 }
132
133 private final int compression;
134
135 private final int packIndexVersion;
136
137 private final boolean logAllRefUpdates;
138
139 private final String excludesfile;
140
141 private final String attributesfile;
142
143 /**
144 * Options for symlink handling
145 *
146 * @since 3.3
147 */
148 public static enum SymLinks {
149 /** Checkout symbolic links as plain files */
150 FALSE,
151 /** Checkout symbolic links as links */
152 TRUE
153 }
154
155 /**
156 * Options for hiding files whose names start with a period
157 *
158 * @since 3.5
159 */
160 public static enum HideDotFiles {
161 /** Do not hide .files */
162 FALSE,
163 /** Hide add .files */
164 TRUE,
165 /** Hide only .git */
166 DOTGITONLY
167 }
168
169 private CoreConfig(Config rc) {
170 compression = rc.getInt(ConfigConstants.CONFIG_CORE_SECTION,
171 ConfigConstants.CONFIG_KEY_COMPRESSION, DEFAULT_COMPRESSION);
172 packIndexVersion = rc.getInt(ConfigConstants.CONFIG_PACK_SECTION,
173 ConfigConstants.CONFIG_KEY_INDEXVERSION, 2);
174 logAllRefUpdates = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION,
175 ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
176 excludesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION, null,
177 ConfigConstants.CONFIG_KEY_EXCLUDESFILE);
178 attributesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION,
179 null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE);
180 }
181
182 /**
183 * Get the compression level to use when storing loose objects
184 *
185 * @return The compression level to use when storing loose objects
186 */
187 public int getCompression() {
188 return compression;
189 }
190
191 /**
192 * Get the preferred pack index file format; 0 for oldest possible.
193 *
194 * @return the preferred pack index file format; 0 for oldest possible.
195 */
196 public int getPackIndexVersion() {
197 return packIndexVersion;
198 }
199
200 /**
201 * Whether to log all refUpdates
202 *
203 * @return whether to log all refUpdates
204 */
205 public boolean isLogAllRefUpdates() {
206 return logAllRefUpdates;
207 }
208
209 /**
210 * Get path of excludesfile
211 *
212 * @return path of excludesfile
213 */
214 public String getExcludesFile() {
215 return excludesfile;
216 }
217
218 /**
219 * Get path of attributesfile
220 *
221 * @return path of attributesfile
222 * @since 3.7
223 */
224 public String getAttributesFile() {
225 return attributesfile;
226 }
227 }