Skip to content

Initial Rebase implementation #964

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

Merged
merged 1 commit into from
Jun 23, 2015
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
1 change: 1 addition & 0 deletions LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="FilterFixture.cs" />
<Compile Include="GlobalSettingsFixture.cs" />
<Compile Include="PatchStatsFixture.cs" />
<Compile Include="RebaseFixture.cs" />
<Compile Include="RefSpecFixture.cs" />
<Compile Include="EqualityFixture.cs" />
<Compile Include="RevertFixture.cs" />
Expand Down
767 changes: 767 additions & 0 deletions LibGit2Sharp.Tests/RebaseFixture.cs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions LibGit2Sharp.Tests/TestHelpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public static class Constants
public static readonly string TemporaryReposPath = BuildPath();
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
public static readonly Identity Identity = new Identity("A. U. Thor", "[email protected]");
public static readonly Identity Identity2 = new Identity("nulltoken", "[email protected]");

public static readonly Signature Signature = new Signature(Identity, new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
public static readonly Signature Signature2 = new Signature(Identity2, DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));

// Populate these to turn on live credential tests: set the
// PrivateRepoUrl to the URL of a repository that requires
Expand Down
61 changes: 61 additions & 0 deletions LibGit2Sharp/AfterRebaseStepInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace LibGit2Sharp
{
/// <summary>
/// Information about a rebase step that was just completed.
/// </summary>
public class AfterRebaseStepInfo
{
/// <summary>
/// Needed for mocking.
/// </summary>
protected AfterRebaseStepInfo()
{ }

internal AfterRebaseStepInfo(RebaseStepInfo stepInfo, Commit commit, long completedStepIndex, long totalStepCount)
{
StepInfo = stepInfo;
Commit = commit;
WasPatchAlreadyApplied = false;
CompletedStepIndex = completedStepIndex;
TotalStepCount = totalStepCount;
}

/// <summary>
/// Constructor to call when the patch has already been applied for this step.
/// </summary>
/// <param name="stepInfo"></param>
/// <param name="completedStepIndex"/>
/// <param name="totalStepCount"></param>
internal AfterRebaseStepInfo(RebaseStepInfo stepInfo, long completedStepIndex, long totalStepCount)
: this (stepInfo, null, completedStepIndex, totalStepCount)
{
WasPatchAlreadyApplied = true;
}

/// <summary>
/// The info on the completed step.
/// </summary>
public virtual RebaseStepInfo StepInfo { get; private set; }

/// <summary>
/// The commit generated by the step, if any.
/// </summary>
public virtual Commit Commit { get; private set; }

/// <summary>
/// Was the changes for this step already applied. If so,
/// <see cref="AfterRebaseStepInfo.Commit"/> will be null.
/// </summary>
public virtual bool WasPatchAlreadyApplied { get; private set; }

/// <summary>
/// The index of the step that was just completed.
/// </summary>
public virtual long CompletedStepIndex { get; private set; }

/// <summary>
/// The total number of steps in the rebase operation.
/// </summary>
public virtual long TotalStepCount { get; private set; }
}
}
41 changes: 41 additions & 0 deletions LibGit2Sharp/BeforeRebaseStepInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LibGit2Sharp
{
/// <summary>
/// Information about a rebase step that is about to be performed.
/// </summary>
public class BeforeRebaseStepInfo
{
/// <summary>
/// Needed for mocking.
/// </summary>
protected BeforeRebaseStepInfo()
{ }

internal BeforeRebaseStepInfo(RebaseStepInfo stepInfo, long stepIndex, long totalStepCount)
{
StepInfo = stepInfo;
StepIndex = stepIndex;
TotalStepCount = totalStepCount;
}

/// <summary>
/// Information on the step that is about to be performed.
/// </summary>
public virtual RebaseStepInfo StepInfo { get; private set; }

/// <summary>
/// The index of the step that is to be run.
/// </summary>
public virtual long StepIndex { get; private set; }

/// <summary>
/// The total number of steps in the rebase operation.
/// </summary>
public virtual long TotalStepCount { get; private set; }
}
}
8 changes: 8 additions & 0 deletions LibGit2Sharp/Core/GitOid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ public static implicit operator ObjectId(GitOid? oid)
{
return oid == null ? null : new ObjectId(oid.Value);
}

/// <summary>
/// Static convenience property to return an id (all zeros).
/// </summary>
public static GitOid Empty
{
get { return new GitOid(); }
}
}
}
13 changes: 13 additions & 0 deletions LibGit2Sharp/Core/GitRebaseOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Runtime.InteropServices;

namespace LibGit2Sharp.Core
{
[StructLayout(LayoutKind.Sequential)]
internal class GitRebaseOperation
{
internal RebaseStepOperation type;
internal GitOid id;
internal IntPtr exec;
}
}
17 changes: 17 additions & 0 deletions LibGit2Sharp/Core/GitRebaseOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Runtime.InteropServices;

namespace LibGit2Sharp.Core
{
[StructLayout(LayoutKind.Sequential)]
internal class GitRebaseOptions
{
public uint version = 1;

public int quiet;

public IntPtr rewrite_notes_ref;

public GitCheckoutOpts checkout_options = new GitCheckoutOpts { version = 1 };
}
}
13 changes: 13 additions & 0 deletions LibGit2Sharp/Core/Handles/RebaseSafeHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using LibGit2Sharp.Core.Handles;

namespace LibGit2Sharp.Core
{
internal class RebaseSafeHandle : SafeHandleBase
{
protected override bool ReleaseHandleImpl()
{
Proxy.git_rebase_free(handle);
return true;
}
}
}
61 changes: 61 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,61 @@ internal static extern int git_branch_remote_name(
RepositorySafeHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string canonical_branch_name);

[DllImport(libgit2)]
internal static extern int git_rebase_init(
out RebaseSafeHandle rebase,
RepositorySafeHandle repo,
GitAnnotatedCommitHandle branch,
GitAnnotatedCommitHandle upstream,
GitAnnotatedCommitHandle onto,
GitRebaseOptions options);

[DllImport(libgit2)]
internal static extern int git_rebase_open(
out RebaseSafeHandle rebase,
RepositorySafeHandle repo,
GitRebaseOptions options);

[DllImport(libgit2)]
internal static extern UIntPtr git_rebase_operation_entrycount(
RebaseSafeHandle rebase);

[DllImport(libgit2)]
internal static extern UIntPtr git_rebase_operation_current(
RebaseSafeHandle rebase);

[DllImport(libgit2)]
internal static extern IntPtr git_rebase_operation_byindex(
RebaseSafeHandle rebase,
UIntPtr index);

[DllImport(libgit2)]
internal static extern int git_rebase_next(
out IntPtr operation,
RebaseSafeHandle rebase);

[DllImport(libgit2)]
internal static extern int git_rebase_commit(
ref GitOid id,
RebaseSafeHandle rebase,
SignatureSafeHandle author,
SignatureSafeHandle committer,
IntPtr message_encoding,
IntPtr message);

[DllImport(libgit2)]
internal static extern int git_rebase_abort(
RebaseSafeHandle rebase);

[DllImport(libgit2)]
internal static extern int git_rebase_finish(
RebaseSafeHandle repo,
SignatureSafeHandle signature);

[DllImport(libgit2)]
internal static extern void git_rebase_free(
IntPtr rebase);

[DllImport(libgit2)]
internal static extern int git_remote_rename(
ref GitStrArray problems,
Expand Down Expand Up @@ -1363,6 +1418,12 @@ internal static extern int git_signature_new(
long time,
int offset);

[DllImport(libgit2)]
internal static extern int git_signature_now(
out SignatureSafeHandle signature,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string email);

[DllImport(libgit2)]
internal static extern int git_signature_dup(out IntPtr dest, IntPtr sig);

Expand Down
Loading