8000 Minor code refactoring · MicrosoftWebMatrix/libgit2sharp@a91fca5 · GitHub
[go: up one dir, main page]

Skip to content

Commit a91fca5

Browse files
committed
Minor code refactoring
1 parent bdf54dd commit a91fca5

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

LibGit2Sharp/ObjectId.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@ public byte[] RawId
8787
/// <returns>true if the <paramref name="sha"/> parameter was converted successfully; otherwise, false.</returns>
8888
public static bool TryParse(string sha, out ObjectId result)
8989
{
90-
return TryParseInternal(sha, true, out result);
91-
}
92-
93-
internal static bool TryParseInternal(string sha, bool allowShortIdentifier, out ObjectId result)
94-
{
95-
result = BuildFrom(sha, false, allowShortIdentifier);
90+
result = BuildFrom(sha, false, true);
9691

9792
return (result == null) ? false : true;
9893
}

LibGit2Sharp/ReferenceCollection.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,32 @@ private int CreateSymbolicReference(string name, string target, bool allowOverwr
9494
return NativeMethods.git_reference_create_symbolic(out reference, repo.Handle, name, target, allowOverwrite);
9595
}
9696

97-
private int CreateDirectReference(string name, ObjectId targetOid, bool allowOverwrite, out IntPtr reference)
97+
private int CreateDirectReference(string name, ObjectId targetId, bool allowOverwrite, out IntPtr reference)
9898
{
99-
if (targetOid is AbbreviatedObjectId) //TODO: This is hacky... :-/
100-
{
101-
var obj = repo.Lookup(targetOid);
102-
if (obj == null)
103-
{
104-
Ensure.Success((int) GitErrorCode.GIT_ENOTFOUND);
105-
}
106-
targetOid = obj.Id;
107-
}
99+
targetId = Unabbreviate(targetId);
108100

109-
GitOid oid = targetOid.Oid;
101+
GitOid oid = targetId.Oid;
110102

111103
return NativeMethods.git_reference_create_oid(out reference, repo.Handle, name, ref oid, allowOverwrite);
112104
}
113105

106+
private ObjectId Unabbreviate(ObjectId targetId)
107+
{
108+
if (!(targetId is AbbreviatedObjectId))
109+
{
110+
return targetId;
111+
}
112+
113+
var obj = repo.Lookup(targetId);
114+
115+
if (obj == null)
116+
{
117+
Ensure.Success((int) GitErrorCode.GIT_ENOTFOUND);
118+
}
119+
120+
return obj.Id;
121+
}
122+
114123
/// <summary>
115124
/// Delete a reference with the specified name
116125
/// </summary>

0 commit comments

Comments
 (0)
0