forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibgit2UnsafeHelper.cs
More file actions
60 lines (49 loc) · 1.82 KB
/
Copy pathLibgit2UnsafeHelper.cs
File metadata and controls
60 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
namespace LibGit2Sharp.Core
{
internal static unsafe class Libgit2UnsafeHelper
{
public static IList<string> ListAllReferenceNames(RepositorySafeHandle repo, GitReferenceType types)
{
UnSafeNativeMethods.git_strarray strArray;
int res = UnSafeNativeMethods.git_reference_listall(out strArray, repo, types);
Ensure.Success(res);
return BuildListOf(strArray);
}
public static IList<string> ListAllRemoteNames(RepositorySafeHandle repo)
{
UnSafeNativeMethods.git_strarray strArray;
int res = UnSafeNativeMethods.git_remote_list(out strArray, repo);
Ensure.Success(res);
return BuildListOf(strArray);
}
public static IList<string> ListAllTagNames(RepositorySafeHandle repo)
{
UnSafeNativeMethods.git_strarray strArray;
int res = UnSafeNativeMethods.git_tag_list(out strArray, repo);
Ensure.Success(res);
return BuildListOf(strArray);
}
private static IList<string> BuildListOf(UnSafeNativeMethods.git_strarray strArray)
{
var list = new List<string>();
try
{
UnSafeNativeMethods.git_strarray* gitStrArray = &strArray;
int numberOfEntries = gitStrArray->size.ToInt32();
for (uint i = 0; i < numberOfEntries; i++)
{
var name = new string(gitStrArray->strings[i]);
list.Add(name);
}
list.Sort(StringComparer.Ordinal);
}
finally
{
UnSafeNativeMethods.git_strarray_free(ref strArray);
}
return list;
}
}
}