~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ngit/NGit/NGit.Transport/ReceiveCommand.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
using System.IO;
46
46
using NGit;
47
47
using NGit.Internal;
 
48
using NGit.Revwalk;
48
49
using NGit.Transport;
49
50
using Sharpen;
50
51
 
52
53
{
53
54
        /// <summary>
54
55
        /// A command being processed by
55
 
        /// <see cref="ReceivePack">ReceivePack</see>
 
56
        /// <see cref="BaseReceivePack">BaseReceivePack</see>
56
57
        /// .
57
58
        /// <p>
58
59
        /// This command instance roughly translates to the server side representation of
92
93
                /// <param name="commands">commands to filter.</param>
93
94
                /// <param name="want">desired status to filter by.</param>
94
95
                /// <returns>
95
 
                /// a copy of the command list containing only those commands with the
96
 
                /// desired status.
 
96
                /// a copy of the command list containing only those commands with
 
97
                /// the desired status.
97
98
                /// </returns>
 
99
                /// <since>2.0</since>
98
100
                public static IList<NGit.Transport.ReceiveCommand> Filter(IList<NGit.Transport.ReceiveCommand
99
101
                        > commands, ReceiveCommand.Result want)
100
102
                {
124
126
 
125
127
                private string message;
126
128
 
 
129
                private bool typeIsCorrect;
 
130
 
127
131
                /// <summary>
128
132
                /// Create a new command for
129
 
                /// <see cref="ReceivePack">ReceivePack</see>
 
133
                /// <see cref="BaseReceivePack">BaseReceivePack</see>
130
134
                /// .
131
135
                /// </summary>
132
136
                /// <param name="oldId">
159
163
 
160
164
                /// <summary>
161
165
                /// Create a new command for
162
 
                /// <see cref="ReceivePack">ReceivePack</see>
 
166
                /// <see cref="BaseReceivePack">BaseReceivePack</see>
163
167
                /// .
164
168
                /// </summary>
165
169
                /// <param name="oldId">
174
178
                /// </param>
175
179
                /// <param name="name">name of the ref being affected.</param>
176
180
                /// <param name="type">type of the command.</param>
 
181
                /// <since>2.0</since>
177
182
                public ReceiveCommand(ObjectId oldId, ObjectId newId, string name, ReceiveCommand.Type
178
183
                         type)
179
184
                {
247
252
                        message = m;
248
253
                }
249
254
 
 
255
                /// <summary>Update the type of this command by checking for fast-forward.</summary>
 
256
                /// <remarks>
 
257
                /// Update the type of this command by checking for fast-forward.
 
258
                /// <p>
 
259
                /// If the command's current type is UPDATE, a merge test will be performed
 
260
                /// using the supplied RevWalk to determine if
 
261
                /// <see cref="GetOldId()">GetOldId()</see>
 
262
                /// is fully
 
263
                /// merged into
 
264
                /// <see cref="GetNewId()">GetNewId()</see>
 
265
                /// . If some commits are not merged the
 
266
                /// update type is changed to
 
267
                /// <see cref="Type.UPDATE_NONFASTFORWARD">Type.UPDATE_NONFASTFORWARD</see>
 
268
                /// .
 
269
                /// </remarks>
 
270
                /// <param name="walk">
 
271
                /// an instance to perform the merge test with. The caller must
 
272
                /// allocate and release this object.
 
273
                /// </param>
 
274
                /// <exception cref="System.IO.IOException">
 
275
                /// either oldId or newId is not accessible in the repository
 
276
                /// used by the RevWalk. This usually indicates data corruption,
 
277
                /// and the command cannot be processed.
 
278
                /// </exception>
 
279
                public virtual void UpdateType(RevWalk walk)
 
280
                {
 
281
                        if (typeIsCorrect)
 
282
                        {
 
283
                                return;
 
284
                        }
 
285
                        if (type == ReceiveCommand.Type.UPDATE && !AnyObjectId.Equals(oldId, newId))
 
286
                        {
 
287
                                RevObject o = walk.ParseAny(oldId);
 
288
                                RevObject n = walk.ParseAny(newId);
 
289
                                if (!(o is RevCommit) || !(n is RevCommit) || !walk.IsMergedInto((RevCommit)o, (RevCommit
 
290
                                        )n))
 
291
                                {
 
292
                                        SetType(ReceiveCommand.Type.UPDATE_NONFASTFORWARD);
 
293
                                }
 
294
                        }
 
295
                        typeIsCorrect = true;
 
296
                }
 
297
 
250
298
                /// <summary>Execute this command during a receive-pack session.</summary>
251
299
                /// <remarks>
252
300
                /// Execute this command during a receive-pack session.
254
302
                /// Sets the status of the command as a side effect.
255
303
                /// </remarks>
256
304
                /// <param name="rp">receive-pack session.</param>
257
 
                public virtual void Execute(ReceivePack rp)
 
305
                /// <since>2.0</since>
 
306
                public virtual void Execute(BaseReceivePack rp)
258
307
                {
259
308
                        try
260
309
                        {
292
341
                        }
293
342
                        catch (IOException err)
294
343
                        {
295
 
                                SetResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, MessageFormat.Format(JGitText
296
 
                                        .Get().lockError, err.Message));
 
344
                                Reject(err);
297
345
                        }
298
346
                }
299
347
 
307
355
                        type = t;
308
356
                }
309
357
 
310
 
                private void SetResult(RefUpdate.Result r)
 
358
                internal virtual void SetTypeFastForwardUpdate()
 
359
                {
 
360
                        type = ReceiveCommand.Type.UPDATE;
 
361
                        typeIsCorrect = true;
 
362
                }
 
363
 
 
364
                /// <summary>Set the result of this command.</summary>
 
365
                /// <remarks>Set the result of this command.</remarks>
 
366
                /// <param name="r">the new result code for this command.</param>
 
367
                public virtual void SetResult(RefUpdate.Result r)
311
368
                {
312
369
                        switch (r)
313
370
                        {
354
411
                        }
355
412
                }
356
413
 
 
414
                internal virtual void Reject(IOException err)
 
415
                {
 
416
                        SetResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, MessageFormat.Format(JGitText
 
417
                                .Get().lockError, err.Message));
 
418
                }
 
419
 
357
420
                public override string ToString()
358
421
                {
359
422
                        return GetType().ToString() + ": " + GetOldId().Name + " " + GetNewId().Name + " "