@Ignore("No unit test, depends on state of git repo") @Test public void testFindCommits () throws IOException { JGitScanner jGitScanner = new JGitScanner("../.git", null); List<GitCommit> commits = jGitScanner.findCommits (); assertThat (commits.size(), greaterThan (0)); }
List<GitCommit> findCommits() throws IOException { Repository repository = getRepository(); List<GitCommit> result = new LinkedList<>(); ObjectId head = repository.resolve("HEAD"); logger.debug("Found head: {}", head); RevWalk rw = new RevWalk(repository); try (Git git = new Git(repository)) { LogCommand logCommand = getLogWithOrWithOutRange(git, range); Iterable<RevCommit> commits = logCommand.call(); DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE); df.setRepository(repository); df.setDiffComparator(RawTextComparator.DEFAULT); df.setDetectRenames(true); for (RevCommit commit : commits) { logger.debug("Commit-Message: '{}'", commit.getShortMessage()); final Date date = new Date(1000 * (long) commit.getCommitTime()); final GitCommit gitCommit = retrieveCommit(ObjectId.toString(commit.getId())); gitCommit.setAuthor(makeStringOfIdent(commit.getAuthorIdent())); gitCommit.setCommitter(makeStringOfIdent(commit.getCommitterIdent())); gitCommit.setDate(date); gitCommit.setMessage(commit.getFullMessage()); gitCommit.setShortMessage(commit.getShortMessage()); gitCommit.setEncoding(commit.getEncodingName()); addCommitParents(rw, df, commit, gitCommit); result.add(gitCommit); } } catch (GitAPIException e) { throw new IllegalStateException("Could not read logs from Git repository '" + path + "'", e); } finally { rw.close(); repository.close(); } logger.debug("Found #{} commits", result.size()); return result; }
JGitScanner { List<GitCommit> findCommits() throws IOException { Repository repository = getRepository(); List<GitCommit> result = new LinkedList<>(); ObjectId head = repository.resolve("HEAD"); logger.debug("Found head: {}", head); RevWalk rw = new RevWalk(repository); try (Git git = new Git(repository)) { LogCommand logCommand = getLogWithOrWithOutRange(git, range); Iterable<RevCommit> commits = logCommand.call(); DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE); df.setRepository(repository); df.setDiffComparator(RawTextComparator.DEFAULT); df.setDetectRenames(true); for (RevCommit commit : commits) { logger.debug("Commit-Message: '{}'", commit.getShortMessage()); final Date date = new Date(1000 * (long) commit.getCommitTime()); final GitCommit gitCommit = retrieveCommit(ObjectId.toString(commit.getId())); gitCommit.setAuthor(makeStringOfIdent(commit.getAuthorIdent())); gitCommit.setCommitter(makeStringOfIdent(commit.getCommitterIdent())); gitCommit.setDate(date); gitCommit.setMessage(commit.getFullMessage()); gitCommit.setShortMessage(commit.getShortMessage()); gitCommit.setEncoding(commit.getEncodingName()); addCommitParents(rw, df, commit, gitCommit); result.add(gitCommit); } } catch (GitAPIException e) { throw new IllegalStateException("Could not read logs from Git repository '" + path + "'", e); } finally { rw.close(); repository.close(); } logger.debug("Found #{} commits", result.size()); return result; } }
JGitScanner { List<GitCommit> findCommits() throws IOException { Repository repository = getRepository(); List<GitCommit> result = new LinkedList<>(); ObjectId head = repository.resolve("HEAD"); logger.debug("Found head: {}", head); RevWalk rw = new RevWalk(repository); try (Git git = new Git(repository)) { LogCommand logCommand = getLogWithOrWithOutRange(git, range); Iterable<RevCommit> commits = logCommand.call(); DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE); df.setRepository(repository); df.setDiffComparator(RawTextComparator.DEFAULT); df.setDetectRenames(true); for (RevCommit commit : commits) { logger.debug("Commit-Message: '{}'", commit.getShortMessage()); final Date date = new Date(1000 * (long) commit.getCommitTime()); final GitCommit gitCommit = retrieveCommit(ObjectId.toString(commit.getId())); gitCommit.setAuthor(makeStringOfIdent(commit.getAuthorIdent())); gitCommit.setCommitter(makeStringOfIdent(commit.getCommitterIdent())); gitCommit.setDate(date); gitCommit.setMessage(commit.getFullMessage()); gitCommit.setShortMessage(commit.getShortMessage()); gitCommit.setEncoding(commit.getEncodingName()); addCommitParents(rw, df, commit, gitCommit); result.add(gitCommit); } } catch (GitAPIException e) { throw new IllegalStateException("Could not read logs from Git repository '" + path + "'", e); } finally { rw.close(); repository.close(); } logger.debug("Found #{} commits", result.size()); return result; } JGitScanner(final String path, String range); }
JGitScanner { List<GitCommit> findCommits() throws IOException { Repository repository = getRepository(); List<GitCommit> result = new LinkedList<>(); ObjectId head = repository.resolve("HEAD"); logger.debug("Found head: {}", head); RevWalk rw = new RevWalk(repository); try (Git git = new Git(repository)) { LogCommand logCommand = getLogWithOrWithOutRange(git, range); Iterable<RevCommit> commits = logCommand.call(); DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE); df.setRepository(repository); df.setDiffComparator(RawTextComparator.DEFAULT); df.setDetectRenames(true); for (RevCommit commit : commits) { logger.debug("Commit-Message: '{}'", commit.getShortMessage()); final Date date = new Date(1000 * (long) commit.getCommitTime()); final GitCommit gitCommit = retrieveCommit(ObjectId.toString(commit.getId())); gitCommit.setAuthor(makeStringOfIdent(commit.getAuthorIdent())); gitCommit.setCommitter(makeStringOfIdent(commit.getCommitterIdent())); gitCommit.setDate(date); gitCommit.setMessage(commit.getFullMessage()); gitCommit.setShortMessage(commit.getShortMessage()); gitCommit.setEncoding(commit.getEncodingName()); addCommitParents(rw, df, commit, gitCommit); result.add(gitCommit); } } catch (GitAPIException e) { throw new IllegalStateException("Could not read logs from Git repository '" + path + "'", e); } finally { rw.close(); repository.close(); } logger.debug("Found #{} commits", result.size()); return result; } JGitScanner(final String path, String range); static void main(String[] args); }
JGitScanner { List<GitCommit> findCommits() throws IOException { Repository repository = getRepository(); List<GitCommit> result = new LinkedList<>(); ObjectId head = repository.resolve("HEAD"); logger.debug("Found head: {}", head); RevWalk rw = new RevWalk(repository); try (Git git = new Git(repository)) { LogCommand logCommand = getLogWithOrWithOutRange(git, range); Iterable<RevCommit> commits = logCommand.call(); DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE); df.setRepository(repository); df.setDiffComparator(RawTextComparator.DEFAULT); df.setDetectRenames(true); for (RevCommit commit : commits) { logger.debug("Commit-Message: '{}'", commit.getShortMessage()); final Date date = new Date(1000 * (long) commit.getCommitTime()); final GitCommit gitCommit = retrieveCommit(ObjectId.toString(commit.getId())); gitCommit.setAuthor(makeStringOfIdent(commit.getAuthorIdent())); gitCommit.setCommitter(makeStringOfIdent(commit.getCommitterIdent())); gitCommit.setDate(date); gitCommit.setMessage(commit.getFullMessage()); gitCommit.setShortMessage(commit.getShortMessage()); gitCommit.setEncoding(commit.getEncodingName()); addCommitParents(rw, df, commit, gitCommit); result.add(gitCommit); } } catch (GitAPIException e) { throw new IllegalStateException("Could not read logs from Git repository '" + path + "'", e); } finally { rw.close(); repository.close(); } logger.debug("Found #{} commits", result.size()); return result; } JGitScanner(final String path, String range); static void main(String[] args);  }