Skip to content

Commit e2fe6ab

Browse files
stefanbellergitster
authored andcommitted
diff.c: factor advance_or_nullify out of mark_color_as_moved
This moves the part of code that checks if we're still in a block into its own function. We'll need a different approach on advancing the blocks in a later patch, so having it as a separate function will prove useful. While at it rename the variable `p` to `prev` to indicate that it refers to the previous line. This is as pmb[i] was assigned in the last iteration of the outmost for loop. Further rename `pnext` to `cur` to indicate that this should match up with the current line of the outmost for loop. Also replace the advancement of pmb[i] to reuse `cur` instead of using `p->next` (which is how the name for pnext could be explained. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b309571 commit e2fe6ab

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

diff.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,25 @@ static void add_lines_to_move_detection(struct diff_options *o,
801801
}
802802
}
803803

804+
static void pmb_advance_or_null(struct diff_options *o,
805+
struct moved_entry *match,
806+
struct hashmap *hm,
807+
struct moved_entry **pmb,
808+
int pmb_nr)
809+
{
810+
int i;
811+
for (i = 0; i < pmb_nr; i++) {
812+
struct moved_entry *prev = pmb[i];
813+
struct moved_entry *cur = (prev && prev->next_line) ?
814+
prev->next_line : NULL;
815+
if (cur && !hm->cmpfn(o, cur, match, NULL)) {
816+
pmb[i] = cur;
817+
} else {
818+
pmb[i] = NULL;
819+
}
820+
}
821+
}
822+
804823
static int shrink_potential_moved_blocks(struct moved_entry **pmb,
805824
int pmb_nr)
806825
{
@@ -875,7 +894,6 @@ static void mark_color_as_moved(struct diff_options *o,
875894
struct moved_entry *key;
876895
struct moved_entry *match = NULL;
877896
struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
878-
int i;
879897

880898
switch (l->s) {
881899
case DIFF_SYMBOL_PLUS:
@@ -906,17 +924,7 @@ static void mark_color_as_moved(struct diff_options *o,
906924
if (o->color_moved == COLOR_MOVED_PLAIN)
907925
continue;
908926

909-
/* Check any potential block runs, advance each or nullify */
910-
for (i = 0; i < pmb_nr; i++) {
911-
struct moved_entry *p = pmb[i];
912-
struct moved_entry *pnext = (p && p->next_line) ?
913-
p->next_line : NULL;
914-
if (pnext && !hm->cmpfn(o, pnext, match, NULL)) {
915-
pmb[i] = p->next_line;
916-
} else {
917-
pmb[i] = NULL;
918-
}
919-
}
927+
pmb_advance_or_null(o, match, hm, pmb, pmb_nr);
920928

921929
pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
922930

0 commit comments

Comments
 (0)