update packages
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
;;; magit-repos.el --- listing repositories -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2010-2021 The Magit Project Contributors
|
||||
;; Copyright (C) 2010-2022 The Magit Project Contributors
|
||||
;;
|
||||
;; You should have received a copy of the AUTHORS.md file which
|
||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
||||
@@ -8,6 +8,8 @@
|
||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
||||
|
||||
;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
;; Magit is free software; you can redistribute it and/or modify it
|
||||
;; under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation; either version 3, or (at your option)
|
||||
@@ -29,12 +31,9 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(eval-when-compile
|
||||
(require 'subr-x))
|
||||
|
||||
(require 'magit-core)
|
||||
|
||||
(declare-function magit-status-setup-buffer "magit-status" (directory))
|
||||
(declare-function magit-status-setup-buffer "magit-status" (&optional directory))
|
||||
|
||||
(defvar x-stretch-cursor)
|
||||
|
||||
@@ -89,10 +88,16 @@ and with `default-directory' bound to the toplevel of its working
|
||||
tree. It has to return a string to be inserted or nil. PROPS is
|
||||
an alist that supports the keys `:right-align' and `:pad-right'.
|
||||
Some entries also use `:help-echo', but `tabulated-list' does not
|
||||
actually support that yet."
|
||||
actually support that yet.
|
||||
|
||||
You may wish to display a range of numeric columns using just one
|
||||
character per column and without any padding between columns, in
|
||||
which case you should use an appropriat HEADER, set WIDTH to 1,
|
||||
and set `:pad-right' to 0. \"+\" is substituted for numbers higher
|
||||
than 9."
|
||||
:package-version '(magit . "2.12.0")
|
||||
:group 'magit-repolist
|
||||
:type `(repeat (list :tag "Column"
|
||||
:type '(repeat (list :tag "Column"
|
||||
(string :tag "Header Label")
|
||||
(integer :tag "Column Width")
|
||||
(function :tag "Inserter Function")
|
||||
@@ -119,6 +124,18 @@ as the value of `magit-repolist-column-flag'."
|
||||
:type '(alist :key-type (function :tag "Predicate Function")
|
||||
:value-type (string :tag "Flag")))
|
||||
|
||||
(defcustom magit-repolist-sort-key '("Path" . nil)
|
||||
"Initial sort key for buffer created by `magit-list-repositories'.
|
||||
If nil, no additional sorting is performed. Otherwise, this
|
||||
should be a cons cell (NAME . FLIP). NAME is a string matching
|
||||
one of the column names in `magit-repolist-columns'. FLIP, if
|
||||
non-nil, means to invert the resulting sort."
|
||||
:package-version '(magit . "3.2.0")
|
||||
:group 'magit-repolist
|
||||
:type '(choice (const nil)
|
||||
(cons (string :tag "Column name")
|
||||
(boolean :tag "Flip order"))))
|
||||
|
||||
;;; List Repositories
|
||||
;;;; Command
|
||||
;;;###autoload
|
||||
@@ -128,14 +145,7 @@ as the value of `magit-repolist-column-flag'."
|
||||
Use the options `magit-repository-directories' to control which
|
||||
repositories are displayed."
|
||||
(interactive)
|
||||
(if magit-repository-directories
|
||||
(with-current-buffer (get-buffer-create "*Magit Repositories*")
|
||||
(magit-repolist-mode)
|
||||
(magit-repolist-refresh)
|
||||
(tabulated-list-print)
|
||||
(switch-to-buffer (current-buffer)))
|
||||
(message "You need to customize `magit-repository-directories' %s"
|
||||
"before you can list repositories")))
|
||||
(magit-repolist-setup (default-value 'magit-repolist-columns)))
|
||||
|
||||
;;;; Mode
|
||||
|
||||
@@ -157,64 +167,98 @@ repositories are displayed."
|
||||
"Major mode for browsing a list of Git repositories."
|
||||
(setq-local x-stretch-cursor nil)
|
||||
(setq tabulated-list-padding 0)
|
||||
(setq tabulated-list-sort-key (cons "Path" nil))
|
||||
(setq tabulated-list-format
|
||||
(vconcat (mapcar (pcase-lambda (`(,title ,width ,_fn ,props))
|
||||
(nconc (list title width t)
|
||||
(-flatten props)))
|
||||
magit-repolist-columns)))
|
||||
(tabulated-list-init-header)
|
||||
(add-hook 'tabulated-list-revert-hook 'magit-repolist-refresh nil t)
|
||||
(setq imenu-prev-index-position-function
|
||||
'magit-imenu--repolist-prev-index-position-function)
|
||||
(setq imenu-extract-index-name-function
|
||||
'magit-imenu--repolist-extract-index-name-function))
|
||||
|
||||
(defun magit-repolist-setup (columns)
|
||||
(unless magit-repository-directories
|
||||
(user-error "You need to customize `magit-repository-directories' %s"
|
||||
"before you can list repositories"))
|
||||
(with-current-buffer (get-buffer-create "*Magit Repositories*")
|
||||
(magit-repolist-mode)
|
||||
(setq-local magit-repolist-columns columns)
|
||||
(magit-repolist-refresh)
|
||||
(switch-to-buffer (current-buffer))))
|
||||
|
||||
(defun magit-repolist-refresh ()
|
||||
(unless tabulated-list-sort-key
|
||||
(setq tabulated-list-sort-key
|
||||
(pcase-let ((`(,column . ,flip) magit-repolist-sort-key))
|
||||
(cons (or (car (assoc column magit-repolist-columns))
|
||||
(caar magit-repolist-columns))
|
||||
flip))))
|
||||
(setq tabulated-list-format
|
||||
(vconcat (mapcar (pcase-lambda (`(,title ,width ,_fn ,props))
|
||||
(nconc (list title width t)
|
||||
(-flatten props)))
|
||||
magit-repolist-columns)))
|
||||
(setq tabulated-list-entries
|
||||
(mapcar (pcase-lambda (`(,id . ,path))
|
||||
(let ((default-directory path))
|
||||
(list path
|
||||
(vconcat (--map (or (funcall (nth 2 it) id) "")
|
||||
magit-repolist-columns)))))
|
||||
(vconcat
|
||||
(mapcar (pcase-lambda (`(,title ,width ,fn ,props))
|
||||
(or (funcall fn `((:id ,id)
|
||||
(:title ,title)
|
||||
(:width ,width)
|
||||
,@props))
|
||||
""))
|
||||
magit-repolist-columns)))))
|
||||
(magit-list-repos-uniquify
|
||||
(--map (cons (file-name-nondirectory (directory-file-name it))
|
||||
it)
|
||||
(magit-list-repos))))))
|
||||
(magit-list-repos)))))
|
||||
(message "Listing repositories...")
|
||||
(tabulated-list-init-header)
|
||||
(tabulated-list-print t)
|
||||
(message "Listing repositories...done"))
|
||||
|
||||
;;;; Columns
|
||||
|
||||
(defun magit-repolist-column-ident (id)
|
||||
(defun magit-repolist-column-ident (spec)
|
||||
"Insert the identification of the repository.
|
||||
Usually this is just its basename."
|
||||
id)
|
||||
(cadr (assq :id spec)))
|
||||
|
||||
(defun magit-repolist-column-path (_id)
|
||||
(defun magit-repolist-column-path (_)
|
||||
"Insert the absolute path of the repository."
|
||||
(abbreviate-file-name default-directory))
|
||||
|
||||
(defun magit-repolist-column-version (_id)
|
||||
(defun magit-repolist-column-version (_)
|
||||
"Insert a description of the repository's `HEAD' revision."
|
||||
(when-let ((v (or (magit-git-string "describe" "--tags" "--dirty")
|
||||
;; If there are no tags, use the date in MELPA format.
|
||||
(magit-git-string "show" "--no-patch" "--format=%cd-g%h"
|
||||
"--date=format:%Y%m%d.%H%M"))))
|
||||
(save-match-data
|
||||
(when (string-match "-dirty\\'" v)
|
||||
(magit--put-face (1+ (match-beginning 0)) (length v) 'error v))
|
||||
(when (string-match
|
||||
"\\(?:-\\([0-9]*\\)-g[a-z0-9]*\\)?\\(?:-\\(dirty\\)\\)?\\'" v)
|
||||
(magit--put-face (match-beginning 0) (match-end 0) 'shadow v)
|
||||
(when (match-end 1)
|
||||
(magit--put-face (match-beginning 1) (match-end 1) 'bold v))
|
||||
(when (match-end 2)
|
||||
(magit--put-face (match-beginning 2) (match-end 2) 'error v)))
|
||||
(if (and v (string-match "\\`[0-9]" v))
|
||||
(concat " " v)
|
||||
(when (and v (string-match "\\`[^0-9]+" v))
|
||||
(magit--put-face 0 (match-end 0) 'shadow v))
|
||||
v))))
|
||||
|
||||
(defun magit-repolist-column-branch (_id)
|
||||
(defun magit-repolist-column-branch (_)
|
||||
"Insert the current branch."
|
||||
(magit-get-current-branch))
|
||||
(let ((branch (magit-get-current-branch)))
|
||||
(if (member branch magit-main-branch-names)
|
||||
(magit--propertize-face branch 'shadow)
|
||||
branch)))
|
||||
|
||||
(defun magit-repolist-column-upstream (_id)
|
||||
(defun magit-repolist-column-upstream (_)
|
||||
"Insert the upstream branch of the current branch."
|
||||
(magit-get-upstream-branch))
|
||||
|
||||
(defun magit-repolist-column-flag (_id)
|
||||
(defun magit-repolist-column-flag (_)
|
||||
"Insert a flag as specified by `magit-repolist-column-flag-alist'.
|
||||
|
||||
By default this indicates whether there are uncommitted changes.
|
||||
@@ -226,43 +270,50 @@ Only one letter is shown, the first that applies."
|
||||
(and (funcall fun) flag))
|
||||
magit-repolist-column-flag-alist))
|
||||
|
||||
(defun magit-repolist-column-unpulled-from-upstream (_id)
|
||||
(defun magit-repolist-column-flags (_)
|
||||
"Insert all flags as specified by `magit-repolist-column-flag-alist'.
|
||||
This is an alternative to function `magit-repolist-column-flag',
|
||||
which only lists the first one found."
|
||||
(mapconcat (pcase-lambda (`(,fun . ,flag))
|
||||
(if (funcall fun) flag " "))
|
||||
magit-repolist-column-flag-alist
|
||||
""))
|
||||
|
||||
(defun magit-repolist-column-unpulled-from-upstream (spec)
|
||||
"Insert number of upstream commits not in the current branch."
|
||||
(--when-let (magit-get-upstream-branch)
|
||||
(let ((n (cadr (magit-rev-diff-count "HEAD" it))))
|
||||
(magit--propertize-face
|
||||
(number-to-string n) (if (> n 0) 'bold 'shadow)))))
|
||||
(magit-repolist-insert-count (cadr (magit-rev-diff-count "HEAD" it)) spec)))
|
||||
|
||||
(defun magit-repolist-column-unpulled-from-pushremote (_id)
|
||||
(defun magit-repolist-column-unpulled-from-pushremote (spec)
|
||||
"Insert number of commits in the push branch but not the current branch."
|
||||
(--when-let (magit-get-push-branch nil t)
|
||||
(let ((n (cadr (magit-rev-diff-count "HEAD" it))))
|
||||
(magit--propertize-face
|
||||
(number-to-string n) (if (> n 0) 'bold 'shadow)))))
|
||||
(magit-repolist-insert-count (cadr (magit-rev-diff-count "HEAD" it)) spec)))
|
||||
|
||||
(defun magit-repolist-column-unpushed-to-upstream (_id)
|
||||
(defun magit-repolist-column-unpushed-to-upstream (spec)
|
||||
"Insert number of commits in the current branch but not its upstream."
|
||||
(--when-let (magit-get-upstream-branch)
|
||||
(let ((n (car (magit-rev-diff-count "HEAD" it))))
|
||||
(magit--propertize-face
|
||||
(number-to-string n) (if (> n 0) 'bold 'shadow)))))
|
||||
(magit-repolist-insert-count (car (magit-rev-diff-count "HEAD" it)) spec)))
|
||||
|
||||
(defun magit-repolist-column-unpushed-to-pushremote (_id)
|
||||
(defun magit-repolist-column-unpushed-to-pushremote (spec)
|
||||
"Insert number of commits in the current branch but not its push branch."
|
||||
(--when-let (magit-get-push-branch nil t)
|
||||
(let ((n (car (magit-rev-diff-count "HEAD" it))))
|
||||
(magit--propertize-face
|
||||
(number-to-string n) (if (> n 0) 'bold 'shadow)))))
|
||||
(magit-repolist-insert-count (car (magit-rev-diff-count "HEAD" it)) spec)))
|
||||
|
||||
(defun magit-repolist-column-branches (_id)
|
||||
(defun magit-repolist-column-branches (spec)
|
||||
"Insert number of branches."
|
||||
(let ((n (length (magit-list-local-branches))))
|
||||
(magit--propertize-face (number-to-string n) (if (> n 1) 'bold 'shadow))))
|
||||
(magit-repolist-insert-count (length (magit-list-local-branches))
|
||||
`((:normal-count 1) ,@spec)))
|
||||
|
||||
(defun magit-repolist-column-stashes (_id)
|
||||
(defun magit-repolist-column-stashes (spec)
|
||||
"Insert number of stashes."
|
||||
(let ((n (length (magit-list-stashes))))
|
||||
(magit--propertize-face (number-to-string n) (if (> n 0) 'bold 'shadow))))
|
||||
(magit-repolist-insert-count (length (magit-list-stashes)) spec))
|
||||
|
||||
(defun magit-repolist-insert-count (n spec)
|
||||
(magit--propertize-face
|
||||
(if (and (> n 9) (= (cadr (assq :width spec)) 1))
|
||||
"+"
|
||||
(number-to-string n))
|
||||
(if (> n (or (cadr (assq :normal-count spec)) 0)) 'bold 'shadow)))
|
||||
|
||||
;;; Read Repository
|
||||
|
||||
|
||||
Reference in New Issue
Block a user