diff options
| author | 2026-04-02 09:08:15 +0000 | |
|---|---|---|
| committer | 2026-04-02 09:08:15 +0000 | |
| commit | 92e95d907d2b88c10d7fd790806e1a1e9bedfda2 (patch) | |
| tree | c3d8005f25a45b3fdfb7be90a26c3011d0e3efe3 /object/signature/bytes.go | |
| parent | furgit: I forgot to add lifetime labels (diff) | |
| signature | No signature | |
object/signature: Rename Serialize to Bytes
Diffstat (limited to 'object/signature/bytes.go')
| -rw-r--r-- | object/signature/bytes.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/object/signature/bytes.go b/object/signature/bytes.go new file mode 100644 index 00000000..0afff5e0 --- /dev/null +++ b/object/signature/bytes.go @@ -0,0 +1,33 @@ +package signature + +import ( + "fmt" + "strconv" + "strings" +) + +// Bytes renders the signature in canonical Git format. +func (signature Signature) Bytes() ([]byte, error) { + var b strings.Builder + b.Grow(len(signature.Name) + len(signature.Email) + 32) + b.Write(signature.Name) + b.WriteString(" <") + b.Write(signature.Email) + b.WriteString("> ") + b.WriteString(strconv.FormatInt(signature.WhenUnix, 10)) + b.WriteByte(' ') + + offset := signature.OffsetMinutes + + sign := '+' + if offset < 0 { + sign = '-' + offset = -offset + } + + hh := offset / 60 + mm := offset % 60 + fmt.Fprintf(&b, "%c%02d%02d", sign, hh, mm) + + return []byte(b.String()), nil +} |
