Subject: Re: [PATCH v5 11/13] xdiff: rename rchg -> changed in xdfile_t

From: Phillip Wood <[email-masked]>
Date: Wed, 24 Sep 2025 11:22:03 +0100

On 23/09/2025 22:24, Ezekiel Newren via GitGitGadget wrote:
> From: Ezekiel Newren <[email-masked]>

I agree "changed" is a better name but the commit message should explain 
what "rchg" is used for so that someone who is not familiar with the 
code can understand why the change in name is desirable.

Thanks

Phillip
> Best-viewed-with: --color-words
> Signed-off-by: Ezekiel Newren <[email-masked]>
> ---
>   xdiff/xdiffi.c     | 28 ++++++++++++++--------------
>   xdiff/xhistogram.c |  8 ++++----
>   xdiff/xpatience.c  |  8 ++++----
>   xdiff/xprepare.c   | 12 ++++++------
>   xdiff/xtypes.h     |  2 +-
>   xdiff/xutils.c     |  4 ++--
>   6 files changed, 31 insertions(+), 31 deletions(-)
> 
> diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c
> index 83c4cff6f7..5535452061 100644
> --- a/xdiff/xdiffi.c
> +++ b/xdiff/xdiffi.c
> @@ -278,10 +278,10 @@ int xdl_recs_cmp(xdfile_t *xdf1, long off1, long lim1,
>   	 */
>   	if (off1 == lim1) {
>   		for (; off2 < lim2; off2++)
> -			xdf2->rchg[xdf2->rindex[off2]] = 1;
> +			xdf2->changed[xdf2->rindex[off2]] = 1;
>   	} else if (off2 == lim2) {
>   		for (; off1 < lim1; off1++)
> -			xdf1->rchg[xdf1->rindex[off1]] = 1;
> +			xdf1->changed[xdf1->rindex[off1]] = 1;
>   	} else {
>   		xdpsplit_t spl;
>   		spl.i1 = spl.i2 = 0;
> @@ -708,7 +708,7 @@ struct xdlgroup {
>   static void group_init(xdfile_t *xdf, struct xdlgroup *g)
>   {
>   	g->start = g->end = 0;
> -	while (xdf->rchg[g->end])
> +	while (xdf->changed[g->end])
>   		g->end++;
>   }
>   
> @@ -722,7 +722,7 @@ static inline int group_next(xdfile_t *xdf, struct xdlgroup *g)
>   		return -1;
>   
>   	g->start = g->end + 1;
> -	for (g->end = g->start; xdf->rchg[g->end]; g->end++)
> +	for (g->end = g->start; xdf->changed[g->end]; g->end++)
>   		;
>   
>   	return 0;
> @@ -738,7 +738,7 @@ static inline int group_previous(xdfile_t *xdf, struct xdlgroup *g)
>   		return -1;
>   
>   	g->end = g->start - 1;
> -	for (g->start = g->end; xdf->rchg[g->start - 1]; g->start--)
> +	for (g->start = g->end; xdf->changed[g->start - 1]; g->start--)
>   		;
>   
>   	return 0;
> @@ -753,10 +753,10 @@ static int group_slide_down(xdfile_t *xdf, struct xdlgroup *g)
>   {
>   	if (g->end < xdf->nrec &&
>   	    recs_match(&xdf->recs[g->start], &xdf->recs[g->end])) {
> -		xdf->rchg[g->start++] = 0;
> -		xdf->rchg[g->end++] = 1;
> +		xdf->changed[g->start++] = 0;
> +		xdf->changed[g->end++] = 1;
>   
> -		while (xdf->rchg[g->end])
> +		while (xdf->changed[g->end])
>   			g->end++;
>   
>   		return 0;
> @@ -774,10 +774,10 @@ static int group_slide_up(xdfile_t *xdf, struct xdlgroup *g)
>   {
>   	if (g->start > 0 &&
>   	    recs_match(&xdf->recs[g->start - 1], &xdf->recs[g->end - 1])) {
> -		xdf->rchg[--g->start] = 1;
> -		xdf->rchg[--g->end] = 0;
> +		xdf->changed[--g->start] = 1;
> +		xdf->changed[--g->end] = 0;
>   
> -		while (xdf->rchg[g->start - 1])
> +		while (xdf->changed[g->start - 1])
>   			g->start--;
>   
>   		return 0;
> @@ -938,9 +938,9 @@ int xdl_build_script(xdfenv_t *xe, xdchange_t **xscr) {
>   	 * Trivial. Collects "groups" of changes and creates an edit script.
>   	 */
>   	for (i1 = xe->xdf1.nrec, i2 = xe->xdf2.nrec; i1 >= 0 || i2 >= 0; i1--, i2--)
> -		if (xe->xdf1.rchg[i1 - 1] || xe->xdf2.rchg[i2 - 1]) {
> -			for (l1 = i1; xe->xdf1.rchg[i1 - 1]; i1--);
> -			for (l2 = i2; xe->xdf2.rchg[i2 - 1]; i2--);
> +		if (xe->xdf1.changed[i1 - 1] || xe->xdf2.changed[i2 - 1]) {
> +			for (l1 = i1; xe->xdf1.changed[i1 - 1]; i1--);
> +			for (l2 = i2; xe->xdf2.changed[i2 - 1]; i2--);
>   
>   			if (!(xch = xdl_add_change(cscr, i1, i2, l1 - i1, l2 - i2))) {
>   				xdl_free_script(cscr);
> diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c
> index 4d857e8ae2..15ca15f6b0 100644
> --- a/xdiff/xhistogram.c
> +++ b/xdiff/xhistogram.c
> @@ -318,11 +318,11 @@ redo:
>   
>   	if (!count1) {
>   		while(count2--)
> -			env->xdf2.rchg[line2++ - 1] = 1;
> +			env->xdf2.changed[line2++ - 1] = 1;
>   		return 0;
>   	} else if (!count2) {
>   		while(count1--)
> -			env->xdf1.rchg[line1++ - 1] = 1;
> +			env->xdf1.changed[line1++ - 1] = 1;
>   		return 0;
>   	}
>   
> @@ -335,9 +335,9 @@ redo:
>   	else {
>   		if (lcs.begin1 == 0 && lcs.begin2 == 0) {
>   			while (count1--)
> -				env->xdf1.rchg[line1++ - 1] = 1;
> +				env->xdf1.changed[line1++ - 1] = 1;
>   			while (count2--)
> -				env->xdf2.rchg[line2++ - 1] = 1;
> +				env->xdf2.changed[line2++ - 1] = 1;
>   			result = 0;
>   		} else {
>   			result = histogram_diff(xpp, env,
> diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c
> index bf69a58527..14092ffb86 100644
> --- a/xdiff/xpatience.c
> +++ b/xdiff/xpatience.c
> @@ -331,11 +331,11 @@ static int patience_diff(xpparam_t const *xpp, xdfenv_t *env,
>   	/* trivial case: one side is empty */
>   	if (!count1) {
>   		while(count2--)
> -			env->xdf2.rchg[line2++ - 1] = 1;
> +			env->xdf2.changed[line2++ - 1] = 1;
>   		return 0;
>   	} else if (!count2) {
>   		while(count1--)
> -			env->xdf1.rchg[line1++ - 1] = 1;
> +			env->xdf1.changed[line1++ - 1] = 1;
>   		return 0;
>   	}
>   
> @@ -347,9 +347,9 @@ static int patience_diff(xpparam_t const *xpp, xdfenv_t *env,
>   	/* are there any matching lines at all? */
>   	if (!map.has_matches) {
>   		while(count1--)
> -			env->xdf1.rchg[line1++ - 1] = 1;
> +			env->xdf1.changed[line1++ - 1] = 1;
>   		while(count2--)
> -			env->xdf2.rchg[line2++ - 1] = 1;
> +			env->xdf2.changed[line2++ - 1] = 1;
>   		xdl_free(map.entries);
>   		return 0;
>   	}
> diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
> index 27c5a4d636..b9b19c36de 100644
> --- a/xdiff/xprepare.c
> +++ b/xdiff/xprepare.c
> @@ -126,7 +126,7 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
>   static void xdl_free_ctx(xdfile_t *xdf)
>   {
>   	xdl_free(xdf->rindex);
> -	xdl_free(xdf->rchg - 1);
> +	xdl_free(xdf->changed - 1);
>   	xdl_free(xdf->recs);
>   }
>   
> @@ -139,7 +139,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
>   	xrecord_t *crec;
>   
>   	xdf->rindex = NULL;
> -	xdf->rchg = NULL;
> +	xdf->changed = NULL;
>   	xdf->recs = NULL;
>   
>   	if (!XDL_ALLOC_ARRAY(xdf->recs, narec))
> @@ -161,7 +161,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
>   		}
>   	}
>   
> -	if (!XDL_CALLOC_ARRAY(xdf->rchg, xdf->nrec + 2))
> +	if (!XDL_CALLOC_ARRAY(xdf->changed, xdf->nrec + 2))
>   		goto abort;
>   
>   	if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) &&
> @@ -170,7 +170,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
>   			goto abort;
>   	}
>   
> -	xdf->rchg += 1;
> +	xdf->changed += 1;
>   	xdf->nreff = 0;
>   	xdf->dstart = 0;
>   	xdf->dend = xdf->nrec - 1;
> @@ -287,7 +287,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
>   		    (dis1[i] == 2 && !xdl_clean_mmatch(dis1, i, xdf1->dstart, xdf1->dend))) {
>   			xdf1->rindex[nreff++] = i;
>   		} else
> -			xdf1->rchg[i] = 1;
> +			xdf1->changed[i] = 1;
>   	}
>   	xdf1->nreff = nreff;
>   
> @@ -297,7 +297,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
>   		    (dis2[i] == 2 && !xdl_clean_mmatch(dis2, i, xdf2->dstart, xdf2->dend))) {
>   			xdf2->rindex[nreff++] = i;
>   		} else
> -			xdf2->rchg[i] = 1;
> +			xdf2->changed[i] = 1;
>   	}
>   	xdf2->nreff = nreff;
>   
> diff --git a/xdiff/xtypes.h b/xdiff/xtypes.h
> index 3d26cbf1ec..c4b5d2d8fa 100644
> --- a/xdiff/xtypes.h
> +++ b/xdiff/xtypes.h
> @@ -48,7 +48,7 @@ typedef struct s_xdfile {
>   	xrecord_t *recs;
>   	long nrec;
>   	long dstart, dend;
> -	char *rchg;
> +	char *changed;
>   	long *rindex;
>   	long nreff;
>   } xdfile_t;
> diff --git a/xdiff/xutils.c b/xdiff/xutils.c
> index 332982b509..ed65c222e6 100644
> --- a/xdiff/xutils.c
> +++ b/xdiff/xutils.c
> @@ -425,8 +425,8 @@ int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
>   	if (xdl_do_diff(&subfile1, &subfile2, xpp, &env) < 0)
>   		return -1;
>   
> -	memcpy(diff_env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1);
> -	memcpy(diff_env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2);
> +	memcpy(diff_env->xdf1.changed + line1 - 1, env.xdf1.changed, count1);
> +	memcpy(diff_env->xdf2.changed + line2 - 1, env.xdf2.changed, count2);
>   
>   	xdl_free_env(&env);
>