crate-ci / cargo-release

Cargo subcommand `release`: everything about releasing a rust crate.
Apache License 2.0
1.33k stars 112 forks source link

diff is noisy if you insert new paragraphs into a changelog #755

Closed sourcefrog closed 7 months ago

sourcefrog commented 7 months ago

In cargo-mutants Cargo.toml I have cargo-release text replacement set up like this:

[workspace.metadata.release]
pre-release-replacements = [
    { "file" = "NEWS.md", search = "## Unreleased", replace = "$0\n\n## {{version}}", exactly = 1 },
]

That is to say it inserts a new version header but leaves an "Unreleased" section at the top.

This works (yay) but I initially thought that it did not, because the displayed diff shows every later paragraph being changed:

.... many lines
@@ -565,2 +565 @@
-- Functions that should not be mutated can be marked with `#[mutants::skip]`
-  from the [`mutants`](https://crates.io/crates/mutants) helper crate.
+## 0.0.2
@@ -568 +567,2 @@
-## 0.0.1
+- Functions that should not be mutated can be marked with `#[mutants::skip]`
+  from the [`mutants`](https://crates.io/crates/mutants) helper crate.
@@ -570 +570,3 @@
-First release.
+## 0.0.1
+
+First release.

I think this is because the diff code you're using isn't smart about looking for inserted lines.

It looks like you're using difflib 0.4. I would have guessed it would do better on this, but maybe not. Personally I have used https://crates.io/crates/similar in cargo-mutants and it does seem to get this kind of thing right. I will have a quick look.