Skip to content

Commit

Permalink
Adapt loadSCMPackage to PackageName API
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 committed Jan 19, 2024
1 parent a10e798 commit ebfbf01
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ class Dub {
try if (m_packageManager.getOrLoadPackage(path)) continue;
catch (Exception e) { logDebug("Failed to load path based selection: %s", e.toString().sanitize); }
} else if (!dep.repository.empty) {
if (m_packageManager.loadSCMPackage(name.toString(), dep.repository))
if (m_packageManager.loadSCMPackage(name, dep.repository))
continue;
} else {
if (m_packageManager.getPackage(p, dep.version_)) continue;
Expand Down Expand Up @@ -703,7 +703,7 @@ class Dub {
continue;
}
} else if (!ver.repository.empty) {
pack = m_packageManager.loadSCMPackage(name.toString(), ver.repository);
pack = m_packageManager.loadSCMPackage(name, ver.repository);
} else {
assert(ver.isExactVersion, "Resolved dependency is neither path, nor repository, nor exact version based!?");
pack = m_packageManager.getPackage(p, ver.version_);
Expand Down Expand Up @@ -1934,7 +1934,7 @@ private class DependencyVersionResolver : DependencyResolver!(Dependency, Depend
return m_rootPackage.basePackage;

if (!dep.repository.empty) {
auto ret = m_dub.packageManager.loadSCMPackage(name.toString(), dep.repository);
auto ret = m_dub.packageManager.loadSCMPackage(name, dep.repository);
return ret !is null && dep.matches(ret.version_) ? ret : null;
}
if (!dep.path.empty) {
Expand Down
22 changes: 13 additions & 9 deletions source/dub/packagemanager.d
Original file line number Diff line number Diff line change
Expand Up @@ -398,29 +398,33 @@ class PackageManager {
The package loaded from the given SCM repository or null if the
package couldn't be loaded.
*/
deprecated("Use the overload that accepts a `dub.dependency : Repository`")
Package loadSCMPackage(string name, Dependency dependency)
in { assert(!dependency.repository.empty); }
do { return this.loadSCMPackage(name, dependency.repository); }

/// Ditto
Package loadSCMPackage(string name, Repository repo)
Package loadSCMPackage(in PackageName name, in Repository repo)
in { assert(!repo.empty); }
do {
Package pack;
const name_ = PackageName(name);

final switch (repo.kind)
{
case repo.Kind.git:
pack = loadGitPackage(name_, repo);
pack = loadGitPackage(name, repo);
}
if (pack !is null) {
addPackages(this.m_internal.fromPath, pack);
}
return pack;
}

deprecated("Use the overload that accepts a `dub.dependency : Repository`")
Package loadSCMPackage(string name, Dependency dependency)
in { assert(!dependency.repository.empty); }
do { return this.loadSCMPackage(name, dependency.repository); }

deprecated("Use `loadSCMPackage(PackageName, Repository)`")
Package loadSCMPackage(string name, Repository repo)
{
return this.loadSCMPackage(PackageName(name), repo);
}

private Package loadGitPackage(in PackageName name, in Repository repo)
{
import dub.internal.git : cloneRepository;
Expand Down
4 changes: 2 additions & 2 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ class Project {
return resolveSubPackage(tmp, subname, true);
},
(Repository repo) {
auto tmp = m_packageManager.loadSCMPackage(basename.toString(), repo);
auto tmp = m_packageManager.loadSCMPackage(basename, repo);
return resolveSubPackage(tmp, subname, true);
},
(VersionRange range) {
Expand All @@ -585,7 +585,7 @@ class Project {
if (p is null)
{
if (!vspec.repository.empty) {
p = m_packageManager.loadSCMPackage(basename.toString(), vspec.repository);
p = m_packageManager.loadSCMPackage(basename, vspec.repository);
resolveSubPackage(p, subname, false);
enforce(p !is null,
"Unable to fetch '%s@%s' using git - does the repository and version exists?".format(
Expand Down
12 changes: 7 additions & 5 deletions source/dub/test/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ package class TestPackageManager : PackageManager
super(local, user, system, false);
}

// Re-introduce hidden/deprecated overloads
public alias loadSCMPackage = PackageManager.loadSCMPackage;

/// Disabled as semantic are not implementable unless a virtual FS is created
public override @property void customCachePaths(NativePath[] custom_cache_paths)
{
Expand Down Expand Up @@ -326,27 +329,26 @@ package class TestPackageManager : PackageManager
* Instead, we allow unittests to explicitly define what packages should be
* reachable in a given test.
*/
public override Package loadSCMPackage(string name, Repository repo)
public override Package loadSCMPackage(in PackageName name, in Repository repo)
{
import std.string : chompPrefix;

// We're trying to match `loadGitPackage` as much as possible
if (!repo.ref_.startsWith("~") && !repo.ref_.isGitHash)
return null;

const name_ = PackageName(name);
string gitReference = repo.ref_.chompPrefix("~");
NativePath destination = this.getPackagePath(PlacementLocation.user, name_, repo.ref_);
NativePath destination = this.getPackagePath(PlacementLocation.user, name, repo.ref_);

foreach (p; getPackageIterator(name))
foreach (p; getPackageIterator(name.toString()))
if (p.path == destination)
return p;

return this.loadSCMRepository(name, repo);
}

/// The private part of `loadSCMPackage`
protected Package loadSCMRepository(string name, Repository repo)
protected Package loadSCMRepository(in PackageName name, in Repository repo)
{
if (auto prepo = repo in this.scm) {
this.add(*prepo);
Expand Down

0 comments on commit ebfbf01

Please sign in to comment.