List of usage examples for org.eclipse.jgit.api Git log
public LogCommand log()
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
@Override public List<ChangeSet> getChangeSets() { Git git = null; try {/*from w w w.java 2 s . co m*/ git = Git.open(new File(path)); List<ChangeSet> allCs = new ArrayList<ChangeSet>(); for (RevCommit r : git.log().all().call()) { String hash = r.getName(); GregorianCalendar date = convertToDate(r); allCs.add(new ChangeSet(hash, date)); } return allCs; } catch (Exception e) { throw new RuntimeException("error in getChangeSets for " + path, e); } finally { if (git != null) git.close(); } }
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
@Override public Commit getCommit(String id) { Git git = null; try {//from w w w .j a va 2 s . c o m git = Git.open(new File(path)); Repository repo = git.getRepository(); Iterable<RevCommit> commits = git.log().add(repo.resolve(id)).call(); Commit theCommit = null; for (RevCommit jgitCommit : commits) { Developer author = new Developer(jgitCommit.getAuthorIdent().getName(), jgitCommit.getAuthorIdent().getEmailAddress()); Developer committer = new Developer(jgitCommit.getCommitterIdent().getName(), jgitCommit.getCommitterIdent().getEmailAddress()); String msg = jgitCommit.getFullMessage().trim(); String hash = jgitCommit.getName().toString(); long epoch = jgitCommit.getCommitTime(); String parent = (jgitCommit.getParentCount() > 0) ? jgitCommit.getParent(0).getName().toString() : ""; GregorianCalendar date = new GregorianCalendar(); date.setTime(new Date(epoch * 1000L)); theCommit = new Commit(hash, author, committer, date, msg, parent); List<DiffEntry> diffsForTheCommit = diffsForTheCommit(repo, jgitCommit); if (diffsForTheCommit.size() > MAX_NUMBER_OF_FILES_IN_A_COMMIT) { log.error("commit " + id + " has more than files than the limit"); throw new RuntimeException("commit " + id + " too big, sorry"); } for (DiffEntry diff : diffsForTheCommit) { ModificationType change = Enum.valueOf(ModificationType.class, diff.getChangeType().toString()); String oldPath = diff.getOldPath(); String newPath = diff.getNewPath(); String diffText = ""; String sc = ""; if (diff.getChangeType() != ChangeType.DELETE) { diffText = getDiffText(repo, diff); sc = getSourceCode(repo, diff); } if (diffText.length() > MAX_SIZE_OF_A_DIFF) { log.error("diff for " + newPath + " too big"); diffText = "-- TOO BIG --"; } theCommit.addModification(oldPath, newPath, change, diffText, sc); } break; } return theCommit; } catch (Exception e) { throw new RuntimeException("error detailing " + id + " in " + path, e); } finally { if (git != null) git.close(); } }
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
@Override public String blame(String file, String currentCommit, Integer line) { Git git = null; try {// w w w. j av a 2 s. c o m git = Git.open(new File(path)); Iterable<RevCommit> commits = git.log().add(git.getRepository().resolve(currentCommit)).call(); ObjectId prior = commits.iterator().next().getParent(0).getId(); BlameResult blameResult = git.blame().setFilePath(file).setStartCommit(prior).setFollowFileRenames(true) .call(); return blameResult.getSourceCommit(line).getId().getName(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (git != null) git.close(); } }
From source file:br.com.riselabs.cotonet.builder.NetworkBuilder.java
License:Open Source License
/** * Returns the conflicting merge scenarios * /*from w w w . j a va2s .co m*/ * @return - a list of merge scenarios. it may be empty in case of no * conflict. * @throws IOException */ private List<MergeScenario> getMergeScenarios() throws IOException { List<MergeScenario> result = new ArrayList<MergeScenario>(); List<RevCommit> mergeCommits = new ArrayList<RevCommit>(); Iterable<RevCommit> gitlog; try { Git git = Git.wrap(getProject().getRepository()); gitlog = git.log().call(); for (RevCommit commit : gitlog) { if (commit.getParentCount() == 2) { mergeCommits.add(commit); // collecting merge commits // we know there is only to parents RevCommit leftParent = commit.getParent(0); RevCommit rightParent = commit.getParent(1); ThreeWayMerger merger = MergeStrategy.RECURSIVE.newMerger(getProject().getRepository(), true); // selecting the conflicting ones boolean noConflicts = false; try { noConflicts = merger.merge(leftParent, rightParent); } catch (NoMergeBaseException e) { StringBuilder sb = new StringBuilder(); sb.append("[" + project.getName() + ":" + project.getUrl() + "] " + "Skipping merge scenario due to '" + e.getMessage() + "'\n"); sb.append("---> Skipped scenario:\n"); sb.append("::Base (<several>): \n"); sb.append("::Left (" + leftParent.getAuthorIdent().getWhen().toString() + "):" + leftParent.getName() + "\n"); sb.append("::Right (" + rightParent.getAuthorIdent().getWhen().toString() + "):" + rightParent.getName() + "\n"); Logger.log(log, sb.toString()); Logger.logStackTrace(log, e); continue; } if (noConflicts) { continue; } RevWalk walk = new RevWalk(getProject().getRepository()); // for merges without a base commit if (merger.getBaseCommitId() == null) continue; RevCommit baseCommit = walk.lookupCommit(merger.getBaseCommitId()); walk.close(); Timestamp mergeDate = new Timestamp(commit.getAuthorIdent().getWhen().getTime()); result.add(new MergeScenario(baseCommit, leftParent, rightParent, commit, mergeDate)); } } } catch (GitAPIException e) { Logger.logStackTrace(log, e); } return result; }
From source file:br.com.riselabs.cotonet.test.helpers.ConflictBasedRepositoryTestCase.java
License:Open Source License
public static void logAllCommits(Repository repo) throws Exception { Git git = Git.wrap(repo); Iterable<RevCommit> commits = git.log().all().call(); for (RevCommit c : commits) { System.out.println("time(s): " + c.getCommitTime() + ", author: " + c.getAuthorIdent().getName()); }//from ww w.j a va2 s. c o m }
From source file:ch.uzh.ifi.seal.permo.history.git.core.model.jgit.JGitRepository.java
License:Apache License
/** * {@inheritDoc}//from w w w . jav a 2s .c om */ @Override public List<Commit> getCommits(final TimePeriod timePeriod) { if (commits == null) { commits = Lists.newArrayList(); try { fetchFromUpstream(); final ObjectId idOfLatestCommit = repository.getRef(JGitUtil.getDefaultRemoteBranch(repository)) .getObjectId(); final Git git = new Git(repository); for (final RevCommit revCommit : git.log().add(idOfLatestCommit).call()) { final LocalDateTime commitTime = DateTimes.ofEpochSeconds(revCommit.getCommitTime()); if (commitTime.isBefore(timePeriod.getStartDateTime())) { break; } else if (!commitTime.isAfter(timePeriod.getEndDateTime())) { commits.add(JGitCommit.of(repository, revCommit)); } } } catch (final IOException | GitAPIException e) { } } return commits; }
From source file:co.bledo.gitmin.servlet.Review.java
License:Apache License
public Response index(Request request) throws Exception { log.entry(request);//from w w w .j a v a2s . co m DateFormat dformat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss"); List<Repo> repos = GitminStorage.getRepos(); Map<String, List<GitListItem>> lists = new HashMap<String, List<GitListItem>>(); for (Repo repo : repos) { Git git = Git.open(new File(GitminConfig.getGitRepositoriesPath() + "/" + repo.name)); Iterable<RevCommit> commits = git.log().setMaxCount(20).call(); List<GitListItem> list = new ArrayList<GitListItem>(); for (RevCommit commit : commits) { log.debug(commit); GitListItem item = new GitListItem(); item.email = commit.getAuthorIdent().getEmailAddress(); item.name = commit.getAuthorIdent().getName(); item.subject = commit.getShortMessage(); item.gravatar = "http://www.gravatar.com/avatar/" + Util.md5(Util.trim(item.email).toLowerCase()) + "?s=40"; item.hash = commit.getName(); item.date = dformat.format(new Date(commit.getCommitTime())); list.add(item); } lists.put(repo.name, list); } VelocityResponse resp = VelocityResponse.newInstance(request, this); resp.assign("lists", lists); return log.exit(resp); }
From source file:com.chungkwong.jgitgui.LogTreeItem.java
License:Open Source License
public LogTreeItem(Git git) throws GitAPIException { super(java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("COMMIT")); try {//from w w w . j a va2 s . c om for (RevCommit rev : git.log().call()) { getChildren().add(new CommitTreeItem(rev)); } } catch (NoHeadException ex) { } }
From source file:com.GitAnalytics.BranchInfo.java
public static List<BranchInfo> getBranches(Git git, List<CommitInfo> allCommits) throws Exception { List<BranchInfo> list = new LinkedList<>(); List<Ref> tags = git.tagList().call(); for (Ref branch : git.branchList().call()) { LinkedList commits = new LinkedList<>(); Set<RevCommit> branchCommits = new HashSet<>(); for (RevCommit commit : git.log().add(branch.getObjectId()).call()) { branchCommits.add(commit);// w ww . j a v a 2 s.c o m } allCommits.stream().filter((commit) -> (branchCommits.contains(commit.getCommit()))) .forEachOrdered((commit) -> { commits.add(commit); }); list.add(new BranchInfo(branch, commits)); } return list; }
From source file:com.google.gct.idea.appengine.synchronization.SampleSyncTaskTest.java
License:Apache License
@Ignore @Test/*from w w w . j a v a 2s .c om*/ public void testSync_singleCommit() throws GitAPIException, IOException, URISyntaxException { // Sync files from mock Git Hub repo to mock local Android sample template repo SampleSyncTask sampleSyncTask = new SampleSyncTask(mockAndroidRepoPath, mockGitHubRepoPath); sampleSyncTask.run(); // Add a file to mock github repo RevCommit commit = addFileToMockGitHubRepo("a.txt", "Adding a.txt"); // Sync files from mock Git Hub repo to mock local Android sample template repo sampleSyncTask.run(); // Check that the last commit in the mock Android repo is the commit made to add a new file Git mockAndroidRepo = Git.open(new File(mockAndroidRepoPath)); Iterable<RevCommit> logs = mockAndroidRepo.log().call(); Assert.assertNotNull(logs); // Check that commits exist boolean hasCommits = false; for (RevCommit aLog : logs) { hasCommits = true; Assert.assertEquals(commit.getCommitTime(), aLog.getCommitTime()); Assert.assertEquals(commit.getFullMessage(), aLog.getFullMessage()); break; } Assert.assertTrue(hasCommits); }