-
Notifications
You must be signed in to change notification settings - Fork 889
/
Tag.cs
117 lines (103 loc) · 4.22 KB
/
Tag.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// A Tag
/// </summary>
public class Tag : ReferenceWrapper<GitObject>, IEquatable<Tag>
{
private static readonly LambdaEqualityHelper<Tag> equalityHelper =
new LambdaEqualityHelper<Tag>(new Func<Tag, object>[] { x => x.CanonicalName, x => x.Target });
internal Tag(Repository repo, Reference reference, string canonicalName)
: base(repo, reference, _ => canonicalName)
{
}
/// <summary>
/// Gets the optional information associated to this tag.
/// <para>When the <see cref = "Tag" /> is a lightweight tag, <c>null</c> is returned.</para>
/// </summary>
public TagAnnotation Annotation
{
get { return TargetObject as TagAnnotation; }
}
/// <summary>
/// Gets the <see cref = "GitObject" /> that this tag points to.
/// </summary>
public GitObject Target
{
get
{
GitObject target = TargetObject;
if ((!(target is TagAnnotation)))
{
return target;
}
return ((TagAnnotation)target).Target;
}
}
/// <summary>
/// Indicates whether the tag holds any metadata.
/// </summary>
public bool IsAnnotated
{
get { return Annotation != null; }
}
/// <summary>
/// Returns the friendly shortened name from a canonical name.
/// </summary>
/// <param name="canonicalName">The canonical name to shorten.</param>
/// <returns></returns>
protected override string Shorten(string canonicalName)
{
Ensure.ArgumentConformsTo(canonicalName, s => s.StartsWith("refs/tags/", StringComparison.Ordinal), "tagName");
return canonicalName.Substring("refs/tags/".Length);
}
/// <summary>
/// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "Tag" />.
/// </summary>
/// <param name = "obj">The <see cref = "Object" /> to compare with the current <see cref = "Tag" />.</param>
/// <returns>True if the specified <see cref = "Object" /> is equal to the current <see cref = "Tag" />; otherwise, false.</returns>
public override bool Equals(object obj)
{
return Equals(obj as Tag);
}
/// <summary>
/// Determines whether the specified <see cref = "Tag" /> is equal to the current <see cref = "Tag" />.
/// </summary>
/// <param name = "other">The <see cref = "Tag" /> to compare with the current <see cref = "Tag" />.</param>
/// <returns>True if the specified <see cref = "Tag" /> is equal to the current <see cref = "Tag" />; otherwise, false.</returns>
public bool Equals(Tag other)
{
return equalityHelper.Equals(this, other);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return equalityHelper.GetHashCode(this);
}
/// <summary>
/// Tests if two <see cref = "Tag" /> are equal.
/// </summary>
/// <param name = "left">First <see cref = "Tag" /> to compare.</param>
/// <param name = "right">Second <see cref = "Tag" /> to compare.</param>
/// <returns>True if the two objects are equal; false otherwise.</returns>
public static bool operator ==(Tag left, Tag right)
{
return Equals(left, right);
}
/// <summary>
/// Tests if two <see cref = "Tag" /> are different.
/// </summary>
/// <param name = "left">First <see cref = "Tag" /> to compare.</param>
/// <param name = "right">Second <see cref = "Tag" /> to compare.</param>
/// <returns>True if the two objects are different; false otherwise.</returns>
public static bool operator !=(Tag left, Tag right)
{
return !Equals(left, right);
}
}
}