diff -e: no script at all when a file has no newline at the end

Aperta
#332 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

Read src/ed_diff.rs around lines 65 and 71, where DiffError::MissingNL causes an early return, and inspect the missing_newline test in tests/by-util/test_diff.rs around line 122. Compare diff -e output for files with missing final newlines against GNU diff; done means the ed script is printed and missing-newline warnings match the described behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When either file's last line has no newline, diff -e prints nothing on stdout:

$ printf 'a\nb' > x; printf 'a\nc\n' > y
$ diffutils diff -e x y
No newline at end of file
$ echo $?
2
$ /usr/bin/diff -e x y    # GNU diff 3.12
2c
c
.
/usr/bin/diff: x: No newline at end of file

$ echo $?
2

GNU still writes the ed script, then warns on stderr for each file that lacks the final newline (diff: FILE: No newline at end of file, then a blank line) and exits 2. Both exit 2, but a caller that applies the script, or shows it, gets nothing from uutils.

The early return is in src/ed_diff.rs:65 and src/ed_diff.rs:71 (DiffError::MissingNL). The test missing_newline (tests/by-util/test_diff.rs:122) checks for the current stderr (starts_with("No newline at end of file")), so matching GNU means changing that test. I have a change that matches GNU for either file, both, two different files with the same content, an empty file and stdin (apart from 2,2d, which is #308); happy to open a PR if you want GNU's output here.

uutils diffutils main 8ff5bda and v0.6.0.

Lingua principale
Rust
Stelle
280
Fork
49
Merge medio
2g 9h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di uutils/diffutils

Tutte le issue di uutils/diffutils

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.