2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
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
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
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.
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
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.
47
using NGit.Revwalk.Filter;
50
namespace NGit.Revwalk.Filter
52
/// <summary>Selects interesting revisions during walking.</summary>
54
/// Selects interesting revisions during walking.
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.
61
/// Applications should install the filter on a RevWalk by
62
/// <see cref="NGit.Revwalk.RevWalk.SetRevFilter(RevFilter)">NGit.Revwalk.RevWalk.SetRevFilter(RevFilter)
64
/// prior to starting traversal.
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
70
/// <see cref="Include(NGit.Revwalk.RevWalk, NGit.Revwalk.RevCommit)">Include(NGit.Revwalk.RevWalk, NGit.Revwalk.RevCommit)
72
/// if it is beneficial to
73
/// their implementation. Deep clones created by
74
/// <see cref="Clone()">Clone()</see>
76
/// construct a thread-safe copy of an existing filter.
78
/// <b>Message filters:</b>
80
/// <li>Author name/email:
81
/// <see cref="AuthorRevFilter">AuthorRevFilter</see>
83
/// <li>Committer name/email:
84
/// <see cref="CommitterRevFilter">CommitterRevFilter</see>
87
/// <see cref="MessageRevFilter">MessageRevFilter</see>
91
/// <b>Merge filters:</b>
93
/// <li>Skip all merges:
94
/// <see cref="NO_MERGES">NO_MERGES</see>
98
/// <b>Boolean modifiers:</b>
101
/// <see cref="AndRevFilter">AndRevFilter</see>
104
/// <see cref="OrRevFilter">OrRevFilter</see>
107
/// <see cref="NotRevFilter">NotRevFilter</see>
111
public abstract class RevFilter
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();
117
private sealed class AllFilter : RevFilter
119
public override bool Include(RevWalk walker, RevCommit c)
124
public override RevFilter Clone()
129
public override bool RequiresCommitBody()
134
public override string ToString()
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();
144
private sealed class NoneFilter : RevFilter
146
public override bool Include(RevWalk walker, RevCommit c)
151
public override RevFilter Clone()
156
public override bool RequiresCommitBody()
161
public override string ToString()
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();
171
private sealed class NoMergesFilter : RevFilter
173
public override bool Include(RevWalk walker, RevCommit c)
175
return c.ParentCount < 2;
178
public override RevFilter Clone()
183
public override bool RequiresCommitBody()
188
public override string ToString()
194
/// <summary>Selects only merge bases of the starting points (thread safe).</summary>
196
/// Selects only merge bases of the starting points (thread safe).
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.
203
public static readonly RevFilter MERGE_BASE = new RevFilter.MergeBaseFilter();
205
private sealed class MergeBaseFilter : RevFilter
207
public override bool Include(RevWalk walker, RevCommit c)
209
throw new NotSupportedException(JGitText.Get().cannotBeCombined);
212
public override RevFilter Clone()
217
public override bool RequiresCommitBody()
222
public override string ToString()
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()
233
return NotRevFilter.Create(this);
236
/// <returns>true if the filter needs the commit body to be parsed.</returns>
237
public virtual bool RequiresCommitBody()
239
// Assume true to be backward compatible with prior behavior.
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>
254
/// true to include this commit in the results; false to have this
255
/// commit be omitted entirely from the results.
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.
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.
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.
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.
276
public abstract bool Include(RevWalk walker, RevCommit cmit);
278
/// <summary>Clone this revision filter, including its parameters.</summary>
280
/// Clone this revision filter, including its parameters.
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.
285
/// <returns>another copy of this filter, suitable for another thread.</returns>
286
public abstract RevFilter Clone();
288
public override string ToString()
290
string n = GetType().FullName;
291
int lastDot = n.LastIndexOf('.');
294
n = Sharpen.Runtime.Substring(n, lastDot + 1);
296
return n.Replace('$', '.');