aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackExt.java
blob: d5bb5f2e2fdf9be3877be538499a55a5bf72e999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (C) 2013, Google Inc. and others
 *
 * 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.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.eclipse.jgit.internal.storage.pack;

/**
 * A pack file extension.
 */
public enum PackExt {
	/** A pack file extension. */
	PACK("pack"), //$NON-NLS-1$

	/** A pack index file extension. */
	INDEX("idx"), //$NON-NLS-1$

	/** A keep pack file extension. */
	KEEP("keep"), //$NON-NLS-1$

	/** A pack bitmap index file extension. */
	BITMAP_INDEX("bitmap"), //$NON-NLS-1$

	/** A reftable file. */
	REFTABLE("ref"), //$NON-NLS-1$

	/** A pack reverse index file extension. */
	REVERSE_INDEX("rev"), //$NON-NLS-1$

	/** A commit graph file extension. */
	COMMIT_GRAPH("graph"), //$NON-NLS-1$

	/** An object size index. */
	OBJECT_SIZE_INDEX("objsize"), //$NON-NLS-1$

	/** Multi pack index */
	MULTI_PACK_INDEX("midx"); //$NON-NLS-1$

	private final String ext;

	private PackExt(String ext) {
		this.ext = ext;
	}

	/**
	 * Get the file extension.
	 *
	 * @return the file extension.
	 */
	public String getExtension() {
		return ext;
	}

	/**
	 * Get the position of the extension in the enum declaration.
	 *
	 * @return the position of the extension in the enum declaration.
	 */
	public int getPosition() {
		return ordinal();
	}

	/**
	 * Get the bit mask of the extension e.g {@code 1 << getPosition()}.
	 *
	 * @return the bit mask of the extension e.g {@code 1 << getPosition()}.
	 */
	public int getBit() {
		return 1 << getPosition();
	}

	/**
	 * Format a temporary file extension for this PackExt.
	 *
	 * @return a temporary file extension
	 */
	public String getTmpExtension() {
		return String.format(".%s_tmp", ext); //$NON-NLS-1$
	}

	@Override
	public String toString() {
		return String.format("PackExt[%s, bit=0x%s]", getExtension(), //$NON-NLS-1$
				Integer.toHexString(getBit()));
	}
}