diff --git a/LibGit2Sharp.sln.DotSettings b/LibGit2Sharp.sln.DotSettings
index 8bc2282a8..cf9a3e98a 100644
--- a/LibGit2Sharp.sln.DotSettings
+++ b/LibGit2Sharp.sln.DotSettings
@@ -11,6 +11,9 @@
True
True
<Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
+ True
+ True
+ True
True
True
True
diff --git a/LibGit2Sharp/Blob.cs b/LibGit2Sharp/Blob.cs
index 73ddbda87..e99a58e81 100644
--- a/LibGit2Sharp/Blob.cs
+++ b/LibGit2Sharp/Blob.cs
@@ -15,7 +15,6 @@ public class Blob : GitObject
{
private readonly ILazy lazySize;
private readonly ILazy lazyIsBinary;
- private readonly ILazy lazyIsMissing;
///
/// Needed for mocking purposes.s
@@ -26,9 +25,8 @@ protected Blob()
internal Blob(Repository repo, ObjectId id)
: base(repo, id)
{
- lazySize = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_rawsize);
- lazyIsBinary = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_is_binary);
- lazyIsMissing = GitObjectLazyGroup.Singleton(repo, id, handle => handle == null, throwsIfMissing: false);
+ lazySize = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_rawsize, throwIfMissing: true);
+ lazyIsBinary = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_is_binary, throwIfMissing: true);
}
///
@@ -47,12 +45,6 @@ internal Blob(Repository repo, ObjectId id)
/// Throws if blob is missing
public virtual bool IsBinary => lazyIsBinary.Value;
-
- ///
- /// Determine if the blob content is missing ( with partially cloned repositories)
- ///
- public virtual bool IsMissing => lazyIsMissing.Value;
-
///
/// Gets the blob content in a .
///
diff --git a/LibGit2Sharp/Core/GitObjectLazyGroup.cs b/LibGit2Sharp/Core/GitObjectLazyGroup.cs
index d6beeb6af..11c83a81e 100644
--- a/LibGit2Sharp/Core/GitObjectLazyGroup.cs
+++ b/LibGit2Sharp/Core/GitObjectLazyGroup.cs
@@ -17,22 +17,16 @@ protected override void EvaluateInternal(Action evaluator)
{
using (var osw = new ObjectSafeWrapper(id, repo.Handle))
{
- if (osw.ObjectPtr == null)
- throw new NotFoundException($"No valid git object identified by '{id}' exists in the repository.");
-
evaluator(osw.ObjectPtr);
}
}
- public static ILazy Singleton(Repository repo, ObjectId id, Func resultSelector, bool throwsIfMissing = true)
+ public static ILazy Singleton(Repository repo, ObjectId id, Func resultSelector, bool throwIfMissing = false)
{
return Singleton(() =>
{
- using (var osw = new ObjectSafeWrapper(id, repo.Handle))
+ using (var osw = new ObjectSafeWrapper(id, repo.Handle, throwIfMissing: throwIfMissing))
{
- if (throwsIfMissing && osw.ObjectPtr == null)
- throw new NotFoundException($"No valid git object identified by '{id}' exists in the repository.");
-
return resultSelector(osw.ObjectPtr);
}
});
diff --git a/LibGit2Sharp/Core/ObjectSafeWrapper.cs b/LibGit2Sharp/Core/ObjectSafeWrapper.cs
index 8bb7e9633..f2ab4a9e1 100644
--- a/LibGit2Sharp/Core/ObjectSafeWrapper.cs
+++ b/LibGit2Sharp/Core/ObjectSafeWrapper.cs
@@ -7,7 +7,7 @@ internal class ObjectSafeWrapper : IDisposable
{
private readonly ObjectHandle objectPtr;
- public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allowNullObjectId = false)
+ public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allowNullObjectId = false, bool throwIfMissing = false)
{
Ensure.ArgumentNotNull(handle, "handle");
@@ -20,13 +20,15 @@ public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allow
Ensure.ArgumentNotNull(id, "id");
objectPtr = Proxy.git_object_lookup(handle, id, GitObjectType.Any);
}
- }
- public ObjectHandle ObjectPtr
- {
- get { return objectPtr; }
+ if (objectPtr == null && throwIfMissing)
+ {
+ throw new NotFoundException($"No valid git object identified by '{id}' exists in the repository.");
+ }
}
+ public ObjectHandle ObjectPtr => objectPtr;
+
public void Dispose()
{
Dispose(true);
diff --git a/LibGit2Sharp/GitObject.cs b/LibGit2Sharp/GitObject.cs
index 218f8f141..ce2bdf543 100644
--- a/LibGit2Sharp/GitObject.cs
+++ b/LibGit2Sharp/GitObject.cs
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Globalization;
using LibGit2Sharp.Core;
-using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp
{
@@ -33,6 +31,8 @@ public abstract class GitObject : IEquatable, IBelongToARepository
private static readonly LambdaEqualityHelper equalityHelper =
new LambdaEqualityHelper(x => x.Id);
+ private readonly ILazy lazyIsMissing;
+
///
/// The containing the object.
///
@@ -53,6 +53,7 @@ protected GitObject(Repository repo, ObjectId id)
{
this.repo = repo;
Id = id;
+ lazyIsMissing = GitObjectLazyGroup.Singleton(repo, id, handle => handle == null, throwIfMissing: false);
}
///
@@ -60,6 +61,14 @@ protected GitObject(Repository repo, ObjectId id)
///
public virtual ObjectId Id { get; private set; }
+ ///
+ /// Determine if the object is missing
+ ///
+ ///
+ /// This is common when dealing with partially cloned repositories as blobs or trees could be missing
+ ///
+ public virtual bool IsMissing => lazyIsMissing.Value;
+
///
/// Gets the 40 character sha1 of this object.
///
diff --git a/LibGit2Sharp/Tree.cs b/LibGit2Sharp/Tree.cs
index ca7055183..95d0ab4fb 100644
--- a/LibGit2Sharp/Tree.cs
+++ b/LibGit2Sharp/Tree.cs
@@ -31,13 +31,13 @@ internal Tree(Repository repo, ObjectId id, string path)
{
this.path = path ?? "";
- lazyCount = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_tree_entrycount);
+ lazyCount = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_tree_entrycount, throwIfMissing: true);
}
///
/// Gets the number of immediately under this .
///
- public virtual int Count { get { return lazyCount.Value; } }
+ public virtual int Count => lazyCount.Value;
///
/// Gets the pointed at by the in this instance.