Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libgit2 #1298

Merged
merged 4 commits into from
Apr 12, 2016
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

### Changes

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

### Fixes
Expand Down
4 changes: 2 additions & 2 deletions CI/build.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
DestinationFiles="@(OutputFiles->'$(DeployFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />

<ItemGroup>
<NativeBinaries Include="$(TestBuildDir)\NativeBinaries\**\*.*" />
<NativeBinaries Include="$(TestBuildDir)\lib\**\*.*" />
</ItemGroup>

<Copy SourceFiles="@(NativeBinaries)"
DestinationFiles="@(NativeBinaries->'$(DeployFolder)\NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
DestinationFiles="@(NativeBinaries->'$(DeployFolder)\lib\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
</Project>
6 changes: 3 additions & 3 deletions LibGit2Sharp.Tests/GlobalSettingsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void CanGetMinimumCompiledInFeatures()
public void CanRetrieveValidVersionString()
{
// Version string format is:
// Major.Minor.Patch[-preDateTime]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)
// Major.Minor.Patch[-preDateTime]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)
// Example output:
// "0.17.0[-pre20170914123547]-deadcafe-06d772d (x86 - Threads, Https)"

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

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

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

GroupCollection matchGroups = regexResult.Groups;

Expand Down
8 changes: 4 additions & 4 deletions LibGit2Sharp.Tests/ShadowCopyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()

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

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

AppDomain.Unload(domain);
Expand Down
6 changes: 6 additions & 0 deletions LibGit2Sharp/Core/GitMergeOpts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ internal struct GitMergeOpts
/// </summary>
public uint RecursionLimit;

/// <summary>
/// Default merge driver to be used when both sides of a merge have
/// changed. The default is the `text` driver.
/// </summary>
public string DefaultDriver;

/// <summary>
/// Flags for automerging content.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/GitWriteStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace LibGit2Sharp.Core
{
[StructLayout(LayoutKind.Sequential)]
internal class GitWriteStream
internal struct GitWriteStream
{
[MarshalAs(UnmanagedType.FunctionPtr)]
public write_fn write;
Expand Down
11 changes: 11 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ internal delegate int source_callback(
int max_length,
IntPtr data);

[DllImport(libgit2)]
internal static extern unsafe int git_blob_create_fromstream(
out IntPtr stream,
git_repository* repositoryPtr,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath hintpath);

[DllImport(libgit2)]
internal static extern unsafe int git_blob_create_fromstream_commit(
ref GitOid oid,
IntPtr stream);

[DllImport(libgit2)]
internal static extern unsafe int git_blob_create_fromchunks(
ref GitOid oid,
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static class Platform
{
public static string ProcessorArchitecture
{
get { return Environment.Is64BitProcess ? "amd64" : "x86"; }
get { return Environment.Is64BitProcess ? "x64" : "x86"; }
}

public static OperatingSystemType OperatingSystem
Expand Down
18 changes: 9 additions & 9 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@ public static unsafe BlameHandle git_blame_file(

#region git_blob_

public static unsafe ObjectId git_blob_create_fromchunks(RepositoryHandle repo, FilePath hintpath, NativeMethods.source_callback fileCallback)
public static unsafe IntPtr git_blob_create_fromstream(RepositoryHandle repo, FilePath hintpath)
{
var oid = new GitOid();
int res = NativeMethods.git_blob_create_fromchunks(ref oid, repo, hintpath, fileCallback, IntPtr.Zero);

if (res == (int)GitErrorCode.User)
{
throw new EndOfStreamException("The stream ended unexpectedly");
}
IntPtr writestream_ptr;

Ensure.ZeroResult(res);
Ensure.ZeroResult(NativeMethods.git_blob_create_fromstream(out writestream_ptr, repo, hintpath));
return writestream_ptr;
}

public static unsafe ObjectId git_blob_create_fromstream_commit(IntPtr writestream_ptr)
{
var oid = new GitOid();
Ensure.ZeroResult(NativeMethods.git_blob_create_fromstream_commit(ref oid, writestream_ptr));
return oid;
}

Expand Down
3 changes: 1 addition & 2 deletions LibGit2Sharp/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ int StreamCreateCallback(out IntPtr git_writestream_out, GitFilter self, IntPtr
Marshal.StructureToPtr(state.thisStream, state.thisPtr, false);

state.nextPtr = git_writestream_next;
state.nextStream = new GitWriteStream();
Marshal.PtrToStructure(state.nextPtr, state.nextStream);
state.nextStream = (GitWriteStream)Marshal.PtrToStructure(state.nextPtr, typeof(GitWriteStream));

state.filterSource = FilterSource.FromNativePtr(filterSourcePtr);
state.output = new WriteStream(state.nextStream, state.nextPtr);
Expand Down
10 changes: 5 additions & 5 deletions LibGit2Sharp/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static GlobalSettings()
if (Platform.OperatingSystem == OperatingSystemType.Windows)
{
string managedPath = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;
nativeLibraryPath = Path.Combine(Path.GetDirectoryName(managedPath), "NativeBinaries");
nativeLibraryPath = Path.Combine(Path.Combine(Path.GetDirectoryName(managedPath), "lib"), "win32");
}

registeredFilters = new Dictionary<Filter, FilterRegistration>();
Expand Down Expand Up @@ -129,10 +129,10 @@ public static LogConfiguration LogConfiguration
/// <summary>
/// Sets a hint path for searching for native binaries: when
/// specified, native binaries will first be searched in a
/// subdirectory of the given path corresponding to the architecture
/// (eg, "x86" or "amd64") before falling back to the default
/// path ("NativeBinaries\x86" or "NativeBinaries\amd64" next
/// to the application).
/// subdirectory of the given path corresponding to the operating
/// system and architecture (eg, "x86" or "x64") before falling
/// back to the default path ("lib\win32\x86" or "lib\win32\x64"
/// next to the application).
/// <para>
/// This must be set before any other calls to the library,
/// and is not available on Unix platforms: see your dynamic
Expand Down
12 changes: 5 additions & 7 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.132\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.132\build\LibGit2Sharp.NativeBinaries.props')" />
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.137\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.137\build\LibGit2Sharp.NativeBinaries.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -79,8 +79,8 @@
<Compile Include="Core\GitFetchOptions.cs" />
<Compile Include="Core\GitPushUpdate.cs" />
<Compile Include="Core\GitSubmoduleIgnore.cs" />
<Compile Include="Core\Platform.cs" />
<Compile Include="Core\GitWriteStream.cs" />
<Compile Include="Core\Platform.cs" />
<Compile Include="Core\WriteStream.cs" />
<Compile Include="Core\GitRebaseOperation.cs" />
<Compile Include="Core\GitRebaseOptions.cs" />
Expand Down Expand Up @@ -381,7 +381,7 @@
<PropertyGroup>
<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>
</PropertyGroup>
<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'))" />
<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'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand All @@ -390,7 +390,5 @@
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Folder Include="Commands\" />
</ItemGroup>
<ItemGroup />
</Project>
48 changes: 45 additions & 3 deletions LibGit2Sharp/ObjectDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public virtual Blob CreateBlob(Stream stream, string hintpath, long numberOfByte
return CreateBlob(stream, hintpath, (long?)numberOfBytesToConsume);
}

private Blob CreateBlob(Stream stream, string hintpath, long? numberOfBytesToConsume)
private unsafe Blob CreateBlob(Stream stream, string hintpath, long? numberOfBytesToConsume)
{
Ensure.ArgumentNotNull(stream, "stream");

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

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

try
{
var buffer = new byte[4 * 1024];
long totalRead = 0;
int read = 0;

while (true)
{
int toRead = numberOfBytesToConsume.HasValue ?
(int)Math.Min(numberOfBytesToConsume.Value - totalRead, (long)buffer.Length) :
buffer.Length;

if (toRead > 0)
{
read = (toRead > 0) ? stream.Read(buffer, 0, toRead) : 0;
}

if (read == 0)
{
break;
}

fixed (byte* buffer_ptr = buffer)
{
writestream.write(writestream_ptr, (IntPtr)buffer_ptr, (UIntPtr)read);
}

totalRead += read;
}

if (numberOfBytesToConsume.HasValue && totalRead < numberOfBytesToConsume.Value)
{
throw new EndOfStreamException("The stream ended unexpectedly");
}
}
catch(Exception e)
{
writestream.free(writestream_ptr);
throw e;
}

ObjectId id = Proxy.git_blob_create_fromstream_commit(writestream_ptr);
return repo.Lookup<Blob>(id);
}

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private string RetrieveAbbrevShaFrom(string name)
/// </summary>
/// <para>
/// The format of the version number is as follows:
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)</para>
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)</para>
/// </para>
/// <returns></returns>
public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LibGit2Sharp.NativeBinaries" version="1.0.132" targetFramework="net4" allowedVersions="[1.0.132]" />
<package id="LibGit2Sharp.NativeBinaries" version="1.0.137" targetFramework="net4" allowedVersions="[1.0.137]" />
</packages>