commit - 4ba2e95571e317867b5ed45cb6c8580a33627500
commit + e72b098390333cd6d10b39518001fba7ba6a1790
blob - 304efb917050acadd79aae06eec9473ae5fdc797
blob + e2f352bf17421cfdc1dd349b9740f53d91599b2e
--- lib/diff_output.h
+++ lib/diff_output.h
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 - 1ead91212f5b867edc7e7187ec03e3d6eaf1f565
blob + 7b0082bd1b84c999c55bbf418266fd4a41017a0c
--- lib/diff_output_plain.c
+++ lib/diff_output_plain.c
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, bool headers_only)
{
- off_t outoff = 0, *offp;
+ off_t *offp;
int left_start, left_len, right_start, right_len;
int rc;
bool change = false;
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.
* 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,
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);
}
}
- 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;
}
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 = {};
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;
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;
}
* loop */
continue;
}
- rc = output_plain_chunk(outinfo, dest, info, result, &cc);
+ rc = output_plain_chunk(outinfo, dest, info, result, &cc,
+ &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);
+ return output_plain_chunk(outinfo, dest, info, result, &cc,
+ &outoff, hunk_headers_only);
return DIFF_RC_OK;
}
blob - 077eb7fcb67ce1962a147e0f065b0755ec7ac98a
blob + 154e8609c89ab357a787c3bfc9b14426c2dd2c2f
--- lib/diffreg.c
+++ lib/diffreg.c
break;
case GOT_DIFF_OUTPUT_PLAIN:
rc = diff_output_plain(lines ? &output_info : NULL,
- outfile, &info, diff_result->result);
+ outfile, &info, diff_result->result, 1);
if (rc != DIFF_RC_OK)
return got_error_set_errno(rc, "diff_output_edscript");
break;