Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 regels
7.0 KiB

4 jaren geleden
  1. ;;; magit-reflog.el --- inspect ref history -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2010-2019 The Magit Project Contributors
  3. ;;
  4. ;; You should have received a copy of the AUTHORS.md file which
  5. ;; lists all contributors. If not, see http://magit.vc/authors.
  6. ;; Author: Jonas Bernoulli <jonas@bernoul.li>
  7. ;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
  8. ;; Magit is free software; you can redistribute it and/or modify it
  9. ;; under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; Magit is distributed in the hope that it will be useful, but WITHOUT
  14. ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  16. ;; License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with Magit. If not, see http://www.gnu.org/licenses.
  20. ;;; Commentary:
  21. ;; This library implements support for looking at Git reflogs.
  22. ;;; Code:
  23. (require 'magit-core)
  24. (require 'magit-log)
  25. (eval-when-compile
  26. (require 'subr-x))
  27. ;;; Options
  28. (defcustom magit-reflog-limit 256
  29. "Maximal number of entries initially shown in reflog buffers.
  30. The limit in the current buffer can be changed using \"+\"
  31. and \"-\"."
  32. :package-version '(magit . "2.91.0")
  33. :group 'magit-git-arguments
  34. :type 'number)
  35. (defcustom magit-reflog-margin
  36. (list (nth 0 magit-log-margin)
  37. (nth 1 magit-log-margin)
  38. 'magit-log-margin-width nil
  39. (nth 4 magit-log-margin))
  40. "Format of the margin in `magit-reflog-mode' buffers.
  41. The value has the form (INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH).
  42. If INIT is non-nil, then the margin is shown initially.
  43. STYLE controls how to format the committer date. It can be one
  44. of `age' (to show the age of the commit), `age-abbreviated' (to
  45. abbreviate the time unit to a character), or a string (suitable
  46. for `format-time-string') to show the actual date.
  47. WIDTH controls the width of the margin. This exists for forward
  48. compatibility and currently the value should not be changed.
  49. AUTHOR controls whether the name of the author is also shown by
  50. default.
  51. AUTHOR-WIDTH has to be an integer. When the name of the author
  52. is shown, then this specifies how much space is used to do so."
  53. :package-version '(magit . "2.9.0")
  54. :group 'magit-log
  55. :group 'magit-margin
  56. :type magit-log-margin--custom-type
  57. :initialize 'magit-custom-initialize-reset
  58. :set-after '(magit-log-margin)
  59. :set (apply-partially #'magit-margin-set-variable 'magit-reflog-mode))
  60. ;;; Faces
  61. (defface magit-reflog-commit '((t :foreground "green"))
  62. "Face for commit commands in reflogs."
  63. :group 'magit-faces)
  64. (defface magit-reflog-amend '((t :foreground "magenta"))
  65. "Face for amend commands in reflogs."
  66. :group 'magit-faces)
  67. (defface magit-reflog-merge '((t :foreground "green"))
  68. "Face for merge, checkout and branch commands in reflogs."
  69. :group 'magit-faces)
  70. (defface magit-reflog-checkout '((t :foreground "blue"))
  71. "Face for checkout commands in reflogs."
  72. :group 'magit-faces)
  73. (defface magit-reflog-reset '((t :foreground "red"))
  74. "Face for reset commands in reflogs."
  75. :group 'magit-faces)
  76. (defface magit-reflog-rebase '((t :foreground "magenta"))
  77. "Face for rebase commands in reflogs."
  78. :group 'magit-faces)
  79. (defface magit-reflog-cherry-pick '((t :foreground "green"))
  80. "Face for cherry-pick commands in reflogs."
  81. :group 'magit-faces)
  82. (defface magit-reflog-remote '((t :foreground "cyan"))
  83. "Face for pull and clone commands in reflogs."
  84. :group 'magit-faces)
  85. (defface magit-reflog-other '((t :foreground "cyan"))
  86. "Face for other commands in reflogs."
  87. :group 'magit-faces)
  88. ;;; Commands
  89. ;;;###autoload
  90. (defun magit-reflog-current ()
  91. "Display the reflog of the current branch.
  92. If `HEAD' is detached, then show the reflog for that instead."
  93. (interactive)
  94. (magit-reflog-setup-buffer (or (magit-get-current-branch) "HEAD")))
  95. ;;;###autoload
  96. (defun magit-reflog-other (ref)
  97. "Display the reflog of a branch or another ref."
  98. (interactive (list (magit-read-local-branch-or-ref "Show reflog for")))
  99. (magit-reflog-setup-buffer ref))
  100. ;;;###autoload
  101. (defun magit-reflog-head ()
  102. "Display the `HEAD' reflog."
  103. (interactive)
  104. (magit-reflog-setup-buffer "HEAD"))
  105. ;;; Mode
  106. (defvar magit-reflog-mode-map
  107. (let ((map (make-sparse-keymap)))
  108. (set-keymap-parent map magit-log-mode-map)
  109. (define-key map "\C-c\C-n" 'undefined)
  110. (define-key map "L" 'magit-margin-settings)
  111. map)
  112. "Keymap for `magit-reflog-mode'.")
  113. (define-derived-mode magit-reflog-mode magit-mode "Magit Reflog"
  114. "Mode for looking at Git reflog.
  115. This mode is documented in info node `(magit)Reflog'.
  116. \\<magit-mode-map>\
  117. Type \\[magit-refresh] to refresh the current buffer.
  118. Type \\[magit-visit-thing] or \\[magit-diff-show-or-scroll-up] \
  119. to visit the commit at point.
  120. Type \\[magit-cherry-pick] to apply the commit at point.
  121. Type \\[magit-reset] to reset `HEAD' to the commit at point.
  122. \\{magit-reflog-mode-map}"
  123. :group 'magit-log
  124. (hack-dir-local-variables-non-file-buffer))
  125. (defun magit-reflog-setup-buffer (ref)
  126. (require 'magit)
  127. (magit-setup-buffer #'magit-reflog-mode nil
  128. (magit-buffer-refname ref)
  129. (magit-buffer-log-args (list (format "-n%s" magit-reflog-limit)))))
  130. (defun magit-reflog-refresh-buffer ()
  131. (magit-set-header-line-format (concat "Reflog for " magit-buffer-refname))
  132. (magit-insert-section (reflogbuf)
  133. (magit-git-wash (apply-partially 'magit-log-wash-log 'reflog)
  134. "reflog" "show" "--format=%h%x00%aN%x00%gd%x00%gs" "--date=raw"
  135. magit-buffer-log-args magit-buffer-refname "--")))
  136. (cl-defmethod magit-buffer-value (&context (major-mode magit-reflog-mode))
  137. magit-buffer-refname)
  138. (defvar magit-reflog-labels
  139. '(("commit" . magit-reflog-commit)
  140. ("amend" . magit-reflog-amend)
  141. ("merge" . magit-reflog-merge)
  142. ("checkout" . magit-reflog-checkout)
  143. ("branch" . magit-reflog-checkout)
  144. ("reset" . magit-reflog-reset)
  145. ("rebase" . magit-reflog-rebase)
  146. ("cherry-pick" . magit-reflog-cherry-pick)
  147. ("initial" . magit-reflog-commit)
  148. ("pull" . magit-reflog-remote)
  149. ("clone" . magit-reflog-remote)
  150. ("autosave" . magit-reflog-commit)
  151. ("restart" . magit-reflog-reset)))
  152. (defun magit-reflog-format-subject (subject)
  153. (let* ((match (string-match magit-reflog-subject-re subject))
  154. (command (and match (match-string 1 subject)))
  155. (option (and match (match-string 2 subject)))
  156. (type (and match (match-string 3 subject)))
  157. (label (if (string= command "commit")
  158. (or type command)
  159. command))
  160. (text (if (string= command "commit")
  161. label
  162. (mapconcat #'identity
  163. (delq nil (list command option type))
  164. " "))))
  165. (format "%-16s "
  166. (magit--propertize-face
  167. text (or (cdr (assoc label magit-reflog-labels))
  168. 'magit-reflog-other)))))
  169. ;;; _
  170. (provide 'magit-reflog)
  171. ;;; magit-reflog.el ends here