Functions for applying diffs.

* magit.el (magit-diff-item-write, magit-apply-diff-item): New.
This commit is contained in:
Marius Vollmer 2008-09-13 23:09:51 +03:00
parent a2b7afc6b5
commit c93e41b5bb

View file

@ -998,6 +998,14 @@ Please see the manual for a complete description of Magit.
(magit-section-end diff))))
(write-region beg end file append-p)))
(defun magit-diff-item-write (diff file &optional append-p)
(let ((beg (save-excursion
(goto-char (magit-section-beginning diff))
(forward-line)
(point)))
(end (magit-section-end diff)))
(write-region beg end file append-p)))
(defun magit-write-hunk-item-patch (hunk file)
(magit-diff-item-write-header (magit-hunk-item-diff hunk) file)
(write-region (magit-section-beginning hunk) (magit-section-end hunk)
@ -1026,6 +1034,14 @@ Please see the manual for a complete description of Magit.
(forward-line))
target))))
(defun magit-apply-diff-item (diff &rest args)
(magit-write-diff-item-patch diff ".git/magit-tmp")
(apply #'magit-run "git" "apply" (append args (list ".git/magit-tmp"))))
(defun magit-apply-hunk-item (hunk &rest args)
(magit-write-hunk-item-patch hunk ".git/magit-tmp")
(apply #'magit-run "git" "apply" (append args (list ".git/magit-tmp"))))
(defun magit-insert-unstaged-changes (title)
(let ((magit-hide-diffs t))
(magit-insert-section 'unstaged title 'magit-wash-diffs
@ -1193,10 +1209,6 @@ Please see the manual for a complete description of Magit.
;;; Staging and Unstaging
(defun magit-apply-hunk-item (hunk &rest args)
(magit-write-hunk-item-patch hunk ".git/magit-tmp")
(apply #'magit-run "git" "apply" (append args (list ".git/magit-tmp"))))
(defun magit-stage-item ()
"Add the item at point to the staging area."
(interactive)