diff options
| author | Ricardo Wurmus <rekado@elephly.net> | 2021-04-08 03:00:57 +0200 |
|---|---|---|
| committer | Ricardo Wurmus <rekado@elephly.net> | 2021-04-08 03:10:14 +0200 |
| commit | 43fb6b765d82ea5acfdc83f61472d99594ee1cbf (patch) | |
| tree | 47eb85831b21244f52255257b38bffe3e3d30fc9 /etc | |
| parent | 56270c1275d8dcdec80c04c032079b694204052a (diff) | |
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.
Diffstat (limited to 'etc')
| -rwxr-xr-x | etc/committer.scm.in | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/etc/committer.scm.in b/etc/committer.scm.in index 8744bae4a7d..376e1ac0634 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in | |||
| @@ -91,10 +91,10 @@ LINE-NO in PORT." | |||
| 91 | (let ((port (open-pipe* OPEN_READ | 91 | (let ((port (open-pipe* OPEN_READ |
| 92 | "git" "diff" | 92 | "git" "diff" |
| 93 | "--no-prefix" | 93 | "--no-prefix" |
| 94 | ;; Do not include any context lines. This makes it | 94 | ;; Only include one context line to avoid lumping in |
| 95 | ;; easier to find the S-expression surrounding the | 95 | ;; new definitions with changes to existing |
| 96 | ;; change. | 96 | ;; definitions. |
| 97 | "--unified=0" | 97 | "--unified=1" |
| 98 | "gnu"))) | 98 | "gnu"))) |
| 99 | (define (extract-line-number line-tag) | 99 | (define (extract-line-number line-tag) |
| 100 | (abs (string->number | 100 | (abs (string->number |
| @@ -132,13 +132,22 @@ LINE-NO in PORT." | |||
| 132 | (loop (cons (make-hunk file-name | 132 | (loop (cons (make-hunk file-name |
| 133 | (extract-line-number old-start) | 133 | (extract-line-number old-start) |
| 134 | (extract-line-number new-start) | 134 | (extract-line-number new-start) |
| 135 | (cons* line "\n" diff-lines) | 135 | (cons (string-append line "\n") |
| 136 | diff-lines) | ||
| 136 | definition?) acc) | 137 | definition?) acc) |
| 137 | file-name))))) | 138 | file-name))))) |
| 138 | (else (loop acc file-name)))))) | 139 | (else (loop acc file-name)))))) |
| 139 | (close-pipe port) | 140 | (close-pipe port) |
| 140 | info)) | 141 | info)) |
| 141 | 142 | ||
| 143 | (define (lines-to-first-change hunk) | ||
| 144 | "Return the number of diff lines until the first change." | ||
| 145 | (1- (count (lambda (line) | ||
| 146 | ((negate char-set-contains?) | ||
| 147 | (char-set #\+ #\-) | ||
| 148 | (string-ref line 0))) | ||
| 149 | (hunk-diff-lines hunk)))) | ||
| 150 | |||
| 142 | (define (old-sexp hunk) | 151 | (define (old-sexp hunk) |
| 143 | "Using the diff information in HUNK return the unmodified S-expression | 152 | "Using the diff information in HUNK return the unmodified S-expression |
| 144 | corresponding to the top-level definition containing the staged changes." | 153 | corresponding to the top-level definition containing the staged changes." |
| @@ -150,7 +159,9 @@ corresponding to the top-level definition containing the staged changes." | |||
| 150 | (close-pipe port) | 159 | (close-pipe port) |
| 151 | (call-with-input-string contents | 160 | (call-with-input-string contents |
| 152 | (lambda (port) | 161 | (lambda (port) |
| 153 | (surrounding-sexp port (hunk-old-line-number hunk)))))) | 162 | (surrounding-sexp port |
| 163 | (+ (lines-to-first-change hunk) | ||
| 164 | (hunk-old-line-number hunk))))))) | ||
| 154 | 165 | ||
| 155 | (define (new-sexp hunk) | 166 | (define (new-sexp hunk) |
| 156 | "Using the diff information in HUNK return the modified S-expression | 167 | "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." | |||
| 158 | (call-with-input-file (hunk-file-name hunk) | 169 | (call-with-input-file (hunk-file-name hunk) |
| 159 | (lambda (port) | 170 | (lambda (port) |
| 160 | (surrounding-sexp port | 171 | (surrounding-sexp port |
| 161 | (hunk-new-line-number hunk))))) | 172 | (+ (lines-to-first-change hunk) |
| 173 | (hunk-new-line-number hunk)))))) | ||
| 162 | 174 | ||
| 163 | (define* (change-commit-message file-name old new #:optional (port (current-output-port))) | 175 | (define* (change-commit-message file-name old new #:optional (port (current-output-port))) |
| 164 | "Print ChangeLog commit message for changes between OLD and NEW." | 176 | "Print ChangeLog commit message for changes between OLD and NEW." |
