Commit d43af7b6 authored by Juri Linkov's avatar Juri Linkov

* lisp/vc/vc.el (vc-diff-mergebase, vc-log-mergebase): New commands.

* lisp/vc/vc-git.el (vc-git-mergebase): New function.
(vc-git-print-log): Interpret string value of arg LIMIT as an end-revision.

* lisp/vc/vc-hooks.el (vc-prefix-map): Bind 'vc-log-mergebase' to
'C-x v M L', and 'vc-diff-mergebase' to 'C-x v M D'.  (Bug#33950)
parent db53731c
Pipeline #1077 failed with stage
in 60 minutes and 2 seconds
......@@ -511,6 +511,10 @@ and compares their entire trees.
*** New user option 'vc-hg-revert-switches' specifies switches to pass
to hg revert.
*** 'C-x v M D' ('vc-diff-mergebase') and 'C-x v M L' ('vc-log-mergebase')
print diffs and logs between the merge base (common ancestor) of two
given revisions.
** Diff mode
+++
*** Hunks are now automatically refined by font-lock.
......
......@@ -101,6 +101,7 @@
(eval-when-compile
(require 'cl-lib)
(require 'subr-x) ; for string-trim-right
(require 'vc)
(require 'vc-dir))
......@@ -1017,7 +1018,8 @@ This prompts for a branch to merge from."
If SHORTLOG is non-nil, use a short format based on `vc-git-root-log-format'.
\(This requires at least Git version 1.5.6, for the --graph option.)
If START-REVISION is non-nil, it is the newest revision to show.
If LIMIT is non-nil, show no more than this many entries."
If LIMIT is a number, show no more than this many entries.
If LIMIT is a revision string, use it as an end-revision."
(let ((coding-system-for-read
(or coding-system-for-read vc-git-log-output-coding-system)))
;; `vc-do-command' creates the buffer, but we need it before running
......@@ -1045,8 +1047,14 @@ If LIMIT is non-nil, show no more than this many entries."
,(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 ".." (if (equal limit "")
"HEAD"
limit)))
(list start-revision)))
'("--")))))))
(defun vc-git-log-outgoing (buffer remote-location)
......@@ -1077,6 +1085,10 @@ If LIMIT is non-nil, show no more than this many entries."
"@{upstream}"
remote-location))))
(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)
......@@ -1093,7 +1105,7 @@ If LIMIT is non-nil, show no more than this many entries."
(cadr vc-git-root-log-format)
"^commit *\\([0-9a-z]+\\)"))
;; Allow expanding short log entries.
(when (memq vc-log-view-type '(short log-outgoing log-incoming))
(when (memq vc-log-view-type '(short log-outgoing log-incoming mergebase))
(setq truncate-lines t)
(set (make-local-variable 'log-view-expanded-log-entry-function)
'vc-git-expanded-log-entry))
......
......@@ -890,6 +890,8 @@ In the latter case, VC mode is deactivated for this buffer."
(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)
......
......@@ -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
;;
......@@ -1854,6 +1858,33 @@ saving the buffer."
(vc-diff-internal t (vc-deduce-fileset t) nil nil
(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
(or (ignore-errors (vc-deduce-fileset t))
(let ((backend (or (vc-deduce-backend) (vc-responsible-backend default-directory))))
(list backend (list (vc-call-backend backend 'root default-directory)))))))
(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)))))
(declare-function ediff-load-version-control "ediff" (&optional silent))
(declare-function ediff-vc-internal "ediff-vers"
(rev1 rev2 &optional startup-hooks))
......@@ -2484,6 +2515,28 @@ When called interactively with a prefix argument, prompt for REMOTE-LOCATION."
(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
(or (ignore-errors (vc-deduce-fileset t))
(let ((backend (or (vc-deduce-backend) (vc-responsible-backend default-directory))))
(list backend (list (vc-call-backend backend 'root default-directory)))))))
(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)
(setq rev1 (vc-call-backend backend 'mergebase rev1 rev2))
(vc-print-log-internal backend (list rootdir) rev1 t (or rev2 ""))))
;;;###autoload
(defun vc-region-history (from to)
"Show the history of the region between FROM and TO.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment