dep: Fix linting issues, update CHANGELOG

This commit is contained in:
sam boyer 2018-07-04 01:13:40 -04:00
Родитель 3c60abcd2f
Коммит 08a43497b3
8 изменённых файлов: 18 добавлений и 186 удалений

Просмотреть файл

@ -1,5 +1,7 @@
# (next version)
# v0.5.0
NEW FEATURES:
* Add CI tests against go1.10. Drop support for go1.8. ([#1620](https://github.com/golang/dep/pull/1620)).
@ -7,6 +9,8 @@ NEW FEATURES:
* List out of date projects in dep status ([#1553](https://github.com/golang/dep/pull/1553)).
* Enabled opt-in persistent caching via `DEPCACHEAGE` env var. ([#1711](https://github.com/golang/dep/pull/1711)).
* Allow `DEPPROJECTROOT` [environment variable](https://golang.github.io/dep/docs/env-vars.html#depprojectroot) to supersede GOPATH deduction and explicitly set the current project's [root](https://golang.github.io/dep/docs/glossary.html#project-root) ([#1883](https://github.com/golang/dep/pull/1883)).
* `dep ensure` now explains what changes to the code or Gopkg.toml have induced solving ([#1912](https://github.com/golang/dep/pull/1912)).
* Hash digests of vendor contents are now stored in `Gopkg.lock`, and the contents of vendor are only rewritten on change or hash mismatch ([#1912](https://github.com/golang/dep/pull/1912)).
BUG FIXES:
@ -17,6 +21,7 @@ IMPROVEMENTS:
* Add template operations support in dep status template output ([#1549](https://github.com/golang/dep/pull/1549)).
* Reduce network access by trusting local source information and only pulling from upstream when necessary ([#1250](https://github.com/golang/dep/pull/1250)).
* Update our dependency on Masterminds/semver to follow upstream again now that [Masterminds/semver#67](https://github.com/Masterminds/semver/pull/67) is merged([#1792](https://github.com/golang/dep/pull/1792)).
* `inputs-digest` was removed from `Gopkg.lock` ([#1912](https://github.com/golang/dep/pull/1912)).
WIP:
* Enable importing external configuration from dependencies during init (#1277). This is feature flagged and disabled by default.

Просмотреть файл

@ -161,13 +161,6 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
rootAnalyzer.FinalizeRootManifestAndLock(p.Manifest, p.Lock, copyLock)
// Run gps.Prepare with appropriate constraint solutions from solve run
// to generate the final lock memo.
s, err = gps.Prepare(params, sm)
if err != nil {
return errors.Wrap(err, "init failed: unable to recalculate the lock digest")
}
// Pass timestamp (yyyyMMddHHmmss format) as suffix to backup name.
vendorbak, err := dep.BackupVendor(filepath.Join(root, "vendor"), time.Now().Format("20060102150405"))
if err != nil {

Просмотреть файл

@ -362,27 +362,6 @@ func pcSliceToMap(l []ProjectConstraint, r ...[]ProjectConstraint) ProjectConstr
return final
}
func (m ProjectConstraints) asSortedSlice() []ProjectConstraint {
pcs := make([]ProjectConstraint, len(m))
k := 0
for pr, pp := range m {
pcs[k] = ProjectConstraint{
Ident: ProjectIdentifier{
ProjectRoot: pr,
Source: pp.Source,
},
Constraint: pp.Constraint,
}
k++
}
sort.SliceStable(pcs, func(i, j int) bool {
return pcs[i].Ident.Less(pcs[j].Ident)
})
return pcs
}
// overrideAll treats the receiver ProjectConstraints map as a set of override
// instructions, and applies overridden values to the ProjectConstraints.
//

Просмотреть файл

@ -59,6 +59,8 @@ type CascadingPruneOptions struct {
PerProjectOptions map[ProjectRoot]PruneOptionSet
}
// ParsePruneOptions extracts PruneOptions from a string using the standard
// encoding.
func ParsePruneOptions(input string) (PruneOptions, error) {
var po PruneOptions
for _, char := range input {

Просмотреть файл

@ -121,6 +121,7 @@ func (s *selection) getRequiredPackagesIn(id ProjectIdentifier) map[string]int {
// Suppress unused linting warning.
var _ = (*selection)(nil).getSelectedPackagesIn
var _ = (*selection)(nil).getProjectImportMap
// Compute a list of the unique packages within the given ProjectIdentifier that
// are currently selected, and the number of times each package has been

Просмотреть файл

@ -176,7 +176,7 @@ func (ls LockSatisfaction) UnmatchedOverrides() map[gps.ProjectRoot]ConstraintMi
return ls.badovr
}
// UnmatchedOverrides reports any normal, non-override constraint rules that
// UnmatchedConstraints reports any normal, non-override constraint rules that
// were not satisfied by the corresponding LockedProject in the Lock.
func (ls LockSatisfaction) UnmatchedConstraints() map[gps.ProjectRoot]ConstraintMismatch {
return ls.badconstraint
@ -186,7 +186,7 @@ func findEffectualConstraints(m gps.Manifest, imports map[string]bool) map[strin
eff := make(map[string]bool)
xt := radix.New()
for pr, _ := range m.DependencyConstraints() {
for pr := range m.DependencyConstraints() {
// FIXME(sdboyer) this has the trailing slash ambiguity problem; adapt
// code from the solver
xt.Insert(string(pr), nil)

Просмотреть файл

@ -15,7 +15,6 @@ import (
"github.com/golang/dep/gps"
"github.com/golang/dep/gps/verify"
"github.com/golang/dep/internal/feedback"
"github.com/golang/dep/internal/fs"
"github.com/pkg/errors"
)
@ -135,62 +134,6 @@ func (sw *SafeWriter) HasManifest() bool {
return sw.Manifest != nil
}
type rawStringDiff struct {
*feedback.StringDiff
}
// MarshalTOML serializes the diff as a string.
func (diff rawStringDiff) MarshalTOML() ([]byte, error) {
return []byte(diff.String()), nil
}
type rawLockedProjectDiff struct {
Name gps.ProjectRoot `toml:"name"`
Source *rawStringDiff `toml:"source,omitempty"`
Version *rawStringDiff `toml:"version,omitempty"`
Branch *rawStringDiff `toml:"branch,omitempty"`
Revision *rawStringDiff `toml:"revision,omitempty"`
Packages []rawStringDiff `toml:"packages,omitempty"`
}
func toRawLockedProjectDiff(diff feedback.LockedProjectDiff) rawLockedProjectDiff {
// this is a shallow copy since we aren't modifying the raw diff
raw := rawLockedProjectDiff{Name: diff.Name}
if diff.Source != nil {
raw.Source = &rawStringDiff{diff.Source}
}
if diff.Version != nil {
raw.Version = &rawStringDiff{diff.Version}
}
if diff.Branch != nil {
raw.Branch = &rawStringDiff{diff.Branch}
}
if diff.Revision != nil {
raw.Revision = &rawStringDiff{diff.Revision}
}
raw.Packages = make([]rawStringDiff, len(diff.Packages))
for i := 0; i < len(diff.Packages); i++ {
raw.Packages[i] = rawStringDiff{&diff.Packages[i]}
}
return raw
}
type rawLockedProjectDiffs struct {
Projects []rawLockedProjectDiff `toml:"projects"`
}
func toRawLockedProjectDiffs(diffs []feedback.LockedProjectDiff) rawLockedProjectDiffs {
raw := rawLockedProjectDiffs{
Projects: make([]rawLockedProjectDiff, len(diffs)),
}
for i := 0; i < len(diffs); i++ {
raw.Projects[i] = toRawLockedProjectDiff(diffs[i])
}
return raw
}
// VendorBehavior defines when the vendor directory should be written.
type VendorBehavior int
@ -452,6 +395,9 @@ func hasDotGit(path string) bool {
return err == nil
}
// DeltaWriter manages batched writes to populate vendor/ and update Gopkg.lock.
// Its primary design goal is to minimize writes by only writing things that
// have changed.
type DeltaWriter struct {
lock *Lock
lockDiff verify.LockDelta
@ -479,7 +425,7 @@ const (
// directory by writing out only those projects that actually need to be written
// out - they have changed in some way, or they lack the necessary hash
// information to be verified.
func NewDeltaWriter(oldLock, newLock *Lock, status map[string]verify.VendorStatus, prune gps.CascadingPruneOptions, vendorDir string, behavior VendorBehavior) (TransactionWriter, error) {
func NewDeltaWriter(oldLock, newLock *Lock, status map[string]verify.VendorStatus, prune gps.CascadingPruneOptions, vendorDir string, behavior VendorBehavior) (DepWriter, error) {
sw := &DeltaWriter{
lock: newLock,
pruneOptions: prune,
@ -722,12 +668,15 @@ func (dw *DeltaWriter) Write(path string, sm gps.SourceManager, examples bool, l
return nil
}
// PrintPreparedActions indicates what changes the DeltaWriter plans to make.
func (dw *DeltaWriter) PrintPreparedActions(output *log.Logger, verbose bool) error {
// FIXME
return nil
}
type TransactionWriter interface {
// A DepWriter is responsible for writing important dep states to disk -
// Gopkg.lock, vendor, and possibly Gopkg.toml.
type DepWriter interface {
PrintPreparedActions(output *log.Logger, verbose bool) error
Write(path string, sm gps.SourceManager, examples bool, logger *log.Logger) error
}

Просмотреть файл

@ -261,103 +261,6 @@ func TestSafeWriter_ManifestAndUnmodifiedLockWithForceVendor(t *testing.T) {
}
}
func testSafeWriter_ModifiedLock(t *testing.T) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)
h := test.NewHelper(t)
defer h.Cleanup()
pc := NewTestProjectContext(h, safeWriterProject)
defer pc.Release()
pc.CopyFile(LockName, safeWriterGoldenLock)
pc.Load()
originalLock := new(Lock)
*originalLock = *pc.Project.Lock
//originalLock.SolveMeta.InputsDigest = []byte{} // zero out the input hash to ensure non-equivalency
sw, _ := NewSafeWriter(nil, originalLock, pc.Project.Lock, VendorOnChanged, defaultCascadingPruneOptions())
// Verify prepared actions
if sw.HasManifest() {
t.Fatal("Did not expect the manifest to be written")
}
if !sw.HasLock() {
t.Fatal("Expected the payload to contain the lock")
}
if !sw.writeLock {
t.Fatal("Expected that the writer should plan to write the lock")
}
if !sw.writeVendor {
t.Fatal("Expected that the writer should plan to write the vendor directory")
}
// Write changes
err := sw.Write(pc.Project.AbsRoot, pc.SourceManager, true, nil)
h.Must(errors.Wrap(err, "SafeWriter.Write failed"))
// Verify file system changes
if err := pc.ManifestShouldNotExist(); err != nil {
t.Fatal(err)
}
if err := pc.LockShouldMatchGolden(safeWriterGoldenLock); err != nil {
t.Fatal(err)
}
if err := pc.VendorShouldExist(); err != nil {
t.Fatal(err)
}
if err := pc.VendorFileShouldExist("github.com/sdboyer/dep-test"); err != nil {
t.Fatal(err)
}
}
func testSafeWriter_ModifiedLockSkipVendor(t *testing.T) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)
h := test.NewHelper(t)
defer h.Cleanup()
pc := NewTestProjectContext(h, safeWriterProject)
defer pc.Release()
pc.CopyFile(LockName, safeWriterGoldenLock)
pc.Load()
originalLock := new(Lock)
*originalLock = *pc.Project.Lock
//originalLock.SolveMeta.InputsDigest = []byte{} // zero out the input hash to ensure non-equivalency
sw, _ := NewSafeWriter(nil, originalLock, pc.Project.Lock, VendorNever, defaultCascadingPruneOptions())
// Verify prepared actions
if sw.HasManifest() {
t.Fatal("Did not expect the payload to contain the manifest")
}
if !sw.HasLock() {
t.Fatal("Expected the payload to contain the lock")
}
if !sw.writeLock {
t.Fatal("Expected that the writer should plan to write the lock")
}
if sw.writeVendor {
t.Fatal("Did not expect the payload to contain the vendor directory")
}
// Write changes
err := sw.Write(pc.Project.AbsRoot, pc.SourceManager, true, nil)
h.Must(errors.Wrap(err, "SafeWriter.Write failed"))
// Verify file system changes
if err := pc.ManifestShouldNotExist(); err != nil {
t.Fatal(err)
}
if err := pc.LockShouldMatchGolden(safeWriterGoldenLock); err != nil {
t.Fatal(err)
}
if err := pc.VendorShouldNotExist(); err != nil {
t.Fatal(err)
}
}
func TestSafeWriter_ForceVendorWhenVendorAlreadyExists(t *testing.T) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)