Skip to content

estimate: do not print children of mismatched major mods #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
47 changes: 29 additions & 18 deletions estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ func otherVersions(mod string) (mods []string) {
return
}

// findOtherVersion search in m for potential other versions of the given
// module and returns the number of the major version found, 0 if not.
func findOtherVersion(m map[string]string, mod string) int {
versions := otherVersions(mod)
for i, version := range versions {
if _, ok := m[version]; ok {
return len(versions) - i
}
}
return 0
}

func estimate(importpath, revision string) error {
removeTemp := func(path string) {
if err := forceRemoveAll(path); err != nil {
Expand Down Expand Up @@ -211,24 +223,26 @@ func estimate(importpath, revision string) error {
} else {
repoRoot = rr.Root
}
var debianVersion string
// Check for potential other major versions already in Debian.
for _, otherVersion := range otherVersions(mod) {
if _, ok := golangBinaries[otherVersion]; ok {
debianVersion = otherVersion
break
v := findOtherVersion(golangBinaries, mod)
if v != 0 {
// Log info to indicate that it is an approximate match
// but consider that it is packaged and skip the children.
if v == 1 {
log.Printf("%s has no version string in Debian", mod)
} else {
log.Printf("%s is v%d in Debian", mod, v)
}
return
}
if debianVersion == "" {
// When multiple modules are developped in the same repo,
// the repo root is often used as the import path metadata
// in Debian, so we do a last try with that.
if _, ok := golangBinaries[repoRoot]; ok {
// Log info to indicate that it is an approximate match
// but consider that it is packaged and skip the children.
log.Printf("%s is packaged as %s in Debian", mod, repoRoot)
return
}
// When multiple modules are developped in the same repo,
// the repo root is often used as the import path metadata
// in Debian, so we do a last try with that.
if _, ok := golangBinaries[repoRoot]; ok {
// Log info to indicate that it is an approximate match
// but consider that it is packaged and skip the children.
log.Printf("%s is packaged as %s in Debian", mod, repoRoot)
return
}
line := strings.Repeat(" ", indent)
if rrseen[repoRoot] {
Expand All @@ -239,9 +253,6 @@ func estimate(importpath, revision string) error {
} else {
line += mod
}
if debianVersion != "" {
line += fmt.Sprintf("\t(%s in Debian)", debianVersion)
}
lines = append(lines, line)
rrseen[repoRoot] = true
needed[mod] = 1
Expand Down