Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cmd/gindex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"

"github.com/G-Node/libgin/libgin"
"github.com/gobwas/glob"
log "github.com/sirupsen/logrus"
)

Expand All @@ -25,6 +26,12 @@ type Configuration struct {
Timeout int64
// Elasticsearch server instance for querying index
Elasticsearch *ESServer

//glob pattern of files to exclude from indexing
ExcludePattern struct {
pattern string
glob glob.Glob
}
}

func loadconfig() *Configuration {
Expand Down Expand Up @@ -80,5 +87,17 @@ func loadconfig() *Configuration {

cfg.Elasticsearch = els

cfg.ExcludePattern.pattern = libgin.ReadConf("exclude_from_index")
if cfg.ExcludePattern.pattern != "" {
g, err := glob.Compile(cfg.ExcludePattern.pattern)
if err != nil {
log.Errorf("File indexing exclusion pattern could not be compiled : \"%s\"", cfg.ExcludePattern)
log.Warnf("All later use of exclusion pattern will be ignored!")
} else {
log.Infof("File indexing exclusion pattern: %v", cfg.ExcludePattern.pattern)
cfg.ExcludePattern.glob = g
}
}

return &cfg
}
12 changes: 9 additions & 3 deletions cmd/gindex/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ func indexCommit(cfg *Configuration, commit *gig.Commit, repoid string, commitid
}
if !hasBlob {
bpath, _ := GetBlobPath(blid.String(), commitid.String(), path)
err = NewBlobFromGig(blob, repoid, blid, commitid.String(), bpath, reponame).AddToIndexTimeout(cfg, blid)
if err != nil {
log.Debugf("Indexing blob failed: %v", err)
if cfg.ExcludePattern.glob != nil && bpath != "" && cfg.ExcludePattern.glob.Match(bpath) {
//do not index file that match exclusion pattern
log.Debugf("NOT indexing blob : %s", bpath)
} else {
log.Debugf("Indexing blob : %s ", bpath)
err = NewBlobFromGig(blob, repoid, blid, commitid.String(), bpath, reponame).AddToIndexTimeout(cfg, blid)
if err != nil {
log.Debugf("Indexing blob failed: %v", err)
}
}
} else {
log.Debugf("Blob there :%s", blid)
Expand Down
1 change: 1 addition & 0 deletions cmd/gindex/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func GetBlobPath(blid, cid, path string) (string, error) {
cmd := git.NewCommand("ls-tree", "-r", cid)
res, err := cmd.RunInDirBytes(path)
if err != nil {
log.Errorf("GetBlobPath: Could not find path for blob: %s\ngit ls-tree error: %+v", blid, err)
return "", err
}
pattern := fmt.Sprintf("%s\\s+(.+)", blid)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/go-macaron/cache v0.0.0-20151013081102-561735312776 // indirect
github.com/go-macaron/inject v0.0.0-20160627170012-d8a0b8677191 // indirect
github.com/go-macaron/session v0.0.0-20190131233854-0a0a789bf193 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogits/go-gogs-client v0.0.0-20190616193657-5a05380e4bc2
github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561 // indirect
github.com/gogs/go-libravatar v0.0.0-20161120025154-cd1abbd55d09 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/go-macaron/inject v0.0.0-20160627170012-d8a0b8677191 h1:NjHlg70DuOkcA
github.com/go-macaron/inject v0.0.0-20160627170012-d8a0b8677191/go.mod h1:VFI2o2q9kYsC4o7VP1HrEVosiZZTd+MVT3YZx4gqvJw=
github.com/go-macaron/session v0.0.0-20190131233854-0a0a789bf193 h1:z/nqwd+ql/r6Q3QGnwNd6B89UjPytM0be5pDQV9TuWw=
github.com/go-macaron/session v0.0.0-20190131233854-0a0a789bf193/go.mod h1:ScEJm9Gk+ez5JJTml5WlBIqavAfuE5nF8e4Gvyz/X+A=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gogits/go-gogs-client v0.0.0-20190616193657-5a05380e4bc2 h1:BbwX8wsMRDZRdNYxAna+4ls3wvMKJyn4PT6Zk1CPxP4=
github.com/gogits/go-gogs-client v0.0.0-20190616193657-5a05380e4bc2/go.mod h1:cY2AIrMgHm6oOHmR7jY+9TtjzSjQ3iG7tURJG3Y6XH0=
github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561 h1:aBzukfDxQlCTVS0NBUjI5YA3iVeaZ9Tb5PxNrrIP1xs=
Expand Down