rust-lang / rust-lang/git2-rs

Divergent hash length behaviour from git when running `git describe --tags --always`

Open
#1,176 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
450
Avg merge
11m
Merged PRs (30d)
1

Description

Hey there!

Noticed that when using git2 to compute the result of git describe, the behaviour can diverge from git

In particular this code

pub fn git_describe_native(path: &Path) -> Result<String> {
    let repo = Repository::open(path)?;

    let mut describe_opts = DescribeOptions::new();
    describe_opts.describe_tags();
    describe_opts.show_commit_oid_as_fallback(true);

    let description = repo.describe(&describe_opts).into_diagnostic()?;

    let format_opts = DescribeFormatOptions::new();
    description.format(Some(&format_opts)).into_diagnostic()?;
}

will differ from git describe --tags --always in specific cases where the repo grows too large.

According to git docs the length of the abbreviation scales as the repository grows, using the approximate number of objects in the repository and a bit of math around the birthday paradox, and defaults to a minimum of 7.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the git_describe_native entry point shown in the issue and compare its output with git describe --tags --always on repositories where abbreviation length diverges. Read the git describe documentation and the relevant git2 describe formatting behavior first. Done means the Rust result matches Git's repository-size-dependent hash abbreviation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.