path: root/dh-elpa.el
diff options
authorSean Whitton <>2016-08-12 11:54:51 -0700
committerSean Whitton <>2016-08-12 11:54:51 -0700
commit314372a9aeb12638d95863ec5b0b22aa42625d99 (patch)
tree123f883bf27a782fc3a94f3dfbbbea7281c11387 /dh-elpa.el
parent44906c9d3c31b71c980ba8696f4fbcc37736c28c (diff)
sanitise versions from env vars
Diffstat (limited to 'dh-elpa.el')
1 files changed, 35 insertions, 3 deletions
diff --git a/dh-elpa.el b/dh-elpa.el
index 6137ab2..6264fd9 100644
--- a/dh-elpa.el
+++ b/dh-elpa.el
@@ -108,13 +108,18 @@ DEB_VERSION_UPSTREAM environment variables are set."))
"Return the package version as found in standard DEB_* environment variables.
-Signal an error if these are both set and they disagree."
+Signal an error if these are both set and they disagree.
+Versions taken from environment variables are run through
;; If one of these environment variables is the empty string, it's
;; as good as unset, so we replace that with the nil value.
(let ((upstream-version (null-empty-string
+ (dhelpa-sanitise-version
+ (getenv "DEB_UPSTREAM_VERSION"))))
(version-upstream (null-empty-string
- (getenv "DEB_VERSION_UPSTREAM"))))
+ (dhelpa-sanitise-version
+ (getenv "DEB_VERSION_UPSTREAM")))))
(if (and upstream-version
(not (string= upstream-version version-upstream)))
@@ -122,6 +127,33 @@ Signal an error if these are both set and they disagree."
environment variables are both set, but they disagree.")
(if upstream-version upstream-version version-upstream))))
+(defun dhelpa-sanitise-version (version)
+ "Sanitise a Debian version VERSION such that it will work with Emacs.
+Our goal is to ensure that ELPA package versions are sorted
+correctly relative to other versions of the package the user
+might have installed in their home directory.
+To do this:
+- we remove all indication of backporting, since that is a matter
+ of Debian packaging and shouldn't affect the ELPA package
+ content
+- we replace '~' with '-' -- Emacs interprets '-rc', '-git' and
+ '-pre' similar to how dpkg interprets '~rc', '~git' and
+ '~pre' (see `version-to-list')
+This will not give the right answer in all cases (for example
+'~foo' where 'foo' is not one of the strings Emacs recognises as
+a pre-release). The Debian package maintainer should patch the
+upstream source to include a proper Package-Version: header in
+such a case."
+ (when version
+ (replace-regexp-in-string
+ "~" "-"
+ (replace-regexp-in-string "~bpo.*$" "" version))))
(defun null-empty-string (str)
"If STR is a string of length zero, return nil. Otherwise, return STR."
(if (and (stringp str)