From 9849897f59fa7ed0e0df0666165c06aed94f0bc1 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Tue, 11 Aug 2015 16:57:39 +0200 Subject: magit-wip-log{,-current}: new commands --- Documentation/RelNotes/2.2.0.txt | 4 +++ Documentation/magit.org | 25 ++++++++++++++++--- lisp/Makefile | 4 +-- lisp/magit-wip.el | 53 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/Documentation/RelNotes/2.2.0.txt b/Documentation/RelNotes/2.2.0.txt index d0e4aa1..3c30ffe6 100644 --- a/Documentation/RelNotes/2.2.0.txt +++ b/Documentation/RelNotes/2.2.0.txt @@ -101,6 +101,10 @@ THIS IS NOT COMPLETE. disagree, so the option `magit-branch-read-upstream-first' has been added. It defaults to t. +* New commands `magit-wip-log' and `magit-wip-log-current' allow + showing log for a branch and its wip refs (which the various wip + modes commit to). + * New command `magit-submodule-deinit'. * New command `magit-commit-augment' allows the user to pick a commit diff --git a/Documentation/magit.org b/Documentation/magit.org index 7595a54..ed10044 100644 --- a/Documentation/magit.org +++ b/Documentation/magit.org @@ -3561,10 +3561,27 @@ commit does not change the fork-point of the working tree wip ref. The fork-points are not adjusted until there actually is a change that should be committed to the respective wip ref. -To recover a lost change from a wip ref, use the reflog. To show the -reflog, use e.g. ~lO refs/wip/index/refs/heads/master RET~ and then move -around until you find the commit which has the lost change. You might -then be able to simply apply it using ~a~ (~magit-apply~). +To view the log for the a branch and its wip refs use the commands +~magit-wip-log~ and ~magit-wip-log-current~. You should use ~--graph~ when +using these commands. Alternatively you can use the reflog to show +all commits that ever existed on a wip ref. You can then recover lost +changes from the commits shown in the log or reflog. + +- Command: magit-wip-log + + This command shows the log for a branch and its wip refs. + + With a negative prefix argument only the worktree wip ref is shown. + The absolute numeric value of the prefix argument controls how many + "branches" of each wip ref are shown. + +- Command: magit-wip-log-current + + This command shows the log for the current branch and its wip refs. + + With a negative prefix argument only the worktree wip ref is shown. + The absolute numeric value of the prefix argument controls how many + "branches" of each wip ref are shown. There exists a total of three global modes that save to the wip refs, which might seem excessive, but allows fine tuning of when exactly 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: -- cgit v1.0