Merge branch 'review2-p5a-fix3-desktop' into review2-p5a-int3
Conflict in WorkspaceFallbackTests: keeps desktop's new newer-copy test and drops ACancelledFirstCopyLeavesNoHalfMedia, which the sync branch removed along with WorkspaceHost.RemovePartialMediaAsync (the cancelled first copy's clean-up now runs in the copy job, tested in Data). ReplayAsync auto-merged with both intents: desktop's working-state conflicts and silent paths, and sync's skip of no-change versions, Settles journal flag and PruneReplaced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
c5ed31bced
21 files changed
+696
-54
No files matched your search
@@ -480,7 +480,9 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
/// only when they are those <paramref name="shown"/> lists (others are recorded and asked about first, as without a
|
||||
/// choice). Taking the server's everywhere tells <paramref name="kept"/> the working state as keeping this side's values
|
||||
/// would have left it (placed), and the working state it replaces is kept aside (<c>versions/.replaced</c>), never in the
|
||||
/// chain. A conflict recorded before stays when the home holds no version after the base (it lost them: nothing to
|
||||
/// chain. A conflict lists this side's value as the working state holds it, the base value it went back to included; where
|
||||
/// the working state holds the home's value already there is nothing to ask, and the replayed versions take that value
|
||||
/// too. A conflict recorded before stays when the home holds no version after the base (it lost them: nothing to
|
||||
/// settle it against).
|
||||
/// Written in steps a cut can stop at any point (<see cref="WorkspaceReplay"/>): the journal, the replayed versions, the
|
||||
/// base with the merged working state (the commit point), then the old versions set aside and the held ones adopted.
|
||||
@@ -534,6 +536,16 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
var choice = takeTheirs is EveryPath ? null : takeTheirs;
|
||||
List<ProjectSettings> mine = [.. locals.Select(v => ProjectMerge.Read(ProjectContent.Rebind(v.SettingsJson, photos)))];
|
||||
var replay = ProjectMerge.Replay(basisSettings, mine, headSettings, choice);
|
||||
// Where the working state holds the home's value already, the user has nothing to choose: the home's value is taken
|
||||
// there, in the replayed versions too, so they and the working state agree (never asked, never listed).
|
||||
var workingSide = WorkingConflicts(tip, working, basisSettings, headSettings);
|
||||
var silent = replay.Conflicts.Concat(ProjectMerge.Conflicts(tip, working, replay.Commits.Count > 0 ? replay.Commits[^1] : headSettings))
|
||||
.Select(d => d.Path).Where(p => !workingSide.Keys.Any(q => Overlaps(p, q))).ToHashSet(StringComparer.Ordinal);
|
||||
if (silent.Count > 0)
|
||||
{
|
||||
choice = choice is null ? silent : new HashSet<string>(choice.Concat(silent), StringComparer.Ordinal);
|
||||
replay = ProjectMerge.Replay(basisSettings, mine, headSettings, choice);
|
||||
}
|
||||
// This side's values wherever both changed: what taking the server's everywhere replaces (the editor's undo of it).
|
||||
var keptTip = replay.Commits.Count > 0 ? replay.Commits[^1] : headSettings;
|
||||
if (takeTheirs is EveryPath) replay = ProjectMerge.Replay(basisSettings, mine, headSettings, Paths(replay.Conflicts));
|
||||
@@ -541,8 +553,7 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
var merge = ProjectMerge.MergeWithConflicts(tip, working, newTip, choice);
|
||||
var keptMine = takeTheirs is EveryPath ? ProjectMerge.MergeWithConflicts(tip, working, keptTip).Merged : merge.Merged;
|
||||
if (takeTheirs is EveryPath) merge = ProjectMerge.MergeWithConflicts(tip, working, newTip, Paths(merge.Conflicts));
|
||||
var differences = AsInTheWorkingState(replay.Conflicts.Concat(merge.Conflicts).DistinctBy(d => d.Path),
|
||||
ProjectMerge.Conflicts(basisSettings, working, headSettings));
|
||||
var differences = AsInTheWorkingState(replay.Conflicts.Concat(merge.Conflicts).DistinctBy(d => d.Path).Where(d => !silent.Contains(d.Path)), workingSide);
|
||||
if (differences.Count > 0 && (takeTheirs is null || (shown is not null && !SameDifferences(shown.Differences, differences))))
|
||||
{
|
||||
var conflict = new WorkspaceConflict(head.Id, head.Number, basis?.Id ?? Guid.Empty, [.. locals.Select(v => v.Id)], differences, DateTimeOffset.UtcNow);
|
||||
@@ -1371,14 +1382,25 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
|
||||
/// <summary>
|
||||
/// The conflicts found as the user sees them: where the working state holds a value of its own against the home's
|
||||
/// (<paramref name="working"/>: edited since the last local version), that value is this side's, not the version's.
|
||||
/// (<paramref name="working"/>, <see cref="WorkingConflicts"/>), that value is this side's, not the version's.
|
||||
/// Keeping mine keeps it, and taking the server's replaces it, so one answer settles what was listed.
|
||||
/// </summary>
|
||||
private static List<SettingsDifference> AsInTheWorkingState(IEnumerable<SettingsDifference> found, IReadOnlyList<SettingsDifference> working)
|
||||
{
|
||||
var now = working.DistinctBy(d => d.Path).ToDictionary(d => d.Path, StringComparer.Ordinal);
|
||||
return [.. found.Select(d => now.TryGetValue(d.Path, out var held) ? held : d)];
|
||||
}
|
||||
private static List<SettingsDifference> AsInTheWorkingState(IEnumerable<SettingsDifference> found, IReadOnlyDictionary<string, SettingsDifference> working) =>
|
||||
[.. found.Select(d => working.TryGetValue(d.Path, out var held) ? held : d)];
|
||||
|
||||
/// <summary>
|
||||
/// The settings where the working state holds a value of its own against the home's head, by path: against the last
|
||||
/// local version (<paramref name="tip"/>: edited since it, the base value it went back to included), else against the
|
||||
/// base (the version's value, unchanged since). A conflict at a path neither lists has the home's value in the working
|
||||
/// state already.
|
||||
/// </summary>
|
||||
private static Dictionary<string, SettingsDifference> WorkingConflicts(ProjectSettings tip, ProjectSettings working, ProjectSettings basis, ProjectSettings head) =>
|
||||
ProjectMerge.Conflicts(tip, working, head).Concat(ProjectMerge.Conflicts(basis, working, head)).DistinctBy(d => d.Path)
|
||||
.ToDictionary(d => d.Path, StringComparer.Ordinal);
|
||||
|
||||
/// <summary>Two merge paths name the same setting, or one lies inside the other ("camera" and "camera.aspect").</summary>
|
||||
private static bool Overlaps(string a, string b) =>
|
||||
a == b || a.StartsWith(b + ".", StringComparison.Ordinal) || b.StartsWith(a + ".", StringComparison.Ordinal);
|
||||
|
||||
/// <summary>Whether two conflicts list the same settings with the same values on each side (in any order).</summary>
|
||||
private static bool SameDifferences(IReadOnlyList<SettingsDifference> shown, IReadOnlyList<SettingsDifference> found) =>
|
||||
|
||||
Reference in new issue
Block a user