Subject: Re: bug#8054: 24.0.50; Who ever heard of a version number that doesn't change all year?

From: Glenn Morris <[email-masked]>
Date: Mon, 21 Nov 2011 19:48:16 -0500

Here's a patch to define an `emacs-bzr-version' during dumping and
include it in bug reports.

=== modified file 'lisp/loadup.el'
*** lisp/loadup.el	2011-07-06 22:43:48 +0000
--- lisp/loadup.el	2011-11-22 00:44:13 +0000
***************
*** 259,264 ****
--- 259,266 ----
  	   (versions (mapcar (function (lambda (name)
  					 (string-to-number (substring name (length base)))))
  			     files)))
+       (setq emacs-bzr-version (condition-case nil (emacs-bzr-get-version)
+                               (error nil)))
        ;; `emacs-version' is a constant, so we shouldn't change it with `setq'.
        (defconst emacs-version
  	(format "%s.%d"

=== modified file 'lisp/mail/emacsbug.el'
*** lisp/mail/emacsbug.el	2011-09-23 23:47:27 +0000
--- lisp/mail/emacsbug.el	2011-11-22 00:25:12 +0000
***************
*** 224,229 ****
--- 224,231 ----
      (add-text-properties (1+ user-point) (point) prompt-properties)
  
      (insert "\n\nIn " (emacs-version) "\n")
+     (if (stringp emacs-bzr-version)
+ 	(insert "Bzr revision: " emacs-bzr-version "\n"))
      (if (fboundp 'x-server-vendor)
  	(condition-case nil
              ;; This is used not only for X11 but also W32 and others.

=== modified file 'lisp/version.el'
*** lisp/version.el	2011-03-12 19:19:47 +0000
--- lisp/version.el	2011-11-22 00:37:43 +0000
***************
*** 78,89 ****
--- 78,110 ----
  ;; We hope that this alias is easier for people to find.
  (defalias 'version 'emacs-version)
  
+ ;; Set during dumping, this is a defvar so that it can be setq'd.
+ (defvar emacs-bzr-version nil
+   "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 ()
+   "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)))))
+ 
  ;; We put version info into the executable in the form that `ident' uses.
  (or (eq system-type 'windows-nt)
      (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version))