"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: diff.git: Fix ed script output
To:
Tom Jones <thj@freebsd.org>
Cc:
gameoftrees@openbsd.org
Date:
Fri, 2 Sep 2022 11:35:01 +0200

Download raw body.

Thread
  • Stefan Sperling:

    diff.git: Fix ed script output

  • On Wed, Aug 31, 2022 at 01:24:44PM +0100, Tom Jones wrote:
    > For this case there is an optimisation where diff_output_plain only
    > generates the headers for a hunk, but I'll leave that path for future
    > hackers.
    
    This passes Got regress (with appropriate changes to diff_output_plain()
    calls, not shown here).
    
    Note that we don't use 'bool' in the public API header files, because
    we don't want to force the use of a 'bool' type on API users (which
    could require including stdbool.h etc.);
    
    diff 9230203d371721cf5bde99f526fe40740aea3b21 279d77aa1e4b921090e702a6a8a5a94a98a062b1
    commit - 9230203d371721cf5bde99f526fe40740aea3b21
    commit + 279d77aa1e4b921090e702a6a8a5a94a98a062b1
    blob - 304efb917050acadd79aae06eec9473ae5fdc797
    blob + e2f352bf17421cfdc1dd349b9740f53d91599b2e
    --- include/diff_output.h
    +++ include/diff_output.h
    @@ -53,7 +53,8 @@ struct diff_chunk_context {
     
     int diff_output_plain(struct diff_output_info **output_info, FILE *dest,
     			const struct diff_input_info *info,
    -			const struct diff_result *result);
    +			const struct diff_result *result,
    +			int hunk_headers_only);
     int diff_output_unidiff(struct diff_output_info **output_info,
     			FILE *dest, const struct diff_input_info *info,
     			const struct diff_result *result,
    blob - 60533bd949aeec8ada84abec88bf7e58e93f5ff5
    blob + 7b0082bd1b84c999c55bbf418266fd4a41017a0c
    --- lib/diff_output_plain.c
    +++ lib/diff_output_plain.c
    @@ -31,7 +31,7 @@ static int
     output_plain_chunk(struct diff_output_info *outinfo,
         FILE *dest, const struct diff_input_info *info,
         const struct diff_result *result,
    -    struct diff_chunk_context *cc, off_t *outoff)
    +    struct diff_chunk_context *cc, off_t *outoff, bool headers_only)
     {
     	off_t *offp;
     	int left_start, left_len, right_start, right_len;
    @@ -113,7 +113,8 @@ output_plain_chunk(struct diff_output_info *outinfo,
     	 * additions and deletions when this happens.
     	 */
     	int c_idx;
    -	for (c_idx = cc->chunk.start; c_idx < cc->chunk.end; c_idx++) {
    +	for (c_idx = cc->chunk.start; !headers_only && c_idx < cc->chunk.end;
    +	    c_idx++) {
     		const struct diff_chunk *c = &result->chunks.head[c_idx];
     		if (c->left_count && !c->right_count)
     			rc = diff_output_lines(outinfo, dest,
    @@ -152,7 +153,7 @@ output_plain_chunk(struct diff_output_info *outinfo,
     int
     diff_output_plain(struct diff_output_info **output_info,
         FILE *dest, const struct diff_input_info *info,
    -    const struct diff_result *result)
    +    const struct diff_result *result, int hunk_headers_only)
     {
     	struct diff_output_info *outinfo = NULL;
     	struct diff_chunk_context cc = {};
    @@ -233,13 +234,13 @@ diff_output_plain(struct diff_output_info **output_inf
     			continue;
     		}
     		rc = output_plain_chunk(outinfo, dest, info, result, &cc,
    -		    &outoff);
    +		    &outoff, hunk_headers_only);
     		if (rc != DIFF_RC_OK)
     			return rc;
     		cc = next;
     	}
     	if (!diff_chunk_context_empty(&cc))
     		return output_plain_chunk(outinfo, dest, info, result, &cc,
    -		    &outoff);
    +		    &outoff, hunk_headers_only);
     	return DIFF_RC_OK;
     }
    
    
  • Stefan Sperling:

    diff.git: Fix ed script output