emacs-devel
[Top][All Lists]
Advanced

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

Re: Setting the value of `emacs-bzr-version' also from a git checkout


From: Dani Moncayo
Subject: Re: Setting the value of `emacs-bzr-version' also from a git checkout
Date: Sun, 13 Oct 2013 22:49:53 +0200

On Sat, Oct 12, 2013 at 12:22 PM, Dani Moncayo <address@hidden> wrote:
> On Wed, Oct 2, 2013 at 2:22 AM, Stefan Monnier <address@hidden> wrote:
>>> Therefore, what I'd like is that "emacs-bzr-version" gave the exact
>>> same string from an Emacs built from either bzr-trunk or git-master.
>>
>> Patch welcome,
>
> The below patch works for me.

Actually that patch was lacking a change in loadup.el:  The call to
`emacs-bzr-get-version' now has to pass `t' in the EXTERNAL argument,
to open the possibility of asking the external version control program
(bzr or git) if the "internal" method fails.  (I've not implemented an
"internal" method for the git case - only the "external" one.).

So here is the new patch (tested in a real bootstrap from a git repo),
which also updates the docstring of `emacs-bzr-get-version'
accordingly:

diff --git a/lisp/loadup.el b/lisp/loadup.el
index 27148ce..f92d6a5 100644
--- a/lisp/loadup.el
+++ b/lisp/loadup.el
@@ -299,7 +299,7 @@
  (string-to-number
  (substring name (length base) exelen))))
      files)))
-      (setq emacs-bzr-version (condition-case nil (emacs-bzr-get-version)
+      (setq emacs-bzr-version (condition-case nil (emacs-bzr-get-version nil t)
                               (error nil)))
       ;; `emacs-version' is a constant, so we shouldn't change it with `setq'.
       (defconst emacs-version
diff --git a/lisp/version.el b/lisp/version.el
index 9667456..dfeb5f7 100644
--- a/lisp/version.el
+++ b/lisp/version.el
@@ -126,20 +126,41 @@ Returns nil if unable to find this information."
                        "dir"))
         (buffer-string))))

+(defun emacs-bzr-version-git (dir)
+  "Ask git for the bzr version information for directory DIR.
+The official git repository of GNU Emacs stores this information
+as notes in each revision"
+  (message "Waiting for git...")
+  (with-temp-buffer
+    (if (zerop
+         (call-process "git" nil '(t nil) nil
+       (concat "--git-dir=" dir ".git")
+       "log"
+                       "-1"
+                       "--pretty=format:%N"))
+ (replace-regexp-in-string "\n" "" (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 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."
+Value is nil 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'.  This directory should correspond to either a
+bzr branch or a git mirror of a bzr branch.  In the second case,
+the bzr revision string should be stored as notes in each
+revision.
+
+Optional argument EXTERNAL non-nil means to maybe ask the
+external version control program (`bzr' or `git').  If `force',
+always ask the external program.  Otherwise only ask the external
+program if we cannot find any information ourselves."
   (or dir (setq dir source-directory))
-  (when (file-directory-p (expand-file-name ".bzr/branch" dir))
-    (if (eq external 'force)
+  (cond ((file-directory-p (expand-file-name ".bzr/branch" dir))
+ ((if (eq external 'force)
       (emacs-bzr-version-bzr dir)
     (let (file loc rev)
       (cond ((file-readable-p
@@ -172,6 +193,9 @@ Otherwise only ask bzr if we cannot find any
information ourselves."
        rev))
     (external
      (emacs-bzr-version-bzr dir)))))))
+ ((file-directory-p (expand-file-name ".git" dir))
+ (if external
+     (emacs-bzr-version-git 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))



--
Dani Moncayo



reply via email to

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