Skip to content

Commit 6c4bf8f

Browse files
oioojBryan C. Mills
authored andcommitted
cmd/go/internal/modfetch: remove legacy code
ReadFileRevs function is no longer used. Change-Id: Ibac6319dca4cf8010195e7c2fb502655494fb728 Reviewed-on: https://go-review.googlesource.com/c/go/+/367756 Run-TryBot: Baokun Lee <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Baokun Lee <[email protected]>
1 parent 08ecdf7 commit 6c4bf8f

3 files changed

Lines changed: 0 additions & 162 deletions

File tree

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,6 @@ type Repo interface {
5555
// os.IsNotExist(err) returns true.
5656
ReadFile(rev, file string, maxSize int64) (data []byte, err error)
5757

58-
// ReadFileRevs reads a single file at multiple versions.
59-
// It should refuse to read more than maxSize bytes.
60-
// The result is a map from each requested rev strings
61-
// to the associated FileRev. The map must have a non-nil
62-
// entry for every requested rev (unless ReadFileRevs returned an error).
63-
// A file simply being missing or even corrupted in revs[i]
64-
// should be reported only in files[revs[i]].Err, not in the error result
65-
// from ReadFileRevs.
66-
// The overall call should return an error (and no map) only
67-
// in the case of a problem with obtaining the data, such as
68-
// a network failure.
69-
// Implementations may assume that revs only contain tags,
70-
// not direct commit hashes.
71-
ReadFileRevs(revs []string, file string, maxSize int64) (files map[string]*FileRev, err error)
72-
7358
// ReadZip downloads a zip file for the subdir subdirectory
7459
// of the given revision to a new file in a given temporary directory.
7560
// It should refuse to read more than maxSize bytes.

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

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -523,140 +523,6 @@ func (r *gitRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) {
523523
return out, nil
524524
}
525525

526-
func (r *gitRepo) ReadFileRevs(revs []string, file string, maxSize int64) (map[string]*FileRev, error) {
527-
// Create space to hold results.
528-
files := make(map[string]*FileRev)
529-
for _, rev := range revs {
530-
f := &FileRev{Rev: rev}
531-
files[rev] = f
532-
}
533-
534-
// Collect locally-known revs.
535-
need, err := r.readFileRevs(revs, file, files)
536-
if err != nil {
537-
return nil, err
538-
}
539-
if len(need) == 0 {
540-
return files, nil
541-
}
542-
543-
// Build list of known remote refs that might help.
544-
var redo []string
545-
refs, err := r.loadRefs()
546-
if err != nil {
547-
return nil, err
548-
}
549-
for _, tag := range need {
550-
if refs["refs/tags/"+tag] != "" {
551-
redo = append(redo, tag)
552-
}
553-
}
554-
if len(redo) == 0 {
555-
return files, nil
556-
}
557-
558-
// Protect r.fetchLevel and the "fetch more and more" sequence.
559-
// See stat method above.
560-
unlock, err := r.mu.Lock()
561-
if err != nil {
562-
return nil, err
563-
}
564-
defer unlock()
565-
566-
if err := r.fetchRefsLocked(); err != nil {
567-
return nil, err
568-
}
569-
570-
if _, err := r.readFileRevs(redo, file, files); err != nil {
571-
return nil, err
572-
}
573-
574-
return files, nil
575-
}
576-
577-
func (r *gitRepo) readFileRevs(tags []string, file string, fileMap map[string]*FileRev) (missing []string, err error) {
578-
var stdin bytes.Buffer
579-
for _, tag := range tags {
580-
fmt.Fprintf(&stdin, "refs/tags/%s\n", tag)
581-
fmt.Fprintf(&stdin, "refs/tags/%s:%s\n", tag, file)
582-
}
583-
584-
data, err := RunWithStdin(r.dir, &stdin, "git", "cat-file", "--batch")
585-
if err != nil {
586-
return nil, err
587-
}
588-
589-
next := func() (typ string, body []byte, ok bool) {
590-
var line string
591-
i := bytes.IndexByte(data, '\n')
592-
if i < 0 {
593-
return "", nil, false
594-
}
595-
line, data = string(bytes.TrimSpace(data[:i])), data[i+1:]
596-
if strings.HasSuffix(line, " missing") {
597-
return "missing", nil, true
598-
}
599-
f := strings.Fields(line)
600-
if len(f) != 3 {
601-
return "", nil, false
602-
}
603-
n, err := strconv.Atoi(f[2])
604-
if err != nil || n > len(data) {
605-
return "", nil, false
606-
}
607-
body, data = data[:n], data[n:]
608-
if len(data) > 0 && data[0] == '\r' {
609-
data = data[1:]
610-
}
611-
if len(data) > 0 && data[0] == '\n' {
612-
data = data[1:]
613-
}
614-
return f[1], body, true
615-
}
616-
617-
badGit := func() ([]string, error) {
618-
return nil, fmt.Errorf("malformed output from git cat-file --batch")
619-
}
620-
621-
for _, tag := range tags {
622-
commitType, _, ok := next()
623-
if !ok {
624-
return badGit()
625-
}
626-
fileType, fileData, ok := next()
627-
if !ok {
628-
return badGit()
629-
}
630-
f := fileMap[tag]
631-
f.Data = nil
632-
f.Err = nil
633-
switch commitType {
634-
default:
635-
f.Err = fmt.Errorf("unexpected non-commit type %q for rev %s", commitType, tag)
636-
637-
case "missing":
638-
// Note: f.Err must not satisfy os.IsNotExist. That's reserved for the file not existing in a valid commit.
639-
f.Err = fmt.Errorf("no such rev %s", tag)
640-
missing = append(missing, tag)
641-
642-
case "tag", "commit":
643-
switch fileType {
644-
default:
645-
f.Err = &fs.PathError{Path: tag + ":" + file, Op: "read", Err: fmt.Errorf("unexpected non-blob type %q", fileType)}
646-
case "missing":
647-
f.Err = &fs.PathError{Path: tag + ":" + file, Op: "read", Err: fs.ErrNotExist}
648-
case "blob":
649-
f.Data = fileData
650-
}
651-
}
652-
}
653-
if len(bytes.TrimSpace(data)) != 0 {
654-
return badGit()
655-
}
656-
657-
return missing, nil
658-
}
659-
660526
func (r *gitRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag string, err error) {
661527
info, err := r.Stat(rev)
662528
if err != nil {

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,19 +382,6 @@ func (r *vcsRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) {
382382
return out, nil
383383
}
384384

385-
func (r *vcsRepo) ReadFileRevs(revs []string, file string, maxSize int64) (map[string]*FileRev, error) {
386-
// We don't technically need to lock here since we're returning an error
387-
// uncondititonally, but doing so anyway will help to avoid baking in
388-
// lock-inversion bugs.
389-
unlock, err := r.mu.Lock()
390-
if err != nil {
391-
return nil, err
392-
}
393-
defer unlock()
394-
395-
return nil, vcsErrorf("ReadFileRevs not implemented")
396-
}
397-
398385
func (r *vcsRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag string, err error) {
399386
// We don't technically need to lock here since we're returning an error
400387
// uncondititonally, but doing so anyway will help to avoid baking in

0 commit comments

Comments
 (0)