|
| 1 | +using System; |
| 2 | +using LibGit2Sharp.Core; |
| 3 | +using LibGit2Sharp.Core.Handles; |
| 4 | + |
| 5 | +namespace LibGit2Sharp |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// A commit with information about its source. Input for merge and rebase functions |
| 9 | + /// </summary> |
| 10 | + public class AnnotatedCommit : IDisposable, IAnnotatedCommit |
| 11 | + { |
| 12 | + internal readonly Repository repository; |
| 13 | + internal AnnotatedCommitHandle Handle { get; private set; } |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// Initialize a <see cref="LibGit2Sharp.AnnotatedCommit"/> from extended SHA-1 syntax |
| 17 | + /// </summary> |
| 18 | + /// <param name="repository">The repository in which the commit lives</param> |
| 19 | + /// <param name="revspec">A string in extended SHA-1 syntax to look up the object</param> |
| 20 | + public AnnotatedCommit(Repository repository, string revspec) |
| 21 | + { |
| 22 | + this.repository = repository; |
| 23 | + this.Handle = Proxy.git_annotated_commit_from_revspec(repository.Handle, revspec); |
| 24 | + } |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// Initialize a <see cref="LibGit2Sharp.AnnotatedCommit"/> from extended SHA-1 syntax |
| 28 | + /// </summary> |
| 29 | + /// <param name="repository">The repository in which the commit lives</param> |
| 30 | + /// <param name="reference">A reference pointing to the commit</param> |
| 31 | + public AnnotatedCommit(Repository repository, Reference reference) |
| 32 | + { |
| 33 | + this.repository = repository; |
| 34 | + using (var refHandle = Proxy.git_reference_lookup(repository.Handle, reference.CanonicalName, true)) |
| 35 | + { |
| 36 | + this.Handle = Proxy.git_annotated_commit_from_ref(repository.Handle, refHandle); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// Initialize a <see cref="LibGit2Sharp.AnnotatedCommit"/> from extended SHA-1 syntax |
| 42 | + /// </summary> |
| 43 | + /// <param name="repository">The repository in which the commit lives</param> |
| 44 | + /// <param name="commit">A commit</param> |
| 45 | + public AnnotatedCommit(Repository repository, Commit commit) |
| 46 | + { |
| 47 | + this.repository = repository; |
| 48 | + this.Handle = Proxy.git_annotated_commit_lookup(repository.Handle, commit.Id.Oid); |
| 49 | + } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// Releases all resource used by the <see cref="LibGit2Sharp.AnnotatedCommit"/> object. |
| 53 | + /// </summary> |
| 54 | + public void Dispose() |
| 55 | + { |
| 56 | + Handle.Dispose(); |
| 57 | + } |
| 58 | + |
| 59 | + AnnotatedCommit IAnnotatedCommit.GetAnnotatedCommit() |
| 60 | + { |
| 61 | + return this; |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
0 commit comments