Skip to content

Commit 1803553

Browse files
angusbjonesjamill
authored andcommitted
Removed unnecessary changes to Tests project.
MergeFixture: Cleaned usings & removed unused method. NativeMethods: Used suggested signature for git_merge. Added ref+fetchhead git_merge_froms just in case they could be used in future (Should I revert this, I'm not sure on your rules about unused methods in a wrapper?) Proxy: Split git_merge and git_merge_from_oid into separate methods and used suggested signature. Fixed the result checking for boolean C calls in is_uptodate and is_fastforward. GitMergeResult: Renamed to MergeResult, put loading prop values in constructor. Repository: Replaced MergeOnto with Merge.
1 parent 4f492d3 commit 1803553

File tree

8 files changed

+83
-111
lines changed

8 files changed

+83
-111
lines changed

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,6 @@
4242
<WarningLevel>4</WarningLevel>
4343
<DocumentationFile />
4444
</PropertyGroup>
45-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
46-
<DebugSymbols>true</DebugSymbols>
47-
<OutputPath>bin\x86\Debug\</OutputPath>
48-
<DefineConstants>TRACE;DEBUG;NET35</DefineConstants>
49-
<DebugType>full</DebugType>
50-
<PlatformTarget>x86</PlatformTarget>
51-
<ErrorReport>prompt</ErrorReport>
52-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
53-
</PropertyGroup>
54-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
55-
<OutputPath>bin\x86\Release\</OutputPath>
56-
<DefineConstants>TRACE</DefineConstants>
57-
<Optimize>true</Optimize>
58-
<DebugType>pdbonly</DebugType>
59-
<PlatformTarget>x86</PlatformTarget>
60-
<ErrorReport>prompt</ErrorReport>
61-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
62-
</PropertyGroup>
63-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Leaks|x86'">
64-
<DebugSymbols>true</DebugSymbols>
65-
<OutputPath>bin\x86\Leaks\</OutputPath>
66-
<DefineConstants>TRACE;DEBUG;NET35;LEAKS</DefineConstants>
67-
<DebugType>full</DebugType>
68-
<PlatformTarget>x86</PlatformTarget>
69-
<ErrorReport>prompt</ErrorReport>
70-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
71-
</PropertyGroup>
7245
<ItemGroup>
7346
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
7447
<SpecificVersion>False</SpecificVersion>
@@ -158,9 +131,6 @@
158131
<Name>LibGit2Sharp</Name>
159132
</ProjectReference>
160133
</ItemGroup>
161-
<ItemGroup>
162-
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
163-
</ItemGroup>
164134
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
165135
<PropertyGroup>
166136
<NativeBinariesDirectory>$(MSBuildProjectDirectory)\..\Lib\NativeBinaries</NativeBinariesDirectory>

LibGit2Sharp.Tests/MergeFixture.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using System.Linq;
2-
using LibGit2Sharp.Tests.TestHelpers;
1+
using LibGit2Sharp.Tests.TestHelpers;
2+
using System.Linq;
33
using Xunit;
4-
using System;
54

65
namespace LibGit2Sharp.Tests
76
{
@@ -97,24 +96,12 @@ public void CanMergeRepos()
9796
secondBranch.Checkout();
9897
AddFileCommitToRepo(repo, "second branch file");
9998

100-
repo.MergeOnto(repo.Branches["FirstBranch"].Tip);
99+
repo.Merge(repo.Branches["FirstBranch"].Tip);
101100

102101
repo.Commit("Merge First+Second");
103102
}
104103
}
105104

106-
private Commit AddCommitToRepo(IRepository repository)
107-
{
108-
string random = Guid.NewGuid().ToString();
109-
string filename = random + ".txt";
110-
111-
Touch(repository.Info.WorkingDirectory, filename, random);
112-
113-
repository.Index.Stage(filename);
114-
115-
return repository.Commit("New commit", Constants.Signature, Constants.Signature);
116-
}
117-
118105
private Commit AddFileCommitToRepo(IRepository repository, string filename, string content = null)
119106
{
120107
filename = filename + ".txt";

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,20 +570,34 @@ internal static extern int git_merge_base(
570570
GitObjectSafeHandle one,
571571
GitObjectSafeHandle two);
572572

573+
[DllImport(libgit2)]
574+
internal static extern int git_merge_head_from_ref(
575+
out GitMergeHeadHandle mergehead,
576+
RepositorySafeHandle repo,
577+
ReferenceSafeHandle reference);
578+
579+
[DllImport(libgit2)]
580+
internal static extern int git_merge_head_from_fetchhead(
581+
out GitMergeHeadHandle mergehead,
582+
RepositorySafeHandle repo,
583+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string branch_name,
584+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote_url,
585+
ref GitOid oid);
586+
573587
[DllImport(libgit2)]
574588
internal static extern int git_merge_head_from_oid(
575-
out GitMergeHeadHandle their_heads,
589+
out GitMergeHeadHandle mergehead,
576590
RepositorySafeHandle repo,
577-
ref GitOid mergeBase);
591+
ref GitOid oid);
578592

579593
[DllImport(libgit2)]
580594
internal static extern int git_merge(
581595
out GitMergeResultHandle mergeResult,
582596
RepositorySafeHandle repo,
583-
ref GitMergeHeadHandle their_heads,
597+
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] [In] IntPtr[] their_heads,
584598
UIntPtr their_heads_len,
585599
ref GitMergeOpts given_opts);
586-
600+
587601
[DllImport(libgit2)]
588602
internal static extern int git_merge_result_is_uptodate(
589603
GitMergeResultHandle merge_result);

LibGit2Sharp/Core/Proxy.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -948,30 +948,44 @@ public static ObjectId git_merge_base(RepositorySafeHandle repo, Commit first, C
948948
}
949949
}
950950

951-
public static GitMergeResult git_merge(RepositorySafeHandle repo, GitMergeOpts opts, GitOid oid)
951+
public static GitMergeHeadHandle git_merge_head_from_oid(RepositorySafeHandle repo, GitOid oid)
952952
{
953953
using (ThreadAffinity())
954954
{
955-
GitMergeHeadHandle their_heads;
955+
GitMergeHeadHandle their_head;
956956

957-
int res1 = NativeMethods.git_merge_head_from_oid(out their_heads, repo, ref oid);
958-
if (res1 == (int)GitErrorCode.NotFound)
957+
int res = NativeMethods.git_merge_head_from_oid(out their_head, repo, ref oid);
958+
if (res == (int)GitErrorCode.NotFound)
959959
return null;
960960

961-
Ensure.ZeroResult(res1);
961+
Ensure.ZeroResult(res);
962+
963+
return their_head;
964+
}
965+
}
962966

967+
public static GitMergeResultHandle git_merge(RepositorySafeHandle repo, GitMergeHeadHandle[] heads, GitMergeOpts options)
968+
{
969+
using (ThreadAffinity())
970+
{
963971
GitMergeResultHandle ret;
964-
965-
int res2 = NativeMethods.git_merge(out ret, repo, ref their_heads, (UIntPtr)1, ref opts);
966972

967-
if (res2 == (int)GitErrorCode.NotFound)
973+
IntPtr[] their_heads = new IntPtr[heads.Length];
974+
for (int i = 0; i < heads.Length; i++)
968975
{
969-
return null;
976+
their_heads[i] = heads[i].DangerousGetHandle();
970977
}
971978

972-
Ensure.ZeroResult(res2);
979+
int res = NativeMethods.git_merge(
980+
out ret,
981+
repo,
982+
their_heads,
983+
(UIntPtr)their_heads.Length,
984+
ref options);
985+
986+
Ensure.ZeroResult(res);
973987

974-
return new GitMergeResult(ret);
988+
return ret;
975989
}
976990
}
977991

@@ -980,7 +994,7 @@ public static bool git_merge_result_is_uptodate(GitMergeResultHandle handle)
980994
using (ThreadAffinity())
981995
{
982996
int res = NativeMethods.git_merge_result_is_uptodate(handle);
983-
Ensure.ZeroResult(res);
997+
Ensure.BooleanResult(res);
984998

985999
return (res == 1);
9861000
}
@@ -991,7 +1005,7 @@ public static bool git_merge_result_is_fastforward(GitMergeResultHandle handle)
9911005
using (ThreadAffinity())
9921006
{
9931007
int res = NativeMethods.git_merge_result_is_fastforward(handle);
994-
Ensure.ZeroResult(res);
1008+
Ensure.BooleanResult(res);
9951009

9961010
return (res == 1);
9971011
}

LibGit2Sharp/GitMergeResult.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<Compile Include="PushOptions.cs" />
9595
<Compile Include="Core\GitBuf.cs" />
9696
<Compile Include="FilteringOptions.cs" />
97-
<Compile Include="GitMergeResult.cs" />
97+
<Compile Include="MergeResult.cs" />
9898
<Compile Include="ResetMode.cs" />
9999
<Compile Include="NoteCollectionExtensions.cs" />
100100
<Compile Include="RefSpecDirection.cs" />

LibGit2Sharp/MergeResult.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using LibGit2Sharp.Core;
2+
using LibGit2Sharp.Core.Handles;
3+
using System.Diagnostics;
4+
5+
namespace LibGit2Sharp
6+
{
7+
public class MergeResult
8+
{
9+
public MergeResult(){}
10+
internal MergeResult(GitMergeResultHandle handle)
11+
{
12+
_isUpToDate = Proxy.git_merge_result_is_uptodate(handle);
13+
_isUpToDate = Proxy.git_merge_result_is_fastforward(handle);
14+
}
15+
16+
private bool _isUpToDate;
17+
public virtual bool IsUpToDate
18+
{
19+
get { return _isUpToDate; }
20+
}
21+
22+
private bool _isFastForward;
23+
public virtual bool IsFastForward
24+
{
25+
get { return _isFastForward; }
26+
}
27+
}
28+
}

LibGit2Sharp/Repository.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,18 +1033,19 @@ public IEnumerable<MergeHead> MergeHeads
10331033
}
10341034

10351035
/// <summary>
1036-
/// Merges the HEAD onto the given commit.
1036+
/// Merges the given commit into HEAD.
10371037
/// </summary>
1038-
public void MergeOnto(
1039-
Commit commit)
1038+
public MergeResult Merge(Commit commit)
10401039
{
1040+
var mergeHeadHandle = Proxy.git_merge_head_from_oid(Handle, commit.Id.Oid);
1041+
10411042
GitMergeOpts opts = new GitMergeOpts()
10421043
{
10431044
Version = 1,
1044-
MergeTreeOpts = { Version = 1, Metric = UIntPtr.Zero },
1045+
MergeTreeOpts = { Version = 1 },
10451046
CheckoutOpts = { version = 1 }
10461047
};
1047-
Proxy.git_merge(Handle, opts, commit.Id.Oid);
1048+
return new MergeResult(Proxy.git_merge(Handle, new GitMergeHeadHandle[] { mergeHeadHandle }, opts));
10481049
}
10491050

10501051
internal StringComparer PathComparer

0 commit comments

Comments
 (0)