Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

subversion/diff

Raw
#!/usr/bin/java --source 23 -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xms32m -Xmx32m -XX:+AlwaysPreTouch -Xshare:on

import static java.lang.System.* ;
import java.util.*;

class diff {
  public static void main(String[] command_line_arguments) throws Throwable
  {
    if(command_line_arguments.length != 7)
      throw fail("svn diff was supposed to give us 7 arguments. did the interface change? we got %s arguments.", command_line_arguments.length);

    //some old gnudiff flag, which newer tools ignore
    var ignored_unified_flag = command_line_arguments[0];

    if(!ignored_unified_flag.equals("-u"))
      throw fail("the first argument should be the `-u` flag, which will be ignored, but was %s.", ignored_unified_flag);

    var left_label_flag = command_line_arguments[1];
    var left_label = command_line_arguments[2];
    var right_label_flag = command_line_arguments[3];
    var right_label = command_line_arguments[4];

    if(!(left_label_flag.equals("-L") && right_label_flag.equals("-L")))
      throw fail("flags for the labes should have been `-L`, but were %s and %s.", left_label_flag, right_label_flag);

    var left_file = command_line_arguments[5];
    var right_file = command_line_arguments[6];

    var code = call("difft", "--display", "inline", "--tab-width", "2", right_file, left_file);
    throw exit(code);
  }

  static int call( String... command) throws Exception
  {
    return new ProcessBuilder()
    .command(command)
    .inheritIO()
    .start()
    .onExit()
    .join()
    .exitValue();
  }

  static Throwable exit(int code) {
    System.exit(code);
    //abuse control flow to make compiler realize `exit` will never return
    return new Throwable(); 
  }

  static String emphasize_global(String message) {
    return "\033[4m" + message + "\033[0m";
  }

  static String emphasize_local(String message) {
    return "\033[3m" + message + "\033[0m";
  }

  static Throwable fail(String message, Object... arguments) {
    out.printf(message, arguments);
    System.exit(1);
    //abuse control flow to make compiler realize `exit` will never return
    return new Throwable(); 
  }

  static Throwable fail() {
    System.exit(1);
    //abuse control flow to make compiler realize `exit` will never return
    return new Throwable(); 
  }
}
// vim:ft=java