Skip to content

Commit c47885b

Browse files
authored
Merge branch 'dotdevelop' into dotdevelop1
2 parents 77efaaa + 9a974f8 commit c47885b

26 files changed

+421
-133
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using LibGit2Sharp.Core;
4+
5+
namespace LibGit2Sharp
6+
{
7+
/// <summary>
8+
/// The exception that is thrown when an operation which requires an
9+
/// authentication fails.
10+
/// </summary>
11+
[Serializable]
12+
public class AuthenticationException : LibGit2SharpException
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class.
16+
/// </summary>
17+
public AuthenticationException()
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a specified error message.
23+
/// </summary>
24+
/// <param name="message">A message that describes the error.</param>
25+
public AuthenticationException(string message)
26+
: base(message)
27+
{
28+
}
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
32+
/// </summary>
33+
/// <param name="message">The error message that explains the reason for the exception.</param>
34+
/// <param name="innerException">The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.</param>
35+
public AuthenticationException(string message, Exception innerException)
36+
: base(message, innerException)
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a serialized data.
42+
/// </summary>
43+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
44+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
45+
protected AuthenticationException(SerializationInfo info, StreamingContext context)
46+
: base(info, context)
47+
{
48+
}
49+
50+
internal AuthenticationException(string message, GitErrorCode code, GitErrorCategory category)
51+
: base(message, code, category)
52+
{
53+
}
54+
}
55+
}

LibGit2Sharp/BlameHunkCollection.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,21 @@ internal unsafe BlameHunkCollection(Repository repo, RepositoryHandle repoHandle
2828
var rawopts = new git_blame_options
2929
{
3030
version = 1,
31+
FindOptions = new GitDiffFindOptions {
32+
Version = 1,
33+
},
3134
flags = options.Strategy.ToGitBlameOptionFlags(),
3235
min_line = new UIntPtr((uint)options.MinLine),
3336
max_line = new UIntPtr((uint)options.MaxLine),
3437
};
3538

39+
if (options.FindNoRenames)
40+
rawopts.FindOptions.Flags = GitDiffFindFlags.GIT_DIFF_FIND_NO_RENAMES;
41+
else if (options.FindExactRenames)
42+
rawopts.FindOptions.Flags = GitDiffFindFlags.GIT_DIFF_FIND_EXACT_MATCH_ONLY;
43+
else
44+
rawopts.FindOptions.Flags = GitDiffFindFlags.GIT_DIFF_FIND_RENAMES;
45+
3646
if (options.StartingAt != null)
3747
{
3848
fixed (byte* p = rawopts.newest_commit.Id)

LibGit2Sharp/BlameOptions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public enum BlameStrategy
77
{
88
/// <summary>
9-
/// Track renames of the file, but no block movement.
9+
/// Track renames of the file using diff rename detection, but no block movement.
1010
/// </summary>
1111
Default,
1212

@@ -58,5 +58,15 @@ public sealed class BlameOptions
5858
/// If this is set to 0, blame ends with the last line in the file.
5959
/// </summary>
6060
public int MaxLine { get; set; }
61+
62+
/// <summary>
63+
/// Disables rename heuristics, only matching renames on unmodified files.
64+
/// </summary>
65+
public bool FindExactRenames { get; set; }
66+
67+
/// <summary>
68+
/// Fully disable rename checking.
69+
/// </summary>
70+
public bool FindNoRenames { get; set; }
6171
}
6272
}

LibGit2Sharp/Core/Ensure.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@ private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCode, GitE
127127
{ GitErrorCode.Conflict, (m, r, c) => new CheckoutConflictException(m, r, c) },
128128
{ GitErrorCode.LockedFile, (m, r, c) => new LockedFileException(m, r, c) },
129129
{ GitErrorCode.NotFound, (m, r, c) => new NotFoundException(m, r, c) },
130-
{ GitErrorCode.Peel, (m, r, c) => new PeelException(m, r, c) },
130+
{ GitErrorCode.Peel, (m, r, c) => new PeelException(m, r, c) },
131+
{ GitErrorCode.Auth, (m, r, c) => new AuthenticationException(m, r, c) },
131132
};
132133

133134
private static unsafe void HandleError(int result)
134135
{
135136
string errorMessage;
136137
GitErrorCategory errorCategory = GitErrorCategory.Unknown;
137-
GitError* error = NativeMethods.git_error_last();
138+
GitError* error = NativeMethods.giterr_last();
138139

139140
if (error == null)
140141
{

LibGit2Sharp/Core/GitBlame.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ internal enum GitBlameOptionFlags
4444
internal class git_blame_options
4545
{
4646
public uint version = 1;
47+
public GitDiffFindOptions FindOptions;
4748
public GitBlameOptionFlags flags;
4849

4950
public UInt16 min_match_characters;

LibGit2Sharp/Core/GitBuf.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class GitBuf : IDisposable
1212

1313
public void Dispose()
1414
{
15-
Proxy.git_buf_dispose(this);
15+
Proxy.git_buf_free(this);
1616
}
1717
}
1818
}

LibGit2Sharp/Core/GitDiff.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ enum GitDiffFindFlags
350350
// turn on all finding features
351351
GIT_DIFF_FIND_ALL = (0x0ff),
352352

353+
// does no work trying to find renames
354+
GIT_DIFF_FIND_NO_RENAMES = (1 << 8),
355+
353356
// measure similarity ignoring leading whitespace (default)
354357
GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE = 0,
355358
// measure similarity ignoring all whitespace
@@ -367,9 +370,9 @@ enum GitDiffFindFlags
367370
}
368371

369372
[StructLayout(LayoutKind.Sequential)]
370-
internal class GitDiffFindOptions
373+
internal struct GitDiffFindOptions
371374
{
372-
public uint Version = 1;
375+
public uint Version;
373376
public GitDiffFindFlags Flags;
374377
public UInt16 RenameThreshold;
375378
public UInt16 RenameFromRewriteThreshold;

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ private sealed class NativeShutdownObject : CriticalFinalizerObject
216216
}
217217

218218
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
219-
internal static extern unsafe GitError* git_error_last();
219+
internal static extern unsafe GitError* giterr_last();
220220

221221
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
222-
internal static extern void git_error_set_str(
222+
internal static extern void giterr_set_str(
223223
GitErrorCategory error_class,
224224
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string errorString);
225225

226226
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
227-
internal static extern void git_error_set_oom();
227+
internal static extern void giterr_set_oom();
228228

229229
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
230230
internal static extern unsafe UInt32 git_blame_get_hunk_count(git_blame* blame);
@@ -406,7 +406,7 @@ internal static extern unsafe int git_branch_upstream_name(
406406
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string referenceName);
407407

408408
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
409-
internal static extern void git_buf_dispose(GitBuf buf);
409+
internal static extern void git_buf_free(GitBuf buf);
410410

411411
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
412412
internal static extern unsafe int git_checkout_tree(
@@ -646,6 +646,24 @@ internal static extern int git_cred_userpass_plaintext_new(
646646
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username,
647647
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string password);
648648

649+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
650+
internal static extern int git_cred_ssh_key_new(
651+
out IntPtr cred,
652+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username,
653+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string publickey,
654+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string privatekey,
655+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string passphrase);
656+
657+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
658+
internal static extern int git_cred_ssh_key_from_agent(
659+
out IntPtr cred,
660+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username);
661+
662+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
663+
internal static extern int git_cred_username_new(
664+
out IntPtr cred,
665+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username);
666+
649667
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
650668
internal static extern void git_cred_free(IntPtr cred);
651669

@@ -752,7 +770,12 @@ internal static extern unsafe int git_diff_foreach(
752770
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
753771
internal static extern unsafe int git_diff_find_similar(
754772
git_diff* diff,
755-
GitDiffFindOptions options);
773+
IntPtr options);
774+
775+
[DllImport(libgit2)]
776+
internal static extern unsafe int git_diff_find_similar(
777+
git_diff* diff,
778+
ref GitDiffFindOptions options);
756779

757780
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
758781
internal static extern unsafe UIntPtr git_diff_num_deltas(git_diff* diff);

0 commit comments

Comments
 (0)