private void AddPayloadDeltas()

in src/managed/DiffGen/DiffGeneration/Workers/SelectItemsForDelta.cs [59:140]


    private void AddPayloadDeltas()
    {
        if (TargetTokens.Payload == null || !TargetTokens.Payload.Any() || SourceTokens.Payload == null || !SourceTokens.Payload.Any())
        {
            Logger.LogError("No payloads to process.");
            return;
        }

        List<string> newItems = new();
        List<string> identicalItems = new();
        List<string> differentItems = new();

        ulong totalNew = 0;
        ulong totalIdentical = 0;
        ulong totalDifferent = 0;

        foreach (var payloadEntry in TargetTokens.Payload)
        {
            var targetPayloadFullPath = payloadEntry.Key.Name;
            var targetPayloadItems = payloadEntry.Value;

            // This will also match exact matches
            var sourceWildcardMatches = SourceTokens.GetPayloadMatchingWildcard(targetPayloadFullPath);

            if (sourceWildcardMatches.Count() == 0)
            {
                newItems.Add($"{payloadEntry.Key.Name}, {string.Join(",", payloadEntry.Value.Select(x => x.ToString()))}");

                ulong totalItemBytes = 0;
                foreach (var item in targetPayloadItems)
                {
                    totalItemBytes += item.Length;
                }

                totalNew += totalItemBytes;

                continue;
            }

            foreach (var targetItem in targetPayloadItems)
            {
                foreach (var sourceItem in sourceWildcardMatches)
                {
                    if (targetItem.Equals(sourceItem))
                    {
                        identicalItems.Add($"{payloadEntry.Key.Name},{string.Join(",", payloadEntry.Value.Select(x => x.ToString()))}");
                        totalIdentical += targetItem.Length;
                        continue;
                    }

                    // If this item is an archive then it will be assembled from
                    // its recipes those items should be diffed, not the archive itself
                    if (TargetTokens.HasArchiveItem(targetItem))
                    {
                        break;
                    }

                    differentItems.Add($"{payloadEntry.Key.Name}, {string.Join(",", payloadEntry.Value.Select(x => x.ToString()))}");

                    totalDifferent += targetItem.Length;

                    var plan = new DeltaPlan(sourceItem, targetItem, targetPayloadFullPath, true);
                    DeltaPlans.AddDeltaPlan(targetItem, plan);
                    TargetItemsNeeded.Add(targetItem);
                    SourceItemsNeeded.Add(sourceItem);
                }
            }
        }

        var newItemsFile = Path.Combine(WorkingFolder, "NewItems.txt");
        File.WriteAllLines(newItemsFile, newItems);

        var identicalItemsFile = Path.Combine(WorkingFolder, "IdenticalItems.txt");
        File.WriteAllLines(identicalItemsFile, identicalItems);

        var differentItemsFile = Path.Combine(WorkingFolder, "DifferentItems.txt");
        File.WriteAllLines(differentItemsFile, differentItems);

        Logger.LogInformation("Total new items found with no basis: Count: {newItemsCount:N0}, Bytes: {totalNew:N0}. Details written to {newItemsFile}", newItems.Count(), totalNew, newItemsFile);
        Logger.LogInformation("Total identical items found: Count: {identicalItemsCount:N0}, Bytes: {totalIdentical:N0}. Details written to {identicalItemsFile}", identicalItems.Count(), totalIdentical, identicalItemsFile);
        Logger.LogInformation("Total different items found: Count: {differentItemsCount:N0}, Bytes: {totalDifferent:N0}. Details written to {differentItemsFile}", differentItems.Count(), totalDifferent, differentItemsFile);
    }