~ubuntu-branches/ubuntu/saucy/monodevelop/saucy

« back to all changes in this revision

Viewing changes to external/ngit/NGit/NGit.Revwalk.Filter/RevFilter.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2012-05-27 18:08:20 UTC
  • mfrom: (1.8.5) (1.5.8 sid)
  • Revision ID: package-import@ubuntu.com-20120527180820-f1ub6lhg0s50wci1
Tags: 3.0.2+dfsg-3
* [fcecfe7] Fix monodevelop-core-addins.pc.in to point to actual 
  installed location of assemblies.
* [26e1a07] DebSrc 3.0 does not support Quilt's -p parameter, so 
  manually adjust the path in the patch file.

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 System;
 
45
using NGit.Internal;
 
46
using NGit.Revwalk;
 
47
using NGit.Revwalk.Filter;
 
48
using Sharpen;
 
49
 
 
50
namespace NGit.Revwalk.Filter
 
51
{
 
52
        /// <summary>Selects interesting revisions during walking.</summary>
 
53
        /// <remarks>
 
54
        /// Selects interesting revisions during walking.
 
55
        /// <p>
 
56
        /// This is an abstract interface. Applications may implement a subclass, or use
 
57
        /// one of the predefined implementations already available within this package.
 
58
        /// Filters may be chained together using <code>AndRevFilter</code> and
 
59
        /// <code>OrRevFilter</code> to create complex boolean expressions.
 
60
        /// <p>
 
61
        /// Applications should install the filter on a RevWalk by
 
62
        /// <see cref="NGit.Revwalk.RevWalk.SetRevFilter(RevFilter)">NGit.Revwalk.RevWalk.SetRevFilter(RevFilter)
 
63
        ///     </see>
 
64
        /// prior to starting traversal.
 
65
        /// <p>
 
66
        /// Unless specifically noted otherwise a RevFilter implementation is not thread
 
67
        /// safe and may not be shared by different RevWalk instances at the same time.
 
68
        /// This restriction allows RevFilter implementations to cache state within their
 
69
        /// instances during
 
70
        /// <see cref="Include(NGit.Revwalk.RevWalk, NGit.Revwalk.RevCommit)">Include(NGit.Revwalk.RevWalk, NGit.Revwalk.RevCommit)
 
71
        ///     </see>
 
72
        /// if it is beneficial to
 
73
        /// their implementation. Deep clones created by
 
74
        /// <see cref="Clone()">Clone()</see>
 
75
        /// may be used to
 
76
        /// construct a thread-safe copy of an existing filter.
 
77
        /// <p>
 
78
        /// <b>Message filters:</b>
 
79
        /// <ul>
 
80
        /// <li>Author name/email:
 
81
        /// <see cref="AuthorRevFilter">AuthorRevFilter</see>
 
82
        /// </li>
 
83
        /// <li>Committer name/email:
 
84
        /// <see cref="CommitterRevFilter">CommitterRevFilter</see>
 
85
        /// </li>
 
86
        /// <li>Message body:
 
87
        /// <see cref="MessageRevFilter">MessageRevFilter</see>
 
88
        /// </li>
 
89
        /// </ul>
 
90
        /// <p>
 
91
        /// <b>Merge filters:</b>
 
92
        /// <ul>
 
93
        /// <li>Skip all merges:
 
94
        /// <see cref="NO_MERGES">NO_MERGES</see>
 
95
        /// .</li>
 
96
        /// </ul>
 
97
        /// <p>
 
98
        /// <b>Boolean modifiers:</b>
 
99
        /// <ul>
 
100
        /// <li>AND:
 
101
        /// <see cref="AndRevFilter">AndRevFilter</see>
 
102
        /// </li>
 
103
        /// <li>OR:
 
104
        /// <see cref="OrRevFilter">OrRevFilter</see>
 
105
        /// </li>
 
106
        /// <li>NOT:
 
107
        /// <see cref="NotRevFilter">NotRevFilter</see>
 
108
        /// </li>
 
109
        /// </ul>
 
110
        /// </remarks>
 
111
        public abstract class RevFilter
 
112
        {
 
113
                /// <summary>Default filter that always returns true (thread safe).</summary>
 
114
                /// <remarks>Default filter that always returns true (thread safe).</remarks>
 
115
                public static readonly RevFilter ALL = new RevFilter.AllFilter();
 
116
 
 
117
                private sealed class AllFilter : RevFilter
 
118
                {
 
119
                        public override bool Include(RevWalk walker, RevCommit c)
 
120
                        {
 
121
                                return true;
 
122
                        }
 
123
 
 
124
                        public override RevFilter Clone()
 
125
                        {
 
126
                                return this;
 
127
                        }
 
128
 
 
129
                        public override bool RequiresCommitBody()
 
130
                        {
 
131
                                return false;
 
132
                        }
 
133
 
 
134
                        public override string ToString()
 
135
                        {
 
136
                                return "ALL";
 
137
                        }
 
138
                }
 
139
 
 
140
                /// <summary>Default filter that always returns false (thread safe).</summary>
 
141
                /// <remarks>Default filter that always returns false (thread safe).</remarks>
 
142
                public static readonly RevFilter NONE = new RevFilter.NoneFilter();
 
143
 
 
144
                private sealed class NoneFilter : RevFilter
 
145
                {
 
146
                        public override bool Include(RevWalk walker, RevCommit c)
 
147
                        {
 
148
                                return false;
 
149
                        }
 
150
 
 
151
                        public override RevFilter Clone()
 
152
                        {
 
153
                                return this;
 
154
                        }
 
155
 
 
156
                        public override bool RequiresCommitBody()
 
157
                        {
 
158
                                return false;
 
159
                        }
 
160
 
 
161
                        public override string ToString()
 
162
                        {
 
163
                                return "NONE";
 
164
                        }
 
165
                }
 
166
 
 
167
                /// <summary>Excludes commits with more than one parent (thread safe).</summary>
 
168
                /// <remarks>Excludes commits with more than one parent (thread safe).</remarks>
 
169
                public static readonly RevFilter NO_MERGES = new RevFilter.NoMergesFilter();
 
170
 
 
171
                private sealed class NoMergesFilter : RevFilter
 
172
                {
 
173
                        public override bool Include(RevWalk walker, RevCommit c)
 
174
                        {
 
175
                                return c.ParentCount < 2;
 
176
                        }
 
177
 
 
178
                        public override RevFilter Clone()
 
179
                        {
 
180
                                return this;
 
181
                        }
 
182
 
 
183
                        public override bool RequiresCommitBody()
 
184
                        {
 
185
                                return false;
 
186
                        }
 
187
 
 
188
                        public override string ToString()
 
189
                        {
 
190
                                return "NO_MERGES";
 
191
                        }
 
192
                }
 
193
 
 
194
                /// <summary>Selects only merge bases of the starting points (thread safe).</summary>
 
195
                /// <remarks>
 
196
                /// Selects only merge bases of the starting points (thread safe).
 
197
                /// <p>
 
198
                /// This is a special case filter that cannot be combined with any other
 
199
                /// filter. Its include method always throws an exception as context
 
200
                /// information beyond the arguments is necessary to determine if the
 
201
                /// supplied commit is a merge base.
 
202
                /// </remarks>
 
203
                public static readonly RevFilter MERGE_BASE = new RevFilter.MergeBaseFilter();
 
204
 
 
205
                private sealed class MergeBaseFilter : RevFilter
 
206
                {
 
207
                        public override bool Include(RevWalk walker, RevCommit c)
 
208
                        {
 
209
                                throw new NotSupportedException(JGitText.Get().cannotBeCombined);
 
210
                        }
 
211
 
 
212
                        public override RevFilter Clone()
 
213
                        {
 
214
                                return this;
 
215
                        }
 
216
 
 
217
                        public override bool RequiresCommitBody()
 
218
                        {
 
219
                                return false;
 
220
                        }
 
221
 
 
222
                        public override string ToString()
 
223
                        {
 
224
                                return "MERGE_BASE";
 
225
                        }
 
226
                }
 
227
 
 
228
                /// <summary>Create a new filter that does the opposite of this filter.</summary>
 
229
                /// <remarks>Create a new filter that does the opposite of this filter.</remarks>
 
230
                /// <returns>a new filter that includes commits this filter rejects.</returns>
 
231
                public virtual RevFilter Negate()
 
232
                {
 
233
                        return NotRevFilter.Create(this);
 
234
                }
 
235
 
 
236
                /// <returns>true if the filter needs the commit body to be parsed.</returns>
 
237
                public virtual bool RequiresCommitBody()
 
238
                {
 
239
                        // Assume true to be backward compatible with prior behavior.
 
240
                        return true;
 
241
                }
 
242
 
 
243
                /// <summary>Determine if the supplied commit should be included in results.</summary>
 
244
                /// <remarks>Determine if the supplied commit should be included in results.</remarks>
 
245
                /// <param name="walker">the active walker this filter is being invoked from within.</param>
 
246
                /// <param name="cmit">
 
247
                /// the commit currently being tested. The commit has been parsed
 
248
                /// and its body is available for inspection only if the filter
 
249
                /// returns true from
 
250
                /// <see cref="RequiresCommitBody()">RequiresCommitBody()</see>
 
251
                /// .
 
252
                /// </param>
 
253
                /// <returns>
 
254
                /// true to include this commit in the results; false to have this
 
255
                /// commit be omitted entirely from the results.
 
256
                /// </returns>
 
257
                /// <exception cref="NGit.Errors.StopWalkException">
 
258
                /// the filter knows for certain that no additional commits can
 
259
                /// ever match, and the current commit doesn't match either. The
 
260
                /// walk is halted and no more results are provided.
 
261
                /// </exception>
 
262
                /// <exception cref="NGit.Errors.MissingObjectException">
 
263
                /// an object the filter needs to consult to determine its answer
 
264
                /// does not exist in the Git repository the walker is operating
 
265
                /// on. Filtering this commit is impossible without the object.
 
266
                /// </exception>
 
267
                /// <exception cref="NGit.Errors.IncorrectObjectTypeException">
 
268
                /// an object the filter needed to consult was not of the
 
269
                /// expected object type. This usually indicates a corrupt
 
270
                /// repository, as an object link is referencing the wrong type.
 
271
                /// </exception>
 
272
                /// <exception cref="System.IO.IOException">
 
273
                /// a loose object or pack file could not be read to obtain data
 
274
                /// necessary for the filter to make its decision.
 
275
                /// </exception>
 
276
                public abstract bool Include(RevWalk walker, RevCommit cmit);
 
277
 
 
278
                /// <summary>Clone this revision filter, including its parameters.</summary>
 
279
                /// <remarks>
 
280
                /// Clone this revision filter, including its parameters.
 
281
                /// <p>
 
282
                /// This is a deep clone. If this filter embeds objects or other filters it
 
283
                /// must also clone those, to ensure the instances do not share mutable data.
 
284
                /// </remarks>
 
285
                /// <returns>another copy of this filter, suitable for another thread.</returns>
 
286
                public abstract RevFilter Clone();
 
287
 
 
288
                public override string ToString()
 
289
                {
 
290
                        string n = GetType().FullName;
 
291
                        int lastDot = n.LastIndexOf('.');
 
292
                        if (lastDot >= 0)
 
293
                        {
 
294
                                n = Sharpen.Runtime.Substring(n, lastDot + 1);
 
295
                        }
 
296
                        return n.Replace('$', '.');
 
297
                }
 
298
        }
 
299
}