@@ -52,12 +52,20 @@ type Cache struct {
52
52
tracs map [plumbing.Hash ]* Trac
53
53
}
54
54
55
- func NewCache (rdir string , r * git.Repository ) * Cache {
55
+ func NewCache (rdir string , r * git.Repository , excludes [] string ) * Cache {
56
56
c := Cache {
57
57
repoDir : rdir ,
58
58
repo : r ,
59
59
tracs : make (map [plumbing.Hash ]* Trac ),
60
60
}
61
+ for _ , x := range excludes {
62
+ hash := plumbing .NewHash (x )
63
+ trac := & Trac {
64
+ name : "[excluded]" ,
65
+ hash : hash ,
66
+ }
67
+ c .add (trac )
68
+ }
61
69
return & c
62
70
}
63
71
@@ -143,7 +151,7 @@ func commitPath(path string, sub int) string {
143
151
}
144
152
145
153
func (c * Cache ) tryFetchFromSubmodules (path string , hash plumbing.Hash ) error {
146
- debugf ("Searching submodules for: %.10v % v\n " , hash , path )
154
+ debugf ("Searching submodules for: %v\n " , path )
147
155
wt , err := c .repo .Worktree ()
148
156
if err != nil {
149
157
return fmt .Errorf ("git worktree: %v" , err )
@@ -200,7 +208,7 @@ func (c *Cache) tryFetchFromSubmodules(path string, hash plumbing.Hash) error {
200
208
}
201
209
return nil
202
210
}
203
- return fmt .Errorf ("%v: %.10v not found." , path , hash )
211
+ return fmt .Errorf ("%v: %v not found." , path , hash )
204
212
}
205
213
206
214
func (c * Cache ) tracTree (path string , tree * object.Tree ) (* Trac , error ) {
@@ -210,6 +218,10 @@ func (c *Cache) tracTree(path string, tree *object.Tree) (*Trac, error) {
210
218
}
211
219
for _ , e := range tree .Entries {
212
220
if e .Mode == filemode .Submodule {
221
+ if c .tracs [e .Hash ] != nil {
222
+ // already handled
223
+ continue
224
+ }
213
225
subpath := fmt .Sprintf ("%s%s@%.10v" , path , e .Name , e .Hash )
214
226
sc , err := c .repo .CommitObject (e .Hash )
215
227
if err != nil {
@@ -269,6 +281,7 @@ func main() {
269
281
log .SetFlags (0 )
270
282
271
283
repodir := getopt .StringLong ("git-dir" , 'd' , "." , "path to git repo" )
284
+ excludes := getopt .ListLong ("exclude" , 'x' , "" , "commitids to exclude" )
272
285
getopt .Parse ()
273
286
274
287
r , err := git .PlainOpen (* repodir )
@@ -286,7 +299,7 @@ func main() {
286
299
if len (args ) != 2 {
287
300
usagef ("command cid takes exactly 1 argument" )
288
301
}
289
- c := NewCache (* repodir , r )
302
+ c := NewCache (* repodir , r , * excludes )
290
303
refname := args [1 ]
291
304
_ , err = c .tracByRef (refname )
292
305
if err != nil {
0 commit comments