Skip to content

Commit 63771c5

Browse files
committed
Merge pull request #1298 from ethomson/libgit2_update
Update libgit2
2 parents db442ba + 2242a9b commit 63771c5

15 files changed

+99
-39
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
### Changes
1818

19+
- The native libraries are now expected to be in the `lib` directory,
20+
instead of `NativeBinaries` for improved mono compatibility. In
21+
addition, the names of platform architectures now better reflect
22+
the vendor naming (eg, `x86_64` instead of `amd64` on Linux).
1923
- Obsolete the config paths in RepositoryOptions
2024

2125
### Fixes

CI/build.msbuild

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
DestinationFiles="@(OutputFiles->'$(DeployFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />
5050

5151
<ItemGroup>
52-
<NativeBinaries Include="$(TestBuildDir)\NativeBinaries\**\*.*" />
52+
<NativeBinaries Include="$(TestBuildDir)\lib\**\*.*" />
5353
</ItemGroup>
5454

5555
<Copy SourceFiles="@(NativeBinaries)"
56-
DestinationFiles="@(NativeBinaries->'$(DeployFolder)\NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
56+
DestinationFiles="@(NativeBinaries->'$(DeployFolder)\lib\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
5757
</Target>
5858
</Project>

LibGit2Sharp.Tests/GlobalSettingsFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void CanGetMinimumCompiledInFeatures()
1919
public void CanRetrieveValidVersionString()
2020
{
2121
// Version string format is:
22-
// Major.Minor.Patch[-preDateTime]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)
22+
// Major.Minor.Patch[-preDateTime]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)
2323
// Example output:
2424
// "0.17.0[-pre20170914123547]-deadcafe-06d772d (x86 - Threads, Https)"
2525

@@ -29,7 +29,7 @@ public void CanRetrieveValidVersionString()
2929
// version: '0.17.0[-pre20170914123547]' LibGit2Sharp version number.
3030
// git2SharpHash:'unknown' ( when compiled from source ) else LibGit2Sharp library hash.
3131
// git2hash: '06d772d' LibGit2 library hash.
32-
// arch: 'x86' or 'amd64' LibGit2 target.
32+
// arch: 'x86' or 'x64' LibGit2 target.
3333
// git2Features: 'Threads, Ssh' LibGit2 features compiled with.
3434
string regex = @"^(?<version>\d{1,}\.\d{1,2}\.\d{1,3}(-(pre|dev)\d{14})?)-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
3535

@@ -38,7 +38,7 @@ public void CanRetrieveValidVersionString()
3838
Match regexResult = Regex.Match(versionInfo, regex);
3939

4040
Assert.True(regexResult.Success, "The following version string format is enforced:" +
41-
"Major.Minor.Patch[-preDateTime]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)");
41+
"Major.Minor.Patch[-preDateTime]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)");
4242

4343
GroupCollection matchGroups = regexResult.Groups;
4444

LibGit2Sharp.Tests/ShadowCopyFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
5959

6060
if (!Constants.IsRunningOnUnix)
6161
{
62-
// ...that this cache doesn't contain the `NativeBinaries` folder
62+
// ...that this cache doesn't contain the `lib` folder
6363
string cachedAssemblyParentPath = Path.GetDirectoryName(cachedAssemblyLocation);
64-
Assert.False(Directory.Exists(Path.Combine(cachedAssemblyParentPath, "NativeBinaries")));
64+
Assert.False(Directory.Exists(Path.Combine(cachedAssemblyParentPath, "lib")));
6565

66-
// ...whereas `NativeBinaries` of course exists next to the source assembly
66+
// ...whereas `lib` of course exists next to the source assembly
6767
string sourceAssemblyParentPath =
6868
Path.GetDirectoryName(new Uri(sourceAssembly.EscapedCodeBase).LocalPath);
69-
Assert.True(Directory.Exists(Path.Combine(sourceAssemblyParentPath, "NativeBinaries")));
69+
Assert.True(Directory.Exists(Path.Combine(sourceAssemblyParentPath, "lib")));
7070
}
7171

7272
AppDomain.Unload(domain);

LibGit2Sharp/Core/GitMergeOpts.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ internal struct GitMergeOpts
3535
/// </summary>
3636
public uint RecursionLimit;
3737

38+
/// <summary>
39+
/// Default merge driver to be used when both sides of a merge have
40+
/// changed. The default is the `text` driver.
41+
/// </summary>
42+
public string DefaultDriver;
43+
3844
/// <summary>
3945
/// Flags for automerging content.
4046
/// </summary>

LibGit2Sharp/Core/GitWriteStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace LibGit2Sharp.Core
55
{
66
[StructLayout(LayoutKind.Sequential)]
7-
internal class GitWriteStream
7+
internal struct GitWriteStream
88
{
99
[MarshalAs(UnmanagedType.FunctionPtr)]
1010
public write_fn write;

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ internal delegate int source_callback(
126126
int max_length,
127127
IntPtr data);
128128

129+
[DllImport(libgit2)]
130+
internal static extern unsafe int git_blob_create_fromstream(
131+
out IntPtr stream,
132+
git_repository* repositoryPtr,
133+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath hintpath);
134+
135+
[DllImport(libgit2)]
136+
internal static extern unsafe int git_blob_create_fromstream_commit(
137+
ref GitOid oid,
138+
IntPtr stream);
139+
129140
[DllImport(libgit2)]
130141
internal static extern unsafe int git_blob_create_fromchunks(
131142
ref GitOid oid,

LibGit2Sharp/Core/Platform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static class Platform
1313
{
1414
public static string ProcessorArchitecture
1515
{
16-
get { return Environment.Is64BitProcess ? "amd64" : "x86"; }
16+
get { return Environment.Is64BitProcess ? "x64" : "x86"; }
1717
}
1818

1919
public static OperatingSystemType OperatingSystem

LibGit2Sharp/Core/Proxy.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,18 @@ public static unsafe BlameHandle git_blame_file(
115115

116116
#region git_blob_
117117

118-
public static unsafe ObjectId git_blob_create_fromchunks(RepositoryHandle repo, FilePath hintpath, NativeMethods.source_callback fileCallback)
118+
public static unsafe IntPtr git_blob_create_fromstream(RepositoryHandle repo, FilePath hintpath)
119119
{
120-
var oid = new GitOid();
121-
int res = NativeMethods.git_blob_create_fromchunks(ref oid, repo, hintpath, fileCallback, IntPtr.Zero);
122-
123-
if (res == (int)GitErrorCode.User)
124-
{
125-
throw new EndOfStreamException("The stream ended unexpectedly");
126-
}
120+
IntPtr writestream_ptr;
127121

128-
Ensure.ZeroResult(res);
122+
Ensure.ZeroResult(NativeMethods.git_blob_create_fromstream(out writestream_ptr, repo, hintpath));
123+
return writestream_ptr;
124+
}
129125

126+
public static unsafe ObjectId git_blob_create_fromstream_commit(IntPtr writestream_ptr)
127+
{
128+
var oid = new GitOid();
129+
Ensure.ZeroResult(NativeMethods.git_blob_create_fromstream_commit(ref oid, writestream_ptr));
130130
return oid;
131131
}
132132

LibGit2Sharp/Filter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ int StreamCreateCallback(out IntPtr git_writestream_out, GitFilter self, IntPtr
261261
Marshal.StructureToPtr(state.thisStream, state.thisPtr, false);
262262

263263
state.nextPtr = git_writestream_next;
264-
state.nextStream = new GitWriteStream();
265-
Marshal.PtrToStructure(state.nextPtr, state.nextStream);
264+
state.nextStream = (GitWriteStream)Marshal.PtrToStructure(state.nextPtr, typeof(GitWriteStream));
266265

267266
state.filterSource = FilterSource.FromNativePtr(filterSourcePtr);
268267
state.output = new WriteStream(state.nextStream, state.nextPtr);

LibGit2Sharp/GlobalSettings.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static GlobalSettings()
2424
if (Platform.OperatingSystem == OperatingSystemType.Windows)
2525
{
2626
string managedPath = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;
27-
nativeLibraryPath = Path.Combine(Path.GetDirectoryName(managedPath), "NativeBinaries");
27+
nativeLibraryPath = Path.Combine(Path.Combine(Path.GetDirectoryName(managedPath), "lib"), "win32");
2828
}
2929

3030
registeredFilters = new Dictionary<Filter, FilterRegistration>();
@@ -129,10 +129,10 @@ public static LogConfiguration LogConfiguration
129129
/// <summary>
130130
/// Sets a hint path for searching for native binaries: when
131131
/// specified, native binaries will first be searched in a
132-
/// subdirectory of the given path corresponding to the architecture
133-
/// (eg, "x86" or "amd64") before falling back to the default
134-
/// path ("NativeBinaries\x86" or "NativeBinaries\amd64" next
135-
/// to the application).
132+
/// subdirectory of the given path corresponding to the operating
133+
/// system and architecture (eg, "x86" or "x64") before falling
134+
/// back to the default path ("lib\win32\x86" or "lib\win32\x64"
135+
/// next to the application).
136136
/// <para>
137137
/// This must be set before any other calls to the library,
138138
/// and is not available on Unix platforms: see your dynamic

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.132\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.132\build\LibGit2Sharp.NativeBinaries.props')" />
3+
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.137\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.137\build\LibGit2Sharp.NativeBinaries.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -79,8 +79,8 @@
7979
<Compile Include="Core\GitFetchOptions.cs" />
8080
<Compile Include="Core\GitPushUpdate.cs" />
8181
<Compile Include="Core\GitSubmoduleIgnore.cs" />
82-
<Compile Include="Core\Platform.cs" />
8382
<Compile Include="Core\GitWriteStream.cs" />
83+
<Compile Include="Core\Platform.cs" />
8484
<Compile Include="Core\WriteStream.cs" />
8585
<Compile Include="Core\GitRebaseOperation.cs" />
8686
<Compile Include="Core\GitRebaseOptions.cs" />
@@ -381,7 +381,7 @@
381381
<PropertyGroup>
382382
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
383383
</PropertyGroup>
384-
<Error Condition="!Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.132\build\LibGit2Sharp.NativeBinaries.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.NativeBinaries.1.0.132\build\LibGit2Sharp.NativeBinaries.props'))" />
384+
<Error Condition="!Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.137\build\LibGit2Sharp.NativeBinaries.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.NativeBinaries.1.0.137\build\LibGit2Sharp.NativeBinaries.props'))" />
385385
</Target>
386386
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
387387
Other similar extension points exist, see Microsoft.Common.targets.
@@ -390,7 +390,5 @@
390390
<Target Name="AfterBuild">
391391
</Target>
392392
-->
393-
<ItemGroup>
394-
<Folder Include="Commands\" />
395-
</ItemGroup>
393+
<ItemGroup />
396394
</Project>

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public virtual Blob CreateBlob(Stream stream, string hintpath, long numberOfByte
213213
return CreateBlob(stream, hintpath, (long?)numberOfBytesToConsume);
214214
}
215215

216-
private Blob CreateBlob(Stream stream, string hintpath, long? numberOfBytesToConsume)
216+
private unsafe Blob CreateBlob(Stream stream, string hintpath, long? numberOfBytesToConsume)
217217
{
218218
Ensure.ArgumentNotNull(stream, "stream");
219219

@@ -228,9 +228,51 @@ private Blob CreateBlob(Stream stream, string hintpath, long? numberOfBytesToCon
228228
throw new ArgumentException("The stream cannot be read from.", "stream");
229229
}
230230

231-
var proc = new Processor(stream, numberOfBytesToConsume);
232-
ObjectId id = Proxy.git_blob_create_fromchunks(repo.Handle, hintpath, proc.Provider);
231+
IntPtr writestream_ptr = Proxy.git_blob_create_fromstream(repo.Handle, hintpath);
232+
GitWriteStream writestream = (GitWriteStream)Marshal.PtrToStructure(writestream_ptr, typeof(GitWriteStream));
233233

234+
try
235+
{
236+
var buffer = new byte[4 * 1024];
237+
long totalRead = 0;
238+
int read = 0;
239+
240+
while (true)
241+
{
242+
int toRead = numberOfBytesToConsume.HasValue ?
243+
(int)Math.Min(numberOfBytesToConsume.Value - totalRead, (long)buffer.Length) :
244+
buffer.Length;
245+
246+
if (toRead > 0)
247+
{
248+
read = (toRead > 0) ? stream.Read(buffer, 0, toRead) : 0;
249+
}
250+
251+
if (read == 0)
252+
{
253+
break;
254+
}
255+
256+
fixed (byte* buffer_ptr = buffer)
257+
{
258+
writestream.write(writestream_ptr, (IntPtr)buffer_ptr, (UIntPtr)read);
259+
}
260+
261+
totalRead += read;
262+
}
263+
264+
if (numberOfBytesToConsume.HasValue && totalRead < numberOfBytesToConsume.Value)
265+
{
266+
throw new EndOfStreamException("The stream ended unexpectedly");
267+
}
268+
}
269+
catch(Exception e)
270+
{
271+
writestream.free(writestream_ptr);
272+
throw e;
273+
}
274+
275+
ObjectId id = Proxy.git_blob_create_fromstream_commit(writestream_ptr);
234276
return repo.Lookup<Blob>(id);
235277
}
236278

LibGit2Sharp/Version.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private string RetrieveAbbrevShaFrom(string name)
7777
/// </summary>
7878
/// <para>
7979
/// The format of the version number is as follows:
80-
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)</para>
80+
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)</para>
8181
/// </para>
8282
/// <returns></returns>
8383
public override string ToString()

LibGit2Sharp/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="LibGit2Sharp.NativeBinaries" version="1.0.132" targetFramework="net4" allowedVersions="[1.0.132]" />
3+
<package id="LibGit2Sharp.NativeBinaries" version="1.0.137" targetFramework="net4" allowedVersions="[1.0.137]" />
44
</packages>

0 commit comments

Comments
 (0)