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

Re: [PATCH 09/15] refs.c: only write reflog update if msg is non-NULL

From
Ronnie Sahlberg <sahlberg@google.com>
Date
Oct 28, 2014, 19:17 UTC
Message-ID
<CAL=YDWkZE0KXrM+SqL1gZoQR_u7kcvWjQfton7AoavfptqcM4w@mail.gmail.com>
In-Reply-To
<xmqq8uk6skky.fsf@gitster.dls.corp.google.com>
On Thu, Oct 23, 2014 at 11:32 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 19 quoted lines
> Ronnie Sahlberg <sahlberg@google.com> writes:
>
>> commit 020ed65a12838bdead64bc3c5de249d3c8f5cfd8 upstream.
>>
>> When performing a reflog transaction update, only write to the reflog iff
>> msg is non-NULL. This can then be combined with REFLOG_TRUNCATE to perform
>> an update that only truncates but does not write.
>
> Does any existing caller call this codepath with update->msg == NULL?
>
> Will "please truncate" stay to be the only plausible special cause
> to call into this codepath without having any meaningful message?
>
> I am trying to make sure that this patch is not painting us into a
> corner where we will find out another reason for doing something
> esoteric in this codepath but need to find a way other than setting
> msg to NULL for the caller to trigger that new codepath.  Put it in
> another way, please convince me that a new boolean field in update,
> e.g. update->truncate_reflog, is way overkill for this.

This change only affects whether or not a reflog entry will be emitted by the update. msg==NULL means we will not create a new entry. This is orthogonal to whether we truncate the log or not.

In order to truncate the reflog we do have a boolean in update->flags & REFLOG_TRUNCATE which determines whether the update will truncate the log or not.

I see these two actions a) write a log entry and b) truncate the log as orthogonal and thus think we should have separate knobs for them.

Currently, modulo bugs, the only caller that will use msg==NULL is when we do reflog truncations. Thus that codepath BOTH sets msg==NULL (to not write a new log entry) and also sets update->flags&REFLOG_TRUNCATE (to truncate the log).

Having separate knobs for the two actions allow us the current behaviour with:
  msg==NULL update->flags&REFLOG_TRUNCATE
but it will also allow a caller to do things like
   msg="truncated by foo because ..." update->flags&REFLOG_TRUNCATE

If there is some future usecase where we want to truncate the log and then also generate a new initial log entry for the new log.

I will work on the commit message to make the distinction between msg==NULL and update->flags&REFLOG_TRUNCATE more clear.

thanks ronnie sahlberg

Show 38 quoted lines
>
>>
>> Change-Id: I44c89caa7e7c4960777b79cfb5d339a5aa3ddf7a
>> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
>> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
>> ---
>>  refs.c | 5 +++--
>>  refs.h | 1 +
>>  2 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/refs.c b/refs.c
>> index d54c3b9..f14b76e 100644
>> --- a/refs.c
>> +++ b/refs.c
>> @@ -3895,8 +3895,9 @@ int transaction_commit(struct transaction *transaction,
>>                               update->reflog_fd = -1;
>>                               continue;
>>                       }
>> -             if (log_ref_write_fd(update->reflog_fd, update->old_sha1,
>> -                                  update->new_sha1,
>> +             if (update->msg &&
>> +                 log_ref_write_fd(update->reflog_fd,
>> +                                  update->old_sha1, update->new_sha1,
>>                                    update->committer, update->msg)) {
>>                       error("Could write to reflog: %s. %s",
>>                             update->refname, strerror(errno));
>> diff --git a/refs.h b/refs.h
>> index 5075073..bf96b36 100644
>> --- a/refs.h
>> +++ b/refs.h
>> @@ -337,6 +337,7 @@ int transaction_delete_ref(struct transaction *transaction,
>>  /*
>>   * Append a reflog entry for refname. If the REFLOG_TRUNCATE flag is set
>>   * this update will first truncate the reflog before writing the entry.
>> + * If msg is NULL no update will be written to the log.
>>   */
>>  int transaction_update_reflog(struct transaction *transaction,
>>                             const char *refname,
Previous: Junio C HamanoNext: Ronnie Sahlberg
Message 20 of 28 in “ref-transactions-reflog”
  1. 00/15 ref-transactions-reflogRonnie Sahlberg, Oct 21, 2014
  2. 01/15 refs.c make ref_transaction_create a wrapper to ref_transaction_updateRonnie Sahlberg, Oct 21, 2014
  3. Junio C HamanoOct 23, 2014
  4. Ronnie SahlbergOct 23, 2014
  5. Junio C HamanoOct 23, 2014
  6. Junio C HamanoOct 28, 2014
  7. 02/15 refs.c: make ref_transaction_delete a wrapper for ref_transaction_updateRonnie Sahlberg, Oct 21, 2014
  8. Junio C HamanoOct 23, 2014
  9. 03/15 refs.c: rename the transaction functionsRonnie Sahlberg, Oct 21, 2014
  10. 04/15 refs.c: add a new update_type field to ref_updateRonnie Sahlberg, Oct 21, 2014
  11. Junio C HamanoOct 23, 2014
  12. 05/15 refs.c: add a function to append a reflog entry to a fdRonnie Sahlberg, Oct 21, 2014
  13. 06/15 copy.c: make copy_fd preserve meaningful errnoRonnie Sahlberg, Oct 21, 2014
  14. Junio C HamanoOct 23, 2014
  15. Ronnie SahlbergOct 23, 2014
  16. 07/15 refs.c: add a transaction function to append a reflog entryRonnie Sahlberg, Oct 21, 2014
  17. 08/15 refs.c: add a flag to allow reflog updates to truncate the logRonnie Sahlberg, Oct 21, 2014
  18. 09/15 refs.c: only write reflog update if msg is non-NULLRonnie Sahlberg, Oct 21, 2014
  19. Junio C HamanoOct 23, 2014
  20. Ronnie SahlbergOct 28, 2014
  21. 10/15 refs.c: allow multiple reflog updates during a single transactionRonnie Sahlberg, Oct 21, 2014
  22. Junio C HamanoOct 23, 2014
  23. Ronnie SahlbergOct 28, 2014
  24. 11/15 reflog.c: use a reflog transaction when writing during expireRonnie Sahlberg, Oct 21, 2014
  25. 12/15 refs.c: rename log_ref_setup to create_reflogRonnie Sahlberg, Oct 21, 2014
  26. 13/15 refs.c: make unlock_ref/close_ref/commit_ref staticRonnie Sahlberg, Oct 21, 2014
  27. 14/15 refs.c: remove lock_any_ref_for_updateRonnie Sahlberg, Oct 21, 2014
  28. 15/15 refs.c: allow deleting refs with a broken sha1Ronnie Sahlberg, Oct 21, 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.