Как получить номер последней редакции от SharpSVN? - PullRequest
31 голосов
/ 26 марта 2009

Как получить номер последней редакции с помощью SharpSVN?

Ответы [ 6 ]

39 голосов
/ 26 марта 2009

Самый дешевый способ получить ревизию головы из хранилища. это команда Info.

using(SvnClient client = new SvnClient())
{
   SvnInfoEventArgs info;
   Uri repos = new Uri("http://my.server/svn/repos");

   client.GetInfo(repos, out info);

   Console.WriteLine(string.Format("The last revision of {0} is {1}", repos, info.Revision));
}
16 голосов
/ 31 августа 2010

Я проверяю последнюю версию рабочей копии с помощью SvnWorkingCopyClient:

var workingCopyClient = new SvnWorkingCopyClient();

SvnWorkingCopyVersion version;

workingCopyClient.GetVersion(workingFolder, out version);

Последняя версия локального рабочего репозитория доступна через

long localRev = version.End;

Для удаленного хранилища используйте

 var client = new SvnClient();

 SvnInfoEventArgs info;

 client.GetInfo(targetUri, out info);

 long remoteRev = info.Revision;

вместо.

Это похоже на использование инструмента svnversion из командной строки. Надеюсь, это поможет.

9 голосов
/ 26 марта 2009

Хорошо, я понял это сам:

SvnInfoEventArgs statuses;
client.GetInfo("svn://repo.address", out statuses);
int LastRevision = statuses.LastChangeRevision;
1 голос
/ 27 июля 2010

Я также много гуглил, но единственная вещь, которая работала для меня, чтобы получить действительно последнюю ревизию, была:

public static long GetRevision(String target)
    {
        SvnClient client = new SvnClient();

        //SvnInfoEventArgs info;
        //client.GetInfo(SvnTarget.FromString(target), out info); //Specify the repository root as Uri
        //return info.Revision
        //return info.LastChangeRevision

        Collection<SvnLogEventArgs> info = new Collection<SvnLogEventArgs>();
        client.GetLog(target, out info);
        return info[0].Revision;
    }

другие решения закомментированы. Попробуйте сами и увидите разницу. , .

0 голосов
/ 28 июля 2014

Это очень старый вопрос, и на него хорошо ответили два лучших ответа. Тем не менее, в надежде, что это кому-то поможет, я публикую следующий метод C #, чтобы проиллюстрировать, как получить не только номера ревизий из хранилища и рабочей копии, но и как проверить типичные ситуации, могут рассматриваться как проблемы, например, в процессе автоматической сборки.

  /// <summary>
  /// Method to get the Subversion revision number for the top folder of the build collection, 
  /// assuming these files were checked-out from Merlinia's Subversion repository. This also 
  /// checks that the working copy is up-to-date. (This does require that a connection to the 
  /// Subversion repository is possible, and that it is running.)
  /// 
  /// One minor problem is that SharpSvn is available in 32-bit or 64-bit DLLs, so the program 
  /// needs to target one or the other platform, not "Any CPU".
  /// 
  /// On error an exception is thrown; caller must be prepared to catch it.
  /// </summary>
  /// <returns>Subversion repository revision number</returns>
  private int GetSvnRevisionNumber()
  {
     try
     {
        // Get the latest revision number from the Subversion repository
        SvnInfoEventArgs svnInfoEventArgs;
        using (SvnClient svnClient = new SvnClient())
        {
           svnClient.GetInfo(new Uri("svn://99.99.99.99/Merlinia/Trunk"), out svnInfoEventArgs);
        }

        // Get the current revision numbers from the working copy that is the "build collection"
        SvnWorkingCopyVersion svnWorkingCopyVersion;
        using (SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient())
        {
           svnWorkingCopyClient.GetVersion(_collectionFolder, out svnWorkingCopyVersion);
        }

        // Check the build collection has not been modified since last commit or update
        if (svnWorkingCopyVersion.Modified)
        {
           throw new MerliniaException(0x3af34e1u, 
                  "Build collection has been modified since last repository commit or update.");
        }

        // Check the build collection is up-to-date relative to the repository
        if (svnInfoEventArgs.Revision != svnWorkingCopyVersion.Start)
        {
           throw new MerliniaException(0x3af502eu, 
             "Build collection not up-to-date, its revisions = {0}-{1}, repository = {2}.",
             svnWorkingCopyVersion.Start, svnWorkingCopyVersion.End, svnInfoEventArgs.Revision);
        }

        return (int)svnInfoEventArgs.Revision;
     }
     catch (Exception e)
     {
        _fLog.Error(0x3af242au, e);
        throw;
     }
  }

(Этот код включает в себя несколько вещей, специфичных для программы, из которой он был скопирован, но это не должно затруднять понимание частей SharpSvn.)

0 голосов
/ 26 марта 2009

Ну, быстрый поиск в Google дал мне это, и это работает (просто укажите на / trunk / URI):

http://sharpsvn.open.collab.net/ds/viewMessage.do?dsForumId=728&dsMessageId=89318

...