Skip to content

Allow comparing Branch objects - #1234

Merged
weihanglo merged 1 commit into
rust-lang:mainfrom
DanielEScherzer:branch-eq-ord
Oct 20, 2026
Merged

weihanglo merged 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

@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Apr 14, 2026
Comment thread src/branch.rs

@weihanglo weihanglo Apr 16, 2026 •

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.

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();

@weihanglo weihanglo Apr 16, 2026 •

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.

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

weihanglo commented May 8, 2026 •

Copy link
Copy Markdown
Member

@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
@rustbot

This comment has been minimized.

@weihanglo weihanglo removed the S-blocked Status: Marked as blocked on further work label Oct 15, 2026
@weihanglo

Copy link
Copy Markdown
Member

Could you rebase it? I am tempted to merge it and test rc1

@weihanglo

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting on PR author and removed S-waiting-on-review Status: Waiting on review labels Oct 15, 2026
@rustbot

rustbot commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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

Closes rust-lang#422
@rustbot

rustbot commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@DanielEScherzer

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting on review and removed S-waiting-on-author Status: Waiting on PR author labels Oct 19, 2026

@weihanglo weihanglo left a comment •

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
weihanglo added this pull request to the merge queue Oct 20, 2026
Merged via the queue into rust-lang:main with commit b108314 Oct 20, 2026
12 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label Oct 20, 2026
@DanielEScherzer
DanielEScherzer deleted the branch-eq-ord branch October 20, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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