-
Notifications
You must be signed in to change notification settings - Fork 1k
internal/gps: Parse abbreviated git revisions #1027
Changes from 1 commit
531fb9c
dfb8719
e0f7e1f
6977b26
2d4b3c2
960d21a
7f19f8b
49bf340
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 | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -578,6 +578,18 @@ func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint | |||||||||||||||||||||||||||
return version.Unpair(), nil | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// Abbreviated git revision? If the string is present, there's a good shot of | ||||||||||||||||||||||||||||
// this. | ||||||||||||||||||||||||||||
if present, _ := sm.RevisionPresentIn(pi, Revision(s)); present { | ||||||||||||||||||||||||||||
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. At the top of this function are a bunch of string checks to validate the revision. I was hoping that we could replace those heuristics with this new logic to lookup the revision from the repo. 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. Yep, I think we can definitely yoink those out, will do. |
||||||||||||||||||||||||||||
srcg, err := sm.srcCoord.getSourceGatewayFor(context.TODO(), pi) | ||||||||||||||||||||||||||||
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. Instead of dipping into the source gateway, this should probably be another function on the source manager, just like dep/internal/gps/source_manager.go Lines 436 to 448 in ee6fcfc
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. My concern here was just in adding another public method to the SourceManager interface, which is already very large. What would you think of a private method on the *sourceManager here to encapsulate this behavior?
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. Yes, good catch. A private method for InferConstraint to call would be better. |
||||||||||||||||||||||||||||
if err == nil { | ||||||||||||||||||||||||||||
ci, err := srcg.commitInfo(context.TODO(), Revision(s)) | ||||||||||||||||||||||||||||
if err == nil { | ||||||||||||||||||||||||||||
return Revision(ci.Commit), nil | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
return nil, errors.Errorf("%s is not a valid version for the package %s(%s)", s, pi.ProjectRoot, pi.Source) | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"time" | ||
|
||
"github.com/Masterminds/semver" | ||
"github.com/Masterminds/vcs" | ||
"github.com/golang/dep/internal/fs" | ||
"github.com/golang/dep/internal/gps/pkgtree" | ||
) | ||
|
@@ -40,6 +41,10 @@ func (bs *baseVCSSource) upstreamURL() string { | |
return bs.repo.Remote() | ||
} | ||
|
||
func (bs *baseVCSSource) commitInfo(ctx context.Context, r Revision) (*vcs.CommitInfo, error) { | ||
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. Is it appropriate to return this type? We could return Another option is to make this a more targeted method, like 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. Yeah I was thinking that we'd return just a |
||
return bs.repo.CommitInfo(string(r)) | ||
} | ||
|
||
func (bs *baseVCSSource) getManifestAndLock(ctx context.Context, pr ProjectRoot, r Revision, an ProjectAnalyzer) (Manifest, Lock, error) { | ||
err := bs.repo.updateVersion(ctx, r.String()) | ||
if err != nil { | ||
|
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.
Perhaps this should return a Revision, instead of types from vcs.
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.
Works for me 👌