From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.bugs Subject: bug#21930: emacs-repository-get-version fails on linked worktrees Date: Mon, 16 Nov 2015 04:46:52 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c317e8ebde3b0524a044ca X-Trace: ger.gmane.org 1447705050 22340 80.91.229.3 (16 Nov 2015 20:17:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Nov 2015 20:17:30 +0000 (UTC) To: 21930@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Nov 16 21:17:22 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1ZyQDJ-0003JN-Nh for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Nov 2015 21:17:21 +0100 Original-Received: from localhost ([::1]:48730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyQDJ-0007xx-7R for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Nov 2015 15:17:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyAlw-0003Lv-AX for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2015 22:48:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyAlu-00045R-Go for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2015 22:48:04 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49694) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyAlu-00045C-E8 for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2015 22:48:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZyAlu-0006Jo-7B for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2015 22:48:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juanma Barranquero Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Nov 2015 03:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21930 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: Bug-Gnu-Emacs Original-Received: via spool by submit@debbugs.gnu.org id=B.144764568024278 (code B ref -1); Mon, 16 Nov 2015 03:48:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Nov 2015 03:48:00 +0000 Original-Received: from localhost ([127.0.0.1]:39402 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZyAls-0006JW-1S for submit@debbugs.gnu.org; Sun, 15 Nov 2015 22:48:00 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:48190) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZyAlX-0006J5-5k for submit@debbugs.gnu.org; Sun, 15 Nov 2015 22:47:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyAlV-0003tk-GT for submit@debbugs.gnu.org; Sun, 15 Nov 2015 22:47:38 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:52083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyAlV-0003tf-Dw for submit@debbugs.gnu.org; Sun, 15 Nov 2015 22:47:37 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyAlT-00034i-Rk for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2015 22:47:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyAlS-0003tM-Eg for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2015 22:47:35 -0500 Original-Received: from mail-lb0-x234.google.com ([2a00:1450:4010:c04::234]:36856) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyAlS-0003tI-3Y for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2015 22:47:34 -0500 Original-Received: by lbblt2 with SMTP id lt2so81421243lbb.3 for ; Sun, 15 Nov 2015 19:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=DSLHiZrAip4G6l4vHF7uf6QEM5z1kBQ8Xx3C3FKl9pk=; b=0KeSwBm3RsInLGue4MscKHjIGb6HfatGcnSRqq+ng6YjyT95XCYNJQPQN3+it/Ac7T EokOhcY13kiBEDoMoqi0zXHlavjp9uDm05sd914PcG5uGg6E5VgKDRrB00mDVQ09tKMu fT5hQei+hwOBxCHHcajTsTAOtBMmff+4WG6uIUheGWdaTuEmuSKpfBiYvbR/DE1av1uZ cwXMyFNZfZvi0Z/zVhoQFUysBxUHfH7szPJwZ/HJkQ1PWqJUGG9qUjBjN8eurIAHZJvP eEx9woZJ5EvSrLljmzJZzJahUp6sw38TPgFZXfB2coBslzUSg7u0j5I6+yhRDb4fYsBf 5Qhw== X-Received: by 10.112.234.163 with SMTP id uf3mr16080874lbc.15.1447645653226; Sun, 15 Nov 2015 19:47:33 -0800 (PST) Original-Received: by 10.25.21.198 with HTTP; Sun, 15 Nov 2015 19:46:52 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:108761 Archived-At: --001a11c317e8ebde3b0524a044ca Content-Type: text/plain; charset=UTF-8 Package: emacs Version: 25.0.50 Severity: minor When run inside a linked worktree (created with "git worktree add ..."), emacs-repository-get-version needs to ask the VCS to find the repository version, which doesn't work during dumping. I'd like to apply this patch to the release branch. diff --git i/lisp/version.el w/lisp/version.el index 43103fd..4207cb4 100644 --- i/lisp/version.el +++ w/lisp/version.el @@ -114,15 +114,15 @@ emacs-repository-version-git (match-string 0))))) -(defun emacs-repository--version-git-1 (file) +(defun emacs-repository--version-git-1 (file dir) "Internal subroutine of `emacs-repository-get-version'." (when (file-readable-p file) - (erase-buffer) - (insert-file-contents file) - (cond ((looking-at "[0-9a-fA-F]\\{40\\}") - (match-string 0)) - ((looking-at "ref: \\(.*\\)") - (emacs-repository--version-git-1 - (expand-file-name (match-string 1) - (file-name-directory file))))))) + (with-temp-buffer + (insert-file-contents file) + (cond ((looking-at "[0-9a-fA-F]\\{40\\}") + (match-string 0)) + ((looking-at "ref: \\(.*\\)") + (emacs-repository--version-git-1 + (expand-file-name (match-string 1) dir) + dir)))))) (defun emacs-repository-get-version (&optional dir external) @@ -139,18 +139,36 @@ emacs-repository-get-version the VCS if we cannot find any information ourselves." (or dir (setq dir source-directory)) - (when (file-directory-p (expand-file-name ".git" dir)) - (if external - (emacs-repository-version-git dir) - (or (let ((files '("HEAD" "refs/heads/master")) - file rev) - (with-temp-buffer - (while (and (not rev) - (setq file (car files))) - (setq file (expand-file-name (format ".git/%s" file) dir) - files (cdr files) - rev (emacs-repository--version-git-1 file)))) - rev) - ;; AFAICS this doesn't work during dumping (bug#20799). - (emacs-repository-version-git dir))))) + (let* ((base-dir (expand-file-name ".git" dir)) + (in-main-worktree (file-directory-p base-dir)) + (in-linked-worktree nil) + sub-dir) + ;; If the sources are in a linked worktree, .git is a file that points to + ;; the location of the main worktree and the repo's administrative files. + (when (and (not in-main-worktree) + (file-regular-p base-dir) + (file-readable-p base-dir)) + (with-temp-buffer + (insert-file-contents base-dir) + (when (looking-at "gitdir: \\(.*\.git\\)\\(.*\\)$") + (setq base-dir (match-string 1) + sub-dir (concat base-dir (match-string 2)) + in-linked-worktree t)))) + ;; We've found a worktree, either main or linked. + (when (or in-main-worktree in-linked-worktree) + (if external + (emacs-repository-version-git dir) + (or (if in-linked-worktree + (emacs-repository--version-git-1 + (expand-file-name "HEAD" sub-dir) base-dir) + (let ((files '("HEAD" "refs/heads/master")) + file rev) + (while (and (not rev) + (setq file (car files))) + (setq file (expand-file-name file base-dir) + files (cdr files) + rev (emacs-repository--version-git-1 file base-dir))) + rev)) + ;; AFAICS this doesn't work during dumping (bug#20799). + (emacs-repository-version-git dir)))))) ;; We put version info into the executable in the form that `ident' uses. --001a11c317e8ebde3b0524a044ca Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Package: emacs
Version: 25.0.50
Severity: mi= nor

When run inside a linked worktree (created wit= h "git worktree add ..."), emacs-repository-get-version needs to = ask the VCS to find the repository version, which doesn't work during d= umping.

I'd like to apply this patch to the re= lease branch.


diff --git i/lis= p/version.el w/lisp/version.el
index 43103fd..4207cb4 100644
--- i/lisp/version.el
+++ w/lisp/version.el
@@ -1= 14,15 +114,15 @@ emacs-repository-version-git
=C2=A0 =C2=A0 (match-string 0)))))
<= div>=C2=A0
-(defun emacs-repository--version-git-1 (file)
+(defun emacs-repository--version-git-1 (file dir)
=C2=A0 =C2= =A0"Internal subroutine of `emacs-repository-get-version'."
=C2=A0 =C2=A0(when (file-readable-p file)
- =C2=A0 =C2= =A0(erase-buffer)
- =C2=A0 =C2=A0(insert-file-contents file)
- =C2=A0 =C2=A0(cond ((looking-at "[0-9a-fA-F]\\{40\\}")
- =C2=A0 (match-= string 0))
- = =C2=A0((looking-at "ref: \\(.*\\)")
- =C2=A0 (emacs-repository--version-git-1
- =C2=A0 =C2=A0= (expand-file-name (match-string 1)
- =C2=A0 =C2=A0 =C2=A0(file-name-directory file)))))= ))
+ =C2=A0 =C2=A0(with-temp-buffer
+ =C2=A0 =C2=A0 =C2= =A0(insert-file-contents file)
+ =C2=A0 =C2=A0 =C2=A0(cond ((look= ing-at "[0-9a-fA-F]\\{40\\}")
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 (match-string 0))
+ =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0((looking-at "ref: \\(.*\\)")
+ =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (emacs-repository--version-git-1
<= div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(expand-file-name (ma= tch-string 1) dir)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0dir))))))
=C2=A0
=C2=A0(defun emacs-repository-ge= t-version (&optional dir external)
@@ -139,18 +139,36 @@ emac= s-repository-get-version
=C2=A0the VCS if we cannot find any info= rmation ourselves."
=C2=A0 =C2=A0(or dir (setq dir source-di= rectory))
- =C2=A0(when (file-directory-p (expand-file-name "= ;.git" dir))
- =C2=A0 =C2=A0(if external
- (emacs-repository-version-git di= r)
- =C2=A0 =C2=A0 =C2=A0(or (let ((files '("HEAD" = "refs/heads/master"))
- file rev)
- =C2=A0 =C2=A0(with-temp-buffer
- =C2=A0 =C2=A0 =C2=A0(while (and (not r= ev)
- =C2=A0= (setq file (car files)))
- (setq file (expand-file-name (format ".git/%s" file)= dir)
- =C2= =A0 =C2=A0 =C2=A0files (cdr files)
- =C2=A0 =C2=A0 =C2=A0rev (emacs-repository--version-= git-1 file))))
- =C2=A0 =C2=A0rev)
-= =C2=A0;; AFAICS this doesn't work during dumping (bug#20799).<= /div>
- =C2=A0(emacs= -repository-version-git dir)))))
+ =C2=A0(let* ((base-dir (expand= -file-name ".git" dir))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 (= in-main-worktree (file-directory-p base-dir))
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (in-linked-worktree nil)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0= sub-dir)
+ =C2=A0 =C2=A0;; If the sources are in a linked worktr= ee, .git is a file that points to
+ =C2=A0 =C2=A0;; the location = of the main worktree and the repo's administrative files.
+ = =C2=A0 =C2=A0(when (and (not in-main-worktree)
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (file-regular-p base-dir)
+ = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (file-readable-p base-dir)= )
+ =C2=A0 =C2=A0 =C2=A0(with-temp-buffer
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0(insert-file-contents base-dir)
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0(when (looking-at "gitdir: \\(.*\.git\\)\\(.*\\)$")<= /div>
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq base-dir (match-string = 1)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sub-d= ir (concat base-dir (match-string 2))
+ =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0in-linked-worktree t))))
+ =C2=A0 = =C2=A0;; We've found a worktree, either main or linked.
+ =C2= =A0 =C2=A0(when (or in-main-worktree in-linked-worktree)
+ =C2=A0= =C2=A0 =C2=A0(if external
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(e= macs-repository-version-git dir)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0(or= (if in-linked-worktree
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(emacs-repository--version-git-1
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (expand-file-name "HEAD&quo= t; sub-dir) base-dir)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0(let ((files '("HEAD" "refs/heads/master"))<= /div>
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0file rev)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(while (and (not rev)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq fil= e (car files)))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(setq file (expand-file-name file base-dir)
+ = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0files (cdr files)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rev (emacs-repository--vers= ion-git-1 file base-dir)))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0rev))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0;; AFAICS this doesn't work during dumping (bug#20799).
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(emacs-repository-version-git d= ir))))))
=C2=A0
=C2=A0;; We put version info into the e= xecutable in the form that `ident' uses.

--001a11c317e8ebde3b0524a044ca--