From: Derrick Stolee <stolee@gmail.com>
To: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org
Cc: Taylor Blau <me@ttaylorr.com>,
Eric Sunshine <sunshine@sunshineco.com>,
Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v2 3/7] merge-ort: fix type of local 'clean' var in handle_content_merge()
Date: Thu, 27 Jun 2024 22:44:42 -0400 [thread overview]
Message-ID: <6db979ed-3d08-4ac4-b1c6-65a76939de35@gmail.com> (raw)
In-Reply-To: <034b91db1d2ed78995b52c014de313744972ff40.1718766019.git.gitgitgadget@gmail.com>
On 6/18/24 11:00 PM, Elijah Newren via GitGitGadget wrote:
> From: Elijah Newren <newren@gmail.com>
>
> handle_content_merge() returns an int. Every caller of
> handle_content_merge() expects an int. However, we declare a local
> variable 'clean' that we use for the return value to be unsigned. To
> make matters worse, we also assign 'clean' the return value of
> merge_submodule() in one codepath, which is defined to return an int.
> It seems that the only reason to have 'clean' be unsigned was to allow a
> cutesy bit manipulation operation to be well-defined. Fix the type of
> the 'clean' local in handle_content_merge().
> @@ -2184,7 +2184,8 @@ static int handle_content_merge(struct merge_options *opt,
> free(result_buf.ptr);
> if (ret)
> return -1;
> - clean &= (merge_status == 0);
> + if (merge_status > 0)
> + clean = 0;
> path_msg(opt, INFO_AUTO_MERGING, 1, path, NULL, NULL, NULL,
> _("Auto-merging %s"), path);
> } else if (S_ISGITLINK(a->mode)) {
Even after this removal of this cute bitflip, there is one more
subtle use still in the code:
diff --git a/merge-ort.c b/merge-ort.c
index 8dfe80f1009..569014eef31 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -2629,7 +2629,8 @@ static char *check_for_directory_rename(struct
merge_options *opt,
new_path = handle_path_level_conflicts(opt, path, side_index,
rename_info,
&collisions[side_index]);
- *clean_merge &= (new_path != NULL);
+ if (*clean_merge && !new_path)
+ *clean_merge = 0;
return new_path;
}
I had to think very carefully about this cleverness to be sure
that this conversion is right (and I'm only mostly sure). When
(new_path != NULL) is false, then we definitely set *clean_merge
to zero. Otherwise, we set it to 1 (but only when it was already
1 or -1). Technically, this does change the behavior by not
squashing -1 into 1, but that is less likely to be an existing
value of *clean_merge.
There are other uses of "clean &= collect_renames(...)" but that
appears to be fine because collect_renames() never results in an
abort state (returning -1).
Thanks,
-Stolee
next prev parent reply other threads:[~2024-06-28 2:44 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-13 20:25 [PATCH 0/7] Fix and improve some error codepaths in merge-ort Elijah Newren via GitGitGadget
2024-06-13 20:25 ` [PATCH 1/7] merge-ort: extract handling of priv member into reusable function Elijah Newren via GitGitGadget
2024-06-13 21:00 ` Junio C Hamano
2024-06-13 22:52 ` Taylor Blau
2024-06-13 20:25 ` [PATCH 2/7] merge-ort: maintain expected invariant for priv member Elijah Newren via GitGitGadget
2024-06-13 22:59 ` Taylor Blau
2024-06-19 2:58 ` Elijah Newren
2024-06-13 20:25 ` [PATCH 3/7] merge-ort: fix type of local 'clean' var in handle_content_merge() Elijah Newren via GitGitGadget
2024-06-13 20:25 ` [PATCH 4/7] merge-ort: clearer propagation of failure-to-function from merge_submodule Elijah Newren via GitGitGadget
2024-06-13 20:25 ` [PATCH 5/7] merge-ort: loosen commented requirements Elijah Newren via GitGitGadget
2024-06-13 20:25 ` [PATCH 6/7] merge-ort: upon merge abort, only show messages causing the abort Elijah Newren via GitGitGadget
2024-06-14 4:19 ` Eric Sunshine
2024-06-19 2:58 ` Elijah Newren
2024-06-13 20:25 ` [PATCH 7/7] merge-ort: convert more error() cases to path_msg() Elijah Newren via GitGitGadget
2024-06-13 23:04 ` [PATCH 0/7] Fix and improve some error codepaths in merge-ort Taylor Blau
2024-06-19 3:00 ` [PATCH v2 " Elijah Newren via GitGitGadget
2024-06-19 3:00 ` [PATCH v2 1/7] merge-ort: extract handling of priv member into reusable function Elijah Newren via GitGitGadget
2024-06-19 3:00 ` [PATCH v2 2/7] merge-ort: maintain expected invariant for priv member Elijah Newren via GitGitGadget
2024-06-28 2:09 ` Derrick Stolee
2024-06-19 3:00 ` [PATCH v2 3/7] merge-ort: fix type of local 'clean' var in handle_content_merge() Elijah Newren via GitGitGadget
2024-06-28 2:44 ` Derrick Stolee [this message]
2024-06-19 3:00 ` [PATCH v2 4/7] merge-ort: clearer propagation of failure-to-function from merge_submodule Elijah Newren via GitGitGadget
2024-06-28 2:12 ` Derrick Stolee
2024-06-28 2:38 ` Elijah Newren
2024-06-28 2:47 ` Derrick Stolee
2024-06-19 3:00 ` [PATCH v2 5/7] merge-ort: loosen commented requirements Elijah Newren via GitGitGadget
2024-06-19 3:00 ` [PATCH v2 6/7] merge-ort: upon merge abort, only show messages causing the abort Elijah Newren via GitGitGadget
2024-06-19 3:00 ` [PATCH v2 7/7] merge-ort: convert more error() cases to path_msg() Elijah Newren via GitGitGadget
2024-07-02 21:33 ` Jeff King
2024-07-03 15:48 ` Elijah Newren
2024-07-03 18:35 ` Junio C Hamano
2024-07-06 6:11 ` Jeff King
2024-06-28 2:45 ` [PATCH v2 0/7] Fix and improve some error codepaths in merge-ort Derrick Stolee
2024-06-28 17:11 ` 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=6db979ed-3d08-4ac4-b1c6-65a76939de35@gmail.com \
--to=stolee@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=me@ttaylorr.com \
--cc=newren@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).