Skip to content

feat: add commit name-rev support#2662

Draft
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
name-rev
Draft

feat: add commit name-rev support#2662
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
name-rev

Conversation

@Byron

@Byron Sebastian Thiel (Byron) commented Jun 21, 2026

Copy link
Copy Markdown
Member

Tasks

This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.

  • refackiew

Everything below this line was generated by Codex GPT-5.

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

Summary

Implements Git-style commit name lookup for issue #1268.

  • Added gix_revision::name_rev() over caller-provided ref tips, so low-level revision logic only knows the prepared names it is allowed to use.
  • Added gix::Commit::name_rev() with a configurable platform for ref selection, repeated include/exclude filters, and id fallback formatting.
  • Reused the describe ref collection path where it fit, while keeping name-rev display names and filtering behavior separate where Git requires different output.
  • Added gix commit name-rev with --tags, repeated --refs <pattern>, repeated --exclude <pattern>, --always, --no-undefined, and --name-only.

Issue

Fixes #1268

The issue asks for functionality similar to:

git name-rev --no-undefined --always 4e2fd00

for shell integration use cases that need to find a branch/ref-based name for a commit.

Git Baseline

Used Git's builtin/name-rev.c behavior as the baseline: prepared ref tips are propagated backwards through the commit graph, first-parent ancestors format as name~N, side-parent paths format as name^M/name~N^M, annotated tags get ^0 when naming their peeled commit, and filtering is handled before the revision-layer walk.

Additional spot checks compared local Git 2.50.1 with the new gix commit name-rev implementation across branch, tag, merge, include, exclude, --tags, --always, and --name-only combinations.

Validation

  • cargo fmt
  • cargo test -p gix-revision name_rev
  • cargo test -p gix commit::name_rev
  • cargo test -p gix commit::describe::tags_preserve_the_full_git_timestamp_range
  • cargo test -p gitoxide-core commit
  • cargo check -p gix -p gitoxide-core
  • cargo check -p gix-revision --all-features
  • cargo check -p gitoxide
  • just clippy -D warnings -A unknown-lints --no-deps
  • cargo run -q -p gitoxide --bin gix -- commit name-rev --no-undefined --always --exclude='tags/*' --exclude='remotes/*' HEAD
  • GIX_TEST_FIXTURE_HASH=sha256 targeted fixture tests for the new name-rev fixtures
  • codex review --commit 29ce60c6729894abeaa230fa7801d259613dd0a1

Attempted cargo check -p gix -p gix-revision -p gitoxide-core --all-features, but it fails before this change is reached because gix-protocol rejects enabling its mutually exclusive blocking-client and async-client features together.

Issue #1268 asks for git-name-rev style commit naming so callers can find the branch or ref context for a commit. Git's builtin/name-rev.c propagates prepared ref names backwards through the commit graph, using first-parent generation names like main~2 and side-parent markers like main^2~1.

Add gix_revision::name_rev() over prepared tip data, with repository/ref collection and filtering implemented in gix::Commit::name_rev(). The gix layer reuses the describe ref collection path where useful while keeping describe's shortened tag names separate from name-rev's ref-style names. Add a basic gix commit name-rev command with --tags, --refs, --exclude, --always, --no-undefined, and --name-only.

Validation:
- cargo test -p gix-revision name_rev
- cargo test -p gix commit::name_rev
- cargo test -p gitoxide-core commit
- cargo check -p gix -p gitoxide-core
- cargo check -p gix-revision --all-features
- cargo check -p gitoxide
- cargo run -p gitoxide --bin gix -- commit name-rev --no-undefined --always --exclude=tags/* --exclude=remotes/* HEAD

Note: cargo check -p gix -p gix-revision -p gitoxide-core --all-features was attempted, but gix-protocol rejects enabling its mutually exclusive blocking-client and async-client features together.
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.

something like git name-rev to get branch of commit

2 participants