commit 26c524e8b8f4e1182ecc904b22d03fc6b69609e8 from: Neels Hofmeyr date: Sun May 03 03:18:58 2020 UTC diff_output_unidiff(): less indent by 'continue' commit - 0c8f9ca838a8ea073480afde255bd0f304742d43 commit + 26c524e8b8f4e1182ecc904b22d03fc6b69609e8 blob - 986d06cbf5ec125bca1bfbce84d7cd3378501735 blob + 372263de595ed3969e52c25db8662df4ad2b69ab --- lib/diff_output_unidiff.c +++ lib/diff_output_unidiff.c @@ -149,42 +149,48 @@ enum diff_rc diff_output_unidiff(FILE *dest, const str for (i = 0; i < result->chunks.len; i++) { struct diff_chunk *c = &result->chunks.head[i]; enum chunk_type t = chunk_type(c); + struct chunk_context next; - if (t == CHUNK_MINUS || t == CHUNK_PLUS) { - if (chunk_context_empty(&cc)) { - /* These are the first lines being printed. - * Note down the start point, any number of subsequent chunks may be joined up to this - * unidiff chunk by context lines or by being directly adjacent. */ - chunk_context_get(&cc, result, i, context_lines); - debug("new chunk to be printed: chunk %d-%d left %d-%d right %d-%d\n", - cc.chunk.start, cc.chunk.end, - cc.left.start, cc.left.end, cc.right.start, cc.right.end); - } else { - /* There already is a previous chunk noted down for being printed. - * Does it join up with this one? */ - struct chunk_context next; - chunk_context_get(&next, result, i, context_lines); - debug("new chunk to be printed: chunk %d-%d left %d-%d right %d-%d\n", - next.chunk.start, next.chunk.end, - next.left.start, next.left.end, next.right.start, next.right.end); - if (chunk_contexts_touch(&cc, &next)) { - /* This next context touches or overlaps the previous one, join. */ - chunk_contexts_merge(&cc, &next); - debug("new chunk to be printed touches previous chunk, now: left %d-%d right %d-%d\n", - cc.left.start, cc.left.end, cc.right.start, cc.right.end); - } else { - /* No touching, so the previous context is complete with a gap between it and - * this next one. Print the previous one and start fresh here. */ - debug("new chunk to be printed does not touch previous chunk; print left %d-%d right %d-%d\n", - cc.left.start, cc.left.end, cc.right.start, cc.right.end); - diff_output_unidiff_chunk(dest, &info_printed, info, result, &cc); - cc = next; - debug("new unprinted chunk is left %d-%d right %d-%d\n", - cc.left.start, cc.left.end, cc.right.start, cc.right.end); - } - } + if (t != CHUNK_MINUS && t != CHUNK_PLUS) + continue; + + if (chunk_context_empty(&cc)) { + /* These are the first lines being printed. + * Note down the start point, any number of subsequent chunks may be joined up to this + * unidiff chunk by context lines or by being directly adjacent. */ + chunk_context_get(&cc, result, i, context_lines); + debug("new chunk to be printed: chunk %d-%d left %d-%d right %d-%d\n", + cc.chunk.start, cc.chunk.end, + cc.left.start, cc.left.end, + cc.right.start, cc.right.end); + continue; } + /* There already is a previous chunk noted down for being printed. + * Does it join up with this one? */ + chunk_context_get(&next, result, i, context_lines); + debug("new chunk to be printed: chunk %d-%d left %d-%d right %d-%d\n", + next.chunk.start, next.chunk.end, + next.left.start, next.left.end, + next.right.start, next.right.end); + + if (chunk_contexts_touch(&cc, &next)) { + /* This next context touches or overlaps the previous one, join. */ + chunk_contexts_merge(&cc, &next); + debug("new chunk to be printed touches previous chunk, now: left %d-%d right %d-%d\n", + cc.left.start, cc.left.end, + cc.right.start, cc.right.end); + continue; + } + + /* No touching, so the previous context is complete with a gap between it and + * this next one. Print the previous one and start fresh here. */ + debug("new chunk to be printed does not touch previous chunk; print left %d-%d right %d-%d\n", + cc.left.start, cc.left.end, cc.right.start, cc.right.end); + diff_output_unidiff_chunk(dest, &info_printed, info, result, &cc); + cc = next; + debug("new unprinted chunk is left %d-%d right %d-%d\n", + cc.left.start, cc.left.end, cc.right.start, cc.right.end); } if (!chunk_context_empty(&cc))