From acb7a8c8a15e196a811fee23acebdc64464cecb5 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sat, 12 Mar 2011 02:04:21 +1100 Subject: [PATCH] Small refactoring of ConfigBase#{haveHg,branch,version}. --HG-- extra : rebase_source : 3507cd5053d8041826855822a399e882a946ae33 --- common/modules/config.jsm | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/common/modules/config.jsm b/common/modules/config.jsm index 0133413b..7c4c4e6c 100644 --- a/common/modules/config.jsm +++ b/common/modules/config.jsm @@ -130,35 +130,38 @@ var ConfigBase = Class("ConfigBase", { .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)) { let uri = this.addon.getResourceURI("../.hg"); if (uri instanceof Ci.nsIFileURL && uri.QueryInterface(Ci.nsIFileURL).file.exists() && io.pathSearch("hg")) - return ["hg", "-R", uri.file.parent.path]; + return uri.file.parent.path; } 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 () { - if (this.haveHg) - return io.system(this.haveHg.concat(["branch"])).output; + if (this.VCSPath) + return io.system(["hg", "-R", this.VCSPath, "branch"]).output; return (/pre-hg\d+-(\S*)/.exec(this.version) || [])[1]; }), /** @property {string} The Dactyl version string. */ version: Class.memoize(function () { - if (/pre$/.test(this.addon.version)) { - let uri = this.addon.getResourceURI("../.hg"); - if (uri instanceof Ci.nsIFileURL && - 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; - } - } + if (this.VCSPath) + return io.system(["hg", "-R", this.VCSPath, "log", "-r.", + "--template=hg{rev}-" + this.branch + " ({date|isodate})"]).output; let version = this.addon.version; if ("@DATE@" !== "@" + "DATE@") version += " (created: @DATE@)";