Provide branch information for both Emacs and Tramp (Bug#33328)

* doc/lispref/intro.texi (Version Info):
Document `emacs-repository-version' and `emacs-repository-branch'.

* etc/NEWS: Mention `emacs-repository-branch'.

* lisp/loadup.el: Initialize `emacs-repository-branch'.

* lisp/version.el (emacs-repository-branch): New variable.
(emacs-repository-branch-git, emacs-repository-get-branch):
New defuns.

* lisp/mail/emacsbug.el (report-emacs-bug):
Insert `emacs-repository-branch'.

* lisp/net/tramp.el (tramp-get-local-gid):
Use `group-name' if available.
(tramp-debug-message):
* lisp/net/tramp-cmds.el (tramp-bug): Report also
`tramp-repository-branch' and `tramp-repository-version'.

* lisp/net/trampver.el (tramp-repository-branch)
(tramp-repository-version): New defconst.
(tramp-repository-get-version): Remove.
This commit is contained in:
Michael Albinus 2018-11-10 16:03:12 +01:00
parent 55f3f21b39
commit a062fc4137
8 changed files with 75 additions and 19 deletions

View file

@ -530,6 +530,18 @@ directory (without cleaning). This is only of relevance when
developing Emacs.
@end defvar
@defvar emacs-repository-version
A string that gives the repository revision from which Emacs was
built. If Emacs was built outside revision control, the value is
@code{nil}.
@end defvar
@defvar emacs-repository-branch
A string that gives the repository branch from which Emacs was built.
In the most cases this is @code{"master"}. If Emacs was built outside
revision control, the value is @code{nil}.
@end defvar
@node Acknowledgments
@section Acknowledgments

View file

@ -225,6 +225,10 @@ In addition to nil or non-nil, the value can now be a predicate
function. Follow mode uses this to control scrolling of its windows
when the last screen line in a window is not fully visible.
+++
** New variable 'emacs-repository-branch'.
It reports the git branch from which Emacs was built.
* Editing Changes in Emacs 27.1

View file

@ -368,8 +368,8 @@ lost after dumping")))
(string-to-number
(substring name (length base) exelen))))
files)))
(setq emacs-repository-version (condition-case nil (emacs-repository-get-version)
(error nil)))
(setq emacs-repository-version (ignore-errors (emacs-repository-get-version))
emacs-repository-branch (ignore-errors (emacs-repository-get-branch)))
;; A constant, so we shouldn't change it with `setq'.
(defconst emacs-build-number
(if versions (1+ (apply 'max versions)) 1))))

View file

@ -307,6 +307,8 @@ usually do not have translators for other languages.\n\n")))
(if (stringp emacs-repository-version)
(insert "Repository revision: " emacs-repository-version "\n"))
(if (stringp emacs-repository-branch)
(insert "Repository branch: " emacs-repository-branch "\n"))
(if (fboundp 'x-server-vendor)
(condition-case nil
;; This is used not only for X11 but also W32 and others.

View file

@ -198,8 +198,9 @@ This includes password cache, file cache, connection cache, buffers."
;; In rare cases, it could contain the password. So we make it nil.
tramp-password-save-function)
(reporter-submit-bug-report
tramp-bug-report-address ; to-address
(format "tramp (%s)" tramp-version) ; package name and version
tramp-bug-report-address ; to-address
(format "tramp (%s %s/%s)" ; package name and version
tramp-version tramp-repository-branch tramp-repository-version)
(sort
(delq nil (mapcar
(lambda (x)

View file

@ -1609,10 +1609,13 @@ ARGUMENTS to actually emit the message (if applicable)."
";; Emacs: %s Tramp: %s -*- mode: outline; -*-"
emacs-version tramp-version))
(when (>= tramp-verbose 10)
(insert
(format
"\n;; Location: %s Git: %s"
(locate-library "tramp") (tramp-repository-get-version)))))
(let ((tramp-verbose 0))
(insert
(format
"\n;; Location: %s Git: %s/%s"
(locate-library "tramp")
(or tramp-repository-branch "")
(or tramp-repository-version ""))))))
(unless (bolp)
(insert "\n"))
;; Timestamp.

View file

@ -38,17 +38,23 @@
(defconst tramp-bug-report-address "tramp-devel@gnu.org"
"Email address to send bug reports to.")
(defun tramp-repository-get-version ()
"Try to return as a string the repository revision of the Tramp sources."
(let ((dir (locate-dominating-file (locate-library "tramp") ".git")))
(when dir
(with-temp-buffer
(let ((default-directory (file-name-as-directory dir)))
(and (zerop
(ignore-errors
(call-process "git" nil '(t nil) nil "rev-parse" "HEAD")))
(not (zerop (buffer-size)))
(replace-regexp-in-string "\n" "" (buffer-string))))))))
(defconst tramp-repository-branch
(ignore-errors
;; Suppress message from `emacs-repository-get-branch'.
(let ((inhibit-message t))
;; `emacs-repository-get-branch' has been introduced with Emacs 27.1.
(with-no-warnings
(emacs-repository-get-branch
(locate-dominating-file (locate-library "tramp") ".git")))))
"The repository branch of the Tramp sources.")
(defconst tramp-repository-version
(ignore-errors
;; Suppress message from `emacs-repository-get-version'.
(let ((inhibit-message t))
(emacs-repository-get-version
(locate-dominating-file (locate-library "tramp") ".git"))))
"The repository revision of the Tramp sources.")
;; Check for Emacs version.
(let ((x (if (not (string-lessp emacs-version "24.1"))

View file

@ -135,6 +135,34 @@ Optional argument DIR is a directory to use instead of `source-directory'.
Optional argument EXTERNAL is ignored."
(emacs-repository-version-git (or dir source-directory)))
(defvar emacs-repository-branch nil
"String giving the repository branch from which this Emacs was built.
Value is nil if Emacs was not built from a repository checkout,
or if we could not determine the branch.")
(defun emacs-repository-branch-git (dir)
"Ask git itself for the branch information for directory DIR."
(message "Waiting for git...")
(with-temp-buffer
(let ((default-directory (file-name-as-directory dir)))
(and (zerop
(with-demoted-errors "Error running git rev-parse --abbrev-ref: %S"
(call-process "git" nil '(t nil) nil
"rev-parse" "--abbrev-ref" "HEAD")))
(goto-char (point-min))
(buffer-substring (point) (line-end-position))))))
(defun emacs-repository-get-branch (&optional dir)
"Try to return as a string the repository branch of the Emacs sources.
The format of the returned string is dependent on the VCS in use.
Value is nil if the sources do not seem to be under version
control, or if we could not determine the branch. 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'."
(emacs-repository-branch-git (or dir source-directory)))
;; 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))
" $\n"))