8
8
"github.com/emirpasic/gods/trees/binaryheap"
9
9
"gopkg.in/src-d/go-git.v4/plumbing"
10
10
"gopkg.in/src-d/go-git.v4/plumbing/object"
11
+ cgobject "gopkg.in/src-d/go-git.v4/plumbing/object/commitgraph"
11
12
)
12
13
13
14
// GetCommitsInfo gets information of all commits that are corresponding to these entries
@@ -19,7 +20,12 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom
19
20
entryPaths [i + 1 ] = entry .Name ()
20
21
}
21
22
22
- c , err := commit .repo .gogitRepo .CommitObject (plumbing .Hash (commit .ID ))
23
+ commitNodeIndex , commitGraphFile := commit .repo .CommitNodeIndex ()
24
+ if commitGraphFile != nil {
25
+ defer commitGraphFile .Close ()
26
+ }
27
+
28
+ c , err := commitNodeIndex .Get (plumbing .Hash (commit .ID ))
23
29
if err != nil {
24
30
return nil , nil , err
25
31
}
@@ -69,14 +75,14 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom
69
75
}
70
76
71
77
type commitAndPaths struct {
72
- commit * object. Commit
78
+ commit cgobject. CommitNode
73
79
// Paths that are still on the branch represented by commit
74
80
paths []string
75
81
// Set of hashes for the paths
76
82
hashes map [string ]plumbing.Hash
77
83
}
78
84
79
- func getCommitTree (c * object. Commit , treePath string ) (* object.Tree , error ) {
85
+ func getCommitTree (c cgobject. CommitNode , treePath string ) (* object.Tree , error ) {
80
86
tree , err := c .Tree ()
81
87
if err != nil {
82
88
return nil , err
@@ -93,7 +99,7 @@ func getCommitTree(c *object.Commit, treePath string) (*object.Tree, error) {
93
99
return tree , nil
94
100
}
95
101
96
- func getFileHashes (c * object. Commit , treePath string , paths []string ) (map [string ]plumbing.Hash , error ) {
102
+ func getFileHashes (c cgobject. CommitNode , treePath string , paths []string ) (map [string ]plumbing.Hash , error ) {
97
103
tree , err := getCommitTree (c , treePath )
98
104
if err == object .ErrDirectoryNotFound {
99
105
// The whole tree didn't exist, so return empty map
@@ -118,16 +124,16 @@ func getFileHashes(c *object.Commit, treePath string, paths []string) (map[strin
118
124
return hashes , nil
119
125
}
120
126
121
- func getLastCommitForPaths (c * object. Commit , treePath string , paths []string ) (map [string ]* object.Commit , error ) {
127
+ func getLastCommitForPaths (c cgobject. CommitNode , treePath string , paths []string ) (map [string ]* object.Commit , error ) {
122
128
// We do a tree traversal with nodes sorted by commit time
123
129
heap := binaryheap .NewWith (func (a , b interface {}) int {
124
- if a .(* commitAndPaths ).commit .Committer . When . Before (b .(* commitAndPaths ).commit .Committer . When ) {
130
+ if a .(* commitAndPaths ).commit .CommitTime (). Before (b .(* commitAndPaths ).commit .CommitTime () ) {
125
131
return 1
126
132
}
127
133
return - 1
128
134
})
129
135
130
- result := make (map [string ]* object. Commit )
136
+ resultNodes := make (map [string ]cgobject. CommitNode )
131
137
initialHashes , err := getFileHashes (c , treePath , paths )
132
138
if err != nil {
133
139
return nil , err
@@ -145,9 +151,9 @@ func getLastCommitForPaths(c *object.Commit, treePath string, paths []string) (m
145
151
146
152
// Load the parent commits for the one we are currently examining
147
153
numParents := current .commit .NumParents ()
148
- var parents []* object. Commit
154
+ var parents []cgobject. CommitNode
149
155
for i := 0 ; i < numParents ; i ++ {
150
- parent , err := current .commit .Parent (i )
156
+ parent , err := current .commit .ParentNode (i )
151
157
if err != nil {
152
158
break
153
159
}
@@ -174,7 +180,7 @@ func getLastCommitForPaths(c *object.Commit, treePath string, paths []string) (m
174
180
for i , path := range current .paths {
175
181
// The results could already contain some newer change for the same path,
176
182
// so don't override that and bail out on the file early.
177
- if result [path ] == nil {
183
+ if resultNodes [path ] == nil {
178
184
if pathUnchanged [i ] {
179
185
// The path existed with the same hash in at least one parent so it could
180
186
// not have been changed in this commit directly.
@@ -188,7 +194,7 @@ func getLastCommitForPaths(c *object.Commit, treePath string, paths []string) (m
188
194
// - We are looking at a merge commit and the hash of the file doesn't
189
195
// match any of the hashes being merged. This is more common for directories,
190
196
// but it can also happen if a file is changed through conflict resolution.
191
- result [path ] = current .commit
197
+ resultNodes [path ] = current .commit
192
198
}
193
199
}
194
200
}
@@ -222,5 +228,15 @@ func getLastCommitForPaths(c *object.Commit, treePath string, paths []string) (m
222
228
}
223
229
}
224
230
231
+ // Post-processing
232
+ result := make (map [string ]* object.Commit )
233
+ for path , commitNode := range resultNodes {
234
+ var err error
235
+ result [path ], err = commitNode .Commit ()
236
+ if err != nil {
237
+ return nil , err
238
+ }
239
+ }
240
+
225
241
return result , nil
226
242
}
0 commit comments