/// <summary> /// Add a new <see cref="ReflogEntry"/> to the current <see cref="ReflogCollection"/>. It will be created as first item of the collection /// The native reflog object will be saved right after inserting the entry. /// </summary> /// <param name="target">the <see cref="ObjectId"/> of the new target the <see cref="Reference"/> will point out to.</param> /// <param name="reflogMessage">the message associated with the new <see cref="ReflogEntry"/>.</param> /// <param name="committer"><see cref="Signature"/> of the comitter.</param> internal virtual void Append(ObjectId target, string reflogMessage, Signature committer) { using (ReferenceSafeHandle reference = Proxy.git_reference_lookup(repo.Handle, canonicalName, true)) using (ReflogSafeHandle reflog = Proxy.git_reflog_read(reference)) { string prettifiedMessage = Proxy.git_message_prettify(reflogMessage); Proxy.git_reflog_append(reflog, target, committer, prettifiedMessage); } }
/// <summary> /// Add a new <see cref="ReflogEntry"/> to the current <see cref="ReflogCollection"/>. It will be created as first item of the collection /// The native reflog object will be saved right after inserting the entry. /// </summary> /// <param name="target">the <see cref="ObjectId"/> of the new target the <see cref="Reference"/> will point out to.</param> /// <param name="reflogMessage">the message associated with the new <see cref="ReflogEntry"/>.</param> /// <param name="committer"><see cref="Signature"/> of the comitter.</param> internal virtual void Append(ObjectId target, string reflogMessage, Signature committer) { var logAllRefUpdates = repo.Config.GetValueOrDefault <bool>("core.logAllRefUpdates", false); if (!logAllRefUpdates) { return; } using (ReflogSafeHandle reflog = Proxy.git_reflog_read(repo.Handle, canonicalName)) { string prettifiedMessage = Proxy.git_message_prettify(reflogMessage); Proxy.git_reflog_append(reflog, target, committer, prettifiedMessage); } }
/// <summary> /// Returns an enumerator that iterates through the collection. /// <para> /// The enumerator returns the <see cref="ReflogEntry"/> by descending order (last reflog entry is returned first). /// </para> /// </summary> /// <returns>An <see cref="IEnumerator{T}"/> object that can be used to iterate through the collection.</returns> public IEnumerator <ReflogEntry> GetEnumerator() { var entries = new List <ReflogEntry>(); using (ReflogSafeHandle reflog = Proxy.git_reflog_read(repo.Handle, canonicalName)) { var entriesCount = Proxy.git_reflog_entrycount(reflog); for (int i = 0; i < entriesCount; i++) { ReflogEntrySafeHandle handle = Proxy.git_reflog_entry_byindex(reflog, i); entries.Add(new ReflogEntry(handle)); } } return(entries.GetEnumerator()); }