7
7
package git
8
8
9
9
import (
10
- "bytes"
11
10
"fmt"
12
- "strconv"
13
- "strings"
14
11
"time"
12
+
13
+ "code.gitea.io/gitea/modules/util"
15
14
)
16
15
17
- // Signature represents the Author or Committer information.
16
+ // Signature represents the Author, Committer or Tagger information.
18
17
type Signature struct {
19
- // Name represents a person name. It is an arbitrary string.
20
- Name string
21
- // Email is an email, but it cannot be assumed to be well-formed.
22
- Email string
23
- // When is the timestamp of the signature.
24
- When time.Time
18
+ Name string // the committer name, it can be anything
19
+ Email string // the committer email, it can be anything
20
+ When time.Time // the timestamp of the signature
25
21
}
26
22
27
23
func (s * Signature ) String () string {
@@ -30,71 +26,5 @@ func (s *Signature) String() string {
30
26
31
27
// Decode decodes a byte array representing a signature to signature
32
28
func (s * Signature ) Decode (b []byte ) {
33
- sig , _ := newSignatureFromCommitline (b )
34
- s .Email = sig .Email
35
- s .Name = sig .Name
36
- s .When = sig .When
37
- }
38
-
39
- // Helper to get a signature from the commit line, which looks like these:
40
- //
41
- // author Patrick Gundlach <[email protected] > 1378823654 +0200
42
- // author Patrick Gundlach <[email protected] > Thu, 07 Apr 2005 22:13:13 +0200
43
- //
44
- // but without the "author " at the beginning (this method should)
45
- // be used for author and committer.
46
- // FIXME: there are a lot of "return sig, err" (but the err is also nil), that's the old behavior, to avoid breaking
47
- func newSignatureFromCommitline (line []byte ) (sig * Signature , err error ) {
48
- sig = new (Signature )
49
- emailStart := bytes .LastIndexByte (line , '<' )
50
- emailEnd := bytes .LastIndexByte (line , '>' )
51
- if emailStart == - 1 || emailEnd == - 1 || emailEnd < emailStart {
52
- return sig , err
53
- }
54
-
55
- if emailStart > 0 { // Empty name has already occurred, even if it shouldn't
56
- sig .Name = strings .TrimSpace (string (line [:emailStart - 1 ]))
57
- }
58
- sig .Email = string (line [emailStart + 1 : emailEnd ])
59
-
60
- hasTime := emailEnd + 2 < len (line )
61
- if ! hasTime {
62
- return sig , err
63
- }
64
-
65
- // Check date format.
66
- firstChar := line [emailEnd + 2 ]
67
- if firstChar >= 48 && firstChar <= 57 {
68
- idx := bytes .IndexByte (line [emailEnd + 2 :], ' ' )
69
- if idx < 0 {
70
- return sig , err
71
- }
72
-
73
- timestring := string (line [emailEnd + 2 : emailEnd + 2 + idx ])
74
- seconds , _ := strconv .ParseInt (timestring , 10 , 64 )
75
- sig .When = time .Unix (seconds , 0 )
76
-
77
- idx += emailEnd + 3
78
- if idx >= len (line ) || idx + 5 > len (line ) {
79
- return sig , err
80
- }
81
-
82
- timezone := string (line [idx : idx + 5 ])
83
- tzhours , err1 := strconv .ParseInt (timezone [0 :3 ], 10 , 64 )
84
- tzmins , err2 := strconv .ParseInt (timezone [3 :], 10 , 64 )
85
- if err1 != nil || err2 != nil {
86
- return sig , err
87
- }
88
- if tzhours < 0 {
89
- tzmins *= - 1
90
- }
91
- tz := time .FixedZone ("" , int (tzhours * 60 * 60 + tzmins * 60 ))
92
- sig .When = sig .When .In (tz )
93
- } else {
94
- sig .When , err = time .Parse (GitTimeLayout , string (line [emailEnd + 2 :]))
95
- if err != nil {
96
- return sig , err
97
- }
98
- }
99
- return sig , err
29
+ * s = * parseSignatureFromCommitLine (util .UnsafeBytesToString (b ))
100
30
}
0 commit comments