@@ -11,20 +11,20 @@ import (
11
11
)
12
12
13
13
// GetCommitsInfo gets information of all commits that are corresponding to these entries
14
- func (tes Entries ) GetCommitsInfo (commit * Commit , treePath string , cache LastCommitCache ) ([][]interface {}, error ) {
14
+ func (tes Entries ) GetCommitsInfo (commit * Commit , treePath string , cache LastCommitCache ) ([][]interface {}, * Commit , error ) {
15
15
entryPaths := make ([]string , len (tes ))
16
16
for i , entry := range tes {
17
17
entryPaths [i ] = entry .Name ()
18
18
}
19
19
20
20
c , err := commit .repo .gogitRepo .CommitObject (plumbing .Hash (commit .ID ))
21
21
if err != nil {
22
- return nil , err
22
+ return nil , nil , err
23
23
}
24
24
25
- revs , err := getLastCommitForPaths (c , treePath , entryPaths )
25
+ revs , treeCommit , err := getLastCommitForPaths (c , treePath , entryPaths )
26
26
if err != nil {
27
- return nil , err
27
+ return nil , nil , err
28
28
}
29
29
30
30
commit .repo .gogitStorage .Close ()
@@ -40,23 +40,45 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom
40
40
}
41
41
commitsInfo [i ] = []interface {}{entry , commit }
42
42
}
43
- return commitsInfo , nil
43
+ return commitsInfo , convertCommit ( treeCommit ), nil
44
44
}
45
45
46
- func getLastCommitForPaths (c * object.Commit , treePath string , paths []string ) ([]* object.Commit , error ) {
46
+ func convertCommit (c * object.Commit ) * Commit {
47
+ commiter := Signature (c .Committer )
48
+ author := Signature (c .Author )
49
+
50
+ var pgpSignaure * CommitGPGSignature
51
+ if c .PGPSignature != "" {
52
+ pgpSignaure = & CommitGPGSignature {
53
+ Signature : c .PGPSignature ,
54
+ Payload : c .Message , // FIXME: This is not correct
55
+ }
56
+ }
57
+
58
+ return & Commit {
59
+ ID : SHA1 (c .Hash ),
60
+ CommitMessage : c .Message ,
61
+ Committer : & commiter ,
62
+ Author : & author ,
63
+ Signature : pgpSignaure ,
64
+ }
65
+ }
66
+
67
+ func getLastCommitForPaths (c * object.Commit , treePath string , paths []string ) ([]* object.Commit , * object.Commit , error ) {
47
68
cIter := object .NewCommitIterCTime (c , nil , nil )
48
69
result := make ([]* object.Commit , len (paths ))
70
+ var resultTree * object.Commit
49
71
remainingResults := len (paths )
50
72
51
73
cTree , err := c .Tree ()
52
74
if err != nil {
53
- return nil , err
75
+ return nil , nil , err
54
76
}
55
77
56
78
if treePath != "" {
57
79
cTree , err = cTree .Tree (treePath )
58
80
if err != nil {
59
- return nil , err
81
+ return nil , nil , err
60
82
}
61
83
}
62
84
lastTreeHash := cTree .Hash
@@ -65,7 +87,7 @@ func getLastCommitForPaths(c *object.Commit, treePath string, paths []string) ([
65
87
for i , path := range paths {
66
88
cEntry , err := cTree .FindEntry (path )
67
89
if err != nil {
68
- return nil , err
90
+ return nil , nil , err
69
91
}
70
92
currentEntryHashes [i ] = cEntry .Hash
71
93
}
@@ -91,6 +113,9 @@ func getLastCommitForPaths(c *object.Commit, treePath string, paths []string) ([
91
113
if lastTreeHash == parentTree .Hash {
92
114
copy (newEntryHashes , currentEntryHashes )
93
115
return nil
116
+ } else if resultTree == nil {
117
+ // save the latest commit that updated treePath
118
+ resultTree = current
94
119
}
95
120
lastTreeHash = parentTree .Hash
96
121
@@ -136,5 +161,5 @@ func getLastCommitForPaths(c *object.Commit, treePath string, paths []string) ([
136
161
return nil
137
162
})
138
163
139
- return result , nil
164
+ return result , resultTree , nil
140
165
}
0 commit comments