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

Re: [PATCH 4/4] refs.c: sort the refs by new_sha1 and merge the two update/delete loops into one

From
Ronnie Sahlberg <sahlberg@google.com>
Date
Apr 10, 2014, 19:40 UTC
Message-ID
<CAL=YDWnADZmCa3v1gk37bbcQcnnAZ=+hi-OSFVdneWrP4_Lv0A@mail.gmail.com>
In-Reply-To
<xmqqy4zdvwjg.fsf@gitster.dls.corp.google.com>
On Thu, Apr 10, 2014 at 12:01 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 48 quoted lines
> Ronnie Sahlberg <sahlberg@google.com> writes:
>
>> We want to make sure that we update all refs before we delete any refs
>> so that there is no point in time where the tips may not be reachable
>> from any ref in the system.
>> We currently acheive this by first looping over all updates and applying
>> them before we run a second loop and perform all the deletes.
>>
>> If we sort the new sha1 for all the refs so that a deleted ref,
>> with sha1 0{40} comes at the end of the array, then we can just run
>> a single loop and still guarantee that all updates happen before
>> any deletes.
>>
>> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
>> ---
>>  refs.c | 18 +++++++++++-------
>>  1 file changed, 11 insertions(+), 7 deletions(-)
>>
>> diff --git a/refs.c b/refs.c
>> index 1678e12..453318e 100644
>> --- a/refs.c
>> +++ b/refs.c
>> @@ -3309,6 +3309,15 @@ static int ref_update_compare(const void *r1, const void *r2)
>>       return strcmp((*u1)->ref_name, (*u2)->ref_name);
>>  }
>>
>> +static int ref_delete_compare(const void *r1, const void *r2)
>> +{
>> +     const struct ref_update * const *u1 = r1;
>> +     const struct ref_update * const *u2 = r2;
>> +
>> +     /* -strcmp so that 0{40} sorts to the end */
>> +     return -strcmp((*u1)->new_sha1, (*u2)->new_sha1);
>
> Two glitches:
>
>  - Didn't you mean hashcmp()?
>
>  - Don't you have an explicit ->delete_ref field that is a more
>    direct way, than relying on the convention "updating to 0{40}
>    is to delte", to express this?
>
> In other words, wouldn't it be more like
>
>         return !(*u1)->delete_ref - !(*u2)->delete_ref;
>
> or something (I may be wrong about the sign, tho---I didn't think
> carefully)?
I don't have access to delete_ref from 'struct ref_update'.

But much worse is that the patch is completely bogus. Sorting and changing the order of the items in the updates[] array does not affect the ordering of the items in the locks[] array so this can not work.

I will delete this bogus patch from any new version of the patch series.

regards ronnie sahlberg

Show 23 quoted lines
>
>
>> +}
>> +
>>  static int ref_update_reject_duplicates(struct ref_update **updates, int n,
>>                                       enum action_on_err onerr)
>>  {
>> @@ -3388,13 +3397,8 @@ int update_refs(const char *action, const struct ref_update **updates_orig,
>>               unlink_or_warn(git_path("logs/%s", delnames[i]));
>>       clear_loose_ref_cache(&ref_cache);
>>
>> -     /* Perform updates first so live commits remain referenced */
>> -     for (i = 0; i < n; i++)
>> -             if (locks[i] && !locks[i]->delete_ref) {
>> -                     ret |= commit_ref_lock(locks[i]);
>> -                     locks[i] = NULL;
>> -             }
>> -     /* And finally perform all deletes */
>> +     /* Sort the array so that we perform all updates before any deletes */
>> +     qsort(updates, n, sizeof(*updates), ref_delete_compare);
>>       for (i = 0; i < n; i++)
>>               if (locks[i]) {
>>                       ret |= commit_ref_lock(locks[i]);
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 9 in “Make update_refs more atomic V2”
  1. 0/4 Make update_refs more atomic V2Ronnie Sahlberg, Apr 10, 2014
  2. 1/4 refs.c: split writing and commiting a ref into two separate functionsRonnie Sahlberg, Apr 10, 2014
  3. 2/4 refs.c: split delete_ref_loose() into a separate flag-for-deletion and commit phaseRonnie Sahlberg, Apr 10, 2014
  4. 3/4 refs.c: change update_refs to run the commit loops once all work is finishedRonnie Sahlberg, Apr 10, 2014
  5. 4/4 refs.c: sort the refs by new_sha1 and merge the two update/delete loops into oneRonnie Sahlberg, Apr 10, 2014
  6. Junio C HamanoApr 10, 2014
  7. Ronnie SahlbergApr 10, 2014
  8. Junio C HamanoApr 10, 2014
  9. Junio C HamanoApr 10, 2014

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.