From abb07a83833e4933cf660cc67788d6df6a8658b5 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 31 Jan 2025 15:07:11 +0100 Subject: =?UTF-8?q?Create=20Differ=20=E2=80=93=20a=20simple=20tool=20for?= =?UTF-8?q?=20diffing=20branches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Differ.java | 68 +++++++++++++++++++++++++++++++++++++++++++++++ LICENSES/BSD-2-Clause.txt | 9 +++++++ 2 files changed, 77 insertions(+) create mode 100644 Differ.java create mode 100644 LICENSES/BSD-2-Clause.txt 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 + * 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; + } +} diff --git a/LICENSES/BSD-2-Clause.txt b/LICENSES/BSD-2-Clause.txt new file mode 100644 index 0000000..5f662b3 --- /dev/null +++ b/LICENSES/BSD-2-Clause.txt @@ -0,0 +1,9 @@ +Copyright (c) + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- cgit v1.2.3