2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org
.spearce
.jgit
.lib
;
41 * Pairing of a name and the {@link ObjectId} it currently has.
43 * A ref in Git is (more or less) a variable that holds a single object
44 * identifier. The object identifier can be any valid Git object (blob, tree,
45 * commit, annotated tag, ...).
48 /** Location where a {@link Ref} is stored. */
49 public static enum Storage
{
51 * The ref does not exist yet, updating it may create it.
53 * Creation is likely to choose {@link #LOOSE} storage.
58 * The ref is stored in a file by itself.
60 * Updating this ref affects only this ref.
65 * The ref is stored in the <code>packed-refs</code> file, with
68 * Updating this ref requires rewriting the file, with perhaps many
69 * other refs being included at the same time.
74 * The ref is both {@link #LOOSE} and {@link #PACKED}.
76 * Updating this ref requires only updating the loose file, but deletion
77 * requires updating both the loose file and the packed refs file.
79 LOOSE_PACKED(true, true),
82 * The ref came from a network advertisement and storage is unknown.
84 * This ref cannot be updated without Git-aware support on the remote
85 * side, as Git-aware code consolidate the remote refs and reported them
88 NETWORK(false, false);
90 private final boolean loose
;
92 private final boolean packed
;
94 private Storage(final boolean l
, final boolean p
) {
100 * @return true if this storage has a loose file.
102 public boolean isLoose() {
107 * @return true if this storage is inside the packed file.
109 public boolean isPacked() {
114 private final Storage storage
;
116 private final String name
;
118 private ObjectId objectId
;
120 private ObjectId peeledObjectId
;
123 * Create a new ref pairing.
126 * method used to store this ref.
130 * current value of the ref. May be null to indicate a ref that
131 * does not exist yet.
133 public Ref(final Storage st
, final String refName
, final ObjectId id
) {
140 * Create a new ref pairing.
143 * method used to store this ref.
147 * current value of the ref. May be null to indicate a ref that
148 * does not exist yet.
150 * peeled value of the ref's tag. May be null if this is not a
151 * tag or the peeled value is not known.
153 public Ref(final Storage st
, final String refName
, final ObjectId id
,
154 final ObjectId peel
) {
158 peeledObjectId
= peel
;
162 * What this ref is called within the repository.
164 * @return name of this ref.
166 public String
getName() {
171 * Cached value of this ref.
173 * @return the value of this ref at the last time we read it.
175 public ObjectId
getObjectId() {
180 * Cached value of <code>ref^{}</code> (the ref peeled to commit).
182 * @return if this ref is an annotated tag the id of the commit (or tree or
183 * blob) that the annotated tag refers to; null if this ref does not
184 * refer to an annotated tag.
186 public ObjectId
getPeeledObjectId() {
187 return peeledObjectId
;
191 * How was this ref obtained?
193 * The current storage model of a Ref may influence how the ref must be
194 * updated or deleted from the repository.
196 * @return type of ref.
198 public Storage
getStorage() {
202 public String
toString() {
203 return "Ref[" + name
+ "=" + ObjectId
.toString(getObjectId()) + "]";