From: Junio C Hamano <gitster@pobox.com>
To: Michael Haggerty <mhagger@alum.mit.edu>
Cc: "Stefan Beller" <sbeller@google.com>,
"Ronnie Sahlberg" <ronniesahlberg@gmail.com>,
"Jonathan Nieder" <jrnieder@gmail.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Jeff King" <peff@peff.net>,
git@vger.kernel.org
Subject: Re: [PATCH v2 4/7] struct ref_lock: delete the force_write member
Date: Mon, 02 Mar 2015 13:44:42 -0800 [thread overview]
Message-ID: <xmqqk2yz9ir9.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1425288597-20547-5-git-send-email-mhagger@alum.mit.edu> (Michael Haggerty's message of "Mon, 2 Mar 2015 10:29:54 +0100")
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. The before and after says the same thing,
i.e. the code used to be:
- We say "do the write-out without questioning" when we are
updating a symbolic ref without dereferencing.
- Do nothing and unlock if we are not told to "do the write-out
without questioning" and the update will be a no-op anyway.
while the code after the change says:
+ Do nothing and unlock if we are not handling "update a symbolic
ref without dereferencing" and the update will be a no-op anyway.
Perhaps the former has the same effect as "avoid a single complex
sentence and use two short sentences instead".
The negation in the condition does not help, either.
* If we are updating a symbolic ref without dereferencing, or if we
are updating with a different object name, we definitely have to
write.
would be easier to understand, perhaps? I.e.
if (hashcmp(update->lock->old_sha1, update->lock->new_sha1) ||
((update->type & REF_ISSYMREF) && (update->flags & REF_NO_DEREF))) {
/* do the write-out thing */
} else {
/* the request to update from the same to the same is a no-op */
unlock_ref(update->lock);
update->lock = NULL;
}
I dunno.
next prev parent reply other threads:[~2015-03-02 21:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-02 9:29 [PATCH v2 0/7] Fix some problems with reflog expiration Michael Haggerty
2015-03-02 9:29 ` [PATCH v2 1/7] write_ref_sha1(): remove check for lock == NULL Michael Haggerty
2015-03-02 9:29 ` [PATCH v2 2/7] write_ref_sha1(): Move write elision test to callers Michael Haggerty
2015-03-02 9:29 ` [PATCH v2 3/7] lock_ref_sha1_basic(): do not set force_write for missing references Michael Haggerty
2015-03-02 9:29 ` [PATCH v2 4/7] struct ref_lock: delete the force_write member Michael Haggerty
2015-03-02 21:44 ` Junio C Hamano [this message]
2015-03-03 10:50 ` Michael Haggerty
2015-03-02 9:29 ` [PATCH v2 5/7] reflog: improve and update documentation Michael Haggerty
2015-03-02 22:04 ` Junio C Hamano
2015-03-03 11:35 ` Michael Haggerty
2015-03-02 9:29 ` [PATCH v2 6/7] reflog_expire(): ignore --updateref for symbolic references Michael Haggerty
2015-03-02 9:29 ` [PATCH v2 7/7] reflog_expire(): never update a reference to null_sha1 Michael Haggerty
2015-03-02 22:09 ` [PATCH v2 0/7] Fix some problems with reflog expiration Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqk2yz9ir9.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=mhagger@alum.mit.edu \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=ronniesahlberg@gmail.com \
--cc=sbeller@google.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.