From 69f43237eeec034dd582d00309b4a4eb8796208e Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Wed, 8 Jun 2022 16:41:02 -0700 Subject: [PATCH] Finally deprecate the legacy line-based format --- cmd/bashbrew/git.go | 11 ++--- manifest/example_test.go | 38 ---------------- manifest/line-based.go | 95 ---------------------------------------- manifest/parse.go | 25 ----------- manifest/rfc2822.go | 3 ++ 5 files changed, 6 insertions(+), 166 deletions(-) delete mode 100644 manifest/line-based.go delete mode 100644 manifest/parse.go diff --git a/cmd/bashbrew/git.go b/cmd/bashbrew/git.go index 195a24a..f22338a 100644 --- a/cmd/bashbrew/git.go +++ b/cmd/bashbrew/git.go @@ -209,13 +209,8 @@ func (r Repo) fetchGitRepo(arch string, entry *manifest.Manifest2822Entry) (stri } defer os.RemoveAll(tempRefDir) - tempRef := path.Join(refBase, filepath.Base(tempRefDir)) - if entry.ArchGitFetch(arch) == manifest.DefaultLineBasedFetch { - // backwards compat (see manifest/line-based.go in go-dockerlibrary) - fetchStrings[0] += tempRef + "/*" - } else { - fetchStrings[0] += tempRef + "/temp" - } + tempRef := path.Join(refBase, filepath.Base(tempRefDir)) + "/temp" + fetchStrings[0] += tempRef fetchStrings = append([]string{ // Git (and more recently, GitHub) support "git fetch"ing a specific commit directly! @@ -223,7 +218,7 @@ func (r Repo) fetchGitRepo(arch string, entry *manifest.Manifest2822Entry) (stri // https://github.com/git/git/commit/f8edeaa05d8623a9f6dad408237496c51101aad8 // https://github.com/go-git/go-git/pull/58 // If that works, we want to prefer it (since it'll be much more efficient at getting us the commit we care about), so we prepend it to our list of "things to try fetching" - entryArchGitCommit + ":" + tempRef + "/temp", + entryArchGitCommit + ":" + tempRef, }, fetchStrings...) } diff --git a/manifest/example_test.go b/manifest/example_test.go index d4c8271..bcd402a 100644 --- a/manifest/example_test.go +++ b/manifest/example_test.go @@ -83,23 +83,6 @@ s390x-File: Dockerfile } fmt.Printf("\n") - man, err = manifest.Parse(bufio.NewReader(strings.NewReader(` -# maintainer: InfoSiftr (@infosiftr) -# maintainer: John Smith (@example-jsmith) - -# first set -a: b@c d -e: b@c d - - # second set -f: g@h -i: g@h j -`))) - if err != nil { - panic(err) - } - fmt.Printf("-------------\nline-based:\n%v\n", man) - // Output: // ------------- // 2822: @@ -145,27 +128,6 @@ i: g@h j // // - raspbian // - raspbian-s390x - // - // ------------- - // line-based: - // Maintainers: InfoSiftr (@infosiftr), John Smith (@example-jsmith) - // GitFetch: refs/heads/* - // - // Tags: a, e - // GitRepo: b - // GitCommit: c - // Directory: d - // - // Tags: f - // GitRepo: g - // GitFetch: refs/tags/h - // GitCommit: FETCH_HEAD - // - // Tags: i - // GitRepo: g - // GitFetch: refs/tags/h - // GitCommit: FETCH_HEAD - // Directory: j } func ExampleFetch_local() { diff --git a/manifest/line-based.go b/manifest/line-based.go deleted file mode 100644 index ea0c327..0000000 --- a/manifest/line-based.go +++ /dev/null @@ -1,95 +0,0 @@ -package manifest - -import ( - "bufio" - "fmt" - "io" - "strings" -) - -const DefaultLineBasedFetch = "refs/heads/*" // backwards compatibility - -// 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) { - entry := defaults.Clone() - - parts := strings.SplitN(line, ":", 2) - if len(parts) < 2 { - return nil, fmt.Errorf("manifest line missing ':': %s", line) - } - entry.Tags = []string{strings.TrimSpace(parts[0])} - - parts = strings.SplitN(parts[1], "@", 2) - if len(parts) < 2 { - return nil, fmt.Errorf("manifest line missing '@': %s", line) - } - entry.GitRepo = strings.TrimSpace(parts[0]) - - parts = strings.SplitN(parts[1], " ", 2) - entry.GitCommit = strings.TrimSpace(parts[0]) - if len(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 -} - -func ParseLineBased(readerIn io.Reader) (*Manifest2822, error) { - reader := bufio.NewReader(readerIn) - - manifest := &Manifest2822{ - Global: DefaultManifestEntry.Clone(), - } - manifest.Global.GitFetch = DefaultLineBasedFetch - - for { - line, err := reader.ReadString('\n') - - line = strings.TrimSpace(line) - if len(line) > 0 { - if line[0] == '#' { - maintainerLine := strings.TrimPrefix(line, "# maintainer: ") - if line != maintainerLine { - // if the prefix was removed, it must be a maintainer line! - maintainer := Manifest2822Maintainer{} - if err := maintainer.UnmarshalControl(maintainerLine); err != nil { - return nil, err - } - manifest.Global.Maintainers = append(manifest.Global.Maintainers, maintainer) - } - } else { - entry, parseErr := ParseLineBasedLine(line, manifest.Global) - if parseErr != nil { - return nil, parseErr - } - - err = manifest.AddEntry(*entry) - if err != nil { - return nil, err - } - } - } - - if err == io.EOF { - break - } - if err != nil { - return nil, err - } - } - - if len(manifest.Global.Maintainers) < 1 { - return nil, fmt.Errorf("missing Maintainers") - } - if invalidMaintainers := manifest.Global.InvalidMaintainers(); len(invalidMaintainers) > 0 { - return nil, fmt.Errorf("invalid Maintainers: %q (expected format %q)", strings.Join(invalidMaintainers, ", "), MaintainersFormat) - } - - return manifest, nil -} diff --git a/manifest/parse.go b/manifest/parse.go deleted file mode 100644 index c9a9410..0000000 --- a/manifest/parse.go +++ /dev/null @@ -1,25 +0,0 @@ -package manifest - -import ( - "bytes" - "io" -) - -// try parsing as a 2822 manifest, but fallback to line-based if that fails -func Parse(reader io.Reader) (*Manifest2822, error) { - buf := &bytes.Buffer{} - - // try parsing as 2822, but also copy back into a new buffer so that if it fails, we can re-parse as line-based - manifest, err2822 := Parse2822(io.TeeReader(reader, buf)) - if err2822 != nil { - manifest, err := ParseLineBased(buf) - if err != nil { - // if we fail parsing line-based, eat the error and return the 2822 parsing error instead - // https://github.com/docker-library/bashbrew/issues/16 - return nil, err2822 - } - return manifest, nil - } - - return manifest, nil -} diff --git a/manifest/rfc2822.go b/manifest/rfc2822.go index ad5c064..2e962b6 100644 --- a/manifest/rfc2822.go +++ b/manifest/rfc2822.go @@ -581,6 +581,9 @@ func (decoder *decoderWrapper) Decode(entry *Manifest2822Entry) error { } } +// https://github.com/docker-library/bashbrew/issues/16 +var Parse = Parse2822 + func Parse2822(readerIn io.Reader) (*Manifest2822, error) { reader := stripper.NewCommentStripper(readerIn)