Skip to content

Commit 5e683b9

Browse files
author
Edward Thomson
committed
Merge pull request #1247
Bring back some pointers
2 parents 746b04d + 93e1d46 commit 5e683b9

File tree

132 files changed

+2607
-2604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2607
-2604
lines changed

LibGit2Sharp.Tests/RefSpecFixture.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ public void RemoteUpdaterSavesRefSpecsPermanently()
105105

106106
using (var repo = new Repository(path))
107107
{
108-
var remote = repo.Network.Remotes["origin"];
109-
repo.Network.Remotes.Update(remote, r => r.FetchRefSpecs = fetchRefSpecs);
108+
using (var remote = repo.Network.Remotes["origin"])
109+
{
110+
repo.Network.Remotes.Update(remote, r => r.FetchRefSpecs = fetchRefSpecs);
111+
}
110112
}
111113

112114
using (var repo = new Repository(path))
@@ -127,22 +129,23 @@ public void CanAddAndRemoveRefSpecs()
127129
var path = SandboxStandardTestRepo();
128130

129131
using (var repo = new Repository(path))
132+
using (var remote = repo.Network.Remotes["origin"])
130133
{
131-
var remote = repo.Network.Remotes["origin"];
132-
133-
remote = repo.Network.Remotes.Update(remote,
134+
using (var updatedRemote = repo.Network.Remotes.Update(remote,
134135
r => r.FetchRefSpecs.Add(newRefSpec),
135-
r => r.PushRefSpecs.Add(newRefSpec));
136-
137-
Assert.Contains(newRefSpec, remote.FetchRefSpecs.Select(r => r.Specification));
138-
Assert.Contains(newRefSpec, remote.PushRefSpecs.Select(r => r.Specification));
139-
140-
remote = repo.Network.Remotes.Update(remote,
141-
r => r.FetchRefSpecs.Remove(newRefSpec),
142-
r => r.PushRefSpecs.Remove(newRefSpec));
143-
144-
Assert.DoesNotContain(newRefSpec, remote.FetchRefSpecs.Select(r => r.Specification));
145-
Assert.DoesNotContain(newRefSpec, remote.PushRefSpecs.Select(r => r.Specification));
136+
r => r.PushRefSpecs.Add(newRefSpec)))
137+
{
138+
Assert.Contains(newRefSpec, updatedRemote.FetchRefSpecs.Select(r => r.Specification));
139+
Assert.Contains(newRefSpec, updatedRemote.PushRefSpecs.Select(r => r.Specification));
140+
141+
using (var updatedRemote2 = repo.Network.Remotes.Update(updatedRemote,
142+
r => r.FetchRefSpecs.Remove(newRefSpec),
143+
r => r.PushRefSpecs.Remove(newRefSpec)))
144+
{
145+
Assert.DoesNotContain(newRefSpec, updatedRemote2.FetchRefSpecs.Select(r => r.Specification));
146+
Assert.DoesNotContain(newRefSpec, updatedRemote2.PushRefSpecs.Select(r => r.Specification));
147+
}
148+
}
146149
}
147150
}
148151

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public virtual void Dispose()
263263
if (LeaksContainer.TypeNames.Any())
264264
{
265265
Assert.False(true, string.Format("Some handles of the following types haven't been properly released: {0}.{1}"
266-
+ "In order to get some help fixing those leaks, uncomment the define LEAKS_TRACKING in SafeHandleBase.cs{1}"
266+
+ "In order to get some help fixing those leaks, uncomment the define LEAKS_TRACKING in Libgit2Object.cs{1}"
267267
+ "and run the tests locally.", string.Join(", ", LeaksContainer.TypeNames), Environment.NewLine));
268268
}
269269
#endif

LibGit2Sharp/BlameHunk.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,35 @@ public class BlameHunk : IEquatable<BlameHunk>
1919
x => x.InitialSignature,
2020
x => x.InitialCommit);
2121

22-
23-
internal BlameHunk(IRepository repository, GitBlameHunk rawHunk)
22+
internal unsafe BlameHunk(IRepository repository, git_blame_hunk* rawHunk)
2423
{
25-
finalCommit = new Lazy<Commit>(() => repository.Lookup<Commit>(rawHunk.FinalCommitId));
26-
origCommit = new Lazy<Commit>(() => repository.Lookup<Commit>(rawHunk.OrigCommitId));
24+
var origId = ObjectId.BuildFromPtr(&rawHunk->orig_commit_id);
25+
var finalId = ObjectId.BuildFromPtr(&rawHunk->final_commit_id);
26+
27+
finalCommit = new Lazy<Commit>(() => repository.Lookup<Commit>(finalId));
28+
origCommit = new Lazy<Commit>(() => repository.Lookup<Commit>(origId));
2729

28-
if (rawHunk.OrigPath != IntPtr.Zero)
30+
31+
if (rawHunk->orig_path != null)
2932
{
30-
InitialPath = LaxUtf8Marshaler.FromNative(rawHunk.OrigPath);
33+
InitialPath = LaxUtf8Marshaler.FromNative(rawHunk->orig_path);
3134
}
32-
LineCount = rawHunk.LinesInHunk.ConvertToInt();
35+
36+
LineCount = (int)rawHunk->lines_in_hunk.ToUInt32();
3337

3438
// Libgit2's line numbers are 1-based
35-
FinalStartLineNumber = rawHunk.FinalStartLineNumber.ConvertToInt() - 1;
36-
InitialStartLineNumber = rawHunk.OrigStartLineNumber.ConvertToInt() - 1;
39+
FinalStartLineNumber = (int)rawHunk->final_start_line_number.ToUInt32() - 1;
40+
InitialStartLineNumber = (int)rawHunk->orig_start_line_number.ToUInt32() - 1;
3741

3842
// Signature objects need to have ownership of their native pointers
39-
if (rawHunk.FinalSignature != IntPtr.Zero)
43+
if (rawHunk->final_signature != null)
4044
{
41-
FinalSignature = new Signature(Proxy.git_signature_dup(rawHunk.FinalSignature));
45+
FinalSignature = new Signature(rawHunk->final_signature);
4246
}
4347

44-
if (rawHunk.OrigSignature != IntPtr.Zero)
48+
if (rawHunk->orig_signature != null)
4549
{
46-
InitialSignature = new Signature(Proxy.git_signature_dup(rawHunk.OrigSignature));
50+
InitialSignature = new Signature(rawHunk->orig_signature);
4751
}
4852
}
4953

LibGit2Sharp/BlameHunkCollection.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Runtime.InteropServices;
56
using LibGit2Sharp.Core;
67
using LibGit2Sharp.Core.Handles;
78

@@ -20,26 +21,32 @@ public class BlameHunkCollection : IEnumerable<BlameHunk>
2021
/// </summary>
2122
protected BlameHunkCollection() { }
2223

23-
internal BlameHunkCollection(Repository repo, RepositorySafeHandle repoHandle, string path, BlameOptions options)
24+
internal unsafe BlameHunkCollection(Repository repo, RepositoryHandle repoHandle, string path, BlameOptions options)
2425
{
2526
this.repo = repo;
2627

27-
var rawopts = new GitBlameOptions
28+
var rawopts = new git_blame_options
2829
{
2930
version = 1,
3031
flags = options.Strategy.ToGitBlameOptionFlags(),
31-
MinLine = new UIntPtr((uint)options.MinLine),
32-
MaxLine = new UIntPtr((uint)options.MaxLine),
32+
min_line = new UIntPtr((uint)options.MinLine),
33+
max_line = new UIntPtr((uint)options.MaxLine),
3334
};
3435

3536
if (options.StartingAt != null)
3637
{
37-
rawopts.NewestCommit = repo.Committish(options.StartingAt).Oid;
38+
fixed (byte* p = rawopts.newest_commit.Id)
39+
{
40+
Marshal.Copy(repo.Committish(options.StartingAt).Oid.Id, 0, new IntPtr(p), git_oid.Size);
41+
}
3842
}
3943

4044
if (options.StoppingAt != null)
4145
{
42-
rawopts.OldestCommit = repo.Committish(options.StoppingAt).Oid;
46+
fixed (byte* p = rawopts.oldest_commit.Id)
47+
{
48+
Marshal.Copy(repo.Committish(options.StoppingAt).Oid.Id, 0, new IntPtr(p), git_oid.Size);
49+
}
4350
}
4451

4552
using (var blameHandle = Proxy.git_blame_file(repoHandle, path, rawopts))

LibGit2Sharp/BranchCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public virtual void Remove(Branch branch)
199199
{
200200
Ensure.ArgumentNotNull(branch, "branch");
201201

202-
using (ReferenceSafeHandle referencePtr = repo.Refs.RetrieveReferencePtr(branch.CanonicalName))
202+
using (ReferenceHandle referencePtr = repo.Refs.RetrieveReferencePtr(branch.CanonicalName))
203203
{
204204
Proxy.git_branch_delete(referencePtr);
205205
}
@@ -267,7 +267,7 @@ public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite)
267267
branch.FriendlyName);
268268
}
269269

270-
using (ReferenceSafeHandle referencePtr = repo.Refs.RetrieveReferencePtr(Reference.LocalBranchPrefix + branch.FriendlyName))
270+
using (ReferenceHandle referencePtr = repo.Refs.RetrieveReferencePtr(Reference.LocalBranchPrefix + branch.FriendlyName))
271271
{
272272
using (Proxy.git_branch_move(referencePtr, newName, allowOverwrite))
273273
{ }

LibGit2Sharp/CertificateSsh.cs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using LibGit2Sharp.Core;
2-
using System;
1+
using System;
32
using System.Runtime.InteropServices;
3+
using LibGit2Sharp.Core;
44

55
namespace LibGit2Sharp
66
{
@@ -39,20 +39,32 @@ protected CertificateSsh()
3939
/// True if we have the SHA1 hostkey hash from the server
4040
/// </summary>public readonly bool HasSHA1;
4141

42-
internal CertificateSsh(GitCertificateSsh cert)
42+
internal unsafe CertificateSsh(git_certificate_ssh* cert)
4343
{
4444

45-
HasMD5 = cert.type.HasFlag(GitCertificateSshType.MD5);
46-
HasSHA1 = cert.type.HasFlag(GitCertificateSshType.SHA1);
45+
HasMD5 = cert->type.HasFlag(GitCertificateSshType.MD5);
46+
HasSHA1 = cert->type.HasFlag(GitCertificateSshType.SHA1);
4747

4848
HashMD5 = new byte[16];
49-
cert.HashMD5.CopyTo(HashMD5, 0);
49+
fixed (byte* p = &HashMD5[0])
50+
{
51+
for (var i = 0; i < HashMD5.Length; i++)
52+
{
53+
HashMD5[i] = p[i];
54+
}
55+
}
5056

5157
HashSHA1 = new byte[20];
52-
cert.HashSHA1.CopyTo(HashSHA1, 0);
58+
fixed (byte* p = &HashSHA1[0])
59+
{
60+
for (var i = 0; i < HashSHA1.Length; i++)
61+
{
62+
HashSHA1[i] = p[i];
63+
}
64+
}
5365
}
5466

55-
internal IntPtr ToPointer()
67+
internal unsafe IntPtr ToPointer()
5668
{
5769
GitCertificateSshType sshCertType = 0;
5870
if (HasMD5)
@@ -64,13 +76,27 @@ internal IntPtr ToPointer()
6476
sshCertType |= GitCertificateSshType.SHA1;
6577
}
6678

67-
var gitCert = new GitCertificateSsh
79+
var gitCert = new git_certificate_ssh()
6880
{
6981
cert_type = GitCertificateType.Hostkey,
7082
type = sshCertType,
7183
};
72-
HashMD5.CopyTo(gitCert.HashMD5, 0);
73-
HashSHA1.CopyTo(gitCert.HashSHA1, 0);
84+
85+
fixed (byte *p = &HashMD5[0])
86+
{
87+
for (var i = 0; i < HashMD5.Length; i++)
88+
{
89+
gitCert.HashMD5[i] = p[i];
90+
}
91+
}
92+
93+
fixed (byte *p = &HashSHA1[0])
94+
{
95+
for (var i = 0; i < HashSHA1.Length; i++)
96+
{
97+
gitCert.HashSHA1[i] = p[i];
98+
}
99+
}
74100

75101
var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(gitCert));
76102
Marshal.StructureToPtr(gitCert, ptr, false);

LibGit2Sharp/CertificateX509.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ protected CertificateX509()
2222
/// </summary>
2323
public virtual X509Certificate Certificate { get; private set; }
2424

25-
internal CertificateX509(GitCertificateX509 cert)
25+
internal unsafe CertificateX509(git_certificate_x509* cert)
2626
{
27-
int len = checked((int) cert.len.ToUInt32());
27+
int len = checked((int) cert->len.ToUInt32());
2828
byte[] data = new byte[len];
29-
Marshal.Copy(cert.data, data, 0, len);
29+
Marshal.Copy(new IntPtr(cert->data), data, 0, len);
3030
Certificate = new X509Certificate(data);
3131
}
3232

33-
internal IntPtr ToPointers(out IntPtr dataPtr)
33+
internal unsafe IntPtr ToPointers(out IntPtr dataPtr)
3434
{
3535
var certData = Certificate.Export(X509ContentType.Cert);
3636
dataPtr = Marshal.AllocHGlobal(certData.Length);
3737
Marshal.Copy(certData, 0, dataPtr, certData.Length);
38-
var gitCert = new GitCertificateX509()
38+
var gitCert = new git_certificate_x509()
3939
{
4040
cert_type = GitCertificateType.X509,
41-
data = dataPtr,
41+
data = (byte*) dataPtr.ToPointer(),
4242
len = (UIntPtr)certData.LongLength,
4343
};
4444

LibGit2Sharp/Commit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private IEnumerable<Note> RetrieveNotesOfCommit(ObjectId oid)
106106
return repo.Notes[oid];
107107
}
108108

109-
private static string RetrieveEncodingOf(GitObjectSafeHandle obj)
109+
private static string RetrieveEncodingOf(ObjectHandle obj)
110110
{
111111
string encoding = Proxy.git_commit_message_encoding(obj);
112112

LibGit2Sharp/CommitLog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public IEnumerable<LogEntry> QueryBy(string path, FollowFilter filter)
108108
private class CommitEnumerator : IEnumerator<Commit>
109109
{
110110
private readonly Repository repo;
111-
private readonly RevWalkerSafeHandle handle;
111+
private readonly RevWalkerHandle handle;
112112
private ObjectId currentOid;
113113

114114
public CommitEnumerator(Repository repo, CommitFilter filter)
@@ -167,7 +167,7 @@ private void Dispose(bool disposing)
167167
handle.SafeDispose();
168168
}
169169

170-
private delegate void HidePushSignature(RevWalkerSafeHandle handle, ObjectId id);
170+
private delegate void HidePushSignature(RevWalkerHandle handle, ObjectId id);
171171

172172
private void InternalHidePush(IList<object> identifier, HidePushSignature hidePush)
173173
{

0 commit comments

Comments
 (0)