diff options
author | Keith Dahlby <dahlbyk@gmail.com> | 2012-05-01 20:41:24 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-05-22 21:27:09 +0400 |
commit | 1c5e7c96c56bfe8c7b9c81cbeb9d44e2cf6248f8 (patch) | |
tree | 3ded0012f446f87f8b614339d119db91498bebed /LibGit2Sharp/Note.cs | |
parent | a400fa557ccddc40cbaa87c64210ae68ac941d6d (diff) |
Add notes retrieval
Diffstat (limited to 'LibGit2Sharp/Note.cs')
-rw-r--r-- | LibGit2Sharp/Note.cs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/LibGit2Sharp/Note.cs b/LibGit2Sharp/Note.cs new file mode 100644 index 00000000..18074933 --- /dev/null +++ b/LibGit2Sharp/Note.cs @@ -0,0 +1,104 @@ +using System; +using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp +{ + /// <summary> + /// A note, attached to a given <see cref = "GitObject"/>. + /// </summary> + public class Note + { + private Note(ObjectId blobId, string message, ObjectId targetObjectId, string @namespace) + { + BlobId = blobId; + Namespace = @namespace; + Message = message; + TargetObjectId = targetObjectId; + } + + /// <summary> + /// The <see cref = "ObjectId"/> of the blob containing the note message. + /// </summary> + public ObjectId BlobId { get; private set; } + + /// <summary> + /// The message. + /// </summary> + public string Message { get; private set; } + + /// <summary> + /// The namespace with which this note is associated. + /// <para>This is the abbreviated namespace (e.g.: commits), and not the canonical namespace (e.g.: refs/notes/commits).</para> + /// </summary> + public string Namespace { get; private set; } + + /// <summary> + /// The <see cref = "ObjectId"/> of the target object. + /// </summary> + public ObjectId TargetObjectId { get; private set; } + + internal static Note BuildFromPtr(Repository repo, string @namespace, ObjectId targetObjectId, NoteSafeHandle note) + { + ObjectId oid = NativeMethods.git_note_oid(note).MarshalAsObjectId(); + string message = NativeMethods.git_note_message(note); + + return new Note(oid, message, targetObjectId, @namespace); + } + + private static readonly LambdaEqualityHelper<Note> equalityHelper = + new LambdaEqualityHelper<Note>(new Func<Note, object>[] { x => x.BlobId, x => x.TargetObjectId, x => x.Namespace }); + + /// <summary> + /// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "Note" />. + /// </summary> + /// <param name = "obj">The <see cref = "Object" /> to compare with the current <see cref = "Note" />.</param> + /// <returns>True if the specified <see cref = "Object" /> is equal to the current <see cref = "Note" />; otherwise, false.</returns> + public override bool Equals(object obj) + { + return Equals(obj as Note); + } + + /// <summary> + /// Determines whether the specified <see cref = "Note" /> is equal to the current <see cref = "Note" />. + /// </summary> + /// <param name = "other">The <see cref = "Note" /> to compare with the current <see cref = "Note" />.</param> + /// <returns>True if the specified <see cref = "Note" /> is equal to the current <see cref = "Note" />; otherwise, false.</returns> + public bool Equals(Note 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 = "Note" /> are equal. + /// </summary> + /// <param name = "left">First <see cref = "Note" /> to compare.</param> + /// <param name = "right">Second <see cref = "Note" /> to compare.</param> + /// <returns>True if the two objects are equal; false otherwise.</returns> + public static bool operator ==(Note left, Note right) + { + return Equals(left, right); + } + + /// <summary> + /// Tests if two <see cref = "Note" /> are different. + /// </summary> + /// <param name = "left">First <see cref = "Note" /> to compare.</param> + /// <param name = "right">Second <see cref = "Note" /> to compare.</param> + /// <returns>True if the two objects are different; false otherwise.</returns> + public static bool operator !=(Note left, Note right) + { + return !Equals(left, right); + } + } +} |