summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.el19
-rw-r--r--lisp/km-magit.el58
2 files changed, 70 insertions, 7 deletions
diff --git a/init.el b/init.el
index a2e31ab..6a0eabd 100644
--- a/init.el
+++ b/init.el
@@ -908,13 +908,6 @@
(setq magit-show-refs-arguments '("--sort=-committerdate"))
- (setq magit-status-sections-hook
- (let ((funcs (list #'magit-insert-unpulled-from-pushremote
- #'magit-insert-unpulled-from-upstream)))
- (append (cl-remove-if (lambda (x) (memq x funcs))
- magit-status-sections-hook)
- funcs)))
-
(remove-hook 'magit-refs-sections-hook #'magit-insert-tags)
(setq magit-display-buffer-function
@@ -1069,6 +1062,8 @@
(define-key magit-log-select-mode-map "."
#'km/magit-log-select-guess-fixup-commit)
+ (define-key magit-status-mode-map "jr" #'magit-jump-to-remote-counts)
+
(define-key magit-refs-mode-map (kbd "C-c C-t") #'km/magit-refs-toggle-tags)
(define-key magit-file-section-map [remap magit-visit-thing]
@@ -1095,6 +1090,16 @@
("j" . km/git-rebase-join-repeats)
("m" . km/git-rebase-move-commit)))
+ (setq magit-status-sections-hook
+ (append
+ (let ((funcs (list #'magit-insert-unpushed-to-upstream
+ #'magit-insert-unpushed-to-pushremote
+ #'magit-insert-unpulled-from-pushremote
+ #'magit-insert-unpulled-from-upstream)))
+ (cl-remove-if (lambda (x) (memq x funcs))
+ magit-status-sections-hook))
+ (list #'km/magit-insert-remote-counts)))
+
(magit-define-popup-action 'magit-commit-popup
?u "Auto commit" #'km/magit-update-or-auto-commit)
diff --git a/lisp/km-magit.el b/lisp/km-magit.el
index 0c4a344..1ec6bba 100644
--- a/lisp/km-magit.el
+++ b/lisp/km-magit.el
@@ -646,6 +646,64 @@ argument. Interactively, this can be accessed using the command
(magit-log (list range) args files)
(call-interactively #'magit-log))))
+(defun km/magit--insert-count-lines (rev counts)
+ (-let [(n-behind n-ahead) counts]
+ (when (> n-ahead 0)
+ (magit-insert-section (unpushed (concat rev ".."))
+ (magit-insert-heading
+ (format "%3s ahead of %s"
+ (propertize (number-to-string n-ahead)
+ 'face 'magit-diffstat-added)
+ rev))))
+ (when (> n-behind 0)
+ (magit-insert-section (unpulled (concat ".." rev))
+ (magit-insert-heading
+ (format "%3s behind %s"
+ (propertize (number-to-string n-behind)
+ 'face 'magit-diffstat-removed)
+ rev))))))
+
+(defun km/magit-insert-remote-counts ()
+ "Insert section showing number of unpushed and unpulled commits.
+
+This function is a lightweight replacement of four
+`magit-status-sections-hook' functions:
+`magit-insert-unpulled-from-upstream',
+`magit-insert-unpulled-from-pushremote',
+`magit-insert-unpushed-to-upstream', and
+`magit-insert-unpushed-to-pushremote'.
+
+Unlike the above functions, this function does not insert a log
+of unpulled or unpushed commits, but instead inserts a combined
+section that only reports the number of commits in each
+category."
+ (when (magit-get-current-branch)
+ (let* ((up-counts (and (magit-git-success "rev-parse" "@{upstream}")
+ (magit-rev-diff-count "@{upstream}" "")))
+ ;; Unlike `magit-insert-unpushed-to-pushremote' and
+ ;; `magit-insert-unpulled-from-pushremote', just use
+ ;; "@{push}". This drops support for the push-remote if
+ ;; push.default isn't set to a compatible value. See
+ ;; Magit's 6505f4cd.
+ (pu-counts (and (magit-git-success "rev-parse" "@{push}")
+ (magit-rev-diff-count "@{push}" "")))
+ (up-any (and up-counts (or (> (car up-counts) 0)
+ (> (cadr up-counts) 0))))
+ (pu-any (and pu-counts (or (> (car pu-counts) 0)
+ (> (cadr pu-counts) 0)))))
+ (when (or up-any pu-any)
+ (magit-insert-section (remote-counts)
+ (magit-insert-heading "Remote counts")
+ (when up-any
+ (km/magit--insert-count-lines "@{upstream}" up-counts))
+ (when (and pu-any (not (and up-any
+ (equal (magit-rev-name "@{upstream}")
+ (magit-rev-name "@{push}")))))
+ (km/magit--insert-count-lines "@{push}" pu-counts)))))))
+
+(magit-define-section-jumper magit-jump-to-remote-counts
+ "Remote counts" remote-counts)
+
;;; Git Rebase mode