Skip to content

Remove seemingly illogical code in rootcp #19214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025

Conversation

guitargeek
Copy link
Contributor

There is this weird check in rootcp --replace where a possibly existing object in the destination file is only deleted if it is not equal (==) to the object in the source file.

The default equality check for TObjects is to compare by pointer, so this condition can never be false and the existing is always deleted, as one would expect from the --replace option.

The object would only not be replaced if the class overrides operator== and both otherObj and obj are the same. But why not deleting the existing object if it's the same anyway?

To me, this check doesn't make sense and this commit suggests to always delete the existing object, as the user would expect when passing the --replace option to rootcp.

Closes #19035.

There is this weird check in `rootcp --replace` where a possibly
existing object in the destination file is only deleted if it is not
equal (`==`) to the object in the source file.

The default equality check for TObjects is to compare by pointer, so
this condition can never be false and the existing is always deleted, as
one would expect from the `--replace` option.

The object would only *not* be replaced if the class overrides
`operator==` and both `otherObj` and `obj` are the same. But why not
deleting the existing object if it's the same anyway?

To me, this check doesn't make sense and this commit suggests to always
delete the existing object, as the user would expect when passing the
`--replace` option to `rootcp`.

Closes root-project#19035.
@guitargeek guitargeek requested a review from dpiparo June 27, 2025 11:05
@guitargeek guitargeek self-assigned this Jun 27, 2025
@guitargeek guitargeek requested a review from pcanal as a code owner June 27, 2025 11:05
Copy link
Member

@dpiparo dpiparo left a comment

Choose a reason for hiding this comment

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

Thanks!

@guitargeek guitargeek merged commit 91af2f4 into root-project:master Jun 27, 2025
23 of 24 checks passed
@guitargeek guitargeek deleted the issue-19035 branch June 27, 2025 13:35
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.

The rootcp --replace logic behaves counterintuitively
3 participants