例如,该行的.gitattributes
文件.代码的输出lg2s
*.cs diff=csharp
using (var repo = new Repository(@"path\to\lg2s")) { var tree1 = repo.Lookup("a845db9").Tree; var tree2 = repo.Lookup ("d677741").Tree; var patches = repo.Diff.Compare (tree1, tree2); foreach (var patch in patches) { Console.WriteLine(patch.Patch); } }
是(不久)
diff --git a/LibGit2Sharp/RepositoryStatus.cs b/LibGit2Sharp/RepositoryStatus.cs @@ -59,8 +59,8 @@ namespace LibGit2Sharp
但输出git bash
是(很快)
diff --git a/LibGit2Sharp/RepositoryStatus.cs b/LibGit2Sharp/RepositoryStatus.cs @@ -59,8 +59,8 @@ internal RepositoryStatus(Repository repo, StatusOptions optio
第二行不一样.
看起来有一个深入的讨论Add .gitattributes support
libgit2 /#508,但PR Add APIs for git attributes
libgit2 /#516是否合并?
现在支持多少种语言?
我们可以指定没有gitattributes
文件的规则吗?
这实际上是差异驱动器和差异的自定义函数上下文规则的问题,而不是属性之一.
那些文件确实有diff=csharp
属性; 问题是该属性并不意味着什么libgit2
.
当git
和libgit2
产生的diff,他们使用正则表达式在其中找到一个差异大块发生函数的名称.如果没有正则表达式可用于查找不以空格开头的第一行,它们也有一个回退规则.
git
包含一个内置差异驱动程序的表,其中包含驱动程序的定义csharp
.
libgit2
不包含该表(如在合并差异驱动程序支持的PR中讨论的那样),因此没有内置的概念用于使用什么模式diff=csharp
.
您解决此问题的替代方案是:
在您的.git/config
文件(或您的$HOME/.gitconfig
)中创建diff.csharp.xfuncname
一个用搜索模式实现的条目,或者
启动Pull Request以libgit2
导入驱动程序定义.导入的问题(以及我没有接受它的原因)是它将涉及获得代码原始作者的许可以重新许可它以供使用libgit2
.
如果您决定启动Pull Request并且您获得CSharp xfuncname模式的作者同意重新授权代码libgit2
,请告诉我,我将很乐意就实际实施进行协作!