Skip to content

Instantly share code, notes, and snippets.

@owickstrom
Created December 30, 2012 14:27
Show Gist options
  • Save owickstrom/4413032 to your computer and use it in GitHub Desktop.
Save owickstrom/4413032 to your computer and use it in GitHub Desktop.
Possible solution (not tested)
public virtual IEnumerable<Commit> GetFromTo(DateTime start, DateTime end)
{
this.ThrowWhenDisposed();
Logger.Debug(Resources.GettingAllCommitsFromToTime, start, end);
var selectedCommitIds = this.stamps.Where(x => x.Value >= start && x.Value < end).Select(x => x.Key);
var firstCommitId = selectedCommitIds.FirstOrDefault();
var lastCommitId = selectedCommitIds.LastOrDefault();
if (lastCommitId == Guid.Empty && lastCommitId == Guid.Empty)
return new Commit[] { };
var startingCommit = this.commits.FirstOrDefault(x => x.CommitId == firstCommitId);
var endingCommit = this.commits.FirstOrDefault(x => x.CommitId == lastCommitId);
var startingCommitIndex = (startingCommit == null) ? 0 : this.commits.IndexOf(startingCommit);
var endingCommitIndex = (endingCommit == null) ? this.commits.Count - 1 : this.commits.IndexOf(endingCommit);
var numberToTake = endingCommitIndex - startingCommitIndex + 1;
return this.commits.Skip(this.commits.IndexOf(startingCommit)).Take(numberToTake);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment