List of usage examples for org.eclipse.jgit.util RawParseUtils parsePersonIdent
public static PersonIdent parsePersonIdent(String in)
From source file:com.google.gerrit.server.notedb.ChangeNotesParser.java
License:Apache License
private void parseSubmitRecords(List<String> lines) throws ConfigInvalidException { SubmitRecord rec = null;//from w ww .ja v a2s . c om for (String line : lines) { int c = line.indexOf(": "); if (c < 0) { rec = new SubmitRecord(); submitRecords.add(rec); int s = line.indexOf(' '); String statusStr = s >= 0 ? line.substring(0, s) : line; Optional<SubmitRecord.Status> status = Enums.getIfPresent(SubmitRecord.Status.class, statusStr); checkFooter(status.isPresent(), FOOTER_SUBMITTED_WITH, line); rec.status = status.get(); if (s >= 0) { rec.errorMessage = line.substring(s); } } else { checkFooter(rec != null, FOOTER_SUBMITTED_WITH, line); SubmitRecord.Label label = new SubmitRecord.Label(); if (rec.labels == null) { rec.labels = Lists.newArrayList(); } rec.labels.add(label); Optional<SubmitRecord.Label.Status> status = Enums.getIfPresent(SubmitRecord.Label.Status.class, line.substring(0, c)); checkFooter(status.isPresent(), FOOTER_SUBMITTED_WITH, line); label.status = status.get(); int c2 = line.indexOf(": ", c + 2); if (c2 >= 0) { label.label = line.substring(c + 2, c2); PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(c2 + 2)); checkFooter(ident != null, FOOTER_SUBMITTED_WITH, line); label.appliedBy = parseIdent(ident); } else { label.label = line.substring(c + 2); } } } }
From source file:com.google.gerrit.server.notedb.ChangeNotesParser.java
License:Apache License
private void parseReviewer(ReviewerState state, String line) throws ConfigInvalidException { PersonIdent ident = RawParseUtils.parsePersonIdent(line); if (ident == null) { throw invalidFooter(state.getFooterKey(), line); }/*from www. j a va 2 s .c om*/ Account.Id accountId = parseIdent(ident); if (!reviewers.containsKey(accountId)) { reviewers.put(accountId, state); } }
From source file:org.eclipse.egit.core.op.CommitOperation.java
License:Open Source License
public void execute(IProgressMonitor m) throws CoreException { IProgressMonitor monitor;//w w w .j a va 2s . c o m if (m == null) monitor = new NullProgressMonitor(); else monitor = m; IWorkspaceRunnable action = new IWorkspaceRunnable() { public void run(IProgressMonitor actMonitor) throws CoreException { final Date commitDate = new Date(); final TimeZone timeZone = TimeZone.getDefault(); final PersonIdent authorIdent = RawParseUtils.parsePersonIdent(author); final PersonIdent committerIdent = RawParseUtils.parsePersonIdent(committer); if (commitAll) { for (Repository repo : repos) { Git git = new Git(repo); try { git.commit().setAll(true).setAuthor(new PersonIdent(authorIdent, commitDate, timeZone)) .setCommitter(new PersonIdent(committerIdent, commitDate, timeZone)) .setMessage(message).call(); } catch (NoHeadException e) { throw new TeamException(e.getLocalizedMessage(), e); } catch (NoMessageException e) { throw new TeamException(e.getLocalizedMessage(), e); } catch (UnmergedPathException e) { throw new TeamException(e.getLocalizedMessage(), e); } catch (ConcurrentRefUpdateException e) { throw new TeamException(CoreText.MergeOperation_InternalError, e); } catch (JGitInternalException e) { throw new TeamException(CoreText.MergeOperation_InternalError, e); } catch (WrongRepositoryStateException e) { throw new TeamException(e.getLocalizedMessage(), e); } } } else if (amending || filesToCommit != null && filesToCommit.length > 0) { actMonitor.beginTask(CoreText.CommitOperation_PerformingCommit, filesToCommit.length * 2); actMonitor.setTaskName(CoreText.CommitOperation_PerformingCommit); HashMap<Repository, Tree> treeMap = new HashMap<Repository, Tree>(); try { if (!prepareTrees(filesToCommit, treeMap, actMonitor)) { // reread the indexes, they were changed in memory for (Repository repo : treeMap.keySet()) repo.getIndex().read(); return; } } catch (IOException e) { throw new TeamException(CoreText.CommitOperation_errorPreparingTrees, e); } try { doCommits(message, treeMap); actMonitor.worked(filesToCommit.length); } catch (IOException e) { throw new TeamException(CoreText.CommitOperation_errorCommittingChanges, e); } } else if (commitWorkingDirChanges) { // TODO commit -a } else { // TODO commit } } }; ResourcesPlugin.getWorkspace().run(action, monitor); }
From source file:org.eclipse.egit.core.op.CommitOperation.java
License:Open Source License
private void doCommits(String actMessage, HashMap<Repository, Tree> treeMap) throws IOException, TeamException { String commitMessage = actMessage; final Date commitDate = new Date(); final TimeZone timeZone = TimeZone.getDefault(); final PersonIdent authorIdent = RawParseUtils.parsePersonIdent(author); final PersonIdent committerIdent = RawParseUtils.parsePersonIdent(committer); for (java.util.Map.Entry<Repository, Tree> entry : treeMap.entrySet()) { Tree tree = entry.getValue();// www . j a va 2 s . c o m Repository repo = tree.getRepository(); repo.getIndex().write(); writeTreeWithSubTrees(tree); ObjectId currentHeadId = repo.resolve(Constants.HEAD); ObjectId[] parentIds; if (amending) { RevCommit[] parents = previousCommit.getParents(); parentIds = new ObjectId[parents.length]; for (int i = 0; i < parents.length; i++) parentIds[i] = parents[i].getId(); } else { if (currentHeadId != null) parentIds = new ObjectId[] { currentHeadId }; else parentIds = new ObjectId[0]; } if (createChangeId) { ObjectId parentId; if (parentIds.length > 0) parentId = parentIds[0]; else parentId = null; ObjectId changeId = ChangeIdUtil.computeChangeId(tree.getId(), parentId, authorIdent, committerIdent, commitMessage); commitMessage = ChangeIdUtil.insertId(commitMessage, changeId); if (changeId != null) commitMessage = commitMessage.replaceAll( "\nChange-Id: I0000000000000000000000000000000000000000\n", //$NON-NLS-1$ "\nChange-Id: I" + changeId.getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } CommitBuilder commit = new CommitBuilder(); commit.setTreeId(tree.getTreeId()); commit.setParentIds(parentIds); commit.setMessage(commitMessage); commit.setAuthor(new PersonIdent(authorIdent, commitDate, timeZone)); commit.setCommitter(new PersonIdent(committerIdent, commitDate, timeZone)); ObjectInserter inserter = repo.newObjectInserter(); ObjectId commitId; try { commitId = inserter.insert(commit); inserter.flush(); } finally { inserter.release(); } final RefUpdate ru = repo.updateRef(Constants.HEAD); ru.setNewObjectId(commitId); ru.setRefLogMessage(buildReflogMessage(commitMessage), false); if (ru.forceUpdate() == RefUpdate.Result.LOCK_FAILURE) { throw new TeamException(NLS.bind(CoreText.CommitOperation_failedToUpdate, ru.getName(), commitId)); } } }
From source file:org.eclipse.egit.core.test.op.TagOperationTest.java
License:Open Source License
@Test public void addTag() throws Exception { assertTrue("Tags should be empty", repository1.getRepository().getTags().isEmpty()); TagBuilder newTag = new TagBuilder(); newTag.setTag("TheNewTag"); newTag.setMessage("Well, I'm the tag"); newTag.setTagger(RawParseUtils.parsePersonIdent(TestUtils.AUTHOR)); newTag.setObjectId(repository1.getRepository().resolve("refs/heads/master"), Constants.OBJ_COMMIT); TagOperation top = new TagOperation(repository1.getRepository(), newTag, false); top.execute(new NullProgressMonitor()); assertFalse("Tags should not be empty", repository1.getRepository().getTags().isEmpty()); try {// ww w . ja va 2 s.c o m top.execute(null); fail("Expected Exception not thrown"); } catch (CoreException e) { // expected } top = new TagOperation(repository1.getRepository(), newTag, true); try { top.execute(null); fail("Expected Exception not thrown"); } catch (CoreException e) { // expected } Ref tagRef = repository1.getRepository().getTags().get("TheNewTag"); RevWalk walk = new RevWalk(repository1.getRepository()); RevTag tag = walk.parseTag(repository1.getRepository().resolve(tagRef.getName())); newTag.setMessage("Another message"); assertFalse("Messages should differ", tag.getFullMessage().equals(newTag.getMessage())); top.execute(null); tag = walk.parseTag(repository1.getRepository().resolve(tagRef.getName())); assertTrue("Messages be same", tag.getFullMessage().equals(newTag.getMessage())); }
From source file:org.eclipse.egit.ui.internal.dialogs.CommitDialog.java
License:Open Source License
@Override protected void okPressed() { commitMessage = commitText.getCommitMessage(); author = authorText.getText().trim(); committer = committerText.getText().trim(); signedOff = signedOffButton.getSelection(); amending = amendingButton.getSelection(); Object[] checkedElements = filesViewer.getCheckedElements(); selectedFiles.clear();/*from w w w . ja va2 s . co m*/ for (Object obj : checkedElements) selectedFiles.add(((CommitItem) obj).file); if (commitMessage.trim().length() == 0) { MessageDialog.openWarning(getShell(), UIText.CommitDialog_ErrorNoMessage, UIText.CommitDialog_ErrorMustEnterCommitMessage); return; } boolean authorValid = false; if (author.length() > 0) { authorValid = RawParseUtils.parsePersonIdent(author) != null; } if (!authorValid) { MessageDialog.openWarning(getShell(), UIText.CommitDialog_ErrorInvalidAuthor, UIText.CommitDialog_ErrorInvalidAuthorSpecified); return; } boolean committerValid = false; if (committer.length() > 0) { committerValid = RawParseUtils.parsePersonIdent(committer) != null; } if (!committerValid) { MessageDialog.openWarning(getShell(), UIText.CommitDialog_ErrorInvalidAuthor, UIText.CommitDialog_ErrorInvalidCommitterSpecified); return; } if (selectedFiles.isEmpty() && !amending) { MessageDialog.openWarning(getShell(), UIText.CommitDialog_ErrorNoItemsSelected, UIText.CommitDialog_ErrorNoItemsSelectedToBeCommitted); return; } authorHandler.updateProposals(); committerHandler.updateProposals(); IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings(); settings.put(SHOW_UNTRACKED_PREF, showUntracked); super.okPressed(); }
From source file:org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent.java
License:Open Source License
/** * Get the status of whether the commit operation should be enabled or * disabled./* ww w. j a v a 2 s . com*/ * <p> * This method checks the current state of the widgets and must always be * called from the UI-thread. * <p> * The returned status includes a message and type denoting why committing * cannot be completed. * * @return non-null commit status */ public CommitStatus getStatus() { if (!commitAllowed) return new CommitStatus(cannotCommitMessage, IMessageProvider.ERROR); String authorValue = authorText.getText(); if (authorValue.length() == 0 || RawParseUtils.parsePersonIdent(authorValue) == null) return new CommitStatus(UIText.CommitMessageComponent_MessageInvalidAuthor, IMessageProvider.ERROR); String committerValue = committerText.getText(); if (committerValue.length() == 0 || RawParseUtils.parsePersonIdent(committerValue) == null) { return new CommitStatus(UIText.CommitMessageComponent_MessageInvalidCommitter, IMessageProvider.ERROR); } if (amending && amendingCommitInRemoteBranch) return new CommitStatus(UIText.CommitMessageComponent_AmendingCommitInRemoteBranch, IMessageProvider.WARNING); return CommitStatus.OK; }
From source file:org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent.java
License:Open Source License
/** * @return true if commit info is ok/*from w w w. j a va 2 s. c o m*/ */ public boolean checkCommitInfo() { updateStateFromUI(); if (commitMessage.trim().length() == 0) { MessageDialog.openWarning(getShell(), UIText.CommitDialog_ErrorNoMessage, UIText.CommitDialog_ErrorMustEnterCommitMessage); return false; } boolean authorValid = false; if (author.length() > 0) authorValid = RawParseUtils.parsePersonIdent(author) != null; if (!authorValid) { MessageDialog.openWarning(getShell(), UIText.CommitDialog_ErrorInvalidAuthor, UIText.CommitDialog_ErrorInvalidAuthorSpecified); return false; } boolean committerValid = false; if (committer.length() > 0) committerValid = RawParseUtils.parsePersonIdent(committer) != null; if (!committerValid) { MessageDialog.openWarning(getShell(), UIText.CommitDialog_ErrorInvalidAuthor, UIText.CommitDialog_ErrorInvalidCommitterSpecified); return false; } authorHandler.updateProposals(); committerHandler.updateProposals(); return true; }
From source file:org.eclipse.egit.ui.test.team.actions.BranchAndResetActionTest.java
License:Open Source License
@BeforeClass public static void setup() throws Exception { repositoryFile = createProjectAndCommitToRepository(); Repository repo = lookupRepository(repositoryFile); perspective = bot.activePerspective(); bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate(); TagBuilder tag = new TagBuilder(); tag.setTag("SomeTag"); tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR)); tag.setMessage("I'm just a little tag"); tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT); TagOperation top = new TagOperation(repo, tag, false); top.execute(null);/* w w w . j a v a 2s.c om*/ touchAndSubmit(null); RepositoriesViewLabelProvider provider = new RepositoriesViewLabelProvider(); LOCAL_BRANCHES = provider.getText(new LocalNode(new RepositoryNode(null, repo), repo)); TAGS = provider.getText(new TagsNode(new RepositoryNode(null, repo), repo)); waitInUI(); }
From source file:org.eclipse.egit.ui.test.team.actions.CommitActionTest.java
License:Open Source License
@BeforeClass public static void setup() throws Exception { repositoryFile = createProjectAndCommitToRepository(); Repository repo = lookupRepository(repositoryFile); // TODO delete the second project for the time being (.gitignore is // currently not hiding the .project file from commit) ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2).delete(false, null); TagBuilder tag = new TagBuilder(); tag.setTag("SomeTag"); tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR)); tag.setMessage("I'm just a little tag"); tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT); TagOperation top = new TagOperation(repo, tag, false); top.execute(null);/* w ww. j a v a2s .c o m*/ touchAndSubmit(null); perspective = bot.activePerspective(); bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate(); waitInUI(); }