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 — Display modification times of input files in context and unified diff by TanmayPatil105 · Pull Request #33 · uutils/diffutils

Conversation

@TanmayPatil105

@TanmayPatil105 TanmayPatil105 commented Mar 27, 2024

Copy link
Copy Markdown
Contributor

Fixes #31

tanmay@tanmay-lenovo:~/Desktop/projects/uutils/diffutils$ cargo run -- -c fruits_old.txt fruits_new.txt 
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/diffutils -c fruits_old.txt fruits_new.txt`
*** fruits_old.txt	2024-03-24 23:43:05.189597645 +0530
--- fruits_new.txt	2024-03-24 23:35:08.922581904 +0530
***************
*** 1,3 ****
  Apple
! Banana
  Cherry
--- 1,3 ----
  Apple
! Fig
  Cherry
tanmay@tanmay-lenovo:~/Desktop/projects/uutils/diffutils$ diff -c fruits_old.txt fruits_new.txt 
*** fruits_old.txt	2024-03-24 23:43:05.189597645 +0530
--- fruits_new.txt	2024-03-24 23:35:08.922581904 +0530
***************
*** 1,3 ****
  Apple
! Banana
  Cherry
--- 1,3 ----
  Apple
! Fig
  Cherry

Sorry, something went wrong.

Uh oh!

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

All reactions
@TanmayPatil105
Display modification times of input files in context diff
42eb15b
Fixes uutils#31
@sylvestre

sylvestre commented Mar 27, 2024

Copy link
Copy Markdown
Collaborator

Could you please add tests

All reactions

Sorry, something went wrong.

Uh oh!

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

@sylvestre

sylvestre commented Mar 27, 2024

Copy link
Copy Markdown
Collaborator

Thanks

All reactions

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105

TanmayPatil105 commented Mar 27, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Okay! The current tests are failing.

error: test failed, to rerun pass `--lib`
---- context_diff::tests::test_permutations_missing_lines stdout ----
thread 'context_diff::tests::test_permutations_missing_lines' panicked at src/context_diff.rs:269:44:
Failed to get metadata: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- context_diff::tests::test_permutations_empty_lines stdout ----
thread 'context_diff::tests::test_permutations_empty_lines' panicked at src/context_diff.rs:269:44:
Failed to get metadata: Os { code: 2, kind: NotFound, message: "No such file or directory" }

---- context_diff::tests::test_permutations stdout ----
thread 'context_diff::tests::test_permutations' panicked at src/context_diff.rs:269:44:
Failed to get metadata: Os { code: 2, kind: NotFound, message: "No such file or directory" }

---- context_diff::tests::test_permutations_reverse stdout ----
thread 'context_diff::tests::test_permutations_reverse' panicked at src/context_diff.rs:269:44:
Failed to get metadata: Os { code: 2, kind: NotFound, message: "No such file or directory" }

---- context_diff::tests::test_stop_early stdout ----
thread 'context_diff::tests::test_stop_early' panicked at src/context_diff.rs:269:44:
Failed to get metadata: Os { code: 2, kind: NotFound, message: "No such file or directory" }

Isn't this strange? We check if file exists in main.rs : https://github.com/uutils/diffutils/blob/main/src/main.rs#L52

Edit: These are unit tests. My bad!

All reactions

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105

TanmayPatil105 commented Mar 27, 2024

Copy link
Copy Markdown
Contributor Author

Could you please add tests

Can you guide me more on these 😅?
Current tests are quite difficult to understand

All reactions

Sorry, something went wrong.

Uh oh!

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

@sylvestre

sylvestre commented Mar 27, 2024

Copy link
Copy Markdown
Collaborator

This one is pretty simple, no ? :)
https://github.com/uutils/diffutils/blob/main/tests/integration.rs#L127-L148

All reactions

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105

TanmayPatil105 commented Mar 28, 2024

Copy link
Copy Markdown
Contributor Author

@sylvestre I was looking at the unit tests and I see we are not actually creating files but only passing filename literals to context_diff::diff. The tests are failing since we are looking for metadata for files which don't exist in the diff function. We are using expected_filename/actual_filename only for printing.
Should we create those files during the tests?

All reactions

Sorry, something went wrong.

Uh oh!

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

@sylvestre

sylvestre commented Mar 28, 2024

Copy link
Copy Markdown
Collaborator

yes please :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@sylvestre
sylvestre force-pushed the context-diff-modification-time branch from 392f726 to 9d4346e Compare March 30, 2024 14:34
sylvestre
sylvestre reviewed Mar 30, 2024
View reviewed changes
Comment thread src/context_diff.rs Resolved

Uh oh!

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

@TanmayPatil105
Fix tests
9ff8f89
@TanmayPatil105
TanmayPatil105 force-pushed the context-diff-modification-time branch from 9d4346e to 9ff8f89 Compare March 31, 2024 10:45
sylvestre and others added 2 commits March 31, 2024 16:17
@sylvestre
Merge branch 'main' into context-diff-modification-time
043c5f9
@TanmayPatil105
Create foo/bar in target/context-diff
80c9944
@TanmayPatil105

TanmayPatil105 commented Mar 31, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

I'm not sure on how the tests are failing on CI, we are creating the files now. It should have worked. Strange 🤔

The tests are working fine on my machine:

test context_diff::tests::test_permutations_missing_lines ... ok
test context_diff::tests::test_permutations_empty_lines ... ok
test context_diff::tests::test_permutations_reverse ... ok
test context_diff::tests::test_permutations ... ok
test normal_diff::tests::test_stop_early ... ok
All reactions

Sorry, something went wrong.

Uh oh!

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

@sylvestre

sylvestre commented Mar 31, 2024

Copy link
Copy Markdown
Collaborator

sorry, could you please fix the conflict? Sorry :(

All reactions

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105
Merge branch 'main' into context-diff-modification-time
88a7568
@TanmayPatil105
TanmayPatil105 force-pushed the context-diff-modification-time branch from 38bd174 to 88a7568 Compare April 1, 2024 07:36
sylvestre
sylvestre reviewed Apr 1, 2024
View reviewed changes
Comment thread Cargo.toml Resolved

Uh oh!

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

@TanmayPatil105
Fix tests
5b814f8
@codecov

codecov Bot commented Apr 3, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.85%. Comparing base (be66ff3) to head (5b814f8).

❗ Current head 5b814f8 differs from pull request most recent head aedd068. Consider uploading reports for the commit aedd068 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #33      +/-   ##
==========================================
- Coverage   76.29%   75.85%   -0.45%     
==========================================
  Files           9        9              
  Lines        2582     2597      +15     
  Branches      663      662       -1     
==========================================
  Hits         1970     1970              
- Misses        459      476      +17     
+ Partials      153      151       -2     
Flag Coverage Δ
macos_latest 76.00% <100.00%> (?)
ubuntu_latest 75.81% <100.00%> (-0.49%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105

TanmayPatil105 commented Apr 3, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

I realized that the tests were passing locally because files were generated during previous test runs.
wondering if cargo should clean up the temp files generated during tests 🤔 . Is there any way to specify it? OR we should manually delete them after every unit test.

All reactions

Sorry, something went wrong.

Uh oh!

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

@sylvestre

sylvestre commented Apr 3, 2024

Copy link
Copy Markdown
Collaborator

Is there any way to specify it?

Yeah, just https://crates.io/crates/tempfile to create these files

All reactions

Sorry, something went wrong.

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 3, 2024
View reviewed changes
Comment thread src/context_diff.rs Resolved

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 3, 2024
View reviewed changes
Comment thread src/context_diff.rs Resolved

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 3, 2024
View reviewed changes
Comment thread src/context_diff.rs Resolved

Uh oh!

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

@TanmayPatil105
Display modification times of input files in unified diff
a3a372f
@TanmayPatil105
TanmayPatil105 force-pushed the context-diff-modification-time branch from a760034 to a3a372f Compare April 3, 2024 18:44
@TanmayPatil105 TanmayPatil105 changed the title Display modification times of input files in context diff Display modification times of input files in context and unified diff Apr 4, 2024
@TanmayPatil105
Merge branch 'main' into context-diff-modification-time
61fb065
TanmayPatil105 added 3 commits April 10, 2024 22:20
@TanmayPatil105
Define assert_diff_eq macro for context&unified diff comparison
00e18a6
@TanmayPatil105
Merge branch 'context-diff-modification-time' of github.com:TanmayPat…
86bd05c
…il105/diffutils into context-diff-modification-time
@TanmayPatil105
Add tests for get_modification_time function
0a77fe1
@TanmayPatil105
TanmayPatil105 force-pushed the context-diff-modification-time branch from 81c1346 to 0a77fe1 Compare April 13, 2024 16:01
@TanmayPatil105

TanmayPatil105 commented Apr 13, 2024

Copy link
Copy Markdown
Contributor Author

Hey @oSoMoN , I have made the necessary changes! Can you review the MR?
Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 13, 2024
View reviewed changes
Comment thread src/utils.rs Outdated
let target = "target/utils";
let _ = std::fs::create_dir(target);
let filename = &format!("{target}/foo");
let temp = File::create(filename).unwrap();

@oSoMoN oSoMoN Apr 13, 2024

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.

Can you use a tempfile.NamedTempFile instead?

Sorry, something went wrong.

Uh oh!

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

All reactions

@TanmayPatil105 TanmayPatil105 Apr 14, 2024

Copy link
Copy Markdown
Contributor Author

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.

I don't think there are APIs to set modification time for a NamedTempFile.

Sorry, something went wrong.

Uh oh!

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

All reactions

@oSoMoN oSoMoN Apr 15, 2024

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.

NamedTempFile::as_file() exposes a reference to the underlying file, so you could do something like this:

use tempfile::NamedTempFile;
let temp = NamedTempFile::new().unwrap();
let current = SystemTime::now();
let _ = temp.as_file().set_modified(current);
…
assert_eq!(current, get_modification_time(&temp.path().to_string_lossy()));

Sorry, something went wrong.

Uh oh!

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

All reactions
oSoMoN
oSoMoN reviewed Apr 13, 2024
View reviewed changes
Comment thread src/utils.rs Resolved

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 13, 2024
View reviewed changes
Comment thread src/macros.rs Resolved

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 13, 2024
View reviewed changes
Comment thread src/macros.rs Resolved

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 13, 2024
View reviewed changes
Comment thread src/utils.rs Resolved

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 13, 2024
View reviewed changes
Comment thread src/context_diff.rs Resolved

Uh oh!

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

oSoMoN
oSoMoN reviewed Apr 13, 2024
View reviewed changes

@oSoMoN oSoMoN left a comment

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.

Thanks Tanmay, that looks quite good!
I have left a handful of comments/suggestions, see inline.

Sorry, something went wrong.

Uh oh!

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

All reactions
TanmayPatil105 added 2 commits April 14, 2024 13:43
@TanmayPatil105
Tests: Replace modification time in diff with "TIMESTAMP" placeholder
900e1c3
@TanmayPatil105
Improve tests
33783d0
@TanmayPatil105

TanmayPatil105 commented Apr 14, 2024

Copy link
Copy Markdown
Contributor Author

Halfway through the changes. I'll complete them shortly!

All reactions

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105
TanmayPatil105 force-pushed the context-diff-modification-time branch from d9d7b56 to aab1a13 Compare April 14, 2024 13:10
@TanmayPatil105
Do not create dummy files
ba7cb0a
Since we now returning SystemTime::now() for invalid file input,
there is no need to crate dummy files
@TanmayPatil105
TanmayPatil105 force-pushed the context-diff-modification-time branch from aab1a13 to ba7cb0a Compare April 14, 2024 17:27
oSoMoN
oSoMoN reviewed Apr 15, 2024
View reviewed changes

@oSoMoN oSoMoN left a comment

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.

Thanks, that looks really good now. Almost ready to merge, see only my suggestion on the use of NamedTempFile.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread src/utils.rs Resolved

Uh oh!

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

Comment thread src/utils.rs Outdated
let target = "target/utils";
let _ = std::fs::create_dir(target);
let filename = &format!("{target}/foo");
let temp = File::create(filename).unwrap();

@oSoMoN oSoMoN Apr 15, 2024

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.

NamedTempFile::as_file() exposes a reference to the underlying file, so you could do something like this:

use tempfile::NamedTempFile;
let temp = NamedTempFile::new().unwrap();
let current = SystemTime::now();
let _ = temp.as_file().set_modified(current);
…
assert_eq!(current, get_modification_time(&temp.path().to_string_lossy()));

Sorry, something went wrong.

Uh oh!

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

All reactions
@oSoMoN

oSoMoN commented Apr 15, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Collaborator

It's worth noting that with the changes in this PR, one test from the GNU test suite which currently fails in main now passes (the timezone test). Nice improvement!

TanmayPatil105 reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105
Use NamedTempFile instead of manually creating files
54c02bd
@TanmayPatil105

TanmayPatil105 commented Apr 16, 2024

Copy link
Copy Markdown
Contributor Author

Done!

All reactions

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105
Replace only the first two occurences of timestamp regex
aedd068
@TanmayPatil105

TanmayPatil105 commented Apr 16, 2024

Copy link
Copy Markdown
Contributor Author

Sorry for the noise! I forgot to run cargo fmt.

All reactions

Sorry, something went wrong.

Uh oh!

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

@oSoMoN
oSoMoN merged commit 1b311c6 into uutils:main Apr 16, 2024
@oSoMoN

oSoMoN commented Apr 16, 2024

Copy link
Copy Markdown
Collaborator

Merged, thanks Tanmay for the contribution!

TanmayPatil105 reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

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

@TanmayPatil105
TanmayPatil105 deleted the context-diff-modification-time branch April 16, 2024 16:53
@marc-hb marc-hb mentioned this pull request May 5, 2026
tests: fix "old" names in generated patch files #224
Merged
marc-hb added a commit to marc-hb/diffutils that referenced this pull request May 5, 2026
@marc-hb
tests: fix "old" names in generated patch files
bb72d51
Fixes uutils#223. Very simple reproduction

```
cd diffutils
mkdir a
touch a/alef  a/alefn  a/alef_  a/alefx  a/alefr  a/fuzz.file
cargo test
```
 => fail

https://www.gnu.org/software/diffutils/manual/html_node/Multiple-Patches.html
states that the "old" file name has precedence over the "new" filename.

I hit this problem because some other (and unfortunately: unknown for
now) test issue left bogus `a/alef*` file(s) behind in my workspace. I
didn't bother cleaning them up because I assumed some test would keep
recreating them and that cost me a lot of time.

This issue seems to have existed since the very first commit.
Interestingly, there as a previous attempt in 2024 to fix this in commit
a3a372f ! So I was apparently not the only affected. BUT that
fix was immediately reverted by commit ba7cb0a in the same
PR. Admittedly, that fix seemed somewhat off-topic in
uutils#33. So here it is again.
sylvestre pushed a commit that referenced this pull request May 13, 2026
@marc-hb @sylvestre
tests: fix "old" names in generated patch files
d73fa83
Fixes #223. Very simple reproduction

```
cd diffutils
mkdir a
touch a/alef  a/alefn  a/alef_  a/alefx  a/alefr  a/fuzz.file
cargo test
```
 => fail

https://www.gnu.org/software/diffutils/manual/html_node/Multiple-Patches.html
states that the "old" file name has precedence over the "new" filename.

I hit this problem because some other (and unfortunately: unknown for
now) test issue left bogus `a/alef*` file(s) behind in my workspace. I
didn't bother cleaning them up because I assumed some test would keep
recreating them and that cost me a lot of time.

This issue seems to have existed since the very first commit.
Interestingly, there as a previous attempt in 2024 to fix this in commit
a3a372f ! So I was apparently not the only affected. BUT that
fix was immediately reverted by commit ba7cb0a in the same
PR. Admittedly, that fix seemed somewhat off-topic in
#33. So here it is again.
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
@oSoMoN oSoMoN oSoMoN requested changes

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.

Context diff doesn't display the last modification timestamp

Uh oh!

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

3 participants

@TanmayPatil105 @sylvestre @oSoMoN
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.