Add more validation and better line-based "git tag" handling
This commit is contained in:
parent
e74aa41b37
commit
a0797a5c0b
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const DefaultLineBasedFetch = "refs/heads/*" // backwards compatibility
|
||||||
|
|
||||||
// TODO write more of a proper parser? (probably not worthwhile given that 2822 is the preferred format)
|
// TODO write more of a proper parser? (probably not worthwhile given that 2822 is the preferred format)
|
||||||
func ParseLineBasedLine(line string, defaults Manifest2822Entry) (*Manifest2822Entry, error) {
|
func ParseLineBasedLine(line string, defaults Manifest2822Entry) (*Manifest2822Entry, error) {
|
||||||
entry := defaults.Clone()
|
entry := defaults.Clone()
|
||||||
|
|
@ -29,6 +31,12 @@ func ParseLineBasedLine(line string, defaults Manifest2822Entry) (*Manifest2822E
|
||||||
entry.Directory = strings.TrimSpace(parts[1])
|
entry.Directory = strings.TrimSpace(parts[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if entry.GitFetch == DefaultLineBasedFetch && !GitCommitRegex.MatchString(entry.GitCommit) {
|
||||||
|
// doesn't look like a commit, must be a tag
|
||||||
|
entry.GitFetch = "refs/tags/" + entry.GitCommit
|
||||||
|
entry.GitCommit = "FETCH_HEAD"
|
||||||
|
}
|
||||||
|
|
||||||
return &entry, nil
|
return &entry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,7 +47,7 @@ func ParseLineBased(readerIn io.Reader) (*Manifest2822, error) {
|
||||||
Global: DefaultManifestEntry.Clone(),
|
Global: DefaultManifestEntry.Clone(),
|
||||||
}
|
}
|
||||||
manifest.Global.Maintainers = []string{`TODO parse old-style "maintainer:" comment lines?`}
|
manifest.Global.Maintainers = []string{`TODO parse old-style "maintainer:" comment lines?`}
|
||||||
manifest.Global.GitFetch = "refs/heads/*" // backwards compatibility
|
manifest.Global.GitFetch = DefaultLineBasedFetch
|
||||||
|
|
||||||
for {
|
for {
|
||||||
line, err := reader.ReadString('\n')
|
line, err := reader.ReadString('\n')
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ import (
|
||||||
"pault.ag/go/debian/control"
|
"pault.ag/go/debian/control"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
GitCommitRegex = regexp.MustCompile(`^[0-9a-f]{1,40}$`)
|
||||||
|
GitFetchRegex = regexp.MustCompile(`^refs/(heads|tags)/[^*?:]+$`)
|
||||||
|
)
|
||||||
|
|
||||||
type Manifest2822 struct {
|
type Manifest2822 struct {
|
||||||
Global Manifest2822Entry
|
Global Manifest2822Entry
|
||||||
Entries []Manifest2822Entry
|
Entries []Manifest2822Entry
|
||||||
|
|
@ -247,6 +252,12 @@ func Parse2822(readerIn io.Reader) (*Manifest2822, error) {
|
||||||
if entry.GitRepo == "" || entry.GitFetch == "" || entry.GitCommit == "" {
|
if entry.GitRepo == "" || entry.GitFetch == "" || entry.GitCommit == "" {
|
||||||
return nil, fmt.Errorf("Tags %q missing one of GitRepo, GitFetch, or GitCommit", entry.TagsString())
|
return nil, fmt.Errorf("Tags %q missing one of GitRepo, GitFetch, or GitCommit", entry.TagsString())
|
||||||
}
|
}
|
||||||
|
if !GitFetchRegex.MatchString(entry.GitFetch) {
|
||||||
|
return nil, fmt.Errorf(`Tags %q has invalid GitFetch (must be "refs/heads/..." or "refs/tags/..."): %q`, entry.TagsString(), entry.GitFetch)
|
||||||
|
}
|
||||||
|
if !GitCommitRegex.MatchString(entry.GitCommit) {
|
||||||
|
return nil, fmt.Errorf(`Tags %q has invalid GitCommit (must be a commit, not a tag or ref): %q`, entry.TagsString(), entry.GitCommit)
|
||||||
|
}
|
||||||
|
|
||||||
err = manifest.AddEntry(entry)
|
err = manifest.AddEntry(entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue