Keep colour labels in the sidecar so they survive and travel

A rating and a flag are written to DarkRoom's sidecar as well as the
catalog, because the catalog is a disposable index and the sidecar is
how a judgement reaches the photographer's other devices. A label had no
place there, so once labels could be set, one would have lived only in
the catalog of the device it was set on and gone with it.

The sidecar version now carries `label` (0 none, 1-5 as the catalog
codes it), written only when set. It merges under the rating's rule, so a
device that never labelled a frame cannot clear another device's label,
and a code this build does not know reads as none rather than as some
other colour. A judgement write carries the catalog's label with the
stars, and the scan takes a sidecar's label into the catalog when it has
one. An older build keeps the line as an unknown key and writes it back.
This commit is contained in:
2026-09-24 21:52:23 -04:00
parent 89859d39d1
commit d748527a4c
4 changed files with 129 additions and 20 deletions
+65
View File
@@ -93,6 +93,9 @@ pub const MAX_RATING: u8 = 5;
/// Highest flag code: 0 unflagged, 1 pick, 2 reject.
pub const MAX_FLAG: u8 = 2;
/// Highest colour-label code: purple. Mirrors `dr_catalog::rating::label_code`.
pub const MAX_LABEL: u8 = 5;
/// TRACES: FR-CAT-8 | FR-NC-8
/// One image's sidecar: a keyed set of versions.
///
@@ -187,6 +190,17 @@ pub struct Version {
/// so a value moving between the two stores needs no translation table
/// that could drift.
pub flag: u8,
/// TRACES: FR-CAT-5
/// The colour label, `0` for none and `1..=5` red, yellow, green, blue,
/// purple — the catalog's `versions.label` codes, for the reason
/// [`Self::flag`] shares its encoding.
///
/// Here for the reason the rating is: a label that lived only in the
/// catalog would go with the catalog, and would never reach the
/// photographer's other devices, which learn judgements from this file.
/// A build that predates the key keeps it as an unknown line and writes
/// it back, so an older device passes it on rather than erasing it.
pub label: u8,
/// The edit itself: `(op, param) -> value`, non-default values only.
pub params: BTreeMap<(String, String), f32>,
/// TRACES: FR-DEV-3 | FR-NC-9
@@ -264,6 +278,7 @@ impl Version {
// it in the "not yet looked at" state a cull resumes from.
rating: 0,
flag: 0,
label: 0,
params,
masks,
film,
@@ -572,6 +587,10 @@ impl Version {
// that never had it.
self.rating = merge_judgement(self.rating, remote.rating, remote_wins);
self.flag = merge_judgement(self.flag, remote.flag, remote_wins);
// TRACES: FR-CAT-5
// A label under the same rule: 0 is "none given", so a device that
// never labelled a frame cannot clear another's label.
self.label = merge_judgement(self.label, remote.label, remote_wins);
// TRACES: FR-DEV-3f
// The film resolves wholesale to the higher revision, like a mask
@@ -873,6 +892,9 @@ impl Sidecar {
if v.flag > 0 {
let _ = writeln!(out, "flag = {}", v.flag);
}
if v.label > 0 {
let _ = writeln!(out, "label = {}", v.label);
}
// TRACES: FR-DEV-3f
// Before the parameters, because it decides what they mean: the
// film's exposure slider is a slider on *that stock's* curve.
@@ -1068,6 +1090,17 @@ impl Sidecar {
Some(value.to_string());
}
"flag" => version.flag = value.parse::<u8>().unwrap_or(0).min(MAX_FLAG),
// TRACES: FR-CAT-5
// A code this build does not know reads as none rather than
// being clamped onto purple: a wrong colour is a claim, and
// no colour is only a gap.
"label" => {
version.label = value
.parse::<u8>()
.ok()
.filter(|l| *l <= MAX_LABEL)
.unwrap_or(0)
}
// TRACES: FR-DEV-8
// Ahead of the `op.param` arm below, which would otherwise try
// to read eight numbers as one float and drop the repair with a
@@ -2828,6 +2861,37 @@ mod tests {
assert_eq!(back.flag, 1);
}
#[test]
fn a_label_survives_the_round_trip_and_an_unknown_one_reads_as_none() {
// TRACES: FR-CAT-5
let mut v = version_of(&EditGraph::default_chain());
v.label = 3;
let mut sidecar = Sidecar::new();
sidecar.put(v);
let text = sidecar.to_text();
assert!(text.contains("label = 3"), "{text}");
let parsed = Sidecar::parse(&text).expect("valid");
assert_eq!(parsed.default_version().expect("a version").label, 3);
let odd = "drsc 1\n\n[version u1]\nname = Default\nrevision = 1\nmodified = 0\n\
label = 9\n";
let parsed = Sidecar::parse(odd).expect("valid");
assert_eq!(parsed.default_version().expect("a version").label, 0);
}
#[test]
fn an_unlabelled_device_cannot_clear_another_devices_label() {
// TRACES: FR-CAT-5
let mut local = version_of(&EditGraph::default_chain());
local.label = 0;
local.revision = 9;
let mut remote = version_of(&EditGraph::default_chain());
remote.label = 1;
remote.revision = 1;
local.merge(&remote, None);
assert_eq!(local.label, 1);
}
#[test]
fn an_unrated_image_writes_no_judgement_lines() {
// The non-default rule applied to judgement: a library that has never
@@ -2838,6 +2902,7 @@ mod tests {
let text = sidecar.to_text();
assert!(!text.contains("rating"), "{text}");
assert!(!text.contains("flag"), "{text}");
assert!(!text.contains("label"), "{text}");
}
#[test]