Skip to content

Commit

Permalink
Use CSharp friendly names for libgit2 error types and codes
Browse files Browse the repository at this point in the history
  • Loading branch information
tclem authored and nulltoken committed Jun 3, 2012
1 parent dd15de9 commit 2631f67
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 49 deletions.
2 changes: 1 addition & 1 deletion LibGit2Sharp/BranchCollection.cs
Expand Up @@ -121,7 +121,7 @@ public void Delete(string name, bool isRemote = false)

int res = NativeMethods.git_branch_delete(repo.Handle, name, isRemote ? GitBranchType.GIT_BRANCH_REMOTE : GitBranchType.GIT_BRANCH_LOCAL);

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/CommitCollection.cs
Expand Up @@ -141,7 +141,7 @@ public Commit FindCommonAncestor(Commit first, Commit second)
GitOid ret;
int result = NativeMethods.git_merge_base(out ret, repo.Handle, osw1.ObjectPtr, osw2.ObjectPtr);

if (result == (int)GitErrorCode.GIT_ENOTFOUND)
if (result == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public bool MoveNext()
GitOid oid;
int res = NativeMethods.git_revwalk_next(out oid, handle);

if (res == (int)GitErrorCode.GIT_EREVWALKOVER)
if (res == (int)GitErrorCode.RevWalkOver)
{
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp/Configuration.cs
Expand Up @@ -109,7 +109,7 @@ private static string ConvertPath(Func<byte[], uint, int> pathRetriever)

int result = pathRetriever(buffer, NativeMethods.GIT_PATH_MAX);

if (result == (int)GitErrorCode.GIT_ENOTFOUND)
if (result == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ public void Delete(string key, ConfigurationLevel level = ConfigurationLevel.Loc

int res = NativeMethods.git_config_delete(h, key);

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return;
}
Expand Down Expand Up @@ -382,7 +382,7 @@ private ConfigurationSafeHandle RetrieveConfigurationHandle(ConfigurationLevel l
{
T value;
var res = getter(out value, handle, key);
if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return defaultValue;
}
Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp/Core/Ensure.cs
Expand Up @@ -54,12 +54,12 @@ public static void ArgumentNotNullOrEmptyString(string argumentValue, string arg
/// True when positive values are allowed as well.</param>
public static void Success(int result, bool allowPositiveResult = false)
{
if (result == (int)GitErrorCode.GIT_OK)
if (result == (int)GitErrorCode.Ok)
{
return;
}

if (allowPositiveResult && result > (int)GitErrorCode.GIT_OK)
if (allowPositiveResult && result > (int)GitErrorCode.Ok)
{
return;
}
Expand All @@ -70,7 +70,7 @@ public static void Success(int result, bool allowPositiveResult = false)

if (error == null)
{
error = new GitError { Klass = -1, Message = IntPtr.Zero };
error = new GitError { Klass = GitErrorType.Unknown, Message = IntPtr.Zero };
errorMessage = "No error message has been provided by the native library";
}
else
Expand Down
21 changes: 1 addition & 20 deletions LibGit2Sharp/Core/GitError.cs
Expand Up @@ -7,25 +7,6 @@ namespace LibGit2Sharp.Core
internal class GitError
{
public IntPtr Message;
public int Klass;
}

internal enum GitErrorType
{
GITERR_NOMEMORY,
GITERR_OS,
GITERR_INVALID,
GITERR_REFERENCE,
GITERR_ZLIB,
GITERR_REPOSITORY,
GITERR_CONFIG,
GITERR_REGEX,
GITERR_ODB,
GITERR_INDEX,
GITERR_OBJECT,
GITERR_NET,
GITERR_TAG,
GITERR_TREE,
GITERR_INDEXER,
public GitErrorType Klass;
}
}
40 changes: 32 additions & 8 deletions LibGit2Sharp/Core/GitErrorCode.cs
Expand Up @@ -2,13 +2,37 @@
{
internal enum GitErrorCode
{
GIT_OK = 0,
GIT_ERROR = -1,
GIT_ENOTFOUND = -3,
GIT_EEXISTS = -4,
GIT_EAMBIGUOUS = -5,
GIT_EBUFS = -6,
GIT_EPASSTHROUGH = -30,
GIT_EREVWALKOVER = -31,
Ok = 0,
Error = -1,

/// <summary>
/// Input does not exist in the scope searched.
/// </summary>
NotFound = -3,

/// <summary>
/// Input already exists in the processed scope.
/// </summary>
Exists = -4,

/// <summary>
/// The given short oid is ambiguous.
/// </summary>
Ambiguous = -5,

/// <summary>
/// Buffer related issue.
/// </summary>
Buffer = -6,

/// <summary>
/// Skip and passthrough the given ODB backend.
/// </summary>
PassThrough = -30,

/// <summary>
/// The revision walker is empty; there are no more commits left to iterate.
/// </summary>
RevWalkOver = -31,
}
}
22 changes: 22 additions & 0 deletions LibGit2Sharp/Core/GitErrorType.cs
@@ -0,0 +1,22 @@
namespace LibGit2Sharp.Core
{
internal enum GitErrorType
{
Unknown = -1,
NoMemory,
Os,
Invalid,
Reference,
Zlib,
Repository,
Config,
Regex,
Odb,
Index,
Object,
Net,
Tag,
Tree,
Indexer,
}
}
4 changes: 2 additions & 2 deletions LibGit2Sharp/Index.cs
Expand Up @@ -63,7 +63,7 @@ public int Count

int res = NativeMethods.git_index_find(handle, path);

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down Expand Up @@ -476,7 +476,7 @@ public FileStatus RetrieveStatus(string filePath)
FileStatus status;

int res = NativeMethods.git_status_file(out status, repo.Handle, relativePath);
if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return FileStatus.Nonexistent;
}
Expand Down
1 change: 1 addition & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Expand Up @@ -74,6 +74,7 @@
<Compile Include="Core\GitBranchType.cs" />
<Compile Include="Core\GitDiff.cs" />
<Compile Include="Core\GitError.cs" />
<Compile Include="Core\GitErrorType.cs" />
<Compile Include="Core\GitNoteData.cs" />
<Compile Include="Core\GitObjectExtensions.cs" />
<Compile Include="Core\Handles\GitErrorSafeHandle.cs" />
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/NoteCollection.cs
Expand Up @@ -137,7 +137,7 @@ private NoteSafeHandle BuildNoteSafeHandle(ObjectId id, string canonicalNamespac

int res = NativeMethods.git_note_read(out noteHandle, repo.Handle, canonicalNamespace, ref oid);

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ public void Delete(ObjectId targetId, Signature author, Signature committer, str
res = NativeMethods.git_note_remove(repo.Handle, canonicalNamespace, authorHandle, committerHandle, ref oid);
}

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/ObjectDatabase.cs
Expand Up @@ -33,7 +33,7 @@ public bool Contains(ObjectId objectId)
{
var oid = objectId.Oid;

return NativeMethods.git_odb_exists(handle, ref oid) != (int)GitErrorCode.GIT_OK;
return NativeMethods.git_odb_exists(handle, ref oid) != (int)GitErrorCode.Ok;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Reference.cs
Expand Up @@ -63,7 +63,7 @@ private static ReferenceSafeHandle PeelToDirectReference(ReferenceSafeHandle han
ReferenceSafeHandle resolvedHandle;
int res = NativeMethods.git_reference_resolve(out resolvedHandle, handle);

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/ReferenceCollection.cs
Expand Up @@ -118,7 +118,7 @@ private ObjectId Unabbreviate(ObjectId targetId)

if (obj == null)
{
Ensure.Success((int)GitErrorCode.GIT_ENOTFOUND);
Ensure.Success((int)GitErrorCode.NotFound);
}

return obj.Id;
Expand Down Expand Up @@ -233,7 +233,7 @@ private ReferenceSafeHandle RetrieveReferencePtr(string referenceName, bool shou
ReferenceSafeHandle reference;
int res = NativeMethods.git_reference_lookup(out reference, repo.Handle, referenceName);

if (!shouldThrowIfNotFound && res == (int)GitErrorCode.GIT_ENOTFOUND)
if (!shouldThrowIfNotFound && res == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/RemoteCollection.cs
Expand Up @@ -34,7 +34,7 @@ internal RemoteSafeHandle LoadRemote(string name, bool throwsIfNotFound)

int res = NativeMethods.git_remote_load(out handle, repository.Handle, name);

if (res == (int)GitErrorCode.GIT_ENOTFOUND && !throwsIfNotFound)
if (res == (int)GitErrorCode.NotFound && !throwsIfNotFound)
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Repository.cs
Expand Up @@ -308,7 +308,7 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath know
res = NativeMethods.git_object_lookup(out obj, handle, ref oid, type);
}

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down Expand Up @@ -400,7 +400,7 @@ public static string Discover(string startingPath)

int result = NativeMethods.git_repository_discover(buffer, buffer.Length, startingPath, false, null);

if ((GitErrorCode)result == GitErrorCode.GIT_ENOTFOUND)
if ((GitErrorCode)result == GitErrorCode.NotFound)
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Tree.cs
Expand Up @@ -50,7 +50,7 @@ private TreeEntry RetrieveFromPath(FilePath relativePath)

int res = NativeMethods.git_tree_get_subtree(out objectPtr, obj.ObjectPtr, relativePath);

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down

0 comments on commit 2631f67

Please sign in to comment.