Repository navigation
diff: date a missing file at the Unix Epoch with -N - #369
Conversation
With -N/--new-file the header of a missing file now shows 1970-01-01 instead of the current time, which is what patch relies on to detect creation and deletion. Covers -u, -c and -r. Fixes uutils#361. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| .and_then(|m| m.modified()) | ||
| .unwrap_or(SystemTime::now()); | ||
| .unwrap_or_else(|error| { | ||
| if missing_as_empty && error.kind() == std::io::ErrorKind::NotFound { |
There was a problem hiding this comment.
with -N, diff -N -u - file now dates stdin at 1970 too: fs::metadata("-") is NotFound.
could you please only use the epoch when the file really was missing, and add a test with stdin?
There was a problem hiding this comment.
Good catch, fixed in e57e23f: the epoch is now used only when the file really was missing, so stdin keeps its current time with -N. Added missing_file_as_empty_keeps_stdin_timestamp, which runs -u and -c with stdin on either side.
| let from_modified_time = get_modification_time( | ||
| ¶ms.from.to_string_lossy(), | ||
| TimestampStyle::Iso, | ||
| params.missing_file != MissingFile::Error, |
There was a problem hiding this comment.
same check as in diff.rs and context_diff.rs, could be dedup, no?
diff.rs already knows if the file was missing, it could pass that down
There was a problem hiding this comment.
Done: the check now lives only in diff.rs, which sets from_missing/to_missing on the params. The formatters just read them.
Record in compare_files whether an operand was absent instead of inferring it from fs::metadata in each formatter, so stdin keeps its current time with -N. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for your PR |
Fixes #361.
With
-N/--new-file, a missing operand is now dated1970-01-01 00:00:00in unified and context headers (including-r) instead of the current time, which is whatpatchuses to detect file creation and deletion. Added a regression test for-u,-c, both locales, and recursive mode.This change was written with AI assistance (Codex/Cursor) and I reviewed the diff and ran the checks myself; the implementation is written from the issue description, not derived from GNU source.
🤖 Generated with Claude Code