]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch: remove legacy code
authorBaokun Lee <bk@golangcn.org>
Wed, 1 Dec 2021 09:48:55 +0000 (17:48 +0800)
committerBryan C. Mills <bcmills@google.com>
Wed, 1 Dec 2021 18:48:35 +0000 (18:48 +0000)
ReadFileRevs function is no longer used.

Change-Id: Ibac6319dca4cf8010195e7c2fb502655494fb728
Reviewed-on: https://go-review.googlesource.com/c/go/+/367756
Run-TryBot: Baokun Lee <bk@golangcn.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Baokun Lee <bk@golangcn.org>

src/cmd/go/internal/modfetch/codehost/codehost.go
src/cmd/go/internal/modfetch/codehost/git.go
src/cmd/go/internal/modfetch/codehost/vcs.go

index 378fbae34f9530378ced67a8298f797891af9e72..5063f8616ab72a6a332f3936e6355554e72c05a4 100644 (file)
@@ -55,21 +55,6 @@ type Repo interface {
        // os.IsNotExist(err) returns true.
        ReadFile(rev, file string, maxSize int64) (data []byte, err error)
 
-       // ReadFileRevs reads a single file at multiple versions.
-       // It should refuse to read more than maxSize bytes.
-       // The result is a map from each requested rev strings
-       // to the associated FileRev. The map must have a non-nil
-       // entry for every requested rev (unless ReadFileRevs returned an error).
-       // A file simply being missing or even corrupted in revs[i]
-       // should be reported only in files[revs[i]].Err, not in the error result
-       // from ReadFileRevs.
-       // The overall call should return an error (and no map) only
-       // in the case of a problem with obtaining the data, such as
-       // a network failure.
-       // Implementations may assume that revs only contain tags,
-       // not direct commit hashes.
-       ReadFileRevs(revs []string, file string, maxSize int64) (files map[string]*FileRev, err error)
-
        // ReadZip downloads a zip file for the subdir subdirectory
        // of the given revision to a new file in a given temporary directory.
        // It should refuse to read more than maxSize bytes.
index a782de56ff95a9caa8a07d9076042e7dc2238b36..2a5255f115c944be67adf6dd5c756ab3c2d0dedb 100644 (file)
@@ -523,140 +523,6 @@ func (r *gitRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) {
        return out, nil
 }
 
-func (r *gitRepo) ReadFileRevs(revs []string, file string, maxSize int64) (map[string]*FileRev, error) {
-       // Create space to hold results.
-       files := make(map[string]*FileRev)
-       for _, rev := range revs {
-               f := &FileRev{Rev: rev}
-               files[rev] = f
-       }
-
-       // Collect locally-known revs.
-       need, err := r.readFileRevs(revs, file, files)
-       if err != nil {
-               return nil, err
-       }
-       if len(need) == 0 {
-               return files, nil
-       }
-
-       // Build list of known remote refs that might help.
-       var redo []string
-       refs, err := r.loadRefs()
-       if err != nil {
-               return nil, err
-       }
-       for _, tag := range need {
-               if refs["refs/tags/"+tag] != "" {
-                       redo = append(redo, tag)
-               }
-       }
-       if len(redo) == 0 {
-               return files, nil
-       }
-
-       // Protect r.fetchLevel and the "fetch more and more" sequence.
-       // See stat method above.
-       unlock, err := r.mu.Lock()
-       if err != nil {
-               return nil, err
-       }
-       defer unlock()
-
-       if err := r.fetchRefsLocked(); err != nil {
-               return nil, err
-       }
-
-       if _, err := r.readFileRevs(redo, file, files); err != nil {
-               return nil, err
-       }
-
-       return files, nil
-}
-
-func (r *gitRepo) readFileRevs(tags []string, file string, fileMap map[string]*FileRev) (missing []string, err error) {
-       var stdin bytes.Buffer
-       for _, tag := range tags {
-               fmt.Fprintf(&stdin, "refs/tags/%s\n", tag)
-               fmt.Fprintf(&stdin, "refs/tags/%s:%s\n", tag, file)
-       }
-
-       data, err := RunWithStdin(r.dir, &stdin, "git", "cat-file", "--batch")
-       if err != nil {
-               return nil, err
-       }
-
-       next := func() (typ string, body []byte, ok bool) {
-               var line string
-               i := bytes.IndexByte(data, '\n')
-               if i < 0 {
-                       return "", nil, false
-               }
-               line, data = string(bytes.TrimSpace(data[:i])), data[i+1:]
-               if strings.HasSuffix(line, " missing") {
-                       return "missing", nil, true
-               }
-               f := strings.Fields(line)
-               if len(f) != 3 {
-                       return "", nil, false
-               }
-               n, err := strconv.Atoi(f[2])
-               if err != nil || n > len(data) {
-                       return "", nil, false
-               }
-               body, data = data[:n], data[n:]
-               if len(data) > 0 && data[0] == '\r' {
-                       data = data[1:]
-               }
-               if len(data) > 0 && data[0] == '\n' {
-                       data = data[1:]
-               }
-               return f[1], body, true
-       }
-
-       badGit := func() ([]string, error) {
-               return nil, fmt.Errorf("malformed output from git cat-file --batch")
-       }
-
-       for _, tag := range tags {
-               commitType, _, ok := next()
-               if !ok {
-                       return badGit()
-               }
-               fileType, fileData, ok := next()
-               if !ok {
-                       return badGit()
-               }
-               f := fileMap[tag]
-               f.Data = nil
-               f.Err = nil
-               switch commitType {
-               default:
-                       f.Err = fmt.Errorf("unexpected non-commit type %q for rev %s", commitType, tag)
-
-               case "missing":
-                       // Note: f.Err must not satisfy os.IsNotExist. That's reserved for the file not existing in a valid commit.
-                       f.Err = fmt.Errorf("no such rev %s", tag)
-                       missing = append(missing, tag)
-
-               case "tag", "commit":
-                       switch fileType {
-                       default:
-                               f.Err = &fs.PathError{Path: tag + ":" + file, Op: "read", Err: fmt.Errorf("unexpected non-blob type %q", fileType)}
-                       case "missing":
-                               f.Err = &fs.PathError{Path: tag + ":" + file, Op: "read", Err: fs.ErrNotExist}
-                       case "blob":
-                               f.Data = fileData
-                       }
-               }
-       }
-       if len(bytes.TrimSpace(data)) != 0 {
-               return badGit()
-       }
-
-       return missing, nil
-}
-
 func (r *gitRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag string, err error) {
        info, err := r.Stat(rev)
        if err != nil {
index c2cca084e3077a8b3f9627e8b212491c1baf06dd..c8449ccdcc0f2a3004dffd62aa5a953caa5d4f1f 100644 (file)
@@ -382,19 +382,6 @@ func (r *vcsRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) {
        return out, nil
 }
 
-func (r *vcsRepo) ReadFileRevs(revs []string, file string, maxSize int64) (map[string]*FileRev, error) {
-       // We don't technically need to lock here since we're returning an error
-       // uncondititonally, but doing so anyway will help to avoid baking in
-       // lock-inversion bugs.
-       unlock, err := r.mu.Lock()
-       if err != nil {
-               return nil, err
-       }
-       defer unlock()
-
-       return nil, vcsErrorf("ReadFileRevs not implemented")
-}
-
 func (r *vcsRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag string, err error) {
        // We don't technically need to lock here since we're returning an error
        // uncondititonally, but doing so anyway will help to avoid baking in