Skip to content

diff: only report a recursive directory loop when both sides loop - #379

Merged
sylvestre merged 2 commits into
uutils:mainfrom
binhvq:recursive-loop-one-side
Nov 11, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
binhvq:recursive-loop-one-side

Conversation

@binhvq

@binhvq binhvq commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #363.

diff -r kept one list of ancestors for both sides and gave up as soon as either directory was in it. GNU checks each side against its own ancestors and only reports a loop when both sides loop, or one loops and the other is missing (-N). If the other side is a real directory, its finite tree ends the recursion.

The ancestors are now stored per pair. I compared a few layouts with GNU diff 3.12 (one side looping, both, -N with a missing side, links to the other side's top, loops of different depth); output and exit status match.

One list of ancestors was shared by both sides, so -r stopped with 'recursive directory loop' as soon as either directory was a link back to a parent. Check each side against its own ancestors, and give up only when both loop or the other side is missing: a real directory on the other side ends the recursion.
Comment thread src/dir_diff.rs Outdated
})
};
if let (true, true, Some(side)) = (
loops(0),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

matching on a tuple of bools is a bit clever
could be if loops(0) && loops(1) and then find the side inside, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, changed in f4fc09f: if loops(0) && loops(1), then the side to name is looked up inside. The GNU testsuite gives the same 19 pass / 10 fail / 4 skip as on the base commit.

@sylvestre
sylvestre merged commit f8b22b9 into uutils:main Nov 11, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

diff - -r reports a "recursive directory loop" when only one side loops

2 participants