Skip to content

Commit 96df5f8

Browse files
bennulltoken
authored andcommitted
Update libgit2 binaries to 5aee963
libgit2/libgit2@b641c00...5aee963 This also change naming convention of libgit2 binaries. Each LibGit2Sharp version works against a specific version of libgit2. LibGit2Sharp managed code relies on the dynamic loader to find the proper libgit2 binary. This binary is located in a directory structure next to the managed assembly, and the loader is instructed to search within this directory structure. Up until now, the binary being searched for was bearing a generic name: [lib]git2.(dll|so|dylib). However, on Windows, if one older version of the native binary, with the same name, is already loaded in the memory, the loader will reuse this one, no matter what directory it's been loaded from. Chances are great that this old libgit2 version is incompatible with what the newer version of LibGit2Sharp expects from its API or behavior. In order to mitigate this, libgit2 binaries are now suffixed with the libgit2 commit sha they've been build from and LibGit2Sharp will bind to a specifically named binary: - git2-{short_sha}.dll on Windows - libgit2-{short_sha}.so on Linux - libgit2-{short_sha}.dylib on Mac OS X. This should allow one to run two different future version of LibGit2Sharp, side by side, without any name clash.
1 parent 96553df commit 96df5f8

21 files changed

+60
-28
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ _ReSharper*/
3434
*.pidb
3535
*.userprefs
3636
*.swp
37-
*.DotSettings
37+
*.DotSettings
38+
39+
!Lib/NativeBinaries/*/*.pdb

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ install:
1111
script:
1212
- git submodule update --init
1313
- mkdir cmake-build
14+
- LIBGIT2SHA=`cat ./LibGit2Sharp/libgit2_hash.txt`
15+
- SHORTSHA=${LIBGIT2SHA:0:7}
1416
- cd cmake-build
15-
- cmake -DTHREADSAFE=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_CLAR=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./libgit2-bin ../libgit2
17+
- cmake -DTHREADSAFE=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_CLAR=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./libgit2-bin -DSONAME_APPEND=$SHORTSHA ../libgit2
1618
- export LD_LIBRARY_PATH=$PWD/libgit2-bin/lib
1719
- cmake --build . --target install
1820
- cd ..
744 KB
Binary file not shown.

Lib/NativeBinaries/amd64/git2.dll

-735 KB
Binary file not shown.
561 KB
Binary file not shown.

Lib/NativeBinaries/x86/git2.dll

-556 KB
Binary file not shown.

LibGit2Sharp.Tests/FetchFixture.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
8282
TestRemoteInfo remoteInfo = TestRemoteInfo.TestRemoteInstance;
8383
var expectedFetchState = new ExpectedFetchState(remoteName);
8484

85-
// Add expected branch objects
86-
foreach (KeyValuePair<string, ObjectId> kvp in remoteInfo.BranchTips)
87-
{
88-
expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
89-
}
90-
91-
// Add expected tags
85+
// Add expected tags only as no branches are expected to be fetched
9286
foreach (KeyValuePair<string, TestRemoteInfo.ExpectedTagInfo> kvp in remoteInfo.Tags)
9387
{
9488
expectedFetchState.AddExpectedTag(kvp.Key, ObjectId.Zero, kvp.Value);

LibGit2Sharp/Core/Handles/GitErrorSafeHandle.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Runtime.InteropServices;
23

34
namespace LibGit2Sharp.Core.Handles
@@ -6,6 +7,14 @@ internal class GitErrorSafeHandle : NotOwnedSafeHandleBase
67
{
78
public GitError MarshalAsGitError()
89
{
10+
// Required on Mono < 3.0.8
11+
// https://bugzilla.xamarin.com/show_bug.cgi?id=11417
12+
// https://github.com/mono/mono/commit/9cdddca7ec283f3b9181f3f69c1acecc0d9cc289
13+
if (handle == IntPtr.Zero)
14+
{
15+
return null;
16+
}
17+
918
return (GitError)Marshal.PtrToStructure(handle, typeof(GitError));
1019
}
1120
}

LibGit2Sharp/Core/NativeDllName.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace LibGit2Sharp.Core
2+
{
3+
internal static class NativeDllName
4+
{
5+
public const string Name = "git2-5aee963";
6+
}
7+
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace LibGit2Sharp.Core
1414
internal static class NativeMethods
1515
{
1616
public const uint GIT_PATH_MAX = 4096;
17-
private const string libgit2 = "git2";
17+
private const string libgit2 = NativeDllName.Name;
1818
private static readonly LibraryLifetimeObject lifetimeObject;
1919
private static int handlesCount;
2020

@@ -656,7 +656,6 @@ internal delegate int ref_glob_callback(
656656
internal static extern int git_reference_foreach_glob(
657657
RepositorySafeHandle repo,
658658
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string glob,
659-
GitReferenceType flags,
660659
ref_glob_callback callback,
661660
IntPtr payload);
662661

LibGit2Sharp/Core/Proxy.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,9 @@ public static void git_reference_delete(ReferenceSafeHandle reference)
11511151
public static ICollection<TResult> git_reference_foreach_glob<TResult>(
11521152
RepositorySafeHandle repo,
11531153
string glob,
1154-
GitReferenceType flags,
11551154
Func<IntPtr, TResult> resultSelector)
11561155
{
1157-
return git_foreach(resultSelector, c => NativeMethods.git_reference_foreach_glob(repo, glob, flags, (x, p) => c(x, p), IntPtr.Zero));
1156+
return git_foreach(resultSelector, c => NativeMethods.git_reference_foreach_glob(repo, glob, (x, p) => c(x, p), IntPtr.Zero));
11581157
}
11591158

11601159
public static void git_reference_free(IntPtr reference)
@@ -1170,12 +1169,12 @@ public static bool git_reference_is_valid_name(string refname)
11701169
return (res == 1);
11711170
}
11721171

1173-
public static IList<string> git_reference_list(RepositorySafeHandle repo, GitReferenceType flags)
1172+
public static IList<string> git_reference_list(RepositorySafeHandle repo)
11741173
{
11751174
using (ThreadAffinity())
11761175
{
11771176
UnSafeNativeMethods.git_strarray arr;
1178-
int res = UnSafeNativeMethods.git_reference_list(out arr, repo, flags);
1177+
int res = UnSafeNativeMethods.git_reference_list(out arr, repo);
11791178
Ensure.ZeroResult(res);
11801179

11811180
return Libgit2UnsafeHelper.BuildListOf(arr);

LibGit2Sharp/Core/UnSafeNativeMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace LibGit2Sharp.Core
66
{
77
internal static unsafe class UnSafeNativeMethods
88
{
9-
private const string libgit2 = "git2";
9+
private const string libgit2 = NativeDllName.Name;
1010

1111
[DllImport(libgit2)]
12-
internal static extern int git_reference_list(out git_strarray array, RepositorySafeHandle repo, GitReferenceType flags);
12+
internal static extern int git_reference_list(out git_strarray array, RepositorySafeHandle repo);
1313

1414
[DllImport(libgit2)]
1515
internal static extern int git_remote_list(out git_strarray array, RepositorySafeHandle repo);

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<Compile Include="CheckoutCallbacks.cs" />
6969
<Compile Include="CheckoutOptions.cs" />
7070
<Compile Include="CompareOptions.cs" />
71+
<Compile Include="Core\NativeDllName.cs" />
7172
<Compile Include="ObjectType.cs" />
7273
<Compile Include="ReferenceExtensions.cs" />
7374
<Compile Include="Conflict.cs" />

LibGit2Sharp/ReferenceCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public virtual Reference this[string name]
5050
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
5151
public virtual IEnumerator<Reference> GetEnumerator()
5252
{
53-
return Proxy.git_reference_list(repo.Handle, GitReferenceType.ListAll)
53+
return Proxy.git_reference_list(repo.Handle)
5454
.Select(n => this[n])
5555
.GetEnumerator();
5656
}
@@ -267,7 +267,7 @@ public virtual IEnumerable<Reference> FromGlob(string pattern)
267267
{
268268
Ensure.ArgumentNotNullOrEmptyString(pattern, "pattern");
269269

270-
return Proxy.git_reference_foreach_glob(repo.Handle, pattern, GitReferenceType.ListAll, Utf8Marshaler.FromNative)
270+
return Proxy.git_reference_foreach_glob(repo.Handle, pattern, Utf8Marshaler.FromNative)
271271
.Select(n => this[n]);
272272
}
273273

LibGit2Sharp/libgit2_hash.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b641c00eebb3c60e8719c0dfc55dde91ca30a5d2
1+
5aee96329ab7869cbe90cf80fd2a3f8f4dc5dccf

LibGit2Sharp/libgit2sharp_hash.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
unknown
1+
unknown

UpdateLibgit2ToSha.ps1

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Push-Location $libgit2Directory
111111
popd
112112
break
113113
}
114+
$shortsha = $sha.Substring(0,7)
114115

115116
Write-Output "Checking out $sha..."
116117
Run-Command -Quiet -Fatal { & $git checkout $sha }
@@ -119,26 +120,41 @@ Push-Location $libgit2Directory
119120
Run-Command -Quiet { & remove-item build -recurse -force }
120121
Run-Command -Quiet { & mkdir build }
121122
cd build
122-
Run-Command -Quiet -Fatal { & $cmake -G "Visual Studio $vs" -D THREADSAFE=ON -D "BUILD_CLAR=$build_clar" .. }
123+
Run-Command -Quiet -Fatal { & $cmake -G "Visual Studio $vs" -D THREADSAFE=ON -D "BUILD_CLAR=$build_clar" -D "SONAME_APPEND=$shortsha" .. }
123124
Run-Command -Quiet -Fatal { & $cmake --build . --config $configuration }
124125
if ($test.IsPresent) { Run-Command -Quiet -Fatal { & $ctest -V . } }
125126
cd $configuration
126127
Run-Command -Quiet { & rm *.exp }
128+
Run-Command -Quiet { & rm $x86Directory\* }
127129
Run-Command -Quiet -Fatal { & copy -fo * $x86Directory }
128130

129131
Write-Output "Building 64-bit..."
130132
cd ..
131133
Run-Command -Quiet { & mkdir build64 }
132134
cd build64
133-
Run-Command -Quiet -Fatal { & $cmake -G "Visual Studio $vs Win64" -D THREADSAFE=ON -D "BUILD_CLAR=$build_clar" ../.. }
135+
Run-Command -Quiet -Fatal { & $cmake -G "Visual Studio $vs Win64" -D THREADSAFE=ON -D "BUILD_CLAR=$build_clar" -D "SONAME_APPEND=$shortsha" ../.. }
134136
Run-Command -Quiet -Fatal { & $cmake --build . --config $configuration }
135137
if ($test.IsPresent) { Run-Command -Quiet -Fatal { & $ctest -V . } }
136138
cd $configuration
137139
Run-Command -Quiet { & rm *.exp }
140+
Run-Command -Quiet { & rm $x64Directory\* }
138141
Run-Command -Quiet -Fatal { & copy -fo * $x64Directory }
139142

140-
Write-Output "Done!"
141143
pop-location
142-
sc -Encoding UTF8 libgit2sharp\libgit2_hash.txt $sha
144+
145+
$dllNameClass = @"
146+
namespace LibGit2Sharp.Core
147+
{
148+
internal static class NativeDllName
149+
{
150+
public const string Name = "git2-$shortsha";
151+
}
152+
}
153+
"@
154+
155+
sc -Encoding ASCII .\Libgit2sharp\Core\NativeDllName.cs $dllNameClass
156+
sc -Encoding ASCII libgit2sharp\libgit2_hash.txt $sha
157+
158+
Write-Output "Done!"
143159
}
144160
exit

build.libgit2sharp.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
PREVIOUS_LD=$LD_LIBRARY_PATH
44

5+
LIBGIT2SHA=`cat ./LibGit2Sharp/libgit2_hash.txt`
6+
SHORTSHA=${LIBGIT2SHA:0:7}
7+
58
rm -rf cmake-build
69
mkdir cmake-build && cd cmake-build
710

8-
cmake -DBUILD_SHARED_LIBS:BOOL=ON -DTHREADSAFE:BOOL=ON -DBUILD_CLAR:BOOL=OFF -DCMAKE_INSTALL_PREFIX=./libgit2-bin ../libgit2
11+
cmake -DBUILD_SHARED_LIBS:BOOL=ON -DTHREADSAFE:BOOL=ON -DBUILD_CLAR:BOOL=OFF -DCMAKE_INSTALL_PREFIX=./libgit2-bin -DSONAME_APPEND=$SHORTSHA ../libgit2
912
cmake --build . --target install
1013

1114
LD_LIBRARY_PATH=$PWD/libgit2-bin/lib:$LD_LIBRARY_PATH

libgit2

Submodule libgit2 updated 210 files

0 commit comments

Comments
 (0)