From 4c3443328e40868bff53ef9ad16dff621f23a4e2 Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Mon, 16 Jan 2023 12:11:10 -0800 Subject: [PATCH] Adding new fields to RevInfo (#1812) * Allow unknown fields in RevInfo * Revert "Allow unknown fields in RevInfo" This reverts commit 902d791554edc19a77dfc6b7c2d9491b71d0ad43. * Adding new fields to rev_info.go * fixed tests --- pkg/download/protocol_test.go | 4 ++- pkg/storage/rev_info.go | 48 +++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/pkg/download/protocol_test.go b/pkg/download/protocol_test.go index 8395ab18..efc06a58 100644 --- a/pkg/download/protocol_test.go +++ b/pkg/download/protocol_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "github.com/stretchr/testify/assert" "io/ioutil" "path/filepath" "regexp" @@ -298,7 +299,8 @@ func TestInfo(t *testing.T) { err = dec.Decode(&info) require.NoError(t, err) - require.EqualValues(t, tc.info, &info) + assert.Equal(t, tc.info.Version, info.Version) + assert.Equal(t, tc.info.Time, info.Time) }) } } diff --git a/pkg/storage/rev_info.go b/pkg/storage/rev_info.go index f68a7bcd..8ed99af7 100644 --- a/pkg/storage/rev_info.go +++ b/pkg/storage/rev_info.go @@ -1,15 +1,47 @@ package storage -import ( - "time" -) +import "time" + +// From https://pkg.go.dev/cmd/go/internal/modfetch/codehost#Origin +type Origin struct { + VCS string `json:",omitempty"` // "git" etc + URL string `json:",omitempty"` // URL of repository + Subdir string `json:",omitempty"` // subdirectory in repo + + // If TagSum is non-empty, then the resolution of this module version + // depends on the set of tags present in the repo, specifically the tags + // of the form TagPrefix + a valid semver version. + // If the matching repo tags and their commit hashes still hash to TagSum, + // the Origin is still valid (at least as far as the tags are concerned). + // The exact checksum is up to the Repo implementation; see (*gitRepo).Tags. + TagPrefix string `json:",omitempty"` + TagSum string `json:",omitempty"` + + // If Ref is non-empty, then the resolution of this module version + // depends on Ref resolving to the revision identified by Hash. + // If Ref still resolves to Hash, the Origin is still valid (at least as far as Ref is concerned). + // For Git, the Ref is a full ref like "refs/heads/main" or "refs/tags/v1.2.3", + // and the Hash is the Git object hash the ref maps to. + // Other VCS might choose differently, but the idea is that Ref is the name + // with a mutable meaning while Hash is a name with an immutable meaning. + Ref string `json:",omitempty"` + Hash string `json:",omitempty"` + + // If RepoSum is non-empty, then the resolution of this module version + // failed due to the repo being available but the version not being present. + // This depends on the entire state of the repo, which RepoSum summarizes. + // For Git, this is a hash of all the refs and their hashes. + RepoSum string `json:",omitempty"` +} // RevInfo is json-encodable into the response body for // GET baseURL/module/@v/version.info -// -// This struct is taken directly from https://research.swtch.com/vgo-module -// (see "Download Protocol" header) +// From https://pkg.go.dev/cmd/go/internal/modfetch/codehost#RevInfo type RevInfo struct { - Version string `json:"Version"` // version string - Time time.Time `json:"Time"` // commit time + Origin *Origin + Name string // complete ID in underlying repository + Short string // shortened ID, for use in pseudo-version + Version string // version used in lookup + Time time.Time // commit time + Tags []string // known tags for commit }