1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 package org.eclipse.jgit.transport;
47
48 import org.eclipse.jgit.lib.AnyObjectId;
49 import org.eclipse.jgit.lib.ObjectId;
50 import org.eclipse.jgit.lib.RefUpdate;
51
52
53
54
55 public class TrackingRefUpdate {
56 private final String remoteName;
57 final String localName;
58 boolean forceUpdate;
59 ObjectId oldObjectId;
60 ObjectId newObjectId;
61
62 private RefUpdate.Result result;
63 private ReceiveCommand cmd;
64
65 TrackingRefUpdate(
66 boolean canForceUpdate,
67 String remoteName,
68 String localName,
69 AnyObjectId oldValue,
70 AnyObjectId newValue) {
71 this.remoteName = remoteName;
72 this.localName = localName;
73 this.forceUpdate = canForceUpdate;
74 this.oldObjectId = oldValue.copy();
75 this.newObjectId = newValue.copy();
76 }
77
78
79
80
81
82
83
84
85 public String getRemoteName() {
86 return remoteName;
87 }
88
89
90
91
92
93
94
95
96 public String getLocalName() {
97 return localName;
98 }
99
100
101
102
103
104
105 public ObjectId getNewObjectId() {
106 return newObjectId;
107 }
108
109
110
111
112
113
114
115
116
117
118
119 public ObjectId getOldObjectId() {
120 return oldObjectId;
121 }
122
123
124
125
126
127
128 public RefUpdate.Result getResult() {
129 return result;
130 }
131
132 void setResult(RefUpdate.Result result) {
133 this.result = result;
134 }
135
136
137
138
139
140
141
142 public ReceiveCommand asReceiveCommand() {
143 if (cmd == null)
144 cmd = new Command();
145 return cmd;
146 }
147
148 final class Command extends ReceiveCommand {
149 Command() {
150 super(oldObjectId, newObjectId, localName);
151 }
152
153 boolean canForceUpdate() {
154 return forceUpdate;
155 }
156
157 @Override
158 public void setResult(RefUpdate.Result status) {
159 result = status;
160 super.setResult(status);
161 }
162
163 @Override
164 public void setResult(ReceiveCommand.Result status) {
165 result = decode(status);
166 super.setResult(status);
167 }
168
169 @Override
170 public void setResult(ReceiveCommand.Result status, String msg) {
171 result = decode(status);
172 super.setResult(status, msg);
173 }
174
175 private RefUpdate.Result decode(ReceiveCommand.Result status) {
176 switch (status) {
177 case OK:
178 if (AnyObjectId.equals(oldObjectId, newObjectId))
179 return RefUpdate.Result.NO_CHANGE;
180 switch (getType()) {
181 case CREATE:
182 return RefUpdate.Result.NEW;
183 case UPDATE:
184 return RefUpdate.Result.FAST_FORWARD;
185 case DELETE:
186 case UPDATE_NONFASTFORWARD:
187 default:
188 return RefUpdate.Result.FORCED;
189 }
190
191 case REJECTED_NOCREATE:
192 case REJECTED_NODELETE:
193 case REJECTED_NONFASTFORWARD:
194 return RefUpdate.Result.REJECTED;
195 case REJECTED_CURRENT_BRANCH:
196 return RefUpdate.Result.REJECTED_CURRENT_BRANCH;
197 case REJECTED_MISSING_OBJECT:
198 return RefUpdate.Result.IO_FAILURE;
199 case LOCK_FAILURE:
200 case NOT_ATTEMPTED:
201 case REJECTED_OTHER_REASON:
202 default:
203 return RefUpdate.Result.LOCK_FAILURE;
204 }
205 }
206 }
207
208
209 @SuppressWarnings("nls")
210 @Override
211 public String toString() {
212 StringBuilder sb = new StringBuilder();
213 sb.append("TrackingRefUpdate[");
214 sb.append(remoteName);
215 sb.append(" -> ");
216 sb.append(localName);
217 if (forceUpdate)
218 sb.append(" (forced)");
219 sb.append(" ");
220 sb.append(oldObjectId == null ? "" : oldObjectId.abbreviate(7).name());
221 sb.append("..");
222 sb.append(newObjectId == null ? "" : newObjectId.abbreviate(7).name());
223 sb.append("]");
224 return sb.toString();
225 }
226 }