tags:

views:

131

answers:

3

I want to cut the svn/cvs recods in pieces and then put in to database. After that i can make use of those data easily.

Any java function can get out the record? and How? If possible, please provide a example. Thank you.

A: 

The Subversion command svn has --xml options for many of its subcommands. You can use this to get log history in XML format, which you can then read in Java using your XML parser of choice. For example:

svn log --xml
Greg Hewgill
+1  A: 

Other options are JavaHL (the Subversion binding to Java) and SvnKit (Java-only library to use Subversion).

These two libraries give you the same options as using 'svn', but without using an external program. So you can just use the structured output the function calls provide.

Bert Huijben
A: 

Here is an example that we use to find out if we need to do some updating based on revisions of files. It might help you. Its C#, but I am sure it is trivial to do the same in Java.

class UpdateNeededCalculator
{
  public static bool IsUpdateNeeded()
  {
     int newestRevisionThis, newestRevision;
     GetNewestRevision(out newestRevision, out newestRevisionThis);

     return !(newestRevisionThis >= newestRevision);
  }
  public static void GetNewestRevision(out int newestRevision, out int newestRevisionThis)
  {
     Process svn = new Process();
     if (File.Exists(@"C:\Program Files (x86)\CollabNet Subversion Client\svn.exe"))
        svn.StartInfo.FileName = @"C:\Program Files (x86)\CollabNet Subversion Client\svn.exe";
     else if (File.Exists(@"C:\Program Files (x86)\CollabNet Subversion\svn.exe"))
        svn.StartInfo.FileName = @"C:\Program Files (x86)\CollabNet Subversion\svn.exe";
     else if (File.Exists(@"C:\Program Files\CollabNet Subversion\svn.exe"))
        svn.StartInfo.FileName = @"C:\Program Files\CollabNet Subversion\svn.exe";
     else if (File.Exists(@"c:\program files (x86)\subversion\bin\svn.exe"))
        svn.StartInfo.FileName = @"c:\program files (x86)\subversion\bin\svn.exe";
     else if (File.Exists(@"C:\Program Files (x86)\CollabNet\Subversion Client\svn.exe"))
        svn.StartInfo.FileName = @"C:\Program Files (x86)\CollabNet\Subversion Client\svn.exe";
     else if (File.Exists(@"c:\program files\subversion\bin\svn.exe"))
        svn.StartInfo.FileName = @"c:\program files\subversion\bin\svn.exe";
     else if (File.Exists(@"C:\CygWin\bin\svn.exe"))
        svn.StartInfo.FileName = @"C:\CygWin\bin\svn.exe";
     else
     {
        Console.WriteLine("You have to install the commandline svn");
        throw new Exception("You have to install the commandline svn");
     }

     svn.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     svn.StartInfo.Arguments = "st --xml -v ..\\blabla";
     svn.StartInfo.RedirectStandardOutput = true;
     svn.StartInfo.UseShellExecute = false;
     svn.Start();

     XmlDocument svnxml = new XmlDocument();
     svnxml.LoadXml(svn.StandardOutput.ReadToEnd());
     svn.WaitForExit();

     newestRevision = 0;
     ProcessTarget(svnxml.FirstChild.NextSibling.FirstChild.ChildNodes, ref newestRevision, false);

     svn.StartInfo.Arguments = "st --xml -v ";
     svn.Start();
     svnxml.LoadXml(svn.StandardOutput.ReadToEnd());
     svn.WaitForExit();

     newestRevisionThis = 0;
     if (File.Exists("blabla.csproj"))
        ProcessTarget(svnxml.FirstChild.NextSibling.FirstChild.ChildNodes, ref newestRevisionThis, true);
  }

  private static void ProcessTarget(XmlNodeList xmlNodeList, ref int newestRevision, bool allFiles)
  {
     foreach (XmlNode entries in xmlNodeList)
     {
        if (entries.Name == "target")
           ProcessTarget(entries.ChildNodes, ref newestRevision, allFiles);
        else
        {
           if (!allFiles && !entries.Attributes["path"].Value.EndsWith(".resx"))
              continue;
           try
           {
              if (entries.FirstChild.Attributes["item"].Value == "unversioned" || entries.FirstChild.Attributes["item"].Value == "added")
              {
                 newestRevision = Int32.MaxValue;
              }
              else
              {
                 int rev = Int32.Parse(entries.FirstChild.FirstChild.Attributes["revision"].Value);
                 if (rev > newestRevision)
                    newestRevision = rev;
              }
           }
           catch { continue; }
        }
     }
  }

}

Cine