1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-18 20:35:46 +01:00

Small refactoring of ConfigBase#{haveHg,branch,version}.

--HG--
extra : rebase_source : 3507cd5053d8041826855822a399e882a946ae33
This commit is contained in:
Doug Kearns
2011-03-12 02:04:21 +11:00
parent 1094eb2412
commit acb7a8c8a1

View File

@@ -130,35 +130,38 @@ var ConfigBase = Class("ConfigBase", {
.nth(function (l) set.has(langs, l), 0); .nth(function (l) set.has(langs, l), 0);
}, },
haveHg: Class.memoize(function () { /**
* @property {string} The pathname of the VCS repository clone's root
* directory if the application is running from one via an extension
* proxy file.
*/
VCSPath: Class.memoize(function () {
if (/pre$/.test(this.addon.version)) { if (/pre$/.test(this.addon.version)) {
let uri = this.addon.getResourceURI("../.hg"); let uri = this.addon.getResourceURI("../.hg");
if (uri instanceof Ci.nsIFileURL && if (uri instanceof Ci.nsIFileURL &&
uri.QueryInterface(Ci.nsIFileURL).file.exists() && uri.QueryInterface(Ci.nsIFileURL).file.exists() &&
io.pathSearch("hg")) io.pathSearch("hg"))
return ["hg", "-R", uri.file.parent.path]; return uri.file.parent.path;
} }
return null; return null;
}), }),
/**
* @property {string} The name of the VCS branch that the application is
* running from if using an extension proxy file or was built from if
* installed as an XPI.
*/
branch: Class.memoize(function () { branch: Class.memoize(function () {
if (this.haveHg) if (this.VCSPath)
return io.system(this.haveHg.concat(["branch"])).output; return io.system(["hg", "-R", this.VCSPath, "branch"]).output;
return (/pre-hg\d+-(\S*)/.exec(this.version) || [])[1]; return (/pre-hg\d+-(\S*)/.exec(this.version) || [])[1];
}), }),
/** @property {string} The Dactyl version string. */ /** @property {string} The Dactyl version string. */
version: Class.memoize(function () { version: Class.memoize(function () {
if (/pre$/.test(this.addon.version)) { if (this.VCSPath)
let uri = this.addon.getResourceURI("../.hg"); return io.system(["hg", "-R", this.VCSPath, "log", "-r.",
if (uri instanceof Ci.nsIFileURL && "--template=hg{rev}-" + this.branch + " ({date|isodate})"]).output;
uri.QueryInterface(Ci.nsIFileURL).file.exists() &&
io.pathSearch("hg")) {
return io.system(["hg", "-R", uri.file.parent.path,
"log", "-r.",
"--template=hg{rev}-" + this.branch + " ({date|isodate})"]).output;
}
}
let version = this.addon.version; let version = this.addon.version;
if ("@DATE@" !== "@" + "DATE@") if ("@DATE@" !== "@" + "DATE@")
version += " (created: @DATE@)"; version += " (created: @DATE@)";