Obtain last Commit

Hi, how can i obtain informations from the last commit, i need to know the revisionnumber and the effected files.
Below some code there i am calling the commitdialog with passing the selected files from the projectview.
After this is done i want to recognize what files were committed and the revisionnumber.



public class Actionclass extends AnAction {   @Override   public void actionPerformed(AnActionEvent anActionEvent) {     Collection<FilePath> paths = new ArrayList<FilePath>();     Project project = anActionEvent.getData(DataKeys.PROJECT);     ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);     VirtualFile[] selectedFiles = anActionEvent.getData(DataKeys.VIRTUAL_FILE_ARRAY);     for(VirtualFile v : selectedFiles)     {         paths.add(VcsContextFactory.SERVICE.getInstance().createFilePathOn(v));     }     final ChangeListManager clManager = ChangeListManager.getInstance(project);     CommitChangeListDialog.commitPaths(project, paths, null, null,"");     
->> now some code to recognize what files there committed (in case the user changed something in the dialog) and the revision number        
  } }



kind regards
syt

10 comments
Comment actions Permalink

Hi,
try to use CommittedChangesProvider#getCommittedChanges() with maxCount == 1.

If your target is just Git, you may want to inspect methods of GitHistoryUtils.

0
Comment actions Permalink

There is no way to do this directly. Note that the files committed by the user may belong to multiple repositories or multiple different version control systems, so they will not necessarily have a single revision number.

You can access the history of each of the files using VcsHistoryProvider and fetch the revision number using VcsHistorySession.getCurrentRevisionNumber().

0
Comment actions Permalink

Thx,
How do i call this method?

I tried it this way:

public void actionPerformed(AnActionEvent anActionEvent) {                 Project project = anActionEvent.getProject();                 ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);                 SvnVcs svn = SvnVcs.getInstance(project);                 RepositoryLocation repositoryLocation = new SvnRepositoryLocation(svn.getInfo(project.getBaseDir()).getRepositoryRootURL().toString());                 ChangeBrowserSettings settings = project.getComponent(ChangeBrowserSettings.class);                 CommittedChangesProvider<SvnChangeList,ChangeBrowserSettings> committedChangesProvider = svn.getCommittedChangesProvider();                 try {                   List<SvnChangeList> changeLists =                     committedChangesProvider.getCommittedChanges(settings,repositoryLocation , 1);                   for (CommittedChangeList repositoryVersion : changeLists) {                     System.out.println(repositoryVersion.getNumber());                   }                 }                 catch (VcsException e1) {                   e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.                 }               }             });



But it throws exceptions like :

[  36829]  ERROR - com.intellij.ide.IdeEventQueue - Error during dispatching of java.awt.event.MouseEvent[MOUSE_RELEASED,(150,481),absolute(1957,616),button=1,modifiers=Button1,clickCount=1] on frame0 java.lang.NullPointerException      at org.jetbrains.idea.svn.history.SvnCommittedChangesProvider.getCommittedChangesImpl(SvnCommittedChangesProvider.java:360)      at org.jetbrains.idea.svn.history.SvnCommittedChangesProvider.getCommittedChanges(SvnCommittedChangesProvider.java:242)      at TFS.GUI.TFSToolWindowFactory$2$1.actionPerformed(TFSToolWindowFactory.java:204)      at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter$1.run(ActionMenuItem.java:256)      at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:892)      at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:114)      at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:227)      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)      at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:101)      at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:512)      at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:44)      at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:532)      at java.awt.Component.processMouseEvent(Component.java:6505)      at javax.swing.JComponent.processMouseEvent(JComponent.java:3312)      at java.awt.Component.processEvent(Component.java:6270)      at java.awt.Container.processEvent(Container.java:2229)      at java.awt.Component.dispatchEventImpl(Component.java:4861)      at java.awt.Container.dispatchEventImpl(Container.java:2287)      at java.awt.Component.dispatchEvent(Component.java:4687)      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)      at java.awt.Container.dispatchEventImpl(Container.java:2273)      at java.awt.Window.dispatchEventImpl(Window.java:2719)      at java.awt.Component.dispatchEvent(Component.java:4687)      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)      at java.awt.EventQueue.access$200(EventQueue.java:103)      at java.awt.EventQueue$3.run(EventQueue.java:688)      at java.awt.EventQueue$3.run(EventQueue.java:686)      at java.security.AccessController.doPrivileged(Native Method)      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)      at java.awt.EventQueue$4.run(EventQueue.java:702)      at java.awt.EventQueue$4.run(EventQueue.java:700)      at java.security.AccessController.doPrivileged(Native Method)      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)      at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)      at com.intellij.ide.IdeEventQueue.d(IdeEventQueue.java:685)      at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:506)      at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:333)      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)      at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

0
Comment actions Permalink

Why do you think that ChangeBrowserSettings is a project component?
Use com.intellij.openapi.vcs.CommittedChangesProvider#createDefaultSettings.
Search for usages in IntelliJ community codebase for details.

0
Comment actions Permalink

I did it like you have suggested it.
I create a List of File:VCSrevsionNumber before i call CommitChangeListDialog.commitPaths()
and afterwards, but CommitChangeListDialog.commitPaths() creates it's own thread, how can i obtain then it has finished?
Because now both Lists contain the same values.


    Collection<FilePath> paths = new ArrayList<FilePath>();     Project project = anActionEvent.getData(PlatformDataKeys.PROJECT);     svn = SvnVcs.getInstance(project);     VirtualFile[] selectedFiles = project.getBaseDir().getChildren();     printNodes(createTree(project.getBaseDir()));     for(VirtualFile vl : selectedFiles)     {       paths.add(VcsContextFactory.SERVICE.getInstance().createFilePathOn(vl));     }     FileNode node_old = createTree(project.getBaseDir());     CommitChangeListDialogCustom.commitPaths(project, paths, null, null, "");     FileNode node_new = createTree(project.getBaseDir());     compareNodes(node_old,node_new);

0
Comment actions Permalink

Use CommitChangeListDialog#commitChanges(Project project, Collection<Change> changes, LocalChangeList initialSelection, List<CommitExecutor> executors, boolean showVcsCommit, String comment, CommitResultHandler customResultHandler)

0
Comment actions Permalink

Hi, this is not actually what i wanted to do.
How can i get this list of committs shown in the Chnges Window?



Attachment(s):
Bildschirmfoto7.png
0
Comment actions Permalink

You can use com.intellij.openapi.vcs.CommittedChangesProvider.

0
Comment actions Permalink

hi, now that i have the revisionnumber is it possible to call the Repository Tab and preselect the change by the given revesion number?

kind regards
syt

0
Comment actions Permalink

As I know, there is no API for that.

0

Please sign in to leave a comment.