aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java367
1 files changed, 288 insertions, 79 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
index 535a6ee175..9de8392690 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
@@ -1,52 +1,24 @@
/*
* Copyright (C) 2008, Google Inc.
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
- * Copyright (C) 2006-2012, Shawn O. Pearce <spearce@spearce.org>
- * and other copyright owners as documented in the project's IP log.
+ * Copyright (C) 2006, 2022, 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 v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
+ * 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.
*
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.lib;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.MessageFormat;
@@ -55,7 +27,9 @@ import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.util.MutableInteger;
-/** Misc. constants used throughout JGit. */
+/**
+ * Misc. constants and helpers used throughout JGit.
+ */
@SuppressWarnings("nls")
public final class Constants {
/** Hash function used natively by Git for all objects. */
@@ -77,6 +51,15 @@ public final class Constants {
*/
public static final int OBJECT_ID_STRING_LENGTH = OBJECT_ID_LENGTH * 2;
+ /**
+ * The historic length of an abbreviated Git object hash string. Git 2.11
+ * changed this static number to a dynamically calculated one that scales
+ * as the repository grows.
+ *
+ * @since 6.1
+ */
+ public static final int OBJECT_ID_ABBREV_STRING_LENGTH = 7;
+
/** Special name for the "HEAD" symbolic-ref. */
public static final String HEAD = "HEAD";
@@ -223,12 +206,6 @@ public final class Constants {
*/
public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' };
- /** Native character encoding for commit messages, file names... */
- public static final String CHARACTER_ENCODING = "UTF-8";
-
- /** Native character encoding for commit messages, file names... */
- public static final Charset CHARSET;
-
/** Default main branch name */
public static final String MASTER = "master";
@@ -259,9 +236,59 @@ public final class Constants {
/** Logs folder name */
public static final String LOGS = "logs";
+ /**
+ * Objects folder name
+ * @since 5.5
+ */
+ public static final String OBJECTS = "objects";
+
+ /**
+ * Reftable folder name
+ * @since 5.6
+ */
+ public static final String REFTABLE = "reftable";
+
+ /**
+ * Reftable table list name.
+ * @since 5.6.2
+ */
+ public static final String TABLES_LIST = "tables.list";
+
/** Info refs folder */
public static final String INFO_REFS = "info/refs";
+ /**
+ * Name of heads folder or file in refs.
+ *
+ * @since 7.0
+ */
+ public static final String HEADS = "heads";
+
+ /**
+ * Prefix for any log.
+ *
+ * @since 7.0
+ */
+ public static final String L_LOGS = LOGS + "/";
+
+ /**
+ * Info alternates file (goes under OBJECTS)
+ * @since 5.5
+ */
+ public static final String INFO_ALTERNATES = "info/alternates";
+
+ /**
+ * HTTP alternates file (goes under OBJECTS)
+ * @since 5.5
+ */
+ public static final String INFO_HTTP_ALTERNATES = "info/http-alternates";
+
+ /**
+ * info commit-graph file (goes under OBJECTS)
+ * @since 6.5
+ */
+ public static final String INFO_COMMIT_GRAPH = "info/commit-graph";
+
/** Packed refs file */
public static final String PACKED_REFS = "packed-refs";
@@ -273,6 +300,13 @@ public final class Constants {
public static final String INFO_EXCLUDE = "info/exclude";
/**
+ * Attributes-override-file
+ *
+ * @since 4.2
+ */
+ public static final String INFO_ATTRIBUTES = "info/attributes";
+
+ /**
* The system property that contains the system user name
*
* @since 3.6
@@ -302,6 +336,24 @@ public final class Constants {
public static final String GIT_CONFIG_NOSYSTEM_KEY = "GIT_CONFIG_NOSYSTEM";
/**
+ * The key of the XDG_CONFIG_HOME directory defined in the
+ * <a href="https://wiki.archlinux.org/index.php/XDG_Base_Directory">
+ * XDG Base Directory specification</a>.
+ *
+ * @since 5.5.2
+ */
+ public static final String XDG_CONFIG_HOME = "XDG_CONFIG_HOME";
+
+ /**
+ * The key of the XDG_CACHE_HOME directory defined in the
+ * <a href="https://wiki.archlinux.org/index.php/XDG_Base_Directory">
+ * XDG Base Directory specification</a>.
+ *
+ * @since 7.3
+ */
+ public static final String XDG_CACHE_HOME = "XDG_CACHE_HOME";
+
+ /**
* The environment variable that limits how close to the root of the file
* systems JGit will traverse when looking for a repository root.
*/
@@ -314,6 +366,14 @@ public final class Constants {
public static final String GIT_DIR_KEY = "GIT_DIR";
/**
+ * The environment variable that tells us which directory is the common
+ * ".git" directory.
+ *
+ * @since 7.0
+ */
+ public static final String GIT_COMMON_DIR_KEY = "GIT_COMMON_DIR";
+
+ /**
* The environment variable that tells us which directory is the working
* directory.
*/
@@ -357,12 +417,47 @@ public final class Constants {
public static final String DOT_GIT_EXT = ".git";
/**
+ * The default extension for local bundle files
+ *
+ * @since 5.8
+ */
+ public static final String DOT_BUNDLE_EXT = ".bundle";
+
+ /**
* Name of the attributes file
*
* @since 3.7
*/
public static final String DOT_GIT_ATTRIBUTES = ".gitattributes";
+ /**
+ * Key for filters in .gitattributes
+ *
+ * @since 4.2
+ */
+ public static final String ATTR_FILTER = "filter";
+
+ /**
+ * clean command name, used to call filter driver
+ *
+ * @since 4.2
+ */
+ public static final String ATTR_FILTER_TYPE_CLEAN = "clean";
+
+ /**
+ * smudge command name, used to call filter driver
+ *
+ * @since 4.2
+ */
+ public static final String ATTR_FILTER_TYPE_SMUDGE = "smudge";
+
+ /**
+ * Builtin filter commands start with this prefix
+ *
+ * @since 4.6
+ */
+ public static final String BUILTIN_FILTER_PREFIX = "jgit://builtin/";
+
/** Name of the ignore file */
public static final String DOT_GIT_IGNORE = ".gitignore";
@@ -380,6 +475,36 @@ public final class Constants {
public static final String GITDIR = "gitdir: ";
/**
+ * Name of the file (inside gitDir) that references the worktree's .git
+ * file (opposite link).
+ *
+ * .git/worktrees/&lt;worktree-name&gt;/gitdir
+ *
+ * A text file containing the absolute path back to the .git file that
+ * points here. This file is used to verify if the linked repository has been
+ * manually removed in which case this directory is no longer needed.
+ * The modification time (mtime) of this file should be updated each time
+ * the linked repository is accessed.
+ *
+ * @since 7.0
+ */
+ public static final String GITDIR_FILE = "gitdir";
+
+ /**
+ * Name of the file (inside gitDir) that has reference to $GIT_COMMON_DIR.
+ *
+ * .git/worktrees/&lt;worktree-name&gt;/commondir
+ *
+ * If this file exists, $GIT_COMMON_DIR will be set to the path specified in
+ * this file unless it is explicitly set. If the specified path is relative,
+ * it is relative to $GIT_DIR. The repository with commondir is incomplete
+ * without the repository pointed by "commondir".
+ *
+ * @since 7.0
+ */
+ public static final String COMMONDIR_FILE = "commondir";
+
+ /**
* Name of the folder (inside gitDir) where submodules are stored
*
* @since 3.6
@@ -394,10 +519,59 @@ public final class Constants {
public static final String HOOKS = "hooks";
/**
+ * Merge attribute.
+ *
+ * @since 4.9
+ */
+ public static final String ATTR_MERGE = "merge"; //$NON-NLS-1$
+
+ /**
+ * Diff attribute.
+ *
+ * @since 4.11
+ */
+ public static final String ATTR_DIFF = "diff"; //$NON-NLS-1$
+
+ /**
+ * Binary value for custom merger.
+ *
+ * @since 4.9
+ */
+ public static final String ATTR_BUILTIN_BINARY_MERGER = "binary"; //$NON-NLS-1$
+
+ /**
+ * Prefix of a GPG signature.
+ *
+ * @since 7.0
+ */
+ public static final String GPG_SIGNATURE_PREFIX = "-----BEGIN PGP SIGNATURE-----"; //$NON-NLS-1$
+
+ /**
+ * Prefix of a CMS signature (X.509, S/MIME).
+ *
+ * @since 7.0
+ */
+ public static final String CMS_SIGNATURE_PREFIX = "-----BEGIN SIGNED MESSAGE-----"; //$NON-NLS-1$
+
+ /**
+ * Prefix of an SSH signature.
+ *
+ * @since 7.0
+ */
+ public static final String SSH_SIGNATURE_PREFIX = "-----BEGIN SSH SIGNATURE-----"; //$NON-NLS-1$
+
+ /**
+ * Union built-in merge driver
+ *
+ * @since 6.10.1
+ */
+ public static final String ATTR_BUILTIN_UNION_MERGE_DRIVER = "union"; //$NON-NLS-1$
+
+ /**
* Create a new digest function for objects.
*
* @return a new digest object.
- * @throws RuntimeException
+ * @throws java.lang.RuntimeException
* this Java virtual machine does not support the required hash
* function. Very unlikely given that JGit uses a hash function
* that is in the Java reference specification.
@@ -417,7 +591,7 @@ public final class Constants {
* @param typeCode the type code, from a pack representation.
* @return the canonical string name of this type.
*/
- public static String typeString(final int typeCode) {
+ public static String typeString(int typeCode) {
switch (typeCode) {
case OBJ_COMMIT:
return TYPE_COMMIT;
@@ -442,7 +616,7 @@ public final class Constants {
* @param typeCode the type code, from a pack representation.
* @return the canonical ASCII encoded name of this type.
*/
- public static byte[] encodedTypeString(final int typeCode) {
+ public static byte[] encodedTypeString(int typeCode) {
switch (typeCode) {
case OBJ_COMMIT:
return ENCODED_TYPE_COMMIT;
@@ -475,7 +649,7 @@ public final class Constants {
* <code>endMark</code> when the parse is successful.
* @return a type code constant (one of {@link #OBJ_BLOB},
* {@link #OBJ_COMMIT}, {@link #OBJ_TAG}, {@link #OBJ_TREE}.
- * @throws CorruptObjectException
+ * @throws org.eclipse.jgit.errors.CorruptObjectException
* there is no valid type identified by <code>typeString</code>.
*/
public static int decodeTypeString(final AnyObjectId id,
@@ -529,7 +703,10 @@ public final class Constants {
throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
}
} catch (ArrayIndexOutOfBoundsException bad) {
- throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
+ CorruptObjectException coe = new CorruptObjectException(id,
+ JGitText.get().corruptObjectInvalidType);
+ coe.initCause(bad);
+ throw coe;
}
}
@@ -541,7 +718,7 @@ public final class Constants {
* @return a decimal representation of the input integer. The returned array
* is the smallest array that will hold the value.
*/
- public static byte[] encodeASCII(final long s) {
+ public static byte[] encodeASCII(long s) {
return encodeASCII(Long.toString(s));
}
@@ -553,48 +730,37 @@ public final class Constants {
* 127 (outside of 7-bit ASCII).
* @return a byte array of the same length as the input string, holding the
* same characters, in the same order.
- * @throws IllegalArgumentException
+ * @throws java.lang.IllegalArgumentException
* the input string contains one or more characters outside of
* the 7-bit ASCII character space.
*/
- public static byte[] encodeASCII(final String s) {
- final byte[] r = new byte[s.length()];
- for (int k = r.length - 1; k >= 0; k--) {
- final char c = s.charAt(k);
- if (c > 127)
- throw new IllegalArgumentException(MessageFormat.format(JGitText.get().notASCIIString, s));
- r[k] = (byte) c;
+ public static byte[] encodeASCII(String s) {
+ try {
+ CharsetEncoder encoder = US_ASCII.newEncoder()
+ .onUnmappableCharacter(CodingErrorAction.REPORT)
+ .onMalformedInput(CodingErrorAction.REPORT);
+ return encoder.encode(CharBuffer.wrap(s)).array();
+ } catch (CharacterCodingException e) {
+ throw new IllegalArgumentException(
+ MessageFormat.format(JGitText.get().notASCIIString, s), e);
}
- return r;
}
/**
- * Convert a string to a byte array in the standard character encoding.
+ * Convert a string to a byte array in the standard character encoding UTF8.
*
* @param str
* the string to convert. May contain any Unicode characters.
* @return a byte array representing the requested string, encoded using the
* default character encoding (UTF-8).
- * @see #CHARACTER_ENCODING
- */
- public static byte[] encode(final String str) {
- final ByteBuffer bb = Constants.CHARSET.encode(str);
- final int len = bb.limit();
- if (bb.hasArray() && bb.arrayOffset() == 0) {
- final byte[] arr = bb.array();
- if (arr.length == len)
- return arr;
- }
-
- final byte[] arr = new byte[len];
- bb.get(arr);
- return arr;
+ */
+ public static byte[] encode(String str) {
+ return str.getBytes(UTF_8);
}
static {
if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength())
throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH);
- CHARSET = Charset.forName(CHARACTER_ENCODING);
}
/** name of the file containing the commit msg for a merge commit */
@@ -626,10 +792,53 @@ public final class Constants {
*/
public static final String COMMIT_EDITMSG = "COMMIT_EDITMSG";
- /** objectid for the empty blob */
+ /**
+ * Well-known object ID for the empty blob.
+ *
+ * @since 0.9.1
+ */
public static final ObjectId EMPTY_BLOB_ID = ObjectId
.fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
+ /**
+ * Well-known object ID for the empty tree.
+ *
+ * @since 5.1
+ */
+ public static final ObjectId EMPTY_TREE_ID = ObjectId
+ .fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904");
+
+ /**
+ * Suffix of lock file name
+ *
+ * @since 4.7
+ */
+ public static final String LOCK_SUFFIX = ".lock"; //$NON-NLS-1$
+
+ /**
+ * Depth used to unshallow a repository
+ *
+ * @since 6.3
+ */
+ public static final int INFINITE_DEPTH = 0x7fffffff;
+
+ /**
+ * We use ({@value}) as generation number for commits not in the
+ * commit-graph file.
+ *
+ * @since 6.5
+ */
+ public static final int COMMIT_GENERATION_UNKNOWN = Integer.MAX_VALUE;
+
+ /**
+ * If a commit-graph file was written by a version of Git that did not
+ * compute generation numbers, then those commits will have generation
+ * number represented by ({@value}).
+ *
+ * @since 6.5
+ */
+ public static final int COMMIT_GENERATION_NOT_COMPUTED = 0;
+
private Constants() {
// Hide the default constructor
}