Commit Diff
Diff:
810479a563ffd6176105f64cb49f9829d45d36df
9230203d371721cf5bde99f526fe40740aea3b21
Commit:
9230203d371721cf5bde99f526fe40740aea3b21
Tree:
5f8f1b4b2c0077932b573ab5a588e0bf338f5925
Author:
Stefan Sperling <stsp@stsp.name>
Date:
Fri Sep 2 09:21:04 2022 UTC
Message:
fix updating of line-offsets output info in plain output mode

reviewed by tom jones
commit - 810479a563ffd6176105f64cb49f9829d45d36df
commit + 9230203d371721cf5bde99f526fe40740aea3b21
blob - 1ead91212f5b867edc7e7187ec03e3d6eaf1f565
blob + 60533bd949aeec8ada84abec88bf7e58e93f5ff5
--- lib/diff_output_plain.c
+++ lib/diff_output_plain.c
@@ -31,9 +31,9 @@ output_plain_chunk(struct diff_output_info *outinfo,
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)
+ struct diff_chunk_context *cc, off_t *outoff)
{
- off_t outoff = 0, *offp;
+ off_t *offp;
int left_start, left_len, right_start, right_len;
int rc;
bool change = false;
@@ -95,6 +95,15 @@ output_plain_chunk(struct diff_output_info *outinfo,
cc->left.end, right_start, cc->right.end);
}
}
+ if (rc < 0)
+ return errno;
+ if (outinfo) {
+ ARRAYLIST_ADD(offp, outinfo->line_offsets);
+ if (offp == NULL)
+ return ENOMEM;
+ *outoff += rc;
+ *offp = *outoff;
+ }
/*
* Now write out all the joined chunks.
@@ -111,8 +120,19 @@ output_plain_chunk(struct diff_output_info *outinfo,
c->solved ? "< " : "?",
c->left_start, c->left_count);
else if (c->right_count && !c->left_count) {
- if (change)
- fprintf(dest, "---\n");
+ if (change) {
+ rc = fprintf(dest, "---\n");
+ if (rc < 0)
+ return errno;
+ if (outinfo) {
+ ARRAYLIST_ADD(offp,
+ outinfo->line_offsets);
+ if (offp == NULL)
+ return ENOMEM;
+ *outoff += rc;
+ *offp = *outoff;
+ }
+ }
rc = diff_output_lines(outinfo, dest,
c->solved ? "> " : "?",
c->right_start, c->right_count);
@@ -126,16 +146,6 @@ output_plain_chunk(struct diff_output_info *outinfo,
}
}
- if (rc < 0)
- return errno;
- if (outinfo) {
- ARRAYLIST_ADD(offp, outinfo->line_offsets);
- if (offp == NULL)
- return ENOMEM;
- outoff += rc;
- *offp = outoff;
- }
-
return DIFF_RC_OK;
}
@@ -153,6 +163,7 @@ diff_output_plain(struct diff_output_info **output_inf
bool force_text = (flags & DIFF_FLAG_FORCE_TEXT_DATA);
bool have_binary = (atomizer_flags & DIFF_ATOMIZER_FOUND_BINARY_DATA);
int i, rc;
+ off_t outoff = 0, *offp;
if (!result)
return EINVAL;
@@ -174,9 +185,18 @@ diff_output_plain(struct diff_output_info **output_inf
if (t != CHUNK_MINUS && t != CHUNK_PLUS)
continue;
- fprintf(dest, "Binary files %s and %s differ\n",
+ rc = fprintf(dest, "Binary files %s and %s differ\n",
diff_output_get_label_left(info),
diff_output_get_label_right(info));
+ if (rc < 0)
+ return errno;
+ if (outinfo) {
+ ARRAYLIST_ADD(offp, outinfo->line_offsets);
+ if (offp == NULL)
+ return ENOMEM;
+ outoff += rc;
+ *offp = outoff;
+ }
break;
}
@@ -212,12 +232,14 @@ diff_output_plain(struct diff_output_info **output_inf
* loop */
continue;
}
- rc = output_plain_chunk(outinfo, dest, info, result, &cc);
+ rc = output_plain_chunk(outinfo, dest, info, result, &cc,
+ &outoff);
if (rc != DIFF_RC_OK)
return rc;
cc = next;
}
if (!diff_chunk_context_empty(&cc))
- return output_plain_chunk(outinfo, dest, info, result, &cc);
+ return output_plain_chunk(outinfo, dest, info, result, &cc,
+ &outoff);
return DIFF_RC_OK;
}
Omar Polo