summaryrefslogtreecommitdiffstats
path: root/Differ.java
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2025-01-31 15:07:11 +0100
committerHarald Eilertsen <haraldei@anduin.net>2025-01-31 15:07:11 +0100
commitabb07a83833e4933cf660cc67788d6df6a8658b5 (patch)
treec52b69875d1586d63671fbfa255dae75021eab83 /Differ.java
downloaddiffer-main.tar.gz
differ-main.tar.bz2
differ-main.zip
Create Differ – a simple tool for diffing branchesmain
Written mostly to help me manage the diff between various branches in the OpenJDK repos and the BSD port repos. The idea is to simply filter out files I don't need to spend time on, while allowing me to easily inspect those that need it.
Diffstat (limited to 'Differ.java')
-rw-r--r--Differ.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/Differ.java b/Differ.java
new file mode 100644
index 0000000..b53f7fe
--- /dev/null
+++ b/Differ.java
@@ -0,0 +1,68 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 The FreeBSD Foundation
+ *
+ * This software was developed by Eilertsens Kodeknekkeri <haraldei@anduin.net>
+ * under sponsorship from The FreeBSD Foundation.
+ */
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+public class Differ
+{
+ private String commit;
+
+ public static void main(String[] args)
+ {
+ var differ = new Differ(args);
+ differ.run();
+ }
+
+ public Differ(String[] args)
+ {
+ commit = args[0];
+ }
+
+ public void run()
+ {
+ try {
+ String[] cmd = {"git", "diff", "--stat", "--name-only", commit};
+ var p = Runtime.getRuntime().exec(cmd);
+
+ p.inputReader()
+ .lines()
+ .filter(filename -> { return includeDiff(filename); })
+ .forEach(filename -> { System.out.println("[ ] " + filename); });
+ } catch (IOException e) {
+ System.err.println("That didn't work: " + e);
+ }
+ }
+
+ private boolean includeDiff(String filename)
+ {
+ try {
+ String[] cmd = {"git", "diff", commit, "--", filename};
+ // System.out.println("[*] Running `" + String.join(" ", cmd) + "`...");
+ var p = Runtime.getRuntime().exec(cmd);
+
+ return p.inputReader()
+ .lines()
+ .anyMatch(line -> { return interestingLine(line); });
+
+ } catch (IOException e) {
+ System.err.println("Could not fetch diff: " + e);
+ return false;
+ }
+ }
+
+ private boolean interestingLine(String line)
+ {
+ var interesting = line.matches("^[+-][^+-].*") && ! line.matches("^.*Copyright.*");
+
+ // System.out.println((interesting ? "! " : " ") + line);
+
+ return interesting;
+ }
+}