aboutsummaryrefslogtreecommitdiff
path: root/object
diff options
context:
space:
mode:
Diffstat (limited to 'object')
-rw-r--r--object/commit.go4
-rw-r--r--object/commit_parse.go4
-rw-r--r--object/ident.go56
-rw-r--r--object/tag.go2
-rw-r--r--object/tag_parse.go2
5 files changed, 34 insertions, 34 deletions
diff --git a/object/commit.go b/object/commit.go
index 8011a20d..bd48bb44 100644
--- a/object/commit.go
+++ b/object/commit.go
@@ -9,8 +9,8 @@ import (
type Commit struct {
Tree objectid.ObjectID
Parents []objectid.ObjectID
- Author Ident
- Committer Ident
+ Author Signature
+ Committer Signature
Message []byte
ChangeID string
ExtraHeaders []ExtraHeader
diff --git a/object/commit_parse.go b/object/commit_parse.go
index 2d207add..ae1b2559 100644
--- a/object/commit_parse.go
+++ b/object/commit_parse.go
@@ -42,13 +42,13 @@ func ParseCommit(body []byte, algo objectid.Algorithm) (*Commit, error) {
}
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)
}
diff --git a/object/ident.go b/object/ident.go
index 83503c89..1ea55cc2 100644
--- a/object/ident.go
+++ b/object/ident.go
@@ -11,24 +11,24 @@ import (
"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
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 @@ func ParseIdent(line []byte) (*Ident, error) {
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 @@ func ParseIdent(line []byte) (*Ident, error) {
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 @@ func ParseIdent(line []byte) (*Ident, error) {
}, 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 @@ func (ident Ident) Serialize() ([]byte, error) {
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)
}
diff --git a/object/tag.go b/object/tag.go
index 9a19b120..9a621ec9 100644
--- a/object/tag.go
+++ b/object/tag.go
@@ -10,7 +10,7 @@ type Tag struct {
Target objectid.ObjectID
TargetType objecttype.Type
Name []byte
- Tagger *Ident
+ Tagger *Signature
Message []byte
}
diff --git a/object/tag_parse.go b/object/tag_parse.go
index 990aefce..ea194085 100644
--- a/object/tag_parse.go
+++ b/object/tag_parse.go
@@ -49,7 +49,7 @@ func ParseTag(body []byte, algo objectid.Algorithm) (*Tag, error) {
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)
}