* bug#33950: 27.0.50; Merge-base alias for git vc-diff
@ 2019-01-02 0:11 Juri Linkov
2019-03-25 21:45 ` Juri Linkov
0 siblings, 1 reply; 3+ messages in thread
From: Juri Linkov @ 2019-01-02 0:11 UTC (permalink / raw)
To: 33950
[-- Attachment #1: Type: text/plain, Size: 126 bytes --]
Following https://lists.gnu.org/archive/html/emacs-devel/2018-12/msg00446.html
here's the patch that implement this feature:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-mergebase.patch --]
[-- Type: text/x-diff, Size: 4432 bytes --]
diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index 84e11f2e01..f32e536981 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -890,6 +890,8 @@ vc-prefix-map
(define-key map "L" 'vc-print-root-log)
(define-key map "I" 'vc-log-incoming)
(define-key map "O" 'vc-log-outgoing)
+ (define-key map "ML" 'vc-log-mergebase)
+ (define-key map "MD" 'vc-diff-mergebase)
(define-key map "m" 'vc-merge)
(define-key map "r" 'vc-retrieve-tag)
(define-key map "s" 'vc-create-tag)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 48b7c98dfa..ccd03c4427 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -429,6 +429,10 @@
;; - region-history-mode ()
;;
;; Major mode to use for the output of `region-history'.
+;;
+;; - mergebase (rev1 &optional rev2)
+;;
+;; Return the common ancestor between REV1 and REV2 revisions.
;; TAG SYSTEM
;;
@@ -1849,6 +1853,30 @@ vc-root-version-diff
t (list backend (list rootdir)) rev1 rev2
(called-interactively-p 'interactive)))))
+
+;;;###autoload
+(defun vc-diff-mergebase (_files rev1 rev2)
+ "Report diffs between the merge base of REV1 and REV2 revisions.
+The merge base is a common ancestor between REV1 and REV2 revisions."
+ (interactive (vc-diff-build-argument-list-internal))
+ (when (and (not rev1) rev2)
+ (error "Not a valid revision range"))
+ (let ((backend (vc-deduce-backend))
+ (default-directory default-directory)
+ rootdir)
+ (if backend
+ (setq rootdir (vc-call-backend backend 'root default-directory))
+ (setq rootdir (read-directory-name "Directory for VC root-diff: "))
+ (setq backend (vc-responsible-backend rootdir))
+ (if backend
+ (setq default-directory rootdir)
+ (error "Directory is not version controlled")))
+ (let ((default-directory rootdir)
+ (rev1 (vc-call-backend backend 'mergebase rev1 rev2)))
+ (vc-diff-internal
+ t (list backend (list rootdir)) rev1 rev2
+ (called-interactively-p 'interactive)))))
+
;;;###autoload
(defun vc-diff (&optional historic not-urgent)
"Display diffs between file revisions.
@@ -2491,6 +2519,25 @@ vc-log-outgoing
(vc-incoming-outgoing-internal backend (or remote-location "")
"*vc-outgoing*" 'log-outgoing)))
+;;;###autoload
+(defun vc-log-mergebase (_files rev1 rev2)
+ "Show a log of changes between the merge base of REV1 and REV2 revisions.
+The merge base is a common ancestor between REV1 and REV2 revisions."
+ (interactive (vc-diff-build-argument-list-internal))
+ (let ((backend (vc-deduce-backend))
+ (default-directory default-directory)
+ rootdir)
+ (if backend
+ (setq rootdir (vc-call-backend backend 'root default-directory))
+ (setq rootdir (read-directory-name "Directory for VC root-log: "))
+ (setq backend (vc-responsible-backend rootdir))
+ (unless backend
+ (error "Directory is not version controlled")))
+ (setq default-directory rootdir)
+ (unless rev2 (setq rev2 "HEAD"))
+ (setq rev1 (vc-call-backend backend 'mergebase rev1 rev2))
+ (vc-print-log-internal backend (list rootdir) rev1 t rev2)))
+
;;;###autoload
(defun vc-region-history (from to)
"Show the history of the region between FROM and TO.
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index aa6809f626..82ff2b58e7 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1045,8 +1045,12 @@ vc-git-print-log
,(format "--pretty=tformat:%s"
(car vc-git-root-log-format))
"--abbrev-commit"))
- (when limit (list "-n" (format "%s" limit)))
- (when start-revision (list start-revision))
+ (when (numberp limit)
+ (list "-n" (format "%s" limit)))
+ (when start-revision
+ (if (and limit (not (numberp limit)))
+ (list (concat start-revision ".." limit))
+ (list start-revision)))
'("--")))))))
(defun vc-git-log-outgoing (buffer remote-location)
@@ -1077,6 +1081,12 @@ vc-git-log-incoming
"@{upstream}"
remote-location))))
+(eval-when-compile (require 'subr-x)) ; for string-trim-right
+
+(defun vc-git-mergebase (rev1 &optional rev2)
+ (unless rev2 (setq rev2 "HEAD"))
+ (string-trim-right (vc-git--run-command-string nil "merge-base" rev1 rev2)))
+
(defvar log-view-message-re)
(defvar log-view-file-re)
(defvar log-view-font-lock-keywords)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#33950: 27.0.50; Merge-base alias for git vc-diff
2019-01-02 0:11 bug#33950: 27.0.50; Merge-base alias for git vc-diff Juri Linkov
@ 2019-03-25 21:45 ` Juri Linkov
2019-04-01 23:29 ` Dmitry Gutov
0 siblings, 1 reply; 3+ messages in thread
From: Juri Linkov @ 2019-03-25 21:45 UTC (permalink / raw)
To: 33950-done
> Following https://lists.gnu.org/archive/html/emacs-devel/2018-12/msg00446.html
> here's the patch that implement this feature:
Today a coworker asked me how she can view all changes on her branch
so she could revert one of them. I showed her how easy is just to
type 'C-x v M D' (vc-diff-mergebase) and enter two revisions: master
and the name of her branch, that quickly solved her problem.
So now I installed this feature that demonstrated its easy use.
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#33950: 27.0.50; Merge-base alias for git vc-diff
2019-03-25 21:45 ` Juri Linkov
@ 2019-04-01 23:29 ` Dmitry Gutov
0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Gutov @ 2019-04-01 23:29 UTC (permalink / raw)
To: 33950, juri
On 25.03.2019 23:45, Juri Linkov wrote:
>> Following https://lists.gnu.org/archive/html/emacs-devel/2018-12/msg00446.html
>> here's the patch that implement this feature:
>
> Today a coworker asked me how she can view all changes on her branch
> so she could revert one of them. I showed her how easy is just to
> type 'C-x v M D' (vc-diff-mergebase) and enter two revisions: master
> and the name of her branch, that quickly solved her problem.
>
> So now I installed this feature that demonstrated its easy use.
Thank you, and good job!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-01 23:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-02 0:11 bug#33950: 27.0.50; Merge-base alias for git vc-diff Juri Linkov
2019-03-25 21:45 ` Juri Linkov
2019-04-01 23:29 ` Dmitry Gutov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.