Re: [PATCH v5 12/13] xdiff: use enum macros NONE(0), SOME(1), TOO_MANY(2) in xprepare.c
- From
Ezekiel Newren <ezekielnewren@gmail.com>
- Date
- Sep 25, 2025, 18:40 UTC
- Message-ID
- <CAH=ZcbC-cB35AGmiKgEQdFa5ee+DftwOQ_dUe4=T+Vq-dxR+qQ@mail.gmail.com>
- In-Reply-To
- <1c3461c3-09bb-404d-a4dc-a895baba68f2@gmail.com>
On Wed, Sep 24, 2025 at 9:18 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 39 quoted lines
> > On 24/09/2025 15:46, Ezekiel Newren wrote: > > On Wed, Sep 24, 2025 at 4:21 AM Phillip Wood <phillip.wood123@gmail.com> wrote: > >> > >> On 23/09/2025 22:24, Ezekiel Newren via GitGitGadget wrote: > >>> From: Ezekiel Newren <ezekielnewren@gmail.com> > >>> > >>> Rename dis1, dis2 to matches1, matches2. > >>> > >>> Define macros NONE(0), SOME(1), TOO_MANY(2) as the enum values for > >>> matches1 and matches2. These states will influence whether changed[i] > >>> is set to 1 or kept as 0. > >> > >> This message also says what is being changed rather than why it is being > >> changed. I think the rename here is a good idea but I'm not sure what > >> "rdis[01]" and "rpdis[01]" are used for and whether they should be > >> renamed if we're renaming "dis[01]" > > > > "Rename dis1, dis2 to matches1, matches2 to give the variable names a > > more obvious meaning." > > > > Would something like that work, or do I need to refine it further? > > I'd maybe add a sentence before that to explain that "dis1 and dis2 are > used to record if a line has zero, one or many matches on the other side > of the diff". I don't think any of these patches need huge commit > messages but a couple of sentences explaining the reasoning would be > helpful for anyone looking at them it the future. > > > I > > would love to rename rdis, rpdis, etc... except that I don't > > understand what is happening or why. Could someone explain the purpose > > of these variables? > > Good question, I'm not sure anyone has an intimate knowledge of this > code. My understanding is that the code aims to remove runs of common > lines when they occur between unique lines in order to reduce the number > of lines we need to look at when we're calculating the diff. I haven't > worked through the code in detail though.
I'm really struggling with how to write this commit message. I would very much appreciate suggestions. Here is what I have so far: --- commit message start --- xdiff: use enum macros NONE(0), SOME(1), TOO_MANY(2) in xprepare.c
The local variables dis1 and dis2 describe how a line should be treated based on how many lines, in the other file, match this line. NONE means the other file does not have any matches to this line. SOME means that there are more than 0 matches, but less than some heuristic threshold. TOO_MANY is when there are more matches than that heuristic threshold.
Note: When need_min is true, matches[i] is always set to SOME when the number of matches is greater than 0.
The names dis1 and dis2 don't convey what they mean, so let's rename them to matches1 and matches2.
Define macros NONE(0), SOME(1), TOO_MANY(2) as the enum values for matches1 and matches2. These states will influence whether changed[i] is set to 1 or kept as 0.
The variables r, rdis0, rpdis0, rdis1, rpdis1 in xdl_clean_mmatch() have not been renamed because I don't understand their purpose. --- commit message end ---
I'll explain the parts of the code that are relevant to the commit message with an example. The following snippet goes through every line (matches1[i]) of file1 to determine what matches1[i] should be by looking at the number of times that line shows up in file2.
if ((mlim = xdl_bogosqrt(xdf1->nrec)) > XDL_MAX_EQLIMIT)
mlim = XDL_MAX_EQLIMIT;
for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; i <=
xdf1->dend; i++, recs++) {
rcrec = cf->rcrecs[recs->ha];
nm = rcrec ? rcrec->len2 : 0;
matches1[i] = (nm == 0) ? NONE: (nm >= mlim && !need_min) ?
TOO_MANY: SOME;
}The lines:
rcrec = cf->rcrecs[recs->ha];
nm = rcrec ? rcrec->len2 : 0;
gets the number of matches from file2 (i.e. rcrec->len2), and then this line:
matches1[i] = (nm == 0) ? NONE: (nm >= mlim && !need_min) ? TOO_MANY: SOME;
Is the logic to set matches1[i] (the line in question of file1) to
NONE, SOME, or TOO_MANY.
mlim seems to be some heuristic threshold based on the XDL_MAX_EQLIMIT
constant which is set to 1024.