示例#1
0
func (c *StoreDefsCmd) filters() []store.DefFilter {
	var fs []store.DefFilter
	if c.UnitType != "" && c.Unit != "" {
		fs = append(fs, store.ByUnits(unit.ID2{Type: c.UnitType, Name: c.Unit}))
	}
	if (c.UnitType != "" && c.Unit == "") || (c.UnitType == "" && c.Unit != "") {
		log.Fatal("must specify either both or neither of --unit-type and --unit (to filter by source unit)")
	}
	if c.CommitID != "" {
		fs = append(fs, store.ByCommitIDs(c.CommitID))
	}
	if c.Repo != "" {
		fs = append(fs, store.ByRepos(c.Repo))
	}
	if c.RepoCommitIDs != "" {
		fs = append(fs, makeRepoCommitIDsFilter(c.RepoCommitIDs))
	}
	if c.Path != "" {
		fs = append(fs, store.ByDefPath(c.Path))
	}
	if c.File != "" {
		fs = append(fs, store.ByFiles(path.Clean(c.File)))
	}
	if c.Query != "" {
		fs = append(fs, store.ByDefQuery(c.Query))
	}
	if c.Filter != nil {
		fs = append(fs, c.Filter)
	}
	if c.Limit != 0 || c.Offset != 0 {
		fs = append(fs, store.Limit(c.Limit, c.Offset))
	}
	return fs
}
示例#2
0
func (c *StoreRefsCmd) filters() []store.RefFilter {
	var fs []store.RefFilter
	if c.UnitType != "" && c.Unit != "" {
		fs = append(fs, store.ByUnits(unit.ID2{Type: c.UnitType, Name: c.Unit}))
	}
	if (c.UnitType != "" && c.Unit == "") || (c.UnitType == "" && c.Unit != "") {
		log.Fatal("must specify either both or neither of --unit-type and --unit (to filter by source unit)")
	}
	if c.CommitID != "" {
		fs = append(fs, store.ByCommitIDs(c.CommitID))
	}
	if c.Repo != "" {
		fs = append(fs, store.ByRepos(c.Repo))
	}
	if c.RepoCommitIDs != "" {
		fs = append(fs, makeRepoCommitIDsFilter(c.RepoCommitIDs))
	}
	if c.File != "" {
		fs = append(fs, store.ByFiles(path.Clean(c.File)))
	}
	if c.Start != 0 {
		fs = append(fs, store.RefFilterFunc(func(ref *graph.Ref) bool {
			return ref.Start >= c.Start
		}))
	}
	if c.End != 0 {
		fs = append(fs, store.RefFilterFunc(func(ref *graph.Ref) bool {
			return ref.End <= c.End
		}))
	}
	if c.DefPath != "" {
		fs = append(fs, store.ByRefDef(graph.RefDefKey{
			DefRepo:     c.DefRepo,
			DefUnitType: c.DefUnitType,
			DefUnit:     c.DefUnit,
			DefPath:     c.DefPath,
		}))
	} else {
		// Slower filters since they don't use an index.
		if c.DefRepo != "" {
			fs = append(fs, store.AbsRefFilterFunc(store.RefFilterFunc(func(ref *graph.Ref) bool {
				return ref.DefRepo == c.DefRepo
			})))
		}
		if c.DefUnitType != "" {
			fs = append(fs, store.AbsRefFilterFunc(store.RefFilterFunc(func(ref *graph.Ref) bool {
				return ref.DefUnitType == c.DefUnitType
			})))
		}
		if c.DefUnit != "" {
			fs = append(fs, store.AbsRefFilterFunc(store.RefFilterFunc(func(ref *graph.Ref) bool {
				return ref.DefUnit == c.DefUnit
			})))
		}
	}
	if c.Limit != 0 || c.Offset != 0 {
		fs = append(fs, store.Limit(c.Limit, c.Offset))
	}
	return fs
}
示例#3
0
func (c *StoreUnitsCmd) filters() []store.UnitFilter {
	var fs []store.UnitFilter
	if c.Type != "" && c.Name != "" {
		fs = append(fs, store.ByUnits(unit.ID2{Type: c.Type, Name: c.Name}))
	}
	if (c.Type != "" && c.Name == "") || (c.Type == "" && c.Name != "") {
		log.Fatal("must specify either both or neither of --type and --name (to filter by source unit)")
	}
	if c.CommitID != "" {
		fs = append(fs, store.ByCommitIDs(c.CommitID))
	}
	if c.Repo != "" {
		fs = append(fs, store.ByRepos(c.Repo))
	}
	if c.RepoCommitIDs != "" {
		fs = append(fs, makeRepoCommitIDsFilter(c.RepoCommitIDs))
	}
	if c.File != "" {
		fs = append(fs, store.ByFiles(path.Clean(c.File)))
	}
	return fs
}
示例#4
0
func (o *DefListOptions) DefFilters() []store.DefFilter {
	var fs []store.DefFilter
	if o.DefKeys != nil {
		fs = append(fs, store.DefFilterFunc(func(def *graph.Def) bool {
			for _, dk := range o.DefKeys {
				if (def.Repo == "" || def.Repo == dk.Repo) && (def.CommitID == "" || def.CommitID == dk.CommitID) &&
					(def.UnitType == "" || def.UnitType == dk.UnitType) && (def.Unit == "" || def.Unit == dk.Unit) &&
					def.Path == dk.Path {
					return true
				}
			}
			return false
		}))
	}
	if o.Name != "" {
		fs = append(fs, store.DefFilterFunc(func(def *graph.Def) bool {
			return def.Name == o.Name
		}))
	}
	if o.ByteEnd != 0 {
		fs = append(fs, store.DefFilterFunc(func(d *graph.Def) bool {
			return d.DefStart == o.ByteStart && d.DefEnd == o.ByteEnd
		}))
	}
	if o.Query != "" {
		fs = append(fs, store.ByDefQuery(o.Query))
	}
	if len(o.RepoRevs) > 0 {
		vs := make([]store.Version, len(o.RepoRevs))
		for i, repoRev := range o.RepoRevs {
			repo, commitID := ParseRepoAndCommitID(repoRev)
			if len(commitID) != 40 {
				log.Printf("WARNING: In DefListOptions.DefFilters, o.RepoRevs[%d]==%q has no commit ID or a non-absolute commit ID. No defs will match it.", i, repoRev)
			}
			vs[i] = store.Version{Repo: repo, CommitID: commitID}
		}
		fs = append(fs, store.ByRepoCommitIDs(vs...))
	}
	if o.Unit != "" && o.UnitType != "" {
		fs = append(fs, store.ByUnits(unit.ID2{Type: o.UnitType, Name: o.Unit}))
	}
	if (o.UnitType != "" && o.Unit == "") || (o.UnitType == "" && o.Unit != "") {
		log.Println("WARNING: DefListOptions.DefFilter: must specify either both or neither of --type and --name (to filter by source unit)")
	}
	if o.File != "" {
		fs = append(fs, store.ByFiles(path.Clean(o.File)))
	}
	if o.FilePathPrefix != "" {
		fs = append(fs, store.ByFiles(path.Clean(o.FilePathPrefix)))
	}
	if len(o.Kinds) > 0 {
		fs = append(fs, store.DefFilterFunc(func(def *graph.Def) bool {
			for _, kind := range o.Kinds {
				if def.Kind == kind {
					return true
				}
			}
			return false
		}))
	}
	if o.Exported {
		fs = append(fs, store.DefFilterFunc(func(def *graph.Def) bool {
			return def.Exported
		}))
	}
	if o.Nonlocal {
		fs = append(fs, store.DefFilterFunc(func(def *graph.Def) bool {
			return !def.Local
		}))
	}
	if !o.IncludeTest {
		fs = append(fs, store.DefFilterFunc(func(def *graph.Def) bool {
			return !def.Test
		}))
	}
	switch o.Sort {
	case "key":
		fs = append(fs, store.DefsSortByKey{})
	case "name":
		fs = append(fs, store.DefsSortByName{})
	}
	return fs
}
示例#5
0
func (f DeltaFilter) DefFilters() []store.DefFilter {
	if f.UnitType != "" && f.Unit != "" {
		return []store.DefFilter{store.ByUnits(unit.ID2{Type: f.UnitType, Name: f.Unit})}
	}
	return nil
}