]> code.delx.au - gnu-emacs/commitdiff
emacs-bzr-get-version tweak
authorGlenn Morris <rgm@gnu.org>
Mon, 9 Apr 2012 23:03:33 +0000 (19:03 -0400)
committerGlenn Morris <rgm@gnu.org>
Mon, 9 Apr 2012 23:03:33 +0000 (19:03 -0400)
* lisp/version.el (emacs-bzr-get-version):
Handle lightweight checkouts of local branches.

lisp/ChangeLog
lisp/version.el

index 954daf68510c04599dbaaf89dcdecef25680c015..a3f992eb9dc34a0d32a98a8c84b14a509cdc7401 100644 (file)
@@ -1,7 +1,11 @@
+2012-04-09  Glenn Morris  <rgm@gnu.org>
+
+       * version.el (emacs-bzr-get-version):
+       Handle lightweight checkouts of local branches.
+
 2012-04-09  Andreas Schwab  <schwab@linux-m68k.org>
 
-       * international/characters.el: Recover lost case pairs.
-       (Bug#11209)
+       * international/characters.el: Recover lost case pairs.  (Bug#11209)
 
 2012-04-09  Chong Yidong  <cyd@gnu.org>
 
index a4bc4fd54a6244d0b98fe6105093bcc3d766198e..56e19147b2c0c6bb65efa316d30a07c4bb0a7a99 100644 (file)
@@ -85,19 +85,35 @@ String giving the bzr revision number from which this Emacs was built.
 This is nil if Emacs was not built from a bzr checkout, or if we could
 not determine the revision.")
 
-(defun emacs-bzr-get-version () "\
+(defun emacs-bzr-get-version (&optional dir) "\
 Try to return as a string the bzr revision number of the Emacs sources.
 Returns nil if the sources do not seem to be under bzr, or if we could
 not determine the revision.  Note that this reports on the current state
-of the sources, which may not correspond to the running Emacs."
-  (let ((file (expand-file-name ".bzr/branch/last-revision" source-directory)))
-    (if (file-readable-p file)
-        (with-temp-buffer
-          (insert-file-contents file)
-          (goto-char (point-max))
-          (if (looking-back "\n")
-              (delete-char -1))
-          (buffer-string)))))
+of the sources, which may not correspond to the running Emacs.
+
+Optional argument DIR is a directory to use instead of `source-directory'."
+  (or dir (setq dir source-directory))
+  (when (file-directory-p (setq dir (expand-file-name ".bzr/branch" dir)))
+    (let (file loc)
+      (cond ((file-readable-p
+              (setq file (expand-file-name "last-revision" dir)))
+             (with-temp-buffer
+               (insert-file-contents file)
+               (goto-char (point-max))
+               (if (looking-back "\n")
+                   (delete-char -1))
+               (buffer-string)))
+            ;; OK, no last-revision.  Is it a lightweight checkout?
+            ((file-readable-p
+              (setq file (expand-file-name "location" dir)))
+             ;; If the parent branch is local, try looking there for the revid.
+             (if (setq loc (with-temp-buffer
+                             (insert-file-contents file)
+                             (if (looking-at "file://\\(.*\\)")
+                                 (match-string 1))))
+                 (emacs-bzr-get-version loc)))
+            ;; Could fall back to eg `bzr testament' at this point.
+            ))))
 
 ;; We put version info into the executable in the form that `ident' uses.
 (or (eq system-type 'windows-nt)