Skip to content

Commit fa1f266

Browse files
committed
Obsolete GitObjectType
1 parent d6c74d2 commit fa1f266

15 files changed

+156
-75
lines changed

LibGit2Sharp/CommitLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private ObjectId DereferenceToCommit(string identifier)
248248
}
249249

250250
// TODO: Should we check the type? Git-log allows TagAnnotation oid as parameter. But what about Blobs and Trees?
251-
GitObject commit = repo.Lookup(identifier, GitObjectType.Any, options);
251+
GitObject commit = repo.Lookup(identifier, Core.GitObjectType.Any, options);
252252

253253
return commit != null ? commit.Id : null;
254254
}

LibGit2Sharp/Core/GitObjectType.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
3+
namespace LibGit2Sharp.Core
4+
{
5+
/// <summary>
6+
/// Underlying type of a <see cref = "GitObject" />
7+
/// </summary>
8+
internal enum GitObjectType
9+
{
10+
/// <summary>
11+
/// Object can be of any type.
12+
/// </summary>
13+
Any = -2,
14+
15+
/// <summary>
16+
/// Object is invalid.
17+
/// </summary>
18+
Bad = -1,
19+
20+
/// <summary>
21+
/// Reserved for future use.
22+
/// </summary>
23+
Ext1 = 0,
24+
25+
/// <summary>
26+
/// A commit object.
27+
/// </summary>
28+
Commit = 1,
29+
30+
/// <summary>
31+
/// A tree (directory listing) object.
32+
/// </summary>
33+
Tree = 2,
34+
35+
/// <summary>
36+
/// A file revision object.
37+
/// </summary>
38+
Blob = 3,
39+
40+
/// <summary>
41+
/// An annotated tag object.
42+
/// </summary>
43+
Tag = 4,
44+
45+
/// <summary>
46+
/// Reserved for future use.
47+
/// </summary>
48+
Ext2 = 5,
49+
50+
/// <summary>
51+
/// A delta, base is given by an offset.
52+
/// </summary>
53+
OfsDelta = 6,
54+
55+
/// <summary>
56+
/// A delta, base is given by object id.
57+
/// </summary>
58+
RefDelta = 7
59+
}
60+
61+
internal static class GitObjectTypeExtensions
62+
{
63+
public static TreeEntryTargetType ToTreeEntryTargetType(this GitObjectType type)
64+
{
65+
switch (type)
66+
{
67+
case GitObjectType.Commit:
68+
return TreeEntryTargetType.GitLink;
69+
70+
case GitObjectType.Tree:
71+
return TreeEntryTargetType.Tree;
72+
73+
case GitObjectType.Blob:
74+
return TreeEntryTargetType.Blob;
75+
76+
default:
77+
throw new InvalidOperationException(string.Format("Cannot map {0} to a TreeEntryTargetType.", type));
78+
}
79+
}
80+
81+
public static ObjectType ToObjectType(this GitObjectType type)
82+
{
83+
switch (type)
84+
{
85+
case GitObjectType.Commit:
86+
return ObjectType.Commit;
87+
88+
case GitObjectType.Tree:
89+
return ObjectType.Tree;
90+
91+
case GitObjectType.Blob:
92+
return ObjectType.Blob;
93+
94+
case GitObjectType.Tag:
95+
return ObjectType.Tag;
96+
97+
default:
98+
throw new InvalidOperationException(string.Format("Cannot map {0} to a ObjectType.", type));
99+
}
100+
}
101+
102+
public static LibGit2Sharp.GitObjectType ToGitObjectType(this GitObjectType type)
103+
{
104+
return (LibGit2Sharp.GitObjectType)type;
105+
}
106+
}
107+
}

LibGit2Sharp/GitObject.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ public virtual string Sha
6060
get { return Id.Sha; }
6161
}
6262

63-
internal static GitObject BuildFrom(Repository repo, ObjectId id, GitObjectType type, FilePath path)
63+
internal static GitObject BuildFrom(Repository repo, ObjectId id, Core.GitObjectType type, FilePath path)
6464
{
6565
switch (type)
6666
{
67-
case GitObjectType.Commit:
67+
case Core.GitObjectType.Commit:
6868
return new Commit(repo, id);
69-
case GitObjectType.Tree:
69+
case Core.GitObjectType.Tree:
7070
return new Tree(repo, id, path);
71-
case GitObjectType.Tag:
71+
case Core.GitObjectType.Tag:
7272
return new TagAnnotation(repo, id);
73-
case GitObjectType.Blob:
73+
case Core.GitObjectType.Blob:
7474
return new Blob(repo, id);
7575
default:
7676
throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unexpected type '{0}' for object '{1}'.", type, id));
@@ -79,14 +79,14 @@ internal static GitObject BuildFrom(Repository repo, ObjectId id, GitObjectType
7979

8080
internal Commit DereferenceToCommit(bool throwsIfCanNotBeDereferencedToACommit)
8181
{
82-
using (GitObjectSafeHandle peeledHandle = Proxy.git_object_peel(repo.Handle, Id, GitObjectType.Commit, throwsIfCanNotBeDereferencedToACommit))
82+
using (GitObjectSafeHandle peeledHandle = Proxy.git_object_peel(repo.Handle, Id, Core.GitObjectType.Commit, throwsIfCanNotBeDereferencedToACommit))
8383
{
8484
if (peeledHandle == null)
8585
{
8686
return null;
8787
}
8888

89-
return (Commit) BuildFrom(repo, Proxy.git_object_id(peeledHandle), GitObjectType.Commit, null);
89+
return (Commit)BuildFrom(repo, Proxy.git_object_id(peeledHandle), Core.GitObjectType.Commit, null);
9090
}
9191
}
9292

LibGit2Sharp/GitObjectType.cs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace LibGit2Sharp
55
/// <summary>
66
/// Underlying type of a <see cref = "GitObject" />
77
/// </summary>
8+
[Obsolete("This type will be removed in the next release.")]
89
public enum GitObjectType
910
{
1011
/// <summary>
@@ -60,43 +61,9 @@ public enum GitObjectType
6061

6162
internal static class GitObjectTypeExtensions
6263
{
63-
public static TreeEntryTargetType ToTreeEntryTargetType(this GitObjectType type)
64+
public static Core.GitObjectType ToCoreGitObjectType(this GitObjectType type)
6465
{
65-
switch (type)
66-
{
67-
case GitObjectType.Commit:
68-
return TreeEntryTargetType.GitLink;
69-
70-
case GitObjectType.Tree:
71-
return TreeEntryTargetType.Tree;
72-
73-
case GitObjectType.Blob:
74-
return TreeEntryTargetType.Blob;
75-
76-
default:
77-
throw new InvalidOperationException(string.Format("Cannot map {0} to a TreeEntryTargetType.", type));
78-
}
79-
}
80-
81-
public static ObjectType ToObjectType(this GitObjectType type)
82-
{
83-
switch (type)
84-
{
85-
case GitObjectType.Commit:
86-
return ObjectType.Commit;
87-
88-
case GitObjectType.Tree:
89-
return ObjectType.Tree;
90-
91-
case GitObjectType.Blob:
92-
return ObjectType.Blob;
93-
94-
case GitObjectType.Tag:
95-
return ObjectType.Tag;
96-
97-
default:
98-
throw new InvalidOperationException(string.Format("Cannot map {0} to a ObjectType.", type));
99-
}
66+
return (Core.GitObjectType)type;
10067
}
10168
}
10269
}

LibGit2Sharp/IRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public interface IRepository : IDisposable
9595
/// <param name = "id">The id to lookup.</param>
9696
/// <param name = "type">The kind of GitObject being looked up</param>
9797
/// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
98+
[Obsolete("This method will be removed in the next release. Please use another Repository.Lookup() overload instead.")]
9899
GitObject Lookup(ObjectId id, GitObjectType type = GitObjectType.Any);
99100

100101
/// <summary>
@@ -103,6 +104,7 @@ public interface IRepository : IDisposable
103104
/// <param name = "objectish">A revparse spec for the object to lookup.</param>
104105
/// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
105106
/// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
107+
[Obsolete("This method will be removed in the next release. Please use another Repository.Lookup() overload instead.")]
106108
GitObject Lookup(string objectish, GitObjectType type = GitObjectType.Any);
107109

108110
/// <summary>

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
<Compile Include="Core\GitIndexEntry.cs" />
208208
<Compile Include="GitObject.cs" />
209209
<Compile Include="GitObjectType.cs" />
210+
<Compile Include="Core\GitObjectType.cs" />
210211
<Compile Include="GitSortOptions.cs" />
211212
<Compile Include="Core\LambdaEqualityHelper.cs" />
212213
<Compile Include="ICommitLog.cs" />

LibGit2Sharp/ObjectType.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ public enum ObjectType
3030

3131
internal static class ObjectTypeExtensions
3232
{
33-
public static GitObjectType ToGitObjectType(this ObjectType type)
33+
public static Core.GitObjectType ToGitObjectType(this ObjectType type)
3434
{
3535
switch (type)
3636
{
3737
case ObjectType.Commit:
38-
return GitObjectType.Commit;
38+
return Core.GitObjectType.Commit;
3939

4040
case ObjectType.Tree:
41-
return GitObjectType.Tree;
41+
return Core.GitObjectType.Tree;
4242

4343
case ObjectType.Blob:
44-
return GitObjectType.Blob;
44+
return Core.GitObjectType.Blob;
4545

4646
case ObjectType.Tag:
47-
return GitObjectType.Tag;
47+
return Core.GitObjectType.Tag;
4848

4949
default:
5050
throw new InvalidOperationException(string.Format("Cannot map {0} to a GitObjectType.", type));

LibGit2Sharp/OdbBackend.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ private static class BackendEntryPoints
197197
private unsafe static int Read(
198198
out IntPtr buffer_p,
199199
out UIntPtr len_p,
200-
out GitObjectType type_p,
200+
out Core.GitObjectType type_p,
201201
IntPtr backend,
202202
ref GitOid oid)
203203
{
204204
buffer_p = IntPtr.Zero;
205205
len_p = UIntPtr.Zero;
206-
type_p = GitObjectType.Bad;
206+
type_p = Core.GitObjectType.Bad;
207207

208208
OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;
209209

@@ -255,15 +255,15 @@ private unsafe static int ReadPrefix(
255255
out GitOid out_oid,
256256
out IntPtr buffer_p,
257257
out UIntPtr len_p,
258-
out GitObjectType type_p,
258+
out Core.GitObjectType type_p,
259259
IntPtr backend,
260260
ref GitOid short_oid,
261261
UIntPtr len)
262262
{
263263
out_oid = default(GitOid);
264264
buffer_p = IntPtr.Zero;
265265
len_p = UIntPtr.Zero;
266-
type_p = GitObjectType.Bad;
266+
type_p = Core.GitObjectType.Bad;
267267

268268
OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;
269269

@@ -320,12 +320,12 @@ private unsafe static int ReadPrefix(
320320

321321
private static int ReadHeader(
322322
out UIntPtr len_p,
323-
out GitObjectType type_p,
323+
out Core.GitObjectType type_p,
324324
IntPtr backend,
325325
ref GitOid oid)
326326
{
327327
len_p = UIntPtr.Zero;
328-
type_p = GitObjectType.Bad;
328+
type_p = Core.GitObjectType.Bad;
329329

330330
OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;
331331

@@ -360,7 +360,7 @@ private static unsafe int Write(
360360
IntPtr backend,
361361
IntPtr data,
362362
UIntPtr len,
363-
GitObjectType type)
363+
Core.GitObjectType type)
364364
{
365365
OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;
366366

@@ -398,7 +398,7 @@ private static int WriteStream(
398398
out IntPtr stream_out,
399399
IntPtr backend,
400400
UIntPtr length,
401-
GitObjectType type)
401+
Core.GitObjectType type)
402402
{
403403
stream_out = IntPtr.Zero;
404404

LibGit2Sharp/ReferenceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static Reference Add(this ReferenceCollection refsColl, string name, stri
4747
Reference reference;
4848
RefState refState = TryResolveReference(out reference, refsColl, canonicalRefNameOrObjectish);
4949

50-
var gitObject = refsColl.repo.Lookup(canonicalRefNameOrObjectish, GitObjectType.Any, LookUpOptions.None);
50+
var gitObject = refsColl.repo.Lookup(canonicalRefNameOrObjectish, Core.GitObjectType.Any, LookUpOptions.None);
5151

5252
if (refState == RefState.Exists)
5353
{

0 commit comments

Comments
 (0)