el/dot-emacs.el: Basic configuration (and fixes) for Magit's repo list.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 7 Jul 2017 19:58:05 +0000 (20:58 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 7 Jul 2017 20:13:48 +0000 (21:13 +0100)
By default it should look in `~/src/' for repositories -- duh.  A
`~/.emacs-local' can override the list as appropriate.

Unfortunately, Magit's repo list is rather buggy.

  * The function `magit-rep-list' returns filenames rather than
    directory names, and Emacs (24, at least) then sets the wrong
    current directory when running inferior processes to find out about
    the repos.

  * The functions `magit-repolist-column-un{pulled-from,pushed-to}-
    {upstream,pushremote}' are just screwed because they expect `magit-
    get-{push,upstream}-branch' to magically turn `nil' into the current
    branch name, which isn't going to happen.

So, configure things, and hack around the bugs.

dot/emacs
el/dot-emacs.el

index d89f442..1062254 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
   (global-set-key [?\C-c ?m ?m] 'magit-status)
   (global-set-key [?\C-c ?m ?d] 'magit-dispatch-popup)
   (global-set-key [?\C-c ?m ?w] 'magit-wip-log)
+  (global-set-key [?\C-c ?m ?r] 'magit-list-repositories)
   (global-set-key [?\C-c ?k] 'compile)
   (global-set-key [?\C-x ?3] 'mdw-split-window-horizontally)
   (global-set-key [?\M-#] 'calc-dispatch)
index 03946d6..403a5e4 100644 (file)
@@ -3637,6 +3637,39 @@ This allows you to pass a list of arguments through `ansi-term'."
          (magit-wip-before-change-mode 1)
          (add-to-list 'magit-no-confirm 'safe-with-wip)))
 
+(setq magit-repolist-columns
+      '(("Name" 16 magit-repolist-column-ident nil)
+       ("Version" 18 magit-repolist-column-version nil)
+       ("St" 2 magit-repolist-column-dirty nil)
+       ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
+       ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
+       ("Path" 32 magit-repolist-column-path nil)))
+
+(setq magit-repository-directories '(("~/etc/profile" . 0)
+                                    ("~/src/" . 1)))
+
+(defadvice magit-list-repos (around mdw-dirname () activate compile)
+  "Make sure the returned names are directory names.
+Otherwise child processes get started in the wrong directory and
+there is sadness."
+  (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
+
+(defun mdw-repolist-column-unpulled-from-upstream (_id)
+  "Insert number of upstream commits not in the current branch."
+  (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
+    (and upstream
+        (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
+          (propertize (number-to-string n) 'face
+                      (if (> n 0) 'bold 'shadow))))))
+
+(defun mdw-repolist-column-unpushed-to-upstream (_id)
+  "Insert number of commits in the current branch but not its upstream."
+  (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
+    (and upstream
+        (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
+          (propertize (number-to-string n) 'face
+                      (if (> n 0) 'bold 'shadow))))))
+
 ;;;--------------------------------------------------------------------------
 ;;; Inferior Emacs Lisp.