From 241ea8e0d1e96a263aaca390dc4c0fd5c23fcbe8 Mon Sep 17 00:00:00 2001 From: Tobias Grothe Date: Wed, 6 Nov 2024 14:40:05 +0100 Subject: [PATCH] Update 6 (minor fixes) --- src/main/java/Main.java | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 9dc64e1..8b8b2d8 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -32,20 +32,18 @@ private static void linearize1(File repo, String main) throws IOException, Inter for (int i = 0; i < branches.size(); i++) { String b1 = branches.get(i); for (int j = i + 1; j < branches.size(); j++) { - if (i != j) { - String b2 = branches.get(j); - System.out.printf("Check %s and %s.%n", b1, b2); - boolean a = - "0".equals(exec(false, repo, "git", "merge-base", "--is-ancestor", b1, b2).get(0)); - if (a) { - ancestorMap.put(new AbstractMap.SimpleEntry<>(b1, b2), true); - ancestorMap.put(new AbstractMap.SimpleEntry<>(b2, b1), false); - } else { - boolean b = - "0".equals(exec(false, repo, "git", "merge-base", "--is-ancestor", b2, b1).get(0)); - ancestorMap.put(new AbstractMap.SimpleEntry<>(b1, b2), false); - ancestorMap.put(new AbstractMap.SimpleEntry<>(b2, b1), b); - } + String b2 = branches.get(j); + System.out.printf("Check %s and %s.%n", b1, b2); + boolean a = + "0".equals(exec(false, repo, "git", "merge-base", "--is-ancestor", b1, b2).get(0)); + if (a) { + ancestorMap.put(new AbstractMap.SimpleEntry<>(b1, b2), true); + ancestorMap.put(new AbstractMap.SimpleEntry<>(b2, b1), false); + } else { + boolean b = + "0".equals(exec(false, repo, "git", "merge-base", "--is-ancestor", b2, b1).get(0)); + ancestorMap.put(new AbstractMap.SimpleEntry<>(b1, b2), false); + ancestorMap.put(new AbstractMap.SimpleEntry<>(b2, b1), b); } } } @@ -152,9 +150,16 @@ private static void linearize2( } } + private static final boolean shouldCmdWrappedToBash = true; + private static List exec(boolean exitIfNoSuccess, File wd, String... cmd) throws IOException, InterruptedException { - String[] newCmd = {"bash", "-c", String.join(" ", cmd)}; + String[] newCmd; + if (shouldCmdWrappedToBash) { + newCmd = new String[] {"bash", "-c", String.join(" ", cmd)}; + } else { + newCmd = cmd; + } ProcessBuilder builder = new ProcessBuilder(newCmd); builder.directory(wd); builder.redirectErrorStream(true);