@@ -15,7 +15,6 @@ import (
1515 gopilosa "github.com/pilosa/go-pilosa"
1616 "github.com/sirupsen/logrus"
1717 "github.com/uber/jaeger-client-go/config"
18- git "gopkg.in/src-d/go-git.v4"
1918 sqle "gopkg.in/src-d/go-mysql-server.v0"
2019 "gopkg.in/src-d/go-mysql-server.v0/server"
2120 "gopkg.in/src-d/go-mysql-server.v0/sql"
@@ -258,30 +257,8 @@ func (c *Server) addMatch(match string) error {
258257 }
259258
260259 if info .IsDir () {
261- ok , err := isGitRepo (path )
262- if err != nil {
263- logrus .WithFields (logrus.Fields {
264- "path" : path ,
265- "error" : err ,
266- }).Error ("path couldn't be inspected" )
267-
268- return filepath .SkipDir
269- }
270-
271- if ok {
272- if ! c .DisableGit {
273- if err := c .pool .AddGitWithID (info .Name (), path ); err != nil {
274- logrus .WithFields (logrus.Fields {
275- "id" : info .Name (),
276- "path" : path ,
277- "error" : err ,
278- }).Error ("repository could not be added" )
279- }
280-
281- logrus .WithField ("path" , path ).Debug ("repository added" )
282- }
283-
284- return filepath .SkipDir
260+ if err := c .addIfGitRepo (path ); err != nil {
261+ return err
285262 }
286263
287264 depth := strings .Count (path , string (os .PathSeparator )) - initDepth
@@ -293,7 +270,7 @@ func (c *Server) addMatch(match string) error {
293270 }
294271
295272 if ! c .DisableSiva &&
296- info .Mode ().IsRegular () && strings . HasSuffix (info .Name (), ".siva" ) {
273+ info .Mode ().IsRegular () && gitbase . IsSivaFile (info .Name ()) {
297274 if err := c .pool .AddSivaFile (path ); err != nil {
298275 logrus .WithFields (logrus.Fields {
299276 "path" : path ,
@@ -310,14 +287,34 @@ func (c *Server) addMatch(match string) error {
310287 })
311288}
312289
313- func isGitRepo (path string ) (bool , error ) {
314- if _ , err := git .PlainOpen (path ); err != nil {
315- if git .ErrRepositoryNotExists == err {
316- return false , nil
290+ func (c * Server ) addIfGitRepo (path string ) error {
291+ ok , err := gitbase .IsGitRepo (path )
292+ if err != nil {
293+ logrus .WithFields (logrus.Fields {
294+ "path" : path ,
295+ "error" : err ,
296+ }).Error ("path couldn't be inspected" )
297+
298+ return filepath .SkipDir
299+ }
300+
301+ if ok {
302+ if ! c .DisableGit {
303+ base := filepath .Base (path )
304+ if err := c .pool .AddGitWithID (base , path ); err != nil {
305+ logrus .WithFields (logrus.Fields {
306+ "id" : base ,
307+ "path" : path ,
308+ "error" : err ,
309+ }).Error ("repository could not be added" )
310+ }
311+
312+ logrus .WithField ("path" , path ).Debug ("repository added" )
317313 }
318314
319- return false , err
315+ // either the repository is added or not, the path must be skipped
316+ return filepath .SkipDir
320317 }
321318
322- return true , nil
319+ return nil
323320}
0 commit comments