aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2012-09-14 20:33:40 -0400
committerGlenn Morris2012-09-14 20:33:40 -0400
commitf40a97091f5ae5ba94d46e41dbc072e2e80c1730 (patch)
treed058beb7559f024221f9228e5abbcf794c3fc0ab
parentcb26b7f5728f68d118c2f1a6694f6cedbf28a0d9 (diff)
downloademacs-f40a97091f5ae5ba94d46e41dbc072e2e80c1730.tar.gz
emacs-f40a97091f5ae5ba94d46e41dbc072e2e80c1730.zip
Improve emacs-bzr-version for lightweight checkouts (bug#12441)
* lisp/version.el (emacs-bzr-version): Doc fix. (emacs-bzr-version-dirstate): New function. (emacs-bzr-get-version): For lightweight checkouts, if the parent is local try and check that it matches the branch. If not, just use dirstate information.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/version.el47
2 files changed, 44 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e27fa53e7b5..34c6d981481 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12012-09-15 Glenn Morris <rgm@gnu.org>
2
3 * version.el (emacs-bzr-version): Doc fix.
4 (emacs-bzr-version-dirstate): New function.
5 (emacs-bzr-get-version): For lightweight checkouts, if the parent
6 is local try and check that it matches the branch. If not, just
7 use dirstate information. (Bug#12441)
8
12012-09-14 Juri Linkov <juri@jurta.org> 92012-09-14 Juri Linkov <juri@jurta.org>
2 10
3 * dired-aux.el (dired-do-chmod): Use `eq' to detect empty input. 11 * dired-aux.el (dired-do-chmod): Use `eq' to detect empty input.
diff --git a/lisp/version.el b/lisp/version.el
index e63c51d0d26..8ef279828b1 100644
--- a/lisp/version.el
+++ b/lisp/version.el
@@ -87,23 +87,36 @@ to the system configuration; look at `system-configuration' instead."
87;; Set during dumping, this is a defvar so that it can be setq'd. 87;; Set during dumping, this is a defvar so that it can be setq'd.
88(defvar emacs-bzr-version nil 88(defvar emacs-bzr-version nil
89 "String giving the bzr revision from which this Emacs was built. 89 "String giving the bzr revision from which this Emacs was built.
90Value is the bzr revision number and a revision ID separated by a blank. 90The format is: [revno] revision_id, where revno may be absent.
91Value is nil if Emacs was not built from a bzr checkout, or if we could 91Value is nil if Emacs was not built from a bzr checkout, or if we could
92not determine the revision.") 92not determine the revision.")
93 93
94(defun emacs-bzr-version-dirstate (dir)
95 "Try to return as a string the bzr revision ID of directory DIR.
96This uses the dirstate file's parent revision entry.
97Returns nil if unable to find this information."
98 (let ((file (expand-file-name ".bzr/checkout/dirstate" dir)))
99 (when (file-readable-p file)
100 (with-temp-buffer
101 (insert-file-contents file)
102 (and (looking-at "#bazaar dirstate flat format 3")
103 (forward-line 3)
104 (looking-at "[0-9]+\0\\([^\0\n]+\\)\0")
105 (match-string 1))))))
106
94(defun emacs-bzr-get-version (&optional dir) 107(defun emacs-bzr-get-version (&optional dir)
95 "Try to return as a string the bzr revision number of the Emacs sources. 108 "Try to return as a string the bzr revision of the Emacs sources.
96Value is the bzr revision number and a revision ID separated by a blank. 109The format is: [revno] revision_id, where revno may be absent.
97Value is nil if the sources do not seem to be under bzr, or if we could 110Value is nil if the sources do not seem to be under bzr, or if we could
98not determine the revision. Note that this reports on the current state 111not determine the revision. Note that this reports on the current state
99of the sources, which may not correspond to the running Emacs. 112of the sources, which may not correspond to the running Emacs.
100 113
101Optional argument DIR is a directory to use instead of `source-directory'." 114Optional argument DIR is a directory to use instead of `source-directory'."
102 (or dir (setq dir source-directory)) 115 (or dir (setq dir source-directory))
103 (when (file-directory-p (setq dir (expand-file-name ".bzr/branch" dir))) 116 (when (file-directory-p dir)
104 (let (file loc) 117 (let (file loc rev)
105 (cond ((file-readable-p 118 (cond ((file-readable-p
106 (setq file (expand-file-name "last-revision" dir))) 119 (setq file (expand-file-name ".bzr/branch/last-revision" dir)))
107 (with-temp-buffer 120 (with-temp-buffer
108 (insert-file-contents file) 121 (insert-file-contents file)
109 (goto-char (point-max)) 122 (goto-char (point-max))
@@ -112,14 +125,26 @@ Optional argument DIR is a directory to use instead of `source-directory'."
112 (buffer-string))) 125 (buffer-string)))
113 ;; OK, no last-revision. Is it a lightweight checkout? 126 ;; OK, no last-revision. Is it a lightweight checkout?
114 ((file-readable-p 127 ((file-readable-p
115 (setq file (expand-file-name "location" dir))) 128 (setq file (expand-file-name ".bzr/branch/location" dir)))
116 ;; If the parent branch is local, try looking there for the revid. 129 (setq rev (emacs-bzr-version-dirstate dir))
117 (if (setq loc (with-temp-buffer 130 ;; If the parent branch is local, try looking there for the rev.
131 ;; Note: there is no guarantee that the parent branch's rev
132 ;; corresponds to this branch. This branch could have
133 ;; been made with a specific -r revno argument, or the
134 ;; parent could have been updated since this branch was created.
135 ;; To try and detect this, we check the dirstate revids
136 ;; to see if they match.
137 (if (and (setq loc (with-temp-buffer
118 (insert-file-contents file) 138 (insert-file-contents file)
119 (if (looking-at "file://\\(.*\\)") 139 (if (looking-at "file://\\(.*\\)")
120 (match-string 1)))) 140 (match-string 1))))
121 (emacs-bzr-get-version loc))) 141 (equal rev (emacs-bzr-version-dirstate loc)))
122 ;; Could fall back to eg `bzr testament' at this point. 142 (emacs-bzr-get-version loc)
143 ;; If parent does not match, the best we can do without
144 ;; calling external commands is to use the dirstate rev.
145 rev))
146 ;; At this point, could fall back to:
147 ;; bzr version-info --custom --template='{revno} {revision_id}\n'
123 )))) 148 ))))
124 149
125;; We put version info into the executable in the form that `ident' uses. 150;; We put version info into the executable in the form that `ident' uses.