Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use CSharp friendly names for libgit2 error types and codes

  • Loading branch information...
commit 2631f67f3a642d8b48c2f5065d3a2a4968bf2de9 1 parent dd15de9
@tclem tclem authored nulltoken committed
View
2  LibGit2Sharp/BranchCollection.cs
@@ -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;
}
View
4 LibGit2Sharp/CommitCollection.cs
@@ -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;
}
@@ -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;
}
View
6 LibGit2Sharp/Configuration.cs
@@ -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;
}
@@ -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;
}
@@ -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;
}
View
6 LibGit2Sharp/Core/Ensure.cs
@@ -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;
}
@@ -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
View
21 LibGit2Sharp/Core/GitError.cs
@@ -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;
}
}
View
40 LibGit2Sharp/Core/GitErrorCode.cs
@@ -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,
}
}
View
22 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,
+ }
+}
View
4 LibGit2Sharp/Index.cs
@@ -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;
}
@@ -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;
}
View
1  LibGit2Sharp/LibGit2Sharp.csproj
@@ -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" />
View
4 LibGit2Sharp/NoteCollection.cs
@@ -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;
}
@@ -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;
}
View
2  LibGit2Sharp/ObjectDatabase.cs
@@ -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>
View
2  LibGit2Sharp/Reference.cs
@@ -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;
}
View
4 LibGit2Sharp/ReferenceCollection.cs
@@ -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;
@@ -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;
}
View
2  LibGit2Sharp/RemoteCollection.cs
@@ -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;
}
View
4 LibGit2Sharp/Repository.cs
@@ -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;
}
@@ -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;
}
View
2  LibGit2Sharp/Tree.cs
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.