branch: elpa/magit
commit 2dd886c28debeabba711c6e4b257cc8c08ab8368
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    magit-blame-styles: Support %h to truncate hashes
    
    Closes #4057.
---
 lisp/magit-blame.el | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lisp/magit-blame.el b/lisp/magit-blame.el
index 5695046a18..e87bd4fc4e 100644
--- a/lisp/magit-blame.el
+++ b/lisp/magit-blame.el
@@ -94,12 +94,17 @@ The following %-specs can be used in `heading-format' and
 `margin-format':
 
   %H    hash              using face `magit-blame-hash'
+  %h    truncated hash    using face `magit-blame-hash'
   %s    summary           using face `magit-blame-summary'
   %a    author            using face `magit-blame-name'
   %A    author time       using face `magit-blame-date'
   %c    committer         using face `magit-blame-name'
   %C    committer time    using face `magit-blame-date'
 
+Note that for performance reasons %h results in truncated
+hashes, as opposed to properly abbreviated hashes that are
+guaranteed to uniquely identify a commit.
+
 Additionally if `margin-format' ends with %f, then the string
 that is displayed in the margin is made at least `margin-width'
 characters wide, which may be desirable if the used face sets
@@ -701,6 +706,7 @@ modes is toggled, then this mode also gets toggled 
automatically.
                               (cdr (assoc k2 revinfo)))
                              f)))
               `((?H . ,(p0 rev         'magit-blame-hash))
+                (?h . ,(p0 (magit-blame--abbrev-hash rev)  'magit-blame-hash))
                 (?s . ,(p1 "summary"   'magit-blame-summary))
                 (?a . ,(p1 "author"    'magit-blame-name))
                 (?c . ,(p1 "committer" 'magit-blame-name))
@@ -731,6 +737,13 @@ modes is toggled, then this mode also gets toggled 
automatically.
                         (seconds-to-time (string-to-number time))
                         tz-in-second)))
 
+(defvar-local magit-blame--abbrev-length nil)
+
+(defun magit-blame--abbrev-hash (rev)
+  (substring rev 0 (or magit-blame--abbrev-length
+                       (setq magit-blame--abbrev-length
+                             (magit-abbrev-length)))))
+
 (defun magit-blame--remove-overlays (&optional beg end)
   (save-restriction
     (widen)

Reply via email to