Switch jgit library to the EDL (3-clause BSD)
[jgit.git] / org.spearce.jgit / src / org / spearce / jgit / lib / Ref.java
blobb7e361fd49bbd21cd340f7bf5fcf8a7bc82ea1d1
1 /*
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
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
21 * written permission.
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;
40 /**
41 * Pairing of a name and the {@link ObjectId} it currently has.
42 * <p>
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, ...).
47 public class Ref {
48 private final String name;
50 private ObjectId objectId;
52 private ObjectId peeledObjectId;
54 /**
55 * Create a new ref pairing.
57 * @param refName
58 * name of this ref.
59 * @param id
60 * current value of the ref. May be null to indicate a ref that
61 * does not exist yet.
63 public Ref(final String refName, final ObjectId id) {
64 name = refName;
65 objectId = id;
68 /**
69 * Create a new ref pairing.
71 * @param refName
72 * name of this ref.
73 * @param id
74 * current value of the ref. May be null to indicate a ref that
75 * does not exist yet.
76 * @param peel
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) {
81 name = refName;
82 objectId = id;
83 peeledObjectId = peel;
86 /**
87 * What this ref is called within the repository.
89 * @return name of this ref.
91 public String getName() {
92 return name;
95 /**
96 * Cached value of this ref.
98 * @return the value of this ref at the last time we read it.
100 public ObjectId getObjectId() {
101 return objectId;
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() + "]";