Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions LibGit2Sharp/Core/GitOid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,15 @@ internal struct GitOid
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] Id;

public static implicit operator ObjectId(GitOid oid)
{
return new ObjectId(oid);
}

public static implicit operator ObjectId(GitOid? oid)
{
return oid == null ? null : new ObjectId(oid.Value);
}
}
}
6 changes: 3 additions & 3 deletions LibGit2Sharp/Core/Handles/OidSafeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ namespace LibGit2Sharp.Core.Handles
{
internal class OidSafeHandle : NotOwnedSafeHandleBase
{
private GitOid MarshalAsGitOid()
private GitOid? MarshalAsGitOid()
{
return (GitOid)Marshal.PtrToStructure(handle, typeof(GitOid));
return (GitOid?)Marshal.PtrToStructure(handle, typeof(GitOid));
}

public ObjectId MarshalAsObjectId()
{
return new ObjectId(MarshalAsGitOid());
return MarshalAsGitOid();
}
}
}
22 changes: 11 additions & 11 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static ObjectId git_blob_create_fromchunks(RepositorySafeHandle repo, Fil
int res = NativeMethods.git_blob_create_fromchunks(ref oid, repo, hintpath, fileCallback, IntPtr.Zero);
Ensure.ZeroResult(res);

return new ObjectId(oid);
return oid;
}
}

Expand All @@ -57,7 +57,7 @@ public static ObjectId git_blob_create_fromdisk(RepositorySafeHandle repo, FileP
int res = NativeMethods.git_blob_create_fromdisk(ref oid, repo, path);
Ensure.ZeroResult(res);

return new ObjectId(oid);
return oid;
}
}

Expand All @@ -69,7 +69,7 @@ public static ObjectId git_blob_create_fromfile(RepositorySafeHandle repo, FileP
int res = NativeMethods.git_blob_create_fromworkdir(ref oid, repo, path);
Ensure.ZeroResult(res);

return new ObjectId(oid);
return oid;
}
}

Expand Down Expand Up @@ -265,7 +265,7 @@ public static ObjectId git_commit_create(
committerHandle, encoding, prettifiedMessage, treePtr.ObjectPtr, parentObjectPtrs.Count, parentsPtrs);
Ensure.ZeroResult(res);

return new ObjectId(commitOid);
return commitOid;
}
}

Expand Down Expand Up @@ -769,7 +769,7 @@ public static void git_index_write(IndexSafeHandle index)
}
}

public static GitOid git_tree_create_fromindex(Index index)
public static ObjectId git_tree_create_fromindex(Index index)
{
using (ThreadAffinity())
{
Expand Down Expand Up @@ -801,7 +801,7 @@ public static ObjectId git_merge_base(RepositorySafeHandle repo, Commit first, C

Ensure.ZeroResult(res);

return new ObjectId(ret);
return ret;
}
}

Expand Down Expand Up @@ -848,7 +848,7 @@ public static ObjectId git_note_create(
int res = NativeMethods.git_note_create(out noteOid, repo, authorHandle, committerHandle, notes_ref, ref oid, note, force ? 1 : 0);
Ensure.ZeroResult(res);

return new ObjectId(noteOid);
return noteOid;
}
}

Expand Down Expand Up @@ -1699,7 +1699,7 @@ public static ObjectId git_revwalk_next(RevWalkerSafeHandle walker)

Ensure.ZeroResult(res);

return new ObjectId(ret);
return ret;
}
}

Expand Down Expand Up @@ -1798,7 +1798,7 @@ public static ObjectId git_tag_create(
int res = NativeMethods.git_tag_create(out oid, repo, name, objectPtr.ObjectPtr, taggerHandle, message, allowOverwrite);
Ensure.ZeroResult(res);

return new ObjectId(oid);
return oid;
}
}

Expand All @@ -1811,7 +1811,7 @@ public static ObjectId git_tag_create_lightweight(RepositorySafeHandle repo, str
int res = NativeMethods.git_tag_create_lightweight(out oid, repo, name, objectPtr.ObjectPtr, allowOverwrite);
Ensure.ZeroResult(res);

return new ObjectId(oid);
return oid;
}
}

Expand Down Expand Up @@ -1958,7 +1958,7 @@ public static ObjectId git_treebuilder_write(RepositorySafeHandle repo, TreeBuil
int res = NativeMethods.git_treebuilder_write(out oid, repo, bld);
Ensure.ZeroResult(res);

return new ObjectId(oid);
return oid;
}
}

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/IndexEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal static IndexEntry BuildFromPtr(Repository repo, IndexEntrySafeHandle ha
return new IndexEntry
{
Path = path.Native,
Id = new ObjectId(entry.oid),
Id = entry.oid,
state = () => repo.Index.RetrieveStatus(path.Native),
StageLevel = Proxy.git_index_entry_stage(handle),
Mode = (Mode)entry.Mode
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public virtual IEnumerable<FetchHead> FetchHeads

return Proxy.git_repository_fetchhead_foreach(
repository.Handle,
(name, url, oid, isMerge) => new FetchHead(repository, name, url, new ObjectId(oid), isMerge, i++));
(name, url, oid, isMerge) => new FetchHead(repository, name, url, oid, isMerge, i++));
}
}

Expand Down Expand Up @@ -76,7 +76,7 @@ public virtual IEnumerable<DirectReference> ListReferences(Remote remote)
return -1;
}

ObjectId oid = new ObjectId(remoteHead.Oid);
ObjectId oid = remoteHead.Oid;
string name = Utf8Marshaler.FromNative(remoteHead.NamePtr);
directReferences.Add(new DirectReference(name, this.repository, oid));

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/NoteCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public virtual IEnumerable<Note> this[string @namespace]
string canonicalNamespace = NormalizeToCanonicalName(@namespace);

return Proxy.git_note_foreach(repo.Handle, canonicalNamespace,
(blobId,annotatedObjId) => RetrieveNote(new ObjectId(annotatedObjId), canonicalNamespace));
(blobId,annotatedObjId) => RetrieveNote(annotatedObjId, canonicalNamespace));
}
}

Expand Down
16 changes: 1 addition & 15 deletions LibGit2Sharp/ObjectId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public virtual string Sha
/// <returns>true if the <paramref name = "sha" /> parameter was converted successfully; otherwise, false.</returns>
public static bool TryParse(string sha, out ObjectId result)
{
result = BuildFrom(sha, false);
result = BuildOidFrom(sha, false);

return result != null;
}
Expand All @@ -113,20 +113,6 @@ public static bool TryParse(string sha, out ObjectId result)
return ToOid(sha);
}

private static ObjectId BuildFrom(string sha, bool shouldThrowIfInvalid)
{
GitOid? oid = BuildOidFrom(sha, shouldThrowIfInvalid);

if (!oid.HasValue)
{
return null;
}

var objectId = new ObjectId(oid.Value);

return objectId;
}

/// <summary>
/// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "ObjectId" />.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/RemoteCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private int GitUpdateTipsHandler(IntPtr str, ref GitOid oldId, ref GitOid newId,
if (onUpdateTips != null)
{
string refName = Utf8Marshaler.FromNative(str);
result = onUpdateTips(refName, new ObjectId(oldId), new ObjectId(newId));
result = onUpdateTips(refName, oldId, newId);
}

return result;
Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ public Commit Commit(string message, Signature author, Signature committer, bool
throw new LibGit2SharpException("Can not amend anything. The Head doesn't point at any commit.");
}

GitOid treeOid = Proxy.git_tree_create_fromindex(Index);
var tree = this.Lookup<Tree>(new ObjectId(treeOid));
var treeId = Proxy.git_tree_create_fromindex(Index);
var tree = this.Lookup<Tree>(treeId);

var parents = RetrieveParentsOfTheCommitBeingCreated(amendPreviousCommit);

Expand Down Expand Up @@ -774,7 +774,7 @@ public virtual IEnumerable<MergeHead> MergeHeads
{
int i = 0;
return Proxy.git_repository_mergehead_foreach(Handle,
commitId => new MergeHead(this, new ObjectId(commitId), i++));
commitId => new MergeHead(this, commitId, i++));
}
}

Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/TreeChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private TreeEntryChanges AddFileChange(GitDiffDelta delta, GitDiffLineOrigin lin
var oldFilePath = FilePathMarshaler.FromNative(delta.OldFile.Path);
var newMode = (Mode)delta.NewFile.Mode;
var oldMode = (Mode)delta.OldFile.Mode;
var newOid = new ObjectId(delta.NewFile.Oid);
var oldOid = new ObjectId(delta.OldFile.Oid);
var newOid = delta.NewFile.Oid;
var oldOid = delta.OldFile.Oid;

if (delta.Status == ChangeKind.Untracked)
{
Expand Down