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

Re: [PATCH 3/3] name-rev: --weight option (WIP)

From
Jeff King <peff@peff.net>
Date
Aug 30, 2012, 03:36 UTC
Message-ID
<20120830033611.GA32268@sigill.intra.peff.net>
In-Reply-To
<7vligxuv6l.fsf@alter.siamese.dyndns.org>
On Wed, Aug 29, 2012 at 04:37:06PM -0700, Junio C Hamano wrote:
Show 28 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > Note that this is fairly expensive (see NEEDSWORK comment in the
> > code).
> 
> And this is with the "notes-cache".
> [...]
> +static int get_tip_weight(struct commit *commit)
> +{
> +	struct strbuf buf = STRBUF_INIT;
> +	size_t sz;
> +	int weight;
> +	char *note = notes_cache_get(&weight_cache, commit->object.sha1, &sz);
> +
> +	if (note && !strtol_i(note, 10, &weight)) {
> +		free(note);
> +		return weight;
> +	}
> +	free(note);
> +
> +	weight = compute_tip_weight(commit);
> +	strbuf_addf(&buf, "%d", weight);
> +	notes_cache_put(&weight_cache, commit->object.sha1,
> +			buf.buf, buf.len);
> +	strbuf_release(&buf);
> +	weight_cache_updated = 1;
> +	return weight;
> +}

It looks like you didn't update compute_tip_weight at all, so it will still do the full traversal down to the roots. I wonder if you can define the weight as a recursive function of the parents. Using the sum of the weights of the parents is not right, because you would double-count in this situation:

  A--B--C--D---M
      \       /
       E--F--G

That would double-count "A" and "B" in this example. But maybe there is a clever way to define it that avoids that.

The advantage would be that you could cheaply find the weights of new commits by only traversing back to the last cached one. I did something similar with the generation number cache (but the recursive definition is easier there).

> +	if (use_weight)
> +		notes_cache_init(&weight_cache, "name-rev-weight", "2012-08-29");

Is that a sufficient validity field? What about grafts or replace objects? For the generation cache, I used a hash of the graft and replace fields.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 19 in “Funny 'git describe --contains' output”
  1. Greg KHAug 29, 2012
  2. Junio C HamanoAug 29, 2012
  3. Junio C HamanoAug 29, 2012
  4. Greg KHAug 29, 2012
  5. 0/3 "git name-rev --weight"Junio C Hamano, Aug 29, 2012
  6. 1/3 name-rev: lose unnecessary typedefJunio C Hamano, Aug 29, 2012
  7. 2/3 name_rev: clarify when a new tip-name is assigned to a commitJunio C Hamano, Aug 29, 2012
  8. 3/3 name-rev: --weight option (WIP)Junio C Hamano, Aug 29, 2012
  9. Junio C HamanoAug 29, 2012
  10. Jeff KingAug 30, 2012
  11. Junio C HamanoAug 30, 2012
  12. Jeff KingAug 30, 2012
  13. Junio C HamanoAug 30, 2012
  14. Junio C HamanoAug 30, 2012
  15. Junio C HamanoAug 30, 2012
  16. Jeff KingAug 30, 2012
  17. Junio C HamanoAug 30, 2012
  18. Philip OakleyAug 30, 2012
  19. Junio C HamanoAug 30, 2012

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.