aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-04-08 03:00:57 +0200
committerRicardo Wurmus <rekado@elephly.net>2021-04-08 03:10:14 +0200
commit43fb6b765d82ea5acfdc83f61472d99594ee1cbf (patch)
tree47eb85831b21244f52255257b38bffe3e3d30fc9
parent56270c1275d8dcdec80c04c032079b694204052a (diff)
downloadguix-43fb6b765d82ea5acfdc83f61472d99594ee1cbf.tar
guix-43fb6b765d82ea5acfdc83f61472d99594ee1cbf.tar.gz
etc/committer: Record minimal context for hunks to avoid problems.
With zero context new definitions would be applied to the wrong location in the file. More context lines lead to larger hunks, though, so we use just one line of context. * etc/committer.scm.in (diff-info): Invoke "git diff" with one line of context. [info]: Merge line break and first line. (lines-to-first-change): New procedure. (old-sexp, new-sexp): Use it.
-rwxr-xr-xetc/committer.scm.in26
1 files changed, 19 insertions, 7 deletions
diff --git a/etc/committer.scm.in b/etc/committer.scm.in
index 8744bae4a7..376e1ac063 100755
--- a/etc/committer.scm.in
+++ b/etc/committer.scm.in
@@ -91,10 +91,10 @@ LINE-NO in PORT."
(let ((port (open-pipe* OPEN_READ
"git" "diff"
"--no-prefix"
- ;; Do not include any context lines. This makes it
- ;; easier to find the S-expression surrounding the
- ;; change.
- "--unified=0"
+ ;; Only include one context line to avoid lumping in
+ ;; new definitions with changes to existing
+ ;; definitions.
+ "--unified=1"
"gnu")))
(define (extract-line-number line-tag)
(abs (string->number
@@ -132,13 +132,22 @@ LINE-NO in PORT."
(loop (cons (make-hunk file-name
(extract-line-number old-start)
(extract-line-number new-start)
- (cons* line "\n" diff-lines)
+ (cons (string-append line "\n")
+ diff-lines)
definition?) acc)
file-name)))))
(else (loop acc file-name))))))
(close-pipe port)
info))
+(define (lines-to-first-change hunk)
+ "Return the number of diff lines until the first change."
+ (1- (count (lambda (line)
+ ((negate char-set-contains?)
+ (char-set #\+ #\-)
+ (string-ref line 0)))
+ (hunk-diff-lines hunk))))
+
(define (old-sexp hunk)
"Using the diff information in HUNK return the unmodified S-expression
corresponding to the top-level definition containing the staged changes."
@@ -150,7 +159,9 @@ corresponding to the top-level definition containing the staged changes."
(close-pipe port)
(call-with-input-string contents
(lambda (port)
- (surrounding-sexp port (hunk-old-line-number hunk))))))
+ (surrounding-sexp port
+ (+ (lines-to-first-change hunk)
+ (hunk-old-line-number hunk)))))))
(define (new-sexp hunk)
"Using the diff information in HUNK return the modified S-expression
@@ -158,7 +169,8 @@ corresponding to the top-level definition containing the staged changes."
(call-with-input-file (hunk-file-name hunk)
(lambda (port)
(surrounding-sexp port
- (hunk-new-line-number hunk)))))
+ (+ (lines-to-first-change hunk)
+ (hunk-new-line-number hunk))))))
(define* (change-commit-message file-name old new #:optional (port (current-output-port)))
"Print ChangeLog commit message for changes between OLD and NEW."