Skip to content

Need to get exact changed lines when using UnifiedDiffUtils.parseUnifiedDiff #89

@HuGanghui

Description

@HuGanghui

Describe the bug
A clear and concise description of what the bug is.

This is not bug, but a improvement issue. we need to get exact changed lines when using UnifiedDiffUtils.parseUnifiedDiff in current version we will get a Patch<String>

public static Patch<String> parseUnifiedDiff(List<String> diff) {

In Patch<String>, the core is the structure Chunk<T>

patch.addDelta(new ChangeDelta<>(new Chunk<>(
old_ln - 1, oldChunkLines), new Chunk<>(
new_ln - 1, newChunkLines)));

but now the information that we can use only the position and lines

private final int position;
private List<T> lines;

and in the lines, we can't tell the difference between no changed lines and changed lines, because we do not do this work when we get the lines:

private static void processLinesInPrevChunk(List<String[]> rawChunk, Patch<String> patch, int old_ln, int new_ln) {
String tag;
String rest;
if (!rawChunk.isEmpty()) {
List<String> oldChunkLines = new ArrayList<>();
List<String> newChunkLines = new ArrayList<>();
for (String[] raw_line : rawChunk) {
tag = raw_line[0];
rest = raw_line[1];
if (" ".equals(tag) || "-".equals(tag)) {
oldChunkLines.add(rest);
}
if (" ".equals(tag) || "+".equals(tag)) {
newChunkLines.add(rest);
}
}
patch.addDelta(new ChangeDelta<>(new Chunk<>(
old_ln - 1, oldChunkLines), new Chunk<>(
new_ln - 1, newChunkLines)));
rawChunk.clear();
}
}

we do not make full use of tag, actually we can:

To Reproduce
Steps to reproduce the behavior:

  1. Example data
  2. simple programm snippet
  3. See error

no reproduce, this is improvement issue.

Expected behavior
A clear and concise description of what you expected to happen.

System

  • Java version
  • Version [e.g. 22]

latest master branch in Github.

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