-
Notifications
You must be signed in to change notification settings - Fork 899
Tree to Tree diffing issue #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
/cc @carlosmn |
Here is the relevant libgit2 code: https://github.com/libgit2/libgit2/blob/development/src/diff.c#L481-483 When the type of a file changes (e.g. symlink -> regular file) then two entries will be created for the path, a deletion and a addition. |
@arrbee Thanks a lot for this pointer. When one gives a little thought about it, it indeed makes sense. I'll recreate a test case as part of the fix to make sure this is covered. |
@carlosmn I've got a slight issue The two following tests pass in my native Win7/x86 environment against the latest tip of The first one attempts at recreating the issue. [Fact]
public void CanHandleTwoTreeEntryChangesWithTheSamePath()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
using (Repository repo = Repository.Init(scd.DirectoryPath))
{
Blob mainContent = CreateBlob(repo, "awesome content\n");
Blob linkContent = CreateBlob(repo, "../../objc/Nu.h");
var tdOld = new TreeDefinition()
.Add("include/Nu/Nu.h", linkContent, Mode.SymbolicLink)
.Add("objc/Nu.h", mainContent, Mode.NonExecutableFile);
Tree treeOld = repo.ObjectDatabase.CreateTree(tdOld);
var tdNew = new TreeDefinition()
.Add("include/Nu/Nu.h", mainContent, Mode.NonExecutableFile);
Tree treeNew = repo.ObjectDatabase.CreateTree(tdNew);
TreeChanges changes = repo.Diff.Compare(treeOld, treeNew);
Assert.NotNull(changes);
}
}
private static Blob CreateBlob(Repository repo, string content)
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
using (var binReader = new BinaryReader(stream))
{
return repo.ObjectDatabase.CreateBlob(binReader);
}
}
[Fact]
public void Issue_196()
{
using (var repo = new Repository(@"D:\Temp\sss\nu"))
{
var treeOld = repo.Lookup<Commit>("b46ed84").Tree;
var treeNew = repo.Lookup<Commit>("d7a2068").Tree;
TreeChanges changes = repo.Diff.Compare(treeOld, treeNew);
Assert.NotNull(changes);
}
} You'll have to apply the following patch to allow the creation of a symlink: diff --git a/LibGit2Sharp/TreeDefinition.cs b/LibGit2Sharp/TreeDefinition.cs
index 8a725a5..7da0eea 100644
--- a/LibGit2Sharp/TreeDefinition.cs
+++ b/LibGit2Sharp/TreeDefinition.cs
@@ -136,7 +136,7 @@ public TreeDefinition Add(string targetTreeEntryPath, Blob blob, Mode mode)
{
Ensure.ArgumentNotNull(blob, "blob");
Ensure.ArgumentConformsTo(mode,
- m => m.HasAny(new[] { Mode.ExecutableFile, Mode.NonExecutableFile, Mode.NonExecutableGroupWritableFile }), "mode");
+ m => m.HasAny(new[] { Mode.ExecutableFile, Mode.NonExecutableFile, Mode.NonExecutableGroupWritableFile, Mode.SymbolicLink }), "mode");
TreeEntryDefinition ted = TreeEntryDefinition.From(blob, mode); This libgit2 code https://github.com/libgit2/libgit2/blob/development/src/diff.c#L459-462 might explain why the tests pass on my computer. However, the stack trace you've provided looks like it's coming from a Win environment, too...
|
I't not based on vNext but v9.5.0 (because the modified library). I haven't had time to test it yet, though it looks like it should show the issue. The issue did happen on a Windows system, so it's not libgit2 working around the issue. I'll investigate today. |
Works for me. I.e. it fails. This is with your first two tests, so it looks like it's able to recreate the situation on Linux/Mono.
|
That's a plus! Have you had the chance to run it on Windows as well? |
I takes more willpower than I had to start up the Windows VM, but I have to double-check whether something is a mono bug, so I might do it later. |
Just tried on Windows and I can't reproduce it. I'll have to ask for more information. |
That situation sounds like it should also have two distinct changes for the one file, so it should also be affected. |
@carlosmn I've worked on a first fix https://github.com/nulltoken/libgit2sharp/tree/fix/issue-196 I'm not especially happy with the code, but that should do it for now. This will require some refactoring later, though as it's barely readable now. Could you please fill in the gaps regarding assertions on Linux and make sure the code actually works? |
Not sure where we left off on this, but https://github.com/dahlbyk/libgit2sharp/compare/fix/issue196 has been rebased on latest. It includes a standalone commit (dahlbyk@71eb036) with |
I can't exactly remember why we would need this. Isn't the 32bits version of msbuild able to correctly produce an AnyCPU build? |
I don't know that there's any difference in the actual build, but tests run in 32-bit by default:
With
|
@dahlbyk I wonder if we could tweak the From what I've read, Could you see if something like this would work on your computer, please?
|
We might need to run those tests in 32 and 64 bits mode, thus against the clr2.0 and clr4.0. How about
|
Doing more than this at the moment really feels like YAGNI to me. We already have both architectures tested with CI, so this .cmd is really only useful if you're trying to debug something that works in x86 but not in x64. |
Fair enough. I've cherry-picked your commit and will open an issue. |
See libgit2/libgit2#878. I've slightly rewrote the tree-to-tree test in C# (cf. nulltoken/topic/type-change). However, I'm not really satisfied with it. I really don't like returning a The tree-to-workdir test still fails on Windows. |
@nulltoken I'd be happy to help. Let me know what I can do. |
@roend83 Thanks a lot for this! It would be awesome if you could rebase #278 on top of vNext and cover it with some tests. Maybe one identifying the exact renamings and another one identifying the copying. Would that fit you? |
@nulltoken Yeah, I'll try to get to it tonight. |
Ready for review. |
I like topic/type-change a lot better than the alternative. Also, |
These tests are related to issue libgit2/libgit2sharp#196
Repository -> git://github.com/timburks/nu.git
Parent -> b46ed8403aba281d47619f71dd46fefa08e5c809
Commit -> d7a206818e70d753845fff30264fbae4a69ad7a0
Diffing those two commits creates two entries with the same name
See programming-nu/nu@d7a2068
The text was updated successfully, but these errors were encountered: