patch 8.2.3390: included xdiff code is outdated
Problem: Included xdiff code is outdated.
Solution: Sync with xdiff in git 2.33. (Christian Brabandt, closes #8431)
diff --git a/src/xdiff/xpatience.c b/src/xdiff/xpatience.c
index f6c84c6..f78c897 100644
--- a/src/xdiff/xpatience.c
+++ b/src/xdiff/xpatience.c
@@ -20,8 +20,6 @@
*
*/
#include "xinclude.h"
-#include "xtypes.h"
-#include "xdiff.h"
/*
* The basic idea of patience diff is to find lines that are unique in
@@ -69,7 +67,7 @@
*/
unsigned anchor : 1;
} *entries, *first, *last;
- // were common records found?
+ /* were common records found? */
unsigned long has_matches;
mmfile_t *file1, *file2;
xdfenv_t *env;
@@ -78,21 +76,21 @@
static int is_anchor(xpparam_t const *xpp, const char *line)
{
- size_t i;
- for (i = 0; i < xpp->anchors_nr; i++) {
+ int i;
+ for (i = 0; i < (int)xpp->anchors_nr; i++) {
if (!strncmp(line, xpp->anchors[i], strlen(xpp->anchors[i])))
return 1;
}
return 0;
}
-// The argument "pass" is 1 for the first file, 2 for the second.
+/* The argument "pass" is 1 for the first file, 2 for the second. */
static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map,
int pass)
{
xrecord_t **records = pass == 1 ?
map->env->xdf1.recs : map->env->xdf2.recs;
- xrecord_t *record = records[line - 1], *other;
+ xrecord_t *record = records[line - 1];
/*
* After xdl_prepare_env() (or more precisely, due to
* xdl_classify_record()), the "ha" member of the records (AKA lines)
@@ -106,11 +104,7 @@
int index = (int)((record->ha << 1) % map->alloc);
while (map->entries[index].line1) {
- other = map->env->xdf1.recs[map->entries[index].line1 - 1];
- if (map->entries[index].hash != record->ha ||
- !xdl_recmatch(record->ptr, record->size,
- other->ptr, other->size,
- map->xpp->flags)) {
+ if (map->entries[index].hash != record->ha) {
if (++index >= map->alloc)
index = 0;
continue;
@@ -155,7 +149,7 @@
result->xpp = xpp;
result->env = env;
- // We know exactly how large we want the hash map
+ /* We know exactly how large we want the hash map */
result->alloc = count1 * 2;
result->entries = (struct entry *)
xdl_malloc(result->alloc * sizeof(struct entry));
@@ -163,11 +157,11 @@
return -1;
memset(result->entries, 0, result->alloc * sizeof(struct entry));
- // First, fill with entries from the first file
+ /* First, fill with entries from the first file */
while (count1--)
insert_record(xpp, line1++, result, 1);
- // Then search for matches in the second file
+ /* Then search for matches in the second file */
while (count2--)
insert_record(xpp, line2++, result, 2);
@@ -185,13 +179,13 @@
while (left + 1 < right) {
int middle = left + (right - left) / 2;
- // by construction, no two entries can be equal
+ /* by construction, no two entries can be equal */
if (sequence[middle]->line2 > entry->line2)
right = middle;
else
left = middle;
}
- // return the index in "sequence", _not_ the sequence length
+ /* return the index in "sequence", _not_ the sequence length */
return left;
}
@@ -206,9 +200,10 @@
*/
static struct entry *find_longest_common_sequence(struct hashmap *map)
{
- struct entry **sequence = (struct entry **)xdl_malloc(map->nr * sizeof(struct entry *));
+ struct entry **sequence = xdl_malloc(map->nr * sizeof(struct entry *));
int longest = 0, i;
struct entry *entry;
+
/*
* If not -1, this entry in sequence must never be overridden.
* Therefore, overriding entries before this has no effect, so
@@ -237,13 +232,13 @@
}
}
- // No common unique lines were found
+ /* No common unique lines were found */
if (!longest) {
xdl_free(sequence);
return NULL;
}
- // Iterate starting at the last element, adjusting the "next" members
+ /* Iterate starting at the last element, adjusting the "next" members */
entry = sequence[longest - 1];
entry->next = NULL;
while (entry->previous) {
@@ -258,8 +253,7 @@
{
xrecord_t *record1 = map->env->xdf1.recs[line1 - 1];
xrecord_t *record2 = map->env->xdf2.recs[line2 - 1];
- return xdl_recmatch(record1->ptr, record1->size,
- record2->ptr, record2->size, map->xpp->flags);
+ return record1->ha == record2->ha;
}
static int patience_diff(mmfile_t *file1, mmfile_t *file2,
@@ -273,7 +267,7 @@
int next1, next2;
for (;;) {
- // Try to grow the line ranges of common lines
+ /* Try to grow the line ranges of common lines */
if (first) {
next1 = first->line1;
next2 = first->line2;
@@ -292,11 +286,8 @@
line2++;
}
- // Recurse
+ /* Recurse */
if (next1 > line1 || next2 > line2) {
- struct hashmap submap;
-
- memset(&submap, 0, sizeof(submap));
if (patience_diff(map->file1, map->file2,
map->xpp, map->env,
line1, next1 - line1,
@@ -323,6 +314,8 @@
int line1, int count1, int line2, int count2)
{
xpparam_t xpp;
+
+ memset(&xpp, 0, sizeof(xpp));
xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK;
return xdl_fall_back_diff(map->env, &xpp,
@@ -343,7 +336,7 @@
struct entry *first;
int result = 0;
- // trivial case: one side is empty
+ /* trivial case: one side is empty */
if (!count1) {
while(count2--)
env->xdf2.rchg[line2++ - 1] = 1;
@@ -359,7 +352,7 @@
line1, count1, line2, count2))
return -1;
- // are there any matching lines at all?
+ /* are there any matching lines at all? */
if (!map.has_matches) {
while(count1--)
env->xdf1.rchg[line1++ - 1] = 1;
@@ -387,7 +380,7 @@
if (xdl_prepare_env(file1, file2, xpp, env) < 0)
return -1;
- // environment is cleaned up in xdl_diff()
+ /* environment is cleaned up in xdl_diff() */
return patience_diff(file1, file2, xpp, env,
1, env->xdf1.nrec, 1, env->xdf2.nrec);
}