﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on Challenge: Find the version</title><description>pb,
  
I will make no comment about TFS at this time.
</description><link>http://ayende.com/3210/challenge-find-the-version#comment10</link><guid>http://ayende.com/3210/challenge-find-the-version#comment10</guid><pubDate>Tue, 25 Mar 2008 07:30:57 GMT</pubDate></item><item><title>pb commented on Challenge: Find the version</title><description>What's up with this? A 2d return array that always has only one element in each array?
  
  
BranchRelative[][] branches =
  
                            SourceControlService.QueryBranches(serverUrl,
  
                                                               credentials,
  
                                                               null,
  
                                                               new ItemSpec[] { spec },
  
                                                               branchChangeset);
  
                        string oldName =
  
                            branches[0][branches[0].GetUpperBound(0)].BranchFromItem.item.Substring(rootPath.Length);
  
</description><link>http://ayende.com/3210/challenge-find-the-version#comment9</link><guid>http://ayende.com/3210/challenge-find-the-version#comment9</guid><pubDate>Tue, 25 Mar 2008 00:32:39 GMT</pubDate></item><item><title>Rik Hemsley commented on Challenge: Find the version</title><description>Wow, you incorporated my code quickly! ;)
  
</description><link>http://ayende.com/3210/challenge-find-the-version#comment8</link><guid>http://ayende.com/3210/challenge-find-the-version#comment8</guid><pubDate>Mon, 24 Mar 2008 19:58:21 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the version</title><description>Rik, take a look at:
  
http://www.codeplex.com/SvnBridge/SourceControl/FileView.aspx?itemId=94304&amp;changeSetId=17051
  
GetVersionForDate()
  
  
Amazing
</description><link>http://ayende.com/3210/challenge-find-the-version#comment7</link><guid>http://ayende.com/3210/challenge-find-the-version#comment7</guid><pubDate>Mon, 24 Mar 2008 19:56:07 GMT</pubDate></item><item><title>Rik Hemsley commented on Challenge: Find the version</title><description>I think I might now have the same worst case as yourself.
  
  
class TFSRepository
  
{
  
    private const TFSFirstRevisionId = 1; // Assumption.
  
  
    private DateTime initialRevisionDate;
  
  
    private DateTime InitialRevisionDate()
  
    {
  
        if (initialRevisionDate == null)
  
        {
  
             initialRevisionDate = sourceControl.QueryLog(
  
                 new ChangesetVersionSpec(TFSFirstRevisionId), 
  
                 new ChangesetVersionSpec(TFSFirstRevisionId),
  
                 1
  
            ).History[0].CommitDateTime;
  
        }
  
  
        return initialRevisionDate;
  
    }
  
  
    private void AssertRepositoryInitialized(int latestRevisionId)
  
    {
  
        if (latestRevisionId &lt; TFSFirstRevisionId)
  
            throw new RepositoryNotYetBornException();
  
    }
  
  
    private DateTime RevisionDateTime(int revisionId)
  
    {
  
        DateTime currentRevisionDate = sourceControl.QueryLog
  
        (
  
               new ChangesetVersionSpec(revisionId),
  
               new ChangesetVersionSpec(revisionId),
  
               1
  
        ).History[0].CommitDateTime;
  
    }
  
  
    public int GetVersionForDate(DateTime date)
  
    {
  
        int currentRevisionId = sourceControl.GetLatestId();
  
  
        AssertRepositoryInitialized(currentRevisionId);
  
  
        DateTime initialRevisionDateTime = RevisionDateTime(TFSFirstRevisionId);
  
  
        DateTime currentRevisionDateTime = RevisionDateTime(currentRevisionId);
  
  
       if (date &lt; InitialRevisionDateTime)
  
           throw new DateBeforeFirstRevisionException(date);
  
  
       if (date &gt; currentRevisionDateTime)
  
           throw new DateAfterCurrentRevisionException(date);
  
  
        return sourceControl.QueryLog
  
        (
  
            new DateVersionSpec(date),
  
            new ChangesetVersionSpec(currentRevisionDateTime),
  
        ).History[0].ChangeSetId - 1;
  
    }
  
}
</description><link>http://ayende.com/3210/challenge-find-the-version#comment6</link><guid>http://ayende.com/3210/challenge-find-the-version#comment6</guid><pubDate>Mon, 24 Mar 2008 19:46:07 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the version</title><description>In one case, it throw something useful (date before anything in the repos), in the other, it just do random things.
  
In your code, it would return the second most recent commit
</description><link>http://ayende.com/3210/challenge-find-the-version#comment5</link><guid>http://ayende.com/3210/challenge-find-the-version#comment5</guid><pubDate>Mon, 24 Mar 2008 19:15:12 GMT</pubDate></item><item><title>Rik Hemsley commented on Challenge: Find the version</title><description>Does it throw useful exceptions (e.g. something like DateRangeException rather than BadCallException)? If so, I'd be tempted to catch them and report them to the caller or user. It would be more 'correct' to ask TFS for the information first, but if cutting down on wire traffic (or new TCP connections - it can't be that bad, can it?) is that important then I think it's fair to break the "exceptions are for stuff you couldn't anticipate" rule.
  
  
I suppose the repository's first commit isn't going to change, so you can cache that, at least.
  
  
</description><link>http://ayende.com/3210/challenge-find-the-version#comment4</link><guid>http://ayende.com/3210/challenge-find-the-version#comment4</guid><pubDate>Mon, 24 Mar 2008 19:07:24 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the version</title><description>You are missing a couple of corner cases, yes.
  
Handling requests for dates before the repository started, and handling dates after the last commit.
  
Both would cause exceptions in the API
</description><link>http://ayende.com/3210/challenge-find-the-version#comment3</link><guid>http://ayende.com/3210/challenge-find-the-version#comment3</guid><pubDate>Mon, 24 Mar 2008 19:00:43 GMT</pubDate></item><item><title>Rik Hemsley commented on Challenge: Find the version</title><description>public int GetVersionForDate(DateTime date)
  
{
  
    return sourceControl.QueryLog
  
    (
  
        new DateVersionSpec(date),
  
        new ChangesetVersionSpec(DateTime.Now),
  
        1
  
    ).History[0].ChangeSetId - 1;
  
}
  
  
+ corner case handling
  
  
Is that only 1 call or am I overestimating the TFS API?
</description><link>http://ayende.com/3210/challenge-find-the-version#comment2</link><guid>http://ayende.com/3210/challenge-find-the-version#comment2</guid><pubDate>Mon, 24 Mar 2008 18:54:57 GMT</pubDate></item><item><title>Ravi Terala commented on Challenge: Find the version</title><description>Talk directly to the TFS cube instead?
</description><link>http://ayende.com/3210/challenge-find-the-version#comment1</link><guid>http://ayende.com/3210/challenge-find-the-version#comment1</guid><pubDate>Mon, 24 Mar 2008 17:39:15 GMT</pubDate></item></channel></rss>