Skip to content

Commit 617b9b8

Browse files
committed
Unify BuildFromPtr/CreateFromPtr implementation and usage
1 parent eb304fb commit 617b9b8

File tree

10 files changed

+16
-20
lines changed

10 files changed

+16
-20
lines changed

LibGit2Sharp/GitObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public virtual string Sha
5151
get { return Id.Sha; }
5252
}
5353

54-
internal static GitObject CreateFromPtr(GitObjectSafeHandle obj, ObjectId id, Repository repo, FilePath path)
54+
internal static GitObject BuildFromPtr(GitObjectSafeHandle obj, ObjectId id, Repository repo, FilePath path)
5555
{
5656
GitObjectType type = Proxy.git_object_type(obj);
5757
switch (type)

LibGit2Sharp/Index.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private IndexEntry this[uint index]
8181
get
8282
{
8383
IndexEntrySafeHandle entryHandle = Proxy.git_index_get(handle, index);
84-
return IndexEntry.CreateFromPtr(repo, entryHandle);
84+
return IndexEntry.BuildFromPtr(repo, entryHandle);
8585
}
8686
}
8787

LibGit2Sharp/IndexEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public FileStatus State
3838
/// </summary>
3939
public ObjectId Id { get; private set; }
4040

41-
internal static IndexEntry CreateFromPtr(Repository repo, IndexEntrySafeHandle handle)
41+
internal static IndexEntry BuildFromPtr(Repository repo, IndexEntrySafeHandle handle)
4242
{
4343
GitIndexEntry entry = handle.MarshalAsGitIndexEntry();
4444

LibGit2Sharp/Note.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private Note(ObjectId blobId, string message, ObjectId targetObjectId, string @n
4444
/// </summary>
4545
public virtual ObjectId TargetObjectId { get; private set; }
4646

47-
internal static Note BuildFromPtr(string @namespace, ObjectId targetObjectId, NoteSafeHandle note)
47+
internal static Note BuildFromPtr(NoteSafeHandle note, string @namespace, ObjectId targetObjectId)
4848
{
4949
ObjectId oid = Proxy.git_note_oid(note);
5050
string message = Proxy.git_note_message(note);

LibGit2Sharp/NoteCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ internal Note RetrieveNote(ObjectId targetObjectId, string canonicalNamespace)
119119
{
120120
using (NoteSafeHandle noteHandle = Proxy.git_note_read(repo.Handle, canonicalNamespace, targetObjectId))
121121
{
122-
return noteHandle == null ? null :
123-
Note.BuildFromPtr(UnCanonicalizeName(canonicalNamespace), targetObjectId, noteHandle);
122+
return noteHandle == null ? null :
123+
Note.BuildFromPtr(noteHandle, UnCanonicalizeName(canonicalNamespace), targetObjectId);
124124
}
125125
}
126126

@@ -211,7 +211,7 @@ public virtual void Remove(ObjectId targetId, Signature author, Signature commit
211211
Ensure.ArgumentNotNullOrEmptyString(@namespace, "@namespace");
212212

213213
string canonicalNamespace = NormalizeToCanonicalName(@namespace);
214-
214+
215215
Proxy.git_note_remove(repo.Handle, canonicalNamespace, author, committer, targetId);
216216
}
217217

LibGit2Sharp/ReferenceCollection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ internal T Resolve<T>(string name) where T : Reference
231231

232232
using (ReferenceSafeHandle referencePtr = RetrieveReferencePtr(name, false))
233233
{
234-
return referencePtr == null ? null : Reference.BuildFromPtr<T>(referencePtr, repo);
234+
return referencePtr == null ? null :
235+
Reference.BuildFromPtr<T>(referencePtr, repo);
235236
}
236237
}
237238

LibGit2Sharp/Remote.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ public class Remote : IEquatable<Remote>
1818
protected Remote()
1919
{ }
2020

21-
internal static Remote CreateFromPtr(RemoteSafeHandle handle)
21+
internal static Remote BuildFromPtr(RemoteSafeHandle handle)
2222
{
23-
if (handle == null)
24-
{
25-
return null;
26-
}
27-
2823
string name = Proxy.git_remote_name(handle);
2924
string url = Proxy.git_remote_url(handle);
3025

LibGit2Sharp/RemoteCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private Remote RemoteForName(string name)
3939
{
4040
using (RemoteSafeHandle handle = Proxy.git_remote_load(repository.Handle, name, false))
4141
{
42-
return Remote.CreateFromPtr(handle);
42+
return handle == null ? null : Remote.BuildFromPtr(handle);
4343
}
4444
}
4545

@@ -80,7 +80,7 @@ public virtual Remote Add(string name, string url)
8080

8181
using (RemoteSafeHandle handle = Proxy.git_remote_add(repository.Handle, name, url))
8282
{
83-
return Remote.CreateFromPtr(handle);
83+
return Remote.BuildFromPtr(handle);
8484
}
8585
}
8686

@@ -115,7 +115,7 @@ public virtual Remote Add(string name, string url, string fetchRefSpec)
115115
using (RemoteSafeHandle handle = Proxy.git_remote_new(repository.Handle, name, url, fetchRefSpec))
116116
{
117117
Proxy.git_remote_save(handle);
118-
return Remote.CreateFromPtr(handle);
118+
return Remote.BuildFromPtr(handle);
119119
}
120120
}
121121

LibGit2Sharp/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath know
306306
obj = Proxy.git_object_lookup(handle, id, type);
307307
}
308308

309-
return obj == null ? null : GitObject.CreateFromPtr(obj, id, this, knownPath);
309+
return obj == null ? null : GitObject.BuildFromPtr(obj, id, this, knownPath);
310310
}
311311
finally
312312
{
@@ -363,7 +363,7 @@ internal GitObject Lookup(string objectish, GitObjectType type, LookUpOptions lo
363363
return null;
364364
}
365365

366-
obj = GitObject.CreateFromPtr(sh, GitObject.ObjectIdOf(sh), this, PathFromRevparseSpec(objectish));
366+
obj = GitObject.BuildFromPtr(sh, GitObject.ObjectIdOf(sh), this, PathFromRevparseSpec(objectish));
367367
}
368368

369369
if (lookUpOptions.Has(LookUpOptions.DereferenceResultToCommit))

LibGit2Sharp/Tree.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ IEnumerator IEnumerable.GetEnumerator()
126126

127127
#endregion
128128

129-
internal static Tree BuildFromPtr(GitObjectSafeHandle obj, ObjectId id, Repository repo, FilePath path)
129+
internal new static Tree BuildFromPtr(GitObjectSafeHandle obj, ObjectId id, Repository repo, FilePath path)
130130
{
131131
var tree = new Tree(id, path, Proxy.git_tree_entrycount(obj), repo);
132132
return tree;

0 commit comments

Comments
 (0)