Pregunta

I'm using Lib2GitSharp to join the Git logs with information from some other systems and I would like to be able to retrieve all git logs since a certain date (or between dates).

I found documentation on querying the log here but it does not appear that there is a way to query the log by date. What would be the equivalent of

git log --since="2013-08-20"

in LibGit2Sharp?

Edit This seems to work but perhaps there a better and/or more elegant way?

using (var repo = new Repository(options.Repo))
{
    var since = new DateTime(2013, 8, 20);
    var commits = repo.Commits.Where(c => c.Committer.When.CompareTo(since) > 0);
    foreach (Commit commit in commits)
    {
        Console.WriteLine("A commit happened at " + commit.Committer.When.ToLocalTime());
    }
}
¿Fue útil?

Solución

Using Linq I can query each commit object in the repository for its date and return only those whose data is greater than the specified one. I am not sure if there is cleaner, faster, more elegant way but this does work.

using (var repo = new Repository(options.Repo))
{
    var since = new DateTimeOffset(new DateTime(2013, 8, 20));
    var filter = new CommitFilter { Since = repo.Branches };
    var commitLog = repo.Commits.QueryBy(filter);
    var commits = commitLog.Where(c => c.Committer.When > since);
    foreach (Commit commit in commits)
    {
        Console.WriteLine("A commit happened at " + commit.Committer.When.ToLocalTime());
    }
}

EDIT: Incorporated suggestions from nulltoken

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top