aboutsummaryrefslogtreecommitdiff
path: root/object/signature/append.go
blob: 3db527529a80b828c7caa219c06cf63848d1b4d4 (about) (plain) (blame)
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
package signature

import (
	"fmt"
	"strconv"
	"slices"
)

// Bytes renders the signature in canonical Git format.
func (signature Signature) AppendTo(dst []byte) ([]byte) {
	slices.Grow(dst, len(signature.Name) + len(signature.Email) + 32)
	dst = append(dst, signature.Name...)
	dst = append(dst, ' ', '<')
	dst = append(dst, signature.Email...)
	dst = append(dst, '>', ' ')
	strconv.AppendInt(dst, signature.WhenUnix, 10)
	dst = append(dst, ' ')

	offset := signature.OffsetMinutes

	sign := '+'
	if offset < 0 {
		sign = '-'
		offset = -offset
	}

	hh := offset / 60
	mm := offset % 60
	dst = fmt.Appendf(dst, "%c%02d%02d", sign, hh, mm)

	return dst
}