@Override public List<CommitDB> getCommits() { try { Iterable<RevCommit> revCommits; revCommits = git.log().all().call(); List<CommitDB> commits = new ArrayList<CommitDB>(); for (RevCommit revCommit : revCommits) { PersonIdent author = revCommit.getAuthorIdent(); CommitDB commit = new CommitDB(0, author.getWhen(), revCommit.getFullMessage(), revCommit.getName()); CommitterDB committerDb = new CommitterDB(0, author.getEmailAddress(), author.getName()); commit.setCommitter(committerDb); commits.add(commit); } return commits; } catch (GitAPIException e) { throw new VisMinerAPIException(e.getMessage(), e); } catch (IOException e) { throw new VisMinerAPIException(e.getMessage(), e); } }
@Override public List<FileDB> getCommitedFiles(CommitDB commitDb) { commands.set(5, commitDb.getName()); processBuilder.command(commands); Process process = null; try { process = processBuilder.start(); BufferedReader buffer = new BufferedReader(new InputStreamReader(process.getInputStream())); String str = null; List<FileDB> files = new ArrayList<FileDB>(); buffer.readLine(); // skips the first line while ((str = buffer.readLine()) != null) { String parts[] = str.split( "\t"); // parts[0] - lines added, parts[1] - lines removed, parts[2] - file path int linesAdded = -1; int linesRemoved = -1; String path = repositoryPath + "/" + parts[2]; if (!parts[0].equals("-")) { linesAdded = Integer.parseInt(parts[0]); } if (!parts[1].equals("-")) { linesRemoved = Integer.parseInt(parts[1]); } FileDB fileDb = new FileDB(0, path, StringUtils.sha1(path)); FileXCommitDB fileXCommit = new FileXCommitDB( new FileXCommitPK(0, commitDb.getId()), linesAdded, linesRemoved, false); if (getData(commitDb.getName(), parts[2]) == null) { fileXCommit.setRemoved(true); } List<FileXCommitDB> filesXCommits = new ArrayList<FileXCommitDB>(1); filesXCommits.add(fileXCommit); fileDb.setFileXCommits(filesXCommits); files.add(fileDb); } buffer.close(); return files; } catch (IOException e) { throw new VisMinerAPIException(e.getMessage(), e); } }