Skip to content

Change connected() to take &self instead of &mut self - #1257

Open
cuishuang wants to merge 2 commits into
rust-lang:mainfrom
cuishuang:main
Open

cuishuang wants to merge 2 commits into
rust-lang:mainfrom
cuishuang:main

Conversation

@cuishuang

Copy link
Copy Markdown

The connected method only reads the connection status without mutating state, so &self is sufficient and avoids unnecessary mutable borrow.

Signed-off-by: cuishuang <imcusg@gmail.com>
@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label May 17, 2026

@DanielEScherzer DanielEScherzer left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking at the various git_remote_connected callbacks in libgit2 there are none that mutate the remote, so looks good to me (once CI passes)

View changes since this review

Signed-off-by: cuishuang <imcusg@gmail.com>
@cuishuang

Copy link
Copy Markdown
Author

Looking at the various git_remote_connected callbacks in libgit2 there are none that mutate the remote, so looks good to me (once CI passes)

View changes since this review

Thanks.

I resubmitted the changes and modified the test cases to pass the CI

@ehuss

ehuss commented May 18, 2026

Copy link
Copy Markdown
Contributor

Is this safe even with a custom transport? The transport vtable does not seem to enforce this as const or have any comments or contracts around that.

@ehuss ehuss added S-waiting-on-author Status: Waiting on PR author and removed S-waiting-on-review Status: Waiting on review labels May 29, 2026
@cuishuang

Copy link
Copy Markdown
Author

Is this safe even with a custom transport? The transport vtable does not seem to enforce this as const or have any comments or contracts around that.

Oh, I missed the custom transport case. Even though git_remote_connected takes a const git_remote *, the transport vtable's is_connected callback takes a mutable git_transport *, and there does not seem to be a contract requiring it to be logically const.

This branch has not been deployed

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

Labels

S-waiting-on-author Status: Waiting on PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants