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 private final String name
;
50 private ObjectId objectId
;
52 private ObjectId peeledObjectId
;
55 * Create a new ref pairing.
60 * current value of the ref. May be null to indicate a ref that
63 public Ref(final String refName
, final ObjectId id
) {
69 * Create a new ref pairing.
74 * current value of the ref. May be null to indicate a ref that
77 * peeled value of the ref's tag. May be null if this is not a
78 * tag or the peeled value is not known.
80 public Ref(final String refName
, final ObjectId id
, final ObjectId peel
) {
83 peeledObjectId
= peel
;
87 * What this ref is called within the repository.
89 * @return name of this ref.
91 public String
getName() {
96 * Cached value of this ref.
98 * @return the value of this ref at the last time we read it.
100 public ObjectId
getObjectId() {
105 * Cached value of <code>ref^{}</code> (the ref peeled to commit).
107 * @return if this ref is an annotated tag the id of the commit (or tree or
108 * blob) that the annotated tag refers to; null if this ref does not
109 * refer to an annotated tag.
111 public ObjectId
getPeeledObjectId() {
112 return peeledObjectId
;
115 public String
toString() {
116 return "Ref[" + name
+ "=" + getObjectId() + "]";