зеркало из https://github.com/github/libgit2sharp.git
Родитель
fa5e0fbc1f
Коммит
e99d81993d
Двоичные данные
Lib/NativeBinaries/amd64/git2.dll
Двоичные данные
Lib/NativeBinaries/amd64/git2.dll
Двоичный файл не отображается.
Двоичные данные
Lib/NativeBinaries/amd64/git2.pdb
Двоичные данные
Lib/NativeBinaries/amd64/git2.pdb
Двоичный файл не отображается.
Двоичные данные
Lib/NativeBinaries/x86/git2.dll
Двоичные данные
Lib/NativeBinaries/x86/git2.dll
Двоичный файл не отображается.
Двоичные данные
Lib/NativeBinaries/x86/git2.pdb
Двоичные данные
Lib/NativeBinaries/x86/git2.pdb
Двоичный файл не отображается.
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using LibGit2Sharp.Core;
|
||||
using LibGit2Sharp.Core.Handles;
|
||||
|
||||
namespace LibGit2Sharp
|
||||
{
|
||||
|
@ -88,13 +89,39 @@ namespace LibGit2Sharp
|
|||
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
|
||||
public virtual IEnumerator<Branch> GetEnumerator()
|
||||
{
|
||||
return Libgit2UnsafeHelper
|
||||
.ListAllBranchNames(repo.Handle, GitBranchType.GIT_BRANCH_LOCAL | GitBranchType.GIT_BRANCH_REMOTE)
|
||||
return new BranchNameEnumerable(repo.Handle, GitBranchType.GIT_BRANCH_LOCAL | GitBranchType.GIT_BRANCH_REMOTE)
|
||||
.Select(n => this[n])
|
||||
.OrderBy(b => b.CanonicalName, StringComparer.Ordinal)
|
||||
.GetEnumerator();
|
||||
}
|
||||
|
||||
private class BranchNameEnumerable : IEnumerable<string>
|
||||
{
|
||||
private readonly List<string> list = new List<string>();
|
||||
|
||||
public BranchNameEnumerable(RepositorySafeHandle handle, GitBranchType gitBranchType)
|
||||
{
|
||||
Ensure.Success(NativeMethods.git_branch_foreach(handle, gitBranchType, Callback, IntPtr.Zero));
|
||||
}
|
||||
|
||||
private int Callback(IntPtr branchName, GitBranchType branchType, IntPtr payload)
|
||||
{
|
||||
string name = Utf8Marshaler.FromNative(branchName);
|
||||
list.Add(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
{
|
||||
return list.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the collection.
|
||||
/// </summary>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
namespace LibGit2Sharp.Core.Handles
|
||||
{
|
||||
internal class TreeEntrySafeHandle_Owned : SafeHandleBase
|
||||
{
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
NativeMethods.git_tree_entry_free(handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,15 +6,6 @@ namespace LibGit2Sharp.Core
|
|||
{
|
||||
internal static unsafe class Libgit2UnsafeHelper
|
||||
{
|
||||
public static IList<string> ListAllBranchNames(RepositorySafeHandle repo, GitBranchType types)
|
||||
{
|
||||
UnSafeNativeMethods.git_strarray strArray;
|
||||
int res = UnSafeNativeMethods.git_branch_list(out strArray, repo, types);
|
||||
Ensure.Success(res);
|
||||
|
||||
return BuildListOf(strArray);
|
||||
}
|
||||
|
||||
public static IList<string> ListAllReferenceNames(RepositorySafeHandle repo, GitReferenceType types)
|
||||
{
|
||||
UnSafeNativeMethods.git_strarray strArray;
|
||||
|
|
|
@ -121,6 +121,18 @@ namespace LibGit2Sharp.Core
|
|||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string branch_name,
|
||||
GitBranchType branch_type);
|
||||
|
||||
internal delegate int branch_foreach_callback(
|
||||
IntPtr branch_name,
|
||||
GitBranchType branch_type,
|
||||
IntPtr payload);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern int git_branch_foreach(
|
||||
RepositorySafeHandle repo,
|
||||
GitBranchType branch_type,
|
||||
branch_foreach_callback branch_cb,
|
||||
IntPtr payload);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern int git_branch_move(
|
||||
RepositorySafeHandle repo,
|
||||
|
@ -608,7 +620,8 @@ namespace LibGit2Sharp.Core
|
|||
[DllImport(libgit2)]
|
||||
public static extern int git_repository_set_workdir(
|
||||
RepositorySafeHandle repository,
|
||||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath workdir);
|
||||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath workdir,
|
||||
bool update_gitlink);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
[return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))]
|
||||
|
@ -709,10 +722,13 @@ namespace LibGit2Sharp.Core
|
|||
public static extern int git_tree_create_fromindex(out GitOid treeOid, IndexSafeHandle index);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern int git_tree_entry_2object(out GitObjectSafeHandle obj, RepositorySafeHandle repo, TreeEntrySafeHandle entry);
|
||||
public static extern int git_tree_entry_to_object(
|
||||
out GitObjectSafeHandle obj,
|
||||
RepositorySafeHandle repo,
|
||||
TreeEntrySafeHandle_Owned entry);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern uint git_tree_entry_attributes(TreeEntrySafeHandle entry);
|
||||
public static extern uint git_tree_entry_attributes(SafeHandle entry);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern TreeEntrySafeHandle git_tree_entry_byindex(GitObjectSafeHandle tree, uint idx);
|
||||
|
@ -723,22 +739,27 @@ namespace LibGit2Sharp.Core
|
|||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath filename);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern OidSafeHandle git_tree_entry_id(TreeEntrySafeHandle entry);
|
||||
public static extern int git_tree_entry_bypath(
|
||||
out TreeEntrySafeHandle_Owned tree,
|
||||
GitObjectSafeHandle root,
|
||||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath treeentry_path);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern void git_tree_entry_free(IntPtr treeEntry);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern OidSafeHandle git_tree_entry_id(SafeHandle entry);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
[return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
|
||||
public static extern string git_tree_entry_name(TreeEntrySafeHandle entry);
|
||||
public static extern string git_tree_entry_name(SafeHandle entry);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern GitObjectType git_tree_entry_type(TreeEntrySafeHandle entry);
|
||||
public static extern GitObjectType git_tree_entry_type(SafeHandle entry);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern uint git_tree_entrycount(GitObjectSafeHandle tree);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern int git_tree_get_subtree(out GitObjectSafeHandle tree, GitObjectSafeHandle root,
|
||||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath treeentry_path);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern int git_treebuilder_create(out TreeBuilderSafeHandle builder, IntPtr src);
|
||||
|
||||
|
|
|
@ -7,9 +7,6 @@ namespace LibGit2Sharp.Core
|
|||
{
|
||||
private const string libgit2 = "git2";
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern int git_branch_list(out git_strarray array, RepositorySafeHandle repo, GitBranchType flags);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
public static extern int git_reference_list(out git_strarray array, RepositorySafeHandle repo, GitReferenceType flags);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace LibGit2Sharp
|
|||
|
||||
private static GitDiffOptions BuildOptions(IEnumerable<string> paths = null)
|
||||
{
|
||||
var options = new GitDiffOptions { InterhunkLines = 2 };
|
||||
var options = new GitDiffOptions();
|
||||
|
||||
if (paths == null)
|
||||
{
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
<Compile Include="Core\Handles\NotOwnedSafeHandleBase.cs" />
|
||||
<Compile Include="Core\Handles\OidSafeHandle.cs" />
|
||||
<Compile Include="Core\Handles\TreeBuilderSafeHandle.cs" />
|
||||
<Compile Include="Core\Handles\TreeEntrySafeHandle_Owned.cs" />
|
||||
<Compile Include="Core\ReferenceExtensions.cs" />
|
||||
<Compile Include="Core\Handles\ReferenceSafeHandle.cs" />
|
||||
<Compile Include="Core\Handles\SignatureSafeHandle.cs" />
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace LibGit2Sharp
|
|||
|
||||
if (!isWorkDirNull)
|
||||
{
|
||||
Ensure.Success(NativeMethods.git_repository_set_workdir(handle, options.WorkingDirectoryPath));
|
||||
Ensure.Success(NativeMethods.git_repository_set_workdir(handle, options.WorkingDirectoryPath, false));
|
||||
}
|
||||
|
||||
configurationGlobalFilePath = options.GlobalConfigurationLocation;
|
||||
|
|
|
@ -52,30 +52,24 @@ namespace LibGit2Sharp
|
|||
|
||||
using (var obj = new ObjectSafeWrapper(Id, repo))
|
||||
{
|
||||
GitObjectSafeHandle objectPtr;
|
||||
TreeEntrySafeHandle_Owned treeEntryPtr;
|
||||
|
||||
int res = NativeMethods.git_tree_get_subtree(out objectPtr, obj.ObjectPtr, relativePath);
|
||||
int res = NativeMethods.git_tree_entry_bypath(out treeEntryPtr, obj.ObjectPtr, relativePath);
|
||||
|
||||
if (res == (int)GitErrorCode.NotFound)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using (treeEntryPtr)
|
||||
{
|
||||
Ensure.Success(res);
|
||||
|
||||
string posixPath = relativePath.Posix;
|
||||
string filename = posixPath.Split('/').Last();
|
||||
|
||||
TreeEntrySafeHandle handle = NativeMethods.git_tree_entry_byname(objectPtr, filename);
|
||||
objectPtr.SafeDispose();
|
||||
|
||||
if (handle.IsInvalid)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string parentPath = posixPath.Substring(0, posixPath.Length - filename.Length);
|
||||
return new TreeEntry(handle, Id, repo, path.Combine(parentPath));
|
||||
return new TreeEntry(treeEntryPtr, Id, repo, path.Combine(parentPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using LibGit2Sharp.Core;
|
||||
using LibGit2Sharp.Core.Compat;
|
||||
using LibGit2Sharp.Core.Handles;
|
||||
|
@ -26,7 +27,7 @@ namespace LibGit2Sharp
|
|||
protected TreeEntry()
|
||||
{ }
|
||||
|
||||
internal TreeEntry(TreeEntrySafeHandle obj, ObjectId parentTreeId, Repository repo, FilePath parentPath)
|
||||
internal TreeEntry(SafeHandle obj, ObjectId parentTreeId, Repository repo, FilePath parentPath)
|
||||
{
|
||||
this.parentTreeId = parentTreeId;
|
||||
this.repo = repo;
|
||||
|
|
|
@ -1 +1 @@
|
|||
1d94a7d0f6c8cb0d1fcf288a1734a7a5abd1b094
|
||||
14e1bc157a06d4513ce4193e6100a338432b3c88
|
||||
|
|
2
libgit2
2
libgit2
|
@ -1 +1 @@
|
|||
Subproject commit 1d94a7d0f6c8cb0d1fcf288a1734a7a5abd1b094
|
||||
Subproject commit 14e1bc157a06d4513ce4193e6100a338432b3c88
|
Загрузка…
Ссылка в новой задаче