From 38a5d7631c2d3002aee09a2bc913ba3364b55dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Stiernstr=C3=B6m?= Date: Mon, 18 Aug 2014 23:00:47 +0200 Subject: [PATCH] Added shortcut `W` to copy full sha1 hash. --- README.md | 3 ++- git-timemachine.el | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4bdbf90..d01d28c 100644 --- a/README.md +++ b/README.md @@ -18,5 +18,6 @@ bind it to a keybinding of your choice). Use the following keys to navigate historic version of the file - `p` Visit previous historic version - `n` Visit next historic version - - `w` Copy the hash of the current historic version + - `w` Copy the abbreviated hash of the current historic version + - `W` Copy the full hash of the current historic version - `q` Exit the time machine. diff --git a/git-timemachine.el b/git-timemachine.el index 9468cad..a717df6 100644 --- a/git-timemachine.el +++ b/git-timemachine.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2014 Peter Stiernström ;; Author: Peter Stiernström -;; Version: 1.6 +;; Version: 1.7 ;; URL: https://github.com/pidu/git-timemachine ;; Package-Requires: ((cl-lib "0.5")) ;; Keywords: git @@ -47,8 +47,7 @@ (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" "--abbrev-commit" "--pretty=format:%h" file)) + (unless (zerop (process-file vc-git-program nil t nil "--no-pager" "log" "--abbrev-commit" "--pretty=format:%h" file)) (error "Failed: 'git log --abbrev-commit --pretty=format:%%h' %s" file)) (goto-char (point-min)) (let (lines) @@ -91,17 +90,35 @@ (setq git-timemachine-revision revision) (goto-char current-position)))) +(defun git-timemachine-full-revision () + "Translated the abbreviated revision to its full counter part." + (let ((default-directory git-timemachine-directory) + (revision git-timemachine-revision) + (file git-timemachine-file)) + (with-temp-buffer + (unless (zerop (process-file vc-git-program nil t nil "--no-pager" "rev-parse" revision "--" file)) + (error "Failed: 'git --no-pager rev-parse' %s -- %s" revision file)) + (goto-char (point-min)) + (buffer-substring-no-properties (point) (line-end-position))))) + (defun git-timemachine-quit () "Exit the timemachine." (interactive) (kill-buffer)) (defun git-timemachine-kill-revision () - "Kill the current revisions commit hash." + "Kill the current revisions abbreviated commit hash." (interactive) (message git-timemachine-revision) (kill-new git-timemachine-revision)) +(defun git-timemachine-kill-full-revision () + "Kill the current revisions full commit hash." + (interactive) + (let ((revision (git-timemachine-full-revision))) + (message revision) + (kill-new revision))) + (define-minor-mode git-timemachine-mode "Git Timemachine, feel the wings of history." :init-value nil @@ -110,7 +127,8 @@ '(("p" . git-timemachine-show-previous-revision) ("n" . git-timemachine-show-next-revision) ("q" . git-timemachine-quit) - ("w" . git-timemachine-kill-revision)) + ("w" . git-timemachine-kill-revision) + ("W" . git-timemachine-kill-full-revision)) :group 'git-timemachine) (defun git-timemachine-validate (file)