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

Re: [PATCH 2/2] files-backend: don't rewrite the `packed-refs` file unnecessarily

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 26, 2017, 06:46 UTC
Message-ID
<xmqqpo9ae79w.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<4c03fc458f619a5f02dd4cae38da8b9b139b850b.1508924577.git.mhagger@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
> Even when we are deleting references, we needn't overwrite the
> `packed-refs` file if the references that we are deleting are not
> present in that file. Implement this optimization as follows:

This goal I can understand. files-transaction-prepare may see a deletion and in order to avoid a deletion of a ref from the file-backend to expose a stale entry in the packed-refs file, it prepares a transaction to remove the same ref that might exist in it. If it turns out that there is no such ref in the packed-refs file, then we can leave the packed-refs file as-is without rewriting.

> * Add a function `is_packed_transaction_noop()`, which checks whether
>   a given packed-refs transaction doesn't actually have to do
>   anything. This function must be called while holding the
>   `packed-refs` lock to avoid races.

This checks three things only to cover the most trivial case (I am perfectly happy that it punts on more complex cases). If an update

 - checks the old value,
 - sets a new value, or
 - deletes a ref that is not on the filesystem,

it is not a trivial case. I can understand the latter two (i.e. We are special casing the deletion, and an update with a new value is not. If removing a file from the filesystem is not sufficient to delete, we may have to rewrite the packed-refs), but not the first one. Is it because currently we do not say "delete this ref only when its current value is X"?

Also it is not immediately obvious how the "is this noop" helper is checking the absence of the same-named ref in the current packed-refs file, which is what matters for the correctness of the optimization.

Previous: Michael HaggertyNext: Michael Haggerty
Message 3 of 7 in “Avoid rewriting "packed-refs" unnecessarily”
  1. 0/2 Avoid rewriting "packed-refs" unnecessarilyMichael Haggerty, Oct 25, 2017
  2. 2/2 files-backend: don't rewrite the `packed-refs` file unnecessarilyMichael Haggerty, Oct 25, 2017
  3. Junio C HamanoOct 26, 2017
  4. Michael HaggertyOct 26, 2017
  5. 1/2 t1409: check that `packed-refs` is not rewritten unnecessarilyMichael Haggerty, Oct 25, 2017
  6. Eric SunshineOct 25, 2017
  7. Michael HaggertyOct 28, 2017

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.