fix(projects): one photo merges as one, newer settings are never merged

A workspace copied before the home hashed or converted a photo named it
differently from the versions the home made since, so a pull merged the
same photo as two: frame edits were silently undone and Keep mine placed
the library's value. Before replaying, the workspace media now learn the
home's hashes (same frame id, size and capture time) and conversion
aliases, so every side names each photo alike. Rebind also gives a
renamed entry the occurrence a placement looks for, so positions on
burst photos keep applying once hashed, and folds entries of one photo
(in Rebind and in the merge's keyed form) instead of keeping one.

Settings of a newer Chronos are no longer merged member by member with
this one's: ProjectMerge refuses when both sides changed. A workspace
pull keeps its local versions and working state untouched and records a
conflict of format that only Save both settles (into a new project of
this format); with nothing local it takes the newer head read-only.
Main's catch-up leaves a newer head and settings written meanwhile as
they are.

When Main's catch-up merge overrides values another writer stored, that
writer's settings are kept as an External version before the Merge one,
so nothing is lost from the history.

Unknown members inside Auto values, camera keyframes and curve points,
and on pending entries once placed, are kept like ProjectSettings' Extra.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-03 10:05:27 +01:00
1 parent 50e28fd63d
commit eac4a36a7b
12 files changed
+905 -38

No files matched your search

+59 -4
View File
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Text.Json;
using Chronos.Core.Model;
using Chronos.Core.Project;
@@ -81,9 +82,12 @@ public sealed class WorkspaceSyncException(PushOutcome outcome, string message)
/// (<see cref="ProjectMerge.Replay"/>, new ids, the old files kept in <c>versions/.replaced</c>), and the working state is
/// merged too (<see cref="ProjectMerge.MergeWithConflicts"/>); settings both sides changed to different values stop
/// there as a conflict (<see cref="WorkspaceConflict"/>) for the user to settle (<see cref="ResolveAsync"/>). Versions
/// travel in the portable form (<see cref="ProjectContent"/>), so frames inserted at the home never move a position. Every
/// operation holds the project's lease; nothing is ever deleted: a restore or save-both first saves uncommitted changes
/// as a version.
/// travel in the portable form (<see cref="ProjectContent"/>), so frames inserted at the home never move a position; before
/// a merge the media learn how the home names its photos now (hashed or converted there since the copy), so every side
/// names one photo alike. Settings of a newer Chronos are never merged with this one's: a project with nothing of its own
/// moves onto them read-only, any other waits on a conflict of format that only Save both settles
/// (<see cref="WorkspaceConflict.NewerFormat"/>). Every operation holds the project's lease; nothing is ever deleted: a
/// restore or save-both first saves uncommitted changes as a version.
/// </summary>
public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
{
@@ -357,8 +361,10 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
var tipVersion = locals.Count > 0 ? locals[^1] : basis;
if (ours.Count > 0) basis = theirs.First(v => v.Id == ours[^1].Id);
locals = [.. locals.Skip(ours.Count)];
var media = project.ReadMedia();
// The media first learn how the home names its photos now (hashed or converted there since the copy).
var media = await MediaNamedAsAtHomeAsync(project, home, cancellationToken).ConfigureAwait(false);
var photos = media?.Photos ?? NoFrames;
if (IsNewer(head) || IsNewer(basis)) return NewerAtHome(project, bundle, media, tipVersion, locals, basis, head, theirs, takeTheirs);
// Each side names a photo as the frames held it when it was saved: named as the media hold it now (a conversion or a
// hash since), the same photo merges as one.
var basisSettings = basis is null ? new ProjectSettings() : ProjectMerge.Read(ProjectContent.Rebind(basis.SettingsJson, photos));
@@ -406,6 +412,55 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
return (moved, null, theirs);
}
/// <summary>
/// The workspace's media with their photos named as the home names them now (<see cref="WorkspaceMedia.NamedAsAt"/>),
/// written back when the home taught them anything, so the versions, the working state and every comparison after this
/// one name each photo alike. Null while the workspace holds no media.
/// </summary>
private static async Task<WorkspaceMedia?> MediaNamedAsAtHomeAsync(WorkspaceProject project, IProjectHome home, CancellationToken cancellationToken)
{
if (project.ReadMedia() is not { } media) return null;
var named = media.NamedAsAt(await home.FramesAsync(cancellationToken).ConfigureAwait(false));
if (!ReferenceEquals(named, media)) project.WriteMedia(named);
return named;
}
private static bool IsNewer(ProjectVersion? version) => version is not null && ProjectContent.FormatOf(version.SettingsJson) > ProjectSettings.CurrentVersion;
/// <summary>
/// The home's head, or the base, holds settings of a newer Chronos: nothing is merged into or out of them, as their known
/// members may mean something else there. With nothing of this workspace's own (no version to send, the working state the
/// last version's), the project moves onto the head as it is, read-only when that is the newer one. Otherwise the local
/// versions and the working state stay as they are and a conflict of format waits (<see cref="WorkspaceConflict.NewerFormat"/>):
/// Save both sends them to a new project made from the base, in this Chronos's format. A choice to merge them
/// (<paramref name="takeTheirs"/> set: keep mine, take the server's) is refused, the conflict left recorded.
/// </summary>
/// <exception cref="WorkspaceSyncException">A choice to merge was made.</exception>
private static (ProjectBundle Bundle, WorkspaceConflict? Conflict, IReadOnlyList<ProjectVersion> Pulled) NewerAtHome(WorkspaceProject project,
ProjectBundle bundle, WorkspaceMedia? media, ProjectVersion? tipVersion, IReadOnlyList<ProjectVersion> locals, ProjectVersion? basis, ProjectVersion head,
IReadOnlyList<ProjectVersion> theirs, IReadOnlySet<string>? takeTheirs)
{
var photos = media?.Photos ?? NoFrames;
var tip = tipVersion?.SettingsJson ?? ProjectContent.ToPortable(new ProjectSettings(), photos);
if (locals.Count == 0 && (bundle.IsReadOnly
|| ProjectContent.SameChoices(tip, Portable(bundle.Project, media) ?? throw MediaMissing(project.ProjectId), photos)))
{
var placed = ProjectSettings.FromJson(ProjectContent.Place(head.SettingsJson, photos), allowNewer: true);
var moved = WithBase(bundle, head) with { Project = placed, Saved = DateTimeOffset.UtcNow };
project.WriteBundle(moved);
return (moved, null, theirs);
}
var newer = Math.Max(ProjectContent.FormatOf(head.SettingsJson), basis is null ? 0 : ProjectContent.FormatOf(basis.SettingsJson));
var format = new SettingsDifference(ProjectMerge.FormatPath, ProjectContent.FormatOf(tip).ToString(CultureInfo.InvariantCulture),
newer.ToString(CultureInfo.InvariantCulture));
var conflict = new WorkspaceConflict(head.Id, head.Number, basis?.Id ?? Guid.Empty, [.. locals.Select(v => v.Id)], [format], DateTimeOffset.UtcNow);
project.WriteSync(project.ReadSync() with { Conflict = conflict });
if (takeTheirs is not null)
throw new WorkspaceSyncException(PushOutcome.NewerFormat,
$"Version {head.Number} of project {project.ProjectId} holds settings of a newer Chronos: nothing of this workspace's is merged into it (save both, or update Chronos).");
return (bundle, conflict, theirs);
}
/// <summary>Both sides kept: this workspace's versions to a new project at the home, this project onto the home's head.</summary>
private async Task<WorkspaceSyncResult> SaveBothAsync(WorkspaceProject project, ProjectBundle bundle, IProjectHome home, string? name, CancellationToken cancellationToken)
{