Constants.java

  1. /*
  2.  * Copyright (C) 2008, Google Inc.
  3.  * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
  4.  * Copyright (C) 2006, 2022, Shawn O. Pearce <spearce@spearce.org> and others
  5.  *
  6.  * This program and the accompanying materials are made available under the
  7.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  8.  * https://www.eclipse.org/org/documents/edl-v10.php.
  9.  *
  10.  * SPDX-License-Identifier: BSD-3-Clause
  11.  */

  12. package org.eclipse.jgit.lib;

  13. import static java.nio.charset.StandardCharsets.UTF_8;

  14. import java.nio.ByteBuffer;
  15. import java.nio.charset.Charset;
  16. import java.security.MessageDigest;
  17. import java.security.NoSuchAlgorithmException;
  18. import java.text.MessageFormat;

  19. import org.eclipse.jgit.errors.CorruptObjectException;
  20. import org.eclipse.jgit.internal.JGitText;
  21. import org.eclipse.jgit.util.MutableInteger;

  22. /**
  23.  * Misc. constants and helpers used throughout JGit.
  24.  */
  25. @SuppressWarnings("nls")
  26. public final class Constants {
  27.     /** Hash function used natively by Git for all objects. */
  28.     private static final String HASH_FUNCTION = "SHA-1";

  29.     /**
  30.      * A Git object hash is 160 bits, i.e. 20 bytes.
  31.      * <p>
  32.      * Changing this assumption is not going to be as easy as changing this
  33.      * declaration.
  34.      */
  35.     public static final int OBJECT_ID_LENGTH = 20;

  36.     /**
  37.      * A Git object can be expressed as a 40 character string of hexadecimal
  38.      * digits.
  39.      *
  40.      * @see #OBJECT_ID_LENGTH
  41.      */
  42.     public static final int OBJECT_ID_STRING_LENGTH = OBJECT_ID_LENGTH * 2;

  43.     /**
  44.      * The historic length of an abbreviated Git object hash string. Git 2.11
  45.      * changed this static number to a dynamically calculated one that scales
  46.      * as the repository grows.
  47.      *
  48.      * @since 6.1
  49.      */
  50.     public static final int OBJECT_ID_ABBREV_STRING_LENGTH = 7;

  51.     /** Special name for the "HEAD" symbolic-ref. */
  52.     public static final String HEAD = "HEAD";

  53.     /** Special name for the "FETCH_HEAD" symbolic-ref. */
  54.     public static final String FETCH_HEAD = "FETCH_HEAD";

  55.     /**
  56.      * Text string that identifies an object as a commit.
  57.      * <p>
  58.      * Commits connect trees into a string of project histories, where each
  59.      * commit is an assertion that the best way to continue is to use this other
  60.      * tree (set of files).
  61.      */
  62.     public static final String TYPE_COMMIT = "commit";

  63.     /**
  64.      * Text string that identifies an object as a blob.
  65.      * <p>
  66.      * Blobs store whole file revisions. They are used for any user file, as
  67.      * well as for symlinks. Blobs form the bulk of any project's storage space.
  68.      */
  69.     public static final String TYPE_BLOB = "blob";

  70.     /**
  71.      * Text string that identifies an object as a tree.
  72.      * <p>
  73.      * Trees attach object ids (hashes) to names and file modes. The normal use
  74.      * for a tree is to store a version of a directory and its contents.
  75.      */
  76.     public static final String TYPE_TREE = "tree";

  77.     /**
  78.      * Text string that identifies an object as an annotated tag.
  79.      * <p>
  80.      * Annotated tags store a pointer to any other object, and an additional
  81.      * message. It is most commonly used to record a stable release of the
  82.      * project.
  83.      */
  84.     public static final String TYPE_TAG = "tag";

  85.     private static final byte[] ENCODED_TYPE_COMMIT = encodeASCII(TYPE_COMMIT);

  86.     private static final byte[] ENCODED_TYPE_BLOB = encodeASCII(TYPE_BLOB);

  87.     private static final byte[] ENCODED_TYPE_TREE = encodeASCII(TYPE_TREE);

  88.     private static final byte[] ENCODED_TYPE_TAG = encodeASCII(TYPE_TAG);

  89.     /** An unknown or invalid object type code. */
  90.     public static final int OBJ_BAD = -1;

  91.     /**
  92.      * In-pack object type: extended types.
  93.      * <p>
  94.      * This header code is reserved for future expansion. It is currently
  95.      * undefined/unsupported.
  96.      */
  97.     public static final int OBJ_EXT = 0;

  98.     /**
  99.      * In-pack object type: commit.
  100.      * <p>
  101.      * Indicates the associated object is a commit.
  102.      * <p>
  103.      * <b>This constant is fixed and is defined by the Git packfile format.</b>
  104.      *
  105.      * @see #TYPE_COMMIT
  106.      */
  107.     public static final int OBJ_COMMIT = 1;

  108.     /**
  109.      * In-pack object type: tree.
  110.      * <p>
  111.      * Indicates the associated object is a tree.
  112.      * <p>
  113.      * <b>This constant is fixed and is defined by the Git packfile format.</b>
  114.      *
  115.      * @see #TYPE_BLOB
  116.      */
  117.     public static final int OBJ_TREE = 2;

  118.     /**
  119.      * In-pack object type: blob.
  120.      * <p>
  121.      * Indicates the associated object is a blob.
  122.      * <p>
  123.      * <b>This constant is fixed and is defined by the Git packfile format.</b>
  124.      *
  125.      * @see #TYPE_BLOB
  126.      */
  127.     public static final int OBJ_BLOB = 3;

  128.     /**
  129.      * In-pack object type: annotated tag.
  130.      * <p>
  131.      * Indicates the associated object is an annotated tag.
  132.      * <p>
  133.      * <b>This constant is fixed and is defined by the Git packfile format.</b>
  134.      *
  135.      * @see #TYPE_TAG
  136.      */
  137.     public static final int OBJ_TAG = 4;

  138.     /** In-pack object type: reserved for future use. */
  139.     public static final int OBJ_TYPE_5 = 5;

  140.     /**
  141.      * In-pack object type: offset delta
  142.      * <p>
  143.      * Objects stored with this type actually have a different type which must
  144.      * be obtained from their delta base object. Delta objects store only the
  145.      * changes needed to apply to the base object in order to recover the
  146.      * original object.
  147.      * <p>
  148.      * An offset delta uses a negative offset from the start of this object to
  149.      * refer to its delta base. The base object must exist in this packfile
  150.      * (even in the case of a thin pack).
  151.      * <p>
  152.      * <b>This constant is fixed and is defined by the Git packfile format.</b>
  153.      */
  154.     public static final int OBJ_OFS_DELTA = 6;

  155.     /**
  156.      * In-pack object type: reference delta
  157.      * <p>
  158.      * Objects stored with this type actually have a different type which must
  159.      * be obtained from their delta base object. Delta objects store only the
  160.      * changes needed to apply to the base object in order to recover the
  161.      * original object.
  162.      * <p>
  163.      * A reference delta uses a full object id (hash) to reference the delta
  164.      * base. The base object is allowed to be omitted from the packfile, but
  165.      * only in the case of a thin pack being transferred over the network.
  166.      * <p>
  167.      * <b>This constant is fixed and is defined by the Git packfile format.</b>
  168.      */
  169.     public static final int OBJ_REF_DELTA = 7;

  170.     /**
  171.      * Pack file signature that occurs at file header - identifies file as Git
  172.      * packfile formatted.
  173.      * <p>
  174.      * <b>This constant is fixed and is defined by the Git packfile format.</b>
  175.      */
  176.     public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' };

  177.     /**
  178.      * Native character encoding for commit messages, file names...
  179.      *
  180.      * @deprecated Use {@link java.nio.charset.StandardCharsets#UTF_8} directly
  181.      *             instead.
  182.      */
  183.     @Deprecated
  184.     public static final Charset CHARSET;

  185.     /**
  186.      * Native character encoding for commit messages, file names...
  187.      *
  188.      * @deprecated Use {@link java.nio.charset.StandardCharsets#UTF_8} directly
  189.      *             instead.
  190.      */
  191.     @Deprecated
  192.     public static final String CHARACTER_ENCODING;

  193.     /** Default main branch name */
  194.     public static final String MASTER = "master";

  195.     /** Default stash branch name */
  196.     public static final String STASH = "stash";

  197.     /** Prefix for branch refs */
  198.     public static final String R_HEADS = "refs/heads/";

  199.     /** Prefix for remotes refs */
  200.     public static final String R_REMOTES = "refs/remotes/";

  201.     /** Prefix for tag refs */
  202.     public static final String R_TAGS = "refs/tags/";

  203.     /** Prefix for notes refs */
  204.     public static final String R_NOTES = "refs/notes/";

  205.     /** Standard notes ref */
  206.     public static final String R_NOTES_COMMITS = R_NOTES + "commits";

  207.     /** Prefix for any ref */
  208.     public static final String R_REFS = "refs/";

  209.     /** Standard stash ref */
  210.     public static final String R_STASH = R_REFS + STASH;

  211.     /** Logs folder name */
  212.     public static final String LOGS = "logs";

  213.     /**
  214.      * Objects folder name
  215.      * @since 5.5
  216.      */
  217.     public static final String OBJECTS = "objects";

  218.     /**
  219.      * Reftable folder name
  220.      * @since 5.6
  221.      */
  222.     public static final String REFTABLE = "reftable";

  223.     /**
  224.      * Reftable table list name.
  225.      * @since 5.6.2
  226.      */
  227.     public static final String TABLES_LIST = "tables.list";

  228.     /** Info refs folder */
  229.     public static final String INFO_REFS = "info/refs";

  230.     /**
  231.      * Info alternates file (goes under OBJECTS)
  232.      * @since 5.5
  233.      */
  234.     public static final String INFO_ALTERNATES = "info/alternates";

  235.     /**
  236.      * HTTP alternates file (goes under OBJECTS)
  237.      * @since 5.5
  238.      */
  239.     public static final String INFO_HTTP_ALTERNATES = "info/http-alternates";

  240.     /** Packed refs file */
  241.     public static final String PACKED_REFS = "packed-refs";

  242.     /**
  243.      * Excludes-file
  244.      *
  245.      * @since 3.0
  246.      */
  247.     public static final String INFO_EXCLUDE = "info/exclude";

  248.     /**
  249.      * Attributes-override-file
  250.      *
  251.      * @since 4.2
  252.      */
  253.     public static final String INFO_ATTRIBUTES = "info/attributes";

  254.     /**
  255.      * The system property that contains the system user name
  256.      *
  257.      * @since 3.6
  258.      */
  259.     public static final String OS_USER_DIR = "user.dir";

  260.     /** The system property that contains the system user name */
  261.     public static final String OS_USER_NAME_KEY = "user.name";

  262.     /** The environment variable that contains the author's name */
  263.     public static final String GIT_AUTHOR_NAME_KEY = "GIT_AUTHOR_NAME";

  264.     /** The environment variable that contains the author's email */
  265.     public static final String GIT_AUTHOR_EMAIL_KEY = "GIT_AUTHOR_EMAIL";

  266.     /** The environment variable that contains the commiter's name */
  267.     public static final String GIT_COMMITTER_NAME_KEY = "GIT_COMMITTER_NAME";

  268.     /** The environment variable that contains the commiter's email */
  269.     public static final String GIT_COMMITTER_EMAIL_KEY = "GIT_COMMITTER_EMAIL";

  270.     /**
  271.      * The environment variable that blocks use of the system config file
  272.      *
  273.      * @since 3.3
  274.      */
  275.     public static final String GIT_CONFIG_NOSYSTEM_KEY = "GIT_CONFIG_NOSYSTEM";

  276.     /**
  277.      * The key of the XDG_CONFIG_HOME directory defined in the XDG base
  278.      * directory specification, see
  279.      * {@link "https://wiki.archlinux.org/index.php/XDG_Base_Directory"}
  280.      *
  281.      * @since 5.5.2
  282.      */
  283.     public static final String XDG_CONFIG_HOME = "XDG_CONFIG_HOME";

  284.     /**
  285.      * The environment variable that limits how close to the root of the file
  286.      * systems JGit will traverse when looking for a repository root.
  287.      */
  288.     public static final String GIT_CEILING_DIRECTORIES_KEY = "GIT_CEILING_DIRECTORIES";

  289.     /**
  290.      * The environment variable that tells us which directory is the ".git"
  291.      * directory
  292.      */
  293.     public static final String GIT_DIR_KEY = "GIT_DIR";

  294.     /**
  295.      * The environment variable that tells us which directory is the working
  296.      * directory.
  297.      */
  298.     public static final String GIT_WORK_TREE_KEY = "GIT_WORK_TREE";

  299.     /**
  300.      * The environment variable that tells us which file holds the Git index.
  301.      */
  302.     public static final String GIT_INDEX_FILE_KEY = "GIT_INDEX_FILE";

  303.     /**
  304.      * The environment variable that tells us where objects are stored
  305.      */
  306.     public static final String GIT_OBJECT_DIRECTORY_KEY = "GIT_OBJECT_DIRECTORY";

  307.     /**
  308.      * The environment variable that tells us where to look for objects, besides
  309.      * the default objects directory.
  310.      */
  311.     public static final String GIT_ALTERNATE_OBJECT_DIRECTORIES_KEY = "GIT_ALTERNATE_OBJECT_DIRECTORIES";

  312.     /** Default value for the user name if no other information is available */
  313.     public static final String UNKNOWN_USER_DEFAULT = "unknown-user";

  314.     /** Beginning of the common "Signed-off-by: " commit message line */
  315.     public static final String SIGNED_OFF_BY_TAG = "Signed-off-by: ";

  316.     /** A gitignore file name */
  317.     public static final String GITIGNORE_FILENAME = ".gitignore";

  318.     /** Default remote name used by clone, push and fetch operations */
  319.     public static final String DEFAULT_REMOTE_NAME = "origin";

  320.     /** Default name for the Git repository directory */
  321.     public static final String DOT_GIT = ".git";

  322.     /** Default name for the Git repository configuration */
  323.     public static final String CONFIG = "config";

  324.     /** A bare repository typically ends with this string */
  325.     public static final String DOT_GIT_EXT = ".git";

  326.     /**
  327.      * The default extension for local bundle files
  328.      *
  329.      * @since 5.8
  330.      */
  331.     public static final String DOT_BUNDLE_EXT = ".bundle";

  332.     /**
  333.      * Name of the attributes file
  334.      *
  335.      * @since 3.7
  336.      */
  337.     public static final String DOT_GIT_ATTRIBUTES = ".gitattributes";

  338.     /**
  339.      * Key for filters in .gitattributes
  340.      *
  341.      * @since 4.2
  342.      */
  343.     public static final String ATTR_FILTER = "filter";

  344.     /**
  345.      * clean command name, used to call filter driver
  346.      *
  347.      * @since 4.2
  348.      */
  349.     public static final String ATTR_FILTER_TYPE_CLEAN = "clean";

  350.     /**
  351.      * smudge command name, used to call filter driver
  352.      *
  353.      * @since 4.2
  354.      */
  355.     public static final String ATTR_FILTER_TYPE_SMUDGE = "smudge";

  356.     /**
  357.      * Builtin filter commands start with this prefix
  358.      *
  359.      * @since 4.6
  360.      */
  361.     public static final String BUILTIN_FILTER_PREFIX = "jgit://builtin/";

  362.     /** Name of the ignore file */
  363.     public static final String DOT_GIT_IGNORE = ".gitignore";

  364.     /** Name of the submodules file */
  365.     public static final String DOT_GIT_MODULES = ".gitmodules";

  366.     /** Name of the .git/shallow file */
  367.     public static final String SHALLOW = "shallow";

  368.     /**
  369.      * Prefix of the first line in a ".git" file
  370.      *
  371.      * @since 3.6
  372.      */
  373.     public static final String GITDIR = "gitdir: ";

  374.     /**
  375.      * Name of the folder (inside gitDir) where submodules are stored
  376.      *
  377.      * @since 3.6
  378.      */
  379.     public static final String MODULES = "modules";

  380.     /**
  381.      * Name of the folder (inside gitDir) where the hooks are stored.
  382.      *
  383.      * @since 3.7
  384.      */
  385.     public static final String HOOKS = "hooks";

  386.     /**
  387.      * Merge attribute.
  388.      *
  389.      * @since 4.9
  390.      */
  391.     public static final String ATTR_MERGE = "merge"; //$NON-NLS-1$

  392.     /**
  393.      * Diff attribute.
  394.      *
  395.      * @since 4.11
  396.      */
  397.     public static final String ATTR_DIFF = "diff"; //$NON-NLS-1$

  398.     /**
  399.      * Binary value for custom merger.
  400.      *
  401.      * @since 4.9
  402.      */
  403.     public static final String ATTR_BUILTIN_BINARY_MERGER = "binary"; //$NON-NLS-1$

  404.     /**
  405.      * Create a new digest function for objects.
  406.      *
  407.      * @return a new digest object.
  408.      * @throws java.lang.RuntimeException
  409.      *             this Java virtual machine does not support the required hash
  410.      *             function. Very unlikely given that JGit uses a hash function
  411.      *             that is in the Java reference specification.
  412.      */
  413.     public static MessageDigest newMessageDigest() {
  414.         try {
  415.             return MessageDigest.getInstance(HASH_FUNCTION);
  416.         } catch (NoSuchAlgorithmException nsae) {
  417.             throw new RuntimeException(MessageFormat.format(
  418.                     JGitText.get().requiredHashFunctionNotAvailable, HASH_FUNCTION), nsae);
  419.         }
  420.     }

  421.     /**
  422.      * Convert an OBJ_* type constant to a TYPE_* type constant.
  423.      *
  424.      * @param typeCode the type code, from a pack representation.
  425.      * @return the canonical string name of this type.
  426.      */
  427.     public static String typeString(int typeCode) {
  428.         switch (typeCode) {
  429.         case OBJ_COMMIT:
  430.             return TYPE_COMMIT;
  431.         case OBJ_TREE:
  432.             return TYPE_TREE;
  433.         case OBJ_BLOB:
  434.             return TYPE_BLOB;
  435.         case OBJ_TAG:
  436.             return TYPE_TAG;
  437.         default:
  438.             throw new IllegalArgumentException(MessageFormat.format(
  439.                     JGitText.get().badObjectType, Integer.valueOf(typeCode)));
  440.         }
  441.     }

  442.     /**
  443.      * Convert an OBJ_* type constant to an ASCII encoded string constant.
  444.      * <p>
  445.      * The ASCII encoded string is often the canonical representation of
  446.      * the type within a loose object header, or within a tag header.
  447.      *
  448.      * @param typeCode the type code, from a pack representation.
  449.      * @return the canonical ASCII encoded name of this type.
  450.      */
  451.     public static byte[] encodedTypeString(int typeCode) {
  452.         switch (typeCode) {
  453.         case OBJ_COMMIT:
  454.             return ENCODED_TYPE_COMMIT;
  455.         case OBJ_TREE:
  456.             return ENCODED_TYPE_TREE;
  457.         case OBJ_BLOB:
  458.             return ENCODED_TYPE_BLOB;
  459.         case OBJ_TAG:
  460.             return ENCODED_TYPE_TAG;
  461.         default:
  462.             throw new IllegalArgumentException(MessageFormat.format(
  463.                     JGitText.get().badObjectType, Integer.valueOf(typeCode)));
  464.         }
  465.     }

  466.     /**
  467.      * Parse an encoded type string into a type constant.
  468.      *
  469.      * @param id
  470.      *            object id this type string came from; may be null if that is
  471.      *            not known at the time the parse is occurring.
  472.      * @param typeString
  473.      *            string version of the type code.
  474.      * @param endMark
  475.      *            character immediately following the type string. Usually ' '
  476.      *            (space) or '\n' (line feed).
  477.      * @param offset
  478.      *            position within <code>typeString</code> where the parse
  479.      *            should start. Updated with the new position (just past
  480.      *            <code>endMark</code> when the parse is successful.
  481.      * @return a type code constant (one of {@link #OBJ_BLOB},
  482.      *         {@link #OBJ_COMMIT}, {@link #OBJ_TAG}, {@link #OBJ_TREE}.
  483.      * @throws org.eclipse.jgit.errors.CorruptObjectException
  484.      *             there is no valid type identified by <code>typeString</code>.
  485.      */
  486.     public static int decodeTypeString(final AnyObjectId id,
  487.             final byte[] typeString, final byte endMark,
  488.             final MutableInteger offset) throws CorruptObjectException {
  489.         try {
  490.             int position = offset.value;
  491.             switch (typeString[position]) {
  492.             case 'b':
  493.                 if (typeString[position + 1] != 'l'
  494.                         || typeString[position + 2] != 'o'
  495.                         || typeString[position + 3] != 'b'
  496.                         || typeString[position + 4] != endMark)
  497.                     throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  498.                 offset.value = position + 5;
  499.                 return Constants.OBJ_BLOB;

  500.             case 'c':
  501.                 if (typeString[position + 1] != 'o'
  502.                         || typeString[position + 2] != 'm'
  503.                         || typeString[position + 3] != 'm'
  504.                         || typeString[position + 4] != 'i'
  505.                         || typeString[position + 5] != 't'
  506.                         || typeString[position + 6] != endMark)
  507.                     throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  508.                 offset.value = position + 7;
  509.                 return Constants.OBJ_COMMIT;

  510.             case 't':
  511.                 switch (typeString[position + 1]) {
  512.                 case 'a':
  513.                     if (typeString[position + 2] != 'g'
  514.                             || typeString[position + 3] != endMark)
  515.                         throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  516.                     offset.value = position + 4;
  517.                     return Constants.OBJ_TAG;

  518.                 case 'r':
  519.                     if (typeString[position + 2] != 'e'
  520.                             || typeString[position + 3] != 'e'
  521.                             || typeString[position + 4] != endMark)
  522.                         throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  523.                     offset.value = position + 5;
  524.                     return Constants.OBJ_TREE;

  525.                 default:
  526.                     throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  527.                 }

  528.             default:
  529.                 throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  530.             }
  531.         } catch (ArrayIndexOutOfBoundsException bad) {
  532.             CorruptObjectException coe = new CorruptObjectException(id,
  533.                     JGitText.get().corruptObjectInvalidType);
  534.             coe.initCause(bad);
  535.             throw coe;
  536.         }
  537.     }

  538.     /**
  539.      * Convert an integer into its decimal representation.
  540.      *
  541.      * @param s
  542.      *            the integer to convert.
  543.      * @return a decimal representation of the input integer. The returned array
  544.      *         is the smallest array that will hold the value.
  545.      */
  546.     public static byte[] encodeASCII(long s) {
  547.         return encodeASCII(Long.toString(s));
  548.     }

  549.     /**
  550.      * Convert a string to US-ASCII encoding.
  551.      *
  552.      * @param s
  553.      *            the string to convert. Must not contain any characters over
  554.      *            127 (outside of 7-bit ASCII).
  555.      * @return a byte array of the same length as the input string, holding the
  556.      *         same characters, in the same order.
  557.      * @throws java.lang.IllegalArgumentException
  558.      *             the input string contains one or more characters outside of
  559.      *             the 7-bit ASCII character space.
  560.      */
  561.     public static byte[] encodeASCII(String s) {
  562.         final byte[] r = new byte[s.length()];
  563.         for (int k = r.length - 1; k >= 0; k--) {
  564.             final char c = s.charAt(k);
  565.             if (c > 127)
  566.                 throw new IllegalArgumentException(MessageFormat.format(JGitText.get().notASCIIString, s));
  567.             r[k] = (byte) c;
  568.         }
  569.         return r;
  570.     }

  571.     /**
  572.      * Convert a string to a byte array in the standard character encoding.
  573.      *
  574.      * @param str
  575.      *            the string to convert. May contain any Unicode characters.
  576.      * @return a byte array representing the requested string, encoded using the
  577.      *         default character encoding (UTF-8).
  578.      * @see #CHARACTER_ENCODING
  579.      */
  580.     public static byte[] encode(String str) {
  581.         final ByteBuffer bb = UTF_8.encode(str);
  582.         final int len = bb.limit();
  583.         if (bb.hasArray() && bb.arrayOffset() == 0) {
  584.             final byte[] arr = bb.array();
  585.             if (arr.length == len)
  586.                 return arr;
  587.         }

  588.         final byte[] arr = new byte[len];
  589.         bb.get(arr);
  590.         return arr;
  591.     }

  592.     static {
  593.         if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength())
  594.             throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH);
  595.         CHARSET = UTF_8;
  596.         CHARACTER_ENCODING = UTF_8.name();
  597.     }

  598.     /** name of the file containing the commit msg for a merge commit */
  599.     public static final String MERGE_MSG = "MERGE_MSG";

  600.     /** name of the file containing the IDs of the parents of a merge commit */
  601.     public static final String MERGE_HEAD = "MERGE_HEAD";

  602.     /** name of the file containing the ID of a cherry pick commit in case of conflicts */
  603.     public static final String CHERRY_PICK_HEAD = "CHERRY_PICK_HEAD";

  604.     /** name of the file containing the commit msg for a squash commit */
  605.     public static final String SQUASH_MSG = "SQUASH_MSG";

  606.     /** name of the file containing the ID of a revert commit in case of conflicts */
  607.     public static final String REVERT_HEAD = "REVERT_HEAD";

  608.     /**
  609.      * name of the ref ORIG_HEAD used by certain commands to store the original
  610.      * value of HEAD
  611.      */
  612.     public static final String ORIG_HEAD = "ORIG_HEAD";

  613.     /**
  614.      * Name of the file in which git commands and hooks store and read the
  615.      * message prepared for the upcoming commit.
  616.      *
  617.      * @since 4.0
  618.      */
  619.     public static final String COMMIT_EDITMSG = "COMMIT_EDITMSG";

  620.     /**
  621.      * Well-known object ID for the empty blob.
  622.      *
  623.      * @since 0.9.1
  624.      */
  625.     public static final ObjectId EMPTY_BLOB_ID = ObjectId
  626.             .fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");

  627.     /**
  628.      * Well-known object ID for the empty tree.
  629.      *
  630.      * @since 5.1
  631.      */
  632.     public static final ObjectId EMPTY_TREE_ID = ObjectId
  633.             .fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904");

  634.     /**
  635.      * Suffix of lock file name
  636.      *
  637.      * @since 4.7
  638.      */
  639.     public static final String LOCK_SUFFIX = ".lock"; //$NON-NLS-1$

  640.     /**
  641.      * Depth used to unshallow a repository
  642.      *
  643.      * @since 6.3
  644.      */
  645.     public static final int INFINITE_DEPTH = 0x7fffffff;

  646.     private Constants() {
  647.         // Hide the default constructor
  648.     }
  649. }