emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit 5043c0c487 1/6: magit-diff--combined-p: New fun


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 5043c0c487 1/6: magit-diff--combined-p: New function
Date: Tue, 12 Sep 2023 18:59:30 -0400 (EDT)

branch: elpa/git-commit
commit 5043c0c487d897164dd37961cca5be6573fd348f
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    magit-diff--combined-p: New function
---
 lisp/magit-apply.el | 6 +++---
 lisp/magit-diff.el  | 6 +++++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el
index 8af447ccae..27a9cf734f 100644
--- a/lisp/magit-apply.el
+++ b/lisp/magit-apply.el
@@ -187,7 +187,7 @@ adjusted as \"@@ -10,6 +10,7 @@\" and \"@@ -18,6 +19,7 
@@\"."
 
 (defun magit-apply-hunks (sections &rest args)
   (let ((section (oref (car sections) parent)))
-    (when (string-match "^diff --cc" (oref section value))
+    (when (magit-diff--combined-p section)
       (user-error "Cannot un-/stage resolution hunks.  Stage the whole file"))
     (magit-apply-patch
      section args
@@ -198,7 +198,7 @@ adjusted as \"@@ -10,6 +10,7 @@\" and \"@@ -18,6 +19,7 
@@\"."
                         "")))))
 
 (defun magit-apply-hunk (section &rest args)
-  (when (string-match "^diff --cc" (magit-section-parent-value section))
+  (when (magit-diff--combined-p (magit-section-parent section))
     (user-error "Cannot un-/stage resolution hunks.  Stage the whole file"))
   (let* ((header (car (oref section value)))
          (header (and (symbolp header) header))
@@ -211,7 +211,7 @@ adjusted as \"@@ -10,6 +10,7 @@\" and \"@@ -18,6 +19,7 
@@\"."
                (magit-apply--adjust-hunk-new-start content))))))
 
 (defun magit-apply-region (section &rest args)
-  (when (string-match "^diff --cc" (magit-section-parent-value section))
+  (when (magit-diff--combined-p (magit-section-parent section))
     (user-error "Cannot un-/stage resolution hunks.  Stage the whole file"))
   (magit-apply-patch (oref section parent) args
                      (concat (magit-diff-file-header section)
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 5f88922aa1..0c4ed34cb8 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -3500,7 +3500,7 @@ last (visual) lines of the region."
               ;; edge of the window.
               'cursor t))
 
-;;; Hunk Utilities
+;;; Utilities
 
 (defun magit-diff-inside-hunk-body-p ()
   "Return non-nil if point is inside the body of a hunk."
@@ -3508,6 +3508,10 @@ last (visual) lines of the region."
        (and-let* ((content (oref (magit-current-section) content)))
          (> (magit-point) content))))
 
+(defun magit-diff--combined-p (section)
+  (cl-assert (cl-typep section 'magit-file-section))
+  (string-match "^diff --cc" (oref section value)))
+
 ;;; Diff Extract
 
 (defun magit-diff-file-header (section &optional no-rename)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]