xdiff: use BUG(...), not xdl_bug(...)

The xdl_bug() function was introduced in e8adf23d1e (xdl_change_compact(): introduce the concept of a change group, 2016-08-22), let's use our usual BUG() function instead. We'll now have meaningful line numbers if we encounter bugs in xdiff, and less code duplication. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 7, 2021 at 18:43 UTC 546096a5cbb4806462d0e8e8fa4a562fc173aa8d
1 file changed +8 -14
xdiff/xdiffi.c
+8 -14
@@ -796,12 +796,6 @@ static int group_slide_up(xdfile_t *xdf, struct xdlgroup *g, long flags)
796 }
797 }
798
799 -static void xdl_bug(const char *msg)
800 -{
801 - fprintf(stderr, "BUG: %s\n", msg);
802 - exit(1);
803 -}
804 -
799 /*
800 * Move back and forward change groups for a consistent and pretty diff output.
801 * This also helps in finding joinable change groups and reducing the diff
@@ -841,7 +835,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
835 /* Shift the group backward as much as possible: */
836 while (!group_slide_up(xdf, &g, flags))
837 if (group_previous(xdfo, &go))
844 - xdl_bug("group sync broken sliding up");
838 + BUG("group sync broken sliding up");
839
840 /*
841 * This is this highest that this group can be shifted.
@@ -857,7 +851,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
851 if (group_slide_down(xdf, &g, flags))
852 break;
853 if (group_next(xdfo, &go))
860 - xdl_bug("group sync broken sliding down");
854 + BUG("group sync broken sliding down");
855
856 if (go.end > go.start)
857 end_matching_other = g.end;
@@ -882,9 +876,9 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
876 */
877 while (go.end == go.start) {
878 if (group_slide_up(xdf, &g, flags))
885 - xdl_bug("match disappeared");
879 + BUG("match disappeared");
880 if (group_previous(xdfo, &go))
887 - xdl_bug("group sync broken sliding to match");
881 + BUG("group sync broken sliding to match");
882 }
883 } else if (flags & XDF_INDENT_HEURISTIC) {
884 /*
@@ -925,9 +919,9 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
919
920 while (g.end > best_shift) {
921 if (group_slide_up(xdf, &g, flags))
928 - xdl_bug("best shift unreached");
922 + BUG("best shift unreached");
923 if (group_previous(xdfo, &go))
930 - xdl_bug("group sync broken sliding to blank line");
924 + BUG("group sync broken sliding to blank line");
925 }
926 }
927
@@ -936,11 +930,11 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
930 if (group_next(xdf, &g))
931 break;
932 if (group_next(xdfo, &go))
939 - xdl_bug("group sync broken moving to next group");
933 + BUG("group sync broken moving to next group");
934 }
935
936 if (!group_next(xdfo, &go))
943 - xdl_bug("group sync broken at end of file");
937 + BUG("group sync broken at end of file");
938
939 return 0;
940 }