Sort "SVN Repositories" view

chrisahn
Posts: 4
Joined: Tue Jul 17, 2007 9:38 am

Sort "SVN Repositories" view

Postby chrisahn » Tue Jul 17, 2007 9:52 am

Subclipse keeps the repositories sorted in the "SVN Repositories" view. It would be nice if Subversive did that too. I use a lot of repositories, and it's very hard to work with the "SVN Repositories" view when they're not sorted.


A workaround is to read .svnRepositories, sort the entries, and write them back out. Here's some quick and very dirty code. Run it, stop eclipse, rename new.svnRepositories to .svnRepositories and restart eclipse.

Code: Select all

package org.polarion.team.svn.core.svnstorage;

import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.TreeMap;

import org.eclipse.core.runtime.Path;
import org.polarion.team.svn.core.SVNTeamPlugin;

public class SortSubversive
{
  public static void main( String[] args ) throws Exception
  {
    File workspace = new File(System.getProperty("user.home"), "Eclipse");
    File plugins = new File(workspace, ".metadata/.plugins");
    File subvDir = new File(plugins, "org.polarion.team.svn.core");
    File subvIn = new File(subvDir, ".svnRepositories");
    File subvOut = new File(subvDir, "new.svnRepositories");
   
    // TreeMap sorts by key
    Map<String, SVNRepositoryLocation> map = new TreeMap<String, SVNRepositoryLocation>();
   
    InputStream in = new FileInputStream(subvIn);
    try
    {
      ObjectInputStream oin = new ObjectInputStream(in);
      for (;;)
      {
        SVNRepositoryLocation location = (SVNRepositoryLocation)oin.readObject();
        map.put(location.id, location);
      }
    }
    catch (EOFException e)
    {
      // we have read it all
    }
    finally
    {
      in.close();
    }
   
    OutputStream out = new FileOutputStream(subvOut);
    try
    {
      ObjectOutputStream oout = new ObjectOutputStream(out);
      for (SVNRepositoryLocation location : map.values())
      {
        oout.writeObject(location);
      }
    }
    finally
    {
      out.close();
    }
   
    // check that new file can be read
    new SVNTeamPlugin();
    SVNRemoteStorage.instance().initializeImpl(new Path(subvDir.toString()), "new.svnRepositories");
  }
}

Alexander Gurov
Posts: 205
Joined: Fri Mar 17, 2006 11:33 am

Postby Alexander Gurov » Tue Jul 17, 2007 3:36 pm

Best regards,
Alexander Gurov
Subversive Team


Return to “Polarion Subversive - Eclipse Client for SVN”

Who is online

Users browsing this forum: No registered users and 2 guests