merge: review2-p5a-fix-desktop into phase 5a fix round 1 integration

# Conflicts:
#	src/Chronos.Data/Workspaces/WorkspaceSync.cs
This commit is contained in:
Alby96 committed 2026-11-03 10:40:02 +01:00
commit 1a35fcdb27
28 files changed
+1328 -139

No files matched your search

@@ -34,7 +34,10 @@ public interface IProjectRenders
/// library): the frames and pixels of the media the workspace holds (<c>media/media.json</c>, the proxies), the project
/// from its working state (<c>project.chronos</c>, positions placed on those frames), saved there atomically under the
/// project's lease and merged against the basis like <see cref="LocalSequenceSource"/> (a pull or a copy job writes it
/// too). Jobs run on this PC's engine against the home's sequence (same id): an analysis reads the home's originals, a
/// too): frame positions photo by photo as the sync merges them (<see cref="Merge"/>), and settings the editor changed to
/// other values than those stored meanwhile asked about (<see cref="ProjectConflictException"/>), never decided for the
/// editor. A pull that brings a newer Chronos's settings turns it read-only (<see cref="ReadOnlyChanged"/>). Jobs run on
/// this PC's engine against the home's sequence (same id): an analysis reads the home's originals, a
/// render renders the home's originals with the project's portable settings and records the project and the version
/// (<see cref="RenderRequests"/>). The deep report is the home's while its frames are the media's, else the copy the
/// workspace took. A copy job that changed the media (Update media) makes saves made against the frames read before refused
@@ -94,12 +97,11 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
public bool IsOutdated => false;
/// <summary>A workspace project's read-only state is known when it opens.</summary>
public event Action? ReadOnlyChanged
{
add { }
remove { }
}
/// <summary>The library's values and the editor's are asked about where both changed a setting, as a sync asks.</summary>
public bool AsksConflicts => true;
/// <summary>The working state read again holds a newer Chronos's settings (a pull took them), or no longer does.</summary>
public event Action? ReadOnlyChanged;
public event Action<Job>? JobChanged;
@@ -183,6 +185,10 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
/// <exception cref="EditorException">The project is read-only, or its media are gone.</exception>
/// <exception cref="FramesChangedException">The media changed since they were read (a copy job): read them again first.</exception>
/// <exception cref="ProjectConflictException">
/// The working state stored meanwhile (a sync took the library's versions) holds other values of settings this edit
/// changed too: nothing is stored until the user keeps theirs or takes the library's.
/// </exception>
public Task<ProjectSettings> SaveProjectAsync(ProjectSettings project, ProjectSettings basis, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(project);
@@ -200,7 +206,13 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
// A copy job moved the working state onto other frames: the editor reads them and moves its positions first.
if (media.FramesVersion != framesVersion) throw new FramesChangedException(Loc.L("Errors.Workspace.MediaChanged"));
var stored = ProjectSettings.FromJson(ProjectContent.Place(bundle.Project.ToJson(), media.Photos), allowNewer: true);
var merged = ProjectMerge.SameValues(stored, basis) ? project : ProjectMerge.Merge(basis, project, stored);
var merged = project;
if (!ProjectMerge.SameValues(stored, basis))
{
var merge = Merge(basis, project, stored, media.Photos);
if (merge.HasConflicts) throw new ProjectConflictException(Loc.L("Editor.Error.SaveConflict"), stored, merge.Conflicts);
merged = merge.Merged;
}
if (ProjectMerge.SameValues(merged, stored)) return merged;
folder.WriteBundle(bundle with { Project = merged, Saved = DateTimeOffset.UtcNow });
return merged;
@@ -208,6 +220,33 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
}, cancellationToken);
}
/// <summary>
/// The editor's merges as the sync merges (owner review 2, R8): member by member, and frame positions photo by photo and
/// flag by flag in the portable form, so an exclusion or a keyframe a sync wrote meanwhile stays beside the editor's own
/// (positional arrays would take one side whole). All three name the frames of the media read last.
/// </summary>
public ProjectMergeResult Merge(ProjectSettings basis, ProjectSettings ours, ProjectSettings theirs) => Merge(basis, ours, theirs, Photos);
private static ProjectMergeResult Merge(ProjectSettings basis, ProjectSettings ours, ProjectSettings theirs, FramePhotos photos)
{
ArgumentNullException.ThrowIfNull(basis);
ArgumentNullException.ThrowIfNull(ours);
ArgumentNullException.ThrowIfNull(theirs);
var merge = ProjectMerge.MergeWithConflicts(basis, ours, theirs);
// Positions only one side moved, or none, merge alike either way; the portable form is needed where both did.
if (photos.Count == 0 || !merge.Conflicts.Any(c => NamesPosition(c.Path)) || basis.IsNewerFormat || ours.IsNewerFormat || theirs.IsNewerFormat) return merge;
var portable = ProjectMerge.MergeWithConflicts(Portable(basis, photos), Portable(ours, photos), Portable(theirs, photos));
var placed = ProjectSettings.FromJson(ProjectContent.Place(ProjectContent.Canonical(portable.Merged.ToJson()), photos), allowNewer: true);
return portable with { Merged = placed };
static ProjectSettings Portable(ProjectSettings settings, FramePhotos photos) =>
ProjectSettings.FromJson(ProjectContent.ToPortable(settings, photos), allowNewer: true);
}
/// <summary>A merge path of a frame position (an exclusion, the hero, a camera keyframe, a frame waiting for its photo).</summary>
private static bool NamesPosition(string path) =>
path is "excludedFrames" or "heroFrame" || path.StartsWith("camera.keyframes", StringComparison.Ordinal) || path.StartsWith("pendingFrames", StringComparison.Ordinal);
public async Task<Guid> SubmitAsync(ArchiveJobRequest request, CancellationToken cancellationToken)
{
if (_engine is null) throw new InvalidOperationException(Loc.L("Editor.Error.NoEngine"));
@@ -271,11 +310,13 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
/// <summary>
/// Takes the media read now: a frame source over them when they differ from those read before (the old one is disposed
/// with this source, as a decode may still read it), their frames and photos, the project's workspace section.
/// with this source, as a decode may still read it), their frames and photos, the project's workspace section, and
/// whether the settings are a newer Chronos's (said by <see cref="ReadOnlyChanged"/> when that changed).
/// </summary>
private void Swap(WorkspaceSequence media, WorkspaceMedia index, BundleWorkspace workspace, bool readOnly)
{
var ids = media.Frames.Select(f => f.Id).ToArray();
bool changed;
lock (_gate)
{
if (_frames is null || index.FramesVersion != _framesVersion || !ids.AsSpan().SequenceEqual(_frameIds))
@@ -289,8 +330,10 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
_framesVersion = index.FramesVersion;
_photos = index.Photos;
_workspace = workspace;
changed = _readOnly != readOnly;
_readOnly = readOnly;
}
if (changed) ReadOnlyChanged?.Invoke();
}
/// <summary>