How can I get the current version of a file?
I'm writing a plugin which gets version control information from a fisheye server (this can provide more information than straight from SVN -- e.g. tags against a particular version). I'd like to mark the revision the user has in IDEA in my UI, but I can't figure out how to get the version number of the current file. Any hints would be appreciated. I realise that the concept of version number varies from VCS to VCS -- I'm working with subversion at the moment.
请先登录再写评论。
Hello Tom,
Which version of IDEA are you targeting? In version 6, there is no API in
IntelliJ IDEA that would return to you this information. However, you can
simply use the bundled SVNKit and its APIs (SVNStatusClient.doStatus()).
In recent 7.0 builds, DiffProvider.getCurrentRevision() returns an actual
SVN revision number rather than simply "HAVE", so you can use this API for
your purpose.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Dmitry Jemerov wrote:
> In version 6, there is no API
> in IntelliJ IDEA that would return to you this information.
Dmitry,
For Version 6 I've been using this code fragment:
String version = null;
final VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
if (historyProvider != null) {
final VcsHistorySession session =
historyProvider.createSessionFor(filePath);
if (session != null) {
version = session.getCurrentRevisionNumber().asString();
}
}
Is there something wrong with doing this then?
N.
Hello Nathan,
>> In version 6, there is no API
>> in IntelliJ IDEA that would return to you this information.
Ah, indeed. This does work correctly with both 6.0 and 7.0.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Thanks to both of you.
Next question, how do I get a FilePath from a VirtualFile?
not sure if it is the recommended way but here is how i did it
PeerFactory.getInstance().getVcsContextFactory().createFilePathOn(virtualFile)
Thanks! That works (and thanks for the pointer to PeerFactory -- I can replace a lot of my code with VcsContextFactory.createContextOn())
Just one more question (and I'd appreciate any pointers to documentation I should be reading) -- What's the difference between VcsContextFactory.createContextOn and VcsContextFactory.createCachedContextOn?
Hello Tom,
The cached context can be reused while handing a different Swing event (for
example, you can pass it to some code you call through invokeLater()). The
regular context fetches the data directly from the respective data providers
and must be used within the same Swing event.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"