Function: magit-apply--adjust-hunk-new-starts

magit-apply--adjust-hunk-new-starts is a byte-compiled function defined in magit-apply.el.

Signature

(magit-apply--adjust-hunk-new-starts HUNKS)

Documentation

Adjust new line numbers in headers of HUNKS for partial application.

HUNKS should be a list of ordered, contiguous hunks to be applied from a file. For example, if there is a sequence of hunks with the headers

  @@ -2,6 +2,7 @@
  @@ -10,6 +11,7 @@
  @@ -18,6 +20,7 @@

and only the second and third are to be applied, they would be adjusted as "@@ -10,6 +10,7 @@" and "@@ -18,6 +19,7 @@".

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-apply.el
(defun magit-apply--adjust-hunk-new-starts (hunks)
  "Adjust new line numbers in headers of HUNKS for partial application.
HUNKS should be a list of ordered, contiguous hunks to be applied
from a file.  For example, if there is a sequence of hunks with
the headers

  @@ -2,6 +2,7 @@
  @@ -10,6 +11,7 @@
  @@ -18,6 +20,7 @@

and only the second and third are to be applied, they would be
adjusted as \"@@ -10,6 +10,7 @@\" and \"@@ -18,6 +19,7 @@\"."
  (let* ((first-hunk (car hunks))
         (offset (if (string-match diff-hunk-header-re-unified first-hunk)
                     (- (string-to-number (match-str 3 first-hunk))
                        (string-to-number (match-str 1 first-hunk)))
                   (error "Header hunks have to be applied individually"))))
    (if (= offset 0)
        hunks
      (mapcar (lambda (hunk)
                (if (string-match diff-hunk-header-re-unified hunk)
                    (replace-match (number-to-string
                                    (- (string-to-number (match-str 3 hunk))
                                       offset))
                                   t t hunk 3)
                  (error "Hunk does not have expected header")))
              hunks))))