开发者

SharpSVN - How to get the previous revision?

I am trying to find an efficient way to get the previous revision of a file to do a text comparison using SharpSVN.

using (SvnClient c = new SvnClient())
{
    c.Authentication.DefaultCredentials = new NetworkCredential(
          ConfigurationManager.AppSettings.Get("SvnServiceUserName")
        , ConfigurationManager.AppSettings.Get("SvnServicePassword")
        , ConfigurationManager.AppSettings.Get("SvnServiceDomain")
        );
    c.Authentication.SslServerTrustHandlers += new EventHandler<SvnSslServerTrustEventArgs>(Authentication_SslServerTrustHandlers);

    Collection<SvnFileVersionEventArgs> fileVersionCollection = new Collection<SvnFileVersionEventArgs>();
    SvnRevisionRange range = new SvnRevisionRange(0, this.hooks.Revision);
    SvnFileVersionsArgs args = new SvnFileVersionsArgs();
    args.RetrieveProperties = true;
    args.Range = range;

    foreach (SvnChangeItem item in log.ChangedPaths)
    {
        string path = this.repositoryPath + item.Path;

        bool gotFileVersions = false;

        try
        {
            if (item.NodeKind == SvnNodeKind.File)
                gotFileVersions = c.GetFileVersions(SvnTarget.FromString(path), args, out fileVersionCollection);

The code above is an example of performing my request, however it is extremely inefficient. My goal is to be able to select a revision, and also the previous revision. For example, if my repository is at r185, but I want to view the file at revision 100, and also view the same file's previous revision (which I wouldn't know what is), how can this be done?

I've looked at c.GetInfo() but this seems to only get the previous revision to the most current commi开发者_如何学运维t.

Thanks!


Try only getting the versions you're looking for. I'm assuming log is an instance of SvnLoggingEventArgs?

If so, use:

args.Range = new SvnRevisionRange(log.Revision, log.Revision - 1);

That way you'll only retrieve the changes from that revision, and because log.Revision is guaranteed to be the revision number of the change, if you subtract one, you have the previous version.


Do you need the Previous version (the version before the last commit) or the local unmodified version.

The Subversion working copy library has the following 'magic' versions

Working    (SvnRevision.None)     - What you have in your working copy 
                                    (includes local modifications)

Head       (SvnRevision.Head)     - The last committed version of a url in the
                                    repository

Base       (SvnRevision.Base)     - The version you last committed or updated to.

Committed  (SvnRevision.Comitted) - The last revision <= BASE in which the path was
                                    modified

Previous   (SvnRevision.Previous) - The last revision before Committed.
                                    (Literally Committed-1)

To get one of these versions you can use SvnClient.Write()

using (SvnClient c = new SvnClient())
using (Stream to = File.Create(@"C:\temp\my.tmp"))
{
   c.Write(new SvnPathTarget(@"F:\projects\file.cs", SvnRevision.Base), to);
}

The files for Working and Base are available locally. For the other versions Subversion has to contact the repository.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜