From f5c4e6f5e05eab2b9b7cdc778a8048129ab887bc Mon Sep 17 00:00:00 2001 From: Stuart Hickinbottom Date: Wed, 5 Nov 2014 22:49:58 +0000 Subject: [PATCH 1/2] Added display of commit age Now shows age of commit (e.g. "2 months ago") in the modeline, and full details of the commit in the minibuffer while navigating through old commits. Added new customisation 'git-timemachine-show-minibuffer-details' to control the display in the minibuffer in case it is distracting. --- git-timemachine.el | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) mode change 100644 => 100755 git-timemachine.el diff --git a/git-timemachine.el b/git-timemachine.el old mode 100644 new mode 100755 index 31209fc..519e00d --- a/git-timemachine.el +++ b/git-timemachine.el @@ -37,6 +37,11 @@ "Number of chars from the full sha1 hash to use for abbreviation." :group 'git-timemachine) +(defcustom git-timemachine-show-minibuffer-details t + "Non-nil means that details of the commit (its hash and date) +will be shown in the minibuffer while navigating commits." + :group 'git-timemachine) + (defvar git-timemachine-directory nil) (defvar git-timemachine-revision nil) (defvar git-timemachine-file nil) @@ -50,13 +55,20 @@ (let ((default-directory git-timemachine-directory) (file git-timemachine-file)) (with-temp-buffer - (unless (zerop (process-file vc-git-program nil t nil "--no-pager" "log" "--pretty=format:%H" file)) - (error "Failed: 'git log --pretty=format:%%H' %s" file)) + (unless (zerop (process-file vc-git-program nil t nil "--no-pager" "log" "--pretty=format:%H:%ar:%ad" file)) + (error "Failed: 'git log --pretty=format:%%H:%%ar:%%ad' %s" file)) (goto-char (point-min)) - (let (lines) + (let ((lines) + (commit-number (count-lines (point-min) (point-max)))) (while (not (eobp)) - (push (buffer-substring-no-properties (line-beginning-position) (line-end-position)) lines) - (forward-line 1)) + (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) + (string-match "\\([^:]*\\):\\([^:]*\\):\\(.*\\)" line) + (let ((commit (match-string 1 line)) + (date-relative (match-string 2 line)) + (date-full (match-string 3 line))) + (push (list commit commit-number date-relative date-full) lines))) + (setq commit-number (1- commit-number)) + (forward-line 1)) (nreverse lines))))) (defun git-timemachine-show-current-revision () @@ -77,21 +89,27 @@ (defun git-timemachine-show-revision (revision) "Show a REVISION (commit hash) of the current file." (when revision - (let ((current-position (point))) + (let ((current-position (point)) + (commit (car revision)) + (commit-index (nth 1 revision)) + (date-relative (nth 2 revision)) + (date-full (nth 3 revision))) (setq buffer-read-only nil) (erase-buffer) (let ((default-directory git-timemachine-directory)) (process-file vc-git-program nil t nil "--no-pager" "show" - (concat revision ":" git-timemachine-file))) + (concat commit ":" git-timemachine-file))) (setq buffer-read-only t) (set-buffer-modified-p nil) (let* ((revisions (git-timemachine--revisions)) - (n-of-m (format "(%d/%d)" (- (length revisions) (cl-position revision revisions :test 'equal)) (length revisions)))) + (n-of-m (format "(%d/%d %s)" commit-index (length revisions) date-relative))) (setq mode-line-buffer-identification (list (propertized-buffer-identification "%12b") "@" - (propertize (git-timemachine-abbreviate revision) 'face 'bold) " " n-of-m))) + (propertize (git-timemachine-abbreviate commit) 'face 'bold) " " n-of-m))) (setq git-timemachine-revision revision) - (goto-char current-position)))) + (goto-char current-position) + (when git-timemachine-show-minibuffer-details + (message (format "commit %s %s (%s)" commit date-full date-relative)))))) (defun git-timemachine-abbreviate (revision) "Return REVISION abbreviated to `git-timemachine-abbreviation-length' chars." @@ -105,13 +123,14 @@ (defun git-timemachine-kill-revision () "Kill the current revisions abbreviated commit hash." (interactive) - (message git-timemachine-revision) - (kill-new git-timemachine-revision)) + (let ((revision (car git-timemachine-revision))) + (message revision) + (kill-new revision))) (defun git-timemachine-kill-abbreviated-revision () "Kill the current revisions full commit hash." (interactive) - (let ((revision (git-timemachine-abbreviate git-timemachine-revision))) + (let ((revision (git-timemachine-abbreviate (car git-timemachine-revision)))) (message revision) (kill-new revision))) From 36a3d027e30f245255491e664bb2c71a1f771fc8 Mon Sep 17 00:00:00 2001 From: Stuart Hickinbottom Date: Wed, 5 Nov 2014 22:53:53 +0000 Subject: [PATCH 2/2] Added minibuffer echo customisation to README --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 48be1d4..1ec3349 100644 --- a/README.md +++ b/README.md @@ -27,5 +27,9 @@ Use the following keys to navigate historic version of the file ## Customize Set `git-timemachine-abbreviation-length` (default 12) to your -preferred length for abbreviated commit hashes. Also `M-x customize -[git-timemachine]`. +preferred length for abbreviated commit hashes. + +Set `git-timemachine-show-minibuffer-details` (default t) to control +whether details of the commit are shown in the minibuffer. + +Also `M-x customize [git-timemachine]`.