From: Juanma Barranquero <lekktu@gmail.com>
To: 21930@debbugs.gnu.org
Subject: bug#21930: emacs-repository-get-version fails on linked worktrees
Date: Mon, 16 Nov 2015 04:46:52 +0100 [thread overview]
Message-ID: <CAAeL0SReDg3RFJdfUAUmy7BkzWfNXw6Ds=iKUnocvdHQvvtvCg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 3608 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 5837 bytes --]
next reply other threads:[~2015-11-16 3:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-16 3:46 Juanma Barranquero [this message]
2015-11-16 23:01 ` bug#21930: emacs-repository-get-version fails on linked worktrees Stephen Leake
2015-11-17 0:20 ` Juanma Barranquero
2015-11-19 18:17 ` Juanma Barranquero
2015-11-19 19:03 ` John Wiegley
2015-11-20 0:40 ` Juanma Barranquero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAeL0SReDg3RFJdfUAUmy7BkzWfNXw6Ds=iKUnocvdHQvvtvCg@mail.gmail.com' \
--to=lekktu@gmail.com \
--cc=21930@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).