From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dani Moncayo Newsgroups: gmane.emacs.devel Subject: Re: Setting the value of `emacs-bzr-version' also from a git checkout Date: Sun, 13 Oct 2013 22:49:53 +0200 Message-ID: References: <87a9is6g2a.fsf@igel.home> <87pprokewg.fsf@wanadoo.es> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1381697397 30726 80.91.229.3 (13 Oct 2013 20:49:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 13 Oct 2013 20:49:57 +0000 (UTC) Cc: =?ISO-8859-1?Q?=D3scar_Fuentes?= , Emacs development discussions To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 13 22:50:01 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VVSbx-0000D2-Gt for ged-emacs-devel@m.gmane.org; Sun, 13 Oct 2013 22:50:01 +0200 Original-Received: from localhost ([::1]:34518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VVSbx-0000y6-4o for ged-emacs-devel@m.gmane.org; Sun, 13 Oct 2013 16:50:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VVSbt-0000wB-QQ for emacs-devel@gnu.org; Sun, 13 Oct 2013 16:49:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VVSbs-0007M2-CR for emacs-devel@gnu.org; Sun, 13 Oct 2013 16:49:57 -0400 Original-Received: from mail-la0-x231.google.com ([2a00:1450:4010:c03::231]:63676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VVSbr-0007Lp-Vw for emacs-devel@gnu.org; Sun, 13 Oct 2013 16:49:56 -0400 Original-Received: by mail-la0-f49.google.com with SMTP id ev20so4978232lab.22 for ; Sun, 13 Oct 2013 13:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=3QTuJTx0e54UZRDWalFCbtgIjLiLkh0qBdqhzyMMmyM=; b=j0PSGUMf79ihjmnuf1v7tyx0wiUYF7FiC0PAJALQrKm2CyRfoiQkKfu6Fjrl9z0TGk IUL+j5BR3zGRYJtJU/hpgscdNmxRcQQJTHV1nfO0G/3UA1hmIr39gsSPIxzX153ykNRN RqJPjft6swe6bA64Dg+I+abSybhZkHls/I1q2elLgWBrlyNJX1+xplSDYo6FLUEymVGi j3h2nUdtsAG2wWiis8Csgq8Wm6i1D2WcEDY7y1e1zE95htLS5bOFUtf3uZbrw+EGWEC1 3VDbA/NxYKnRsyHeAP0P/Ge+xq81ErwWmeQjqjPnkdyXVzuZM/bT0/73bJnSlSAecpUE 9dfQ== X-Received: by 10.152.28.7 with SMTP id x7mr3779881lag.26.1381697394079; Sun, 13 Oct 2013 13:49:54 -0700 (PDT) Original-Received: by 10.114.176.231 with HTTP; Sun, 13 Oct 2013 13:49:53 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::231 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:164185 Archived-At: On Sat, Oct 12, 2013 at 12:22 PM, Dani Moncayo wrote: > On Wed, Oct 2, 2013 at 2:22 AM, Stefan Monnier 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