1
1
package main
2
2
3
3
import (
4
+ "bufio"
4
5
"fmt"
5
6
"gopkg.in/src-d/go-git.v4"
6
7
"gopkg.in/src-d/go-git.v4/config"
@@ -51,7 +52,7 @@ type Cache struct {
51
52
52
53
func NewCache (rdir string , r * git.Repository , excludes []string ,
53
54
autoexclude bool ,
54
- debugf , infof func (fmt string , args ... interface {})) * Cache {
55
+ debugf , infof func (fmt string , args ... interface {})) ( * Cache , error ) {
55
56
c := Cache {
56
57
debugf : debugf ,
57
58
infof : infof ,
@@ -61,11 +62,40 @@ func NewCache(rdir string, r *git.Repository, excludes []string,
61
62
excludes : make (map [plumbing.Hash ]bool ),
62
63
tracs : make (map [plumbing.Hash ]* Trac ),
63
64
}
65
+
64
66
for _ , x := range excludes {
65
67
hash := plumbing .NewHash (x )
66
68
c .exclude (hash )
67
69
}
68
- return & c
70
+
71
+ wt , err := r .Worktree ()
72
+ if err != nil {
73
+ return nil , fmt .Errorf ("git worktree: %v" , err )
74
+ }
75
+ f , err := wt .Filesystem .Open (".trac-excludes" )
76
+ if err == nil { // file might not exist, but that's ok
77
+ r := bufio .NewReader (f )
78
+ for {
79
+ line , err := r .ReadString ('\n' )
80
+ if err != nil {
81
+ break
82
+ }
83
+ // trim comments
84
+ pos := strings .Index (line , "#" )
85
+ if pos >= 0 {
86
+ line = line [:pos ]
87
+ }
88
+ // trim whitespace
89
+ line = strings .TrimSpace (line )
90
+
91
+ if line != "" {
92
+ hash := plumbing .NewHash (line )
93
+ c .exclude (hash )
94
+ }
95
+ }
96
+ }
97
+
98
+ return & c , nil
69
99
}
70
100
71
101
func (c * Cache ) String () string {
@@ -89,7 +119,6 @@ func (c *Cache) String() string {
89
119
func (c * Cache ) exclude (hash plumbing.Hash ) {
90
120
if ! c .excludes [hash ] {
91
121
c .excludes [hash ] = true
92
- c .infof ("Excluding %v\n " , hash )
93
122
}
94
123
}
95
124
@@ -460,6 +489,7 @@ func (c *Cache) tracTree(path string, tree *object.Tree) (*Trac, error) {
460
489
err = c .tryFetchFromSubmodules (subpath , e .Hash )
461
490
if err != nil {
462
491
if c .autoexclude {
492
+ c .infof ("Excluding %v\n " , e .Hash )
463
493
c .exclude (e .Hash )
464
494
continue
465
495
}
0 commit comments