@@ -855,6 +855,38 @@ static int shrink_potential_moved_blocks(struct moved_entry **pmb,
855
855
return rp + 1 ;
856
856
}
857
857
858
+ /*
859
+ * If o->color_moved is COLOR_MOVED_PLAIN, this function does nothing.
860
+ *
861
+ * Otherwise, if the last block has fewer alphanumeric characters than
862
+ * COLOR_MOVED_MIN_ALNUM_COUNT, unset DIFF_SYMBOL_MOVED_LINE on all lines in
863
+ * that block.
864
+ *
865
+ * The last block consists of the (n - block_length)'th line up to but not
866
+ * including the nth line.
867
+ *
868
+ * NEEDSWORK: This uses the same heuristic as blame_entry_score() in blame.c.
869
+ * Think of a way to unify them.
870
+ */
871
+ static void adjust_last_block (struct diff_options * o , int n , int block_length )
872
+ {
873
+ int i , alnum_count = 0 ;
874
+ if (o -> color_moved == COLOR_MOVED_PLAIN )
875
+ return ;
876
+ for (i = 1 ; i < block_length + 1 ; i ++ ) {
877
+ const char * c = o -> emitted_symbols -> buf [n - i ].line ;
878
+ for (; * c ; c ++ ) {
879
+ if (!isalnum (* c ))
880
+ continue ;
881
+ alnum_count ++ ;
882
+ if (alnum_count >= COLOR_MOVED_MIN_ALNUM_COUNT )
883
+ return ;
884
+ }
885
+ }
886
+ for (i = 1 ; i < block_length + 1 ; i ++ )
887
+ o -> emitted_symbols -> buf [n - i ].flags &= ~DIFF_SYMBOL_MOVED_LINE ;
888
+ }
889
+
858
890
/* Find blocks of moved code, delegate actual coloring decision to helper */
859
891
static void mark_color_as_moved (struct diff_options * o ,
860
892
struct hashmap * add_lines ,
@@ -890,20 +922,13 @@ static void mark_color_as_moved(struct diff_options *o,
890
922
}
891
923
892
924
if (!match ) {
893
- if (block_length < COLOR_MOVED_MIN_BLOCK_LENGTH &&
894
- o -> color_moved != COLOR_MOVED_PLAIN ) {
895
- for (i = 0 ; i < block_length + 1 ; i ++ ) {
896
- l = & o -> emitted_symbols -> buf [n - i ];
897
- l -> flags &= ~DIFF_SYMBOL_MOVED_LINE ;
898
- }
899
- }
925
+ adjust_last_block (o , n , block_length );
900
926
pmb_nr = 0 ;
901
927
block_length = 0 ;
902
928
continue ;
903
929
}
904
930
905
931
l -> flags |= DIFF_SYMBOL_MOVED_LINE ;
906
- block_length ++ ;
907
932
908
933
if (o -> color_moved == COLOR_MOVED_PLAIN )
909
934
continue ;
@@ -933,11 +958,17 @@ static void mark_color_as_moved(struct diff_options *o,
933
958
}
934
959
935
960
flipped_block = (flipped_block + 1 ) % 2 ;
961
+
962
+ adjust_last_block (o , n , block_length );
963
+ block_length = 0 ;
936
964
}
937
965
966
+ block_length ++ ;
967
+
938
968
if (flipped_block )
939
969
l -> flags |= DIFF_SYMBOL_MOVED_LINE_ALT ;
940
970
}
971
+ adjust_last_block (o , n , block_length );
941
972
942
973
free (pmb );
943
974
}
0 commit comments