2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
5
This program and the accompanying materials are made available
6
under the terms of the Eclipse Distribution License v1.0 which
7
accompanies this distribution, is reproduced below, and is
8
available at http://www.eclipse.org/org/documents/edl-v10.php
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
19
- Redistributions in binary form must reproduce the above
20
copyright notice, this list of conditions and the following
21
disclaimer in the documentation and/or other materials provided
22
with the distribution.
24
- Neither the name of the Eclipse Foundation, Inc. nor the
25
names of its contributors may be used to endorse or promote
26
products derived from this software without specific prior
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50
/// Pairing of a name and the
51
/// <see cref="ObjectId">ObjectId</see>
54
/// A ref in Git is (more or less) a variable that holds a single object
55
/// identifier. The object identifier can be any valid Git object (blob, tree,
56
/// commit, annotated tag, ...).
58
/// The ref name has the attributes of the ref that was asked for as well as the
59
/// ref it was resolved to for symbolic refs plus the object id it points to and
60
/// (for tags) the peeled target object id, i.e. the tag resolved recursively
61
/// until a non-tag object is referenced.
65
/// <summary>What this ref is called within the repository.</summary>
66
/// <remarks>What this ref is called within the repository.</remarks>
67
/// <returns>name of this ref.</returns>
70
/// <summary>Test if this reference is a symbolic reference.</summary>
72
/// Test if this reference is a symbolic reference.
74
/// A symbolic reference does not have its own
75
/// <see cref="ObjectId">ObjectId</see>
77
/// instead points to another
79
/// in the same database and always
80
/// uses that other reference's value as its own.
83
/// true if this is a symbolic reference; false if this reference
84
/// contains its own ObjectId.
89
/// Traverse target references until
90
/// <see cref="IsSymbolic()">IsSymbolic()</see>
94
/// <see cref="IsSymbolic()">IsSymbolic()</see>
100
/// <see cref="IsSymbolic()">IsSymbolic()</see>
101
/// is true, this method recursively traverses
102
/// <see cref="GetTarget()">GetTarget()</see>
104
/// <see cref="IsSymbolic()">IsSymbolic()</see>
107
/// This method is effectively
109
/// return isSymbolic() ? getTarget().getLeaf() : this;
112
/// <returns>the reference that actually stores the ObjectId value.</returns>
116
/// Get the reference this reference points to, or
117
/// <code>this</code>
121
/// <see cref="IsSymbolic()">IsSymbolic()</see>
122
/// is true this method returns the reference it
123
/// directly names, which might not be the leaf reference, but could be
124
/// another symbolic reference.
126
/// If this is a leaf level reference that contains its own ObjectId,this
128
/// <code>this</code>
132
/// the target reference, or
133
/// <code>this</code>
138
/// <summary>Cached value of this ref.</summary>
139
/// <remarks>Cached value of this ref.</remarks>
140
/// <returns>the value of this ref at the last time we read it.</returns>
141
ObjectId GetObjectId();
143
/// <summary>Cached value of <code>ref^{}</code> (the ref peeled to commit).</summary>
144
/// <remarks>Cached value of <code>ref^{}</code> (the ref peeled to commit).</remarks>
146
/// if this ref is an annotated tag the id of the commit (or tree or
147
/// blob) that the annotated tag refers to; null if this ref does not
148
/// refer to an annotated tag.
150
ObjectId GetPeeledObjectId();
152
/// <returns>whether the Ref represents a peeled tag</returns>
156
/// How was this ref obtained?
158
/// The current storage model of a Ref may influence how the ref must be
159
/// updated or deleted from the repository.
162
/// How was this ref obtained?
164
/// The current storage model of a Ref may influence how the ref must be
165
/// updated or deleted from the repository.
167
/// <returns>type of ref.</returns>
168
RefStorage GetStorage();
173
/// <see cref="Ref">Ref</see>
176
public class RefStorage
178
/// <summary>The ref does not exist yet, updating it may create it.</summary>
180
/// The ref does not exist yet, updating it may create it.
182
/// Creation is likely to choose
183
/// <see cref="LOOSE">LOOSE</see>
186
public static RefStorage NEW = new RefStorage(true, false);
188
/// <summary>The ref is stored in a file by itself.</summary>
190
/// The ref is stored in a file by itself.
192
/// Updating this ref affects only this ref.
194
public static RefStorage LOOSE = new RefStorage(true, false);
196
/// <summary>The ref is stored in the <code>packed-refs</code> file, with others.</summary>
198
/// The ref is stored in the <code>packed-refs</code> file, with others.
200
/// Updating this ref requires rewriting the file, with perhaps many
201
/// other refs being included at the same time.
203
public static RefStorage PACKED = new RefStorage(false, true);
207
/// <see cref="LOOSE">LOOSE</see>
209
/// <see cref="PACKED">PACKED</see>
212
/// Updating this ref requires only updating the loose file, but deletion
213
/// requires updating both the loose file and the packed refs file.
215
public static RefStorage LOOSE_PACKED = new RefStorage(true, true);
217
/// <summary>The ref came from a network advertisement and storage is unknown.</summary>
219
/// The ref came from a network advertisement and storage is unknown.
221
/// This ref cannot be updated without Git-aware support on the remote
222
/// side, as Git-aware code consolidate the remote refs and reported them
225
public static RefStorage NETWORK = new RefStorage(false, false);
227
private readonly bool loose;
229
private readonly bool packed;
231
private RefStorage(bool l, bool p)
237
/// <returns>true if this storage has a loose file.</returns>
238
public virtual bool IsLoose()
243
/// <returns>true if this storage is inside the packed file.</returns>
244
public virtual bool IsPacked()