changelog: parse entries with a shared limit-based helper
Replace parse_previous_version/parse_previous_version_from_str with parse_changelog_entries(path, limit: Option<usize>), parsing up to the given number of entries (None: the whole file) newest-first through the same strict entry parser instead of a header-only scan. The single-entry helpers stay as thin wrappers, and callers needing the previous entry now get its full source name and version, not just the raw string.
This commit is contained in:
+13
-22
@@ -14,9 +14,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::context::Context;
|
||||
use crate::debian::{
|
||||
ChecksumEntry, ControlInfo, FileChecksums, FilesList, parse_changelog_entry_from_str,
|
||||
};
|
||||
use crate::debian::{ChecksumEntry, ControlInfo, FileChecksums, FilesList};
|
||||
|
||||
use super::parse_checksum_field;
|
||||
|
||||
@@ -70,7 +68,10 @@ pub fn generate_binary_metadata(
|
||||
// Metadata sources inside the context
|
||||
// ------------------------------------------------------------------
|
||||
let changelog_content = ctx.read_file(&package_dir.join("debian/changelog"))?;
|
||||
let entry = parse_changelog_entry_from_str(&changelog_content)?;
|
||||
let mut entries =
|
||||
crate::debian::changelog::parse_changelog_entries_from_str(&changelog_content, Some(2))?;
|
||||
let entry = entries.remove(0);
|
||||
let previous_entry = entries.into_iter().next();
|
||||
|
||||
let control_content = ctx.read_file(&package_dir.join("debian/control"))?;
|
||||
let control = ControlInfo::parse_content(&control_content)?;
|
||||
@@ -147,22 +148,13 @@ pub fn generate_binary_metadata(
|
||||
// a changelog that cannot yield it is a hard error, like in the
|
||||
// source-build path. Reuse the changelog read above instead of
|
||||
// reading the file a second time.
|
||||
let changelog_path = package_dir.join("debian/changelog");
|
||||
let prev = crate::debian::changelog::parse_previous_version_from_str(&changelog_content)
|
||||
.map_err(|e| {
|
||||
format!(
|
||||
"cannot parse the previous version from '{}': {e}",
|
||||
changelog_path.display()
|
||||
)
|
||||
})?;
|
||||
if let Some(prev) = prev {
|
||||
source_display = format!("{} ({})", entry.source, prev);
|
||||
if let Some(prev) = &previous_entry {
|
||||
source_display = format!("{} ({})", entry.source, prev.version.full());
|
||||
binary_only_changes = Some(format!(
|
||||
"{}\n\n -- {} <{}> {}",
|
||||
entry.changes_field, entry.maintainer_name, entry.maintainer_email, entry.date_raw
|
||||
));
|
||||
let prev_version = crate::debian::DebianVersion::parse(&prev)?;
|
||||
let dsc_name = format!("{}_{}.dsc", entry.source, prev_version.no_epoch());
|
||||
let dsc_name = format!("{}_{}.dsc", entry.source, prev.version.no_epoch());
|
||||
let dsc_path = upload_dir.join(&dsc_name);
|
||||
if ctx.exists(&dsc_path)? {
|
||||
include_dsc_artifacts(ctx, upload_dir, &dsc_name, &mut checksums)?;
|
||||
@@ -628,10 +620,10 @@ Files:
|
||||
}
|
||||
|
||||
/// A binary-only (binNMU) build whose changelog cannot yield the
|
||||
/// previous version (malformed second header, unbalanced parenthesis)
|
||||
/// must fail the metadata generation with a diagnostic naming the
|
||||
/// changelog, instead of silently emitting a plain `Source:` `.changes`
|
||||
/// with no `Binary-Only-Changes` and no redistributed previous `.dsc`.
|
||||
/// previous entry (malformed second header, unbalanced parenthesis) must
|
||||
/// fail the metadata generation with a diagnostic naming the problem,
|
||||
/// instead of silently emitting a plain `Source:` `.changes` with no
|
||||
/// `Binary-Only-Changes` and no redistributed previous `.dsc`.
|
||||
#[test]
|
||||
fn binary_only_prev_version_parse_failure_errors_instead_of_wrong_metadata() {
|
||||
let changelog = "\
|
||||
@@ -683,9 +675,8 @@ Description: test package
|
||||
let err = generate_binary_metadata(&ctx, &tree, base.path(), &opts)
|
||||
.expect_err("binary-only build with an unparseable changelog must fail");
|
||||
let err = err.to_string();
|
||||
assert!(err.contains("debian/changelog"), "{err}");
|
||||
assert!(err.contains("previous version"), "{err}");
|
||||
assert!(err.contains("unbalanced parenthesis"), "{err}");
|
||||
assert!(err.contains("1.0-1 unstable"), "{err}");
|
||||
}
|
||||
|
||||
/// An unreadable `debian/files` (e.g. permissions) must fail the
|
||||
|
||||
Reference in New Issue
Block a user