-
Notifications
You must be signed in to change notification settings - Fork 1k
Note diffs b/w imported and solved lock #1475
Changes from 6 commits
c92b728
6d1ebdc
14f1ae8
fd6ef50
c2c59f1
ce07d2e
502b4a3
16c38f4
9075212
e910026
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,123 @@ func (cf ConstraintFeedback) LogFeedback(logger *log.Logger) { | |
} | ||
} | ||
|
||
type brokenImport interface { | ||
String() string | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This struct is only tracking versions and revisions for feedback, but that may not be sufficient. Not sure... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to warn when one of the following properties of a locked project changes:
|
||
|
||
type modifiedImport struct { | ||
source, branch, revision, version *gps.StringDiff | ||
projectPath string | ||
} | ||
|
||
func (mi modifiedImport) String() string { | ||
var pv string | ||
var pr string | ||
pp := mi.projectPath | ||
|
||
var cr string | ||
var cv string | ||
cp := "" | ||
|
||
if mi.revision != nil { | ||
pr = fmt.Sprintf("(%s)", trimSHA(mi.revision.Previous)) | ||
cr = fmt.Sprintf("(%s)", trimSHA(mi.revision.Current)) | ||
} | ||
|
||
if mi.version != nil { | ||
pv = mi.version.Previous | ||
cv = mi.version.Current | ||
} else if mi.branch != nil { | ||
pv = mi.branch.Previous | ||
cv = mi.branch.Current | ||
} | ||
|
||
if mi.source != nil { | ||
pp = fmt.Sprintf("%s(%s)", mi.projectPath, mi.source.Previous) | ||
cp = fmt.Sprintf(" for %s(%s)", mi.projectPath, mi.source.Current) | ||
} | ||
|
||
// Warning: Unable to preserve imported lock VERSION/BRANCH (REV) for PROJECT(SOURCE). Locking in VERSION/BRANCH (REV) for PROJECT(SOURCE) | ||
return fmt.Sprintf("%v %s for %s. Locking in %v %s%s", | ||
pv, | ||
pr, | ||
pp, | ||
cv, | ||
cr, | ||
cp, | ||
) | ||
} | ||
|
||
type removedImport struct { | ||
source, branch, revision, version *gps.StringDiff | ||
projectPath string | ||
} | ||
|
||
func (ri removedImport) String() string { | ||
var pr string | ||
var pv string | ||
pp := ri.projectPath | ||
|
||
if ri.revision != nil { | ||
pr = fmt.Sprintf("(%s)", trimSHA(ri.revision.Previous)) | ||
} | ||
|
||
if ri.version != nil { | ||
pv = ri.version.Previous | ||
} else if ri.branch != nil { | ||
pv = ri.branch.Previous | ||
} | ||
|
||
if ri.source != nil { | ||
pp = fmt.Sprintf("%s(%s)", ri.projectPath, ri.source.Previous) | ||
} | ||
|
||
// Warning: Unable to preserve imported lock VERSION/BRANCH (REV) for PROJECT(SOURCE). Locking in VERSION/BRANCH (REV) for PROJECT(SOURCE) | ||
return fmt.Sprintf("%v %s for %s. The project was removed from the lock because it is not used.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vars all on the same line, please - unless this is a practice from stdlib/the toolchain with which i'm unfamiliar. |
||
pv, | ||
pr, | ||
pp, | ||
) | ||
} | ||
|
||
// BrokenImportFeedback holds problematic lock feedback data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be a complete sentence, but also an informative one. Per the discussion in the other comment about "problematic", that term is both uninformative, and its connotation may or may not apply. |
||
type BrokenImportFeedback struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming again: i think that neither "broken" nor "import" are the right terms here. i believe something like |
||
brokenImports []brokenImport | ||
} | ||
|
||
// NewBrokenImportFeedback builds a feedback entry for problems with imports from a diff of the pre- and post- solved locks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: let's add a line break here, and a complete sentence (final period). Also, we can only categorically say that everything we might log here is a "problem" if we're imagining the sole use case for this feedback is on This doesn't require changing implementation, but rewriting these docs to focus on the functional relationship being handled by the type should happen in order to minimize future confusion about this type's purpose. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note - i could be convinced that this particular feedback mechanism is specific to the |
||
func NewBrokenImportFeedback(ld *gps.LockDiff) *BrokenImportFeedback { | ||
bi := &BrokenImportFeedback{} | ||
for _, lpd := range ld.Modify { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if we also needed to cover There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also want to warn when the final lock has removed a project. Maybe something like:
For example, I had a project in my glide.lock that was imported, but was then removed by dep. It may help me realize that I need to manually add a We could look for adds, but that is beyond the scope of broken locks, and doesn't belong in this PR. That is what the existing functionality is doing in the else block of FinalizeManifestAndLock. |
||
bi.brokenImports = append(bi.brokenImports, modifiedImport{ | ||
projectPath: string(lpd.Name), | ||
source: lpd.Source, | ||
branch: lpd.Branch, | ||
revision: lpd.Revision, | ||
version: lpd.Version, | ||
}) | ||
} | ||
|
||
for _, lpd := range ld.Remove { | ||
bi.brokenImports = append(bi.brokenImports, removedImport{ | ||
projectPath: string(lpd.Name), | ||
source: lpd.Source, | ||
branch: lpd.Branch, | ||
revision: lpd.Revision, | ||
version: lpd.Version, | ||
}) | ||
} | ||
|
||
return bi | ||
} | ||
|
||
// LogFeedback logs a warning for all changes between the initially imported and post- solve locks | ||
func (b BrokenImportFeedback) LogFeedback(logger *log.Logger) { | ||
for _, bi := range b.brokenImports { | ||
logger.Printf("Warning: Unable to preserve imported lock %v\n", bi) | ||
} | ||
} | ||
|
||
// GetUsingFeedback returns a dependency "using" feedback message. For example: | ||
// | ||
// Using ^1.0.0 as constraint for direct dep github.com/foo/bar | ||
|
@@ -99,13 +216,7 @@ func GetUsingFeedback(version, consType, depType, projectPath string) string { | |
// Locking in v1.1.4 (bc29b4f) for direct dep github.com/foo/bar | ||
// Locking in master (436f39d) for transitive dep github.com/baz/qux | ||
func GetLockingFeedback(version, revision, depType, projectPath string) string { | ||
// Check if it's a valid SHA1 digest and trim to 7 characters. | ||
if len(revision) == 40 { | ||
if _, err := hex.DecodeString(revision); err == nil { | ||
// Valid SHA1 digest | ||
revision = revision[0:7] | ||
} | ||
} | ||
revision = trimSHA(revision) | ||
|
||
if depType == DepTypeImported { | ||
if version == "" { | ||
|
@@ -115,3 +226,15 @@ func GetLockingFeedback(version, revision, depType, projectPath string) string { | |
} | ||
return fmt.Sprintf("Locking in %s (%s) for %s %s", version, revision, depType, projectPath) | ||
} | ||
|
||
// trimSHA checks if revision is a valid SHA1 digest and trims to 7 characters. | ||
func trimSHA(revision string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this convenience method, which we could leverage above at https://github.com/golang/dep/pull/1475/files#diff-ca9bf3aa3bbb62e361e500352f67474bR152 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if len(revision) == 40 { | ||
if _, err := hex.DecodeString(revision); err == nil { | ||
// Valid SHA1 digest | ||
revision = revision[0:7] | ||
} | ||
} | ||
|
||
return revision | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming: "Import" is not the noun here. "Dependency" is slightly murky in our terminology, but is probably the best noun to use. And, prefer "changed" to "broken," per other comments.