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 public class TrackingRefUpdate {
54 private final String remoteName;
55 final String localName;
56 boolean forceUpdate;
57 ObjectId oldObjectId;
58 ObjectId newObjectId;
59
60 private RefUpdate.Result result;
61 private ReceiveCommand cmd;
62
63 TrackingRefUpdate(
64 boolean canForceUpdate,
65 String remoteName,
66 String localName,
67 AnyObjectId oldValue,
68 AnyObjectId newValue) {
69 this.remoteName = remoteName;
70 this.localName = localName;
71 this.forceUpdate = canForceUpdate;
72 this.oldObjectId = oldValue.copy();
73 this.newObjectId = newValue.copy();
74 }
75
76
77
78
79
80
81
82
83 public String getRemoteName() {
84 return remoteName;
85 }
86
87
88
89
90
91
92
93
94 public String getLocalName() {
95 return localName;
96 }
97
98
99
100
101
102
103 public ObjectId getNewObjectId() {
104 return newObjectId;
105 }
106
107
108
109
110
111
112
113
114
115
116
117 public ObjectId getOldObjectId() {
118 return oldObjectId;
119 }
120
121
122
123
124
125
126 public RefUpdate.Result getResult() {
127 return result;
128 }
129
130 void setResult(RefUpdate.Result result) {
131 this.result = result;
132 }
133
134
135
136
137
138 public ReceiveCommand asReceiveCommand() {
139 if (cmd == null)
140 cmd = new Command();
141 return cmd;
142 }
143
144 final class Command extends ReceiveCommand {
145 Command() {
146 super(oldObjectId, newObjectId, localName);
147 }
148
149 boolean canForceUpdate() {
150 return forceUpdate;
151 }
152
153 @Override
154 public void setResult(RefUpdate.Result status) {
155 result = status;
156 super.setResult(status);
157 }
158
159 @Override
160 public void setResult(ReceiveCommand.Result status) {
161 result = decode(status);
162 super.setResult(status);
163 }
164
165 @Override
166 public void setResult(ReceiveCommand.Result status, String msg) {
167 result = decode(status);
168 super.setResult(status, msg);
169 }
170
171 private RefUpdate.Result decode(ReceiveCommand.Result status) {
172 switch (status) {
173 case OK:
174 if (AnyObjectId.equals(oldObjectId, newObjectId))
175 return RefUpdate.Result.NO_CHANGE;
176 switch (getType()) {
177 case CREATE:
178 return RefUpdate.Result.NEW;
179 case UPDATE:
180 return RefUpdate.Result.FAST_FORWARD;
181 case DELETE:
182 case UPDATE_NONFASTFORWARD:
183 default:
184 return RefUpdate.Result.FORCED;
185 }
186
187 case REJECTED_NOCREATE:
188 case REJECTED_NODELETE:
189 case REJECTED_NONFASTFORWARD:
190 return RefUpdate.Result.REJECTED;
191 case REJECTED_CURRENT_BRANCH:
192 return RefUpdate.Result.REJECTED_CURRENT_BRANCH;
193 case REJECTED_MISSING_OBJECT:
194 return RefUpdate.Result.IO_FAILURE;
195 case LOCK_FAILURE:
196 case NOT_ATTEMPTED:
197 case REJECTED_OTHER_REASON:
198 default:
199 return RefUpdate.Result.LOCK_FAILURE;
200 }
201 }
202 }
203
204 @SuppressWarnings("nls")
205 @Override
206 public String toString() {
207 StringBuilder sb = new StringBuilder();
208 sb.append("TrackingRefUpdate[");
209 sb.append(remoteName);
210 sb.append(" -> ");
211 sb.append(localName);
212 if (forceUpdate)
213 sb.append(" (forced)");
214 sb.append(" ");
215 sb.append(oldObjectId == null ? "" : oldObjectId.abbreviate(7).name());
216 sb.append("..");
217 sb.append(newObjectId == null ? "" : newObjectId.abbreviate(7).name());
218 sb.append("]");
219 return sb.toString();
220 }
221 }