Exemplo n.º 1
0
 /**
  * @param changelog
  * @return
  * @throws IOException
  * @throws SAXException
  */
 private HashMap<String, Path> createPathMap(final String changelog)
     throws IOException, SAXException {
   final HashMap<String, Path> pathMap = new HashMap<String, Path>();
   final Collection<Path> changeSet = createChangeSet(changelog).getPaths();
   for (final Path path : changeSet) {
     pathMap.put(path.getPath(), path);
   }
   return pathMap;
 }
Exemplo n.º 2
0
 /**
  * Creates a link to the file. https://[Gitorious
  * URL]/blobs/a9182a07750c9a0dfd89a8461adf72ef5ef0885b/pom.xml
  *
  * @param path
  * @return file link
  * @throws IOException
  */
 @Override
 public URL getFileLink(Path path) throws IOException {
   if (path.getEditType().equals(EditType.DELETE)) {
     return getDiffLink(path);
   } else {
     final String spec = "blobs/" + path.getChangeSet().getId() + "/" + path.getPath();
     return new URL(url, url.getPath() + spec);
   }
 }
Exemplo n.º 3
0
 /**
  * Creates a link to the commit diff.
  *
  * <p>https://[Gitorious
  * URL]/commit/a9182a07750c9a0dfd89a8461adf72ef5ef0885b/diffs?diffmode=sidebyside&fragment=1#[path
  * to file]
  *
  * @param path
  * @return diff link
  * @throws IOException
  */
 @Override
 public URL getDiffLink(Path path) throws IOException {
   final GitChangeSet changeSet = path.getChangeSet();
   return new URL(
       url,
       "commit/"
           + changeSet.getId().toString()
           + "/diffs?diffmode=sidebyside&fragment=1#"
           + path.getPath());
 }
Exemplo n.º 4
0
 /**
  * Creates a link to the file. http://[GitWeb URL]?a=blob;f=[path];h=[dst, or src for deleted
  * files];hb=[commit]
  *
  * @param path file
  * @return file link
  * @throws IOException
  */
 @Override
 public URL getFileLink(Path path) throws IOException {
   String h = (path.getDst() != null) ? path.getDst() : path.getSrc();
   String spec =
       param()
           .add("a=blob")
           .add("f=" + path.getPath())
           .add("h=" + h)
           .add("hb=" + path.getChangeSet().getId())
           .toString();
   return new URL(url, url.getPath() + spec);
 }
Exemplo n.º 5
0
 /**
  * Creates a link to the file diff. http://[GitWeb
  * URL]?a=blobdiff;f=[path];fp=[path];h=[dst];hp=[src];hb=[commit];hpb=[parent commit]
  *
  * @param path affected file path
  * @return diff link
  * @throws IOException
  */
 @Override
 public URL getDiffLink(Path path) throws IOException {
   if (path.getEditType() != EditType.EDIT
       || path.getSrc() == null
       || path.getDst() == null
       || path.getChangeSet().getParentCommit() == null) {
     return null;
   }
   GitChangeSet changeSet = path.getChangeSet();
   String spec =
       param()
           .add("a=blobdiff")
           .add("f=" + path.getPath())
           .add("fp=" + path.getPath())
           .add("h=" + path.getSrc())
           .add("hp=" + path.getDst())
           .add("hb=" + changeSet.getId())
           .add("hpb=" + changeSet.getParentCommit())
           .toString();
   return new URL(url, url.getPath() + spec);
 }
  public void testChangeSet() {
    ArrayList<String> lines = new ArrayList<String>();
    lines.add("Some header junk we should ignore...");
    lines.add("header line 2");
    lines.add("commit 123abc456def");
    lines.add("tree 789ghi012jkl");
    lines.add("parent 345mno678pqr");
    lines.add("author John Author <*****@*****.**> 1234567 -0600");
    lines.add("commiter John Committer <*****@*****.**> 1234567 -0600");
    lines.add("");
    lines.add("    Commit title.");
    lines.add("    Commit extended description.");
    lines.add("");
    lines.add(
        ":000000 123456 0000000000000000000000000000000000000000 123abc456def789abc012def345abc678def901a A\tsrc/test/add.file");
    lines.add(
        ":123456 000000 123abc456def789abc012def345abc678def901a 0000000000000000000000000000000000000000 D\tsrc/test/deleted.file");
    lines.add(
        ":123456 789012 123abc456def789abc012def345abc678def901a bc234def567abc890def123abc456def789abc01 M\tsrc/test/modified.file");
    lines.add(
        ":123456 789012 123abc456def789abc012def345abc678def901a bc234def567abc890def123abc456def789abc01 R012\tsrc/test/renamedFrom.file\tsrc/test/renamedTo.file");
    GitChangeSet changeSet = new GitChangeSet(lines);

    Assert.assertEquals("123abc456def", changeSet.getId());
    Assert.assertEquals("Commit title.", changeSet.getMsg());
    Assert.assertEquals("Commit title.\nCommit extended description.\n", changeSet.getComment());
    HashSet<String> expectedAffectedPaths = new HashSet<String>(7);
    expectedAffectedPaths.add("src/test/add.file");
    expectedAffectedPaths.add("src/test/deleted.file");
    expectedAffectedPaths.add("src/test/modified.file");
    expectedAffectedPaths.add("src/test/renamedFrom.file\tsrc/test/renamedTo.file");
    Assert.assertEquals(expectedAffectedPaths, changeSet.getAffectedPaths());

    Collection<Path> actualPaths = changeSet.getPaths();
    Assert.assertEquals(4, actualPaths.size());
    for (Path path : actualPaths) {
      if ("src/test/add.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.ADD, path.getEditType());
        Assert.assertNull(path.getSrc());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getDst());
      } else if ("src/test/deleted.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.DELETE, path.getEditType());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getSrc());
        Assert.assertNull(path.getDst());
      } else if ("src/test/modified.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.EDIT, path.getEditType());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getSrc());
        Assert.assertEquals("bc234def567abc890def123abc456def789abc01", path.getDst());
      } else if ("src/test/renamedFrom.file\tsrc/test/renamedTo.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.EDIT, path.getEditType());
        Assert.assertNull(path.getSrc());
        Assert.assertNull(path.getDst());
      } else {
        Assert.fail("Unrecognized path.");
      }
    }
  }