基线:全量源码首提(D1 版本控制落地,含第一轮优化 B1-B4/A1/A4/缩放修复)
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
# ============================================================
|
||||
# 扒图同步检查.ps1 —— Cad/Pdf 扒图窗口 Form3.cs 漂移护栏
|
||||
# ============================================================
|
||||
# 背景: 扒图\Cad\Form3.cs 与 扒图\Pdf\Form3.cs 是约 98% 重复的双胞胎文件
|
||||
# (物理合并被 SD 设计器"项目内自定义类型"死结阻挡,2026-10-01 决策维持双文件)。
|
||||
# 历史上 Pdf 侧修复漏同步回 Cad(AdgvMsgHook 右键多选保持 / F1 合并防抖),
|
||||
# 本脚本防止再次漂移。
|
||||
# 原理: 两文件做字面映射归一化(CadBridge→PdfBridge / cadbt→pdfbt / CAD→PDF /
|
||||
# namespace MyApp→MyAppPdf)后 git diff,差异行数不超过基线即 PASS。
|
||||
# 用法: powershell -ExecutionPolicy Bypass -File tools\扒图同步检查.ps1
|
||||
# 加 -UpdateBaseline 把当前差异量定为新基线(确认属合法演进后使用)。
|
||||
# ============================================================
|
||||
param([switch]$UpdateBaseline)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$cadPath = Join-Path $root '成套报价软件\扒图\Cad\Form3.cs'
|
||||
$pdfPath = Join-Path $root '成套报价软件\扒图\Pdf\Form3.cs'
|
||||
$baseline = Join-Path $PSScriptRoot '扒图同步基线.txt'
|
||||
|
||||
foreach ($f in @($cadPath, $pdfPath)) {
|
||||
if (-not (Test-Path $f)) { Write-Host "[FAIL] 缺少文件: $f" -ForegroundColor Red; exit 2 }
|
||||
}
|
||||
|
||||
function Normalize([string]$path) {
|
||||
(Get-Content $path -Encoding UTF8) | ForEach-Object {
|
||||
$_ = $_ -creplace '^namespace MyApp\s*$', 'namespace MyAppPdf'
|
||||
$_ = $_ -creplace 'CadBridge', 'PdfBridge'
|
||||
$_ = $_ -creplace 'cadbt', 'pdfbt'
|
||||
$_ = $_ -creplace 'CAD', 'PDF'
|
||||
$_
|
||||
}
|
||||
}
|
||||
|
||||
$tmpCad = Join-Path $env:TEMP 'baotu_cad_norm.cs'
|
||||
$tmpPdf = Join-Path $env:TEMP 'baotu_pdf_norm.cs'
|
||||
Normalize $cadPath | Set-Content $tmpCad -Encoding UTF8
|
||||
Normalize $pdfPath | Set-Content $tmpPdf -Encoding UTF8
|
||||
|
||||
$diffFile = Join-Path $env:TEMP 'baotu_drift.diff'
|
||||
$null = git diff --no-index --unified=1 $tmpCad $tmpPdf 2>$null | Out-File $diffFile -Encoding UTF8
|
||||
|
||||
$numstat = git diff --no-index --numstat $tmpCad $tmpPdf 2>$null
|
||||
$added = 0; $deleted = 0
|
||||
if ($numstat) {
|
||||
$parts = (@($numstat)[0]) -split "`t"
|
||||
if ($parts.Count -ge 2) { $added = [int]$parts[0]; $deleted = [int]$parts[1] }
|
||||
}
|
||||
$drift = $added + $deleted
|
||||
|
||||
if ($UpdateBaseline) {
|
||||
Set-Content $baseline -Value $drift -Encoding ASCII
|
||||
Write-Host "[OK] 基线已更新为 $drift 行差异 (完整差异: $diffFile)"
|
||||
exit 0
|
||||
}
|
||||
|
||||
if (-not (Test-Path $baseline)) {
|
||||
Write-Host "[FAIL] 缺少基线文件 $baseline ,请先跑一次 -UpdateBaseline 生成" -ForegroundColor Red
|
||||
exit 2
|
||||
}
|
||||
$limit = [int](Get-Content $baseline -TotalCount 1)
|
||||
|
||||
Write-Host ("扒图 Cad/Pdf 归一化差异: {0} 行 (基线上限 {1} 行)" -f $drift, $limit)
|
||||
if ($drift -gt $limit) {
|
||||
Write-Host "[FAIL] 差异超过基线 —— 两文件已漂移!请排查:" -ForegroundColor Red
|
||||
Write-Host " ① 是否一侧修了 bug 忘了同步另一侧?(最常见原因)"
|
||||
Write-Host " ② 完整差异见: $diffFile"
|
||||
Write-Host " ③ 确属合法演进后,用 -UpdateBaseline 刷新基线"
|
||||
exit 1
|
||||
}
|
||||
Write-Host "[PASS] 同步状态正常"
|
||||
Reference in New Issue
Block a user