Skip to content

Commit 1f36860

Browse files
committed
Cache PeeledTarget to gain better performance
1 parent c8b59c7 commit 1f36860

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,22 @@ public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Com
167167
}
168168
}
169169

170+
private static Dictionary<string, GitObject> _cachedPeeledTarget = new Dictionary<string, GitObject>();
171+
170172
public static GitObject PeeledTarget(this Tag tag)
171173
{
174+
GitObject cachedTarget;
175+
if(_cachedPeeledTarget.TryGetValue(tag.Target.Sha, out cachedTarget))
176+
{
177+
return cachedTarget;
178+
}
172179
var target = tag.Target;
173180

174181
while (target is TagAnnotation)
175182
{
176183
target = ((TagAnnotation)(target)).Target;
177184
}
178-
185+
_cachedPeeledTarget.Add(tag.Target.Sha, target);
179186
return target;
180187
}
181188

0 commit comments

Comments
 (0)