Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions src/haxelib/VersionData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ package haxelib;
else
throw 'Invalid VscID $s';
}

public function getName() {
return switch cast(this, VcsID) {
case Git: "Git";
case Hg: "Mercurial";
};
}
}

/** Class containing repoducible git or hg library data. **/
Expand All @@ -28,7 +35,7 @@ class VcsData {
var url:String;
/** Commit hash **/
@:optional
var ref:Null<String>;
var commit:Null<String>;
/** The git tag or mercurial revision **/
@:optional
var tag:Null<String>;
Expand All @@ -45,7 +52,7 @@ class VcsData {

public function toString(): String {
var qualifier =
if (ref != null) ref
if (commit != null) commit
else if (tag != null) tag
else if (branch != null) branch
else null;
Expand All @@ -54,6 +61,35 @@ class VcsData {
else
url;
}

public function isReproducible() {
return commit != null;
}

/**
Returns an object containing the filled-in VcsData fields,
without the empty ones.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, what? I struggle to make sense of both this description and the implementation. What is the point of this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It converts a VcsData class object into an anonymous object with the fields that actually carry any information. This is useful when you want to write to a json file, where including the null fields is pointless.

This is haxelib's cli for git installs:

haxelib git [project-name] [git-clone-path] [branch] [subDir] [tag]

So if you want to install with a tag but not a branch or subDir, you have to put both of those anyway as empty strings. The method also excludes fields that have empty values like this, which don't actually hold any useful information about the installation.

**/
public function getCleaned() {
var data:{
url:String,
?commit:String,
?tag:String,
?branch:String,
?subDir:String
} = { url : url };

if (commit != null)
data.commit = commit;
if (tag != null)
data.tag = tag;
if (!(branch == null || branch == ""))
data.branch = branch;
if (!(subDir == null || haxe.io.Path.normalize(subDir) == ""))
data.subDir = subDir;

return data;
}
}

/** Data required to reproduce a library version **/
Expand Down Expand Up @@ -89,7 +125,7 @@ class VersionDataHelper {
type: type,
data: {
url: vcsRegex.matched(2),
ref: vcsRegex.matched(3),
commit: vcsRegex.matched(3),
branch: vcsRegex.matched(4),
subDir: null,
tag: null
Expand Down
17 changes: 17 additions & 0 deletions src/haxelib/api/FsUtils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,21 @@ class FsUtils {
seek(root);
return ret;
}

/**
Switches to directory found at `path`, executes `f()` in this directory,
before switching back to the previous directory.
**/
public static function runInDirectory<T>(path:String, f:() -> T):T {
final oldCwd = Sys.getCwd();
try {
Sys.setCwd(path);
final value = f();
Sys.setCwd(oldCwd);
return value;
} catch (e) {
Sys.setCwd(oldCwd);
throw e;
}
}
}
17 changes: 15 additions & 2 deletions src/haxelib/api/GlobalScope.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ class GlobalScope extends Scope {
}

public function setVcsVersion(library:ProjectName, vcsVersion:VcsID, ?data:VcsData):Void {
if (data == null) data = {url: "unknown"};
if (data != null) {
repository.setVcsData(library, vcsVersion, data);
}

if (data.subDir != null) {
if (!(data == null || data.subDir == "" || data.subDir == null)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks weird, could we De Morgan it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

final devDir = repository.getValidVersionPath(library, vcsVersion) + data.subDir;
repository.setDevPath(library, devDir);
} else {
Expand Down Expand Up @@ -273,4 +275,15 @@ class GlobalScope extends Scope {
return {path: path, version: current};
}

public function resolve(library:ProjectName):VersionData {
final version = repository.getCurrentVersion(library);

return switch version {
case vcs if (VcsID.isValid(vcs)):
final vcsId = VcsID.ofString(vcs);
VcsInstall(vcsId, repository.getVcsData(library, vcsId));
case semVer:
Haxelib(SemVer.ofString(semVer));
};
}
}
Loading
Loading