From c82931119a22c6d71db879563f57a9cdd285967b Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sat, 20 Feb 2016 13:46:31 +0100 Subject: [PATCH] update git-timemachine. --- .../git-timemachine-pkg.el | 1 - .../git-timemachine-autoloads.el | 9 +- .../git-timemachine-pkg.el | 1 + .../git-timemachine.el | 101 ++++++++++++------ 4 files changed, 79 insertions(+), 33 deletions(-) delete mode 100644 elpa/git-timemachine-20150624.1446/git-timemachine-pkg.el rename elpa/{git-timemachine-20150624.1446 => git-timemachine-20160120.416}/git-timemachine-autoloads.el (70%) create mode 100644 elpa/git-timemachine-20160120.416/git-timemachine-pkg.el rename elpa/{git-timemachine-20150624.1446 => git-timemachine-20160120.416}/git-timemachine.el (74%) diff --git a/elpa/git-timemachine-20150624.1446/git-timemachine-pkg.el b/elpa/git-timemachine-20150624.1446/git-timemachine-pkg.el deleted file mode 100644 index 70635be0..00000000 --- a/elpa/git-timemachine-20150624.1446/git-timemachine-pkg.el +++ /dev/null @@ -1 +0,0 @@ -(define-package "git-timemachine" "20150624.1446" "Walk through git revisions of a file" 'nil :url "https://github.com/pidu/git-timemachine" :keywords '("git")) diff --git a/elpa/git-timemachine-20150624.1446/git-timemachine-autoloads.el b/elpa/git-timemachine-20160120.416/git-timemachine-autoloads.el similarity index 70% rename from elpa/git-timemachine-20150624.1446/git-timemachine-autoloads.el rename to elpa/git-timemachine-20160120.416/git-timemachine-autoloads.el index d4faa6fa..ace999b3 100644 --- a/elpa/git-timemachine-20150624.1446/git-timemachine-autoloads.el +++ b/elpa/git-timemachine-20160120.416/git-timemachine-autoloads.el @@ -3,8 +3,8 @@ ;;; Code: (add-to-list 'load-path (or (file-name-directory #$) (car load-path))) -;;;### (autoloads nil "git-timemachine" "git-timemachine.el" (21908 -;;;;;; 14267 0 0)) +;;;### (autoloads nil "git-timemachine" "git-timemachine.el" (22215 +;;;;;; 7686 0 0)) ;;; Generated autoloads from git-timemachine.el (autoload 'git-timemachine-toggle "git-timemachine" "\ @@ -17,6 +17,11 @@ Enable git timemachine for file of current buffer. \(fn)" t nil) +(autoload 'git-timemachine-switch-branch "git-timemachine" "\ +Enable git timemachine for current buffer, switching to GIT-BRANCH. + +\(fn GIT-BRANCH)" t nil) + ;;;*** ;; Local Variables: diff --git a/elpa/git-timemachine-20160120.416/git-timemachine-pkg.el b/elpa/git-timemachine-20160120.416/git-timemachine-pkg.el new file mode 100644 index 00000000..f388f2ae --- /dev/null +++ b/elpa/git-timemachine-20160120.416/git-timemachine-pkg.el @@ -0,0 +1 @@ +(define-package "git-timemachine" "20160120.416" "Walk through git revisions of a file" 'nil :url "https://github.com/pidu/git-timemachine" :keywords '("git")) diff --git a/elpa/git-timemachine-20150624.1446/git-timemachine.el b/elpa/git-timemachine-20160120.416/git-timemachine.el similarity index 74% rename from elpa/git-timemachine-20150624.1446/git-timemachine.el rename to elpa/git-timemachine-20160120.416/git-timemachine.el index deb874a7..4281b3ea 100644 --- a/elpa/git-timemachine-20150624.1446/git-timemachine.el +++ b/elpa/git-timemachine-20160120.416/git-timemachine.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2014 Peter Stiernström ;; Author: Peter Stiernström -;; Version: 2.7 -;; Package-Version: 20150624.1446 +;; Version: 3.0 +;; Package-Version: 20160120.416 ;; URL: https://github.com/pidu/git-timemachine ;; Keywords: git @@ -52,6 +52,11 @@ will be shown in the minibuffer while navigating commits." "How to display the minibuffer detail" :group 'git-timemachine) +(defface git-timemachine-minibuffer-author-face + '((t (:foreground "orange"))) + "How to display the author in minibuffer" + :group 'git-timemachine) + (defcustom git-timemachine-minibuffer-detail 'subject "What to display when `git-timemachine-show-minibuffer-details` is t. @@ -61,13 +66,28 @@ Available values are: :type '(radio (const :tag "Commit SHA" commit) (const :tag "Commit Subject" subject)) :group 'git-timemachine) +(defcustom git-timemachine-show-author + t + "Prepend author to minibuffer details." + :type 'boolean + :group 'git-timemachine) + (defvar-local git-timemachine-directory nil) (defvar-local git-timemachine-revision nil) (defvar-local git-timemachine-file nil) (defvar-local git-timemachine--revisions-cache nil) -(defun git-timemachine--revisions () - "List git revisions of current buffers file." +(defun git-timemachine-completing-read-fn (&rest args) + "Apply ARGS to `ido-completing-read' if available and fall back to `completing-read'." + (if (fboundp 'ido-completing-read) + (apply 'ido-completing-read args) + (apply 'completing-read args) + )) + +(defun git-timemachine--revisions (&optional git-branch) + "List git revisions of current buffers file. + +When passed a GIT-BRANCH, lists revisions from that branch." (if git-timemachine--revisions-cache git-timemachine--revisions-cache (setq git-timemachine--revisions-cache @@ -76,21 +96,26 @@ Available values are: (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" "--name-only" "--follow" "--pretty=format:%H:%ar:%ad:%s" file)) + + (unless (zerop (if git-branch + (process-file vc-git-program nil t nil "--no-pager" "log" git-branch "--name-only" "--follow" "--pretty=format:%H%x00%ar%x00%ad%x00%s%x00%an" "--" file) + (process-file vc-git-program nil t nil "--no-pager" "log" "--name-only" "--follow" "--pretty=format:%H%x00%ar%x00%ad%x00%s%x00%an" "--" file))) (error "Git log command exited with non-zero exit status for file: %s" file)) + (goto-char (point-min)) (let ((lines) (commit-number (/ (1+ (count-lines (point-min) (point-max))) 3))) (while (not (eobp)) (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) - (string-match "\\([^:]*\\):\\([^:]*\\):\\(.*\\):\\(.*\\)" line) + (string-match "\\([^\0]*\\)\0\\([^\0]*\\)\0\\([^\0]*\\)\0\\(.*\\)\0\\(.*\\)" line) (let ((commit (match-string 1 line)) (date-relative (match-string 2 line)) (date-full (match-string 3 line)) - (subject (match-string 4 line))) + (subject (match-string 4 line)) + (author (match-string 5 line))) (forward-line 1) (let ((file-name (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) - (push (list commit file-name commit-number date-relative date-full subject) lines)))) + (push (list commit file-name commit-number date-relative date-full subject author) lines)))) (setq commit-number (1- commit-number)) (forward-line 2)) (nreverse lines)))) @@ -101,9 +126,15 @@ Available values are: (interactive) (git-timemachine-show-revision (car (git-timemachine--revisions)))) +(defun git-timemachine-show-latest-revision-in-branch (git-branch) + "Show last (current) revision of file in GIT-BRANCH." + (interactive "MGit branch: ") + (git-timemachine-show-revision (car (git-timemachine--revisions git-branch)))) + (defun git-timemachine--next-revision (revisions) "Return the revision following the current revision in REVISIONS." - (cadr (cl-member (car git-timemachine-revision) revisions :key #'car :test #'string=))) + (or (cadr (cl-member (car git-timemachine-revision) revisions :key #'car :test #'string=)) + (car (reverse revisions)))) (defun git-timemachine-show-previous-revision () "Show previous revision of file." @@ -153,13 +184,13 @@ Available values are: (defun git-timemachine--show-minibuffer-details (revision) "Show details for REVISION in minibuffer." - (let ((detail - (if (eq git-timemachine-minibuffer-detail 'commit) - (car revision) - (nth 5 revision))) - (date-relative (nth 3 revision)) - (date-full (nth 4 revision))) - (message (format "%s [%s (%s)]" (propertize detail 'face 'git-timemachine-minibuffer-detail-face) date-full date-relative)))) + (let* ((date-relative (nth 3 revision)) + (date-full (nth 4 revision)) + (author (if git-timemachine-show-author (concat (nth 6 revision) ": ") "")) + (sha-or-subject (if (eq git-timemachine-minibuffer-detail 'commit) (car revision) (nth 5 revision)))) + (message "%s%s [%s (%s)]" + (propertize author 'face 'git-timemachine-minibuffer-author-face) + (propertize sha-or-subject 'face 'git-timemachine-minibuffer-detail-face) date-full date-relative))) (defun git-timemachine-abbreviate (revision) "Return REVISION abbreviated to `git-timemachine-abbreviation-length' chars." @@ -205,18 +236,8 @@ Call with the value of 'buffer-file-name." (unless (vc-git-registered file) (error "This file is not git tracked"))) -;;;###autoload -(defun git-timemachine-toggle () - "Toggle git timemachine mode." - (interactive) - (if (bound-and-true-p git-timemachine-mode) - (git-timemachine-quit) - (git-timemachine))) - -;;;###autoload -(defun git-timemachine () - "Enable git timemachine for file of current buffer." - (interactive) +(defun git-timemachine--start (get-revision-fn) + "Setup a timemachine buffer and populate it from the result of GET-REVISION-FN." (setq git-timemachine--revisions-cache nil) (git-timemachine-validate (buffer-file-name)) (let ((git-directory (expand-file-name (vc-git-root (buffer-file-name)))) @@ -230,12 +251,32 @@ Call with the value of 'buffer-file-name." (funcall mode) (setq git-timemachine-directory git-directory git-timemachine-file (file-relative-name file-name git-directory) - git-timemachine-revision nil) - (git-timemachine-show-current-revision) + git-timemachine-revision nil) + (funcall get-revision-fn) (goto-char (point-min)) (forward-line (1- cur-line)) (git-timemachine-mode)))) +;;;###autoload +(defun git-timemachine-toggle () + "Toggle git timemachine mode." + (interactive) + (if (bound-and-true-p git-timemachine-mode) + (git-timemachine-quit) + (git-timemachine))) + +;;;###autoload +(defun git-timemachine () + "Enable git timemachine for file of current buffer." + (interactive) + (git-timemachine--start #'git-timemachine-show-current-revision)) + +;;;###autoload +(defun git-timemachine-switch-branch (git-branch) + "Enable git timemachine for current buffer, switching to GIT-BRANCH." + (interactive (list (git-timemachine-completing-read-fn "Branch to switch to: "(vc-git-branches)))) + (git-timemachine--start (lambda () (git-timemachine-show-latest-revision-in-branch git-branch)))) + (provide 'git-timemachine) ;;; git-timemachine.el ends here -- 2.47.3