Message ID | 2813a15b48b70ead7e3fd062d1b49baee665fc9d.1718766019.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 5fadf1f93371204b82a02a30315f655a293aa7f5 |
Headers | show |
Series | Fix and improve some error codepaths in merge-ort | expand |
On 6/18/24 11:00 PM, Elijah Newren via GitGitGadget wrote: > From: Elijah Newren <newren@gmail.com> > > The 'clean' member variable is somewhat of a tri-state (1 = clean, 0 = > conflicted, -1 = failure-to-determine), but we often like to think of > it as binary (ignoring the possibility of a negative value) and use > constructs like '!clean' to reflect this. However, these constructs > can make codepaths more difficult to understand, unless we handle the > negative case early and return pre-emptively; do that in > handle_content_merge() to make the code a bit easier to read. This patch is correct and valuable. Would it be valuable to go a bit further and turn 'clean' into an enum that reflects these states? Perhaps that would prevent future changes from slipping into this mistake. Thanks, -Stolee
On Thu, Jun 27, 2024 at 7:12 PM Derrick Stolee <stolee@gmail.com> wrote: > > On 6/18/24 11:00 PM, Elijah Newren via GitGitGadget wrote: > > From: Elijah Newren <newren@gmail.com> > > > > The 'clean' member variable is somewhat of a tri-state (1 = clean, 0 = > > conflicted, -1 = failure-to-determine), but we often like to think of > > it as binary (ignoring the possibility of a negative value) and use > > constructs like '!clean' to reflect this. However, these constructs > > can make codepaths more difficult to understand, unless we handle the > > negative case early and return pre-emptively; do that in > > handle_content_merge() to make the code a bit easier to read. > > This patch is correct and valuable. > > Would it be valuable to go a bit further and turn 'clean' into > an enum that reflects these states? Perhaps that would prevent > future changes from slipping into this mistake. That may make sense to investigate, but I suspect it may be a bigger change and would recommend making such a clean up a separate series. Also, I'm curious if it makes sense to finish off replacing recursive with ort first; as long as recursive exists, it has the same problem and in fact was the source of using a tri-state 'clean' variable and thus would need the same cleanup. But if we replace recursive with ort (making explicit requests for 'recursive' be handled by 'ort', as originally designed and intended), that cuts the number of sites needing this cleanup in half.
On 6/27/24 10:38 PM, Elijah Newren wrote: > On Thu, Jun 27, 2024 at 7:12 PM Derrick Stolee <stolee@gmail.com> wrote: >> >> On 6/18/24 11:00 PM, Elijah Newren via GitGitGadget wrote: >>> From: Elijah Newren <newren@gmail.com> >>> >>> The 'clean' member variable is somewhat of a tri-state (1 = clean, 0 = >>> conflicted, -1 = failure-to-determine), but we often like to think of >>> it as binary (ignoring the possibility of a negative value) and use >>> constructs like '!clean' to reflect this. However, these constructs >>> can make codepaths more difficult to understand, unless we handle the >>> negative case early and return pre-emptively; do that in >>> handle_content_merge() to make the code a bit easier to read. >> >> This patch is correct and valuable. >> >> Would it be valuable to go a bit further and turn 'clean' into >> an enum that reflects these states? Perhaps that would prevent >> future changes from slipping into this mistake. > > That may make sense to investigate, but I suspect it may be a bigger > change and would recommend making such a clean up a separate series. > > Also, I'm curious if it makes sense to finish off replacing recursive > with ort first; as long as recursive exists, it has the same problem > and in fact was the source of using a tri-state 'clean' variable and > thus would need the same cleanup. But if we replace recursive with > ort (making explicit requests for 'recursive' be handled by 'ort', as > originally designed and intended), that cuts the number of sites > needing this cleanup in half. Your fast response to this message means that I didn't see this when I mentioned it in my closing of the review (in response to your cover letter). Reducing the size of the conversion would definitely be good to do, and then you could also consider using the existing ll_merge_result enum, though it technically has four states. Thanks, -Stolee
diff --git a/merge-ort.c b/merge-ort.c index be0f5bc3838..d187c966c6a 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2193,6 +2193,8 @@ static int handle_content_merge(struct merge_options *opt, clean = merge_submodule(opt, pathnames[0], two_way ? null_oid() : &o->oid, &a->oid, &b->oid, &result->oid); + if (clean < 0) + return -1; if (opt->priv->call_depth && two_way && !clean) { result->mode = o->mode; oidcpy(&result->oid, &o->oid);