Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit c3259a4

Browse files
committed
Merge branch 'feedback' into detect-branch-vs-tag
2 parents 0765851 + b9bebf4 commit c3259a4

File tree

5 files changed

+67
-67
lines changed

5 files changed

+67
-67
lines changed

cmd/dep/glide_importer.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ func (g *glideImporter) buildProjectConstraint(pkg glidePackage) (pc gps.Project
208208
pc.Ident = gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(pkg.Name), Source: pkg.Repository}
209209
pc.Constraint, err = deduceConstraint(pkg.Reference, pc.Ident, g.sm)
210210

211+
f := fb.NewConstraintFeedback(pc.Constraint, pc.Ident.ProjectRoot, fb.DepTypeImported)
212+
f.LogFeedback(g.logger)
211213
return
212214
}
213215

@@ -226,6 +228,8 @@ func (g *glideImporter) buildLockedProject(pkg glideLockedPackage) gps.LockedPro
226228
version = revision
227229
}
228230

229-
feedback(version, pi.ProjectRoot, fb.DepTypeImported, g.logger)
231+
f := fb.NewLockedProjectFeedback(version, pi.ProjectRoot, fb.DepTypeImported)
232+
f.LogFeedback(g.logger)
233+
230234
return gps.NewLockedProject(pi, version, nil)
231235
}

cmd/dep/gopath_scanner.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ func (g *gopathScanner) overlay(rootM *dep.Manifest, rootL *dep.Lock) {
9191
}
9292
rootM.Constraints[pkg] = prj
9393
v := g.pd.ondisk[pkg]
94-
feedback(v, pkg, fb.DepTypeDirect, g.ctx.Err)
94+
f := fb.NewConstraintFeedback(v, pkg, fb.DepTypeDirect)
95+
f.LogFeedback(g.ctx.Err)
96+
f = fb.NewLockedProjectFeedback(v, pkg, fb.DepTypeDirect)
97+
f.LogFeedback(g.ctx.Err)
9598
}
9699

97100
// Keep track of which projects have been locked
@@ -110,7 +113,8 @@ func (g *gopathScanner) overlay(rootM *dep.Manifest, rootL *dep.Lock) {
110113

111114
if _, isDirect := g.directDeps[string(pkg)]; !isDirect {
112115
v := g.pd.ondisk[pkg]
113-
feedback(v, pkg, fb.DepTypeTransitive, g.ctx.Err)
116+
f := fb.NewLockedProjectFeedback(v, pkg, fb.DepTypeTransitive)
117+
f.LogFeedback(g.ctx.Err)
114118
}
115119
}
116120

cmd/dep/root_analyzer.go

+2-48
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
package main
66

77
import (
8-
"encoding/hex"
8+
"io/ioutil"
9+
"log"
910

1011
"github.com/golang/dep"
11-
fb "github.com/golang/dep/internal/feedback"
1212
"github.com/golang/dep/internal/gps"
1313
"github.com/pkg/errors"
14-
"io/ioutil"
15-
"log"
1614
)
1715

1816
// importer handles importing configuration from other dependency managers into
@@ -148,50 +146,6 @@ func (a *rootAnalyzer) Info() (string, int) {
148146
return name, version
149147
}
150148

151-
// feedback logs project constraint as feedback to the user.
152-
func feedback(v gps.Version, pr gps.ProjectRoot, depType string, logger *log.Logger) {
153-
rev, version, branch := gps.VersionComponentStrings(v)
154-
155-
// Check if it's a valid SHA1 digest and trim to 7 characters.
156-
if len(rev) == 40 {
157-
if _, err := hex.DecodeString(rev); err == nil {
158-
// Valid SHA1 digest
159-
rev = rev[0:7]
160-
}
161-
}
162-
163-
// Get LockedVersion
164-
var ver string
165-
if version != "" {
166-
ver = version
167-
} else if branch != "" {
168-
ver = branch
169-
}
170-
171-
cf := &fb.ConstraintFeedback{
172-
LockedVersion: ver,
173-
Revision: rev,
174-
ProjectPath: string(pr),
175-
DependencyType: depType,
176-
}
177-
178-
// Get non-revision constraint if available
179-
if c := getProjectPropertiesFromVersion(v).Constraint; c != nil {
180-
cf.Version = c.String()
181-
}
182-
183-
// Attach ConstraintType for direct/imported deps based on locked version
184-
if cf.DependencyType == fb.DepTypeDirect || cf.DependencyType == fb.DepTypeImported {
185-
if cf.LockedVersion != "" {
186-
cf.ConstraintType = fb.ConsTypeConstraint
187-
} else {
188-
cf.ConstraintType = fb.ConsTypeHint
189-
}
190-
}
191-
192-
cf.LogFeedback(logger)
193-
}
194-
195149
func lookupVersionForRevision(rev gps.Revision, pi gps.ProjectIdentifier, sm gps.SourceManager) (gps.Version, error) {
196150
// Find the version that goes with this revision, if any
197151
versions, err := sm.ListVersions(pi)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Detected glide configuration files...
22
Converting from glide.yaml and glide.lock...
3-
Using ^0.8.1 as initial constraint for imported dep github.com/sdboyer/deptest
4-
Trying v0.8.1 (3f4c3be) as initial lock for imported dep github.com/sdboyer/deptest
3+
Using master as initial constraint for imported dep github.com/sdboyer/deptest
54
Using ^2.0.0 as initial constraint for imported dep github.com/sdboyer/deptestdos
5+
Using master as initial constraint for imported dep github.com/golang/lint
6+
Trying v0.8.1 (3f4c3be) as initial lock for imported dep github.com/sdboyer/deptest
67
Trying v2.0.0 (5c60720) as initial lock for imported dep github.com/sdboyer/deptestdos
7-
Using cb00e56 as initial hint for imported dep github.com/golang/lint

internal/feedback/feedback.go

+51-13
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
package feedback
66

77
import (
8+
"encoding/hex"
89
"fmt"
910
"log"
11+
12+
"github.com/golang/dep/internal/gps"
1013
)
1114

1215
// Constraint types
@@ -25,23 +28,50 @@ const DepTypeImported = "imported dep"
2528

2629
// ConstraintFeedback holds project constraint feedback data
2730
type ConstraintFeedback struct {
28-
Version, LockedVersion, Revision, ConstraintType, DependencyType, ProjectPath string
31+
Constraint, LockedVersion, Revision, ConstraintType, DependencyType, ProjectPath string
2932
}
3033

31-
// LogFeedback logs the feedback
34+
// NewConstraintFeedback builds a feedback entry for a constraint in the manifest.
35+
func NewConstraintFeedback(c gps.Constraint, pr gps.ProjectRoot, depType string) *ConstraintFeedback {
36+
cf := &ConstraintFeedback{
37+
Constraint: c.String(),
38+
ProjectPath: string(pr),
39+
DependencyType: depType,
40+
}
41+
42+
if _, ok := c.(gps.Revision); ok {
43+
cf.ConstraintType = ConsTypeHint
44+
} else {
45+
cf.ConstraintType = ConsTypeConstraint
46+
}
47+
48+
return cf
49+
}
50+
51+
// NewLockedProjectFeedback builds a feedback entry for a project in the lock.
52+
func NewLockedProjectFeedback(v gps.Version, pr gps.ProjectRoot, depType string) *ConstraintFeedback {
53+
cf := &ConstraintFeedback{
54+
ProjectPath: string(pr),
55+
DependencyType: depType,
56+
}
57+
58+
switch vt := v.(type) {
59+
case gps.PairedVersion:
60+
cf.LockedVersion = vt.String()
61+
cf.Revision = vt.Underlying().String()
62+
case gps.Revision:
63+
cf.Revision = vt.String()
64+
}
65+
66+
return cf
67+
}
68+
69+
// LogFeedback logs feedback on changes made to the manifest or lock.
3270
func (cf ConstraintFeedback) LogFeedback(logger *log.Logger) {
33-
// "Using" feedback for direct dep
34-
if cf.DependencyType == DepTypeDirect || cf.DependencyType == DepTypeImported {
35-
ver := cf.Version
36-
// revision as version for hint
37-
if cf.ConstraintType == ConsTypeHint {
38-
ver = cf.Revision
39-
}
40-
logger.Printf(" %v", GetUsingFeedback(ver, cf.ConstraintType, cf.DependencyType, cf.ProjectPath))
71+
if cf.Constraint != "" {
72+
logger.Printf(" %v", GetUsingFeedback(cf.Constraint, cf.ConstraintType, cf.DependencyType, cf.ProjectPath))
4173
}
42-
// No "Locking" feedback for hints. "Locking" feedback only for constraint
43-
// and transitive dep
44-
if cf.ConstraintType != ConsTypeHint {
74+
if cf.LockedVersion != "" && cf.Revision != "" {
4575
logger.Printf(" %v", GetLockingFeedback(cf.LockedVersion, cf.Revision, cf.DependencyType, cf.ProjectPath))
4676
}
4777
}
@@ -62,6 +92,14 @@ func GetUsingFeedback(version, consType, depType, projectPath string) string {
6292
// Locking in v1.1.4 (bc29b4f) for direct dep github.com/foo/bar
6393
// Locking in master (436f39d) for transitive dep github.com/baz/qux
6494
func GetLockingFeedback(version, revision, depType, projectPath string) string {
95+
// Check if it's a valid SHA1 digest and trim to 7 characters.
96+
if len(revision) == 40 {
97+
if _, err := hex.DecodeString(revision); err == nil {
98+
// Valid SHA1 digest
99+
revision = revision[0:7]
100+
}
101+
}
102+
65103
if depType == DepTypeImported {
66104
return fmt.Sprintf("Trying %s (%s) as initial lock for %s %s", version, revision, depType, projectPath)
67105
}

0 commit comments

Comments
 (0)