Skip to content

Commit 7dfe427

Browse files
phillipwoodgitster
authored andcommitted
diff --color-moved: factor out function
This code is quite heavily indented and having it in its own function simplifies an upcoming change. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bea084b commit 7dfe427

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

diff.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,38 @@ static int shrink_potential_moved_blocks(struct moved_block *pmb,
10981098
return rp + 1;
10991099
}
11001100

1101+
static void fill_potential_moved_blocks(struct diff_options *o,
1102+
struct hashmap *hm,
1103+
struct moved_entry *match,
1104+
struct emitted_diff_symbol *l,
1105+
struct moved_block **pmb_p,
1106+
int *pmb_alloc_p, int *pmb_nr_p)
1107+
1108+
{
1109+
struct moved_block *pmb = *pmb_p;
1110+
int pmb_alloc = *pmb_alloc_p, pmb_nr = *pmb_nr_p;
1111+
1112+
/*
1113+
* The current line is the start of a new block.
1114+
* Setup the set of potential blocks.
1115+
*/
1116+
hashmap_for_each_entry_from(hm, match, ent) {
1117+
ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
1118+
if (o->color_moved_ws_handling &
1119+
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
1120+
if (compute_ws_delta(l, match->es, &(pmb[pmb_nr]).wsd))
1121+
pmb[pmb_nr++].match = match;
1122+
} else {
1123+
pmb[pmb_nr].wsd = 0;
1124+
pmb[pmb_nr++].match = match;
1125+
}
1126+
}
1127+
1128+
*pmb_p = pmb;
1129+
*pmb_alloc_p = pmb_alloc;
1130+
*pmb_nr_p = pmb_nr;
1131+
}
1132+
11011133
/*
11021134
* If o->color_moved is COLOR_MOVED_PLAIN, this function does nothing.
11031135
*
@@ -1198,23 +1230,8 @@ static void mark_color_as_moved(struct diff_options *o,
11981230
pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
11991231

12001232
if (pmb_nr == 0) {
1201-
/*
1202-
* The current line is the start of a new block.
1203-
* Setup the set of potential blocks.
1204-
*/
1205-
hashmap_for_each_entry_from(hm, match, ent) {
1206-
ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
1207-
if (o->color_moved_ws_handling &
1208-
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
1209-
if (compute_ws_delta(l, match->es,
1210-
&pmb[pmb_nr].wsd))
1211-
pmb[pmb_nr++].match = match;
1212-
} else {
1213-
pmb[pmb_nr].wsd = 0;
1214-
pmb[pmb_nr++].match = match;
1215-
}
1216-
}
1217-
1233+
fill_potential_moved_blocks(
1234+
o, hm, match, l, &pmb, &pmb_alloc, &pmb_nr);
12181235
if (adjust_last_block(o, n, block_length) &&
12191236
pmb_nr && last_symbol != l->s)
12201237
flipped_block = (flipped_block + 1) % 2;

0 commit comments

Comments
 (0)