private static List<RevCommit> filterValidCommits(List<RevCommit> revCommits) { final List<RevCommit> filteredCommits = new LinkedList<>(); for (RevCommit commit : revCommits) { final String commitAuthor = commit.getAuthorIdent().getName(); if (!USERS_EXCLUDED_FROM_VALIDATION.contains(commitAuthor)) { filteredCommits.add(commit); } } return filteredCommits; }
private static List<RevCommit> getCommitsByLastCommitAuthor( Iterator<RevCommit> previousCommitsIterator) { final List<RevCommit> commits = new LinkedList<>(); if (previousCommitsIterator.hasNext()) { final RevCommit lastCommit = previousCommitsIterator.next(); final String lastCommitAuthor = lastCommit.getAuthorIdent().getName(); commits.add(lastCommit); boolean wasLastCheckedCommitAuthorSameAsLastCommit = true; while (wasLastCheckedCommitAuthorSameAsLastCommit && previousCommitsIterator.hasNext()) { final RevCommit currentCommit = previousCommitsIterator.next(); final String currentCommitAuthor = currentCommit.getAuthorIdent().getName(); if (currentCommitAuthor.equals(lastCommitAuthor)) { commits.add(currentCommit); } else { wasLastCheckedCommitAuthorSameAsLastCommit = false; } } } return commits; }
String getMergedConfig(String branchName, RevCommit newCommit) throws GitAPIException, IOException { MergeResult result = null; try { checkout(branchName); result = git.merge().include(newCommit).call(); } catch (GitAPIException e) { LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); throw e; } if (!result.getMergeStatus().isSuccessful()) { LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed as config file has changed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); throw new ConfigFileHasChangedException(); } LOGGER.info("[CONFIG_MERGE] Successfully merged commit {} by user {} to branch {}. Merge commit revision is {}", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); return FileUtils.readFileToString(new File(workingDir, CRUISE_CONFIG_XML), UTF_8); }
public static ArrayMemory valueOf(PersonIdent value) { ArrayMemory memory = new ArrayMemory(); memory.refOfIndex("name").assign(value.getName()); memory.refOfIndex("email").assign(value.getEmailAddress()); memory.refOfIndex("when").assign(value.getWhen() == null ? Memory.NULL : LongMemory.valueOf(value.getWhen().getTime())); memory.refOfIndex("timeZone").assign( value.getTimeZone() == null ? Memory.NULL : StringMemory.valueOf(value.getTimeZone().getID()) ); return memory; }
/** * Copy a {@link org.eclipse.jgit.lib.PersonIdent}, but alter the clone's * time stamp * * @param pi * original {@link org.eclipse.jgit.lib.PersonIdent} * @param aWhen * local time */ public PersonIdent(PersonIdent pi, Date aWhen) { this(pi.getName(), pi.getEmailAddress(), aWhen.getTime(), pi.tzOffset); }
@Override public String getCommitAuthorName() throws GitCommitIdExecutionException { return evalCommit.getAuthorIdent().getName(); }
/** * Copy a {@link org.eclipse.jgit.lib.PersonIdent}. * * @param pi * Original {@link org.eclipse.jgit.lib.PersonIdent} */ public PersonIdent(PersonIdent pi) { this(pi.getName(), pi.getEmailAddress()); }
/** * Copy a PersonIdent, but alter the clone's time stamp * * @param pi * original {@link org.eclipse.jgit.lib.PersonIdent} * @param when * local time * @param tz * time zone */ public PersonIdent(PersonIdent pi, Date when, TimeZone tz) { this(pi.getName(), pi.getEmailAddress(), when, tz); }
/** * Copy a PersonIdent, but alter the clone's time stamp * * @param pi * original {@link org.eclipse.jgit.lib.PersonIdent} * @param aWhen * local time stamp * @param aTZ * time zone */ public PersonIdent(PersonIdent pi, long aWhen, int aTZ) { this(pi.getName(), pi.getEmailAddress(), aWhen, aTZ); }
private String toString(PersonIdent author) { final StringBuilder a = new StringBuilder(); a.append("Author: "); //$NON-NLS-1$ a.append(author.getName()); a.append(" <"); //$NON-NLS-1$ a.append(author.getEmailAddress()); a.append(">\n"); //$NON-NLS-1$ a.append("Date: "); //$NON-NLS-1$ a.append(dateFormatter.formatDate(author)); a.append("\n"); //$NON-NLS-1$ return a.toString(); } }
/** {@inheritDoc} */ @Override @SuppressWarnings("nls") public String toString() { final StringBuilder r = new StringBuilder(); final SimpleDateFormat dtfmt; dtfmt = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z", Locale.US); dtfmt.setTimeZone(getTimeZone()); r.append("PersonIdent["); r.append(getName()); r.append(", "); r.append(getEmailAddress()); r.append(", "); r.append(dtfmt.format(Long.valueOf(when))); r.append("]"); return r.toString(); } }
private static boolean canCombine(@Nullable PersonIdent a, @Nullable PersonIdent b) { if (a != null && b != null) { // Same name and email address. Combine timestamp as the two // proposals are running concurrently and appear together or // not at all from the point of view of an outside reader. return a.getName().equals(b.getName()) && a.getEmailAddress().equals(b.getEmailAddress()); } // If a and b are null, both will be the system identity. return a == null && b == null; }
String toAuthorScript(PersonIdent author) { StringBuilder sb = new StringBuilder(100); sb.append(GIT_AUTHOR_NAME); sb.append("='"); //$NON-NLS-1$ sb.append(author.getName()); sb.append("'\n"); //$NON-NLS-1$ sb.append(GIT_AUTHOR_EMAIL); sb.append("='"); //$NON-NLS-1$ sb.append(author.getEmailAddress()); sb.append("'\n"); //$NON-NLS-1$ // the command line uses the "external String" // representation for date and timezone sb.append(GIT_AUTHOR_DATE); sb.append("='"); //$NON-NLS-1$ sb.append("@"); // @ for time in seconds since 1970 //$NON-NLS-1$ String externalString = author.toExternalString(); sb .append(externalString.substring(externalString .lastIndexOf('>') + 2)); sb.append("'\n"); //$NON-NLS-1$ return sb.toString(); }
LogEntry(String refName, long updateIndex, PersonIdent who, ObjectId oldId, ObjectId newId, String message) { super(key(refName, updateIndex)); this.oldId = oldId; this.newId = newId; this.timeSecs = who.getWhen().getTime() / 1000L; this.tz = (short) who.getTimeZoneOffset(); this.name = who.getName().getBytes(UTF_8); this.email = who.getEmailAddress().getBytes(UTF_8); this.msg = message.getBytes(UTF_8); }
/** * Format for Git storage. * * @return a string in the git author format */ public String toExternalString() { final StringBuilder r = new StringBuilder(); appendSanitized(r, getName()); r.append(" <"); //$NON-NLS-1$ appendSanitized(r, getEmailAddress()); r.append("> "); //$NON-NLS-1$ r.append(when / 1000); r.append(' '); appendTimezone(r, tzOffset); return r.toString(); }
public static void main(String args[]) throws IOException, GitAPIException { try (Repository repo = CookbookHelper.openJGitCookbookRepository()) { final String[] list = new File(".").list(); if(list == null) { throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath()); } for(String file : list) { if(new File(file).isDirectory()) { continue; } System.out.println("Blaming " + file); final BlameResult result = new Git(repo).blame().setFilePath(file) .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call(); final RawText rawText = result.getResultContents(); for (int i = 0; i < rawText.size(); i++) { final PersonIdent sourceAuthor = result.getSourceAuthor(i); final RevCommit sourceCommit = result.getSourceCommit(i); System.out.println(sourceAuthor.getName() + (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") + ": " + rawText.getString(i)); } } } } }
public static void main(String args[]) throws IOException, GitAPIException { try (Repository repo = CookbookHelper.openJGitCookbookRepository()) { final String[] list = new File(".").list(); if(list == null) { throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath()); } for(String file : list) { if(new File(file).isDirectory()) { continue; } System.out.println("Blaming " + file); final BlameResult result = new Git(repo).blame().setFilePath(file) .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call(); final RawText rawText = result.getResultContents(); for (int i = 0; i < rawText.size(); i++) { final PersonIdent sourceAuthor = result.getSourceAuthor(i); final RevCommit sourceCommit = result.getSourceCommit(i); System.out.println(sourceAuthor.getName() + (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") + ": " + rawText.getString(i)); } } } } }
/** * Get latest commit by ref name from local .git */ @Override public GitCommit commit(String refName) throws GitException { try (Git git = gitOpen()) { Repository repo = git.getRepository(); Ref head = repo.findRef(refName); if (head == null) { return null; } try (RevWalk walk = new RevWalk(repo)) { RevCommit commit = walk.parseCommit(head.getObjectId()); walk.dispose(); String id = commit.getId().getName(); String message = commit.getFullMessage(); String author = commit.getAuthorIdent().getName(); return new GitCommit(id, message, author); } } catch (IOException e) { throw new GitException("Fail to get commit message", e); } }
private String formatCommitInfo() { PersonIdent committer, author; committer = mCommit.getCommitterIdent(); author = mCommit.getAuthorIdent(); return "commit " + mNewCommit + "\n" + "Author: " + author.getName() + " <" + author.getEmailAddress() + ">\n" + "AuthorDate: " + author.getWhen() + "\n" + "Commit: " + committer.getName() + " <" + committer.getEmailAddress() + ">\n" + "CommitDate: " + committer.getWhen() + "\n"; }