Created
November 24, 2011 13:20
-
-
Save shytikov/1391331 to your computer and use it in GitHub Desktop.
Draft implementation of viewing file history for libgit2sharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Commit> modificationCommits = new List<Commit>(); | |
string currentSha = startingItemSha; | |
string currentPath = startingItemPath; | |
Commit temp = null; | |
foreach (Commit c in repository.Commits) | |
{ | |
if (c.Tree.Any<TreeEntry>(entry => entry.Name == currentPath)) | |
{ | |
// If file with given name was found, check its SHA | |
TreeEntry te = c.Tree.First<TreeEntry>(entry => entry.Name == currentPath); | |
if (te.Target.Sha == currentSha) | |
{ | |
// In case if file's SHA matches file was not changed in this commit | |
// and temporary commit need to be updated to current one | |
temp = c; | |
} | |
else | |
{ | |
// In case if file's SHA don't match file was changed during commit | |
// and temporary commit need to be added to the commits collection | |
// as the one where update occur. The file's SHA updated to current one | |
modificationCommits.Add(temp); | |
currentSha = te.Target.Sha; | |
} | |
} | |
else | |
{ | |
// File with given name not found. this means it was renamed. | |
// However ut's SHA still the same, so it can be found by it. | |
if (c.Tree.Any<TreeEntry>(entry => entry.Target.Sha == currentSha)) | |
{ | |
TreeEntry te = c.Tree.First<TreeEntry>(entry => entry.Target.Sha == currentSha); | |
currentSha = te.Target.Sha; | |
currentPath = te.Name; | |
modificationCommits.Add(temp); | |
} | |
} | |
} | |
if (null != temp) | |
{ | |
modificationCommits.Add(temp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment