GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — diff: date a missing -N operand at the Epoch in headers by sarankumar1325 · Pull Request #367 · uutils/diffutils

Conversation

@sarankumar1325

@sarankumar1325 sarankumar1325 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #361

With -N / --new-file, a missing operand is treated as empty. GNU dates it at the Unix Epoch (1970-01-01 00:00:00) in the unified and context headers. That is the convention patch uses to tell that a file must be created or removed. get_modification_time fell back to the current time for any metadata error, so the missing side got today's date and patch left an empty file behind instead of deleting it:

$ TZ=UTC0 diff -N -u A/only B/only
--- A/only	2026-11-09 15:18:23.146917271 +0000
+++ B/only	2026-11-09 15:18:23.167832210 +0000   # GNU: 1970-01-01 00:00:00.000000000 +0000

get_modification_time now returns the Epoch when the file does not exist (ErrorKind::NotFound). Standard input (-) and other errors keep the current time as before. This covers -u, -c (both timestamp styles) and -r -N directory comparisons, since they all go through this function. Output now matches GNU diff 3.x on the box for all three.

Tests:

  • tests/by-util/test_diff.rs: new_file_missing_side_dated_at_epoch (unix only, since it sets TZ like context_timestamp_follows_time_locale) checks -u, -c with an ISO locale and -c with LC_ALL=C, with the missing file on either side, plus -r -N -u over two directories. It fails on main and passes with this change.
  • src/utils.rs: the invalid_file unit test asserted the old "now" fallback for a missing file. It is replaced by missing_file (expects the Epoch) and stdin (expects the current time for -).

cargo test --test tests (43 passed), cargo test --lib modification_time, cargo fmt --check and cargo clippy -- -D warnings are clean.

I used an AI assistant to write this change. I reviewed and tested it myself.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sarankumar1325
diff: date a missing -N operand at the Epoch in headers
a0758ba
With -N, a missing operand is treated as empty. GNU dates it at
1970-01-01 00:00:00 in the -u/-c headers, which is how patch knows to
create or remove the file. We used the current time for any stat
error, so patch left an empty file behind. Use the Epoch when the file
does not exist; stdin and other errors keep the current time.

Fixes uutils#361
Copilot AI balanced review requested due to automatic review settings November 9, 2026 15:19
Copilot AI reviewed Nov 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sylvestre
sylvestre reviewed Nov 9, 2026
View reviewed changes
Comment thread src/utils.rs Outdated
/// Retrieves the modification time of the input file specified by file path.
/// A file that does not exist (treated as empty with `-N`) is dated at the
/// Unix Epoch, as GNU diff does, so that `patch` knows to create or delete
/// it. If any other error occurs, it returns the current system time.

@sylvestre sylvestre Nov 9, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be shorter, no? something like "A missing file (-N) is dated at the Epoch, other errors at now."

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/by-util/test_diff.rs
missing.display()
)));
}
}

@sylvestre sylvestre Nov 9, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you run the upstream testsuite on this?
TESTS=new-file ./tests/run-upstream-testsuite.sh

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sarankumar1325 added 2 commits November 10, 2026 01:21
@sarankumar1325
Merge remote-tracking branch 'up/main' into fix/new-file-epoch-date
9b2df4f
@sarankumar1325
diff: shorten the get_modification_time doc comment
67102b0
Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:55
Copilot AI reviewed Nov 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sylvestre

sylvestre commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

sorry but it needs to be rebased

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sylvestre sylvestre sylvestre left review comments
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

diff - -N: a missing file is dated "now" instead of the Epoch in -u/-c headers

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@sarankumar1325 @sylvestre
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.