Skip to content

Commit 5bdac6b

Browse files
committed
Rebase tweaks
1 parent b01721e commit 5bdac6b

File tree

5 files changed

+51
-32
lines changed

5 files changed

+51
-32
lines changed

LibGit2Sharp/Core/Proxy.cs

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static string git_branch_remote_name(RepositorySafeHandle repo, string ca
212212
int res = NativeMethods.git_branch_remote_name(buf, repo, canonical_branch_name);
213213

214214
if (!shouldThrowIfNotFound &&
215-
(res == (int) GitErrorCode.NotFound || res == (int) GitErrorCode.Ambiguous))
215+
(res == (int)GitErrorCode.NotFound || res == (int)GitErrorCode.Ambiguous))
216216
{
217217
return null;
218218
}
@@ -228,7 +228,7 @@ public static string git_branch_upstream_name(RepositorySafeHandle handle, strin
228228
using (var buf = new GitBuf())
229229
{
230230
int res = NativeMethods.git_branch_upstream_name(buf, handle, canonicalReferenceName);
231-
if (res == (int) GitErrorCode.NotFound)
231+
if (res == (int)GitErrorCode.NotFound)
232232
{
233233
return null;
234234
}
@@ -803,7 +803,7 @@ public static int git_diff_num_deltas(DiffSafeHandle diff)
803803

804804
public static GitDiffDelta git_diff_get_delta(DiffSafeHandle diff, int idx)
805805
{
806-
return NativeMethods.git_diff_get_delta(diff, (UIntPtr) idx).MarshalAs<GitDiffDelta>(false);
806+
return NativeMethods.git_diff_get_delta(diff, (UIntPtr)idx).MarshalAs<GitDiffDelta>(false);
807807
}
808808

809809
#endregion
@@ -1507,7 +1507,7 @@ public static void git_odb_stream_write(OdbStreamSafeHandle stream, byte[] data,
15071507
{
15081508
fixed (byte *p = data)
15091509
{
1510-
res = NativeMethods.git_odb_stream_write(stream, (IntPtr) p, (UIntPtr) len);
1510+
res = NativeMethods.git_odb_stream_write(stream, (IntPtr)p, (UIntPtr)len);
15111511
}
15121512
}
15131513

@@ -1546,7 +1546,7 @@ public static PatchSafeHandle git_patch_from_diff(DiffSafeHandle diff, int idx)
15461546
using (ThreadAffinity())
15471547
{
15481548
PatchSafeHandle handle;
1549-
int res = NativeMethods.git_patch_from_diff(out handle, diff, (UIntPtr) idx);
1549+
int res = NativeMethods.git_patch_from_diff(out handle, diff, (UIntPtr)idx);
15501550
Ensure.ZeroResult(res);
15511551
return handle;
15521552
}
@@ -1608,26 +1608,22 @@ public static RebaseSafeHandle git_rebase_open(RepositorySafeHandle repo)
16081608
return rebase;
16091609
}
16101610

1611-
public static int git_rebase_operation_entrycount(RebaseSafeHandle rebase)
1611+
public static long git_rebase_operation_entrycount(RebaseSafeHandle rebase)
16121612
{
1613-
UIntPtr count = NativeMethods.git_rebase_operation_entrycount(rebase);
1614-
int entryCountAsInt = (int) count; // What to convert to
1615-
return entryCountAsInt;
1613+
return NativeMethods.git_rebase_operation_entrycount(rebase).ConvertToLong();
16161614
}
16171615

1618-
public static int git_rebase_operation_current(RebaseSafeHandle rebase)
1616+
public static long git_rebase_operation_current(RebaseSafeHandle rebase)
16191617
{
1620-
UIntPtr current = NativeMethods.git_rebase_operation_current(rebase);
1621-
int currentEntryAsInt = (int) current; // What to convert to
1622-
return currentEntryAsInt;
1618+
return NativeMethods.git_rebase_operation_current(rebase).ConvertToLong();
16231619
}
16241620

16251621
public static GitRebaseOperation git_rebase_operation_byindex(
16261622
RebaseSafeHandle rebase,
1627-
int index)
1623+
long index)
16281624
{
16291625
Debug.Assert(index >= 0);
1630-
IntPtr ptr = NativeMethods.git_rebase_operation_byindex(rebase, ((UIntPtr) index));
1626+
IntPtr ptr = NativeMethods.git_rebase_operation_byindex(rebase, ((UIntPtr)index));
16311627
GitRebaseOperation operation = ptr.MarshalAs<GitRebaseOperation>();
16321628

16331629
// Workaround until 92e87dd74 from libgit2 is consumed by LibGit2#
@@ -2011,7 +2007,7 @@ public static bool git_refspec_force(GitRefSpecHandle refSpec)
20112007

20122008
public static TagFetchMode git_remote_autotag(RemoteSafeHandle remote)
20132009
{
2014-
return (TagFetchMode) NativeMethods.git_remote_autotag(remote);
2010+
return (TagFetchMode)NativeMethods.git_remote_autotag(remote);
20152011
}
20162012

20172013
public static RemoteSafeHandle git_remote_create(RepositorySafeHandle repo, string name, string url)
@@ -2203,7 +2199,7 @@ public static void git_remote_set_url(RemoteSafeHandle remote, string url)
22032199
Ensure.ZeroResult(res);
22042200
}
22052201
}
2206-
2202+
22072203
public static void git_remote_set_pushurl(RemoteSafeHandle remote, string url)
22082204
{
22092205
using (ThreadAffinity())
@@ -2334,7 +2330,7 @@ public static void git_remote_rename(RepositorySafeHandle repo, string name, str
23342330
{
23352331
if (callback == null)
23362332
{
2337-
callback = problem => {};
2333+
callback = problem => { };
23382334
}
23392335

23402336
var array = new GitStrArrayNative();
@@ -2854,7 +2850,7 @@ public static void git_stash_drop(RepositorySafeHandle repo, int index)
28542850
{
28552851
using (ThreadAffinity())
28562852
{
2857-
int res = NativeMethods.git_stash_drop(repo, (UIntPtr) index);
2853+
int res = NativeMethods.git_stash_drop(repo, (UIntPtr)index);
28582854
Ensure.BooleanResult(res);
28592855
}
28602856
}
@@ -3585,5 +3581,28 @@ internal static int ConvertResultToCancelFlag(bool result)
35853581
return result ? 0 : (int)GitErrorCode.User;
35863582
}
35873583
}
3584+
3585+
/// <summary>
3586+
/// Class to hold extension methods used by the proxy class.
3587+
/// </summary>
3588+
static class ProxyExtensions
3589+
{
3590+
/// <summary>
3591+
/// Convert a UIntPtr to a long value. Will throw
3592+
/// exception if there is an overflow.
3593+
/// </summary>
3594+
/// <param name="input"></param>
3595+
/// <returns></returns>
3596+
public static long ConvertToLong(this UIntPtr input)
3597+
{
3598+
ulong ulongValue = (ulong)input;
3599+
if (ulongValue > long.MaxValue)
3600+
{
3601+
throw new LibGit2SharpException("value exceeds size of long");
3602+
}
3603+
3604+
return (long)input;
3605+
}
3606+
}
35883607
}
35893608
// ReSharper restore InconsistentNaming

LibGit2Sharp/Rebase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
178178
if (options.RebaseStepCompleted != null)
179179
{
180180
// Get information on the current step
181-
int currentStepIndex = Proxy.git_rebase_operation_current(rebase);
182-
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebase);
181+
long currentStepIndex = Proxy.git_rebase_operation_current(rebase);
182+
long totalStepCount = Proxy.git_rebase_operation_entrycount(rebase);
183183
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebase, currentStepIndex);
184184

185185
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
@@ -246,8 +246,8 @@ public virtual RebaseStepInfo GetCurrentStepInfo()
246246
try
247247
{
248248
rebaseHandle = Proxy.git_rebase_open(repository.Handle);
249-
int currentStepIndex = Proxy.git_rebase_operation_current(rebaseHandle);
250-
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseHandle);
249+
long currentStepIndex = Proxy.git_rebase_operation_current(rebaseHandle);
250+
long totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseHandle);
251251
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebaseHandle, currentStepIndex);
252252
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
253253
gitRebasestepInfo.id,

LibGit2Sharp/RebaseOperationImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public static RebaseResult Run(RebaseSafeHandle rebaseOperationHandle,
4040
{
4141
rebaseOperationReport = Proxy.git_rebase_next(rebaseOperationHandle, ref gitCheckoutOpts);
4242

43-
int currentStepIndex = Proxy.git_rebase_operation_current(rebaseOperationHandle);
44-
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseOperationHandle);
43+
long currentStepIndex = Proxy.git_rebase_operation_current(rebaseOperationHandle);
44+
long totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseOperationHandle);
4545

4646
if (rebaseOperationReport == null)
4747
{

LibGit2Sharp/RebaseResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ protected RebaseResult()
3939
{ }
4040

4141
internal RebaseResult(RebaseStatus status,
42-
int stepNumber,
43-
int totalSteps,
42+
long stepNumber,
43+
long totalSteps,
4444
RebaseStepInfo currentStepInfo)
4545
{
4646
Status = status;
@@ -66,11 +66,11 @@ internal RebaseResult(RebaseStatus status,
6666
/// <summary>
6767
/// The number of completed steps.
6868
/// </summary>
69-
public virtual int CompletedStepCount { get; protected set; }
69+
public virtual long CompletedStepCount { get; protected set; }
7070

7171
/// <summary>
7272
/// The total number of steps in the rebase.
7373
/// </summary>
74-
public virtual int TotalStepCount { get; protected set; }
74+
public virtual long TotalStepCount { get; protected set; }
7575
}
7676
}

LibGit2Sharp/RebaseStepInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class RebaseStepInfo
1717
protected RebaseStepInfo()
1818
{ }
1919

20-
internal RebaseStepInfo(RebaseStepOperation type, ObjectId id, string exec, int stepIndex, int totalStepCount)
20+
internal RebaseStepInfo(RebaseStepOperation type, ObjectId id, string exec, long stepIndex, long totalStepCount)
2121
{
2222
Type = type;
2323
ID = id;
@@ -44,11 +44,11 @@ internal RebaseStepInfo(RebaseStepOperation type, ObjectId id, string exec, int
4444
/// <summary>
4545
/// The index of this step.
4646
/// </summary>
47-
public virtual int StepIndex { get; private set; }
47+
public virtual long StepIndex { get; private set; }
4848

4949
/// <summary>
5050
/// The total number of steps.
5151
/// </summary>
52-
public virtual int TotalStepCount { get; private set; }
52+
public virtual long TotalStepCount { get; private set; }
5353
}
5454
}

0 commit comments

Comments
 (0)