-
Notifications
You must be signed in to change notification settings - Fork 1k
internal/gps: Parse abbreviated git revisions #1027
Changes from 4 commits
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ package gps | |
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
|
@@ -519,24 +518,13 @@ func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint | |
return Any(), nil | ||
} | ||
|
||
slen := len(s) | ||
if slen == 40 { | ||
if _, err := hex.DecodeString(s); err == nil { | ||
// Whether or not it's intended to be a SHA1 digest, this is a | ||
// valid byte sequence for that, so go with Revision. This | ||
// covers git and hg | ||
return Revision(s), nil | ||
} | ||
} | ||
|
||
// Next, try for bzr, which has a three-component GUID separated by | ||
// dashes. There should be two, but the email part could contain | ||
// internal dashes | ||
// Bazaar has a three-component GUID separated by dashes. There should be two, | ||
// but the email part could contain internal dashes. | ||
if strings.Contains(s, "@") && strings.Count(s, "-") >= 2 { | ||
// Work from the back to avoid potential confusion from the email | ||
i3 := strings.LastIndex(s, "-") | ||
// Skip if - is last char, otherwise this would panic on bounds err | ||
if slen == i3+1 { | ||
if len(s) == i3+1 { | ||
return NewVersion(s), nil | ||
} | ||
|
||
|
@@ -578,9 +566,29 @@ func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint | |
return version.Unpair(), nil | ||
} | ||
|
||
// Revision, possibly abbreviated | ||
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. Originally the function checked if the string given was a revision first (note the comment at the top of the file). Unless we need to change that behavior(?), let's move this back to the top where we are replacing the old code. 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 think we do need to change that behavior. If we put it at the top, then we'll dereference branch names and version tags, turning them into pure Revisions. 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. Okay then let's just update the comment to reflect the new order. |
||
r, err := sm.disambiguateRevision(context.TODO(), pi, Revision(s)) | ||
if err == nil { | ||
return r, nil | ||
} | ||
|
||
return nil, errors.Errorf("%s is not a valid version for the package %s(%s)", s, pi.ProjectRoot, pi.Source) | ||
} | ||
|
||
// disambiguateRevision looks up a revision in the underlying source, spitting | ||
// it back out in an unabbreviated, disambiguated form. | ||
// | ||
// For example, if pi refers to a git-based project, then rev could be an | ||
// abbreviated git commit hash. disambiguateRevision would return the complete | ||
// hash. | ||
func (sm *SourceMgr) disambiguateRevision(ctx context.Context, pi ProjectIdentifier, rev Revision) (Revision, error) { | ||
srcg, err := sm.srcCoord.getSourceGatewayFor(context.TODO(), pi) | ||
if err != nil { | ||
return "", err | ||
} | ||
return srcg.disambiguateRevision(ctx, rev) | ||
} | ||
|
||
type timeCount struct { | ||
count int | ||
start time.Time | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,8 @@ func TestSourceManager_InferConstraint(t *testing.T) { | |
"v2": NewBranch("v2"), | ||
"v0.12.0-12-de4dcafe0": svs, | ||
"master": NewBranch("master"), | ||
"5b3352dc16517996fb951394bcbbe913a2a616e3": Revision("5b3352dc16517996fb951394bcbbe913a2a616e3"), | ||
"3f4c3bea144e112a69bbe5d8d01c1b09a544253f": Revision("3f4c3bea144e112a69bbe5d8d01c1b09a544253f"), | ||
"3f4c3bea": Revision("3f4c3bea144e112a69bbe5d8d01c1b09a544253f"), | ||
|
||
// valid bzr rev | ||
"[email protected]": Revision("[email protected]"), | ||
|
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.
What happens when you remove the specific handling for bzr? I was hoping (but don't know for sure!) that
repo.CommitInfo
would work for all vcs types, including bzr.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.
I was hoping we could too, but doing so makes the current test fail (since the current test operates on a git repo, not a bzr one).
I think this should work for bzr too... but I've never used bzr in my life, really. I'm a little wary of trying to write a realistic test given my lack of experience with bzr. If you feel like you could review it well and guide me, though, I'm game.
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.
Yeah, I don't think our CI build runs against any real bzr repos?
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.
the gps tests include some real tests against bzr.