From ca027a8760f8b3bcc36add30de7e7d4c540a4919 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gustav=20H=C3=A5llberg?= Date: Wed, 5 Aug 2009 14:46:24 +0200 Subject: [PATCH] stgit.el: Abbreviate renames/copies with common prefix/suffix MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Gustav HÃ¥llberg --- contrib/stgit.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/contrib/stgit.el b/contrib/stgit.el index 6d84fd2..e8995b3 100644 --- a/contrib/stgit.el +++ b/contrib/stgit.el @@ -461,13 +461,52 @@ Cf. `stgit-file-type-change-string'." (defstruct (stgit-file) old-perm new-perm copy-or-rename cr-score cr-from cr-to status file) +(defun stgit-describe-copy-or-rename (file) + (let (from to common-head common-tail + (arrow (concat " " + (propertize "->" 'face 'stgit-description-face) + " "))) + + (when stgit-abbreviate-copies-and-renames + (setq from (split-string (stgit-file-cr-from file) "/") + to (split-string (stgit-file-cr-to file) "/")) + + (while (and from to (cdr from) (cdr to) + (string-equal (car from) (car to))) + (setq common-head (cons (car from) common-head) + from (cdr from) + to (cdr to))) + (setq common-head (nreverse common-head) + from (nreverse from) + to (nreverse to)) + (while (and from to (cdr from) (cdr to) + (string-equal (car from) (car to))) + (setq common-tail (cons (car from) common-tail) + from (cdr from) + to (cdr to))) + (setq from (nreverse from) + to (nreverse to))) + + (if (or common-head common-tail) + (concat (if common-head + (mapconcat #'identity common-head "/") + "") + (if common-head "/" "") + (propertize "{" 'face 'stgit-description-face) + (mapconcat #'identity from "/") + arrow + (mapconcat #'identity to "/") + (propertize "}" 'face 'stgit-description-face) + (if common-tail "/" "") + (if common-tail + (mapconcat #'identity common-tail "/") + "")) + (concat (stgit-file-cr-from file) arrow (stgit-file-cr-to file))))) + (defun stgit-file-pp (file) (let ((status (stgit-file-status file)) (name (if (stgit-file-copy-or-rename file) - (concat (stgit-file-cr-from file) - (propertize " -> " - 'face 'stgit-description-face) - (stgit-file-cr-to file)) + (stgit-describe-copy-or-rename file) (stgit-file-file file))) (mode-change (stgit-file-mode-change-string (stgit-file-old-perm file) @@ -1514,4 +1553,11 @@ Use \\[stgit-toggle-worktree] to show the work tree." (not stgit-show-unknown))) (stgit-reload)) +(defcustom stgit-abbreviate-copies-and-renames + t + "If non-nil, abbreviate copies and renames as \"dir/{old -> new}/file\" +instead of \"dir/old/file -> dir/new/file\"." + :type 'boolean + :group 'stgit) + (provide 'stgit) -- 2.11.0