Exemple #1
0
func makeRepoCommitIDsFilter(repoCommitIDs string) interface {
	store.ByRepoCommitIDsFilter
	store.VersionFilter
	store.DefFilter
	store.UnitFilter
	store.RefFilter
} {
	if repoCommitIDs == "" {
		panic("empty repoCommitIDs")
	}
	rcs := strings.Split(repoCommitIDs, ",")
	vs := make([]store.Version, len(rcs))
	for i, rc := range rcs {
		rc = strings.TrimSpace(rc)
		repo, commitID := parseRepoAndCommitID(rc)
		if len(commitID) != 40 {
			log.Printf("WARNING: --repo-commits entry #%d (%q) has no commit ID or a non-absolute commit ID. Nothing will match it.", i, rc)
		}
		vs[i] = store.Version{Repo: repo, CommitID: commitID}
	}
	return store.ByRepoCommitIDs(vs...)
}
Exemple #2
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
}