From cd674a83c6c9b2afab0e6c4edd1d87f535a8ba95 Mon Sep 17 00:00:00 2001 From: Morten Telling Date: Mon, 3 Aug 2020 16:08:34 +0200 Subject: [PATCH] Mark no file with /dev/null to align with git diff If you run git diff locally with a staged new file the diff will indicate that the file did not exist before with `--- /dev/null`. I believe this should align with this? --- .../src/main/java/com/github/difflib/UnifiedDiffUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java b/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java index 8221bdc6..2098aacf 100644 --- a/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java +++ b/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java @@ -33,6 +33,7 @@ public final class UnifiedDiffUtils { private static final Pattern UNIFIED_DIFF_CHUNK_REGEXP = Pattern .compile("^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@$"); + private static final String NULL_FILE_INDICATOR = "/dev/null"; /** * Parse the given text in unified format and creates the list of deltas for it. @@ -143,8 +144,8 @@ public static List generateUnifiedDiff(String originalFileName, int contextSize) { if (!patch.getDeltas().isEmpty()) { List ret = new ArrayList<>(); - ret.add("--- " + Optional.ofNullable(originalFileName).orElse("")); - ret.add("+++ " + Optional.ofNullable(revisedFileName).orElse("")); + ret.add("--- " + Optional.ofNullable(originalFileName).orElse(NULL_FILE_INDICATOR)); + ret.add("+++ " + Optional.ofNullable(revisedFileName).orElse(NULL_FILE_INDICATOR)); List> patchDeltas = new ArrayList<>( patch.getDeltas());