5
5
package git
6
6
7
7
import (
8
- "path"
9
-
10
8
"gopkg.in/src-d/go-git.v4/plumbing"
11
9
"gopkg.in/src-d/go-git.v4/plumbing/object"
12
10
"gopkg.in/src-d/go-git.v4/plumbing/storer"
@@ -16,15 +14,15 @@ import (
16
14
func (tes Entries ) GetCommitsInfo (commit * Commit , treePath string , cache LastCommitCache ) ([][]interface {}, error ) {
17
15
entryPaths := make ([]string , len (tes ))
18
16
for i , entry := range tes {
19
- entryPaths [i ] = path . Join ( treePath , entry .Name () )
17
+ entryPaths [i ] = entry .Name ()
20
18
}
21
19
22
20
c , err := commit .repo .gogitRepo .CommitObject (plumbing .Hash (commit .ID ))
23
21
if err != nil {
24
22
return nil , err
25
23
}
26
24
27
- revs , err := getLastCommitForPaths (c , entryPaths )
25
+ revs , err := getLastCommitForPaths (c , treePath , entryPaths )
28
26
if err != nil {
29
27
return nil , err
30
28
}
@@ -45,7 +43,7 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom
45
43
return commitsInfo , nil
46
44
}
47
45
48
- func getLastCommitForPaths (c * object.Commit , paths []string ) ([]* object.Commit , error ) {
46
+ func getLastCommitForPaths (c * object.Commit , treePath string , paths []string ) ([]* object.Commit , error ) {
49
47
cIter := object .NewCommitIterCTime (c , nil , nil )
50
48
result := make ([]* object.Commit , len (paths ))
51
49
remainingResults := len (paths )
@@ -55,6 +53,14 @@ func getLastCommitForPaths(c *object.Commit, paths []string) ([]*object.Commit,
55
53
return nil , err
56
54
}
57
55
56
+ if treePath != "" {
57
+ cTree , err = cTree .Tree (treePath )
58
+ if err != nil {
59
+ return nil , err
60
+ }
61
+ }
62
+ lastTreeHash := cTree .Hash
63
+
58
64
currentEntryHashes := make ([]plumbing.Hash , len (paths ))
59
65
for i , path := range paths {
60
66
cEntry , err := cTree .FindEntry (path )
@@ -73,6 +79,21 @@ func getLastCommitForPaths(c *object.Commit, paths []string) ([]*object.Commit,
73
79
return err
74
80
}
75
81
82
+ if treePath != "" {
83
+ parentTree , err = parentTree .Tree (treePath )
84
+ // the whole tree doesn't exist
85
+ if err != nil {
86
+ return nil
87
+ }
88
+ }
89
+
90
+ // bail-out early if this tree branch was not changed in the commit
91
+ if lastTreeHash == parentTree .Hash {
92
+ copy (newEntryHashes , currentEntryHashes )
93
+ return nil
94
+ }
95
+ lastTreeHash = parentTree .Hash
96
+
76
97
for i , path := range paths {
77
98
// skip path if we already found it
78
99
if currentEntryHashes [i ] != plumbing .ZeroHash {
0 commit comments