~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/NGit/NGit/Ref.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This code is derived from jgit (http://eclipse.org/jgit).
 
3
Copyright owners are documented in jgit's IP log.
 
4
 
 
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
 
9
 
 
10
All rights reserved.
 
11
 
 
12
Redistribution and use in source and binary forms, with or
 
13
without modification, are permitted provided that the following
 
14
conditions are met:
 
15
 
 
16
- Redistributions of source code must retain the above copyright
 
17
  notice, this list of conditions and the following disclaimer.
 
18
 
 
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.
 
23
 
 
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
 
27
  written permission.
 
28
 
 
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.
 
42
*/
 
43
 
 
44
using NGit;
 
45
using Sharpen;
 
46
 
 
47
namespace NGit
 
48
{
 
49
        /// <summary>
 
50
        /// Pairing of a name and the
 
51
        /// <see cref="ObjectId">ObjectId</see>
 
52
        /// it currently has.
 
53
        /// <p>
 
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, ...).
 
57
        /// <p>
 
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.
 
62
        /// </summary>
 
63
        public interface Ref
 
64
        {
 
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>
 
68
                string GetName();
 
69
 
 
70
                /// <summary>Test if this reference is a symbolic reference.</summary>
 
71
                /// <remarks>
 
72
                /// Test if this reference is a symbolic reference.
 
73
                /// <p>
 
74
                /// A symbolic reference does not have its own
 
75
                /// <see cref="ObjectId">ObjectId</see>
 
76
                /// value, but
 
77
                /// instead points to another
 
78
                /// <code>Ref</code>
 
79
                /// in the same database and always
 
80
                /// uses that other reference's value as its own.
 
81
                /// </remarks>
 
82
                /// <returns>
 
83
                /// true if this is a symbolic reference; false if this reference
 
84
                /// contains its own ObjectId.
 
85
                /// </returns>
 
86
                bool IsSymbolic();
 
87
 
 
88
                /// <summary>
 
89
                /// Traverse target references until
 
90
                /// <see cref="IsSymbolic()">IsSymbolic()</see>
 
91
                /// is false.
 
92
                /// <p>
 
93
                /// If
 
94
                /// <see cref="IsSymbolic()">IsSymbolic()</see>
 
95
                /// is false, returns
 
96
                /// <code>this</code>
 
97
                /// .
 
98
                /// <p>
 
99
                /// If
 
100
                /// <see cref="IsSymbolic()">IsSymbolic()</see>
 
101
                /// is true, this method recursively traverses
 
102
                /// <see cref="GetTarget()">GetTarget()</see>
 
103
                /// until
 
104
                /// <see cref="IsSymbolic()">IsSymbolic()</see>
 
105
                /// returns false.
 
106
                /// <p>
 
107
                /// This method is effectively
 
108
                /// <pre>
 
109
                /// return isSymbolic() ? getTarget().getLeaf() : this;
 
110
                /// </pre>
 
111
                /// </summary>
 
112
                /// <returns>the reference that actually stores the ObjectId value.</returns>
 
113
                Ref GetLeaf();
 
114
 
 
115
                /// <summary>
 
116
                /// Get the reference this reference points to, or
 
117
                /// <code>this</code>
 
118
                /// .
 
119
                /// <p>
 
120
                /// If
 
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.
 
125
                /// <p>
 
126
                /// If this is a leaf level reference that contains its own ObjectId,this
 
127
                /// method returns
 
128
                /// <code>this</code>
 
129
                /// .
 
130
                /// </summary>
 
131
                /// <returns>
 
132
                /// the target reference, or
 
133
                /// <code>this</code>
 
134
                /// .
 
135
                /// </returns>
 
136
                Ref GetTarget();
 
137
 
 
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();
 
142
 
 
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>
 
145
                /// <returns>
 
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.
 
149
                /// </returns>
 
150
                ObjectId GetPeeledObjectId();
 
151
 
 
152
                /// <returns>whether the Ref represents a peeled tag</returns>
 
153
                bool IsPeeled();
 
154
 
 
155
                /// <summary>
 
156
                /// How was this ref obtained?
 
157
                /// <p>
 
158
                /// The current storage model of a Ref may influence how the ref must be
 
159
                /// updated or deleted from the repository.
 
160
                /// </summary>
 
161
                /// <remarks>
 
162
                /// How was this ref obtained?
 
163
                /// <p>
 
164
                /// The current storage model of a Ref may influence how the ref must be
 
165
                /// updated or deleted from the repository.
 
166
                /// </remarks>
 
167
                /// <returns>type of ref.</returns>
 
168
                RefStorage GetStorage();
 
169
        }
 
170
 
 
171
        /// <summary>
 
172
        /// Location where a
 
173
        /// <see cref="Ref">Ref</see>
 
174
        /// is stored.
 
175
        /// </summary>
 
176
        public class RefStorage
 
177
        {
 
178
                /// <summary>The ref does not exist yet, updating it may create it.</summary>
 
179
                /// <remarks>
 
180
                /// The ref does not exist yet, updating it may create it.
 
181
                /// <p>
 
182
                /// Creation is likely to choose
 
183
                /// <see cref="LOOSE">LOOSE</see>
 
184
                /// storage.
 
185
                /// </remarks>
 
186
                public static RefStorage NEW = new RefStorage(true, false);
 
187
 
 
188
                /// <summary>The ref is stored in a file by itself.</summary>
 
189
                /// <remarks>
 
190
                /// The ref is stored in a file by itself.
 
191
                /// <p>
 
192
                /// Updating this ref affects only this ref.
 
193
                /// </remarks>
 
194
                public static RefStorage LOOSE = new RefStorage(true, false);
 
195
 
 
196
                /// <summary>The ref is stored in the <code>packed-refs</code> file, with others.</summary>
 
197
                /// <remarks>
 
198
                /// The ref is stored in the <code>packed-refs</code> file, with others.
 
199
                /// <p>
 
200
                /// Updating this ref requires rewriting the file, with perhaps many
 
201
                /// other refs being included at the same time.
 
202
                /// </remarks>
 
203
                public static RefStorage PACKED = new RefStorage(false, true);
 
204
 
 
205
                /// <summary>
 
206
                /// The ref is both
 
207
                /// <see cref="LOOSE">LOOSE</see>
 
208
                /// and
 
209
                /// <see cref="PACKED">PACKED</see>
 
210
                /// .
 
211
                /// <p>
 
212
                /// Updating this ref requires only updating the loose file, but deletion
 
213
                /// requires updating both the loose file and the packed refs file.
 
214
                /// </summary>
 
215
                public static RefStorage LOOSE_PACKED = new RefStorage(true, true);
 
216
 
 
217
                /// <summary>The ref came from a network advertisement and storage is unknown.</summary>
 
218
                /// <remarks>
 
219
                /// The ref came from a network advertisement and storage is unknown.
 
220
                /// <p>
 
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
 
223
                /// to this process.
 
224
                /// </remarks>
 
225
                public static RefStorage NETWORK = new RefStorage(false, false);
 
226
 
 
227
                private readonly bool loose;
 
228
 
 
229
                private readonly bool packed;
 
230
 
 
231
                private RefStorage(bool l, bool p)
 
232
                {
 
233
                        loose = l;
 
234
                        packed = p;
 
235
                }
 
236
 
 
237
                /// <returns>true if this storage has a loose file.</returns>
 
238
                public virtual bool IsLoose()
 
239
                {
 
240
                        return loose;
 
241
                }
 
242
 
 
243
                /// <returns>true if this storage is inside the packed file.</returns>
 
244
                public virtual bool IsPacked()
 
245
                {
 
246
                        return packed;
 
247
                }
 
248
        }
 
249
}