emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r110040: Add option to ask bzr itself


From: Glenn Morris
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110040: Add option to ask bzr itself for the emacs bzr revision
Date: Sat, 15 Sep 2012 13:00:45 -0700
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110040
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Sat 2012-09-15 13:00:45 -0700
message:
  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.
modified:
  lisp/ChangeLog
  lisp/version.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-09-15 01:11:52 +0000
+++ b/lisp/ChangeLog    2012-09-15 20:00:45 +0000
@@ -1,5 +1,8 @@
 2012-09-15  Glenn Morris  <address@hidden>
 
+       * 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

=== modified file 'lisp/version.el'
--- a/lisp/version.el   2012-09-15 00:45:00 +0000
+++ b/lisp/version.el   2012-09-15 20:00:45 +0000
@@ -104,48 +104,74 @@
              (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))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]