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 18, 2024
1 parent b7569b0 commit ce544cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
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
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 ce544cb

Please sign in to comment.