示例#1
0
文件: GitLog.java 项目: krzydyn/java
 private static void usage() {
   Log.debug("debug version");
   System.out.println("Usage is: ");
   System.out.println(
       "java -jar gitsvg.jar [--line-height line-height] [--format fmt] [--svg <file>] [--log <file>] <path-to-repo> <branch-or-commit>");
   System.exit(1);
 }
示例#2
0
文件: GitLog.java 项目: krzydyn/java
  public static void main(String[] args) {
    int dy = 20;
    String fmt = "";
    String cmtfile = null;
    String svgfile = "git.svg";

    int argi = 0;
    for (; argi < args.length; ++argi) {
      if (!args[argi].startsWith("-")) break;
      if (args[argi].equals("--line-height")) {
        ++argi;
        dy = Integer.parseInt(args[argi]);
      } else if (args[argi].equals("--format")) {
        ++argi;
        fmt = args[argi];
      } else if (args[argi].equals("--svg")) {
        ++argi;
        svgfile = args[argi];
      } else if (args[argi].equals("--log")) {
        ++argi;
        cmtfile = args[argi];
      }
    }
    if (args.length < argi + 2) {
      usage();
    }

    String repo_path = args[argi];
    String branch = args[argi + 1];

    GitGraph graph = new GitGraph(new GitRepo(repo_path));
    graph.setUserFormat(fmt, cmtfile == null);
    Svg svg = graph.buildSvg(branch, dy, limit);

    if (cmtfile != null) {
      Log.notice("Writing commits to file '%s'", cmtfile);
      if (cmtfile.equals("-")) {
        try {
          graph.saveCommits(System.out);
        } catch (Exception e) {
          e.printStackTrace();
        }
      } else {
        try (OutputStream os = new FileOutputStream(cmtfile)) {
          graph.saveCommits(os);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      Log.notice("Writing commits done");
    }

    if (svg != null) {
      Log.notice("Writing SVG to file");
      try (OutputStream os = new FileOutputStream(svgfile)) {
        svg.write(os);
      } catch (IOException e) {
        e.printStackTrace();
      }
      Log.notice("Writing SVG done");
    }
  }