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.
44
using System.Collections.Generic;
48
using NGit.Api.Errors;
51
using NGit.Treewalk.Filter;
57
/// A class used to execute a
59
/// command. It has setters for all
60
/// supported options and arguments of this command and a
61
/// <see cref="Call()">Call()</see>
63
/// to finally execute the command. Each instance of this class should only be
64
/// used for one invocation of the command (means: one call to
65
/// <see cref="Call()">Call()</see>
68
/// This is currently a very basic implementation which takes only one starting
69
/// revision as option.
70
/// TODO: add more options (revision ranges, sorting, ...)
72
/// <seealso><a href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"
73
/// * >Git documentation about Log</a></seealso>
74
public class LogCommand : GitCommand<Iterable<RevCommit>>
78
private bool startSpecified = false;
80
private readonly IList<PathFilter> pathFilters = new AList<PathFilter>();
82
/// <param name="repo"></param>
83
protected internal LogCommand(Repository repo) : base(repo)
85
walk = new RevWalk(repo);
91
/// command with all the options and parameters
92
/// collected by the setter methods (e.g.
93
/// <see cref="Add(NGit.AnyObjectId)">Add(NGit.AnyObjectId)</see>
95
/// <see cref="Not(NGit.AnyObjectId)">Not(NGit.AnyObjectId)</see>
96
/// , ..) of this class. Each instance of this class
97
/// should only be used for one invocation of the command. Don't call this
98
/// method twice on an instance.
100
/// <returns>an iteration over RevCommits</returns>
101
/// <exception cref="NGit.Api.Errors.NoHeadException"></exception>
102
/// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
103
public override Iterable<RevCommit> Call()
106
if (pathFilters.Count > 0)
108
walk.SetTreeFilter(PathFilterGroup.Create(pathFilters));
114
ObjectId headId = repo.Resolve(Constants.HEAD);
117
throw new NoHeadException(JGitText.Get().noHEADExistsAndNoExplicitStartingRevisionWasSpecified
122
catch (IOException e)
124
// all exceptions thrown by add() shouldn't occur and represent
125
// severe low-level exception which are therefore wrapped
126
throw new JGitInternalException(JGitText.Get().anExceptionOccurredWhileTryingToAddTheIdOfHEAD
134
/// <summary>Mark a commit to start graph traversal from.</summary>
135
/// <remarks>Mark a commit to start graph traversal from.</remarks>
136
/// <seealso cref="NGit.Revwalk.RevWalk.MarkStart(NGit.Revwalk.RevCommit)">NGit.Revwalk.RevWalk.MarkStart(NGit.Revwalk.RevCommit)
138
/// <param name="start"></param>
141
/// <code>this</code>
143
/// <exception cref="NGit.Errors.MissingObjectException">
144
/// the commit supplied is not available from the object
145
/// database. This usually indicates the supplied commit is
146
/// invalid, but the reference was constructed during an earlier
148
/// <see cref="NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)">NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)
152
/// <exception cref="NGit.Errors.IncorrectObjectTypeException">
153
/// the object was not parsed yet and it was discovered during
154
/// parsing that it is not actually a commit. This usually
155
/// indicates the caller supplied a non-commit SHA-1 to
156
/// <see cref="NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)">NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)
160
/// <exception cref="NGit.Api.Errors.JGitInternalException">
161
/// a low-level exception of JGit has occurred. The original
162
/// exception can be retrieved by calling
163
/// <see cref="System.Exception.InnerException()">System.Exception.InnerException()</see>
165
/// <code>IOException's</code>
166
/// to be wrapped. Subclasses of
167
/// <see cref="System.IO.IOException">System.IO.IOException</see>
169
/// <see cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException
172
/// typically not wrapped here but thrown as original exception
174
public virtual NGit.Api.LogCommand Add(AnyObjectId start)
176
return Add(true, start);
181
/// <code>--not start</code>
183
/// <code>^start</code>
185
/// <param name="start"></param>
188
/// <code>this</code>
190
/// <exception cref="NGit.Errors.MissingObjectException">
191
/// the commit supplied is not available from the object
192
/// database. This usually indicates the supplied commit is
193
/// invalid, but the reference was constructed during an earlier
195
/// <see cref="NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)">NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)
199
/// <exception cref="NGit.Errors.IncorrectObjectTypeException">
200
/// the object was not parsed yet and it was discovered during
201
/// parsing that it is not actually a commit. This usually
202
/// indicates the caller supplied a non-commit SHA-1 to
203
/// <see cref="NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)">NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)
207
/// <exception cref="NGit.Api.Errors.JGitInternalException">
208
/// a low-level exception of JGit has occurred. The original
209
/// exception can be retrieved by calling
210
/// <see cref="System.Exception.InnerException()">System.Exception.InnerException()</see>
212
/// <code>IOException's</code>
213
/// to be wrapped. Subclasses of
214
/// <see cref="System.IO.IOException">System.IO.IOException</see>
216
/// <see cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException
219
/// typically not wrapped here but thrown as original exception
221
public virtual NGit.Api.LogCommand Not(AnyObjectId start)
223
return Add(false, start);
228
/// <code>since..until</code>
230
/// <param name="since"></param>
231
/// <param name="until"></param>
234
/// <code>this</code>
236
/// <exception cref="NGit.Errors.MissingObjectException">
237
/// the commit supplied is not available from the object
238
/// database. This usually indicates the supplied commit is
239
/// invalid, but the reference was constructed during an earlier
241
/// <see cref="NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)">NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)
245
/// <exception cref="NGit.Errors.IncorrectObjectTypeException">
246
/// the object was not parsed yet and it was discovered during
247
/// parsing that it is not actually a commit. This usually
248
/// indicates the caller supplied a non-commit SHA-1 to
249
/// <see cref="NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)">NGit.Revwalk.RevWalk.LookupCommit(NGit.AnyObjectId)
253
/// <exception cref="NGit.Api.Errors.JGitInternalException">
254
/// a low-level exception of JGit has occurred. The original
255
/// exception can be retrieved by calling
256
/// <see cref="System.Exception.InnerException()">System.Exception.InnerException()</see>
258
/// <code>IOException's</code>
259
/// to be wrapped. Subclasses of
260
/// <see cref="System.IO.IOException">System.IO.IOException</see>
262
/// <see cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException
265
/// typically not wrapped here but thrown as original exception
267
public virtual NGit.Api.LogCommand AddRange(AnyObjectId since, AnyObjectId until)
269
return Not(since).Add(until);
272
/// <summary>Show only commits that affect any of the specified paths.</summary>
274
/// Show only commits that affect any of the specified paths. The path must
275
/// either name a file or a directory exactly. Note that regex expressions or
276
/// wildcards are not supported.
278
/// <param name="path">a path is relative to the top level of the repository</param>
281
/// <code>this</code>
283
public virtual NGit.Api.LogCommand AddPath(string path)
286
pathFilters.AddItem(PathFilter.Create(path));
290
/// <exception cref="NGit.Errors.MissingObjectException"></exception>
291
/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
292
/// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
293
private NGit.Api.LogCommand Add(bool include, AnyObjectId start)
300
walk.MarkStart(walk.LookupCommit(start));
301
startSpecified = true;
305
walk.MarkUninteresting(walk.LookupCommit(start));
309
catch (MissingObjectException e)
313
catch (IncorrectObjectTypeException e)
317
catch (IOException e)
319
throw new JGitInternalException(MessageFormat.Format(JGitText.Get().exceptionOccurredDuringAddingOfOptionToALogCommand