Refine search
/** * 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()); }
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; }
@Override PersonIdent getAuthor() { return new PersonIdent(description, ""); //$NON-NLS-1$ } }
/** * 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(); }
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"; }
@Nullable @Override public String getAuthor() { if (gitNewCommit == null) return null; final PersonIdent ident = gitNewCommit.getAuthorIdent(); return String.format("%s <%s>", ident.getName(), ident.getEmailAddress()); }
private Git.Head getHead(final Repository repository) throws IOException { ObjectId revision = repository.resolve(Constants.HEAD); RevCommit commit = new RevWalk(repository).parseCommit(revision); Git.Head head = new Git.Head( revision.getName(), commit.getAuthorIdent().getName(), commit.getAuthorIdent().getEmailAddress(), commit.getCommitterIdent().getName(), commit.getCommitterIdent().getEmailAddress(), commit.getFullMessage() ); return head; }
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); }
/** * 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); } }
public CommitInfo createCommitInfo(RevCommit entry) { final Date date = GitFacade.getCommitDate(entry); String author = entry.getAuthorIdent().getName(); boolean merge = entry.getParentCount() > 1; String shortMessage = entry.getShortMessage(); String trimmedMessage = Strings.trimString(shortMessage, 78); String name = entry.getName(); String commitHashText = getShortCommitHash(name); return new CommitInfo(commitHashText, name, author, date, merge, trimmedMessage, shortMessage); }
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 Value(RevCommit commit) { this.id = commit.copy(); this.author = commit.getAuthorIdent(); this.commitDate = commit.getCommitterIdent().getWhen(); this.summary = StringUtils.substringBefore(commit.getFullMessage(), "\n").trim(); }
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 PersonIdent getLatestPersonIdent(Collection<RevCommit> commits) { PersonIdent latest = null; for (RevCommit commit : commits) { PersonIdent ident = commit.getCommitterIdent(); Date when = ident.getWhen(); if (latest == null || when.after(latest.getWhen())) { latest = ident; } } return latest; }
public int compare(RevCommit o1, RevCommit o2) { return o1.getAuthorIdent().getWhen() .compareTo(o2.getAuthorIdent().getWhen()); } });
private static PersonIdent tmpAuthor(List<RevCommit> commits) { // Construct a predictable author using most recent commit time. int t = 0; for (int i = 0; i < commits.size();) { t = Math.max(t, commits.get(i).getCommitTime()); } String name = "Ketch Stage"; //$NON-NLS-1$ String email = "tmp@tmp"; //$NON-NLS-1$ return new PersonIdent(name, email, t * 1000L, 0); }
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(); }
public boolean matches(Pattern pattern, RevCommit commit) { PersonIdent committer = commit.getCommitterIdent(); if (committer != null) return matches(pattern, committer.getName()) || matches(pattern, committer.getEmailAddress()); else return false; } }
@Test public void setDefaultCommitter_newPersonIdentInstanceShouldHaveTheSpecifiedUserNameAndEmail() throws IOException { String name = "test_user"; String email = "test@user.com"; RepositoryUtils.setDefaultCommitter(name, email, repo); PersonIdent actual = new PersonIdent(repo); assertEquals(name, actual.getName()); assertEquals(email, actual.getEmailAddress()); }
public Date getDate() { PersonIdent person = commit.getAuthorIdent(); if( person == null) person = commit.getCommitterIdent(); return person != null ? person.getWhen() : new Date(0); }