SharpSvn Tips http://sharpsvntips.net Most recent posts at SharpSvn Tips posterous.com Sun, 03 Jul 2011 12:13:00 -0700 Retrieving changed paths http://sharpsvntips.net/retrieving-changed-paths http://sharpsvntips.net/retrieving-changed-paths

Retrieving what files where added / deleted / changed in a certain revision can be determined using SvnClient.Log()

using (SvnClient client = new SvnClient())
{
    client.Log(
        reposUri,
        new SvnLogArgs {Range = new SvnRevisionRange(9999, 9999)},
        (o, e) =>
            {
                foreach (SvnChangeItem changeItem in e.ChangedPaths)
                {
                    Console.WriteLine(
                        string.Format(
                            "{0} {1} {2} {3}",
                            changeItem.Action,
                            changeItem.Path,
                            changeItem.CopyFromRevision,
                            changeItem.CopyFromPath));
                }
            });
}

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Tue, 21 Jun 2011 13:17:00 -0700 When/why to SvnClient.LoadConfiguration http://sharpsvntips.net/whenwhy-to-svnclientloadconfiguration http://sharpsvntips.net/whenwhy-to-svnclientloadconfiguration

SvnClient.LoadConfig​urationDefault() (just like svn.exe) assumes the user’s registry hive is always available (e.g. it can read from HKEY_CURRENT_USER). It uses a few windows api calls on retrieving which directory to use for the settings.

When running a website, or another service or similar cases where there is a ‘current user’ but the full user profile hasn’t been loaded, the call can fail after a timeout.

Using .LoadConfiguration(​<path>) skips these procedures as it says: Only load these settings. (+– equivalent to using --config-dir <path> on svn.exe)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Wed, 03 Nov 2010 12:41:41 -0700 Retrieving multiple versions of a file http://sharpsvntips.net/post/1470118738/retrieving-multiple-versions-of-a-file http://sharpsvntips.net/post/1470118738/retrieving-multiple-versions-of-a-file

You can use the client.FileVersions() command to retrieve multiple version of the same file. This fetches one complete file, and all other files using the differences between each revision in a single connection. This should give much better performance than retrieving all files individually with client.Write()

public void WriteRevisions(SvnTarget target,
                           SvnRevision from,
                           SvnRevision to)
{
    using(SvnClient client = new SvnClient())
    {
        SvnFileVersionsArgs ea = new SvnFileVersionsArgs 
            {
                Start = from,
                End = to
            };

        client.FileVersions(target, ea,
            (s, e) =>
                {
                    Debug.WriteLine(e.Revision);
                    e2.WriteTo(...);
                });
    }
}

See method WalkMe (and others) in this testcase to see more details about its usage (Username guest, no password).

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Wed, 27 Oct 2010 11:15:00 -0700 Undoing changes from a revision http://sharpsvntips.net/post/1414181004/undoing-changes-from-a-revision http://sharpsvntips.net/post/1414181004/undoing-changes-from-a-revision

If there’s a need to revert changes that were made to in a certain revision or revision range, you need to perform a reverse merge. The basic idea is to reverse the start and end revisions, causing a merge that’s the opposite of the revision itself.

(Reverse) merging can be done with the Merge method. Passing the revision range is done with SvnRevisionRange. For a reverse merge, make sure the startRevision is larger than the endRevision. To undo revision 123, you want to pass (123, 122)

To undo a file in the working copy:

var range = new SvnRevisionRange(revision, revision - 1);
client.Merge(path, path, range);

This means that to undo all changes (ie go back to the state at revision, you can use:

var range = new SvnRevisionRange(SvnRevision.Working, revision);

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Tue, 26 Oct 2010 11:41:00 -0700 Creating your own custom Subversion management layer http://sharpsvntips.net/2009/10/creating-your-own-custom-subversion.html http://sharpsvntips.net/2009/10/creating-your-own-custom-subversion.html http://www.troyhunt.com/2009/10/creating-your-own-custom-subversion.html

Using SharpSvn and VisualSvn Server to create a management interface

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Mon, 25 Oct 2010 07:56:00 -0700 Changing the svn:author property for a revision http://sharpsvntips.net/post/1397302704/changing-the-svn-author-property-for-a-revision http://sharpsvntips.net/post/1397302704/changing-the-svn-author-property-for-a-revision

The author for each Subversion revision is stored in the svn:author revision property. To change this afterwards, you can use SetRevisionProperty. You also need to make sure that making changes like this one is allowed in the pre-revprop-change repository hook.

using (SvnClient client = new SvnClient())
{
    client.SetRevisionProperty(new Uri("http://my/repository"), 12345,
                              SvnPropertyNames.SvnAuthor,
                              "MyName");
}

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Sun, 24 Oct 2010 08:41:36 -0700 SVN – Sub-Directory Renames via C# http://sharpsvntips.net/2010/08/11/svn-sub-directory-renames-via-c http://sharpsvntips.net/2010/08/11/svn-sub-directory-renames-via-c http://gregorbowie.wordpress.com/2010/08/11/svn-sub-directory-renames-via-c/

Nice application of SharpSvn to automate a simple task that can avoid lots of manual labour

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Sat, 23 Oct 2010 09:28:00 -0700 Getting file content from repository (in memory) http://sharpsvntips.net/post/1380066141/getting-file-content-from-repository-in-memory http://sharpsvntips.net/post/1380066141/getting-file-content-from-repository-in-memory

It’s possible to retrieve files from the repository, and accessing the contents of these files without the need for temp files. To do this, SvnClient.Write can be used:

public void ReadContents(
                         Url url, 
                         Stream stream, 
                         long? revision=null)
{
    // Use the HEAD version when the revision param
    // wasn't specified
    var target = revision == null
        ? new SvnUriTarget(url, SvnRevisionType.Head)
        : new SvnUriTarget(url, revision);

    client.Write(target, stream);
}

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Fri, 22 Oct 2010 08:41:13 -0700 SharpSvn: A Primer http://sharpsvntips.net/2010/03/sharpsvn-a-primer/trackback http://sharpsvntips.net/2010/03/sharpsvn-a-primer/trackback http://merill.net/2010/03/sharpsvn-a-primer/trackback/

Great getting started article

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Thu, 14 Oct 2010 05:18:00 -0700 GetStatus and Status http://sharpsvntips.net/post/1312684793/getstatus-and-status http://sharpsvntips.net/post/1312684793/getstatus-and-status

This post will go into how to use GetStatus and Status.

The GetStatus methods retrieve the status for the file(s) and directory(s) specified. This is similar to running svn status on the command line.

GetStatus(String path, 
          out Collection<SvnStatusEventArgs> statuses)
GetStatus(String path, 
          SvnStatusArgs args, 
          Collection(SvnStatusEventArgs) statuses)

With this call you pass in a path and optional args, and it will run a recursive status on that path. The path needs to be a valid working copy. The statuses that are encountered during the scan are added to the collection.

You can check the properties of SvnStatusEventArgs to determine the dir/file and its Subversion status. The properties prefixed with Remote are only valid when you’re doing a remote status.

Example:

Collection<SvnStatusEventArgs> statuses;
client.GetStatus(path, statuses);
foreach(SvnStatusEventArgs arg in statuses)
{
    Console.WriteLine(arg.LocalContentStatus +
                      " - " + arg.FullPath);
}

To execute a remote status, you need to use the overload with the StatusArgs parameter, and set the ContactRepository property to true:

Collection<SvnStatusEventArgs> statuses;
client.GetStatus(path, 
                 new SvnStatusArgs
                 {
                     ContactRepository = true
                 },
                 statuses);
foreach(SvnStatusEventArgs arg in statuses)
{
    Console.WriteLine("Remote status: " + 
                      arg.RemoteContentStatus + 
                      " - " + arg.FullPath);
}

As a general rule in SharpSvn, the Command methods execute the command and call an event handler every time a status is found in this case, whereas the GetCommand calls wait until all statuses are retrieved, adding them to the collection out parameter. It’s using an out parameter because the exception throwing can be (partially) disabled, making the function return false when something went wrong.

For example:

client.Status(
    String path, 
    (sender, ea)
    {
        Console.WriteLine(ea.LocalContentStatus +
                          " - " + ea.FullPath);
    });

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken
Wed, 13 Oct 2010 20:40:51 -0700 SvnEventArgs.Detach: when to call? http://sharpsvntips.net/post/1314861830/svneventargs-detach-when-to-call http://sharpsvntips.net/post/1314861830/svneventargs-detach-when-to-call

When using the SvnClient methods that take an EventHandler instead of an out parameter with collection (the Get* methods), properties are not marshaled from unmanaged code to .NET by default (for performance reasons). If you’re filtering on just a single property of a class derived from SvnEventArgs that has lots of properties with lots of data in it, it hurts performance to marshal all properties to managed code.

The problem is that it’s only allowed to marshal the data from unmanaged to managed while the command is running, so this code will result in invalid objects in the unversionedStatuses list. The LocalContentStatus will be valid, because that has already been marshaled because it’s evaluated in the if statement.

List<SvnStatusEventArgs> unversionedStatuses = 
    new List<SvnStatusEventArgs>();

client.Status(workingCopyPath, (o, e) =>
{
    if(e.LocalContentStatus == SvnStatus.NotVersioned)
    {
        unversionedStatuses.Add(e);
    }
});

To fix this, call Detach inside the event handler. Detach marshals all data to the managed object (like GetStatus would do).

client.Status(workingCopyPath, (o, e) =>
{
    if(e.LocalContentStatus == SvnStatus.NotVersioned)
    {
        e.Detach();
        unversionedStatuses.Add(e);
    }
});

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/hesAXxyWQMrWi srijken srijken srijken