You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Constants.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * Copyright (C) 2008, Google Inc.
  3. * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
  4. * Copyright (C) 2006-2017, Shawn O. Pearce <spearce@spearce.org>
  5. * and other copyright owners as documented in the project's IP log.
  6. *
  7. * This program and the accompanying materials are made available
  8. * under the terms of the Eclipse Distribution License v1.0 which
  9. * accompanies this distribution, is reproduced below, and is
  10. * available at http://www.eclipse.org/org/documents/edl-v10.php
  11. *
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or
  15. * without modification, are permitted provided that the following
  16. * conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * - Neither the name of the Eclipse Foundation, Inc. nor the
  27. * names of its contributors may be used to endorse or promote
  28. * products derived from this software without specific prior
  29. * written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  32. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  33. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  34. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  36. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  37. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  38. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  39. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  40. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  41. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  43. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. */
  45. package org.eclipse.jgit.lib;
  46. import java.nio.ByteBuffer;
  47. import java.nio.charset.Charset;
  48. import java.security.MessageDigest;
  49. import java.security.NoSuchAlgorithmException;
  50. import java.text.MessageFormat;
  51. import org.eclipse.jgit.errors.CorruptObjectException;
  52. import org.eclipse.jgit.internal.JGitText;
  53. import org.eclipse.jgit.util.MutableInteger;
  54. /** Misc. constants used throughout JGit. */
  55. @SuppressWarnings("nls")
  56. public final class Constants {
  57. /** Hash function used natively by Git for all objects. */
  58. private static final String HASH_FUNCTION = "SHA-1";
  59. /**
  60. * A Git object hash is 160 bits, i.e. 20 bytes.
  61. * <p>
  62. * Changing this assumption is not going to be as easy as changing this
  63. * declaration.
  64. */
  65. public static final int OBJECT_ID_LENGTH = 20;
  66. /**
  67. * A Git object can be expressed as a 40 character string of hexadecimal
  68. * digits.
  69. *
  70. * @see #OBJECT_ID_LENGTH
  71. */
  72. public static final int OBJECT_ID_STRING_LENGTH = OBJECT_ID_LENGTH * 2;
  73. /** Special name for the "HEAD" symbolic-ref. */
  74. public static final String HEAD = "HEAD";
  75. /** Special name for the "FETCH_HEAD" symbolic-ref. */
  76. public static final String FETCH_HEAD = "FETCH_HEAD";
  77. /**
  78. * Text string that identifies an object as a commit.
  79. * <p>
  80. * Commits connect trees into a string of project histories, where each
  81. * commit is an assertion that the best way to continue is to use this other
  82. * tree (set of files).
  83. */
  84. public static final String TYPE_COMMIT = "commit";
  85. /**
  86. * Text string that identifies an object as a blob.
  87. * <p>
  88. * Blobs store whole file revisions. They are used for any user file, as
  89. * well as for symlinks. Blobs form the bulk of any project's storage space.
  90. */
  91. public static final String TYPE_BLOB = "blob";
  92. /**
  93. * Text string that identifies an object as a tree.
  94. * <p>
  95. * Trees attach object ids (hashes) to names and file modes. The normal use
  96. * for a tree is to store a version of a directory and its contents.
  97. */
  98. public static final String TYPE_TREE = "tree";
  99. /**
  100. * Text string that identifies an object as an annotated tag.
  101. * <p>
  102. * Annotated tags store a pointer to any other object, and an additional
  103. * message. It is most commonly used to record a stable release of the
  104. * project.
  105. */
  106. public static final String TYPE_TAG = "tag";
  107. private static final byte[] ENCODED_TYPE_COMMIT = encodeASCII(TYPE_COMMIT);
  108. private static final byte[] ENCODED_TYPE_BLOB = encodeASCII(TYPE_BLOB);
  109. private static final byte[] ENCODED_TYPE_TREE = encodeASCII(TYPE_TREE);
  110. private static final byte[] ENCODED_TYPE_TAG = encodeASCII(TYPE_TAG);
  111. /** An unknown or invalid object type code. */
  112. public static final int OBJ_BAD = -1;
  113. /**
  114. * In-pack object type: extended types.
  115. * <p>
  116. * This header code is reserved for future expansion. It is currently
  117. * undefined/unsupported.
  118. */
  119. public static final int OBJ_EXT = 0;
  120. /**
  121. * In-pack object type: commit.
  122. * <p>
  123. * Indicates the associated object is a commit.
  124. * <p>
  125. * <b>This constant is fixed and is defined by the Git packfile format.</b>
  126. *
  127. * @see #TYPE_COMMIT
  128. */
  129. public static final int OBJ_COMMIT = 1;
  130. /**
  131. * In-pack object type: tree.
  132. * <p>
  133. * Indicates the associated object is a tree.
  134. * <p>
  135. * <b>This constant is fixed and is defined by the Git packfile format.</b>
  136. *
  137. * @see #TYPE_BLOB
  138. */
  139. public static final int OBJ_TREE = 2;
  140. /**
  141. * In-pack object type: blob.
  142. * <p>
  143. * Indicates the associated object is a blob.
  144. * <p>
  145. * <b>This constant is fixed and is defined by the Git packfile format.</b>
  146. *
  147. * @see #TYPE_BLOB
  148. */
  149. public static final int OBJ_BLOB = 3;
  150. /**
  151. * In-pack object type: annotated tag.
  152. * <p>
  153. * Indicates the associated object is an annotated tag.
  154. * <p>
  155. * <b>This constant is fixed and is defined by the Git packfile format.</b>
  156. *
  157. * @see #TYPE_TAG
  158. */
  159. public static final int OBJ_TAG = 4;
  160. /** In-pack object type: reserved for future use. */
  161. public static final int OBJ_TYPE_5 = 5;
  162. /**
  163. * In-pack object type: offset delta
  164. * <p>
  165. * Objects stored with this type actually have a different type which must
  166. * be obtained from their delta base object. Delta objects store only the
  167. * changes needed to apply to the base object in order to recover the
  168. * original object.
  169. * <p>
  170. * An offset delta uses a negative offset from the start of this object to
  171. * refer to its delta base. The base object must exist in this packfile
  172. * (even in the case of a thin pack).
  173. * <p>
  174. * <b>This constant is fixed and is defined by the Git packfile format.</b>
  175. */
  176. public static final int OBJ_OFS_DELTA = 6;
  177. /**
  178. * In-pack object type: reference delta
  179. * <p>
  180. * Objects stored with this type actually have a different type which must
  181. * be obtained from their delta base object. Delta objects store only the
  182. * changes needed to apply to the base object in order to recover the
  183. * original object.
  184. * <p>
  185. * A reference delta uses a full object id (hash) to reference the delta
  186. * base. The base object is allowed to be omitted from the packfile, but
  187. * only in the case of a thin pack being transferred over the network.
  188. * <p>
  189. * <b>This constant is fixed and is defined by the Git packfile format.</b>
  190. */
  191. public static final int OBJ_REF_DELTA = 7;
  192. /**
  193. * Pack file signature that occurs at file header - identifies file as Git
  194. * packfile formatted.
  195. * <p>
  196. * <b>This constant is fixed and is defined by the Git packfile format.</b>
  197. */
  198. public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' };
  199. /** Native character encoding for commit messages, file names... */
  200. public static final String CHARACTER_ENCODING = "UTF-8";
  201. /** Native character encoding for commit messages, file names... */
  202. public static final Charset CHARSET;
  203. /** Default main branch name */
  204. public static final String MASTER = "master";
  205. /** Default stash branch name */
  206. public static final String STASH = "stash";
  207. /** Prefix for branch refs */
  208. public static final String R_HEADS = "refs/heads/";
  209. /** Prefix for remotes refs */
  210. public static final String R_REMOTES = "refs/remotes/";
  211. /** Prefix for tag refs */
  212. public static final String R_TAGS = "refs/tags/";
  213. /** Prefix for notes refs */
  214. public static final String R_NOTES = "refs/notes/";
  215. /** Standard notes ref */
  216. public static final String R_NOTES_COMMITS = R_NOTES + "commits";
  217. /** Prefix for any ref */
  218. public static final String R_REFS = "refs/";
  219. /** Standard stash ref */
  220. public static final String R_STASH = R_REFS + STASH;
  221. /** Logs folder name */
  222. public static final String LOGS = "logs";
  223. /** Info refs folder */
  224. public static final String INFO_REFS = "info/refs";
  225. /** Packed refs file */
  226. public static final String PACKED_REFS = "packed-refs";
  227. /**
  228. * Excludes-file
  229. *
  230. * @since 3.0
  231. */
  232. public static final String INFO_EXCLUDE = "info/exclude";
  233. /**
  234. * Attributes-override-file
  235. *
  236. * @since 4.2
  237. */
  238. public static final String INFO_ATTRIBUTES = "info/attributes";
  239. /**
  240. * The system property that contains the system user name
  241. *
  242. * @since 3.6
  243. */
  244. public static final String OS_USER_DIR = "user.dir";
  245. /** The system property that contains the system user name */
  246. public static final String OS_USER_NAME_KEY = "user.name";
  247. /** The environment variable that contains the author's name */
  248. public static final String GIT_AUTHOR_NAME_KEY = "GIT_AUTHOR_NAME";
  249. /** The environment variable that contains the author's email */
  250. public static final String GIT_AUTHOR_EMAIL_KEY = "GIT_AUTHOR_EMAIL";
  251. /** The environment variable that contains the commiter's name */
  252. public static final String GIT_COMMITTER_NAME_KEY = "GIT_COMMITTER_NAME";
  253. /** The environment variable that contains the commiter's email */
  254. public static final String GIT_COMMITTER_EMAIL_KEY = "GIT_COMMITTER_EMAIL";
  255. /**
  256. * The environment variable that blocks use of the system config file
  257. *
  258. * @since 3.3
  259. */
  260. public static final String GIT_CONFIG_NOSYSTEM_KEY = "GIT_CONFIG_NOSYSTEM";
  261. /**
  262. * The environment variable that limits how close to the root of the file
  263. * systems JGit will traverse when looking for a repository root.
  264. */
  265. public static final String GIT_CEILING_DIRECTORIES_KEY = "GIT_CEILING_DIRECTORIES";
  266. /**
  267. * The environment variable that tells us which directory is the ".git"
  268. * directory
  269. */
  270. public static final String GIT_DIR_KEY = "GIT_DIR";
  271. /**
  272. * The environment variable that tells us which directory is the working
  273. * directory.
  274. */
  275. public static final String GIT_WORK_TREE_KEY = "GIT_WORK_TREE";
  276. /**
  277. * The environment variable that tells us which file holds the Git index.
  278. */
  279. public static final String GIT_INDEX_FILE_KEY = "GIT_INDEX_FILE";
  280. /**
  281. * The environment variable that tells us where objects are stored
  282. */
  283. public static final String GIT_OBJECT_DIRECTORY_KEY = "GIT_OBJECT_DIRECTORY";
  284. /**
  285. * The environment variable that tells us where to look for objects, besides
  286. * the default objects directory.
  287. */
  288. public static final String GIT_ALTERNATE_OBJECT_DIRECTORIES_KEY = "GIT_ALTERNATE_OBJECT_DIRECTORIES";
  289. /** Default value for the user name if no other information is available */
  290. public static final String UNKNOWN_USER_DEFAULT = "unknown-user";
  291. /** Beginning of the common "Signed-off-by: " commit message line */
  292. public static final String SIGNED_OFF_BY_TAG = "Signed-off-by: ";
  293. /** A gitignore file name */
  294. public static final String GITIGNORE_FILENAME = ".gitignore";
  295. /** Default remote name used by clone, push and fetch operations */
  296. public static final String DEFAULT_REMOTE_NAME = "origin";
  297. /** Default name for the Git repository directory */
  298. public static final String DOT_GIT = ".git";
  299. /** Default name for the Git repository configuration */
  300. public static final String CONFIG = "config";
  301. /** A bare repository typically ends with this string */
  302. public static final String DOT_GIT_EXT = ".git";
  303. /**
  304. * Name of the attributes file
  305. *
  306. * @since 3.7
  307. */
  308. public static final String DOT_GIT_ATTRIBUTES = ".gitattributes";
  309. /**
  310. * Key for filters in .gitattributes
  311. *
  312. * @since 4.2
  313. */
  314. public static final String ATTR_FILTER = "filter";
  315. /**
  316. * clean command name, used to call filter driver
  317. *
  318. * @since 4.2
  319. */
  320. public static final String ATTR_FILTER_TYPE_CLEAN = "clean";
  321. /**
  322. * smudge command name, used to call filter driver
  323. *
  324. * @since 4.2
  325. */
  326. public static final String ATTR_FILTER_TYPE_SMUDGE = "smudge";
  327. /**
  328. * Builtin filter commands start with this prefix
  329. *
  330. * @since 4.6
  331. */
  332. public static final String BUILTIN_FILTER_PREFIX = "jgit://builtin/";
  333. /** Name of the ignore file */
  334. public static final String DOT_GIT_IGNORE = ".gitignore";
  335. /** Name of the submodules file */
  336. public static final String DOT_GIT_MODULES = ".gitmodules";
  337. /** Name of the .git/shallow file */
  338. public static final String SHALLOW = "shallow";
  339. /**
  340. * Prefix of the first line in a ".git" file
  341. *
  342. * @since 3.6
  343. */
  344. public static final String GITDIR = "gitdir: ";
  345. /**
  346. * Name of the folder (inside gitDir) where submodules are stored
  347. *
  348. * @since 3.6
  349. */
  350. public static final String MODULES = "modules";
  351. /**
  352. * Name of the folder (inside gitDir) where the hooks are stored.
  353. *
  354. * @since 3.7
  355. */
  356. public static final String HOOKS = "hooks";
  357. /**
  358. * Merge attribute.
  359. *
  360. * @since 4.9
  361. */
  362. public static final String ATTR_MERGE = "merge"; //$NON-NLS-1$
  363. /**
  364. * Binary value for custom merger.
  365. *
  366. * @since 4.9
  367. */
  368. public static final String ATTR_BUILTIN_BINARY_MERGER = "binary"; //$NON-NLS-1$
  369. /**
  370. * Create a new digest function for objects.
  371. *
  372. * @return a new digest object.
  373. * @throws RuntimeException
  374. * this Java virtual machine does not support the required hash
  375. * function. Very unlikely given that JGit uses a hash function
  376. * that is in the Java reference specification.
  377. */
  378. public static MessageDigest newMessageDigest() {
  379. try {
  380. return MessageDigest.getInstance(HASH_FUNCTION);
  381. } catch (NoSuchAlgorithmException nsae) {
  382. throw new RuntimeException(MessageFormat.format(
  383. JGitText.get().requiredHashFunctionNotAvailable, HASH_FUNCTION), nsae);
  384. }
  385. }
  386. /**
  387. * Convert an OBJ_* type constant to a TYPE_* type constant.
  388. *
  389. * @param typeCode the type code, from a pack representation.
  390. * @return the canonical string name of this type.
  391. */
  392. public static String typeString(final int typeCode) {
  393. switch (typeCode) {
  394. case OBJ_COMMIT:
  395. return TYPE_COMMIT;
  396. case OBJ_TREE:
  397. return TYPE_TREE;
  398. case OBJ_BLOB:
  399. return TYPE_BLOB;
  400. case OBJ_TAG:
  401. return TYPE_TAG;
  402. default:
  403. throw new IllegalArgumentException(MessageFormat.format(
  404. JGitText.get().badObjectType, Integer.valueOf(typeCode)));
  405. }
  406. }
  407. /**
  408. * Convert an OBJ_* type constant to an ASCII encoded string constant.
  409. * <p>
  410. * The ASCII encoded string is often the canonical representation of
  411. * the type within a loose object header, or within a tag header.
  412. *
  413. * @param typeCode the type code, from a pack representation.
  414. * @return the canonical ASCII encoded name of this type.
  415. */
  416. public static byte[] encodedTypeString(final int typeCode) {
  417. switch (typeCode) {
  418. case OBJ_COMMIT:
  419. return ENCODED_TYPE_COMMIT;
  420. case OBJ_TREE:
  421. return ENCODED_TYPE_TREE;
  422. case OBJ_BLOB:
  423. return ENCODED_TYPE_BLOB;
  424. case OBJ_TAG:
  425. return ENCODED_TYPE_TAG;
  426. default:
  427. throw new IllegalArgumentException(MessageFormat.format(
  428. JGitText.get().badObjectType, Integer.valueOf(typeCode)));
  429. }
  430. }
  431. /**
  432. * Parse an encoded type string into a type constant.
  433. *
  434. * @param id
  435. * object id this type string came from; may be null if that is
  436. * not known at the time the parse is occurring.
  437. * @param typeString
  438. * string version of the type code.
  439. * @param endMark
  440. * character immediately following the type string. Usually ' '
  441. * (space) or '\n' (line feed).
  442. * @param offset
  443. * position within <code>typeString</code> where the parse
  444. * should start. Updated with the new position (just past
  445. * <code>endMark</code> when the parse is successful.
  446. * @return a type code constant (one of {@link #OBJ_BLOB},
  447. * {@link #OBJ_COMMIT}, {@link #OBJ_TAG}, {@link #OBJ_TREE}.
  448. * @throws CorruptObjectException
  449. * there is no valid type identified by <code>typeString</code>.
  450. */
  451. public static int decodeTypeString(final AnyObjectId id,
  452. final byte[] typeString, final byte endMark,
  453. final MutableInteger offset) throws CorruptObjectException {
  454. try {
  455. int position = offset.value;
  456. switch (typeString[position]) {
  457. case 'b':
  458. if (typeString[position + 1] != 'l'
  459. || typeString[position + 2] != 'o'
  460. || typeString[position + 3] != 'b'
  461. || typeString[position + 4] != endMark)
  462. throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  463. offset.value = position + 5;
  464. return Constants.OBJ_BLOB;
  465. case 'c':
  466. if (typeString[position + 1] != 'o'
  467. || typeString[position + 2] != 'm'
  468. || typeString[position + 3] != 'm'
  469. || typeString[position + 4] != 'i'
  470. || typeString[position + 5] != 't'
  471. || typeString[position + 6] != endMark)
  472. throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  473. offset.value = position + 7;
  474. return Constants.OBJ_COMMIT;
  475. case 't':
  476. switch (typeString[position + 1]) {
  477. case 'a':
  478. if (typeString[position + 2] != 'g'
  479. || typeString[position + 3] != endMark)
  480. throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  481. offset.value = position + 4;
  482. return Constants.OBJ_TAG;
  483. case 'r':
  484. if (typeString[position + 2] != 'e'
  485. || typeString[position + 3] != 'e'
  486. || typeString[position + 4] != endMark)
  487. throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  488. offset.value = position + 5;
  489. return Constants.OBJ_TREE;
  490. default:
  491. throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  492. }
  493. default:
  494. throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  495. }
  496. } catch (ArrayIndexOutOfBoundsException bad) {
  497. throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
  498. }
  499. }
  500. /**
  501. * Convert an integer into its decimal representation.
  502. *
  503. * @param s
  504. * the integer to convert.
  505. * @return a decimal representation of the input integer. The returned array
  506. * is the smallest array that will hold the value.
  507. */
  508. public static byte[] encodeASCII(final long s) {
  509. return encodeASCII(Long.toString(s));
  510. }
  511. /**
  512. * Convert a string to US-ASCII encoding.
  513. *
  514. * @param s
  515. * the string to convert. Must not contain any characters over
  516. * 127 (outside of 7-bit ASCII).
  517. * @return a byte array of the same length as the input string, holding the
  518. * same characters, in the same order.
  519. * @throws IllegalArgumentException
  520. * the input string contains one or more characters outside of
  521. * the 7-bit ASCII character space.
  522. */
  523. public static byte[] encodeASCII(final String s) {
  524. final byte[] r = new byte[s.length()];
  525. for (int k = r.length - 1; k >= 0; k--) {
  526. final char c = s.charAt(k);
  527. if (c > 127)
  528. throw new IllegalArgumentException(MessageFormat.format(JGitText.get().notASCIIString, s));
  529. r[k] = (byte) c;
  530. }
  531. return r;
  532. }
  533. /**
  534. * Convert a string to a byte array in the standard character encoding.
  535. *
  536. * @param str
  537. * the string to convert. May contain any Unicode characters.
  538. * @return a byte array representing the requested string, encoded using the
  539. * default character encoding (UTF-8).
  540. * @see #CHARACTER_ENCODING
  541. */
  542. public static byte[] encode(final String str) {
  543. final ByteBuffer bb = Constants.CHARSET.encode(str);
  544. final int len = bb.limit();
  545. if (bb.hasArray() && bb.arrayOffset() == 0) {
  546. final byte[] arr = bb.array();
  547. if (arr.length == len)
  548. return arr;
  549. }
  550. final byte[] arr = new byte[len];
  551. bb.get(arr);
  552. return arr;
  553. }
  554. static {
  555. if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength())
  556. throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH);
  557. CHARSET = Charset.forName(CHARACTER_ENCODING);
  558. }
  559. /** name of the file containing the commit msg for a merge commit */
  560. public static final String MERGE_MSG = "MERGE_MSG";
  561. /** name of the file containing the IDs of the parents of a merge commit */
  562. public static final String MERGE_HEAD = "MERGE_HEAD";
  563. /** name of the file containing the ID of a cherry pick commit in case of conflicts */
  564. public static final String CHERRY_PICK_HEAD = "CHERRY_PICK_HEAD";
  565. /** name of the file containing the commit msg for a squash commit */
  566. public static final String SQUASH_MSG = "SQUASH_MSG";
  567. /** name of the file containing the ID of a revert commit in case of conflicts */
  568. public static final String REVERT_HEAD = "REVERT_HEAD";
  569. /**
  570. * name of the ref ORIG_HEAD used by certain commands to store the original
  571. * value of HEAD
  572. */
  573. public static final String ORIG_HEAD = "ORIG_HEAD";
  574. /**
  575. * Name of the file in which git commands and hooks store and read the
  576. * message prepared for the upcoming commit.
  577. *
  578. * @since 4.0
  579. */
  580. public static final String COMMIT_EDITMSG = "COMMIT_EDITMSG";
  581. /** objectid for the empty blob */
  582. public static final ObjectId EMPTY_BLOB_ID = ObjectId
  583. .fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
  584. private Constants() {
  585. // Hide the default constructor
  586. }
  587. }