diff options
| author | Glenn Morris | 2015-06-13 17:17:47 -0700 |
|---|---|---|
| committer | Glenn Morris | 2015-06-13 17:17:47 -0700 |
| commit | 86076e65524933f7d1c9812cec292fdc7d5dc60c (patch) | |
| tree | 39ec8564b8810538f47dec5058d65f8404c823d9 | |
| parent | e5ab4d92ec404531b5fa9d8fcbce5979a46b220a (diff) | |
| download | emacs-86076e65524933f7d1c9812cec292fdc7d5dc60c.tar.gz emacs-86076e65524933f7d1c9812cec292fdc7d5dc60c.zip | |
Tweaks for getting repository version; a bit more like it was for bzr.
* lisp/version.el (emacs-repository-version-git)
(emacs-repository--version-git-1): New functions,
split from emacs-repository-get-version.
(emacs-repository-get-version): Make the second argument meaningful.
| -rw-r--r-- | lisp/version.el | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/lisp/version.el b/lisp/version.el index 5776e6d7b26..112611d1083 100644 --- a/lisp/version.el +++ b/lisp/version.el | |||
| @@ -100,7 +100,30 @@ or if we could not determine the revision.") | |||
| 100 | (define-obsolete-function-alias 'emacs-bzr-get-version | 100 | (define-obsolete-function-alias 'emacs-bzr-get-version |
| 101 | 'emacs-repository-get-version "24.4") | 101 | 'emacs-repository-get-version "24.4") |
| 102 | 102 | ||
| 103 | (defun emacs-repository-get-version (&optional dir _unused) | 103 | (defun emacs-repository-version-git (dir) |
| 104 | "Ask git itself for the version information for directory DIR." | ||
| 105 | (message "Waiting for git...") | ||
| 106 | (with-temp-buffer | ||
| 107 | (let ((default-directory (file-name-as-directory dir))) | ||
| 108 | (and (eq 0 | ||
| 109 | (ignore-errors | ||
| 110 | (call-process "git" nil '(t nil) nil "rev-parse" "HEAD"))) | ||
| 111 | (not (zerop (buffer-size))) | ||
| 112 | (replace-regexp-in-string "\n" "" (buffer-string)))))) | ||
| 113 | |||
| 114 | (defun emacs-repository--version-git-1 (file) | ||
| 115 | "Internal subroutine of `emacs-repository-get-version'." | ||
| 116 | (when (file-readable-p file) | ||
| 117 | (erase-buffer) | ||
| 118 | (insert-file-contents file) | ||
| 119 | (cond ((looking-at "[0-9a-fA-F]\\{40\\}") | ||
| 120 | (match-string 0)) | ||
| 121 | ((looking-at "ref: \\(.*\\)") | ||
| 122 | (emacs-repository--version-git-1 | ||
| 123 | (expand-file-name (match-string 1) | ||
| 124 | (file-name-directory file))))))) | ||
| 125 | |||
| 126 | (defun emacs-repository-get-version (&optional dir external) | ||
| 104 | "Try to return as a string the repository revision of the Emacs sources. | 127 | "Try to return as a string the repository revision of the Emacs sources. |
| 105 | The format of the returned string is dependent on the VCS in use. | 128 | The format of the returned string is dependent on the VCS in use. |
| 106 | Value is nil if the sources do not seem to be under version | 129 | Value is nil if the sources do not seem to be under version |
| @@ -108,35 +131,25 @@ control, or if we could not determine the revision. Note that | |||
| 108 | this reports on the current state of the sources, which may not | 131 | this reports on the current state of the sources, which may not |
| 109 | correspond to the running Emacs. | 132 | correspond to the running Emacs. |
| 110 | 133 | ||
| 111 | Optional argument DIR is a directory to use instead of `source-directory'." | 134 | Optional argument DIR is a directory to use instead of `source-directory'. |
| 135 | Optional argument EXTERNAL non-nil means to just ask the VCS itself, | ||
| 136 | if the sources appear to be under version control. Otherwise only ask | ||
| 137 | the VCS if we cannot find any information ourselves." | ||
| 112 | (or dir (setq dir source-directory)) | 138 | (or dir (setq dir source-directory)) |
| 113 | (let ((file (expand-file-name ".git/HEAD" dir))) | 139 | (when (file-directory-p (expand-file-name ".git" dir)) |
| 114 | (or (if (file-readable-p file) | 140 | (if external |
| 141 | (emacs-repository-version-git dir) | ||
| 142 | (or (let ((files '("HEAD" "refs/heads/master")) | ||
| 143 | file rev) | ||
| 115 | (with-temp-buffer | 144 | (with-temp-buffer |
| 116 | (insert-file-contents file) | 145 | (while (and (not rev) |
| 117 | (cond ((looking-at "[0-9a-fA-F]\\{40\\}") | 146 | (setq file (car files))) |
| 118 | (match-string 0)) | 147 | (setq file (expand-file-name (format ".git/%s" file) dir) |
| 119 | ((looking-at "ref: \\(.*\\)") | 148 | files (cdr files) |
| 120 | (when (file-readable-p | 149 | rev (emacs-repository--version-git-1 file)))) |
| 121 | (setq file | 150 | rev) |
| 122 | (expand-file-name (format ".git/%s" | 151 | ;; AFAICS this doesn't work during dumping (bug#20799). |
| 123 | (match-string 1)) | 152 | (emacs-repository-version-git dir))))) |
| 124 | dir))) | ||
| 125 | (erase-buffer) | ||
| 126 | (insert-file-contents file) | ||
| 127 | (if (looking-at "[0-9a-fA-F]\\{40\\}") | ||
| 128 | (match-string 0))))))) | ||
| 129 | (when (file-accessible-directory-p (expand-file-name ".git" dir)) | ||
| 130 | (message "Waiting for git...") | ||
| 131 | (with-temp-buffer | ||
| 132 | (let ((default-directory (file-name-as-directory dir))) | ||
| 133 | (and (eq 0 | ||
| 134 | (condition-case nil | ||
| 135 | (call-process "git" nil '(t nil) nil "rev-parse" | ||
| 136 | "HEAD") | ||
| 137 | (error nil))) | ||
| 138 | (not (zerop (buffer-size))) | ||
| 139 | (replace-regexp-in-string "\n" "" (buffer-string))))))))) | ||
| 140 | 153 | ||
| 141 | ;; We put version info into the executable in the form that `ident' uses. | 154 | ;; We put version info into the executable in the form that `ident' uses. |
| 142 | (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version)) | 155 | (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version)) |