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

Commit cbf0318

Browse files
committed
gps: don't fold inputs to root deduction
But, still preserve the rule that we record the canonical folded URL in memory, so that we can have non-canonical inputs come in first and still converge with subsequent canonical, or other-case-variant forms later.
1 parent 101c2d9 commit cbf0318

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

internal/gps/manager_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,12 @@ func TestSourceCreationCounts(t *testing.T) {
427427
"case variance across path and URL-based access": {
428428
roots: []ProjectIdentifier{
429429
ProjectIdentifier{ProjectRoot: ProjectRoot("github.com/sdboyer/gpkt"), Source: "https://github.com/Sdboyer/gpkt"},
430+
ProjectIdentifier{ProjectRoot: ProjectRoot("github.com/sdboyer/gpkt"), Source: "https://github.com/SdbOyer/gpkt"},
430431
mkPI("github.com/sdboyer/gpkt"),
431432
ProjectIdentifier{ProjectRoot: ProjectRoot("github.com/sdboyer/gpkt"), Source: "https://github.com/sdboyeR/gpkt"},
432433
mkPI("github.com/sdboyeR/gpkt"),
433434
},
434-
namecount: 5,
435+
namecount: 6,
435436
srccount: 1,
436437
},
437438
}

internal/gps/source.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ func (sc *sourceCoordinator) getSourceGatewayFor(ctx context.Context, id Project
102102
// systems. So we follow this path, which is both a vastly simpler solution
103103
// and one that seems quite likely to work in practice.
104104
foldedNormalName := toFold(normalizedName)
105-
if foldedNormalName != normalizedName {
105+
notFolded := foldedNormalName != normalizedName
106+
if notFolded {
106107
// If the folded name differs from the input name, then there may
107108
// already be an entry for it in the nameToURL map, so check again.
108109
if url, has := sc.nameToURL[foldedNormalName]; has {
@@ -164,7 +165,7 @@ func (sc *sourceCoordinator) getSourceGatewayFor(ctx context.Context, id Project
164165
sc.psrcmut.Unlock()
165166
}
166167

167-
pd, err := sc.deducer.deduceRootPath(ctx, foldedNormalName)
168+
pd, err := sc.deducer.deduceRootPath(ctx, normalizedName)
168169
if err != nil {
169170
// As in the deducer, don't cache errors so that externally-driven retry
170171
// strategies can be constructed.
@@ -207,6 +208,14 @@ func (sc *sourceCoordinator) getSourceGatewayFor(ctx context.Context, id Project
207208
return nil, err
208209
}
209210

211+
// If the normalizedName and foldedNormalName differ, then we're pretty well
212+
// guaranteed that returned URL will also need folding into canonical form.
213+
var unfoldedURL string
214+
if notFolded {
215+
unfoldedURL = url
216+
url = toFold(url)
217+
}
218+
210219
// We know we have a working srcGateway at this point, and need to
211220
// integrate it back into the main map.
212221
sc.srcmut.Lock()
@@ -218,10 +227,11 @@ func (sc *sourceCoordinator) getSourceGatewayFor(ctx context.Context, id Project
218227
sc.nameToURL[url] = url
219228
}
220229

221-
// Make sure we have both the folded and unfolded names recorded in the map,
222-
// should they differ.
223-
if normalizedName != foldedNormalName {
230+
// Make sure we have both the folded and unfolded names and URLs recorded in
231+
// the map, if the input needed folding.
232+
if notFolded {
224233
sc.nameToURL[normalizedName] = url
234+
sc.nameToURL[unfoldedURL] = url
225235
}
226236

227237
if sa, has := sc.srcs[url]; has {

0 commit comments

Comments
 (0)