Add support for parsing git trailers #614

Merged
lollipopman merged 5 commits from trailers into master 2020-06-02 12:30:42 -05:00
2 changed files with 84 additions and 0 deletions

42
message.go Normal file
View File

@ -0,0 +1,42 @@
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
package git
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
/*
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
#include <git2.h>
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
*/
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
import "C"
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
import (
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
"runtime"
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
"unsafe"
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
)
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
// Trailer represents a single git message trailer.
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
type Trailer struct {
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
Key string
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
Value string
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
}
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
// MessageTrailers parses trailers out of a message, returning a slice of
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
// Trailer structs. Trailers are key/value pairs in the last paragraph of a
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
// message, not including any patches or conflicts that may be present.
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
func MessageTrailers(message string) ([]Trailer, error) {
lhchavez commented 2020-06-01 20:37:41 -05:00 (Migrated from github.com)
Review

Can the docstrings from libgit2 be copied (+adapted) as the golang docstrings? For example, this could be

// MessageTrailers parses trailers out of a message. Trailers are key/value
// pairs in the last paragraph of a message, not including any patches or
// conflicts that may be present.

Same for Trailer above in L12 (from 849f371ea8/include/git2/message.h (L41))

Can the docstrings from [libgit2](https://libgit2.org/libgit2/#HEAD/group/message/git_message_trailers) be copied (+adapted) as the golang docstrings? For example, this could be ```go // MessageTrailers parses trailers out of a message. Trailers are key/value // pairs in the last paragraph of a message, not including any patches or // conflicts that may be present. ``` Same for `Trailer` above in L12 (from https://github.com/libgit2/libgit2/blob/849f371ea89257512ef505d0094d77b1ec812c53/include/git2/message.h#L41)
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
var trailersC C.git_message_trailer_array
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
messageC := C.CString(message)
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
defer C.free(unsafe.Pointer(messageC))
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
runtime.LockOSThread()
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
defer runtime.UnlockOSThread()
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
ecode := C.git_message_trailers(&trailersC, messageC)
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
if ecode < 0 {
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
return nil, MakeGitError(ecode)
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
}
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
defer C.git_message_trailer_array_free(&trailersC)
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
trailers := make([]Trailer, trailersC.count)
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
var trailer *C.git_message_trailer
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i+1, p+unsafe.Sizeof(C.git_message_trailer{}) {
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
trailer = (*C.git_message_trailer)(unsafe.Pointer(p))
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
trailers[i] = Trailer{Key: C.GoString(trailer.key), Value: C.GoString(trailer.value)}
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
}
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
return trailers, nil
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.
}
lhchavez commented 2020-06-01 20:39:38 -05:00 (Migrated from github.com)
Review

minor nit:

(if this was copied from another file, let me know which one and we'll fix that later).

minor nit: ```suggestion ``` (if this was copied from another file, let me know which one and we'll fix that later).
lhchavez commented 2020-06-01 20:45:12 -05:00 (Migrated from github.com)
Review

maybe

	for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) {

for a tiny bit more symmetry between the initialization and post-steps.

maybe ```suggestion for i, p := 0, uintptr(unsafe.Pointer(trailersC.trailers)); i < int(trailersC.count); i, p = i + 1, p + unsafe.Sizeof(C.git_message_trailer{}) { ``` for a tiny bit more symmetry between the initialization and post-steps.

42
message_test.go Normal file
View File

@ -0,0 +1,42 @@
package git
import (
"fmt"
"reflect"
"testing"
)
func TestTrailers(t *testing.T) {
t.Parallel()
tests := []struct {
input string
expected []Trailer
}{
{
"commit with zero trailers\n",
[]Trailer{},
},
{
"commit with one trailer\n\nCo-authored-by: Alice <alice@example.com>\n",
[]Trailer{
Trailer{Key: "Co-authored-by", Value: "Alice <alice@example.com>"},
},
},
{
"commit with two trailers\n\nCo-authored-by: Alice <alice@example.com>\nSigned-off-by: Bob <bob@example.com>\n",
[]Trailer{
Trailer{Key: "Co-authored-by", Value: "Alice <alice@example.com>"},
Trailer{Key: "Signed-off-by", Value: "Bob <bob@example.com>"}},
},
}
for _, test := range tests {
fmt.Printf("%s", test.input)
actual, err := MessageTrailers(test.input)
if err != nil {
t.Errorf("Trailers returned an unexpected error: %v", err)
}
if !reflect.DeepEqual(test.expected, actual) {
t.Errorf("expecting %#v\ngot %#v", test.expected, actual)
}
}
}