aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2012-09-15 13:00:45 -0700
committerGlenn Morris2012-09-15 13:00:45 -0700
commit72aa16e19b24eb73c812c13d4cd77afd7977fc25 (patch)
tree416feaf0068b5f41a6c5766bf2bcbdcd2d438b06
parent830be228cde51f401457d95de0af8152a5a9b75d (diff)
downloademacs-72aa16e19b24eb73c812c13d4cd77afd7977fc25.tar.gz
emacs-72aa16e19b24eb73c812c13d4cd77afd7977fc25.zip
Add option to ask bzr itself for the emacs bzr revision
* lisp/version.el (emacs-bzr-version-bzr): New function. (emacs-bzr-get-version): Add optional EXTERNAL argument.
-rw-r--r--lisp/ChangeLog3
-rw-r--r--lisp/version.el94
2 files changed, 63 insertions, 34 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c9aa7e99356..b436d9e364e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,8 @@
12012-09-15 Glenn Morris <rgm@gnu.org> 12012-09-15 Glenn Morris <rgm@gnu.org>
2 2
3 * version.el (emacs-bzr-version-bzr): New function.
4 (emacs-bzr-get-version): Add optional EXTERNAL argument.
5
3 * vc/vc-bzr.el (vc-bzr-working-revision): For lightweight local 6 * vc/vc-bzr.el (vc-bzr-working-revision): For lightweight local
4 checkouts, check the parent dirstate matches the branch. 7 checkouts, check the parent dirstate matches the branch.
5 Add "--tree" to "bzr revno" arguments. Don't try to shorten the 8 Add "--tree" to "bzr revno" arguments. Don't try to shorten the
diff --git a/lisp/version.el b/lisp/version.el
index 47476cb268a..1fb3828e15d 100644
--- a/lisp/version.el
+++ b/lisp/version.el
@@ -104,48 +104,74 @@ Returns nil if unable to find this information."
104 (looking-at "[0-9]+\0\\([^\0\n]+\\)\0") 104 (looking-at "[0-9]+\0\\([^\0\n]+\\)\0")
105 (match-string 1)))))) 105 (match-string 1))))))
106 106
107(defun emacs-bzr-get-version (&optional dir) 107(defun emacs-bzr-version-bzr (dir)
108 "Ask bzr itself for the version information for directory DIR."
109 ;; Comments on `bzr version-info':
110 ;; i) Unknown files also cause clean != 1.
111 ;; ii) It can be slow, contacting the upstream repo to get the
112 ;; branch nick if one is not set locally, even with a custom
113 ;; template that is not asking for the nick (as used here). You'd
114 ;; think the latter part would be trivial to fix:
115 ;; https://bugs.launchpad.net/bzr/+bug/882541/comments/3
116 ;; https://bugs.launchpad.net/bzr/+bug/629150
117 ;; You can set the nick locally with `bzr nick ...', which speeds
118 ;; things up enormously. `bzr revno' does not have this issue, but
119 ;; has no way to print the revision_id AFAICS.
120 (message "Waiting for bzr...")
121 (with-temp-buffer
122 (if (zerop
123 (call-process "bzr" nil '(t nil) nil "version-info"
124 "--custom"
125 "--template={revno} {revision_id} (clean = {clean})"
126 "dir"))
127 (buffer-string))))
128
129(defun emacs-bzr-get-version (&optional dir external)
108 "Try to return as a string the bzr revision of the Emacs sources. 130 "Try to return as a string the bzr revision of the Emacs sources.
109The format is: [revno] revision_id, where revno may be absent. 131The format is: [revno] revision_id, where revno may be absent.
110Value is nil if the sources do not seem to be under bzr, or if we could 132Value is nil if the sources do not seem to be under bzr, or if we could
111not determine the revision. Note that this reports on the current state 133not determine the revision. Note that this reports on the current state
112of the sources, which may not correspond to the running Emacs. 134of the sources, which may not correspond to the running Emacs.
113 135
114Optional argument DIR is a directory to use instead of `source-directory'." 136Optional argument DIR is a directory to use instead of `source-directory'.
137Optional argument EXTERNAL non-nil means to maybe ask `bzr' itself,
138if the sources appear to be under bzr. If `force', always ask bzr.
139Otherwise only ask bzr if we cannot find any information ourselves."
115 (or dir (setq dir source-directory)) 140 (or dir (setq dir source-directory))
116 (when (file-directory-p (expand-file-name ".bzr/branch" dir)) 141 (when (file-directory-p (expand-file-name ".bzr/branch" dir))
117 (let (file loc rev) 142 (if (eq external 'force)
118 (cond ((file-readable-p 143 (emacs-bzr-version-bzr dir)
119 (setq file (expand-file-name ".bzr/branch/last-revision" dir))) 144 (let (file loc rev)
120 (with-temp-buffer 145 (cond ((file-readable-p
121 (insert-file-contents file) 146 (setq file (expand-file-name ".bzr/branch/last-revision" dir)))
122 (goto-char (point-max)) 147 (with-temp-buffer
123 (if (looking-back "\n") 148 (insert-file-contents file)
124 (delete-char -1)) 149 (goto-char (point-max))
125 (buffer-string))) 150 (if (looking-back "\n")
126 ;; OK, no last-revision. Is it a lightweight checkout? 151 (delete-char -1))
127 ((file-readable-p 152 (buffer-string)))
128 (setq file (expand-file-name ".bzr/branch/location" dir))) 153 ;; OK, no last-revision. Is it a lightweight checkout?
129 (setq rev (emacs-bzr-version-dirstate dir)) 154 ((file-readable-p
130 ;; If the parent branch is local, try looking there for the rev. 155 (setq file (expand-file-name ".bzr/branch/location" dir)))
131 ;; Note: there is no guarantee that the parent branch's rev 156 (setq rev (emacs-bzr-version-dirstate dir))
132 ;; corresponds to this branch. This branch could have 157 ;; If the parent branch is local, try looking there for the rev.
133 ;; been made with a specific -r revno argument, or the 158 ;; Note: there is no guarantee that the parent branch's rev
134 ;; parent could have been updated since this branch was created. 159 ;; corresponds to this branch. This branch could have
135 ;; To try and detect this, we check the dirstate revids 160 ;; been made with a specific -r revno argument, or the
136 ;; to see if they match. 161 ;; parent could have been updated since this branch was created.
137 (if (and (setq loc (with-temp-buffer 162 ;; To try and detect this, we check the dirstate revids
138 (insert-file-contents file) 163 ;; to see if they match.
139 (if (looking-at "file://\\(.*\\)") 164 (if (and (setq loc (with-temp-buffer
140 (match-string 1)))) 165 (insert-file-contents file)
141 (equal rev (emacs-bzr-version-dirstate loc))) 166 (if (looking-at "file://\\(.*\\)")
142 (emacs-bzr-get-version loc) 167 (match-string 1))))
143 ;; If parent does not match, the best we can do without 168 (equal rev (emacs-bzr-version-dirstate loc)))
144 ;; calling external commands is to use the dirstate rev. 169 (emacs-bzr-get-version loc)
145 rev)) 170 ;; If parent does not match, the best we can do without
146 ;; At this point, could fall back to: 171 ;; calling external commands is to use the dirstate rev.
147 ;; bzr version-info --custom --template='{revno} {revision_id}\n' 172 rev))
148 )))) 173 (external
174 (emacs-bzr-version-bzr dir)))))))
149 175
150;; We put version info into the executable in the form that `ident' uses. 176;; We put version info into the executable in the form that `ident' uses.
151(purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version)) 177(purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version))