ref: 3a7df704f3a48015c898ea7cb694359f5b326515
parent: fabf75c8123756db8b2a6013375396e0b8847bac
author: Runxi Yu <me@runxiyu.org>
date: Sun Feb 22 16:51:36 EST 2026
object: Rename ident to signature
--- a/object/commit.go
+++ b/object/commit.go
@@ -9,8 +9,8 @@
type Commit struct {Tree objectid.ObjectID
Parents []objectid.ObjectID
- Author Ident
- Committer Ident
+ Author Signature
+ Committer Signature
Message []byte
ChangeID string
ExtraHeaders []ExtraHeader
--- a/object/commit_parse.go
+++ b/object/commit_parse.go
@@ -42,13 +42,13 @@
}
c.Parents = append(c.Parents, id)
case "author":
- idt, err := ParseIdent(value)
+ idt, err := ParseSignature(value)
if err != nil { return nil, fmt.Errorf("object: commit: author: %w", err)}
c.Author = *idt
case "committer":
- idt, err := ParseIdent(value)
+ idt, err := ParseSignature(value)
if err != nil { return nil, fmt.Errorf("object: commit: committer: %w", err)}
--- a/object/ident.go
+++ b/object/ident.go
@@ -11,8 +11,8 @@
"codeberg.org/lindenii/furgit/internal/intconv"
)
-// Ident represents a Git identity (author/committer/tagger).
-type Ident struct {+// Signature represents a Git signature (author/committer/tagger).
+type Signature struct {Name []byte
Email []byte
WhenUnix int64
@@ -19,16 +19,16 @@
OffsetMinutes int32
}
-// ParseIdent parses a canonical Git identity line:
+// ParseSignature parses a canonical Git signature line:
// "Name <email> 123456789 +0000".
-func ParseIdent(line []byte) (*Ident, error) {+func ParseSignature(line []byte) (*Signature, error) {lt := bytes.IndexByte(line, '<')
if lt < 0 {- return nil, errors.New("object: ident: missing opening <")+ return nil, errors.New("object: signature: missing opening <")}
gtRel := bytes.IndexByte(line[lt+1:], '>')
if gtRel < 0 {- return nil, errors.New("object: ident: missing closing >")+ return nil, errors.New("object: signature: missing closing >")}
gt := lt + 1 + gtRel
@@ -37,21 +37,21 @@
rest := line[gt+1:]
if len(rest) == 0 || rest[0] != ' ' {- return nil, errors.New("object: ident: missing timestamp separator")+ return nil, errors.New("object: signature: missing timestamp separator")}
rest = rest[1:]
before, after, ok := bytes.Cut(rest, []byte{' '}) if !ok {- return nil, errors.New("object: ident: missing timezone separator")+ return nil, errors.New("object: signature: missing timezone separator")}
when, err := strconv.ParseInt(string(before), 10, 64)
if err != nil {- return nil, fmt.Errorf("object: ident: invalid timestamp: %w", err)+ return nil, fmt.Errorf("object: signature: invalid timestamp: %w", err)}
tz := after
if len(tz) < 5 {- return nil, errors.New("object: ident: invalid timezone encoding")+ return nil, errors.New("object: signature: invalid timezone encoding")}
sign := 1
switch tz[0] {@@ -59,32 +59,32 @@
sign = -1
case '+':
default:
- return nil, errors.New("object: ident: invalid timezone sign")+ return nil, errors.New("object: signature: invalid timezone sign")}
hh, err := strconv.Atoi(string(tz[1:3]))
if err != nil {- return nil, fmt.Errorf("object: ident: invalid timezone hours: %w", err)+ return nil, fmt.Errorf("object: signature: invalid timezone hours: %w", err)}
mm, err := strconv.Atoi(string(tz[3:5]))
if err != nil {- return nil, fmt.Errorf("object: ident: invalid timezone minutes: %w", err)+ return nil, fmt.Errorf("object: signature: invalid timezone minutes: %w", err)}
if hh < 0 || hh > 23 {- return nil, errors.New("object: ident: invalid timezone hours range")+ return nil, errors.New("object: signature: invalid timezone hours range")}
if mm < 0 || mm > 59 {- return nil, errors.New("object: ident: invalid timezone minutes range")+ return nil, errors.New("object: signature: invalid timezone minutes range")}
total := int64(hh)*60 + int64(mm)
offset, err := intconv.Int64ToInt32(total)
if err != nil {- return nil, errors.New("object: ident: timezone overflow")+ return nil, errors.New("object: signature: timezone overflow")}
if sign < 0 {offset = -offset
}
- return &Ident{+ return &Signature{Name: nameBytes,
Email: emailBytes,
WhenUnix: when,
@@ -92,18 +92,18 @@
}, nil
}
-// Serialize renders the identity in canonical Git format.
-func (ident Ident) Serialize() ([]byte, error) {+// Serialize renders the signature in canonical Git format.
+func (signature Signature) Serialize() ([]byte, error) {var b strings.Builder
- b.Grow(len(ident.Name) + len(ident.Email) + 32)
- b.Write(ident.Name)
+ b.Grow(len(signature.Name) + len(signature.Email) + 32)
+ b.Write(signature.Name)
b.WriteString(" <")- b.Write(ident.Email)
+ b.Write(signature.Email)
b.WriteString("> ")- b.WriteString(strconv.FormatInt(ident.WhenUnix, 10))
+ b.WriteString(strconv.FormatInt(signature.WhenUnix, 10))
b.WriteByte(' ')- offset := ident.OffsetMinutes
+ offset := signature.OffsetMinutes
sign := '+'
if offset < 0 {sign = '-'
@@ -115,8 +115,8 @@
return []byte(b.String()), nil
}
-// When returns a time.Time with the identity's timezone offset.
-func (ident Ident) When() time.Time {- loc := time.FixedZone("git", int(ident.OffsetMinutes)*60)- return time.Unix(ident.WhenUnix, 0).In(loc)
+// When returns a time.Time with the signature's timezone offset.
+func (signature Signature) When() time.Time {+ loc := time.FixedZone("git", int(signature.OffsetMinutes)*60)+ return time.Unix(signature.WhenUnix, 0).In(loc)
}
--- a/object/tag.go
+++ b/object/tag.go
@@ -10,7 +10,7 @@
Target objectid.ObjectID
TargetType objecttype.Type
Name []byte
- Tagger *Ident
+ Tagger *Signature
Message []byte
}
--- a/object/tag_parse.go
+++ b/object/tag_parse.go
@@ -49,7 +49,7 @@
case "tag":
t.Name = append([]byte(nil), value...)
case "tagger":
- idt, err := ParseIdent(value)
+ idt, err := ParseSignature(value)
if err != nil { return nil, fmt.Errorf("object: tag: tagger: %w", err)}
--
⑨