mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
New commands to apply changes to other working trees
* lisp/vc/diff-mode.el (diff-apply-buffer): New TEST argument. * lisp/vc/vc.el (diff-apply-buffer): Declare. (vc-no-confirm-moving-changes): New user option. (vc-apply-to-other-working-tree) (vc-apply-root-to-other-working-tree): New commands. * lisp/vc/vc-hooks.el (vc-prefix-map): Bind them. * doc/emacs/vc1-xtra.texi (Other Working Trees): * etc/NEWS: Document them.
This commit is contained in:
parent
0000d9b7b1
commit
208e80018a
5 changed files with 227 additions and 32 deletions
|
|
@ -2213,17 +2213,21 @@ customize `diff-ask-before-revert-and-kill-hunk' to control that."
|
|||
(when (null (diff-apply-buffer beg end t))
|
||||
(diff-hunk-kill)))))
|
||||
|
||||
(defun diff-apply-buffer (&optional beg end reverse)
|
||||
(defun diff-apply-buffer (&optional beg end reverse test)
|
||||
"Apply the diff in the entire diff buffer.
|
||||
Interactively, if the region is active, apply all hunks that the region
|
||||
overlaps; otherwise, apply all hunks.
|
||||
With a prefix argument, reverse-apply the hunks.
|
||||
If applying all hunks succeeds, save the changed buffers.
|
||||
|
||||
When called from Lisp with optional arguments, restrict the application
|
||||
to hunks lying between BEG and END, and reverse-apply them when REVERSE
|
||||
is non-nil. Returns nil if buffers were successfully modified and
|
||||
saved, or the number of failed hunk applications otherwise."
|
||||
When called from Lisp, returns nil if buffers were successfully modified
|
||||
and saved, or the number of failed hunk applications otherwise.
|
||||
Optional arguments BEG and END restrict the hunks to be applied to those
|
||||
lying between BEG and END.
|
||||
Optional argument REVERSE means to reverse-apply hunks.
|
||||
Optional argument TEST means to not actually apply or reverse-apply any
|
||||
hunks, but return the same information: nil if all hunks can be applied,
|
||||
or the number of hunks that can't be applied."
|
||||
(interactive (list (use-region-beginning)
|
||||
(use-region-end)
|
||||
current-prefix-arg))
|
||||
|
|
@ -2234,7 +2238,7 @@ saved, or the number of failed hunk applications otherwise."
|
|||
(goto-char (or beg (point-min)))
|
||||
(diff-beginning-of-hunk t)
|
||||
(while (pcase-let ((`(,buf ,line-offset ,pos ,_src ,dst ,switched)
|
||||
(diff-find-source-location nil reverse)))
|
||||
(diff-find-source-location nil reverse test)))
|
||||
(cond ((and line-offset (not switched))
|
||||
(push (cons pos dst)
|
||||
(alist-get buf buffer-edits)))
|
||||
|
|
@ -2244,23 +2248,25 @@ saved, or the number of failed hunk applications otherwise."
|
|||
(or (not end) (< (point) end))
|
||||
(looking-at-p diff-hunk-header-re)))))
|
||||
(cond ((zerop failures)
|
||||
(dolist (buf-edits (reverse buffer-edits))
|
||||
(with-current-buffer (car buf-edits)
|
||||
(dolist (edit (cdr buf-edits))
|
||||
(let ((pos (car edit))
|
||||
(dst (cdr edit))
|
||||
(inhibit-read-only t))
|
||||
(goto-char (car pos))
|
||||
(delete-region (car pos) (cdr pos))
|
||||
(insert (car dst))))
|
||||
(save-buffer)))
|
||||
(message "Saved %d buffers" (length buffer-edits))
|
||||
(unless test
|
||||
(dolist (buf-edits (reverse buffer-edits))
|
||||
(with-current-buffer (car buf-edits)
|
||||
(dolist (edit (cdr buf-edits))
|
||||
(let ((pos (car edit))
|
||||
(dst (cdr edit))
|
||||
(inhibit-read-only t))
|
||||
(goto-char (car pos))
|
||||
(delete-region (car pos) (cdr pos))
|
||||
(insert (car dst))))
|
||||
(save-buffer)))
|
||||
(message "Saved %d buffers" (length buffer-edits)))
|
||||
nil)
|
||||
(t
|
||||
(message (ngettext "%d hunk failed; no buffers changed"
|
||||
"%d hunks failed; no buffers changed"
|
||||
failures)
|
||||
failures)
|
||||
(unless test
|
||||
(message (ngettext "%d hunk failed; no buffers changed"
|
||||
"%d hunks failed; no buffers changed"
|
||||
failures)
|
||||
failures))
|
||||
failures))))
|
||||
|
||||
(defalias 'diff-mouse-goto-source #'diff-goto-source)
|
||||
|
|
@ -2616,7 +2622,7 @@ Call FUN with two args (BEG and END) for each hunk."
|
|||
(or (ignore-errors (diff-hunk-next) (point))
|
||||
max)))))))))
|
||||
|
||||
;; This doesn't use `diff--iterate-hunks', since that assumes that
|
||||
;; This doesn't use `diff--iterate-hunks' because that assumes that
|
||||
;; hunks don't change size.
|
||||
(defun diff--ignore-whitespace-all-hunks ()
|
||||
"Re-diff all the hunks, ignoring whitespace-differences."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue