Repository navigation
fix(diff): GNU per-pair header for directory comparison, no raw argv echo (#1861) - #1864
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1861
UNVERIFIED-BY-CAPTAIN
问题
目录比较时,每个文件对前无条件多印一行原始 argv 复读头,全同文件也印:
退出码全对,纯输出污染。根因在
compare_directory_pair:比较之前无条件dput("diff " + command_tail + ...),而command_tail是由command_tail_from_raw_args拼出的完整原始参数串(程序名与目录操作数都在内),且 -N(treat-as-empty)路径有第二处同样的无条件印头。
修复(单一机制)
CaptureScope):目录比较先把文件对的输出捕获成body,确认 body 合格后才在 body 前印头。合格判据与 GNU 一致:
Files ... differ由比较自身发出);-s的 identical 通知(Files ... are identical)不算 body → 不印头;-r -y同)。diff+ 命令行上实际给出的选项 token(程序名与两个操作数除外;操作数从 raw_args 末尾匹配,避免与选项值同名时误删)
token/路径的引用规则照 GNU 实测:含 shell 不安全字符的选项 token 单引号
(
'--unified=2'),含空格的路径双引号("E E/f f")。-r的目录对:GNU 对diff dA dB同样印diff dA/f dB/f头,此前实现只在 recursive 时印(且印错),现一并对齐。--diff-program对不印头:外部程序直接继承 stdout 无法捕获,其输出自成body;GNU diffutils 无此选项,无 oracle 可对。
本 PR 删除了什么
compare_directory_pair的command_tail参数管线(改为header_prefix)。头的唯一生成点收敛到
compare_pair_with_header一处,无第二走法残留。command_tail本身保留:它仍是-l/--paginate的 pr 式页眉标题来源(GNU -l 的标题即完整调用行),与文件对头无关。
净行账
src/commands/diff.cpp:+134 / −19(净 +115)tests/unit/diff/diff_unit_test.cpp:+83 / −0(净 +83)回归钉(tests/unit/diff,issue1861 五条)
-rq全同:rc 0、stdout 全空-rq不同:stdout 恰Files A/f.txt and B/f.txt differ-r全同:rc 0、stdout 全空-r混合树:stdout 恰diff -r A/f.txt B/f.txt+ 正文,全同对无头验证
红的恰是四条新钉,失败输出原样呈现本单签名
diff diff -rq A B A/f.txt B/f.txt;修复后 47/47 全过。(-rq 全同零输出 rc0;-rq 混合仅
Files ... differrc1;-r 混合头为diff -r dA/g.txt dB/g.txt;单文件全同 rc0 零输出;-r 全同零输出)。hunk 时无头)、选项 token 原样回显(
-ri、--recursive、-U 2、'--unified=2'等)、--亦回显、无 -r 目录对亦印头、-N 头用操作数序。本地验证构建以
-DWINUXCMD_ENABLE_PCRE2=OFF配置(diff 不依赖 PCRE2);默认口径以本 PR 的 CI 为准。
scripts/format.py未能执行——本机无 clang-format,X299 的VS2022 clang-format 不识仓内
.clang-format的AlignFunctionDeclarations键(需更新版本);改动代码按文件既有风格书写。
明列「保持不变」类),未新增或改动任何自然语言消息,无目录同步需求。
范围外(如实登记)
--label:GNU 会把 label 代入头与 unified 头,winuxcmd目录路径此前即不处理 label(正文亦然),属既存面,不在本单范围。
-y -s全同对的 identical 通知在 winuxcmd 中位于正文之前、GNU 在正文之后,属既存序差,不在本单范围。