aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2015-08-11 16:57:39 +0200
committerJonas Bernoulli <jonas@bernoul.li>2015-08-11 16:57:39 +0200
commit9849897f59fa7ed0e0df0666165c06aed94f0bc1 (patch)
tree72c8a6d7401bbf8fbc5c950e0a51be14dd4d8532 /lisp
parente29087e6f8a070349f8d60c7374dc8356887a0ed (diff)
magit-wip-log{,-current}: new commands
Diffstat (limited to 'lisp')
-rw-r--r--lisp/Makefile4
-rw-r--r--lisp/magit-wip.el53
2 files changed, 55 insertions, 2 deletions
diff --git a/lisp/Makefile b/lisp/Makefile
index bfc5ce8..056065d 100644
--- a/lisp/Makefile
+++ b/lisp/Makefile
@@ -17,9 +17,9 @@ magit-process.elc: with-editor.elc magit-utils.elc magit-section.elc \
magit-core.elc: magit-utils.elc magit-section.elc magit-git.elc \
magit-mode.elc magit-popup.elc magit-process.elc
magit-diff.elc: git-commit.elc magit-core.elc
-magit-wip.elc: magit-core.elc
-magit-apply.elc: magit-core.elc magit-diff.elc magit-wip.elc
magit-log.elc: magit-core.elc magit-diff.elc
+magit-wip.elc: magit-core.elc magit-log.elc
+magit-apply.elc: magit-core.elc magit-diff.elc magit-wip.elc
magit.elc: with-editor.elc git-commit.elc \
magit-core.elc magit-diff.elc magit-apply.elc magit-log.elc
magit-sequence.elc: magit.elc
diff --git a/lisp/magit-wip.el b/lisp/magit-wip.el
index 4be9d13..e424892 100644
--- a/lisp/magit-wip.el
+++ b/lisp/magit-wip.el
@@ -31,6 +31,7 @@
;;; Code:
(require 'magit-core)
+(require 'magit-log)
(require 'format-spec)
;;; Options
@@ -228,6 +229,58 @@ only commit changes to FILES using MSG as commit message."
wipref
ref))
+;;; Log
+
+(defun magit-wip-log-current (branch args files count)
+ "Show log for the current branch and its wip refs.
+With a negative prefix argument only show the worktree wip ref.
+The absolute numeric value of the prefix argument controls how
+many \"branches\" of each wip ref are shown."
+ (interactive
+ (nconc (list (or (magit-get-current-branch) "HEAD"))
+ (magit-log-arguments)
+ (list (prefix-numeric-value current-prefix-arg))))
+ (magit-wip-log branch args files count))
+
+(defun magit-wip-log (branch args files count)
+ "Show log for a branch and its wip refs.
+With a negative prefix argument only show the worktree wip ref.
+The absolute numeric value of the prefix argument controls how
+many \"branches\" of each wip ref are shown."
+ (interactive
+ (nconc (list (magit-completing-read
+ "Log branch and its wip refs"
+ (-snoc (magit-list-local-branch-names) "HEAD")
+ nil t nil 'magit-revision-history
+ (or (magit-branch-at-point)
+ (magit-get-current-branch)
+ "HEAD")))
+ (magit-log-arguments)
+ (list (prefix-numeric-value current-prefix-arg))))
+ (unless (equal branch "HEAD")
+ (setq branch (concat "refs/heads/" branch)))
+ (magit-log (nconc (list branch)
+ (magit-wip-log-get-tips
+ (concat magit-wip-namespace "wtree/" branch)
+ (abs count))
+ (and (>= count 0)
+ (magit-wip-log-get-tips
+ (concat magit-wip-namespace "index/" branch)
+ (abs count))))
+ args files))
+
+(defun magit-wip-log-get-tips (wipref count)
+ (let ((reflog (magit-git-lines "reflog" wipref)) tips)
+ (while (and reflog (> count 1))
+ (setq reflog (cl-member "^[^ ]+ [^:]+: restart autosaving"
+ reflog :test #'string-match-p))
+ (when (and (cadr reflog)
+ (string-match "^[^ ]+ \\([^:]+\\)" (cadr reflog)))
+ (push (match-string 1 (cadr reflog)) tips))
+ (setq reflog (cddr reflog))
+ (cl-decf count))
+ (cons wipref (nreverse tips))))
+
;;; magit-wip.el ends soon
(provide 'magit-wip)
;; Local Variables: