1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.lib;
13
14 import org.eclipse.jgit.annotations.NonNull;
15 import org.eclipse.jgit.annotations.Nullable;
16
17
18
19
20
21 public abstract class ObjectIdRef implements Ref {
22
23 public static class Unpeeled extends ObjectIdRef {
24
25
26
27
28
29
30
31
32
33
34
35 public Unpeeled(@NonNull Storage st, @NonNull String name,
36 @Nullable ObjectId id) {
37 super(st, name, id, UNDEFINED_UPDATE_INDEX);
38 }
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public Unpeeled(@NonNull Storage st, @NonNull String name,
55 @Nullable ObjectId id, long updateIndex) {
56 super(st, name, id, updateIndex);
57 }
58
59 @Override
60 @Nullable
61 public ObjectId getPeeledObjectId() {
62 return null;
63 }
64
65 @Override
66 public boolean isPeeled() {
67 return false;
68 }
69 }
70
71
72 public static class PeeledTag extends ObjectIdRef {
73 private final ObjectId peeledObjectId;
74
75
76
77
78
79
80
81
82
83
84
85
86
87 public PeeledTag(@NonNull Storage st, @NonNull String name,
88 @Nullable ObjectId/../../org/eclipse/jgit/lib/ObjectId.html#ObjectId">ObjectId id, @NonNull ObjectId p) {
89 super(st, name, id, UNDEFINED_UPDATE_INDEX);
90 peeledObjectId = p;
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 public PeeledTag(@NonNull Storage st, @NonNull String name,
110 @Nullable ObjectId/../../org/eclipse/jgit/lib/ObjectId.html#ObjectId">ObjectId id, @NonNull ObjectId p, long updateIndex) {
111 super(st, name, id, updateIndex);
112 peeledObjectId = p;
113 }
114
115 @Override
116 @NonNull
117 public ObjectId getPeeledObjectId() {
118 return peeledObjectId;
119 }
120
121 @Override
122 public boolean isPeeled() {
123 return true;
124 }
125 }
126
127
128 public static class PeeledNonTag extends ObjectIdRef {
129
130
131
132
133
134
135
136
137
138
139
140 public PeeledNonTag(@NonNull Storage st, @NonNull String name,
141 @Nullable ObjectId id) {
142 super(st, name, id, UNDEFINED_UPDATE_INDEX);
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 public PeeledNonTag(@NonNull Storage st, @NonNull String name,
160 @Nullable ObjectId id, long updateIndex) {
161 super(st, name, id, updateIndex);
162 }
163
164 @Override
165 @Nullable
166 public ObjectId getPeeledObjectId() {
167 return null;
168 }
169
170 @Override
171 public boolean isPeeled() {
172 return true;
173 }
174 }
175
176 private final String name;
177
178 private final Storage storage;
179
180 private final ObjectId objectId;
181
182 private final long updateIndex;
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 protected ObjectIdRef(@NonNull Storage st, @NonNull String name,
200 @Nullable ObjectId id, long updateIndex) {
201 this.name = name;
202 this.storage = st;
203 this.objectId = id;
204 this.updateIndex = updateIndex;
205 }
206
207
208 @Override
209 @NonNull
210 public String getName() {
211 return name;
212 }
213
214
215 @Override
216 public boolean isSymbolic() {
217 return false;
218 }
219
220
221 @Override
222 @NonNull
223 public Ref getLeaf() {
224 return this;
225 }
226
227
228 @Override
229 @NonNull
230 public Ref getTarget() {
231 return this;
232 }
233
234
235 @Override
236 @Nullable
237 public ObjectId getObjectId() {
238 return objectId;
239 }
240
241
242 @Override
243 @NonNull
244 public Storage getStorage() {
245 return storage;
246 }
247
248
249
250
251
252 @Override
253 public long getUpdateIndex() {
254 if (updateIndex == UNDEFINED_UPDATE_INDEX) {
255 throw new UnsupportedOperationException();
256 }
257 return updateIndex;
258 }
259
260
261 @NonNull
262 @Override
263 public String toString() {
264 StringBuilder r = new StringBuilder();
265 r.append("Ref[");
266 r.append(getName());
267 r.append('=');
268 r.append(ObjectId.toString(getObjectId()));
269 r.append('(');
270 r.append(updateIndex);
271 r.append(")]");
272 return r.toString();
273 }
274 }