diff options
-rw-r--r-- | LibGit2Sharp/CommitLog.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/Core/GitObjectType.cs | 107 | ||||
-rw-r--r-- | LibGit2Sharp/GitObject.cs | 14 | ||||
-rw-r--r-- | LibGit2Sharp/GitObjectType.cs | 39 | ||||
-rw-r--r-- | LibGit2Sharp/IRepository.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/LibGit2Sharp.csproj | 1 | ||||
-rw-r--r-- | LibGit2Sharp/ObjectType.cs | 10 | ||||
-rw-r--r-- | LibGit2Sharp/OdbBackend.cs | 16 | ||||
-rw-r--r-- | LibGit2Sharp/ReferenceCollectionExtensions.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 20 | ||||
-rw-r--r-- | LibGit2Sharp/StashCollection.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/TagCollectionExtensions.cs | 4 | ||||
-rw-r--r-- | LibGit2Sharp/TreeEntry.cs | 4 | ||||
-rw-r--r-- | LibGit2Sharp/TreeEntryDefinition.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/TreeEntryTargetType.cs | 6 |
15 files changed, 156 insertions, 75 deletions
diff --git a/LibGit2Sharp/CommitLog.cs b/LibGit2Sharp/CommitLog.cs index 9618cd85..d6b9a9eb 100644 --- a/LibGit2Sharp/CommitLog.cs +++ b/LibGit2Sharp/CommitLog.cs @@ -248,7 +248,7 @@ namespace LibGit2Sharp } // TODO: Should we check the type? Git-log allows TagAnnotation oid as parameter. But what about Blobs and Trees? - GitObject commit = repo.Lookup(identifier, GitObjectType.Any, options); + GitObject commit = repo.Lookup(identifier, Core.GitObjectType.Any, options); return commit != null ? commit.Id : null; } diff --git a/LibGit2Sharp/Core/GitObjectType.cs b/LibGit2Sharp/Core/GitObjectType.cs new file mode 100644 index 00000000..083447c8 --- /dev/null +++ b/LibGit2Sharp/Core/GitObjectType.cs @@ -0,0 +1,107 @@ +using System; + +namespace LibGit2Sharp.Core +{ + /// <summary> + /// Underlying type of a <see cref = "GitObject" /> + /// </summary> + internal enum GitObjectType + { + /// <summary> + /// Object can be of any type. + /// </summary> + Any = -2, + + /// <summary> + /// Object is invalid. + /// </summary> + Bad = -1, + + /// <summary> + /// Reserved for future use. + /// </summary> + Ext1 = 0, + + /// <summary> + /// A commit object. + /// </summary> + Commit = 1, + + /// <summary> + /// A tree (directory listing) object. + /// </summary> + Tree = 2, + + /// <summary> + /// A file revision object. + /// </summary> + Blob = 3, + + /// <summary> + /// An annotated tag object. + /// </summary> + Tag = 4, + + /// <summary> + /// Reserved for future use. + /// </summary> + Ext2 = 5, + + /// <summary> + /// A delta, base is given by an offset. + /// </summary> + OfsDelta = 6, + + /// <summary> + /// A delta, base is given by object id. + /// </summary> + RefDelta = 7 + } + + internal static class GitObjectTypeExtensions + { + public static TreeEntryTargetType ToTreeEntryTargetType(this GitObjectType type) + { + switch (type) + { + case GitObjectType.Commit: + return TreeEntryTargetType.GitLink; + + case GitObjectType.Tree: + return TreeEntryTargetType.Tree; + + case GitObjectType.Blob: + return TreeEntryTargetType.Blob; + + default: + throw new InvalidOperationException(string.Format("Cannot map {0} to a TreeEntryTargetType.", type)); + } + } + + public static ObjectType ToObjectType(this GitObjectType type) + { + switch (type) + { + case GitObjectType.Commit: + return ObjectType.Commit; + + case GitObjectType.Tree: + return ObjectType.Tree; + + case GitObjectType.Blob: + return ObjectType.Blob; + + case GitObjectType.Tag: + return ObjectType.Tag; + + default: + throw new InvalidOperationException(string.Format("Cannot map {0} to a ObjectType.", type)); + } + } + + public static LibGit2Sharp.GitObjectType ToGitObjectType(this GitObjectType type) + { + return (LibGit2Sharp.GitObjectType)type; + } + } +} diff --git a/LibGit2Sharp/GitObject.cs b/LibGit2Sharp/GitObject.cs index e8420926..a61892c4 100644 --- a/LibGit2Sharp/GitObject.cs +++ b/LibGit2Sharp/GitObject.cs @@ -60,17 +60,17 @@ namespace LibGit2Sharp get { return Id.Sha; } } - internal static GitObject BuildFrom(Repository repo, ObjectId id, GitObjectType type, FilePath path) + internal static GitObject BuildFrom(Repository repo, ObjectId id, Core.GitObjectType type, FilePath path) { switch (type) { - case GitObjectType.Commit: + case Core.GitObjectType.Commit: return new Commit(repo, id); - case GitObjectType.Tree: + case Core.GitObjectType.Tree: return new Tree(repo, id, path); - case GitObjectType.Tag: + case Core.GitObjectType.Tag: return new TagAnnotation(repo, id); - case GitObjectType.Blob: + case Core.GitObjectType.Blob: return new Blob(repo, id); default: throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unexpected type '{0}' for object '{1}'.", type, id)); @@ -79,14 +79,14 @@ namespace LibGit2Sharp internal Commit DereferenceToCommit(bool throwsIfCanNotBeDereferencedToACommit) { - using (GitObjectSafeHandle peeledHandle = Proxy.git_object_peel(repo.Handle, Id, GitObjectType.Commit, throwsIfCanNotBeDereferencedToACommit)) + using (GitObjectSafeHandle peeledHandle = Proxy.git_object_peel(repo.Handle, Id, Core.GitObjectType.Commit, throwsIfCanNotBeDereferencedToACommit)) { if (peeledHandle == null) { return null; } - return (Commit) BuildFrom(repo, Proxy.git_object_id(peeledHandle), GitObjectType.Commit, null); + return (Commit)BuildFrom(repo, Proxy.git_object_id(peeledHandle), Core.GitObjectType.Commit, null); } } diff --git a/LibGit2Sharp/GitObjectType.cs b/LibGit2Sharp/GitObjectType.cs index 024943e3..70cc88e6 100644 --- a/LibGit2Sharp/GitObjectType.cs +++ b/LibGit2Sharp/GitObjectType.cs @@ -5,6 +5,7 @@ namespace LibGit2Sharp /// <summary> /// Underlying type of a <see cref = "GitObject" /> /// </summary> + [Obsolete("This type will be removed in the next release.")] public enum GitObjectType { /// <summary> @@ -60,43 +61,9 @@ namespace LibGit2Sharp internal static class GitObjectTypeExtensions { - public static TreeEntryTargetType ToTreeEntryTargetType(this GitObjectType type) + public static Core.GitObjectType ToCoreGitObjectType(this GitObjectType type) { - switch (type) - { - case GitObjectType.Commit: - return TreeEntryTargetType.GitLink; - - case GitObjectType.Tree: - return TreeEntryTargetType.Tree; - - case GitObjectType.Blob: - return TreeEntryTargetType.Blob; - - default: - throw new InvalidOperationException(string.Format("Cannot map {0} to a TreeEntryTargetType.", type)); - } - } - - public static ObjectType ToObjectType(this GitObjectType type) - { - switch (type) - { - case GitObjectType.Commit: - return ObjectType.Commit; - - case GitObjectType.Tree: - return ObjectType.Tree; - - case GitObjectType.Blob: - return ObjectType.Blob; - - case GitObjectType.Tag: - return ObjectType.Tag; - - default: - throw new InvalidOperationException(string.Format("Cannot map {0} to a ObjectType.", type)); - } + return (Core.GitObjectType)type; } } } diff --git a/LibGit2Sharp/IRepository.cs b/LibGit2Sharp/IRepository.cs index 24f41031..0da38104 100644 --- a/LibGit2Sharp/IRepository.cs +++ b/LibGit2Sharp/IRepository.cs @@ -95,6 +95,7 @@ namespace LibGit2Sharp /// <param name = "id">The id to lookup.</param> /// <param name = "type">The kind of GitObject being looked up</param> /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns> + [Obsolete("This method will be removed in the next release. Please use another Repository.Lookup() overload instead.")] GitObject Lookup(ObjectId id, GitObjectType type = GitObjectType.Any); /// <summary> @@ -103,6 +104,7 @@ namespace LibGit2Sharp /// <param name = "objectish">A revparse spec for the object to lookup.</param> /// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param> /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns> + [Obsolete("This method will be removed in the next release. Please use another Repository.Lookup() overload instead.")] GitObject Lookup(string objectish, GitObjectType type = GitObjectType.Any); /// <summary> diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index cf4fc0a3..d36959ac 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -207,6 +207,7 @@ <Compile Include="Core\GitIndexEntry.cs" /> <Compile Include="GitObject.cs" /> <Compile Include="GitObjectType.cs" /> + <Compile Include="Core\GitObjectType.cs" /> <Compile Include="GitSortOptions.cs" /> <Compile Include="Core\LambdaEqualityHelper.cs" /> <Compile Include="ICommitLog.cs" /> diff --git a/LibGit2Sharp/ObjectType.cs b/LibGit2Sharp/ObjectType.cs index efe4e251..c23a6046 100644 --- a/LibGit2Sharp/ObjectType.cs +++ b/LibGit2Sharp/ObjectType.cs @@ -30,21 +30,21 @@ namespace LibGit2Sharp internal static class ObjectTypeExtensions { - public static GitObjectType ToGitObjectType(this ObjectType type) + public static Core.GitObjectType ToGitObjectType(this ObjectType type) { switch (type) { case ObjectType.Commit: - return GitObjectType.Commit; + return Core.GitObjectType.Commit; case ObjectType.Tree: - return GitObjectType.Tree; + return Core.GitObjectType.Tree; case ObjectType.Blob: - return GitObjectType.Blob; + return Core.GitObjectType.Blob; case ObjectType.Tag: - return GitObjectType.Tag; + return Core.GitObjectType.Tag; default: throw new InvalidOperationException(string.Format("Cannot map {0} to a GitObjectType.", type)); diff --git a/LibGit2Sharp/OdbBackend.cs b/LibGit2Sharp/OdbBackend.cs index 5a204869..cf76cdce 100644 --- a/LibGit2Sharp/OdbBackend.cs +++ b/LibGit2Sharp/OdbBackend.cs @@ -197,13 +197,13 @@ namespace LibGit2Sharp private unsafe static int Read( out IntPtr buffer_p, out UIntPtr len_p, - out GitObjectType type_p, + out Core.GitObjectType type_p, IntPtr backend, ref GitOid oid) { buffer_p = IntPtr.Zero; len_p = UIntPtr.Zero; - type_p = GitObjectType.Bad; + type_p = Core.GitObjectType.Bad; OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; @@ -255,7 +255,7 @@ namespace LibGit2Sharp out GitOid out_oid, out IntPtr buffer_p, out UIntPtr len_p, - out GitObjectType type_p, + out Core.GitObjectType type_p, IntPtr backend, ref GitOid short_oid, UIntPtr len) @@ -263,7 +263,7 @@ namespace LibGit2Sharp out_oid = default(GitOid); buffer_p = IntPtr.Zero; len_p = UIntPtr.Zero; - type_p = GitObjectType.Bad; + type_p = Core.GitObjectType.Bad; OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; @@ -320,12 +320,12 @@ namespace LibGit2Sharp private static int ReadHeader( out UIntPtr len_p, - out GitObjectType type_p, + out Core.GitObjectType type_p, IntPtr backend, ref GitOid oid) { len_p = UIntPtr.Zero; - type_p = GitObjectType.Bad; + type_p = Core.GitObjectType.Bad; OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; @@ -360,7 +360,7 @@ namespace LibGit2Sharp IntPtr backend, IntPtr data, UIntPtr len, - GitObjectType type) + Core.GitObjectType type) { OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; @@ -398,7 +398,7 @@ namespace LibGit2Sharp out IntPtr stream_out, IntPtr backend, UIntPtr length, - GitObjectType type) + Core.GitObjectType type) { stream_out = IntPtr.Zero; diff --git a/LibGit2Sharp/ReferenceCollectionExtensions.cs b/LibGit2Sharp/ReferenceCollectionExtensions.cs index 15cbaa50..3d7c0905 100644 --- a/LibGit2Sharp/ReferenceCollectionExtensions.cs +++ b/LibGit2Sharp/ReferenceCollectionExtensions.cs @@ -47,7 +47,7 @@ namespace LibGit2Sharp Reference reference; RefState refState = TryResolveReference(out reference, refsColl, canonicalRefNameOrObjectish); - var gitObject = refsColl.repo.Lookup(canonicalRefNameOrObjectish, GitObjectType.Any, LookUpOptions.None); + var gitObject = refsColl.repo.Lookup(canonicalRefNameOrObjectish, Core.GitObjectType.Any, LookUpOptions.None); if (refState == RefState.Exists) { diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 54707803..1840dd6b 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -392,7 +392,7 @@ namespace LibGit2Sharp /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns> public GitObject Lookup(ObjectId id) { - return LookupInternal(id, GitObjectType.Any, null); + return LookupInternal(id, Core.GitObjectType.Any, null); } /// <summary> @@ -402,7 +402,7 @@ namespace LibGit2Sharp /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns> public GitObject Lookup(string objectish) { - return Lookup(objectish, GitObjectType.Any, LookUpOptions.None); + return Lookup(objectish, Core.GitObjectType.Any, LookUpOptions.None); } /// <summary> @@ -433,12 +433,13 @@ namespace LibGit2Sharp /// <param name = "id">The id to lookup.</param> /// <param name = "type">The kind of GitObject being looked up</param> /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns> + [Obsolete("This method will be removed in the next release. Please use another Repository.Lookup() overload instead.")] public GitObject Lookup(ObjectId id, GitObjectType type = GitObjectType.Any) { - return LookupInternal(id, type, null); + return LookupInternal(id, type.ToCoreGitObjectType(), null); } - internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath knownPath) + internal GitObject LookupInternal(ObjectId id, Core.GitObjectType type, FilePath knownPath) { Ensure.ArgumentNotNull(id, "id"); @@ -467,9 +468,10 @@ namespace LibGit2Sharp /// <param name = "objectish">A revparse spec for the object to lookup.</param> /// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param> /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns> + [Obsolete("This method will be removed in the next release. Please use another Repository.Lookup() overload instead.")] public GitObject Lookup(string objectish, GitObjectType type = GitObjectType.Any) { - return Lookup(objectish, type, LookUpOptions.None); + return Lookup(objectish, type.ToCoreGitObjectType(), LookUpOptions.None); } private static string PathFromRevparseSpec(string spec) @@ -488,7 +490,7 @@ namespace LibGit2Sharp return (m.Groups.Count > 1) ? m.Groups[1].Value : null; } - internal GitObject Lookup(string objectish, GitObjectType type, LookUpOptions lookUpOptions) + internal GitObject Lookup(string objectish, Core.GitObjectType type, LookUpOptions lookUpOptions) { Ensure.ArgumentNotNullOrEmptyString(objectish, "commitOrBranchSpec"); @@ -505,9 +507,9 @@ namespace LibGit2Sharp return null; } - GitObjectType objType = Proxy.git_object_type(sh); + Core.GitObjectType objType = Proxy.git_object_type(sh); - if (type != GitObjectType.Any && objType != type) + if (type != Core.GitObjectType.Any && objType != type) { return null; } @@ -531,7 +533,7 @@ namespace LibGit2Sharp /// <returns>The commit.</returns> internal Commit LookupCommit(string committish) { - return (Commit)Lookup(committish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound | LookUpOptions.DereferenceResultToCommit | LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit); + return (Commit)Lookup(committish, Core.GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound | LookUpOptions.DereferenceResultToCommit | LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit); } /// <summary> diff --git a/LibGit2Sharp/StashCollection.cs b/LibGit2Sharp/StashCollection.cs index 7807c1f8..33cbf294 100644 --- a/LibGit2Sharp/StashCollection.cs +++ b/LibGit2Sharp/StashCollection.cs @@ -69,7 +69,7 @@ namespace LibGit2Sharp throw new ArgumentOutOfRangeException("index", "The passed index must be a positive integer."); } - GitObject stashCommit = repo.Lookup(string.Format("stash@{{{0}}}", index), GitObjectType.Commit, LookUpOptions.None); + GitObject stashCommit = repo.Lookup(string.Format("stash@{{{0}}}", index), Core.GitObjectType.Commit, LookUpOptions.None); return stashCommit == null ? null : new Stash(repo, stashCommit.Id, index); } diff --git a/LibGit2Sharp/TagCollectionExtensions.cs b/LibGit2Sharp/TagCollectionExtensions.cs index 413f37e1..210ba971 100644 --- a/LibGit2Sharp/TagCollectionExtensions.cs +++ b/LibGit2Sharp/TagCollectionExtensions.cs @@ -20,7 +20,7 @@ namespace LibGit2Sharp { Ensure.ArgumentNotNullOrEmptyString(objectish, "target"); - GitObject objectToTag = tags.repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound); + GitObject objectToTag = tags.repo.Lookup(objectish, Core.GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound); return tags.Add(name, objectToTag, tagger, message, allowOverwrite); } @@ -36,7 +36,7 @@ namespace LibGit2Sharp { Ensure.ArgumentNotNullOrEmptyString(objectish, "objectish"); - GitObject objectToTag = tags.repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound); + GitObject objectToTag = tags.repo.Lookup(objectish, Core.GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound); return tags.Add(name, objectToTag, allowOverwrite); } diff --git a/LibGit2Sharp/TreeEntry.cs b/LibGit2Sharp/TreeEntry.cs index 65f3795b..bcf92d6b 100644 --- a/LibGit2Sharp/TreeEntry.cs +++ b/LibGit2Sharp/TreeEntry.cs @@ -32,8 +32,8 @@ namespace LibGit2Sharp this.repo = repo; targetOid = Proxy.git_tree_entry_id(obj); - GitObjectType treeEntryTargetType = Proxy.git_tree_entry_type(obj); - Type = treeEntryTargetType; + Core.GitObjectType treeEntryTargetType = Proxy.git_tree_entry_type(obj); + Type = treeEntryTargetType.ToGitObjectType(); TargetType = treeEntryTargetType.ToTreeEntryTargetType(); target = new Lazy<GitObject>(RetrieveTreeEntryTarget); diff --git a/LibGit2Sharp/TreeEntryDefinition.cs b/LibGit2Sharp/TreeEntryDefinition.cs index 6aa3c7c5..5ef55b2d 100644 --- a/LibGit2Sharp/TreeEntryDefinition.cs +++ b/LibGit2Sharp/TreeEntryDefinition.cs @@ -180,6 +180,7 @@ namespace LibGit2Sharp get { return Mode.Directory; } } + [Obsolete("This property will be removed in the next release. Please use TransientTreeTreeEntryDefinition.TargetType instead.")] public override GitObjectType Type { get { return GitObjectType.Tree; } @@ -193,6 +194,7 @@ namespace LibGit2Sharp internal class TransientBlobTreeEntryDefinition : TransientTreeEntryDefinition { + [Obsolete("This property will be removed in the next release. Please use TransientBlobTreeEntryDefinition.TargetType instead.")] public override GitObjectType Type { get { return GitObjectType.Blob; } diff --git a/LibGit2Sharp/TreeEntryTargetType.cs b/LibGit2Sharp/TreeEntryTargetType.cs index abfc8350..0178b92d 100644 --- a/LibGit2Sharp/TreeEntryTargetType.cs +++ b/LibGit2Sharp/TreeEntryTargetType.cs @@ -30,15 +30,15 @@ namespace LibGit2Sharp internal static class TreeEntryTargetTypeExtensions { - public static GitObjectType ToGitObjectType(this TreeEntryTargetType type) + public static Core.GitObjectType ToGitObjectType(this TreeEntryTargetType type) { switch (type) { case TreeEntryTargetType.Tree: - return GitObjectType.Tree; + return Core.GitObjectType.Tree; case TreeEntryTargetType.Blob: - return GitObjectType.Blob; + return Core.GitObjectType.Blob; default: throw new InvalidOperationException(string.Format("Cannot map {0} to a GitObjectType.", type)); |