Skip to content

Commit 3d1963c

Browse files
committed
Ignoredファイル出力の設定追加とレポートへの記載対応
1 parent 90b1bf5 commit 3d1963c

7 files changed

Lines changed: 132 additions & 20 deletions

File tree

Models/ConfigSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public sealed class ConfigSettings
2828
/// </summary>
2929
public bool ShouldIncludeUnchangedFiles { get; set; }
3030

31+
/// <summary>
32+
/// IgnoredExtensions に該当し比較対象から除外されたファイルもレポートへ出力するか否か。
33+
/// </summary>
34+
public bool ShouldIncludeIgnoredFiles { get; set; }
35+
3136
/// <summary>
3237
/// IL全文を出力するか否か
3338
/// </summary>

Models/FileDiffResultLists.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ public enum DiffDetailResult
2222
TextMatch, // テキストベースで一致
2323
TextMismatch // テキストベースで不一致
2424
}
25+
26+
/// <summary>
27+
/// IgnoredExtensions により比較対象から除外されたファイルがどのフォルダに存在したかを示すフラグ。
28+
/// </summary>
29+
[Flags]
30+
public enum IgnoredFileLocation
31+
{
32+
None = 0,
33+
Old = 1,
34+
New = 2
35+
}
2536
#region public properties
2637
/// <summary>
2738
/// 旧バージョン側(比較元)ファイルの絶対パスのリスト
@@ -62,6 +73,11 @@ public enum DiffDetailResult
6273
/// 1 件以上のファイルが <see cref="DiffDetailResult.MD5Mismatch"/> と判定されているかどうか。
6374
/// </summary>
6475
public static bool HasAnyMd5Mismatch => FileRelativePathToDiffDetailDictionary.Values.Any(result => result == DiffDetailResult.MD5Mismatch);
76+
77+
/// <summary>
78+
/// IgnoredExtensions 対象ファイルの相対パスと所在(旧/新フォルダ)情報。
79+
/// </summary>
80+
public static ConcurrentDictionary<string, IgnoredFileLocation> IgnoredFilesRelativePathToLocation { get; } = new ConcurrentDictionary<string, IgnoredFileLocation>(StringComparer.OrdinalIgnoreCase);
6581
#endregion
6682

6783
/// <summary>
@@ -76,5 +92,20 @@ public static void RecordDiffDetail(string fileRelativePath, DiffDetailResult di
7692
// 既に存在する場合は上書き、存在しなければ追加 (スレッドセーフ)
7793
FileRelativePathToDiffDetailDictionary[fileRelativePath] = diffDetailResult;
7894
}
95+
96+
/// <summary>
97+
/// IgnoredExtensions に該当したファイルの所在情報を記録します。
98+
/// </summary>
99+
/// <param name="fileRelativePath">フォルダ基準の相対パス。</param>
100+
/// <param name="location">旧/新のどちらに存在したかを示すフラグ。</param>
101+
/// <exception cref="ArgumentException">fileRelativePath が null または空白の場合。</exception>
102+
public static void RecordIgnoredFile(string fileRelativePath, IgnoredFileLocation location)
103+
{
104+
if (string.IsNullOrWhiteSpace(fileRelativePath))
105+
{
106+
throw new ArgumentException("fileRelativePath cannot be null or whitespace.", nameof(fileRelativePath));
107+
}
108+
IgnoredFilesRelativePathToLocation.AddOrUpdate(fileRelativePath, location, (_, existing) => existing | location);
109+
}
79110
}
80111
}

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ dotnet tool install -g ilspycmd
3434
- ILMismatch: IL(中間言語)ベースで不一致(ビルド固有情報の差異は無視)
3535
- TextMatch: テキストベースで一致
3636
- TextMismatch: テキストベースで不一致
37-
- 比較結果区分ごと(Unchanged/Added/Removed/Modified)にファイルを分類
38-
- 比較結果区分ごとのファイル一覧を`Reports/<コマンドライン第3引数に指定したレポートのラベル>/diff_report.md`に出力(ファイルのパス、最終更新日時[`config.json`のShouldOutputFileTimestampsがtrueの場合]、判定根拠)
39-
- Unchanged/Modified は相対パスで記載されます。
40-
- Added/Removed は絶対パスで記載されます。
41-
- 比較結果区分ごとのファイル数を集計し`Reports/<コマンドライン第3引数に指定したレポートのラベル>/diff_report.md`に出力
42-
- 比較結果区分Unchangedのファイル一覧は、`config.json`のShouldIncludeUnchangedFilesがtrueの場合のみ出力されます。
43-
- `MD5Mismatch` が 1 件以上存在する場合は、標準出力と `diff_report.md` の Summary 直下に警告を表示し、MD5 ハッシュ比較しか行えず、かつ不一致と判定されたファイルがある旨を明確に示します。
37+
- 比較結果区分ごと(Unchanged/Added/Removed/Modified)にファイルを分類
38+
- 比較結果区分ごとのファイル一覧を`Reports/<コマンドライン第3引数に指定したレポートのラベル>/diff_report.md`に出力(ファイルのパス、最終更新日時[`config.json`のShouldOutputFileTimestampsがtrueの場合]、判定根拠)
39+
- Unchanged/Modified は相対パスで記載されます。
40+
- Added/Removed は絶対パスで記載されます。
41+
- 比較結果区分ごとのファイル数を集計し`Reports/<コマンドライン第3引数に指定したレポートのラベル>/diff_report.md`に出力
42+
- 比較結果区分Unchangedのファイル一覧は、`config.json`のShouldIncludeUnchangedFilesがtrueの場合のみ出力されます。
43+
- IgnoredExtensions対象のファイル一覧は、`config.json`のShouldIncludeIgnoredFilesがtrueの場合に `## [ x ] Ignored Files` として Unchanged の直前に出力されます。
44+
- `MD5Mismatch` が 1 件以上存在する場合は、標準出力と `diff_report.md` の Summary 直下に警告を表示し、MD5 ハッシュ比較しか行えず、かつ不一致と判定されたファイルがある旨を明確に示します。
4445

4546
## ファイル比較フロー
4647

@@ -139,10 +140,11 @@ dotnet tool install -g ilspycmd
139140
".xml",
140141
".yaml",
141142
".yml"
142-
],
143-
"MaxLogGenerations": 5,
144-
"ShouldIncludeUnchangedFiles": true,
145-
"ShouldOutputILText": true,
143+
],
144+
"MaxLogGenerations": 5,
145+
"ShouldIncludeUnchangedFiles": true,
146+
"ShouldIncludeIgnoredFiles": true,
147+
"ShouldOutputILText": true,
146148
"ShouldOutputFileTimestamps": true,
147149
"MaxParallelism": 0,
148150
"EnableILCache": true,
@@ -162,9 +164,11 @@ dotnet tool install -g ilspycmd
162164
- ピリオド(`.`)付きの拡張子で指定してください(例: `.cs`, `.json`, `.xml`)。
163165
- MaxLogGenerations
164166
- アプリケーションログのローテーション世代数
165-
- ShouldIncludeUnchangedFiles
166-
- `Reports/<コマンドライン第3引数に指定したレポートのラベル>/diff_report.md`にUnchangedのファイル一覧を含めるか否か
167-
- ShouldOutputILText
167+
- ShouldIncludeUnchangedFiles
168+
- `Reports/<コマンドライン第3引数に指定したレポートのラベル>/diff_report.md`にUnchangedのファイル一覧を含めるか否か
169+
- ShouldIncludeIgnoredFiles
170+
- IgnoredExtensions に該当して比較対象から除外されたファイルを `diff_report.md` の `## [ x ] Ignored Files` セクション(Unchanged の直前)に出力するか否か
171+
- ShouldOutputILText
168172
- `Reports/<コマンドライン第3引数に指定したレポートのラベル>/IL/old, new`にIL全文を出力するか否か
169173
- ShouldOutputFileTimestamps
170174
- `diff_report.md` の各ファイル行に最終更新日時を併記するか否か(true で併記)。

Services/FolderDiffService.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public async Task ExecuteFolderDiffAsync()
151151
var reason = $"manual={_config.OptimizeForNetworkShares}, auto={_config.AutoDetectNetworkShares}, oldIsNetwork={_detectedNetworkOld}, newIsNetwork={_detectedNetworkNew}";
152152
LoggerService.LogMessage($"[INFO] Execution mode: {mode} ({reason})", shouldOutputMessageToConsole: true);
153153

154+
FileDiffResultLists.IgnoredFilesRelativePathToLocation.Clear();
154155
FileDiffResultLists.UnchangedFilesRelativePath.Clear();
155156
FileDiffResultLists.AddedFilesAbsolutePath.Clear();
156157
FileDiffResultLists.RemovedFilesAbsolutePath.Clear();
@@ -164,12 +165,10 @@ public async Task ExecuteFolderDiffAsync()
164165
// IgnoredExtensions を大文字小文字を無視して評価するために HashSet を用意
165166
var ignoredExtensions = new HashSet<string>(_config.IgnoredExtensions ?? Enumerable.Empty<string>(), StringComparer.OrdinalIgnoreCase);
166167

167-
FileDiffResultLists.OldFilesAbsolutePath = Directory.GetFiles(_oldFolderAbsolutePath, "*", SearchOption.AllDirectories)
168-
.Where(f => !ignoredExtensions.Contains(Path.GetExtension(f))).ToList();
168+
FileDiffResultLists.OldFilesAbsolutePath = EnumerateIncludedFiles(_oldFolderAbsolutePath, ignoredExtensions, FileDiffResultLists.IgnoredFileLocation.Old);
169169
_progressReporter.ReportProgress(0.0);
170170

171-
FileDiffResultLists.NewFilesAbsolutePath = Directory.GetFiles(_newFolderAbsolutePath, "*", SearchOption.AllDirectories)
172-
.Where(f => !ignoredExtensions.Contains(Path.GetExtension(f))).ToList();
171+
FileDiffResultLists.NewFilesAbsolutePath = EnumerateIncludedFiles(_newFolderAbsolutePath, ignoredExtensions, FileDiffResultLists.IgnoredFileLocation.New);
173172
_progressReporter.ReportProgress(0.0);
174173

175174
// OldFilesの相対パス群とNewFilesの相対パス群の和(重複除外)を取得し、個数0なら処理を終了。
@@ -252,7 +251,6 @@ public async Task ExecuteFolderDiffAsync()
252251
Directory.CreateDirectory(_ilNewFolderAbsolutePath);
253252
LoggerService.LogMessage($"[INFO] Prepared IL output directories: old='{_ilOldFolderAbsolutePath}', new='{_ilNewFolderAbsolutePath}'", shouldOutputMessageToConsole: true);
254253
}
255-
256254
int processedFileCount = 0;
257255
// new 側の全ファイル絶対パスを入れた集合(大文字小文字無視)。
258256
// old 側を走査しながら一致したパスを削除していき、最後に残ったものを Added 判定に利用する。
@@ -459,5 +457,27 @@ private async Task<int> DetermineDiffsInParallelAsync(HashSet<string> remainingN
459457

460458
return processedFileCount;
461459
}
460+
461+
/// <summary>
462+
/// IgnoredExtensions を適用して比較対象へ含めるファイル一覧を取得します。必要に応じて無視対象のレポート用情報も記録します。
463+
/// </summary>
464+
private List<string> EnumerateIncludedFiles(string rootFolderAbsolutePath, HashSet<string> ignoredExtensions, FileDiffResultLists.IgnoredFileLocation locationFlag)
465+
{
466+
var includedFiles = new List<string>();
467+
foreach (var fileAbsolutePath in Directory.GetFiles(rootFolderAbsolutePath, "*", SearchOption.AllDirectories))
468+
{
469+
if (ignoredExtensions.Contains(Path.GetExtension(fileAbsolutePath)))
470+
{
471+
if (_config.ShouldIncludeIgnoredFiles)
472+
{
473+
var relativePath = Path.GetRelativePath(rootFolderAbsolutePath, fileAbsolutePath);
474+
FileDiffResultLists.RecordIgnoredFile(relativePath, locationFlag);
475+
}
476+
continue;
477+
}
478+
includedFiles.Add(fileAbsolutePath);
479+
}
480+
return includedFiles;
481+
}
462482
}
463483
}

Services/ReportGenerateService.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
4+
using System.Linq;
35
using FolderDiffIL4DotNet.Common;
46
using FolderDiffIL4DotNet.Models;
57
using FolderDiffIL4DotNet.Utils;
@@ -63,6 +65,51 @@ public void GenerateDiffReport(
6365
streamWriter.WriteLine($" - `{FileDiffResultLists.DiffDetailResult.ILMatch}` / `{FileDiffResultLists.DiffDetailResult.ILMismatch}`: IL(Intermediate Language) match / mismatch");
6466
streamWriter.WriteLine($" - `{FileDiffResultLists.DiffDetailResult.TextMatch}` / `{FileDiffResultLists.DiffDetailResult.TextMismatch}`: Text match / mismatch");
6567

68+
// ボディ - Ignored Files -
69+
// Ignored Files はアプリ設定(ShouldIncludeIgnoredFiles)が true の場合のみ出力。
70+
// ShouldOutputFileTimestamps が true なら旧/新それぞれの存在箇所に応じた最終更新日時を併記し、
71+
// 旧/新のどちらに存在したかもラベル((old)/(new)/(old/new))で明示します。
72+
if (config.ShouldIncludeIgnoredFiles && FileDiffResultLists.IgnoredFilesRelativePathToLocation.Count > 0)
73+
{
74+
streamWriter.WriteLine("\n## [ x ] Ignored Files");
75+
foreach (var entry in FileDiffResultLists.IgnoredFilesRelativePathToLocation.OrderBy(kvp => kvp.Key, StringComparer.OrdinalIgnoreCase))
76+
{
77+
var locationLabel = entry.Value switch
78+
{
79+
FileDiffResultLists.IgnoredFileLocation.Old => "(old)",
80+
FileDiffResultLists.IgnoredFileLocation.New => "(new)",
81+
FileDiffResultLists.IgnoredFileLocation.Old | FileDiffResultLists.IgnoredFileLocation.New => "(old/new)",
82+
_ => string.Empty
83+
};
84+
85+
string timestampInfo = null;
86+
if (config.ShouldOutputFileTimestamps)
87+
{
88+
var timestampParts = new List<string>();
89+
if ((entry.Value & FileDiffResultLists.IgnoredFileLocation.Old) != 0)
90+
{
91+
timestampParts.Add($"updated_old: {Caching.TimestampCache.GetOrAdd(Path.Combine(oldFolderAbsolutePath, entry.Key))}");
92+
}
93+
if ((entry.Value & FileDiffResultLists.IgnoredFileLocation.New) != 0)
94+
{
95+
timestampParts.Add($"updated_new: {Caching.TimestampCache.GetOrAdd(Path.Combine(newFolderAbsolutePath, entry.Key))}");
96+
}
97+
timestampInfo = timestampParts.Count > 0 ? string.Join(", ", timestampParts) : null;
98+
}
99+
100+
var line = $"- [ x ] {entry.Key}";
101+
if (!string.IsNullOrEmpty(locationLabel))
102+
{
103+
line += $" {locationLabel}";
104+
}
105+
if (config.ShouldOutputFileTimestamps && !string.IsNullOrEmpty(timestampInfo))
106+
{
107+
line += $" <u>({timestampInfo})</u>";
108+
}
109+
streamWriter.WriteLine(line);
110+
}
111+
}
112+
66113
// ボディ - Unchanged Files -
67114
// Unchanged Files はアプリ設定で出力可否を制御。
68115
// ShouldOutputFileTimestamps が true の場合のみ、
@@ -135,6 +182,10 @@ public void GenerateDiffReport(
135182

136183
// フッタ
137184
streamWriter.WriteLine("\n## Summary");
185+
if (config.ShouldIncludeIgnoredFiles)
186+
{
187+
streamWriter.WriteLine($"- Ignored : {FileDiffResultLists.IgnoredFilesRelativePathToLocation.Count}");
188+
}
138189
streamWriter.WriteLine($"- Unchanged : {FileDiffResultLists.UnchangedFilesRelativePath.Count}");
139190
streamWriter.WriteLine($"- Added : {FileDiffResultLists.AddedFilesAbsolutePath.Count}");
140191
streamWriter.WriteLine($"- Removed : {FileDiffResultLists.RemovedFilesAbsolutePath.Count}");

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
],
7777
"MaxLogGenerations": 5,
7878
"ShouldIncludeUnchangedFiles": true,
79+
"ShouldIncludeIgnoredFiles": true,
7980
"ShouldOutputILText": true,
8081
"ShouldOutputFileTimestamps": true,
8182
"MaxParallelism": 0,

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"publicReleaseRefSpec": [
55
"^refs/heads/main$",
66
"^refs/tags/v\\d+\\.\\d+(?:\\.\\d+)?$"

0 commit comments

Comments
 (0)