List of usage examples for org.eclipse.jgit.revwalk RevCommit getCommitTime
public final int getCommitTime()
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 w w . 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: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; }/*from www. j ava 2s.c om*/ 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:at.nonblocking.maven.nonsnapshot.impl.ScmHandlerGitImpl.java
License:Apache License
@Override public boolean checkChangesSinceDate(final File moduleDirectory, final Date date) { if (this.git == null) { return false; }//from www . ja v a2 s .c o m try { String modulePath = PathUtil.relativePath(this.baseDir, moduleDirectory); LogCommand logCommand = this.git.log().setMaxCount(100); if (!modulePath.isEmpty()) { logCommand.addPath(modulePath); } for (RevCommit commit : logCommand.call()) { Date commitTime = new Date(commit.getCommitTime() * 1000L); if (commitTime.after(date)) { if (!commit.getFullMessage().startsWith(NONSNAPSHOT_COMMIT_MESSAGE_PREFIX)) { LOG.debug("Module folder {}: Change since last commit: rev{} @ {} ({})", new Object[] { moduleDirectory.getAbsolutePath(), commit.getId(), commitTime, commit.getFullMessage() }); return true; } } else { break; } } } catch (Exception e) { LOG.warn("Failed to check changes for path: {}" + moduleDirectory.getAbsolutePath(), e); return true; } return false; }
From source file:boa.datagen.scm.GitConnector.java
License:Apache License
@Override protected void setRevisions() { try {//from w ww . java2 s . co 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
private GregorianCalendar convertToDate(RevCommit revCommit) { GregorianCalendar date = new GregorianCalendar(); date.setTime(new Date(revCommit.getCommitTime() * 1000L)); return date;/*w w w . j ava 2 s . c om*/ }
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 va 2 s . c om 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.test.helpers.ConflictBasedRepositoryTestCase.java
License:Open Source License
public static void logAllCommits(Repository repo) throws Exception { Git git = Git.wrap(repo);/*from w w w. j ava 2 s. co 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:ch.uzh.ifi.seal.permo.history.git.core.model.jgit.JGitRepository.java
License:Apache License
/** * {@inheritDoc}/*www .j av a 2 s.co m*/ */ @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 a 2 s . c o 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.addthis.hydra.job.store.JobStoreGit.java
License:Apache License
/** * Get a JSON representation of the log of changes to a file * * @param jobId The jobId to fetch the log for * @return A log of the form [{commit:commitid, time:time, msg:commitmessage}, ...] * @throws GitAPIException If there is a problem fetching the log * @throws JSONException If there is a problem generating the JSON */// ww w. ja v a 2 s . co m public JSONArray getGitLog(String jobId) throws Exception { JSONArray rv = new JSONArray(); for (RevCommit commit : git.log().addPath(getPathForJobId(jobId)).call()) { JSONObject commitJson = new JSONObject().put("commit", commit.getName()) .put("time", 1000L * (commit.getCommitTime())).put("msg", commit.getFullMessage()); rv.put(commitJson); } return rv; }