@@ -365,57 +365,67 @@ private static bool AllowOrphanReference(IRepository repo, string identifier)
365
365
|| string . Equals ( identifier , repo . Head . CanonicalName , StringComparison . Ordinal ) ;
366
366
}
367
367
368
- /// <summary>
369
- /// Dereferences the passed identifier to a commit. If the identifier is enumerable, all items are dereferenced.
370
- /// </summary>
371
- /// <param name="repo">Repository to search</param>
372
- /// <param name="identifier">Committish to dereference</param>
373
- /// <param name="throwIfNotFound">If true, allow thrown exceptions to propagate. If false, exceptions will be swallowed and null returned.</param>
374
- /// <returns>A series of commit <see cref="ObjectId"/>s which identify commit objects.</returns>
375
- internal static IEnumerable < ObjectId > Committishes ( this Repository repo , object identifier , bool throwIfNotFound = false )
368
+ private static ObjectId SingleCommittish ( this Repository repo , object identifier )
376
369
{
377
- ObjectId singleReturnValue = null ;
370
+ if ( ReferenceEquals ( identifier , null ) )
371
+ {
372
+ return null ;
373
+ }
378
374
379
375
if ( identifier is string )
380
376
{
381
- singleReturnValue = DereferenceToCommit ( repo , identifier as string ) ;
377
+ return DereferenceToCommit ( repo , ( string ) identifier ) ;
382
378
}
383
379
384
380
if ( identifier is ObjectId )
385
381
{
386
- singleReturnValue = DereferenceToCommit ( repo , ( ( ObjectId ) identifier ) . Sha ) ;
382
+ return DereferenceToCommit ( repo , ( ( ObjectId ) identifier ) . Sha ) ;
387
383
}
388
384
389
385
if ( identifier is Commit )
390
386
{
391
- singleReturnValue = ( ( Commit ) identifier ) . Id ;
387
+ return ( ( Commit ) identifier ) . Id ;
392
388
}
393
389
394
390
if ( identifier is TagAnnotation )
395
391
{
396
- singleReturnValue = DereferenceToCommit ( repo , ( ( TagAnnotation ) identifier ) . Target . Id . Sha ) ;
392
+ return DereferenceToCommit ( repo , ( ( TagAnnotation ) identifier ) . Target . Id . Sha ) ;
397
393
}
398
394
399
395
if ( identifier is Tag )
400
396
{
401
- singleReturnValue = DereferenceToCommit ( repo , ( ( Tag ) identifier ) . Target . Id . Sha ) ;
397
+ return DereferenceToCommit ( repo , ( ( Tag ) identifier ) . Target . Id . Sha ) ;
402
398
}
403
399
404
- if ( identifier is Branch )
400
+ var branch = identifier as Branch ;
401
+ if ( branch != null )
405
402
{
406
- var branch = ( Branch ) identifier ;
407
403
if ( branch . Tip != null || ! branch . IsCurrentRepositoryHead )
408
404
{
409
405
Ensure . GitObjectIsNotNull ( branch . Tip , branch . CanonicalName ) ;
410
- singleReturnValue = branch . Tip . Id ;
406
+ return branch . Tip . Id ;
411
407
}
412
408
}
413
409
414
410
if ( identifier is Reference )
415
411
{
416
- singleReturnValue = DereferenceToCommit ( repo , ( ( Reference ) identifier ) . CanonicalName ) ;
412
+ return DereferenceToCommit ( repo , ( ( Reference ) identifier ) . CanonicalName ) ;
417
413
}
418
414
415
+ return null ;
416
+ }
417
+
418
+ /// <summary>
419
+ /// Dereferences the passed identifier to a commit. If the identifier is enumerable, all items are dereferenced.
420
+ /// </summary>
421
+ /// <param name="repo">Repository to search</param>
422
+ /// <param name="identifier">Committish to dereference</param>
423
+ /// <param name="throwIfNotFound">If true, allow thrown exceptions to propagate. If false, exceptions will be swallowed and null returned.</param>
424
+ /// <returns>A series of commit <see cref="ObjectId"/>s which identify commit objects.</returns>
425
+ internal static IEnumerable < ObjectId > Committishes ( this Repository repo , object identifier , bool throwIfNotFound = false )
426
+ {
427
+ var singleReturnValue = repo . SingleCommittish ( identifier ) ;
428
+
419
429
if ( singleReturnValue != null )
420
430
{
421
431
yield return singleReturnValue ;
0 commit comments