Accessing the notes from the Commit
object makes libgit2 access the notes tree at each iteration of the loop. A more efficient way to do it is to:
- first, load the list of commits you are interested in (you are already doing that apparently)
- then load all the notes associated with the
push-date
namespace only once - and eventually perform a join between those two lists
note: this will add some more pressure from a memory perspective, but it should be faster.
This can be done in C# with the following code:
using (var repo = new Repository("your_repo_path"))
{
var notes = repo.Notes["push-date"];
var commits = repo.Commits.QueryBy(
new CommitFilter {Since = "1234567", Until = "89abcde"});
var pairs = from commit in commits
from note in notes
where note.TargetObjectId == commit.Id
select new {Commit = commit, Note = note};
foreach (var pair in pairs)
{
Debug.Write(pair.Commit.Sha + " : " + pair.Note);
}
}
This will output the commits which have a note associated in the push-date
namespace.
note: if you are using the QueryBy
syntax to retrieve the list of commits, please be aware that commit specified as Until
will be excluded from the list (e.g.: as in git log A...B)
In order to also show the commits which have no notes associated in the push-date
namespace, you can use the following linq query:
var pairs2 = from commit in commits
join note in notes on commit.Id equals note.TargetObjectId into gj
from subnote in gj.DefaultIfEmpty()
select new { Commit = commit, Note = subnote };