List of usage examples for org.eclipse.jgit.revwalk RevCommit getAuthorIdent
public final PersonIdent getAuthorIdent()
From source file:Node.java
License:Open Source License
public static Node createNode(RevWalk walk, ObjectId id, boolean recur) throws IOException { String key = id.getName();//from w ww .ja v a 2 s .c om RevCommit commit; Node node; if (nodeMap.containsKey(key)) { // commit node was already mapped node = nodeMap.get(key); } else { // create new commit node commit = walk.parseCommit(id); node = new Node(key, commit.getAuthorIdent().getEmailAddress(), commit.getCommitTime(), commit.getFullMessage(), commit.getShortMessage()); node.setBackground(new Color(240, 240, 255)); node.setForeground(new Color(0, 0, 127)); if (recur) { // add parent nodes for (ObjectId parentCommit : commit.getParents()) node.addParent(Node.createNode(walk, parentCommit, recur)); } } return node; }
From source file:am.ik.categolj3.api.git.GitStore.java
License:Apache License
Author author(RevCommit commit) { String name = commit != null ? commit.getAuthorIdent().getName() : ""; Date date = commit != null ? commit.getAuthorIdent().getWhen() : new Date(); OffsetDateTime o = OffsetDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); return new Author(name, o); }
From source file:at.ac.tuwien.inso.subcat.miner.GitMiner.java
License:Open Source License
private void processCommit(Repository repository, RevWalk walk, RevCommit rev, Map<String, ManagedFile> fileCache) throws SQLException, IOException { Identity author = resolveIdentity(rev.getAuthorIdent()); Identity committer = resolveIdentity(rev.getCommitterIdent()); Date date = new java.util.Date((long) rev.getCommitTime() * 1000); String message = rev.getFullMessage(); Map<String, FileStats> fileStats = new HashMap<String, FileStats>(); DiffOutputStream outputStream = new DiffOutputStream(); processDiff(repository, walk, rev, outputStream, fileStats); String revision = rev.getId().getName(); int totalLinesAdded = outputStream.getTotalLinesAdded(); int totalLinesRemoved = outputStream.getTotalLinesRemoved(); int fileCount = fileStats.size(); Commit commit = model.addCommit(revision, project, author, committer, date, message, fileCount, totalLinesAdded, totalLinesRemoved); for (Map.Entry<String, FileStats> item : fileStats.entrySet()) { if (stopped == true) { break; }//www .j av a2s . c o m FileStats stats = item.getValue(); String path = item.getKey(); switch (stats.type) { case COPY: // There is no active copy in git, // use ADD instead. /* ManagedFile originalFile = fileCache.get (stats.oldPath); assert (originalFile != null); ManagedFile copiedFile = model.addManagedFile (project, path); model.addFileChange (commit, copiedFile, stats.linesAdded, stats.linesRemoved, stats.emptyLinesAdded, stats.emptyLinesRemoved, stats.chunks); model.addIsCopy (copiedFile, commit, originalFile); fileCache.put (path, copiedFile); break; */ case ADD: ManagedFile addedFile = model.addManagedFile(project, path); model.addFileChange(commit, addedFile, stats.linesAdded, stats.linesRemoved, stats.emptyLinesAdded, stats.emptyLinesRemoved, stats.chunks); fileCache.put(path, addedFile); break; case DELETE: ManagedFile deletedFile = fileCache.get(path); // Merge handling if (deletedFile != null) { model.addFileDeletion(deletedFile, commit); fileCache.remove(stats.oldPath); } break; case MODIFY: ManagedFile modifiedFile = fileCache.get(path); assert (modifiedFile != null); model.addFileChange(commit, modifiedFile, stats.linesAdded, stats.linesRemoved, stats.emptyLinesAdded, stats.emptyLinesRemoved, stats.chunks); break; case RENAME: ManagedFile renamedFile = fileCache.get(stats.oldPath); // E.g. on merges after a rename. if (renamedFile != null) { model.addFileRename(renamedFile, commit, stats.oldPath, path); fileCache.put(path, renamedFile); } break; default: assert (false); } } emitTasksProcessed(1); }
From source file:boa.datagen.scm.GitConnector.java
License:Apache License
@Override protected void setRevisions() { try {//from w ww. ja v a 2s . c o m revwalk.reset(); revwalk.markStart(revwalk.parseCommit(repository.resolve(Constants.HEAD))); revwalk.sort(RevSort.TOPO, true); revwalk.sort(RevSort.COMMIT_TIME_DESC, true); revwalk.sort(RevSort.REVERSE, true); revisions.clear(); revisionMap = new HashMap<String, Integer>(); for (final RevCommit rc : revwalk) { final GitCommit gc = new GitCommit(repository, this); gc.setId(rc.getName()); gc.setAuthor(rc.getAuthorIdent().getName()); gc.setCommitter(rc.getCommitterIdent().getName()); gc.setDate(new Date(((long) rc.getCommitTime()) * 1000)); gc.setMessage(rc.getFullMessage()); gc.getChangeFiles(this.revisionMap, rc); revisionMap.put(gc.id, revisions.size()); revisions.add(gc); } } catch (final IOException e) { if (debug) System.err.println("Git Error getting parsing HEAD commit for " + path + ". " + e.getMessage()); } }
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
@Override public Commit getCommit(String id) { Git git = null;/*from w w w. j a v a 2s . c o m*/ try { 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.riselabs.cotonet.builder.NetworkBuilder.java
License:Open Source License
/** * Returns the conflicting merge scenarios * /* ww w . j ava 2s .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);//ww w. jav a2 s . c o m Iterable<RevCommit> commits = git.log().all().call(); for (RevCommit c : commits) { System.out.println("time(s): " + c.getCommitTime() + ", author: " + c.getAuthorIdent().getName()); } }
From source file:br.com.riselabs.cotonet.util.CodefaceHelper.java
License:Open Source License
/** * Returns a commit from the given repository dated {@code i} months * earlier.//from ww w . jav a2s .co m * * @param repo * @param refCommit * @param i * @return * @throws IOException * @throws IncorrectObjectTypeException * @throws MissingObjectException */ private static RevCommit getEarlierCommit(Repository repo, String refCommit, int i) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevCommit result = null; try (RevWalk rw = new RevWalk(repo)) { ObjectId refID = ObjectId.fromString(refCommit); RevCommit base = rw.parseCommit(refID); rw.markStart(base); Date baseDate = base.getAuthorIdent().getWhen(); Instant instant = baseDate.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); LocalDate reference = zdt.toLocalDate(); RevCommit aux; while ((aux = rw.next()) != null) { Date resultDate = aux.getAuthorIdent().getWhen(); instant = resultDate.toInstant(); zdt = instant.atZone(ZoneId.systemDefault()); LocalDate imonths = zdt.toLocalDate(); long days = ChronoUnit.DAYS.between(imonths, reference); if ((days % 30) > i) { return aux; } else { // in case it reaches the beginning of the tree returns the // last commit result = aux; } } rw.close(); } return result; }
From source file:br.edu.ifpb.scm.api.git.Git.java
private Author createAuthor(RevCommit it) { try {/*from ww w. jav a 2 s . co m*/ return new Author(it.getAuthorIdent().getName(), it.getAuthorIdent().getEmailAddress()); } catch (Exception e) { return null; } }
From source file:br.gov.servicos.editor.conteudo.RepositorioGitTest.java
private void garanteQueAlteracaoFoiPara(File localRepo, String branch) throws IOException { try (Git git = Git.open(localRepo)) { Ref foo = git.getRepository().getRef(branch); assertThat(foo, is(notNullValue())); RevCommit commit = new RevWalk(git.getRepository()).parseCommit(foo.getObjectId()); assertThat(commit.getAuthorIdent().getName(), is("fulano")); assertThat(commit.getAuthorIdent().getEmailAddress(), is("servicos@planejamento.gov.br")); assertThat(commit.getFullMessage(), is("Alterao de teste")); }/*w w w .j a va2 s.c o m*/ }