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
52
/// <summary>Default (and first pass) RevCommit Generator implementation for RevWalk.
55
/// Default (and first pass) RevCommit Generator implementation for RevWalk.
57
/// This generator starts from a set of one or more commits and process them in
58
/// descending (newest to oldest) commit time order. Commits automatically cause
59
/// their parents to be enqueued for further processing, allowing the entire
60
/// commit graph to be walked. A
61
/// <see cref="NGit.Revwalk.Filter.RevFilter">NGit.Revwalk.Filter.RevFilter</see>
62
/// may be used to select a subset
63
/// of the commits and return them to the caller.
65
internal class PendingGenerator : Generator
67
private const int PARSED = RevWalk.PARSED;
69
private const int SEEN = RevWalk.SEEN;
71
private const int UNINTERESTING = RevWalk.UNINTERESTING;
73
/// <summary>Number of additional commits to scan after we think we are done.</summary>
75
/// Number of additional commits to scan after we think we are done.
77
/// This small buffer of commits is scanned to ensure we didn't miss anything
78
/// as a result of clock skew when the commits were made. We need to set our
79
/// constant to 1 additional commit due to the use of a pre-increment
80
/// operator when accessing the value.
82
internal const int OVER_SCAN = 5 + 1;
85
/// A commit near the end of time, to initialize
86
/// <see cref="last">last</see>
89
private static readonly RevCommit INIT_LAST;
91
static PendingGenerator()
93
INIT_LAST = new RevCommit(ObjectId.ZeroId);
94
INIT_LAST.commitTime = int.MaxValue;
97
private readonly RevWalk walker;
99
private readonly DateRevQueue pending;
101
private readonly RevFilter filter;
103
private readonly int output;
106
/// Last commit produced to the caller from
107
/// <see cref="Next()">Next()</see>
110
private RevCommit last = INIT_LAST;
112
/// <summary>Number of commits we have remaining in our over-scan allotment.</summary>
114
/// Number of commits we have remaining in our over-scan allotment.
116
/// Only relevant if there are
117
/// <see cref="UNINTERESTING">UNINTERESTING</see>
119
/// <see cref="pending">pending</see>
122
private int overScan = OVER_SCAN;
124
internal bool canDispose;
126
internal PendingGenerator(RevWalk w, DateRevQueue p, RevFilter f, int @out)
135
internal override int OutputType()
137
return output | SORT_COMMIT_TIME_DESC;
140
/// <exception cref="NGit.Errors.MissingObjectException"></exception>
141
/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
142
/// <exception cref="System.IO.IOException"></exception>
143
internal override RevCommit Next()
149
RevCommit c = pending.Next();
152
walker.reader.WalkAdviceEnd();
156
if ((c.flags & UNINTERESTING) != 0)
162
if (filter.RequiresCommitBody())
166
produce = filter.Include(walker, c);
168
foreach (RevCommit p in c.parents)
170
if ((p.flags & SEEN) != 0)
174
if ((p.flags & PARSED) == 0)
176
p.ParseHeaders(walker);
181
walker.CarryFlagsImpl(c);
182
if ((c.flags & UNINTERESTING) != 0)
184
if (pending.EverbodyHasFlag(UNINTERESTING))
186
RevCommit n = pending.Peek();
187
if (n != null && n.commitTime >= last.commitTime)
189
// This is too close to call. The next commit we
190
// would pop is dated after the last one produced.
191
// We have to keep going to ensure that we carry
192
// flags as much as necessary.
194
overScan = OVER_SCAN;
200
throw StopWalkException.INSTANCE;
206
overScan = OVER_SCAN;
227
catch (StopWalkException)
229
walker.reader.WalkAdviceEnd();