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

Re: [PATCH v2 4/7] struct ref_lock: delete the force_write member

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Mar 3, 2015, 10:50 UTC
Message-ID
<54F59212.5040105@alum.mit.edu>
In-Reply-To
<xmqqk2yz9ir9.fsf@gitster.dls.corp.google.com>
On 03/02/2015 10:44 PM, Junio C Hamano wrote:
Show 34 quoted lines
> Michael Haggerty <mhagger@alum.mit.edu> writes:
> 
>> Instead, compute the value when it is needed.
> 
>> @@ -2318,8 +2317,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
>>  	lock->ref_name = xstrdup(refname);
>>  	lock->orig_ref_name = xstrdup(orig_refname);
>>  	ref_file = git_path("%s", refname);
>> -	if ((flags & REF_NODEREF) && (type & REF_ISSYMREF))
>> -		lock->force_write = 1;
>>  
>>   retry:
>>  	switch (safe_create_leading_directories(ref_file)) {
>> @@ -3787,8 +3784,13 @@ int ref_transaction_commit(struct ref_transaction *transaction,
>>  		struct ref_update *update = updates[i];
>>  
>>  		if (!is_null_sha1(update->new_sha1)) {
>> -			if (!update->lock->force_write &&
>> -			    !hashcmp(update->lock->old_sha1, update->new_sha1)) {
>> +			if (!((update->type & REF_ISSYMREF)
>> +			      && (update->flags & REF_NODEREF))
>> +			    && !hashcmp(update->lock->old_sha1, update->new_sha1)) {
>> +				/*
>> +				 * The reference already has the desired
>> +				 * value, so we don't need to write it.
>> +				 */
>>  				unlock_ref(update->lock);
>>  				update->lock = NULL;
>>  			} else if (write_ref_sha1(update->lock, update->new_sha1,
> 
> The code before and after the change are equivalent.
> 
> It shouldn't be the case, but somehow I find the original slightly
> easier to understand. [...]

I had the same feeling; thanks for confirming it. How about I introduce a temporary variable `overwriting_symref` as an aid to the reader? I think this makes it pretty clear:

Show 15 quoted lines
>  		if (!is_null_sha1(update->new_sha1)) {
> -			if (!update->lock->force_write &&
> -			    !hashcmp(update->lock->old_sha1, update->new_sha1)) {
> +			int overwriting_symref = ((update->type & REF_ISSYMREF) &&
> +						  (update->flags & REF_NODEREF));
> +
> +			if (!overwriting_symref
> +			    && !hashcmp(update->lock->old_sha1, update->new_sha1)) {
> +				/*
> +				 * The reference already has the desired
> +				 * value, so we don't need to write it.
> +				 */
>  				unlock_ref(update->lock);
>  				update->lock = NULL;
>  			} else if (write_ref_sha1(update->lock, update->new_sha1,
Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
Previous: Junio C HamanoNext: Michael Haggerty
Message 7 of 13 in “Fix some problems with reflog expiration”
  1. 0/7 Fix some problems with reflog expirationMichael Haggerty, Mar 2, 2015
  2. 1/7 write_ref_sha1(): remove check for lock == NULLMichael Haggerty, Mar 2, 2015
  3. 2/7 write_ref_sha1(): Move write elision test to callersMichael Haggerty, Mar 2, 2015
  4. 3/7 lock_ref_sha1_basic(): do not set force_write for missing referencesMichael Haggerty, Mar 2, 2015
  5. 4/7 struct ref_lock: delete the force_write memberMichael Haggerty, Mar 2, 2015
  6. Junio C HamanoMar 2, 2015
  7. Michael HaggertyMar 3, 2015
  8. 5/7 reflog: improve and update documentationMichael Haggerty, Mar 2, 2015
  9. Junio C HamanoMar 2, 2015
  10. Michael HaggertyMar 3, 2015
  11. 6/7 reflog_expire(): ignore --updateref for symbolic referencesMichael Haggerty, Mar 2, 2015
  12. 7/7 reflog_expire(): never update a reference to null_sha1Michael Haggerty, Mar 2, 2015
  13. Junio C HamanoMar 2, 2015

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.