Skip to content

Commit

Permalink
Only cache versions on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Sep 22, 2015
1 parent 45308c7 commit 88e3f26
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions source/dub/package_.d
Original file line number Diff line number Diff line change
Expand Up @@ -598,38 +598,45 @@ class Package {

private string determineVersionFromSCM(Path path)
{
import std.file : exists, readText;

// quickly determine head commit without invoking GIT
string head_commit;
auto hpath = (path ~ ".git/HEAD").toNativeString();
if (exists(hpath)) {
auto head_ref = readText(hpath).strip();
if (head_ref.startsWith("ref: ")) {
auto rpath = (path ~ (".git/"~head_ref[5 .. $])).toNativeString();
if (exists(rpath))
head_commit = readText(rpath).strip();
// On Windows, which is slow at running external processes,
// cache the version numbers that are determined using
// GIT to speed up the initialization phase.
version (Windows) {
import std.file : exists, readText;

// quickly determine head commit without invoking GIT
string head_commit;
auto hpath = (path ~ ".git/HEAD").toNativeString();
if (exists(hpath)) {
auto head_ref = readText(hpath).strip();
if (head_ref.startsWith("ref: ")) {
auto rpath = (path ~ (".git/"~head_ref[5 .. $])).toNativeString();
if (exists(rpath))
head_commit = readText(rpath).strip();
}
}
}

// return the last determined version for that commit
// not that this is not always correct, most notably when
// a tag gets added/removed/changed and changes the outcome
// of the full version detection computation
auto vcachepath = path ~ ".dub/version.json";
if (existsFile(vcachepath)) {
auto ver = jsonFromFile(vcachepath);
if (head_commit == ver["commit"].opt!string)
return ver["version"].get!string;
// return the last determined version for that commit
// not that this is not always correct, most notably when
// a tag gets added/removed/changed and changes the outcome
// of the full version detection computation
auto vcachepath = path ~ ".dub/version.json";
if (existsFile(vcachepath)) {
auto ver = jsonFromFile(vcachepath);
if (head_commit == ver["commit"].opt!string)
return ver["version"].get!string;
}
}

// if no cache file or the HEAD commit changed, perform full detection
auto ret = determineVersionWithGIT(path);

// update version cache file
if (head_commit.length) {
if (!existsFile(path ~".dub")) createDirectory(path ~ ".dub");
atomicWriteJsonFile(vcachepath, Json(["commit": Json(head_commit), "version": Json(ret)]));
version (Windows) {
// update version cache file
if (head_commit.length) {
if (!existsFile(path ~".dub")) createDirectory(path ~ ".dub");
atomicWriteJsonFile(vcachepath, Json(["commit": Json(head_commit), "version": Json(ret)]));
}
}

return ret;
Expand Down

0 comments on commit 88e3f26

Please sign in to comment.