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 = new SectionParser<CoreConfig>() {
61 public CoreConfig parse(final Config cfg) {
62 return new CoreConfig(cfg);
63 }
64 };
65
66 /** Permissible values for {@code core.autocrlf}. */
67 public static enum AutoCRLF {
68 /** Automatic CRLF->LF conversion is disabled. */
69 FALSE,
70
71 /** Automatic CRLF->LF conversion is enabled. */
72 TRUE,
73
74 /** CRLF->LF performed, but no LF->CRLF. */
75 INPUT;
76 }
77
78 /**
79 * Permissible values for {@code core.checkstat}
80 *
81 * @since 3.0
82 */
83 public static enum CheckStat {
84 /**
85 * Only check the size and whole second part of time stamp when
86 * comparing the stat info in the dircache with actual file stat info.
87 */
88 MINIMAL,
89
90 /**
91 * Check as much of the dircache stat info as possible. Implementation
92 * limits may apply.
93 */
94 DEFAULT
95 }
96
97 private final int compression;
98
99 private final int packIndexVersion;
100
101 private final boolean logAllRefUpdates;
102
103 private final String excludesfile;
104
105 private final String attributesfile;
106
107 /**
108 * Options for symlink handling
109 *
110 * @since 3.3
111 */
112 public static enum SymLinks {
113 /** Checkout symbolic links as plain files */
114 FALSE,
115 /** Checkout symbolic links as links */
116 TRUE
117 }
118
119 /**
120 * Options for hiding files whose names start with a period
121 *
122 * @since 3.5
123 */
124 public static enum HideDotFiles {
125 /** Do not hide .files */
126 FALSE,
127 /** Hide add .files */
128 TRUE,
129 /** Hide only .git */
130 DOTGITONLY
131 }
132
133 private CoreConfig(final Config rc) {
134 compression = rc.getInt(ConfigConstants.CONFIG_CORE_SECTION,
135 ConfigConstants.CONFIG_KEY_COMPRESSION, DEFAULT_COMPRESSION);
136 packIndexVersion = rc.getInt(ConfigConstants.CONFIG_PACK_SECTION,
137 ConfigConstants.CONFIG_KEY_INDEXVERSION, 2);
138 logAllRefUpdates = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION,
139 ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
140 excludesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION, null,
141 ConfigConstants.CONFIG_KEY_EXCLUDESFILE);
142 attributesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION,
143 null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE);
144 }
145
146 /**
147 * @return The compression level to use when storing loose objects
148 */
149 public int getCompression() {
150 return compression;
151 }
152
153 /**
154 * @return the preferred pack index file format; 0 for oldest possible.
155 */
156 public int getPackIndexVersion() {
157 return packIndexVersion;
158 }
159
160 /**
161 * @return whether to log all refUpdates
162 */
163 public boolean isLogAllRefUpdates() {
164 return logAllRefUpdates;
165 }
166
167 /**
168 * @return path of excludesfile
169 */
170 public String getExcludesFile() {
171 return excludesfile;
172 }
173
174 /**
175 * @return path of attributesfile
176 * @since 3.7
177 */
178 public String getAttributesFile() {
179 return attributesfile;
180 }
181 }