sequencer: introduce todo_list_write_to_file()
[gitweb.git] / xdiff / xdiffi.c
index 760fbb6db7583f6d0ec5eed9b9c63ea6a0e7abe7..1f1f4a3c7808435f73b0ffd1c35d5b0572516b6c 100644 (file)
@@ -13,8 +13,8 @@
  *  Lesser General Public License for more details.
  *
  *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  License along with this library; if not, see
+ *  <http://www.gnu.org/licenses/>.
  *
  *  Davide Libenzi <davidel@xmailserver.org>
  *
 
 #include "xinclude.h"
 
-
-
 #define XDL_MAX_COST_MIN 256
 #define XDL_HEUR_MIN_COST 256
 #define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1)
 #define XDL_SNAKE_CNT 20
 #define XDL_K_HEUR 4
 
-
-
 typedef struct s_xdpsplit {
        long i1, i2;
        int min_lo, min_hi;
 } xdpsplit_t;
 
-
-
-
-static long xdl_split(unsigned long const *ha1, long off1, long lim1,
-                     unsigned long const *ha2, long off2, long lim2,
-                     long *kvdf, long *kvdb, int need_min, xdpsplit_t *spl,
-                     xdalgoenv_t *xenv);
-static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, long chg2);
-
-
-
-
-
 /*
  * See "An O(ND) Difference Algorithm and its Variations", by Eugene Myers.
  * Basically considers a "box" (off1, off2, lim1, lim2) and scan from both
@@ -400,11 +383,6 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1,
 }
 
 
-static int is_blank_line(xrecord_t *rec, long flags)
-{
-       return xdl_blankline(rec->ptr, rec->size, flags);
-}
-
 static int recs_match(xrecord_t *rec1, xrecord_t *rec2, long flags)
 {
        return (rec1->ha == rec2->ha &&
@@ -596,6 +574,11 @@ static void measure_split(const xdfile_t *xdf, long split,
  */
 #define INDENT_WEIGHT 60
 
+/*
+ * How far do we slide a hunk at most?
+ */
+#define INDENT_HEURISTIC_MAX_SLIDING 100
+
 /*
  * Compute a badness score for the hypothetical split whose measurements are
  * stored in m. The weight factors were determined empirically using the tools and
@@ -821,7 +804,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
        struct xdlgroup g, go;
        long earliest_end, end_matching_other;
        long groupsize;
-       unsigned int blank_lines;
 
        group_init(xdf, &g);
        group_init(xdfo, &go);
@@ -846,13 +828,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
                         */
                        end_matching_other = -1;
 
-                       /*
-                        * Boolean value that records whether there are any blank
-                        * lines that could be made to be the last line of this
-                        * group.
-                        */
-                       blank_lines = 0;
-
                        /* Shift the group backward as much as possible: */
                        while (!group_slide_up(xdf, &g, flags))
                                if (group_previous(xdfo, &go))
@@ -869,11 +844,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
 
                        /* Now shift the group forward as far as possible: */
                        while (1) {
-                               if (!blank_lines)
-                                       blank_lines = is_blank_line(
-                                                       xdf->recs[g.end - 1],
-                                                       flags);
-
                                if (group_slide_down(xdf, &g, flags))
                                        break;
                                if (group_next(xdfo, &go))
@@ -906,21 +876,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
                                if (group_previous(xdfo, &go))
                                        xdl_bug("group sync broken sliding to match");
                        }
-               } else if ((flags & XDF_COMPACTION_HEURISTIC) && blank_lines) {
-                       /*
-                        * Compaction heuristic: if it is possible to shift the
-                        * group to make its bottom line a blank line, do so.
-                        *
-                        * As we already shifted the group forward as far as
-                        * possible in the earlier loop, we only need to handle
-                        * backward shifts, not forward ones.
-                        */
-                       while (!is_blank_line(xdf->recs[g.end - 1], flags)) {
-                               if (group_slide_up(xdf, &g, flags))
-                                       xdl_bug("blank line disappeared");
-                               if (group_previous(xdfo, &go))
-                                       xdl_bug("group sync broken sliding to blank line");
-                       }
                } else if (flags & XDF_INDENT_HEURISTIC) {
                        /*
                         * Indent heuristic: a group of pure add/delete lines
@@ -936,7 +891,12 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
                        long shift, best_shift = -1;
                        struct split_score best_score;
 
-                       for (shift = earliest_end; shift <= g.end; shift++) {
+                       shift = earliest_end;
+                       if (g.end - groupsize - 1 > shift)
+                               shift = g.end - groupsize - 1;
+                       if (g.end - INDENT_HEURISTIC_MAX_SLIDING > shift)
+                               shift = g.end - INDENT_HEURISTIC_MAX_SLIDING;
+                       for (; shift <= g.end; shift++) {
                                struct split_measurement m;
                                struct split_score score = {0, 0};