Taking programmatic control over SmartSVN

While SmartSVN is running, it can receive commands to be executed, like opening a file compare for a versioned file. This is how the Windows Explorer Integration and the Mac OS X Finder Integration are working. This article will show how to use this socket-based command API for custom integrations of SmartSVN.

First of all, SmartSVN has to be started, either normally or by supplying the --server-mode command line parameter (requires Java 6) which prevents a project window to occur. On Windows you may execute: bin/smartsvn.exe --server-mode. On Unix you may use bin/smartsvn.sh --server-mode. A platform-independent way to start SmartSVN is java --jar smartsvn.jar --server-mode which will work fine on Mac OS X.

Once SmartSVN has been started, it will create a port-file within its settings directory immediately. It contains the port number for client connections. To perform a SmartSVN command, a new socket should be created connecting to this port at host 127.0.0.1, then the communication can start.

The protocol is very simple: The client sends the command name, terminated by \n. Then it sends the absolute file paths to be used by the command, every path on a separate line, terminated by \n. Finally it sends one more empty line, i.e. just \n. For example:

get-states
d:\\working-copy\\a.txt
d:\\working-copy\\b.txt
d:\\working-copy\\c.txt
(empty line)

Note, that the text has to be escaped like character and string literals have to be escaped in Java source code, e.g. on Windows the backslash \ has to be escaped \\.

Depending on the command, SmartSVN will return a response. In case of our get-states example, this could be:

d:\\working-copy\\a.txt <tab> unchanged
d:\\working-copy\\b.txt <tab> unchanged
d:\\working-copy\\c.txt <tab> modified
(empty line)

Here, file a.txt and b.txt are reported as unchanged while file c.txt is modified.

Actually, only the get-states command has a response. For all other commands the socket will be closed immediately after having received the final trailing empty line. Other available commands are:

  • add
  • annotate
  • cleanup
  • commit
  • compare
  • ignore
  • lock
  • unlock
  • log
  • rename
  • remove
  • resolve
  • revert
  • revision-graph
  • update

For example, to open SmartSVN’s File Compare for c.txt, following lines should be sent:

compare
d:\\working-copy/c.txt
(empty line)

When implementing a communication with SmartSVN’s server it may be helpful to set the logging level for the smartsvn.server category to debug. For details refer to the Technical Articles.

The attached Java class contains a complete example implementation, which connects to a running SmartSVN instance, scans a working copy directory for a modified file and then opens the File Compare.

Tips for Migrating from CVS to SVN

I was asked by a couple of CVS users who want to start with SVN (using our SVN client SmartSVN) about some tips how to avoid common pitfalls. So, from my personal experience and from problems we have got reported by our users, I would consider following issues as notable:

With SVN you don’t have tags and branches as a built-in feature like in CVS. Instead, tags and branches are handled by using special paths and SVN’s cheap copy feature. Don’t try to reinvent the wheel but better stick with a default repository layout:

repository-root
[-] project1
| [-] branches
| | [+] branch1
| | [+] branch2
...
| [-] tags
| | [+] tag1
| | [+] tag2
...
| [+] trunk
[-] project2
| [-] branches
| | [+] branch1
| | [+] branch2
...
| [-] tags
| | [+] tag1
| | [+] tag2
...
| [+] trunk
...

Quite often people check out the whole repository or project including all tags and branches. Don’t do that but only check out either the trunk or a specific tag or branch. It is quite easy to “switch” between them.

With CVS it often was common practice to add a certain tag to only a few files. Forget about tagging individual files in SVN.
SVN can tag (aka copy) large parts of the repository as effective as just a small part.
Another advantage of tagging always the full repository is that you are able to switch easily to that project state.
If you have used file-based (not (only) project-based) tags in CVS and history doesn’t really matter to you, better import fresh project states in the SVN repository and don’t convert the CVS repository to SVN.

A lot of projects consist of multiple parts. With CVS you might have used CVS modules or shell scripts to check out from different repository locations or different repositories.
SVN’s externals are a much better concept and should be used instead.

SmartGit – 5th Milestone

The 5th milestone of SmartGit, a client for the distributed version control system (DVCS) Git, is available.

The most notable changes in Milestone 5 are:

  • basic submodule support
  • log improvements
  • configurable accelerators

All changes can be found in the change log.

We would like to invite everyone to give this milestone build a try and share your ideas with us. Join the SmartGit community!

Download SmartGit

Note:

SmartGit requires a Git installation on your system.

SmartCVS 7.1 beta 1

The first beta version of SmartCVS 7.1 beta 1 is available. The most new features and improves are:

  • Transactions: ability to filter by branch and/or author
  • for Windows there exists a portable bundle (e.g. for USB-stick usage)
  • Transactions: ability to show for time or tag range
  • external tools: option to use system open or edit command (requires Java 1.6)
  • external file comparators: ability to use (e.g. graphic) viewers which only can accept one file, but can be invoked two times to open two files
  • OS X: reveal in Finder
  • file filter, speed search: configurable, e.g. with smart upper case (e.g. “FB” will match “FooBar.txt”)
  • Commit dialog: ability to open change report
  • working copies with :ssh: (instead of :ext:) are working now (to be compatible with other CVS clients)
  • built-in File Compare: if binary files are compared, file size and hash code are shown
  • built-in File Compare: option to deactivate synchronized scrolling
  • built-in File Compare: optionally ignore case changes
  • Conflict Solver: ability to pass left and right title to external tool
  • Conflict Solver: shows Save toolbar button
  • tables, time columns: show today/yesterday if applicable

Download SmartCVS 7.1 beta 1

Start Developing Plugin for SmartSVN Enterprise

SmartSVN Enterprise offers a Plugin-API which allows to add own functionality to SmartSVN. In this article I want to show how to configure IntelliJ IDEA to compile a sample plugin and how to launch SmartSVN to load this plugin. Of course you should be able to use any other Java IDE, too.

Ensure that SmartSVN is installed and configured. It must have an Enterprise (demo) license registered. How to get an Enterprise demo license.

Now create a project structure:

  • create an empty directory (we will use C:\projects\mergeInfoColumn) as the root for the project
  • create a lib directory and copy all .jar files from the SmartSVN installation into it (svnkit-cli.jar is not required and hence can be skipped)
  • create a src directory and unpack the mergeInfoColumn directory from the plugin-sources.zip of the SmartSVN installation into it.

Create a new project in IDEA and add a Java module mergeInfoColumn and configure its Sources, Paths and Dependencies according to the following screenshots.

Remember this output path, we will need it later, so SmartSVN can load the plugin:

Every SmartSVN plugin depends on the openapi.jar, the mergeInfoColumn plugin also requires the svnkit.jar to compile:

Open the compiler settings and ensure that .properties files are copied from the sources to the classes directory.

To launch SmartSVN you will need all its jar files, hence we create another module named launcher just for launching purposes.
Add all the .jar files from the lib directory as dependency. To ensure that the mergeInfoColumn module is also compiled before launching, add it also as dependency:

Create a Run/Debug configuration. Use the main class SmartSVN and tell SmartSVN where to look for the plugin classes by setting the VM property smartsvn.pluginLocations. Use the compiler output path configured above. You can use absolute paths, but also, as shown in this screenshot, relative ones.

Now you should be able to launch SmartSVN. If everything is done right, you should see “Plugin … loaded.” message on the console immediately after SmartSVN start up.