diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2018-08-05 13:19:36 -0500 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2018-08-05 13:19:36 -0500 |
| commit | 0bcd923ce2fa41e86e4cb6a974fc195e457b0057 (patch) | |
| tree | 88d92062238e8fd92095c784b1a60a14797e17cd | |
| parent | a9c3242ee00b4f92a335ee88bc7c91b18a8c51f3 (diff) | |
Add a shortstat margin style for logs
The current implementation is problematic as it requires git to be
called once per commit, but doing it properly would have required
changes to highly problematic parts of existing code. Eventually
those things will get refactored at which point this new feature will
get a performance boost too. Even before that we will likely start
using libgit2, which should also help a lot. Until one of these two
things has happened I am not adding the toggle command to the popups.
Closes #3035.
| -rw-r--r-- | lisp/magit-log.el | 83 | ||||
| -rw-r--r-- | lisp/magit-margin.el | 4 | ||||
| -rw-r--r-- | lisp/magit-refs.el | 3 | ||||
| -rw-r--r-- | lisp/magit-stash.el | 2 |
4 files changed, 64 insertions, 28 deletions
diff --git a/lisp/magit-log.el b/lisp/magit-log.el index 1e4f8ea..b7681dd 100644 --- a/lisp/magit-log.el +++ b/lisp/magit-log.el @@ -1139,12 +1139,12 @@ Do not add this to a hook variable." (* (string-to-number (match-string 3 date)) 60)))) (save-excursion (backward-char) - (magit-log-format-margin author date))) + (magit-log-format-margin hash author date))) (when (and (eq style 'cherry) (magit-buffer-margin-p)) (save-excursion (backward-char) - (apply #'magit-log-format-margin + (apply #'magit-log-format-margin hash (split-string (magit-rev-format "%aN%x00%ct" hash) "\0")))) (when (and graph (not (eobp)) @@ -1285,30 +1285,63 @@ If there is no blob buffer in the same frame, then do nothing." ;;; Log Margin -(defun magit-log-format-margin (author date) +(defvar-local magit-log-margin-show-shortstat nil) + +(defun magit-toggle-log-margin-style () + "Toggle between the regular and the shortstat margin style. +The shortstat style is experimental and rather slow." + (interactive) + (setq magit-log-margin-show-shortstat + (not magit-log-margin-show-shortstat)) + (magit-set-buffer-margin nil t)) + +(defun magit-log-format-margin (rev author date) (when-let ((option (magit-margin-option))) - (pcase-let ((`(,_ ,style ,width ,details ,details-width) - (or magit-buffer-margin - (symbol-value option)))) - (magit-make-margin-overlay - (concat (and details - (concat (propertize (truncate-string-to-width - (or author "") - details-width - nil ?\s (make-string 1 magit-ellipsis)) - 'face 'magit-log-author) - " ")) - (propertize - (if (stringp style) - (format-time-string - style - (seconds-to-time (string-to-number date))) - (pcase-let* ((abbr (eq style 'age-abbreviated)) - (`(,cnt ,unit) (magit--age date abbr))) - (format (format (if abbr "%%2i%%-%ic" "%%2i %%-%is") - (- width (if details (1+ details-width) 0))) - cnt unit))) - 'face 'magit-log-date)))))) + (if magit-log-margin-show-shortstat + (magit-log-format-shortstat-margin rev) + (pcase-let ((`(,_ ,style ,width ,details ,details-width) + (or magit-buffer-margin + (symbol-value option)))) + (magit-make-margin-overlay + (concat (and details + (concat (propertize (truncate-string-to-width + (or author "") + details-width + nil ?\s (make-string 1 magit-ellipsis)) + 'face 'magit-log-author) + " ")) + (propertize + (if (stringp style) + (format-time-string + style + (seconds-to-time (string-to-number date))) + (pcase-let* ((abbr (eq style 'age-abbreviated)) + (`(,cnt ,unit) (magit--age date abbr))) + (format (format (if abbr "%%2i%%-%ic" "%%2i %%-%is") + (- width (if details (1+ details-width) 0))) + cnt unit))) + 'face 'magit-log-date))))))) + +(defun magit-log-format-shortstat-margin (rev) + (magit-make-margin-overlay + (if-let ((line (and rev (magit-git-string + "show" "--format=" "--shortstat" rev)))) + (if (string-match "\ +\\([0-9]+\\) files? changed, \ +\\(?:\\([0-9]+\\) insertions?(\\+)\\)?\ +\\(?:\\(?:, \\)?\\([0-9]+\\) deletions?(-)\\)?\\'" line) + (magit-bind-match-strings (files add del) line + (format + "%5s %5s%4s" + (if add + (propertize (format "%s+" add) 'face 'magit-diffstat-added) + "") + (if del + (propertize (format "%s-" del) 'face 'magit-diffstat-removed) + "") + files)) + "") + ""))) (defun magit-log-margin-width (style details details-width) (+ (if details (1+ details-width) 0) diff --git a/lisp/magit-margin.el b/lisp/magit-margin.el index 4210d96..76ad344 100644 --- a/lisp/magit-margin.el +++ b/lisp/magit-margin.el @@ -145,7 +145,9 @@ does not carry to other options." (with-selected-window window (set-window-margins nil (car (window-margins)) (and (magit-buffer-margin-p) - (nth 2 magit-buffer-margin)))))) + (if magit-log-margin-show-shortstat + 16 ; kludge + (nth 2 magit-buffer-margin))))))) (defun magit-make-margin-overlay (&optional string previous-line) (if previous-line diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el index 8a8635c..80f6d30 100644 --- a/lisp/magit-refs.el +++ b/lisp/magit-refs.el @@ -740,7 +740,8 @@ line is inserted at all." (save-excursion (goto-char (line-beginning-position 0)) (let ((line (magit-rev-format "%ct%cN" commit))) - (magit-log-format-margin (substring line 10) + (magit-log-format-margin commit + (substring line 10) (substring line 0 10))))) (provide 'magit-refs) diff --git a/lisp/magit-stash.el b/lisp/magit-stash.el index 9f4ea5a..98497ec 100644 --- a/lisp/magit-stash.el +++ b/lisp/magit-stash.el @@ -383,7 +383,7 @@ instead of \"Stashes:\"." (insert " " msg "\n") (save-excursion (backward-char) - (magit-log-format-margin author date))))) + (magit-log-format-margin autostash author date))))) (if verified (magit-git-wash (apply-partially 'magit-log-wash-log 'stash) "reflog" "--format=%gd%x00%aN%x00%at%x00%gs" ref) |
