@@ -212,7 +212,7 @@ public static string git_branch_remote_name(RepositorySafeHandle repo, string ca
212
212
int res = NativeMethods . git_branch_remote_name ( buf , repo , canonical_branch_name ) ;
213
213
214
214
if ( ! shouldThrowIfNotFound &&
215
- ( res == ( int ) GitErrorCode . NotFound || res == ( int ) GitErrorCode . Ambiguous ) )
215
+ ( res == ( int ) GitErrorCode . NotFound || res == ( int ) GitErrorCode . Ambiguous ) )
216
216
{
217
217
return null ;
218
218
}
@@ -228,7 +228,7 @@ public static string git_branch_upstream_name(RepositorySafeHandle handle, strin
228
228
using ( var buf = new GitBuf ( ) )
229
229
{
230
230
int res = NativeMethods . git_branch_upstream_name ( buf , handle , canonicalReferenceName ) ;
231
- if ( res == ( int ) GitErrorCode . NotFound )
231
+ if ( res == ( int ) GitErrorCode . NotFound )
232
232
{
233
233
return null ;
234
234
}
@@ -803,7 +803,7 @@ public static int git_diff_num_deltas(DiffSafeHandle diff)
803
803
804
804
public static GitDiffDelta git_diff_get_delta ( DiffSafeHandle diff , int idx )
805
805
{
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 ) ;
807
807
}
808
808
809
809
#endregion
@@ -1507,7 +1507,7 @@ public static void git_odb_stream_write(OdbStreamSafeHandle stream, byte[] data,
1507
1507
{
1508
1508
fixed ( byte * p = data )
1509
1509
{
1510
- res = NativeMethods . git_odb_stream_write ( stream , ( IntPtr ) p , ( UIntPtr ) len ) ;
1510
+ res = NativeMethods . git_odb_stream_write ( stream , ( IntPtr ) p , ( UIntPtr ) len ) ;
1511
1511
}
1512
1512
}
1513
1513
@@ -1546,7 +1546,7 @@ public static PatchSafeHandle git_patch_from_diff(DiffSafeHandle diff, int idx)
1546
1546
using ( ThreadAffinity ( ) )
1547
1547
{
1548
1548
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 ) ;
1550
1550
Ensure . ZeroResult ( res ) ;
1551
1551
return handle ;
1552
1552
}
@@ -1608,26 +1608,22 @@ public static RebaseSafeHandle git_rebase_open(RepositorySafeHandle repo)
1608
1608
return rebase ;
1609
1609
}
1610
1610
1611
- public static int git_rebase_operation_entrycount ( RebaseSafeHandle rebase )
1611
+ public static long git_rebase_operation_entrycount ( RebaseSafeHandle rebase )
1612
1612
{
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 ( ) ;
1616
1614
}
1617
1615
1618
- public static int git_rebase_operation_current ( RebaseSafeHandle rebase )
1616
+ public static long git_rebase_operation_current ( RebaseSafeHandle rebase )
1619
1617
{
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 ( ) ;
1623
1619
}
1624
1620
1625
1621
public static GitRebaseOperation git_rebase_operation_byindex (
1626
1622
RebaseSafeHandle rebase ,
1627
- int index )
1623
+ long index )
1628
1624
{
1629
1625
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 ) ) ;
1631
1627
GitRebaseOperation operation = ptr . MarshalAs < GitRebaseOperation > ( ) ;
1632
1628
1633
1629
// Workaround until 92e87dd74 from libgit2 is consumed by LibGit2#
@@ -2011,7 +2007,7 @@ public static bool git_refspec_force(GitRefSpecHandle refSpec)
2011
2007
2012
2008
public static TagFetchMode git_remote_autotag ( RemoteSafeHandle remote )
2013
2009
{
2014
- return ( TagFetchMode ) NativeMethods . git_remote_autotag ( remote ) ;
2010
+ return ( TagFetchMode ) NativeMethods . git_remote_autotag ( remote ) ;
2015
2011
}
2016
2012
2017
2013
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)
2203
2199
Ensure . ZeroResult ( res ) ;
2204
2200
}
2205
2201
}
2206
-
2202
+
2207
2203
public static void git_remote_set_pushurl ( RemoteSafeHandle remote , string url )
2208
2204
{
2209
2205
using ( ThreadAffinity ( ) )
@@ -2334,7 +2330,7 @@ public static void git_remote_rename(RepositorySafeHandle repo, string name, str
2334
2330
{
2335
2331
if ( callback == null )
2336
2332
{
2337
- callback = problem => { } ;
2333
+ callback = problem => { } ;
2338
2334
}
2339
2335
2340
2336
var array = new GitStrArrayNative ( ) ;
@@ -2854,7 +2850,7 @@ public static void git_stash_drop(RepositorySafeHandle repo, int index)
2854
2850
{
2855
2851
using ( ThreadAffinity ( ) )
2856
2852
{
2857
- int res = NativeMethods . git_stash_drop ( repo , ( UIntPtr ) index ) ;
2853
+ int res = NativeMethods . git_stash_drop ( repo , ( UIntPtr ) index ) ;
2858
2854
Ensure . BooleanResult ( res ) ;
2859
2855
}
2860
2856
}
@@ -3585,5 +3581,28 @@ internal static int ConvertResultToCancelFlag(bool result)
3585
3581
return result ? 0 : ( int ) GitErrorCode . User ;
3586
3582
}
3587
3583
}
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
+ }
3588
3607
}
3589
3608
// ReSharper restore InconsistentNaming
0 commit comments