← 输入框|github.com|刷新
Skip to content

Fuzzy patching does not account for earlier changes in line count #237

Closed

Description

@PHJ2000

applyFuzzy(source, 0) can fail on the unchanged source after an earlier change reduces the line count:

import com.github.difflib.DiffUtils;
import com.github.difflib.patch.Patch;
import java.util.Arrays;
import java.util.List;
public class Reproduce {
 public static void main(String[] args) throws Exception {
  List<String> source=Arrays.asList("a","b","c","d","e");
  List<String> target=Arrays.asList("x","d","y");
  Patch<String> patch=DiffUtils.diff(source,target);
  System.out.println(patch.getDeltas());
  System.out.println("exact="+patch.applyTo(source));
  System.out.println("fuzzy="+patch.applyFuzzy(source,0));
 }
}

applyTo returns [x, d, y]. applyFuzzy throws IndexOutOfBoundsException with 4.17 and PatchFailedException with current master instead of returning the same result.

An expanding earlier change can also cause a later delta to modify a newly inserted matching line. lastPatchDelta only records the found position; it needs to include the difference between the target and source chunk sizes as well.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions