From 2778bb2cc9bf7bdfb2ed7b3a99dd931d6d3fbbfa Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Thu, 25 Aug 2022 19:37:35 +0200 Subject: [PATCH] WorkTreeUpdater: remove safeWrite option This was added in Ideaefd5178 to anticipate on writing files for ApplyCommand, but we are keeping WorkTreeUpdater private to the merge package for now. Change-Id: Ifa79dac245e60eb7a77eaea4cc1249222e347d38 --- .../org/eclipse/jgit/merge/ResolveMerger.java | 2 +- .../eclipse/jgit/util/WorkTreeUpdater.java | 25 ++----------------- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java index d79f5d4100..f4d19cb79a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java @@ -915,7 +915,7 @@ public class ResolveMerger extends ThreeWayMerger { StreamLoader contentLoader = WorkTreeUpdater.createStreamLoader(rawMerged::openInputStream, rawMerged.length()); workTreeUpdater.updateFileWithContent(contentLoader, - eol, tw.getSmudgeCommand(attributes), of.getPath(), of, false); + eol, tw.getSmudgeCommand(attributes), of.getPath(), of); return of; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/WorkTreeUpdater.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/WorkTreeUpdater.java index e5de2b4a7d..d35efe3e35 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/WorkTreeUpdater.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/WorkTreeUpdater.java @@ -18,8 +18,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; import java.time.Instant; import java.util.HashMap; import java.util.LinkedList; @@ -611,37 +609,18 @@ public class WorkTreeUpdater implements Closeable { * of the file to be updated * @param file * to be updated - * @param safeWrite - * whether the content should be written to a buffer first * @throws IOException * if the file cannot be updated */ public void updateFileWithContent(StreamLoader resultStreamLoader, EolStreamType streamType, String smudgeCommand, String path, - File file, boolean safeWrite) throws IOException { + File file) throws IOException { if (inCore) { return; } CheckoutMetadata metadata = new CheckoutMetadata(streamType, smudgeCommand); - if (safeWrite) { - // Write to a buffer and copy to the file only if everything was - // fine. - TemporaryBuffer buffer = new TemporaryBuffer.LocalFile(null); - try { - try (TemporaryBuffer buf = buffer) { - DirCacheCheckout.getContent(repo, path, metadata, - resultStreamLoader, workingTreeOptions, buf); - } - try (InputStream bufIn = buffer.openInputStream()) { - Files.copy(bufIn, file.toPath(), - StandardCopyOption.REPLACE_EXISTING); - } - } finally { - buffer.destroy(); - } - return; - } + try (OutputStream outputStream = new FileOutputStream(file)) { DirCacheCheckout.getContent(repo, path, metadata, resultStreamLoader, workingTreeOptions, outputStream); -- 2.39.5