Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Lib/NativeBinaries/amd64/git2.dll
Binary file not shown.
Binary file modified Lib/NativeBinaries/amd64/git2.pdb
Binary file not shown.
Binary file modified Lib/NativeBinaries/x86/git2.dll
Binary file not shown.
Binary file modified Lib/NativeBinaries/x86/git2.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/CloneFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void CallsProgressCallbacks(string url)

var scd = BuildSelfCleaningDirectory();
using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath,
onTransferProgress: (_) => transferWasCalled = true,
onTransferProgress: (_) => { transferWasCalled = true; return 0; },
onCheckoutProgress: (a, b, c) => checkoutWasCalled = true))
{
Assert.True(transferWasCalled);
Expand Down
5 changes: 1 addition & 4 deletions LibGit2Sharp/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@ private string RemoteNameFromLocalBranch()

private string RemoteNameFromRemoteTrackingBranch()
{
using (ReferenceSafeHandle branchPtr = repo.Refs.RetrieveReferencePtr(CanonicalName))
{
return Proxy.git_branch_remote_name(repo.Handle, branchPtr);
}
return Proxy.git_branch_remote_name(repo.Handle, CanonicalName);
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion LibGit2Sharp/BranchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ public virtual Branch Move(Branch branch, string newName, bool allowOverwrite =

using (ReferenceSafeHandle referencePtr = repo.Refs.RetrieveReferencePtr("refs/heads/" + branch.Name))
{
Proxy.git_branch_move(referencePtr, newName, allowOverwrite);
using (ReferenceSafeHandle ref_out = Proxy.git_branch_move(referencePtr, newName, allowOverwrite))
{
}
}

return this[newName];
Expand Down
5 changes: 1 addition & 4 deletions LibGit2Sharp/BranchUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ private void GetUpstreamInformation(string canonicalName, out string remoteName,
}
else if (canonicalName.StartsWith(remotePrefix, StringComparison.Ordinal))
{
using (ReferenceSafeHandle branchPtr = repo.Refs.RetrieveReferencePtr(canonicalName))
{
remoteName = Proxy.git_branch_remote_name(repo.Handle, branchPtr);
}
remoteName = Proxy.git_branch_remote_name(repo.Handle, canonicalName);

Remote remote = repo.Network.Remotes.RemoteForName(remoteName);
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repo.Handle, remote.Name, true))
Expand Down
11 changes: 4 additions & 7 deletions LibGit2Sharp/Core/GitDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,9 @@ public void Dispose()
[Flags]
internal enum GitDiffFileFlags
{
GIT_DIFF_FILE_VALID_OID = (1 << 0),
GIT_DIFF_FILE_FREE_PATH = (1 << 1),
GIT_DIFF_FILE_BINARY = (1 << 2),
GIT_DIFF_FILE_NOT_BINARY = (1 << 3),
GIT_DIFF_FILE_FREE_DATA = (1 << 4),
GIT_DIFF_FILE_UNMAP_DATA = (1 << 5),
GIT_DIFF_FLAG_BINARY = (1 << 0),
GIT_DIFF_FLAG_NOT_BINARY = (1 << 1),
GIT_DIFF_FLAG_VALID_OID = (1 << 2),
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -218,7 +215,7 @@ internal class GitDiffDelta
public GitDiffFile NewFile;
public ChangeKind Status;
public uint Similarity;
public int Binary;
public uint Flags;
}

[StructLayout(LayoutKind.Sequential)]
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Core/GitDiffExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ internal static class GitDiffExtensions
public static bool IsBinary(this GitDiffDelta delta)
{
//TODO Fix the interop issue on amd64 and use GitDiffDelta.Binary
return delta.OldFile.Flags.HasFlag(GitDiffFileFlags.GIT_DIFF_FILE_BINARY)
|| delta.NewFile.Flags.HasFlag(GitDiffFileFlags.GIT_DIFF_FILE_BINARY);
return delta.OldFile.Flags.HasFlag(GitDiffFileFlags.GIT_DIFF_FLAG_BINARY)
|| delta.NewFile.Flags.HasFlag(GitDiffFileFlags.GIT_DIFF_FLAG_BINARY);
}
}
}
9 changes: 6 additions & 3 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ internal static extern int git_branch_foreach(

[DllImport(libgit2)]
internal static extern int git_branch_move(
out ReferenceSafeHandle ref_out,
ReferenceSafeHandle reference,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string new_branch_name,
[MarshalAs(UnmanagedType.Bool)] bool force);
Expand All @@ -146,7 +147,7 @@ internal static extern int git_branch_remote_name(
byte[] remote_name_out,
UIntPtr buffer_size,
RepositorySafeHandle repo,
ReferenceSafeHandle branch);
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string canonical_branch_name);

[DllImport(libgit2)]
internal static extern int git_branch_tracking_name(
Expand Down Expand Up @@ -648,6 +649,7 @@ internal static extern int git_reference_lookup(

[DllImport(libgit2)]
internal static extern int git_reference_rename(
out ReferenceSafeHandle ref_out,
ReferenceSafeHandle reference,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string newName,
[MarshalAs(UnmanagedType.Bool)] bool force);
Expand All @@ -656,10 +658,11 @@ internal static extern int git_reference_rename(
internal static extern int git_reference_resolve(out ReferenceSafeHandle resolvedReference, ReferenceSafeHandle reference);

[DllImport(libgit2)]
internal static extern int git_reference_set_target(ReferenceSafeHandle reference, ref GitOid id);
internal static extern int git_reference_set_target(out ReferenceSafeHandle ref_out, ReferenceSafeHandle reference, ref GitOid id);

[DllImport(libgit2)]
internal static extern int git_reference_symbolic_set_target(
out ReferenceSafeHandle ref_out,
ReferenceSafeHandle reference,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string target);

Expand Down Expand Up @@ -986,7 +989,7 @@ internal static extern int git_tag_delete(
[DllImport(libgit2)]
internal static extern void git_threads_shutdown();

internal delegate void git_transfer_progress_callback(ref GitTransferProgress stats, IntPtr payload);
internal delegate int git_transfer_progress_callback(ref GitTransferProgress stats, IntPtr payload);

[DllImport(libgit2)]
internal static extern uint git_tree_entry_filemode(SafeHandle entry);
Expand Down
38 changes: 25 additions & 13 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,27 @@ public static ICollection<TResult> git_branch_foreach<TResult>(
return git_foreach(resultSelector, c => NativeMethods.git_branch_foreach(repo, branch_type, (x, y, p) => c(x, y, p), IntPtr.Zero));
}

public static void git_branch_move(ReferenceSafeHandle reference, string new_branch_name, bool force)
public static ReferenceSafeHandle git_branch_move(ReferenceSafeHandle reference, string new_branch_name, bool force)
{
using (ThreadAffinity())
{
int res = NativeMethods.git_branch_move(reference, new_branch_name, force);
ReferenceSafeHandle ref_out;
int res = NativeMethods.git_branch_move(out ref_out, reference, new_branch_name, force);
Ensure.ZeroResult(res);
return ref_out;
}
}

public static string git_branch_remote_name(RepositorySafeHandle repo, ReferenceSafeHandle branch)
public static string git_branch_remote_name(RepositorySafeHandle repo, string canonical_branch_name)
{
using (ThreadAffinity())
{
int bufSize = NativeMethods.git_branch_remote_name(null, UIntPtr.Zero, repo, branch);
int bufSize = NativeMethods.git_branch_remote_name(null, UIntPtr.Zero, repo, canonical_branch_name);
Ensure.Int32Result(bufSize);

var buffer = new byte[bufSize];

int res = NativeMethods.git_branch_remote_name(buffer, (UIntPtr)buffer.Length, repo, branch);
int res = NativeMethods.git_branch_remote_name(buffer, (UIntPtr)buffer.Length, repo, canonical_branch_name);
Ensure.Int32Result(res);

return Utf8Marshaler.Utf8FromBuffer(buffer) ?? string.Empty;
Expand Down Expand Up @@ -1124,8 +1126,6 @@ public static void git_reference_delete(ReferenceSafeHandle reference)
using (ThreadAffinity())
{
int res = NativeMethods.git_reference_delete(reference);
reference.SetHandleAsInvalid();

Ensure.ZeroResult(res);
}
}
Expand Down Expand Up @@ -1192,12 +1192,16 @@ public static ObjectId git_reference_oid(ReferenceSafeHandle reference)
return NativeMethods.git_reference_target(reference).MarshalAsObjectId();
}

public static void git_reference_rename(ReferenceSafeHandle reference, string newName, bool allowOverwrite)
public static ReferenceSafeHandle git_reference_rename(ReferenceSafeHandle reference, string newName, bool allowOverwrite)
{
using (ThreadAffinity())
{
int res = NativeMethods.git_reference_rename(reference, newName, allowOverwrite);
ReferenceSafeHandle ref_out;

int res = NativeMethods.git_reference_rename(out ref_out, reference, newName, allowOverwrite);
Ensure.ZeroResult(res);

return ref_out;
}
}

Expand All @@ -1219,22 +1223,30 @@ public static ReferenceSafeHandle git_reference_resolve(ReferenceSafeHandle refe
}
}

public static void git_reference_set_oid(ReferenceSafeHandle reference, ObjectId id)
public static ReferenceSafeHandle git_reference_set_target(ReferenceSafeHandle reference, ObjectId id)
{
using (ThreadAffinity())
{
GitOid oid = id.Oid;
int res = NativeMethods.git_reference_set_target(reference, ref oid);
ReferenceSafeHandle ref_out;

int res = NativeMethods.git_reference_set_target(out ref_out, reference, ref oid);
Ensure.ZeroResult(res);

return ref_out;
}
}

public static void git_reference_set_target(ReferenceSafeHandle reference, string target)
public static ReferenceSafeHandle git_reference_symbolic_set_target(ReferenceSafeHandle reference, string target)
{
using (ThreadAffinity())
{
int res = NativeMethods.git_reference_symbolic_set_target(reference, target);
ReferenceSafeHandle ref_out;

int res = NativeMethods.git_reference_symbolic_set_target(out ref_out, reference, target);
Ensure.ZeroResult(res);

return ref_out;
}
}

Expand Down
1 change: 1 addition & 0 deletions LibGit2Sharp/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private GitDiffOptions BuildOptions(DiffOptions diffOptions, IEnumerable<string>
var options = new GitDiffOptions();

options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_TYPECHANGE;
options.ContextLines = 3;

if (diffOptions.HasFlag(DiffOptions.IncludeUntracked))
{
Expand Down
3 changes: 2 additions & 1 deletion LibGit2Sharp/Handlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
/// Delegate definition for transfer progress callback.
/// </summary>
/// <param name="progress">The <see cref = "TransferProgress" /> object containing progress information.</param>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include the return value in the comments for the delegate?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely I can.

public delegate void TransferProgressHandler(TransferProgress progress);
/// <returns>Return negative integer to cancel.</returns>
public delegate int TransferProgressHandler(TransferProgress progress);

/// <summary>
/// Delegate definition to handle reporting errors when updating references on the remote.
Expand Down
19 changes: 11 additions & 8 deletions LibGit2Sharp/ReferenceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ public virtual Reference Move(Reference reference, string newName, bool allowOve

using (ReferenceSafeHandle handle = RetrieveReferencePtr(reference.CanonicalName))
{
Proxy.git_reference_rename(handle, newName, allowOverwrite);

return Reference.BuildFromPtr<Reference>(handle, repo);
using (ReferenceSafeHandle handle_out = Proxy.git_reference_rename(handle, newName, allowOverwrite))
{
return Reference.BuildFromPtr<Reference>(handle_out, repo);
}
}
}

Expand All @@ -181,7 +182,7 @@ public virtual Reference UpdateTarget(Reference directRef, ObjectId targetId)
Ensure.ArgumentNotNull(targetId, "targetId");

return UpdateTarget(directRef, targetId,
(h, id) => Proxy.git_reference_set_oid(h, id));
(h, id) => Proxy.git_reference_set_target(h, id));
}

/// <summary>
Expand All @@ -196,10 +197,10 @@ public virtual Reference UpdateTarget(Reference symbolicRef, Reference targetRef
Ensure.ArgumentNotNull(targetRef, "targetRef");

return UpdateTarget(symbolicRef, targetRef,
(h, r) => Proxy.git_reference_set_target(h, r.CanonicalName));
(h, r) => Proxy.git_reference_symbolic_set_target(h, r.CanonicalName));
}

private Reference UpdateTarget<T>(Reference reference, T target, Action<ReferenceSafeHandle, T> setter)
private Reference UpdateTarget<T>(Reference reference, T target, Func<ReferenceSafeHandle, T, ReferenceSafeHandle> setter)
{
if (reference.CanonicalName == "HEAD")
{
Expand All @@ -219,8 +220,10 @@ private Reference UpdateTarget<T>(Reference reference, T target, Action<Referenc

using (ReferenceSafeHandle referencePtr = RetrieveReferencePtr(reference.CanonicalName))
{
setter(referencePtr, target);
return Reference.BuildFromPtr<Reference>(referencePtr, repo);
using (ReferenceSafeHandle ref_out = setter(referencePtr, target))
{
return Reference.BuildFromPtr<Reference>(ref_out, repo);
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions LibGit2Sharp/TransferCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ internal static NativeMethods.git_transfer_progress_callback GenerateCallback(Tr
/// </summary>
/// <param name="progress"><see cref = "GitTransferProgress" /> structure containing progress information.</param>
/// <param name="payload">Payload data.</param>
private void OnGitTransferProgress(ref GitTransferProgress progress, IntPtr payload)
/// <returns>the result of the wrapped <see cref = "TransferProgressHandler" /></returns>
private int OnGitTransferProgress(ref GitTransferProgress progress, IntPtr payload)
{
onTransferProgress(new TransferProgress(progress));
return onTransferProgress(new TransferProgress(progress));
}
}
}
2 changes: 1 addition & 1 deletion LibGit2Sharp/libgit2_hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
40a605104c2060c2bc5a08dfb62cafe473baeb21
eef7e80e68a530f8ce1d1ec196d41fc33a1ced6e
2 changes: 1 addition & 1 deletion libgit2
Submodule libgit2 updated 206 files