feat(copies): pure comparison, detection rules, details payload and comparison sides
Detection, Integrate and Merge need one comparison of two copies of a time-lapse, so this adds it: CopyComparer classifies every photo (same, converted, same unhashed, deleted here/there, differs, two versions, only here/there) with strict Differs and Versions rules so whole-second capture times and bursts never pair, unusable frames held as nothing and marked for repair, and the score of design 3.2. CopyRules ports 1.1's same-originals gate exactly for "Link when half shared" and holds the Decide table, ask-again thresholds, fingerprints, hints and the probe sample. CopyPayload compares details in portable form (same photo at another index is no line) and merges the chosen sides into one payload that must parse as a project. CopySides reads both sides from the index and a server and answers the last-copy check across every archive. SyncTombstones gains FromDtos for local pairs. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
283d04d9cd
commit
f6f81e2c37
9 files changed
+1465
No files matched your search
@@ -0,0 +1,236 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Sync;
|
||||
|
||||
namespace Chronos.Data.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// The details of two copies line by line (owner review 6, Q4; design §4.3): title, tags, rating, notes and settings, the
|
||||
/// settings compared in their portable form (frame positions by photo), so the same choice on the same photo at another
|
||||
/// position is no difference; and the one payload both sides get once every line is chosen. Pure.
|
||||
/// </summary>
|
||||
public static class CopyPayload
|
||||
{
|
||||
/// <summary>The one line every difference of the frame positions (exclusions, hero, keyframes by photo) collapses into.</summary>
|
||||
public const string PendingFramesPath = "pendingFrames";
|
||||
|
||||
private const string Title = SyncRules.MetadataPath + "title";
|
||||
private const string Tags = SyncRules.MetadataPath + "tags";
|
||||
private const string Rating = SyncRules.MetadataPath + "rating";
|
||||
private const string Notes = SyncRules.MetadataPath + "notes";
|
||||
|
||||
/// <summary>
|
||||
/// The payload with its settings in portable form (<see cref="ProjectContent.ToPortable(string, FramePhotos)"/> on
|
||||
/// <paramref name="photos"/>, the frames its positions name). Settings that are not a project are kept normalised as they are.
|
||||
/// </summary>
|
||||
public static SyncPayload Portable(SyncPayload payload, FramePhotos photos)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(payload);
|
||||
ArgumentNullException.ThrowIfNull(photos);
|
||||
var settings = SyncRules.NormalizeSettings(payload.SettingsJson);
|
||||
try
|
||||
{
|
||||
return payload with { SettingsJson = ProjectContent.ToPortable(settings, photos) };
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return payload with { SettingsJson = settings };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Every difference of title, tags, rating, notes and settings, settings compared in their portable form (positions by
|
||||
/// photo, each side's settings made portable with its own photos), so the same exclusion at index 10 here and 12 there is
|
||||
/// no line. Lines under "pendingFrames" collapse into one line "pendingFrames" (Frame positions).
|
||||
/// </summary>
|
||||
public static IReadOnlyList<DetailLine> Lines(SyncPayload here, FramePhotos herePhotos, SyncPayload there, FramePhotos therePhotos)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(here);
|
||||
ArgumentNullException.ThrowIfNull(there);
|
||||
var mine = Portable(here, herePhotos);
|
||||
var theirs = Portable(there, therePhotos);
|
||||
return Collapse(SyncRules.Differences(mine, theirs, int.MaxValue), mine, theirs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The one payload both sides get, in portable form: here's values, with there's at every path chosen
|
||||
/// <see cref="CopySide.Other"/>. Every line must be chosen. Each side places it on its own frames at write time
|
||||
/// (<see cref="ProjectContent.Place"/>, under its lease).
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException">A line has no choice.</exception>
|
||||
/// <exception cref="InvalidDataException">The merged settings are not a project this Chronos reads: nothing is to be applied.</exception>
|
||||
public static SyncPayload Merge(SyncPayload herePortable, SyncPayload therePortable, IReadOnlyDictionary<string, CopySide> choices,
|
||||
IReadOnlyList<DetailLine> lines)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(herePortable);
|
||||
ArgumentNullException.ThrowIfNull(therePortable);
|
||||
ArgumentNullException.ThrowIfNull(choices);
|
||||
ArgumentNullException.ThrowIfNull(lines);
|
||||
if (lines.FirstOrDefault(l => !choices.ContainsKey(l.Path)) is { } unchosen)
|
||||
throw new ArgumentException($"The detail '{unchosen.Path}' has no side chosen.", nameof(choices));
|
||||
|
||||
var (title, tags, rating, notes) = (herePortable.Title, herePortable.Tags, herePortable.Rating, herePortable.Notes);
|
||||
var settings = Parse(SyncRules.NormalizeSettings(herePortable.SettingsJson));
|
||||
var other = Parse(SyncRules.NormalizeSettings(therePortable.SettingsJson));
|
||||
foreach (var line in lines.Where(l => choices[l.Path] == CopySide.Other).DistinctBy(l => l.Path, StringComparer.Ordinal))
|
||||
{
|
||||
switch (line.Path)
|
||||
{
|
||||
case Title:
|
||||
title = therePortable.Title;
|
||||
break;
|
||||
case Tags:
|
||||
tags = therePortable.Tags;
|
||||
break;
|
||||
case Rating:
|
||||
rating = therePortable.Rating;
|
||||
break;
|
||||
case Notes:
|
||||
notes = therePortable.Notes;
|
||||
break;
|
||||
case "settings":
|
||||
settings = other?.DeepClone();
|
||||
break;
|
||||
default:
|
||||
settings = Set(settings, other, line.Path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var json = settings?.ToJsonString() ?? string.Empty;
|
||||
string merged;
|
||||
try
|
||||
{
|
||||
// Read as a project (never a newer Chronos's: its values may mean something else), then written canonically.
|
||||
_ = ProjectSettings.FromJson(json);
|
||||
merged = ProjectContent.Canonical(json);
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
throw new InvalidDataException("The merged settings are not a project.", ex);
|
||||
}
|
||||
return new SyncPayload(title, tags, rating, notes, merged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the excluded flag, by photo, for the incoming versions of a Union keep-both (design §5e): each key (a canonical
|
||||
/// SHA-256, or "u:<size>:<capture ms>") becomes an excluded pending frame, or marks the one already naming it.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidDataException">The settings are of a newer Chronos.</exception>
|
||||
/// <exception cref="JsonException">The settings are not a project.</exception>
|
||||
public static SyncPayload ExcludeVersions(SyncPayload portable, IReadOnlyCollection<string> photoKeys)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(portable);
|
||||
ArgumentNullException.ThrowIfNull(photoKeys);
|
||||
if (photoKeys.Count == 0) return portable;
|
||||
var settings = ProjectSettings.FromJson(SyncRules.NormalizeSettings(portable.SettingsJson));
|
||||
var pending = (settings.PendingFrames ?? []).ToList();
|
||||
foreach (var key in photoKeys.Distinct(StringComparer.Ordinal))
|
||||
{
|
||||
if (Photo(key) is not { } photo) continue;
|
||||
var at = pending.FindIndex(p => p.Occurrence == 0 && Names(p, photo));
|
||||
if (at >= 0) pending[at] = pending[at] with { Excluded = true };
|
||||
else pending.Add(new PendingFrame { Sha256 = photo.Sha256, Size = photo.Size, CapturedAt = photo.CapturedAt, Excluded = true });
|
||||
}
|
||||
return portable with { SettingsJson = ProjectContent.Canonical((settings with { PendingFrames = pending }).ToJson()) };
|
||||
}
|
||||
|
||||
/// <summary>Paths whose value moved between two payloads of one side (the apply-time check of design §5c step 5).</summary>
|
||||
public static IReadOnlySet<string> Moved(SyncPayload before, SyncPayload after)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(before);
|
||||
ArgumentNullException.ThrowIfNull(after);
|
||||
return Collapse(SyncRules.Differences(before, after, int.MaxValue), before, after).Select(l => l.Path).ToHashSet(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
private static List<DetailLine> Collapse(IReadOnlyList<SettingsDifference> differences, SyncPayload here, SyncPayload there)
|
||||
{
|
||||
var lines = new List<DetailLine>(differences.Count);
|
||||
var pending = false;
|
||||
foreach (var difference in differences)
|
||||
{
|
||||
if (difference.Path == PendingFramesPath || difference.Path.StartsWith(PendingFramesPath + ".", StringComparison.Ordinal))
|
||||
{
|
||||
if (pending) continue;
|
||||
pending = true;
|
||||
lines.Add(new DetailLine(PendingFramesPath, PendingOf(here), PendingOf(there)));
|
||||
continue;
|
||||
}
|
||||
lines.Add(new DetailLine(difference.Path, difference.Mine, difference.Theirs));
|
||||
}
|
||||
return lines;
|
||||
|
||||
static string? PendingOf(SyncPayload payload) =>
|
||||
Parse(SyncRules.NormalizeSettings(payload.SettingsJson)) is JsonObject project && project[PendingFramesPath] is { } node ? node.ToJsonString() : null;
|
||||
}
|
||||
|
||||
private static JsonNode? Parse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonNode.Parse(json);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return JsonValue.Create(json);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Sets <paramref name="path"/> of <paramref name="target"/> to the value it has in <paramref name="source"/>; removes it where the source has none.</summary>
|
||||
private static JsonNode? Set(JsonNode? target, JsonNode? source, string path)
|
||||
{
|
||||
var names = path.Split('.');
|
||||
var value = source;
|
||||
var present = true;
|
||||
foreach (var name in names)
|
||||
{
|
||||
if (value is JsonObject o && o.TryGetPropertyValue(name, out var child))
|
||||
{
|
||||
value = child;
|
||||
continue;
|
||||
}
|
||||
present = false;
|
||||
break;
|
||||
}
|
||||
if (target is not JsonObject root)
|
||||
{
|
||||
if (!present) return target;
|
||||
root = new JsonObject();
|
||||
target = root;
|
||||
}
|
||||
var parent = root;
|
||||
for (var i = 0; i < names.Length - 1; i++)
|
||||
{
|
||||
if (parent[names[i]] is JsonObject next)
|
||||
{
|
||||
parent = next;
|
||||
continue;
|
||||
}
|
||||
if (!present) return target;
|
||||
var created = new JsonObject();
|
||||
parent[names[i]] = created;
|
||||
parent = created;
|
||||
}
|
||||
if (present) parent[names[^1]] = value?.DeepClone();
|
||||
else parent.Remove(names[^1]);
|
||||
return target;
|
||||
}
|
||||
|
||||
/// <summary>The photo a key names (<see cref="CopyComparer.UnhashedKey"/>); null for an unhashed photo without a capture time.</summary>
|
||||
private static FramePhoto? Photo(string key)
|
||||
{
|
||||
if (!key.StartsWith(CopyComparer.UnhashedPrefix, StringComparison.Ordinal)) return key.Length == 0 ? null : new FramePhoto(key.ToLowerInvariant(), 0, null);
|
||||
var parts = key[CopyComparer.UnhashedPrefix.Length..].Split(':');
|
||||
return parts.Length == 2 && long.TryParse(parts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var size)
|
||||
&& long.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var ms)
|
||||
? new FramePhoto(null, size, new DateTime(ms * TimeSpan.TicksPerMillisecond, DateTimeKind.Unspecified))
|
||||
: null;
|
||||
}
|
||||
|
||||
private static bool Names(PendingFrame entry, FramePhoto photo) => photo.IsHashed
|
||||
? string.Equals(entry.Sha256, photo.Sha256, StringComparison.OrdinalIgnoreCase)
|
||||
: string.IsNullOrEmpty(entry.Sha256) && entry.Size == photo.Size && entry.CapturedAt is { } at
|
||||
&& CopyComparer.Millisecond(at) == CopyComparer.Millisecond(photo.CapturedAt!.Value);
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Chronos.Core.Project;
|
||||
|
||||
namespace Chronos.Data.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// The decisions of detection that need no I/O (owner review 6, #73; design §3.1, §3.2): whether two copies are a pair, what
|
||||
/// the Link matches setting does with one, 1.1's same-originals gate, when a kept-apart pair asks again, fingerprints, hints
|
||||
/// and the probe sample. Pure and thread-safe.
|
||||
/// </summary>
|
||||
public static class CopyRules
|
||||
{
|
||||
/// <summary>A pair at all needs this much of the smaller side shared (per mille), besides at least one photo.</summary>
|
||||
public const int MinContainment = 100;
|
||||
|
||||
/// <summary>The photos a probe samples of a sequence by default.</summary>
|
||||
public const int ProbeSize = 64;
|
||||
|
||||
private const string FingerprintVersion = "c1";
|
||||
|
||||
/// <summary>A pair at all: a link, a session key, or (Shared + SharedUnhashed + SharedRemoved) ≥ 1 and Containment ≥ 100.</summary>
|
||||
public static bool IsCopy(CopyEvidence evidence, CopyScore score)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(score);
|
||||
if (evidence is CopyEvidence.Link or CopyEvidence.SessionKey) return true;
|
||||
return score.Shared + score.SharedUnhashed + score.SharedRemoved >= 1 && score.Containment >= MinContainment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What detection does with a pair that has no answer (state Candidate or new), by the setting (design §3.2): a local↔local
|
||||
/// pair is never linked (it would need a merge); WhenIdentical links exactly the same photos known by SHA-256 on both sides;
|
||||
/// WhenHalfShared links by 1.1's rule (<see cref="SameOriginals"/>). Everything else that is a pair asks.
|
||||
/// </summary>
|
||||
/// <param name="evidence">The pair's evidence (a back-reference makes a pair without shared photos); Hashes by default.</param>
|
||||
public static CopyDecision Decide(CopyLinking linking, CopyKind kind, CopyScore score, SameOriginalsInput gate, CopyEvidence evidence = CopyEvidence.Hashes)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(score);
|
||||
ArgumentNullException.ThrowIfNull(gate);
|
||||
if (kind == CopyKind.LocalServer)
|
||||
{
|
||||
var link = linking switch
|
||||
{
|
||||
CopyLinking.WhenIdentical => score.Identical && score.ByHash,
|
||||
CopyLinking.WhenHalfShared => SameOriginals(gate),
|
||||
_ => false,
|
||||
};
|
||||
if (link) return CopyDecision.Link;
|
||||
}
|
||||
return IsCopy(evidence, score) ? CopyDecision.Ask : CopyDecision.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 1.1's <c>SyncService.SameOriginalsAsync</c> rule with the gates of <c>MatchByContentAsync</c>, ported exactly (owner Q1
|
||||
/// "today's rule"): both unlinked, the same first-capture second, camera models equal ignoring case, at least one local
|
||||
/// hash, and at least half of the smaller side's originals shared by canonical SHA-256.
|
||||
/// </summary>
|
||||
public static bool SameOriginals(SameOriginalsInput gate)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(gate);
|
||||
if (!gate.BothUnlinked || gate.LocalFirst is not { } local || gate.RemoteFirst is not { } remote) return false;
|
||||
if (Second(local) != Second(remote)) return false;
|
||||
if (!string.Equals(gate.LocalCamera, gate.RemoteCamera, StringComparison.OrdinalIgnoreCase)) return false;
|
||||
if (gate.LocalHashed <= 0) return false;
|
||||
return gate.SharedCanonical > 0 && 2L * gate.SharedCanonical >= Math.Min(gate.LocalHashed, gate.RemoteFrames);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A kept-apart pair asks again (design §3.6): it became Identical (it was not when the user answered), or Shared grew by
|
||||
/// at least max(10, 25 % of the shared count the user answered).
|
||||
/// </summary>
|
||||
public static bool AsksAgain(FoundCopy answered, CopyScore now)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(answered);
|
||||
ArgumentNullException.ThrowIfNull(now);
|
||||
if (answered.State != CopyState.KeptApart) return false;
|
||||
var wasIdentical = WasIdentical(answered.AnsweredFingerprint) ?? answered.Score.Identical;
|
||||
if (now.Identical && !wasIdentical) return true;
|
||||
var before = answered.AnsweredShared ?? answered.Score.Shared;
|
||||
var grown = now.Shared - before;
|
||||
return grown >= 10 && 4L * grown >= before;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What a comparison found, as text: the counts and both sides' frames versions. Equal fingerprints mean nothing moved
|
||||
/// since (detection skips the comparison; a kept-apart answer stands).
|
||||
/// </summary>
|
||||
public static string Fingerprint(CopyScore score, int localFramesVersion, int otherFramesVersion)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(score);
|
||||
return string.Join(':', FingerprintVersion,
|
||||
Text(score.Shared), Text(score.SharedUnhashed), Text(score.SharedRemoved), Text(score.OnlyHere), Text(score.OnlyThere), Text(score.Differs),
|
||||
Text(score.DeletedHere), Text(score.DeletedThere), Text(score.Versions), Text(score.LocalPhotos), Text(score.OtherPhotos),
|
||||
Text(localFramesVersion), Text(otherFramesVersion));
|
||||
|
||||
static string Text(int value) => value.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>The SHA-256 (lower-case hex) of a plan's lines joined by '\n': equal plans have equal fingerprints.</summary>
|
||||
public static string PlanFingerprint(IEnumerable<string> lines)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(lines);
|
||||
return Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(string.Join('\n', lines))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How alike two sequences look, 0–100 (design §3.1): 40 × the capture-range overlap fraction of the shorter range, 25 when
|
||||
/// the camera models are equal ignoring case, 20 when the median intervals are within 10 %, 15 when the titles share a word
|
||||
/// of at least 4 letters (ignoring case). A null Last is read as First (a sequence without a last capture yet).
|
||||
/// </summary>
|
||||
public static int Hints(CopyHintsInput a, CopyHintsInput b)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(a);
|
||||
ArgumentNullException.ThrowIfNull(b);
|
||||
var score = (int)Math.Round(40 * Overlap(a, b), MidpointRounding.AwayFromZero);
|
||||
if (!string.IsNullOrWhiteSpace(a.Camera) && string.Equals(a.Camera.Trim(), b.Camera?.Trim(), StringComparison.OrdinalIgnoreCase)) score += 25;
|
||||
if (a.MedianInterval is > 0 and var x && b.MedianInterval is > 0 and var y && Math.Abs(x - y) <= 0.1 * Math.Max(x, y)) score += 20;
|
||||
if (Words(a.Title).Overlaps(Words(b.Title))) score += 15;
|
||||
return Math.Clamp(score, 0, 100);
|
||||
}
|
||||
|
||||
/// <summary>Up to <paramref name="max"/> photo keys, evenly spaced over the sequence, the first and the last included.</summary>
|
||||
public static IReadOnlyList<FramePhoto> Probe(IReadOnlyList<FramePhoto> photos, int max = ProbeSize)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(photos);
|
||||
if (max <= 0 || photos.Count == 0) return [];
|
||||
if (photos.Count <= max) return [.. photos];
|
||||
if (max == 1) return [photos[0]];
|
||||
var sample = new FramePhoto[max];
|
||||
var last = photos.Count - 1;
|
||||
for (var i = 0; i < max; i++) sample[i] = photos[(int)((long)i * last / (max - 1))];
|
||||
return sample;
|
||||
}
|
||||
|
||||
private static DateTime Second(DateTime time) => new(time.Ticks - time.Ticks % TimeSpan.TicksPerSecond, DateTimeKind.Unspecified);
|
||||
|
||||
/// <summary>Whether a fingerprint (<see cref="Fingerprint"/>) records an Identical score; null for one in another form.</summary>
|
||||
private static bool? WasIdentical(string? fingerprint)
|
||||
{
|
||||
if (fingerprint is null) return null;
|
||||
var parts = fingerprint.Split(':');
|
||||
if (parts.Length != 14 || parts[0] != FingerprintVersion) return null;
|
||||
var counts = new int[parts.Length - 1];
|
||||
for (var i = 1; i < parts.Length; i++)
|
||||
{
|
||||
if (!int.TryParse(parts[i], NumberStyles.Integer, CultureInfo.InvariantCulture, out counts[i - 1])) return null;
|
||||
}
|
||||
// shared, shared unhashed, removed, only here, only there, differs, deleted here, deleted there, versions, …
|
||||
return counts[3] == 0 && counts[4] == 0 && counts[5] == 0 && counts[6] == 0 && counts[7] == 0 && counts[0] + counts[1] > 0;
|
||||
}
|
||||
|
||||
/// <summary>The fraction of the shorter capture range the two ranges share (a single instant within the other's range: 1).</summary>
|
||||
private static double Overlap(CopyHintsInput a, CopyHintsInput b)
|
||||
{
|
||||
if (a.First is not { } aFirst || b.First is not { } bFirst) return 0;
|
||||
var (aFrom, aTo) = Range(aFirst, a.Last);
|
||||
var (bFrom, bTo) = Range(bFirst, b.Last);
|
||||
var from = aFrom > bFrom ? aFrom : bFrom;
|
||||
var to = aTo < bTo ? aTo : bTo;
|
||||
if (to < from) return 0;
|
||||
var shorter = Math.Min((aTo - aFrom).Ticks, (bTo - bFrom).Ticks);
|
||||
return shorter <= 0 ? 1 : Math.Min(1, (double)(to - from).Ticks / shorter);
|
||||
|
||||
static (DateTime From, DateTime To) Range(DateTime first, DateTime? last) => last is { } l && l >= first ? (first, l) : (first, first);
|
||||
}
|
||||
|
||||
/// <summary>The words of at least 4 letters of a title, lower-case.</summary>
|
||||
private static HashSet<string> Words(string? title)
|
||||
{
|
||||
var words = new HashSet<string>(StringComparer.Ordinal);
|
||||
if (string.IsNullOrWhiteSpace(title)) return words;
|
||||
var word = new StringBuilder();
|
||||
foreach (var c in title + " ")
|
||||
{
|
||||
if (char.IsLetterOrDigit(c))
|
||||
{
|
||||
word.Append(char.ToLowerInvariant(c));
|
||||
continue;
|
||||
}
|
||||
if (word.ToString() is var w && w.Count(char.IsLetter) >= 4) words.Add(w);
|
||||
word.Clear();
|
||||
}
|
||||
return words;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol;
|
||||
|
||||
namespace Chronos.Data.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// The two sides of a comparison as <see cref="CopyComparer"/> reads them (owner review 6, #73; design §4.2): a local
|
||||
/// sequence's frames and tombstones, a server sequence's manifest with its frames' capture times, and the last-copy check
|
||||
/// the planners make before anything goes to a trash.
|
||||
/// </summary>
|
||||
public sealed class CopySides(ChronosDatabase db)
|
||||
{
|
||||
/// <summary>Frames whose file holds nothing usable: the other side's copy repairs them.</summary>
|
||||
public const FrameFlags UnusableFlags = FrameFlags.Missing | FrameFlags.Corrupt;
|
||||
|
||||
/// <summary>Parameters per statement of <see cref="HeldElsewhereAsync"/>.</summary>
|
||||
private const int Batch = 500;
|
||||
|
||||
private readonly ChronosDatabase _db = db ?? throw new ArgumentNullException(nameof(db));
|
||||
private readonly DbAccess _access = new(db.Database);
|
||||
|
||||
/// <summary>A local sequence: every frame row in index order and its tombstones (<see cref="SyncTombstones.ToDto"/>).</summary>
|
||||
public async Task<CopySideInput> LocalAsync(Guid id, CancellationToken ct)
|
||||
{
|
||||
var frames = await Processing.SequenceFrames.ListAsync(_db, id, ct).ConfigureAwait(false);
|
||||
var removals = await _db.FrameRemovals.ListBySequenceAsync(id, ct).ConfigureAwait(false);
|
||||
return new CopySideInput(
|
||||
[.. frames.Select(f => new CopyPhotoInput(f.Id, f.Index, f.FileName, f.Sha256, f.Size, f.CapturedAt, (f.Flags & UnusableFlags) != 0))],
|
||||
SyncTombstones.ToDto(removals));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A server sequence: its manifest (content, flags, tombstones) with the capture times of its frame rows (the manifest
|
||||
/// has none). A frame the listing no longer has keeps no capture time.
|
||||
/// </summary>
|
||||
public async Task<CopySideInput> RemoteAsync(ISyncRemote remote, Guid id, CancellationToken ct)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(remote);
|
||||
var manifest = await remote.GetManifestAsync(id, ct).ConfigureAwait(false);
|
||||
var rows = await remote.ListFramesAsync(id, ct).ConfigureAwait(false);
|
||||
var captured = new Dictionary<Guid, DateTime?>(rows.Count);
|
||||
foreach (var row in rows) captured[row.Id] = row.CapturedAt;
|
||||
return new CopySideInput(
|
||||
[.. manifest.Frames.Select(f => new CopyPhotoInput(f.Id, f.Index, f.FileName, f.Sha256.Length == 0 ? null : f.Sha256, f.Size,
|
||||
captured.GetValueOrDefault(f.Id), (f.Flags & (long)UnusableFlags) != 0))],
|
||||
manifest.Removed ?? []);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The raw SHA-256 (lower-case) of <paramref name="sha256"/> that a usable frame (not Missing or Corrupt) of any sequence
|
||||
/// of this index other than <paramref name="except"/> holds: what is not the last copy of its photo. Batched.
|
||||
/// </summary>
|
||||
public async Task<IReadOnlySet<string>> HeldElsewhereAsync(IReadOnlyCollection<string> sha256, IReadOnlyCollection<Guid> except, CancellationToken ct)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sha256);
|
||||
ArgumentNullException.ThrowIfNull(except);
|
||||
var held = new HashSet<string>(StringComparer.Ordinal);
|
||||
var wanted = sha256.Where(s => !string.IsNullOrEmpty(s)).Select(s => s.ToLowerInvariant()).Distinct(StringComparer.Ordinal).ToList();
|
||||
var excluded = except.Distinct().ToList();
|
||||
foreach (var chunk in wanted.Chunk(Math.Max(1, Batch - excluded.Count)))
|
||||
{
|
||||
var p = new SqlParameters();
|
||||
var not = excluded.Count == 0 ? string.Empty : $" AND sequence_id NOT IN ({string.Join(", ", excluded.Select(id => p.Add(id)))})";
|
||||
var hashes = string.Join(", ", chunk.Select(sha => p.Add(sha)));
|
||||
var rows = await _access.ListAsync(
|
||||
$"SELECT DISTINCT sha256 FROM frames WHERE sha256 IN ({hashes}) AND (flags & {(int)UnusableFlags}) = 0{not}",
|
||||
p.ToArray(), r => r.GetString(0), ct).ConfigureAwait(false);
|
||||
foreach (var sha in rows) held.Add(sha.ToLowerInvariant());
|
||||
}
|
||||
return held;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
using System.Globalization;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Copies;
|
||||
|
||||
namespace Chronos.Data.Sync;
|
||||
|
||||
/// <summary>
|
||||
/// The photo-by-photo comparison of two copies of one time-lapse (owner review 6, #73; design §4.1): which photos both hold,
|
||||
/// which only one holds, which one side deleted, which differ and which a Union kept in two versions. Detection, the Compare
|
||||
/// dialog, Integrate and Merge all read this one comparison. Pure: no I/O, thread-safe, O(n log n).
|
||||
/// </summary>
|
||||
public static class CopyComparer
|
||||
{
|
||||
/// <summary>The unhashed key prefix: "u:<size>:<capture millisecond>".</summary>
|
||||
internal const string UnhashedPrefix = "u:";
|
||||
|
||||
/// <summary>
|
||||
/// Compares <paramref name="here"/> (this PC, or the kept sequence of a merge) with <paramref name="there"/> (the server,
|
||||
/// or the other local sequence). Each photo lands in exactly one class; unusable frames (Missing or Corrupt) hold nothing
|
||||
/// and mark the photo the other side brings as a repair.
|
||||
/// </summary>
|
||||
public static CopyComparisonResult Compare(CopySideInput here, CopySideInput there)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(here);
|
||||
ArgumentNullException.ThrowIfNull(there);
|
||||
// 1. Tombstones of both sides; unusable frames left out of their side's holdings.
|
||||
var tombstones = SyncTombstones.FromDtos(here.Removed ?? [], there.Removed);
|
||||
var mine = Holdings(here.Photos, tombstones);
|
||||
var theirs = Holdings(there.Photos, tombstones);
|
||||
var brokenHere = Broken(here.Photos, tombstones);
|
||||
var brokenThere = Broken(there.Photos, tombstones);
|
||||
var theirsByKey = theirs.ToDictionary(h => h.Key, StringComparer.Ordinal);
|
||||
var done = new HashSet<Holding>(ReferenceEqualityComparer.Instance);
|
||||
var photos = new List<ComparedPhoto>(mine.Count + theirs.Count);
|
||||
|
||||
// 3. Same and Converted: one canonical key on both sides.
|
||||
foreach (var h in mine)
|
||||
{
|
||||
if (!h.Hashed || !theirsByKey.TryGetValue(h.Key, out var t)) continue;
|
||||
var (hereFrame, thereFrame, same) = Pick(h, t);
|
||||
photos.Add(new ComparedPhoto(same ? PhotoClass.Same : PhotoClass.Converted, h.Key, hereFrame, thereFrame, h.Occurrences, t.Occurrences, hereFrame.Size));
|
||||
done.Add(h);
|
||||
done.Add(t);
|
||||
}
|
||||
|
||||
// 4. SameUnhashed: one side not hashed, the same size and capture millisecond (FramePhoto.Matches), one to one.
|
||||
var bySizeAndTime = new Dictionary<(long Size, long Ms), List<Holding>>();
|
||||
foreach (var t in theirs)
|
||||
{
|
||||
if (done.Contains(t) || t.Ms is not { } ms) continue;
|
||||
if (!bySizeAndTime.TryGetValue((t.First.Size, ms), out var list)) bySizeAndTime[(t.First.Size, ms)] = list = [];
|
||||
list.Add(t);
|
||||
}
|
||||
foreach (var h in mine)
|
||||
{
|
||||
if (done.Contains(h) || h.Ms is not { } ms || !bySizeAndTime.TryGetValue((h.First.Size, ms), out var candidates)) continue;
|
||||
var t = candidates.FirstOrDefault(c => !done.Contains(c) && (!h.Hashed || !c.Hashed));
|
||||
if (t is null) continue;
|
||||
var key = h.Hashed ? h.Key : t.Hashed ? t.Key : h.Key;
|
||||
photos.Add(new ComparedPhoto(PhotoClass.SameUnhashed, key, h.First, t.First, h.Occurrences, t.Occurrences, h.First.Size));
|
||||
done.Add(h);
|
||||
done.Add(t);
|
||||
}
|
||||
|
||||
// 5. Deleted there / deleted here: held by one side, tombstoned by the other, which does not hold it.
|
||||
foreach (var h in mine.Where(h => !done.Contains(h) && h.Hashed && tombstones.DeletedRemotely(h.Key)))
|
||||
{
|
||||
photos.Add(new ComparedPhoto(PhotoClass.DeletedThere, h.Key, h.First, null, h.Occurrences, 0, h.First.Size));
|
||||
done.Add(h);
|
||||
}
|
||||
foreach (var t in theirs.Where(t => !done.Contains(t) && t.Hashed && tombstones.DeletedLocally(t.Key)))
|
||||
{
|
||||
photos.Add(Brought(PhotoClass.DeletedHere, t, brokenHere));
|
||||
done.Add(t);
|
||||
}
|
||||
|
||||
// 6. Differs, strictly: one hashed photo per side at one sub-second instant, with the same file name.
|
||||
var hereAt = HashedAt(mine.Where(h => !done.Contains(h)));
|
||||
var thereAt = HashedAt(theirs.Where(t => !done.Contains(t)));
|
||||
foreach (var (ms, onHere) in hereAt)
|
||||
{
|
||||
if (onHere.Count != 1 || !SubSecond(ms) || !thereAt.TryGetValue(ms, out var onThere) || onThere.Count != 1) continue;
|
||||
var (h, t) = (onHere[0], onThere[0]);
|
||||
if (!string.Equals(h.First.FileName, t.First.FileName, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
photos.Add(new ComparedPhoto(PhotoClass.Differs, h.Key, h.First, t.First, h.Occurrences, t.Occurrences, h.First.Size));
|
||||
done.Add(h);
|
||||
done.Add(t);
|
||||
}
|
||||
|
||||
// 7. Versions: a sub-second instant holding exactly the same two shared photos on both sides (a Union keep-both).
|
||||
MarkVersions(photos, mine, theirs);
|
||||
|
||||
// 8. The rest is on one side only (unhashed leftovers are not assumed to match).
|
||||
foreach (var h in mine.Where(h => !done.Contains(h)))
|
||||
photos.Add(new ComparedPhoto(PhotoClass.OnlyHere, h.Key, h.First, null, h.Occurrences, 0, h.First.Size, RepairsThere: Repairs(h, brokenThere)));
|
||||
foreach (var t in theirs.Where(t => !done.Contains(t))) photos.Add(Brought(PhotoClass.OnlyThere, t, brokenHere));
|
||||
|
||||
photos.Sort(Order);
|
||||
return new CopyComparisonResult(photos, Totals(photos), Score(photos, mine.Count, theirs.Count));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For linked pairs at each reconcile: only the deletion counts, cheaply. Deleted there: distinct photos this side holds
|
||||
/// that the other side tombstoned and does not hold; deleted here the other way round (as <see cref="SyncRules.CompareOriginals(IReadOnlyCollection{FramePhoto}, IReadOnlyCollection{FramePhoto}, SyncTombstones)"/>
|
||||
/// leaves them out).
|
||||
/// </summary>
|
||||
public static (int DeletedHere, int DeletedThere) Deletions(IReadOnlyCollection<FramePhoto> here, IReadOnlyCollection<FramePhoto> there, SyncTombstones tombstones)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(here);
|
||||
ArgumentNullException.ThrowIfNull(there);
|
||||
ArgumentNullException.ThrowIfNull(tombstones);
|
||||
if (tombstones.IsEmpty) return (0, 0);
|
||||
var mine = here.Select(tombstones.Canonical).ToList();
|
||||
var theirs = there.Select(tombstones.Canonical).ToList();
|
||||
var minePhotos = new FramePhotos(mine.Select((p, i) => (i, p)));
|
||||
var theirPhotos = new FramePhotos(theirs.Select((p, i) => (i, p)));
|
||||
return (Count(theirs, tombstones.DeletedLocally, minePhotos), Count(mine, tombstones.DeletedRemotely, theirPhotos));
|
||||
|
||||
static int Count(List<FramePhoto> side, Func<string?, bool> deleted, FramePhotos other) =>
|
||||
side.Where(p => p.IsHashed && deleted(p.Sha256) && other.IndexOf(p) is null).Select(p => p.Sha256!.ToLowerInvariant()).Distinct(StringComparer.Ordinal).Count();
|
||||
}
|
||||
|
||||
/// <summary>The key of an unhashed photo by its size and capture time; a photo without a time is keyed by its frame (it matches nothing).</summary>
|
||||
internal static string UnhashedKey(long size, DateTime? capturedAt, Guid frameId) => capturedAt is { } at
|
||||
? string.Create(CultureInfo.InvariantCulture, $"{UnhashedPrefix}{size}:{Millisecond(at)}")
|
||||
: string.Create(CultureInfo.InvariantCulture, $"{UnhashedPrefix}{size}:{frameId:N}");
|
||||
|
||||
internal static long Millisecond(DateTime time) => time.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
|
||||
/// <summary>A capture millisecond with a sub-second part: the camera records real sub-second times.</summary>
|
||||
private static bool SubSecond(long ms) => ms % 1000 != 0;
|
||||
|
||||
/// <summary>One photo of one side: its key and the frames holding it, in index order (the first stands for it).</summary>
|
||||
private sealed class Holding(string key, bool hashed, List<CopyPhotoInput> frames)
|
||||
{
|
||||
public string Key { get; } = key;
|
||||
|
||||
public bool Hashed { get; } = hashed;
|
||||
|
||||
public List<CopyPhotoInput> Frames { get; } = frames;
|
||||
|
||||
public CopyPhotoInput First => Frames[0];
|
||||
|
||||
public int Occurrences => Frames.Count;
|
||||
|
||||
public long? Ms => First.CapturedAt is { } at ? Millisecond(at) : null;
|
||||
}
|
||||
|
||||
/// <summary>2. A side's usable frames grouped by photo key (copies of one photo inside a side count once), in index order.</summary>
|
||||
private static List<Holding> Holdings(IReadOnlyList<CopyPhotoInput> photos, SyncTombstones tombstones)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(photos);
|
||||
var result = new List<Holding>();
|
||||
var byKey = new Dictionary<string, Holding>(StringComparer.Ordinal);
|
||||
foreach (var frame in photos.Where(p => p is { Unusable: false }).OrderBy(p => p.Index).ThenBy(p => p.FrameId))
|
||||
{
|
||||
var hashed = !string.IsNullOrEmpty(frame.Sha256);
|
||||
var key = Key(frame, tombstones);
|
||||
if (byKey.TryGetValue(key, out var holding))
|
||||
{
|
||||
holding.Frames.Add(frame);
|
||||
continue;
|
||||
}
|
||||
byKey[key] = holding = new Holding(key, hashed, [frame]);
|
||||
result.Add(holding);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string Key(CopyPhotoInput frame, SyncTombstones tombstones) => string.IsNullOrEmpty(frame.Sha256)
|
||||
? UnhashedKey(frame.Size, frame.CapturedAt, frame.FrameId)
|
||||
: tombstones.Canonical(frame.Sha256)!;
|
||||
|
||||
/// <summary>The keys of a side's unusable frames: canonical SHA-256 and size and capture time, so a photo either way marks a repair.</summary>
|
||||
private static HashSet<string> Broken(IReadOnlyList<CopyPhotoInput> photos, SyncTombstones tombstones)
|
||||
{
|
||||
var broken = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var frame in photos.Where(p => p is { Unusable: true }))
|
||||
{
|
||||
broken.Add(Key(frame, tombstones));
|
||||
if (frame.CapturedAt is not null) broken.Add(UnhashedKey(frame.Size, frame.CapturedAt, frame.FrameId));
|
||||
}
|
||||
return broken;
|
||||
}
|
||||
|
||||
private static bool Repairs(Holding brought, HashSet<string> broken) =>
|
||||
broken.Count > 0 && (broken.Contains(brought.Key) || (brought.First.CapturedAt is not null
|
||||
&& broken.Contains(UnhashedKey(brought.First.Size, brought.First.CapturedAt, brought.First.FrameId))));
|
||||
|
||||
/// <summary>A photo only the other side holds (or holds and this side deleted).</summary>
|
||||
private static ComparedPhoto Brought(PhotoClass c, Holding t, HashSet<string> brokenHere) =>
|
||||
new(c, t.Key, null, t.First, 0, t.Occurrences, t.First.Size, RepairsHere: Repairs(t, brokenHere));
|
||||
|
||||
/// <summary>The frames standing for a photo both hold: one with the same raw SHA-256 on each side when there is one (Same), else the first (Converted).</summary>
|
||||
private static (CopyPhotoInput Here, CopyPhotoInput There, bool Same) Pick(Holding h, Holding t)
|
||||
{
|
||||
foreach (var mine in h.Frames)
|
||||
{
|
||||
var theirs = t.Frames.FirstOrDefault(f => string.Equals(f.Sha256, mine.Sha256, StringComparison.OrdinalIgnoreCase));
|
||||
if (theirs is not null) return (mine, theirs, true);
|
||||
}
|
||||
return (h.First, t.First, false);
|
||||
}
|
||||
|
||||
/// <summary>The hashed photos left at each capture millisecond.</summary>
|
||||
private static SortedDictionary<long, List<Holding>> HashedAt(IEnumerable<Holding> holdings)
|
||||
{
|
||||
var at = new SortedDictionary<long, List<Holding>>();
|
||||
foreach (var h in holdings)
|
||||
{
|
||||
if (!h.Hashed || h.Ms is not { } ms) continue;
|
||||
if (!at.TryGetValue(ms, out var list)) at[ms] = list = [];
|
||||
list.Add(h);
|
||||
}
|
||||
return at;
|
||||
}
|
||||
|
||||
private static void MarkVersions(List<ComparedPhoto> photos, List<Holding> mine, List<Holding> theirs)
|
||||
{
|
||||
var hereAt = KeysAt(mine);
|
||||
var thereAt = KeysAt(theirs);
|
||||
var shared = photos.Where(p => p.Class is PhotoClass.Same or PhotoClass.Converted).Select(p => p.Key).ToHashSet(StringComparer.Ordinal);
|
||||
for (var i = 0; i < photos.Count; i++)
|
||||
{
|
||||
var p = photos[i];
|
||||
if (p.Class is not (PhotoClass.Same or PhotoClass.Converted) || p.Here!.CapturedAt is not { } hereTime || p.There!.CapturedAt is not { } thereTime) continue;
|
||||
var ms = Millisecond(hereTime);
|
||||
if (ms != Millisecond(thereTime) || !SubSecond(ms)) continue;
|
||||
if (!hereAt.TryGetValue(ms, out var onHere) || !thereAt.TryGetValue(ms, out var onThere)) continue;
|
||||
if (onHere.Count == 2 && onThere.Count == 2 && onHere.SetEquals(onThere) && onHere.All(shared.Contains)) photos[i] = p with { Class = PhotoClass.Versions };
|
||||
}
|
||||
|
||||
static Dictionary<long, HashSet<string>> KeysAt(List<Holding> side)
|
||||
{
|
||||
var at = new Dictionary<long, HashSet<string>>();
|
||||
foreach (var h in side)
|
||||
{
|
||||
if (h.Ms is not { } ms) continue;
|
||||
if (!at.TryGetValue(ms, out var keys)) at[ms] = keys = new HashSet<string>(StringComparer.Ordinal);
|
||||
keys.Add(h.Key);
|
||||
}
|
||||
return at;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Capture order, then key and class: the same for any order of the inputs.</summary>
|
||||
private static int Order(ComparedPhoto a, ComparedPhoto b)
|
||||
{
|
||||
var byTime = ((a.Here ?? a.There)!.CapturedAt ?? DateTime.MaxValue).CompareTo((b.Here ?? b.There)!.CapturedAt ?? DateTime.MaxValue);
|
||||
if (byTime != 0) return byTime;
|
||||
var byKey = string.CompareOrdinal(a.Key, b.Key);
|
||||
return byKey != 0 ? byKey : a.Class.CompareTo(b.Class);
|
||||
}
|
||||
|
||||
private static PhotoClassTotal[] Totals(List<ComparedPhoto> photos) =>
|
||||
[
|
||||
.. Enum.GetValues<PhotoClass>().Select(c =>
|
||||
{
|
||||
var of = photos.Where(p => p.Class == c).ToList();
|
||||
return new PhotoClassTotal(c, of.Count, of.Sum(p => p.Here?.Size ?? 0), of.Sum(p => p.There?.Size ?? 0));
|
||||
}),
|
||||
];
|
||||
|
||||
/// <summary>10. The counts and ratios of design §3.2 (Versions counted in Shared).</summary>
|
||||
private static CopyScore Score(List<ComparedPhoto> photos, int localPhotos, int otherPhotos)
|
||||
{
|
||||
int Of(PhotoClass c) => photos.Count(p => p.Class == c);
|
||||
var versions = Of(PhotoClass.Versions);
|
||||
var shared = Of(PhotoClass.Same) + Of(PhotoClass.Converted) + versions;
|
||||
var unhashed = Of(PhotoClass.SameUnhashed);
|
||||
var (deletedHere, deletedThere) = (Of(PhotoClass.DeletedHere), Of(PhotoClass.DeletedThere));
|
||||
var removed = deletedHere + deletedThere;
|
||||
var smaller = Math.Min(localPhotos, otherPhotos);
|
||||
var union = localPhotos + otherPhotos - (shared + unhashed);
|
||||
var containment = smaller == 0 ? 0 : (int)Math.Min(1000, 1000L * (shared + unhashed + removed) / smaller);
|
||||
var overlap = union <= 0 ? 0 : (int)Math.Min(1000, 1000L * (shared + unhashed) / union);
|
||||
return new CopyScore(shared, unhashed, removed, Of(PhotoClass.OnlyHere), Of(PhotoClass.OnlyThere), Of(PhotoClass.Differs), deletedHere, deletedThere,
|
||||
versions, localPhotos, otherPhotos, containment, overlap, 0);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,18 @@ public sealed class SyncTombstones
|
||||
/// <summary>No photo removed on either side.</summary>
|
||||
public static SyncTombstones None { get; } = new([], null);
|
||||
|
||||
/// <summary>
|
||||
/// The tombstones of two copies both given as the manifest carries them (<see cref="ToDto"/>): a local pair compared
|
||||
/// with each other (owner review 6, #73), <paramref name="here"/> standing for "this PC".
|
||||
/// </summary>
|
||||
public static SyncTombstones FromDtos(IEnumerable<RemovedPhotoDto> here, IEnumerable<RemovedPhotoDto>? there)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(here);
|
||||
return new SyncTombstones(here.Where(r => r is not null).Select(r => new FrameRemoval(Guid.Empty, r.Sha256, r.Replacement,
|
||||
string.Equals(r.Reason, Wire(RemovalReason.Replaced), StringComparison.OrdinalIgnoreCase) ? RemovalReason.Replaced : RemovalReason.Deleted, r.At)),
|
||||
there?.Where(r => r is not null));
|
||||
}
|
||||
|
||||
/// <summary>Whether either side removed or replaced anything.</summary>
|
||||
public bool IsEmpty => _deletedLocally.Count == 0 && _deletedRemotely.Count == 0 && _canonical.Count == 0;
|
||||
|
||||
|
||||
Reference in new issue
Block a user