Skip to content

Allow comparing Branch objects#1234

Open
DanielEScherzer wants to merge 1 commit into
rust-lang:mainfrom
DanielEScherzer:branch-eq-ord
Open

Allow comparing Branch objects#1234
DanielEScherzer wants to merge 1 commit into
rust-lang:mainfrom
DanielEScherzer:branch-eq-ord

Conversation

@DanielEScherzer
Copy link
Copy Markdown
Contributor

Add implementations for PartialOrd, Ord, PartialEq, and Eq. The actual is delegated to the underlying Reference object.

Closes #422

Add implementations for `PartialOrd`, `Ord`, `PartialEq`, and `Eq`. The actual
is delegated to the underlying `Reference` object.

Closes rust-lang#422
@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Apr 14, 2026
Comment thread src/branch.rs
Copy link
Copy Markdown
Member

@weihanglo weihanglo Apr 16, 2026

Choose a reason for hiding this comment

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

Haven't yet checked by myself. Does libgit2 have or plan to have an compare functions for branch or references?

View changes since the review

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.

It allows comparing references with git_reference_cmp() which is what impl<'repo> Ord for Reference<'repo> uses

Comment thread src/branch.rs
let mut b1 = repo.branch("foo", &commit, false).unwrap();
assert!(!b1.is_head());
repo.branch("foo2", &commit, false).unwrap();
let b2 = repo.branch("foo2", &commit, false).unwrap();
Copy link
Copy Markdown
Member

@weihanglo weihanglo Apr 16, 2026

Choose a reason for hiding this comment

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

Have we considered the equality here be based on branch name instead of Reference equality? It is a bit weird and too implicit when two different branch names differ comparsion says there are the same.

Perhaps we should be more explicit on the comparsion, and don't implement the eq operator?

View changes since the review

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.

What if you had two different references (lowercase) to the same branch, but the underlying References are not the same - I would be surprised if those two branches are considered equal

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree with that one, too.

Semantically a reference is composed of target and name and oid. However upstream libgit2 has a bug that didn't consider them when comparing. They fixed that in libgit2/libgit2#6346 but won't release it until libgit2 v2.

I think until then we might not want to tie to one about-to-change semantic. What do you think?

(#851 has done a good research btw)

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.

No objections to waiting, but do we know when libgit2 v2 will come out?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@weihanglo
Copy link
Copy Markdown
Member

weihanglo commented May 8, 2026

@rustbot label +S-blocked +upstream

wait for upstream change in libgit2 v2 probably

@rustbot rustbot added S-blocked Status: Marked as blocked on further work upstream An upstream issue with libgit2 labels May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-blocked Status: Marked as blocked on further work S-waiting-on-review Status: Waiting on review upstream An upstream issue with libgit2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Eq and Ord for Branch?

3 participants