(Map<String, String> treeFrom, Map<String, String> treeTo)
| 46 | } |
| 47 | |
| 48 | public static String diffTrees(Map<String, String> treeFrom, Map<String, String> treeTo) { |
| 49 | StringBuilder output = new StringBuilder(); |
| 50 | final Map<String, List<String>> pathObjectIds = compareTrees(treeFrom, treeTo); |
| 51 | pathObjectIds.forEach((path, objectIds) -> { |
| 52 | final String from = objectIds.get(0); |
| 53 | final String to = objectIds.get(1); |
| 54 | if (!Objects.equals(from, to)) { |
| 55 | if (from == null) { |
| 56 | output.append(String.format("\ncreated file: %s\n", path)); |
| 57 | final List<LineObject> lineObjects = convertObjectContentToLines(to); |
| 58 | lineObjects.forEach(lineObject -> lineObject.setAction(ConstantVal.PLUS)); |
| 59 | final String diffResult = lineObjects.stream().map(LineObject::toString).collect(Collectors.joining(System.lineSeparator())); |
| 60 | output.append(diffResult); |
| 61 | } else if (to == null) { |
| 62 | output.append(String.format("\ndeleted file: %s\n", path)); |
| 63 | final List<LineObject> lineObjects = convertObjectContentToLines(from); |
| 64 | lineObjects.forEach(lineObject -> lineObject.setAction(ConstantVal.MINUS)); |
| 65 | final String diffResult = lineObjects.stream().map(LineObject::toString).collect(Collectors.joining(System.lineSeparator())); |
| 66 | output.append(diffResult); |
| 67 | } else { |
| 68 | output.append(String.format("\nchange file: %s\n", path)); |
| 69 | final List<LineObject> lineObjects = diffBlobs(from, to); |
| 70 | final String diffResult = lineObjects.stream().map(LineObject::toString).collect(Collectors.joining(System.lineSeparator())); |
| 71 | output.append(diffResult); |
| 72 | } |
| 73 | } |
| 74 | }); |
| 75 | return output.toString(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * https://qqtim.club/2020/06/14/git-myers-diff/ |
no test coverage detected