Example #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
}
Example #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
}
Example #3
0
func (c *StoreVersionsCmd) filters() []store.VersionFilter {
	var fs []store.VersionFilter
	if c.Repo != "" {
		fs = append(fs, store.ByRepos(c.Repo))
	}
	if c.CommitIDPrefix != "" {
		fs = append(fs, store.VersionFilterFunc(func(version *store.Version) bool {
			return strings.HasPrefix(version.CommitID, c.CommitIDPrefix)
		}))
	}
	if c.RepoCommitIDs != "" {
		fs = append(fs, makeRepoCommitIDsFilter(c.RepoCommitIDs))
	}
	return fs
}
Example #4
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
}