git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] describe: count the distance correctly when commit dates are skewed

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 2, 2026, 12:46 UTC
Message-ID
<auiGP4XhObUzC9vD@pks.im>
In-Reply-To
<20261031065525.19883-2-torvalds@kernel.org>
On Fri, Oct 30, 2026 at 11:55:03PM -0700, Linus Torvalds wrote:
Show 16 quoted lines
> From: Linus Torvalds <torvalds@linux-foundation.org>
> 
> The current merge window for Linux v7.4 showed annoying behavior with
> 'git describe', where it doesn't actually follow the documented intent
> of the result: the commit distance is miscomputed when the commit dates
> aren't entirely reliable.
> 
> This makes the 'git describe' output not match what the kernel
> calculates in its localversion:
> 
> 	linux$ git describe && uname -r
> 	v7.3-19342-g2a500a04d6f9
> 	7.3.0-19059-g2a500a04d6f9
> 
> and the kernel calculation is correct, and 'git describe' is wrong. The
> number that 'git describe' gives (19342) is nonsense.

Out of curiosity, how do you calculate the localversion...? *goes checking* Ah, you seem to use `git rev-list --count --left-right $tag`, so you basically reimplement parts of git-describe(1).

Is there a reason why you use your own script, e.g. because of a missing feature? Besides the fact of course that git-describe(1) is buggy in this particular case.

Show 14 quoted lines
> The fix is to take the commit generation number into account when
> ordering the commits. That will still fail if the repository has no
> commit graph, but it at least improves on the situation in the common
> case. With that one-liner fix, 'git describe' gets the correct commit
> distance on my kernel tree:
> 
> 	linux$ git describe && uname -r
> 	v7.3-19059-g2a500a04d6f9
> 	7.3.0-19059-g2a500a04d6f9
> 
> See also commit 1b600e659a ("Compute accurate distances in git-describe
> before output.", 2007-01-27) which fixed a different issue in this same
> area. Clearly the *intent* is that the distance number is actually the
> real distance.

Hmm. The big downside of this particular change is that you may now get different results depending on whether or not you have a recent commit graph. So you may get different results based on when git-maintenance(1) last decided to update it, and that would in turn result in highly puzzling behaviour for the end user.

So...
Show 13 quoted lines
> diff --git a/builtin/describe.c b/builtin/describe.c
> index c0abc931a5..2cd597d919 100644
> --- a/builtin/describe.c
> +++ b/builtin/describe.c
> @@ -328,7 +328,7 @@ static void append_suffix(int depth, const struct object_id *oid, struct strbuf
>  static void describe_commit(struct commit *cmit, struct strbuf *dst)
>  {
>  	struct commit *c, *gave_up_on = NULL;
> -	struct prio_queue queue = { compare_commits_by_commit_date };
> +	struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
>  	struct commit_name *n;
>  	struct possible_tag all_matches[MAX_TAGS];
>  	unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;

... I wonder whether we should also call `ensure_generations_valid()` here. That function is very expensive in cases where we don't have a commit graph as it backfills generation numbers, and it may have to walk the complete commit graph to do so. But isn't that better compared to silently yielding a potentially-wrong result?

Thanks!
Patrick
Previous: SZEDER GáborNext: Derrick Stolee
Message 7 of 13 in “describe: count the distance correctly when commit dates are skewed”
  1. describe: count the distance correctly when commit dates are skewedLinus Torvalds, Oct 31, 2026
  2. Tuomas AholaOct 31, 2026
  3. Junio C HamanoNov 1, 2026
  4. Tuomas AholaNov 1, 2026
  5. Junio C HamanoNov 1, 2026
  6. SZEDER GáborNov 2, 2026
  7. Patrick SteinhardtNov 2, 2026
  8. Derrick StoleeNov 2, 2026
  9. Junio C HamanoNov 2, 2026
  10. Derrick StoleeNov 2, 2026
  11. Linus TorvaldsNov 2, 2026
  12. Patrick SteinhardtNov 3, 2026
  13. Linus TorvaldsNov 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.