aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2019-03-25 23:45:31 +0200
committerJuri Linkov2019-03-25 23:45:31 +0200
commitd43af7b64bd22724e5e9a624bcc06b4ed28faf73 (patch)
treec67ea4d1d90dca703dccfa0106c181dc109d676e
parentdb53731c5f7e11240244161623b82b55cf303043 (diff)
downloademacs-d43af7b64bd22724e5e9a624bcc06b4ed28faf73.tar.gz
emacs-d43af7b64bd22724e5e9a624bcc06b4ed28faf73.zip
* 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)
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/vc/vc-git.el20
-rw-r--r--lisp/vc/vc-hooks.el2
-rw-r--r--lisp/vc/vc.el53
4 files changed, 75 insertions, 4 deletions
diff --git a/etc/NEWS b/etc/NEWS
index ad01bd8516b..afee1e1dcad 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -511,6 +511,10 @@ and compares their entire trees.
511*** New user option 'vc-hg-revert-switches' specifies switches to pass 511*** New user option 'vc-hg-revert-switches' specifies switches to pass
512to hg revert. 512to hg revert.
513 513
514*** 'C-x v M D' ('vc-diff-mergebase') and 'C-x v M L' ('vc-log-mergebase')
515print diffs and logs between the merge base (common ancestor) of two
516given revisions.
517
514** Diff mode 518** Diff mode
515+++ 519+++
516*** Hunks are now automatically refined by font-lock. 520*** Hunks are now automatically refined by font-lock.
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 0f8c9c836ce..a921ff1bb88 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -101,6 +101,7 @@
101 101
102(eval-when-compile 102(eval-when-compile
103 (require 'cl-lib) 103 (require 'cl-lib)
104 (require 'subr-x) ; for string-trim-right
104 (require 'vc) 105 (require 'vc)
105 (require 'vc-dir)) 106 (require 'vc-dir))
106 107
@@ -1017,7 +1018,8 @@ This prompts for a branch to merge from."
1017If SHORTLOG is non-nil, use a short format based on `vc-git-root-log-format'. 1018If SHORTLOG is non-nil, use a short format based on `vc-git-root-log-format'.
1018\(This requires at least Git version 1.5.6, for the --graph option.) 1019\(This requires at least Git version 1.5.6, for the --graph option.)
1019If START-REVISION is non-nil, it is the newest revision to show. 1020If START-REVISION is non-nil, it is the newest revision to show.
1020If LIMIT is non-nil, show no more than this many entries." 1021If LIMIT is a number, show no more than this many entries.
1022If LIMIT is a revision string, use it as an end-revision."
1021 (let ((coding-system-for-read 1023 (let ((coding-system-for-read
1022 (or coding-system-for-read vc-git-log-output-coding-system))) 1024 (or coding-system-for-read vc-git-log-output-coding-system)))
1023 ;; `vc-do-command' creates the buffer, but we need it before running 1025 ;; `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."
1045 ,(format "--pretty=tformat:%s" 1047 ,(format "--pretty=tformat:%s"
1046 (car vc-git-root-log-format)) 1048 (car vc-git-root-log-format))
1047 "--abbrev-commit")) 1049 "--abbrev-commit"))
1048 (when limit (list "-n" (format "%s" limit))) 1050 (when (numberp limit)
1049 (when start-revision (list start-revision)) 1051 (list "-n" (format "%s" limit)))
1052 (when start-revision
1053 (if (and limit (not (numberp limit)))
1054 (list (concat start-revision ".." (if (equal limit "")
1055 "HEAD"
1056 limit)))
1057 (list start-revision)))
1050 '("--"))))))) 1058 '("--")))))))
1051 1059
1052(defun vc-git-log-outgoing (buffer remote-location) 1060(defun vc-git-log-outgoing (buffer remote-location)
@@ -1077,6 +1085,10 @@ If LIMIT is non-nil, show no more than this many entries."
1077 "@{upstream}" 1085 "@{upstream}"
1078 remote-location)))) 1086 remote-location))))
1079 1087
1088(defun vc-git-mergebase (rev1 &optional rev2)
1089 (unless rev2 (setq rev2 "HEAD"))
1090 (string-trim-right (vc-git--run-command-string nil "merge-base" rev1 rev2)))
1091
1080(defvar log-view-message-re) 1092(defvar log-view-message-re)
1081(defvar log-view-file-re) 1093(defvar log-view-file-re)
1082(defvar log-view-font-lock-keywords) 1094(defvar log-view-font-lock-keywords)
@@ -1093,7 +1105,7 @@ If LIMIT is non-nil, show no more than this many entries."
1093 (cadr vc-git-root-log-format) 1105 (cadr vc-git-root-log-format)
1094 "^commit *\\([0-9a-z]+\\)")) 1106 "^commit *\\([0-9a-z]+\\)"))
1095 ;; Allow expanding short log entries. 1107 ;; Allow expanding short log entries.
1096 (when (memq vc-log-view-type '(short log-outgoing log-incoming)) 1108 (when (memq vc-log-view-type '(short log-outgoing log-incoming mergebase))
1097 (setq truncate-lines t) 1109 (setq truncate-lines t)
1098 (set (make-local-variable 'log-view-expanded-log-entry-function) 1110 (set (make-local-variable 'log-view-expanded-log-entry-function)
1099 'vc-git-expanded-log-entry)) 1111 'vc-git-expanded-log-entry))
diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index 2052ace12bf..07b3d86b518 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -890,6 +890,8 @@ In the latter case, VC mode is deactivated for this buffer."
890 (define-key map "L" 'vc-print-root-log) 890 (define-key map "L" 'vc-print-root-log)
891 (define-key map "I" 'vc-log-incoming) 891 (define-key map "I" 'vc-log-incoming)
892 (define-key map "O" 'vc-log-outgoing) 892 (define-key map "O" 'vc-log-outgoing)
893 (define-key map "ML" 'vc-log-mergebase)
894 (define-key map "MD" 'vc-diff-mergebase)
893 (define-key map "m" 'vc-merge) 895 (define-key map "m" 'vc-merge)
894 (define-key map "r" 'vc-retrieve-tag) 896 (define-key map "r" 'vc-retrieve-tag)
895 (define-key map "s" 'vc-create-tag) 897 (define-key map "s" 'vc-create-tag)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 0a638ec7d7f..e6f30c9f804 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -429,6 +429,10 @@
429;; - region-history-mode () 429;; - region-history-mode ()
430;; 430;;
431;; Major mode to use for the output of `region-history'. 431;; Major mode to use for the output of `region-history'.
432;;
433;; - mergebase (rev1 &optional rev2)
434;;
435;; Return the common ancestor between REV1 and REV2 revisions.
432 436
433;; TAG SYSTEM 437;; TAG SYSTEM
434;; 438;;
@@ -1854,6 +1858,33 @@ saving the buffer."
1854 (vc-diff-internal t (vc-deduce-fileset t) nil nil 1858 (vc-diff-internal t (vc-deduce-fileset t) nil nil
1855 (called-interactively-p 'interactive)))) 1859 (called-interactively-p 'interactive))))
1856 1860
1861;;;###autoload
1862(defun vc-diff-mergebase (_files rev1 rev2)
1863 "Report diffs between the merge base of REV1 and REV2 revisions.
1864The merge base is a common ancestor between REV1 and REV2 revisions."
1865 (interactive
1866 (vc-diff-build-argument-list-internal
1867 (or (ignore-errors (vc-deduce-fileset t))
1868 (let ((backend (or (vc-deduce-backend) (vc-responsible-backend default-directory))))
1869 (list backend (list (vc-call-backend backend 'root default-directory)))))))
1870 (when (and (not rev1) rev2)
1871 (error "Not a valid revision range"))
1872 (let ((backend (vc-deduce-backend))
1873 (default-directory default-directory)
1874 rootdir)
1875 (if backend
1876 (setq rootdir (vc-call-backend backend 'root default-directory))
1877 (setq rootdir (read-directory-name "Directory for VC root-diff: "))
1878 (setq backend (vc-responsible-backend rootdir))
1879 (if backend
1880 (setq default-directory rootdir)
1881 (error "Directory is not version controlled")))
1882 (let ((default-directory rootdir)
1883 (rev1 (vc-call-backend backend 'mergebase rev1 rev2)))
1884 (vc-diff-internal
1885 t (list backend (list rootdir)) rev1 rev2
1886 (called-interactively-p 'interactive)))))
1887
1857(declare-function ediff-load-version-control "ediff" (&optional silent)) 1888(declare-function ediff-load-version-control "ediff" (&optional silent))
1858(declare-function ediff-vc-internal "ediff-vers" 1889(declare-function ediff-vc-internal "ediff-vers"
1859 (rev1 rev2 &optional startup-hooks)) 1890 (rev1 rev2 &optional startup-hooks))
@@ -2485,6 +2516,28 @@ When called interactively with a prefix argument, prompt for REMOTE-LOCATION."
2485 "*vc-outgoing*" 'log-outgoing))) 2516 "*vc-outgoing*" 'log-outgoing)))
2486 2517
2487;;;###autoload 2518;;;###autoload
2519(defun vc-log-mergebase (_files rev1 rev2)
2520 "Show a log of changes between the merge base of REV1 and REV2 revisions.
2521The merge base is a common ancestor between REV1 and REV2 revisions."
2522 (interactive
2523 (vc-diff-build-argument-list-internal
2524 (or (ignore-errors (vc-deduce-fileset t))
2525 (let ((backend (or (vc-deduce-backend) (vc-responsible-backend default-directory))))
2526 (list backend (list (vc-call-backend backend 'root default-directory)))))))
2527 (let ((backend (vc-deduce-backend))
2528 (default-directory default-directory)
2529 rootdir)
2530 (if backend
2531 (setq rootdir (vc-call-backend backend 'root default-directory))
2532 (setq rootdir (read-directory-name "Directory for VC root-log: "))
2533 (setq backend (vc-responsible-backend rootdir))
2534 (unless backend
2535 (error "Directory is not version controlled")))
2536 (setq default-directory rootdir)
2537 (setq rev1 (vc-call-backend backend 'mergebase rev1 rev2))
2538 (vc-print-log-internal backend (list rootdir) rev1 t (or rev2 ""))))
2539
2540;;;###autoload
2488(defun vc-region-history (from to) 2541(defun vc-region-history (from to)
2489 "Show the history of the region between FROM and TO. 2542 "Show the history of the region between FROM and TO.
2490 2543