]> git.eshelyaron.com Git - emacs.git/commitdiff
Add option to ask bzr itself for the emacs bzr revision
authorGlenn Morris <rgm@gnu.org>
Sat, 15 Sep 2012 20:00:45 +0000 (13:00 -0700)
committerGlenn Morris <rgm@gnu.org>
Sat, 15 Sep 2012 20:00:45 +0000 (13:00 -0700)
* lisp/version.el (emacs-bzr-version-bzr): New function.
(emacs-bzr-get-version): Add optional EXTERNAL argument.

lisp/ChangeLog
lisp/version.el

index c9aa7e99356f7c030bcf00e20c78475523aefefb..b436d9e364e0f7f5ddef644f8da2e767ce0df50d 100644 (file)
@@ -1,5 +1,8 @@
 2012-09-15  Glenn Morris  <rgm@gnu.org>
 
+       * version.el (emacs-bzr-version-bzr): New function.
+       (emacs-bzr-get-version): Add optional EXTERNAL argument.
+
        * vc/vc-bzr.el (vc-bzr-working-revision): For lightweight local
        checkouts, check the parent dirstate matches the branch.
        Add "--tree" to "bzr revno" arguments.  Don't try to shorten the
index 47476cb268a3fb57f82ac8e7f38a3bc2846f50af..1fb3828e15d225e9f23ab2585f20fa0e5b67cd29 100644 (file)
@@ -104,48 +104,74 @@ Returns nil if unable to find this information."
              (looking-at "[0-9]+\0\\([^\0\n]+\\)\0")
              (match-string 1))))))
 
-(defun emacs-bzr-get-version (&optional dir)
+(defun emacs-bzr-version-bzr (dir)
+  "Ask bzr itself for the version information for directory DIR."
+  ;; Comments on `bzr version-info':
+  ;; i) Unknown files also cause clean != 1.
+  ;; ii) It can be slow, contacting the upstream repo to get the
+  ;; branch nick if one is not set locally, even with a custom
+  ;; template that is not asking for the nick (as used here).  You'd
+  ;; think the latter part would be trivial to fix:
+  ;; https://bugs.launchpad.net/bzr/+bug/882541/comments/3
+  ;; https://bugs.launchpad.net/bzr/+bug/629150
+  ;; You can set the nick locally with `bzr nick ...', which speeds
+  ;; things up enormously.  `bzr revno' does not have this issue, but
+  ;; has no way to print the revision_id AFAICS.
+  (message "Waiting for bzr...")
+  (with-temp-buffer
+    (if (zerop
+         (call-process "bzr" nil '(t nil) nil "version-info"
+                       "--custom"
+                       "--template={revno} {revision_id} (clean = {clean})"
+                       "dir"))
+        (buffer-string))))
+
+(defun emacs-bzr-get-version (&optional dir external)
   "Try to return as a string the bzr revision of the Emacs sources.
 The format is: [revno] revision_id, where revno may be absent.
 Value is 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.
 
-Optional argument DIR is a directory to use instead of `source-directory'."
+Optional argument DIR is a directory to use instead of `source-directory'.
+Optional argument EXTERNAL non-nil means to maybe ask `bzr' itself,
+if the sources appear to be under bzr.  If `force', always ask bzr.
+Otherwise only ask bzr if we cannot find any information ourselves."
   (or dir (setq dir source-directory))
   (when (file-directory-p (expand-file-name ".bzr/branch" dir))
-    (let (file loc rev)
-      (cond ((file-readable-p
-              (setq file (expand-file-name ".bzr/branch/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 ".bzr/branch/location" dir)))
-             (setq rev (emacs-bzr-version-dirstate dir))
-             ;; If the parent branch is local, try looking there for the rev.
-             ;; Note: there is no guarantee that the parent branch's rev
-             ;; corresponds to this branch.  This branch could have
-             ;; been made with a specific -r revno argument, or the
-             ;; parent could have been updated since this branch was created.
-             ;; To try and detect this, we check the dirstate revids
-             ;; to see if they match.
-             (if (and (setq loc (with-temp-buffer
-                             (insert-file-contents file)
-                             (if (looking-at "file://\\(.*\\)")
-                                 (match-string 1))))
-                      (equal rev (emacs-bzr-version-dirstate loc)))
-                 (emacs-bzr-get-version loc)
-               ;; If parent does not match, the best we can do without
-               ;; calling external commands is to use the dirstate rev.
-               rev))
-            ;; At this point, could fall back to:
-            ;; bzr version-info --custom --template='{revno} {revision_id}\n'
-            ))))
+    (if (eq external 'force)
+        (emacs-bzr-version-bzr dir)
+      (let (file loc rev)
+        (cond ((file-readable-p
+                (setq file (expand-file-name ".bzr/branch/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 ".bzr/branch/location" dir)))
+               (setq rev (emacs-bzr-version-dirstate dir))
+               ;; If the parent branch is local, try looking there for the rev.
+               ;; Note: there is no guarantee that the parent branch's rev
+               ;; corresponds to this branch.  This branch could have
+               ;; been made with a specific -r revno argument, or the
+               ;; parent could have been updated since this branch was created.
+               ;; To try and detect this, we check the dirstate revids
+               ;; to see if they match.
+               (if (and (setq loc (with-temp-buffer
+                                    (insert-file-contents file)
+                                    (if (looking-at "file://\\(.*\\)")
+                                        (match-string 1))))
+                        (equal rev (emacs-bzr-version-dirstate loc)))
+                   (emacs-bzr-get-version loc)
+                 ;; If parent does not match, the best we can do without
+                 ;; calling external commands is to use the dirstate rev.
+                 rev))
+              (external
+               (emacs-bzr-version-bzr dir)))))))
 
 ;; We put version info into the executable in the form that `ident' uses.
 (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version))