diff --git a/source/dub/package_.d b/source/dub/package_.d index d1234dd468..0c1fb7c3c7 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -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;