I got another libgit2 issue and will be very grateful for your help.
I'm trying to retrieve file history, i.e. list of commits where this file was changed. And it seems to be quite unconventional... As far as I can see, there are no function for that.
The only approach I can come up with is to use revision walking API to iterate through revisions, check the tree object attached to commit and search for given file there, if found, add commit to my list, otherwise proceed to next commit.
But it looks none-optimal for me...
May be is there any other approach, for example, look directly into .git folder and get needed information there?
Many thanks in advance!
If using C#, this functionality has been added to the
LibGit2Sharp
0.22.0 NuGet Package (Pull Request 963). You can do the following:In my Diff All Files VS Extension (which is open source so you can view the code), I needed to get a file's previous commit so I can see what changes were made to a file in a given commit. This is how I retrieved the file's previous commit:
Your approach is the correct one. Beware that you'll have to fight against:
Even though understanding the .git folder layout is always a well-spent time, I'm afraid this won't help you with this specific file history issue.
Note: this question is very close from this libgit2sharp issue: How to get the last commit that affected a given file?
Update
Pull request #963 adds this very feature.
It's available since
LibGit2Sharp.0.22.0-pre20150415174523
pre-release NuGet package.This is mainly followed in issues/495 of libgit2.
Even though it is implemented in libgit2sharp (PR 963, for milestone 22), it is still "up for grabs" in libgit2 itself.
The issue is documented in issues/3041: Provide log functionality wrapping the
revwalk
.The approach mentioned in the question was used in this libgit2sharp example and can be adapted to C using libgit2. It remains the current workaround, pending the resolution of 3041.