View Javadoc
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  
46  package org.eclipse.jgit.lib;
47  
48  import static java.nio.charset.StandardCharsets.UTF_8;
49  
50  import java.nio.ByteBuffer;
51  import java.nio.charset.Charset;
52  import java.security.MessageDigest;
53  import java.security.NoSuchAlgorithmException;
54  import java.text.MessageFormat;
55  
56  import org.eclipse.jgit.errors.CorruptObjectException;
57  import org.eclipse.jgit.internal.JGitText;
58  import org.eclipse.jgit.util.MutableInteger;
59  
60  /**
61   * Misc. constants used throughout JGit.
62   */
63  @SuppressWarnings("nls")
64  public final class Constants {
65  	/** Hash function used natively by Git for all objects. */
66  	private static final String HASH_FUNCTION = "SHA-1";
67  
68  	/**
69  	 * A Git object hash is 160 bits, i.e. 20 bytes.
70  	 * <p>
71  	 * Changing this assumption is not going to be as easy as changing this
72  	 * declaration.
73  	 */
74  	public static final int OBJECT_ID_LENGTH = 20;
75  
76  	/**
77  	 * A Git object can be expressed as a 40 character string of hexadecimal
78  	 * digits.
79  	 *
80  	 * @see #OBJECT_ID_LENGTH
81  	 */
82  	public static final int OBJECT_ID_STRING_LENGTH = OBJECT_ID_LENGTH * 2;
83  
84  	/** Special name for the "HEAD" symbolic-ref. */
85  	public static final String HEAD = "HEAD";
86  
87  	/** Special name for the "FETCH_HEAD" symbolic-ref. */
88  	public static final String FETCH_HEAD = "FETCH_HEAD";
89  
90  	/**
91  	 * Text string that identifies an object as a commit.
92  	 * <p>
93  	 * Commits connect trees into a string of project histories, where each
94  	 * commit is an assertion that the best way to continue is to use this other
95  	 * tree (set of files).
96  	 */
97  	public static final String TYPE_COMMIT = "commit";
98  
99  	/**
100 	 * Text string that identifies an object as a blob.
101 	 * <p>
102 	 * Blobs store whole file revisions. They are used for any user file, as
103 	 * well as for symlinks. Blobs form the bulk of any project's storage space.
104 	 */
105 	public static final String TYPE_BLOB = "blob";
106 
107 	/**
108 	 * Text string that identifies an object as a tree.
109 	 * <p>
110 	 * Trees attach object ids (hashes) to names and file modes. The normal use
111 	 * for a tree is to store a version of a directory and its contents.
112 	 */
113 	public static final String TYPE_TREE = "tree";
114 
115 	/**
116 	 * Text string that identifies an object as an annotated tag.
117 	 * <p>
118 	 * Annotated tags store a pointer to any other object, and an additional
119 	 * message. It is most commonly used to record a stable release of the
120 	 * project.
121 	 */
122 	public static final String TYPE_TAG = "tag";
123 
124 	private static final byte[] ENCODED_TYPE_COMMIT = encodeASCII(TYPE_COMMIT);
125 
126 	private static final byte[] ENCODED_TYPE_BLOB = encodeASCII(TYPE_BLOB);
127 
128 	private static final byte[] ENCODED_TYPE_TREE = encodeASCII(TYPE_TREE);
129 
130 	private static final byte[] ENCODED_TYPE_TAG = encodeASCII(TYPE_TAG);
131 
132 	/** An unknown or invalid object type code. */
133 	public static final int OBJ_BAD = -1;
134 
135 	/**
136 	 * In-pack object type: extended types.
137 	 * <p>
138 	 * This header code is reserved for future expansion. It is currently
139 	 * undefined/unsupported.
140 	 */
141 	public static final int OBJ_EXT = 0;
142 
143 	/**
144 	 * In-pack object type: commit.
145 	 * <p>
146 	 * Indicates the associated object is a commit.
147 	 * <p>
148 	 * <b>This constant is fixed and is defined by the Git packfile format.</b>
149 	 *
150 	 * @see #TYPE_COMMIT
151 	 */
152 	public static final int OBJ_COMMIT = 1;
153 
154 	/**
155 	 * In-pack object type: tree.
156 	 * <p>
157 	 * Indicates the associated object is a tree.
158 	 * <p>
159 	 * <b>This constant is fixed and is defined by the Git packfile format.</b>
160 	 *
161 	 * @see #TYPE_BLOB
162 	 */
163 	public static final int OBJ_TREE = 2;
164 
165 	/**
166 	 * In-pack object type: blob.
167 	 * <p>
168 	 * Indicates the associated object is a blob.
169 	 * <p>
170 	 * <b>This constant is fixed and is defined by the Git packfile format.</b>
171 	 *
172 	 * @see #TYPE_BLOB
173 	 */
174 	public static final int OBJ_BLOB = 3;
175 
176 	/**
177 	 * In-pack object type: annotated tag.
178 	 * <p>
179 	 * Indicates the associated object is an annotated tag.
180 	 * <p>
181 	 * <b>This constant is fixed and is defined by the Git packfile format.</b>
182 	 *
183 	 * @see #TYPE_TAG
184 	 */
185 	public static final int OBJ_TAG = 4;
186 
187 	/** In-pack object type: reserved for future use. */
188 	public static final int OBJ_TYPE_5 = 5;
189 
190 	/**
191 	 * In-pack object type: offset delta
192 	 * <p>
193 	 * Objects stored with this type actually have a different type which must
194 	 * be obtained from their delta base object. Delta objects store only the
195 	 * changes needed to apply to the base object in order to recover the
196 	 * original object.
197 	 * <p>
198 	 * An offset delta uses a negative offset from the start of this object to
199 	 * refer to its delta base. The base object must exist in this packfile
200 	 * (even in the case of a thin pack).
201 	 * <p>
202 	 * <b>This constant is fixed and is defined by the Git packfile format.</b>
203 	 */
204 	public static final int OBJ_OFS_DELTA = 6;
205 
206 	/**
207 	 * In-pack object type: reference delta
208 	 * <p>
209 	 * Objects stored with this type actually have a different type which must
210 	 * be obtained from their delta base object. Delta objects store only the
211 	 * changes needed to apply to the base object in order to recover the
212 	 * original object.
213 	 * <p>
214 	 * A reference delta uses a full object id (hash) to reference the delta
215 	 * base. The base object is allowed to be omitted from the packfile, but
216 	 * only in the case of a thin pack being transferred over the network.
217 	 * <p>
218 	 * <b>This constant is fixed and is defined by the Git packfile format.</b>
219 	 */
220 	public static final int OBJ_REF_DELTA = 7;
221 
222 	/**
223 	 * Pack file signature that occurs at file header - identifies file as Git
224 	 * packfile formatted.
225 	 * <p>
226 	 * <b>This constant is fixed and is defined by the Git packfile format.</b>
227 	 */
228 	public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' };
229 
230 	/**
231 	 * Native character encoding for commit messages, file names...
232 	 *
233 	 * @deprecated Use {@link java.nio.charset.StandardCharsets#UTF_8} directly
234 	 *             instead.
235 	 **/
236 	@Deprecated
237 	public static final Charset CHARSET;
238 
239 	/** Native character encoding for commit messages, file names... */
240 	public static final String CHARACTER_ENCODING;
241 
242 	/** Default main branch name */
243 	public static final String MASTER = "master";
244 
245 	/** Default stash branch name */
246 	public static final String STASH = "stash";
247 
248 	/** Prefix for branch refs */
249 	public static final String R_HEADS = "refs/heads/";
250 
251 	/** Prefix for remotes refs */
252 	public static final String R_REMOTES = "refs/remotes/";
253 
254 	/** Prefix for tag refs */
255 	public static final String R_TAGS = "refs/tags/";
256 
257 	/** Prefix for notes refs */
258 	public static final String R_NOTES = "refs/notes/";
259 
260 	/** Standard notes ref */
261 	public static final String R_NOTES_COMMITS = R_NOTES + "commits";
262 
263 	/** Prefix for any ref */
264 	public static final String R_REFS = "refs/";
265 
266 	/** Standard stash ref */
267 	public static final String R_STASH = R_REFS + STASH;
268 
269 	/** Logs folder name */
270 	public static final String LOGS = "logs";
271 
272 	/** Info refs folder */
273 	public static final String INFO_REFS = "info/refs";
274 
275 	/** Packed refs file */
276 	public static final String PACKED_REFS = "packed-refs";
277 
278 	/**
279 	 * Excludes-file
280 	 *
281 	 * @since 3.0
282 	 */
283 	public static final String INFO_EXCLUDE = "info/exclude";
284 
285 	/**
286 	 * Attributes-override-file
287 	 *
288 	 * @since 4.2
289 	 */
290 	public static final String INFO_ATTRIBUTES = "info/attributes";
291 
292 	/**
293 	 * The system property that contains the system user name
294 	 *
295 	 * @since 3.6
296 	 */
297 	public static final String OS_USER_DIR = "user.dir";
298 
299 	/** The system property that contains the system user name */
300 	public static final String OS_USER_NAME_KEY = "user.name";
301 
302 	/** The environment variable that contains the author's name */
303 	public static final String GIT_AUTHOR_NAME_KEY = "GIT_AUTHOR_NAME";
304 
305 	/** The environment variable that contains the author's email */
306 	public static final String GIT_AUTHOR_EMAIL_KEY = "GIT_AUTHOR_EMAIL";
307 
308 	/** The environment variable that contains the commiter's name */
309 	public static final String GIT_COMMITTER_NAME_KEY = "GIT_COMMITTER_NAME";
310 
311 	/** The environment variable that contains the commiter's email */
312 	public static final String GIT_COMMITTER_EMAIL_KEY = "GIT_COMMITTER_EMAIL";
313 
314 	/**
315 	 * The environment variable that blocks use of the system config file
316 	 *
317 	 * @since 3.3
318 	 */
319 	public static final String GIT_CONFIG_NOSYSTEM_KEY = "GIT_CONFIG_NOSYSTEM";
320 
321 	/**
322 	 * The environment variable that limits how close to the root of the file
323 	 * systems JGit will traverse when looking for a repository root.
324 	 */
325 	public static final String GIT_CEILING_DIRECTORIES_KEY = "GIT_CEILING_DIRECTORIES";
326 
327 	/**
328 	 * The environment variable that tells us which directory is the ".git"
329 	 * directory
330 	 */
331 	public static final String GIT_DIR_KEY = "GIT_DIR";
332 
333 	/**
334 	 * The environment variable that tells us which directory is the working
335 	 * directory.
336 	 */
337 	public static final String GIT_WORK_TREE_KEY = "GIT_WORK_TREE";
338 
339 	/**
340 	 * The environment variable that tells us which file holds the Git index.
341 	 */
342 	public static final String GIT_INDEX_FILE_KEY = "GIT_INDEX_FILE";
343 
344 	/**
345 	 * The environment variable that tells us where objects are stored
346 	 */
347 	public static final String GIT_OBJECT_DIRECTORY_KEY = "GIT_OBJECT_DIRECTORY";
348 
349 	/**
350 	 * The environment variable that tells us where to look for objects, besides
351 	 * the default objects directory.
352 	 */
353 	public static final String GIT_ALTERNATE_OBJECT_DIRECTORIES_KEY = "GIT_ALTERNATE_OBJECT_DIRECTORIES";
354 
355 	/** Default value for the user name if no other information is available */
356 	public static final String UNKNOWN_USER_DEFAULT = "unknown-user";
357 
358 	/** Beginning of the common "Signed-off-by: " commit message line */
359 	public static final String SIGNED_OFF_BY_TAG = "Signed-off-by: ";
360 
361 	/** A gitignore file name */
362 	public static final String GITIGNORE_FILENAME = ".gitignore";
363 
364 	/** Default remote name used by clone, push and fetch operations */
365 	public static final String DEFAULT_REMOTE_NAME = "origin";
366 
367 	/** Default name for the Git repository directory */
368 	public static final String DOT_GIT = ".git";
369 
370 	/** Default name for the Git repository configuration */
371 	public static final String CONFIG = "config";
372 
373 	/** A bare repository typically ends with this string */
374 	public static final String DOT_GIT_EXT = ".git";
375 
376 	/**
377 	 * Name of the attributes file
378 	 *
379 	 * @since 3.7
380 	 */
381 	public static final String DOT_GIT_ATTRIBUTES = ".gitattributes";
382 
383 	/**
384 	 * Key for filters in .gitattributes
385 	 *
386 	 * @since 4.2
387 	 */
388 	public static final String ATTR_FILTER = "filter";
389 
390 	/**
391 	 * clean command name, used to call filter driver
392 	 *
393 	 * @since 4.2
394 	 */
395 	public static final String ATTR_FILTER_TYPE_CLEAN = "clean";
396 
397 	/**
398 	 * smudge command name, used to call filter driver
399 	 *
400 	 * @since 4.2
401 	 */
402 	public static final String ATTR_FILTER_TYPE_SMUDGE = "smudge";
403 
404 	/**
405 	 * Builtin filter commands start with this prefix
406 	 *
407 	 * @since 4.6
408 	 */
409 	public static final String BUILTIN_FILTER_PREFIX = "jgit://builtin/";
410 
411 	/** Name of the ignore file */
412 	public static final String DOT_GIT_IGNORE = ".gitignore";
413 
414 	/** Name of the submodules file */
415 	public static final String DOT_GIT_MODULES = ".gitmodules";
416 
417 	/** Name of the .git/shallow file */
418 	public static final String SHALLOW = "shallow";
419 
420 	/**
421 	 * Prefix of the first line in a ".git" file
422 	 *
423 	 * @since 3.6
424 	 */
425 	public static final String GITDIR = "gitdir: ";
426 
427 	/**
428 	 * Name of the folder (inside gitDir) where submodules are stored
429 	 *
430 	 * @since 3.6
431 	 */
432 	public static final String MODULES = "modules";
433 
434 	/**
435 	 * Name of the folder (inside gitDir) where the hooks are stored.
436 	 *
437 	 * @since 3.7
438 	 */
439 	public static final String HOOKS = "hooks";
440 
441 	/**
442 	 * Merge attribute.
443 	 *
444 	 * @since 4.9
445 	 */
446 	public static final String ATTR_MERGE = "merge"; //$NON-NLS-1$
447 
448 	/**
449 	 * Diff attribute.
450 	 *
451 	 * @since 4.11
452 	 */
453 	public static final String ATTR_DIFF = "diff"; //$NON-NLS-1$
454 
455 	/**
456 	 * Binary value for custom merger.
457 	 *
458 	 * @since 4.9
459 	 */
460 	public static final String ATTR_BUILTIN_BINARY_MERGER = "binary"; //$NON-NLS-1$
461 
462 	/**
463 	 * Create a new digest function for objects.
464 	 *
465 	 * @return a new digest object.
466 	 * @throws java.lang.RuntimeException
467 	 *             this Java virtual machine does not support the required hash
468 	 *             function. Very unlikely given that JGit uses a hash function
469 	 *             that is in the Java reference specification.
470 	 */
471 	public static MessageDigest newMessageDigest() {
472 		try {
473 			return MessageDigest.getInstance(HASH_FUNCTION);
474 		} catch (NoSuchAlgorithmException nsae) {
475 			throw new RuntimeException(MessageFormat.format(
476 					JGitText.get().requiredHashFunctionNotAvailable, HASH_FUNCTION), nsae);
477 		}
478 	}
479 
480 	/**
481 	 * Convert an OBJ_* type constant to a TYPE_* type constant.
482 	 *
483 	 * @param typeCode the type code, from a pack representation.
484 	 * @return the canonical string name of this type.
485 	 */
486 	public static String typeString(int typeCode) {
487 		switch (typeCode) {
488 		case OBJ_COMMIT:
489 			return TYPE_COMMIT;
490 		case OBJ_TREE:
491 			return TYPE_TREE;
492 		case OBJ_BLOB:
493 			return TYPE_BLOB;
494 		case OBJ_TAG:
495 			return TYPE_TAG;
496 		default:
497 			throw new IllegalArgumentException(MessageFormat.format(
498 					JGitText.get().badObjectType, Integer.valueOf(typeCode)));
499 		}
500 	}
501 
502 	/**
503 	 * Convert an OBJ_* type constant to an ASCII encoded string constant.
504 	 * <p>
505 	 * The ASCII encoded string is often the canonical representation of
506 	 * the type within a loose object header, or within a tag header.
507 	 *
508 	 * @param typeCode the type code, from a pack representation.
509 	 * @return the canonical ASCII encoded name of this type.
510 	 */
511 	public static byte[] encodedTypeString(int typeCode) {
512 		switch (typeCode) {
513 		case OBJ_COMMIT:
514 			return ENCODED_TYPE_COMMIT;
515 		case OBJ_TREE:
516 			return ENCODED_TYPE_TREE;
517 		case OBJ_BLOB:
518 			return ENCODED_TYPE_BLOB;
519 		case OBJ_TAG:
520 			return ENCODED_TYPE_TAG;
521 		default:
522 			throw new IllegalArgumentException(MessageFormat.format(
523 					JGitText.get().badObjectType, Integer.valueOf(typeCode)));
524 		}
525 	}
526 
527 	/**
528 	 * Parse an encoded type string into a type constant.
529 	 *
530 	 * @param id
531 	 *            object id this type string came from; may be null if that is
532 	 *            not known at the time the parse is occurring.
533 	 * @param typeString
534 	 *            string version of the type code.
535 	 * @param endMark
536 	 *            character immediately following the type string. Usually ' '
537 	 *            (space) or '\n' (line feed).
538 	 * @param offset
539 	 *            position within <code>typeString</code> where the parse
540 	 *            should start. Updated with the new position (just past
541 	 *            <code>endMark</code> when the parse is successful.
542 	 * @return a type code constant (one of {@link #OBJ_BLOB},
543 	 *         {@link #OBJ_COMMIT}, {@link #OBJ_TAG}, {@link #OBJ_TREE}.
544 	 * @throws org.eclipse.jgit.errors.CorruptObjectException
545 	 *             there is no valid type identified by <code>typeString</code>.
546 	 */
547 	public static int decodeTypeString(final AnyObjectId id,
548 			final byte[] typeString, final byte endMark,
549 			final MutableInteger offset) throws CorruptObjectException {
550 		try {
551 			int position = offset.value;
552 			switch (typeString[position]) {
553 			case 'b':
554 				if (typeString[position + 1] != 'l'
555 						|| typeString[position + 2] != 'o'
556 						|| typeString[position + 3] != 'b'
557 						|| typeString[position + 4] != endMark)
558 					throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
559 				offset.value = position + 5;
560 				return Constants.OBJ_BLOB;
561 
562 			case 'c':
563 				if (typeString[position + 1] != 'o'
564 						|| typeString[position + 2] != 'm'
565 						|| typeString[position + 3] != 'm'
566 						|| typeString[position + 4] != 'i'
567 						|| typeString[position + 5] != 't'
568 						|| typeString[position + 6] != endMark)
569 					throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
570 				offset.value = position + 7;
571 				return Constants.OBJ_COMMIT;
572 
573 			case 't':
574 				switch (typeString[position + 1]) {
575 				case 'a':
576 					if (typeString[position + 2] != 'g'
577 							|| typeString[position + 3] != endMark)
578 						throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
579 					offset.value = position + 4;
580 					return Constants.OBJ_TAG;
581 
582 				case 'r':
583 					if (typeString[position + 2] != 'e'
584 							|| typeString[position + 3] != 'e'
585 							|| typeString[position + 4] != endMark)
586 						throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
587 					offset.value = position + 5;
588 					return Constants.OBJ_TREE;
589 
590 				default:
591 					throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
592 				}
593 
594 			default:
595 				throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
596 			}
597 		} catch (ArrayIndexOutOfBoundsException bad) {
598 			throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
599 		}
600 	}
601 
602 	/**
603 	 * Convert an integer into its decimal representation.
604 	 *
605 	 * @param s
606 	 *            the integer to convert.
607 	 * @return a decimal representation of the input integer. The returned array
608 	 *         is the smallest array that will hold the value.
609 	 */
610 	public static byte[] encodeASCII(long s) {
611 		return encodeASCII(Long.toString(s));
612 	}
613 
614 	/**
615 	 * Convert a string to US-ASCII encoding.
616 	 *
617 	 * @param s
618 	 *            the string to convert. Must not contain any characters over
619 	 *            127 (outside of 7-bit ASCII).
620 	 * @return a byte array of the same length as the input string, holding the
621 	 *         same characters, in the same order.
622 	 * @throws java.lang.IllegalArgumentException
623 	 *             the input string contains one or more characters outside of
624 	 *             the 7-bit ASCII character space.
625 	 */
626 	public static byte[] encodeASCII(String s) {
627 		final byte[] r = new byte[s.length()];
628 		for (int k = r.length - 1; k >= 0; k--) {
629 			final char c = s.charAt(k);
630 			if (c > 127)
631 				throw new IllegalArgumentException(MessageFormat.format(JGitText.get().notASCIIString, s));
632 			r[k] = (byte) c;
633 		}
634 		return r;
635 	}
636 
637 	/**
638 	 * Convert a string to a byte array in the standard character encoding.
639 	 *
640 	 * @param str
641 	 *            the string to convert. May contain any Unicode characters.
642 	 * @return a byte array representing the requested string, encoded using the
643 	 *         default character encoding (UTF-8).
644 	 * @see #CHARACTER_ENCODING
645 	 */
646 	public static byte[] encode(String str) {
647 		final ByteBuffer bb = UTF_8.encode(str);
648 		final int len = bb.limit();
649 		if (bb.hasArray() && bb.arrayOffset() == 0) {
650 			final byte[] arr = bb.array();
651 			if (arr.length == len)
652 				return arr;
653 		}
654 
655 		final byte[] arr = new byte[len];
656 		bb.get(arr);
657 		return arr;
658 	}
659 
660 	static {
661 		if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength())
662 			throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH);
663 		CHARSET = UTF_8;
664 		CHARACTER_ENCODING = UTF_8.name();
665 	}
666 
667 	/** name of the file containing the commit msg for a merge commit */
668 	public static final String MERGE_MSG = "MERGE_MSG";
669 
670 	/** name of the file containing the IDs of the parents of a merge commit */
671 	public static final String MERGE_HEAD = "MERGE_HEAD";
672 
673 	/** name of the file containing the ID of a cherry pick commit in case of conflicts */
674 	public static final String CHERRY_PICK_HEAD = "CHERRY_PICK_HEAD";
675 
676 	/** name of the file containing the commit msg for a squash commit */
677 	public static final String SQUASH_MSG = "SQUASH_MSG";
678 
679 	/** name of the file containing the ID of a revert commit in case of conflicts */
680 	public static final String REVERT_HEAD = "REVERT_HEAD";
681 
682 	/**
683 	 * name of the ref ORIG_HEAD used by certain commands to store the original
684 	 * value of HEAD
685 	 */
686 	public static final String ORIG_HEAD = "ORIG_HEAD";
687 
688 	/**
689 	 * Name of the file in which git commands and hooks store and read the
690 	 * message prepared for the upcoming commit.
691 	 *
692 	 * @since 4.0
693 	 */
694 	public static final String COMMIT_EDITMSG = "COMMIT_EDITMSG";
695 
696 	/**
697 	 * Well-known object ID for the empty blob.
698 	 *
699 	 * @since 0.9.1
700 	 */
701 	public static final ObjectId EMPTY_BLOB_ID = ObjectId
702 			.fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
703 
704 	/**
705 	 * Well-known object ID for the empty tree.
706 	 *
707 	 * @since 5.1
708 	 */
709 	public static final ObjectId EMPTY_TREE_ID = ObjectId
710 			.fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904");
711 
712 	/**
713 	 * Suffix of lock file name
714 	 *
715 	 * @since 4.7
716 	 */
717 	public static final String LOCK_SUFFIX = ".lock"; //$NON-NLS-1$
718 
719 	private Constants() {
720 		// Hide the default constructor
721 	}
722 }