Let a photographer name the state they liked, and go back to it or look at it
FR-DEV-5 asked for named snapshots of an edit state and FR-DEV-7 for a comparison against a chosen one, and neither existed. The history stack is per sitting and forgotten with it, on purpose — the gap that mattered was an automatically saved mis-drag with no way back, and that was closed first. What was left was the other half: a state the photographer wants to keep *because* it is worth keeping, which is a different thing from a step and is not served by making the steps last longer. A snapshot is an edit state, and an edit state is exactly what a sidecar version stores, so it is stored as one: a `[version]` block carrying `snapshot-of = <uuid>`. The parameters, the masks and their parts, the repairs and the film all arrive through the blocks that already carry them, a merge keys on the uuid as it does for any version, and a build that predates the key reads the block as a named version and keeps it — the right failure. Only the pointer is new. The one reader that has to know is `default_version`, which must never answer with a snapshot: a file whose edit is missing is not a file whose edit is one of its saved moments. The snapshots of an edit are listed by that pointer, oldest first, the same on every device. Writing them back removes what this sitting deleted and puts in what it holds, and leaves standing whatever it never saw — a snapshot the other device took since the photograph was opened here is not this device's to remove by not knowing about it. That is the rule the version merge already keeps, applied one level down, and it is why the save carries the deleted ids rather than replacing the list wholesale as the masks are. Each is re-pointed at the uuid the save settled on, because the default may have been fused onto its canonical identity since the snapshot was taken. Restoring is one history step, so undo takes it back whole, as a paste is. Taking and deleting are not steps: they change nothing about the photograph, and an undo that removed a snapshot would be undoing a decision to remember. Holding the eye beside one renders the snapshot and hands the edit straight back — the same suspension "Before" uses, against a point the photographer chose rather than the file. Two sessions on the same photograph get ids that cannot collide, stamped with the second and a random word, because the merge folds equal ids into one.
This commit is contained in:
+96
-4
@@ -315,6 +315,7 @@ pub fn save_local(
|
||||
preset: &Preset,
|
||||
scope: Scope,
|
||||
masks: Option<&dr_pipeline::mask::MaskStack>,
|
||||
snapshots: Option<(&[dr_pipeline::Version], &[String])>,
|
||||
) -> Result<(), String> {
|
||||
let path = local_sidecar_path(image);
|
||||
|
||||
@@ -369,6 +370,10 @@ pub fn save_local(
|
||||
version.revision = version.revision.saturating_add(1);
|
||||
version.modified = now_secs();
|
||||
sidecar.put(version);
|
||||
// TRACES: FR-DEV-5
|
||||
if let Some((kept, removed)) = snapshots {
|
||||
sidecar.replace_snapshots(&uuid, kept.to_vec(), removed);
|
||||
}
|
||||
|
||||
let text = sidecar.to_text();
|
||||
|
||||
@@ -401,9 +406,9 @@ pub fn save_open_edit(
|
||||
session: &Rc<RefCell<Option<DevelopSession>>>,
|
||||
library: &Rc<library_ui::LibraryController>,
|
||||
) {
|
||||
// Both taken in one borrow: they are one edit, and a mask stack captured
|
||||
// All taken in one borrow: they are one edit, and a mask stack captured
|
||||
// from a session that had already moved on would be a different image's.
|
||||
let Some((preset, masks, film)) = session.borrow().as_ref().map(|s| {
|
||||
let Some((preset, masks, film, snapshots, removed)) = session.borrow().as_ref().map(|s| {
|
||||
(
|
||||
s.copy_settings(),
|
||||
// TRACES: FR-DEV-3
|
||||
@@ -429,6 +434,12 @@ pub fn save_open_edit(
|
||||
.unwrap_or_default()
|
||||
}),
|
||||
}),
|
||||
// TRACES: FR-DEV-5
|
||||
// The snapshots as they stand and the ids deleted this sitting,
|
||||
// so the file gains what was taken and loses what was removed —
|
||||
// and keeps what another device added meanwhile.
|
||||
s.snapshots().to_vec(),
|
||||
s.removed_snapshots().to_vec(),
|
||||
)
|
||||
}) else {
|
||||
return;
|
||||
@@ -443,7 +454,13 @@ pub fn save_open_edit(
|
||||
// `Everything`: this is the image's *own* edit being written back,
|
||||
// not a paste onto someone else's. Excluding framing here would
|
||||
// make a crop the one adjustment that never survived a restart.
|
||||
if let Err(e) = save_local(path, &preset, Scope::everything(), Some(&masks)) {
|
||||
if let Err(e) = save_local(
|
||||
path,
|
||||
&preset,
|
||||
Scope::everything(),
|
||||
Some(&masks),
|
||||
Some((&snapshots, &removed)),
|
||||
) {
|
||||
log::warn!("saving {}: {e}", path.display());
|
||||
}
|
||||
}
|
||||
@@ -461,6 +478,7 @@ pub fn save_open_edit(
|
||||
// sliders were written and every mask was dropped.
|
||||
masks: Some(masks),
|
||||
film: Some(film),
|
||||
snapshots: Some((snapshots, removed)),
|
||||
},
|
||||
};
|
||||
library_ui::start_sidecar_writes(window, library, vec![write]);
|
||||
@@ -536,6 +554,15 @@ pub fn apply_stored_edit(
|
||||
let mut slot = session.borrow_mut();
|
||||
let Some(s) = slot.as_mut() else { return false };
|
||||
s.apply_version(version);
|
||||
// TRACES: FR-DEV-5
|
||||
// And the snapshots taken of it, on this device or another.
|
||||
s.set_snapshots(
|
||||
sidecar
|
||||
.snapshots_of(&version.uuid)
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
crate::sync_rows(window, rows, session);
|
||||
@@ -1162,6 +1189,7 @@ mod tests {
|
||||
&Preset::capture(&graph),
|
||||
Scope::everything(),
|
||||
Some(graph.masks()),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1209,6 +1237,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1242,6 +1271,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
save_local(
|
||||
@@ -1249,6 +1279,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1267,6 +1298,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let first = load_local(&image)
|
||||
@@ -1279,6 +1311,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let second = load_local(&image)
|
||||
@@ -1313,6 +1346,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1335,7 +1369,8 @@ mod tests {
|
||||
&image,
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.is_err());
|
||||
assert_eq!(
|
||||
@@ -1353,6 +1388,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1638,4 +1674,60 @@ mod tests {
|
||||
"the failed overwrite kept the new value"
|
||||
);
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// A snapshot goes into the file beside the edit and comes back out as a
|
||||
/// snapshot of it; deleting one takes it out of the file; and neither
|
||||
/// touches the edit the photograph opens at.
|
||||
#[test]
|
||||
fn snapshots_survive_the_local_sidecar_and_leave_it_when_deleted() {
|
||||
let dir = tempdir("snapshots");
|
||||
let image = dir.join("IMG_0001.CR3");
|
||||
std::fs::write(&image, b"").unwrap();
|
||||
|
||||
let graph = edited();
|
||||
let mut liked = EditGraph::default_chain();
|
||||
liked.set_param(
|
||||
dr_pipeline::ops::exposure::ID,
|
||||
dr_pipeline::ops::exposure::EXPOSURE,
|
||||
1.5,
|
||||
);
|
||||
let snapshot = dr_pipeline::Version::from_graph("snap-1", "Brighter", &liked);
|
||||
|
||||
save_local(
|
||||
&image,
|
||||
&Preset::capture(&graph),
|
||||
Scope::everything(),
|
||||
None,
|
||||
Some((&[snapshot], &[])),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let text = std::fs::read_to_string(local_sidecar_path(&image)).unwrap();
|
||||
let sidecar = Sidecar::parse(&text).unwrap();
|
||||
let edit = sidecar.default_version().expect("the edit");
|
||||
assert!(!edit.is_snapshot(), "the photograph opens at its edit");
|
||||
let back = sidecar.snapshots_of(&edit.uuid);
|
||||
assert_eq!(back.len(), 1);
|
||||
assert_eq!(back[0].name, "Brighter");
|
||||
assert_eq!(
|
||||
back[0]
|
||||
.params
|
||||
.get(&("exposure".to_string(), "exposure".to_string())),
|
||||
Some(&1.5)
|
||||
);
|
||||
|
||||
save_local(
|
||||
&image,
|
||||
&Preset::capture(&graph),
|
||||
Scope::everything(),
|
||||
None,
|
||||
Some((&[], &["snap-1".to_string()])),
|
||||
)
|
||||
.unwrap();
|
||||
let text = std::fs::read_to_string(local_sidecar_path(&image)).unwrap();
|
||||
let sidecar = Sidecar::parse(&text).unwrap();
|
||||
let edit = sidecar.default_version().expect("the edit is still there");
|
||||
assert!(sidecar.snapshots_of(&edit.uuid).is_empty(), "{text}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user