Challenge: Find the version
Okay, here is something that I had to deal with today. I had to implement the dated-rev-report command in SvnBridge. This command sends a date to the server, and get the first revision id that was committed before to that date. Because code is unambiguous, if we were using SQL, it would have been:
CREATE PROC DatedRevReport @requestedDate DATETIME AS SELECT TOP 1 RevisionId FROM Revisions WHERE CommittedDate < @requestedDate ORDER BY CommittedDate DESC
Simple, right? Except that the interface that I have to TFS is not SQL (and I would be pretty sad if it was, so that is a good thing). I have to go through the TFS API in order to get that result.
Here is the API that I have to work with (actually, that is a drastically simplified API, but it contains all the stuff required to solve this issue).
public interface ISourceControl { int GetLatestId(); LogItem QueryLog(VersionSpec from, VersionSpec to, int countToReturn); } public class LogItem { public SourceItemHistory[] History; } public class History { public int ChangeSetId; public DateTime CommitDateTime; } public class DateVersionSpec : VersionSpec { public DateTime Date; } public class ChangesetVersionSpec : VersionSpec { public int ChangesetId; }
Your task, if you agree to accept it, is to build implement the following method:
public int GetVersionForDate(DateTime date) { // your implementation here }
One important consideration is that you should reduce remote calls. I managed to get it down to 4 remote calls for the worst case scenario. It could have been 3, but TFS has some... finicky date handling.
So, how would you solve the issue?
Comments
Talk directly to the TFS cube instead?
public int GetVersionForDate(DateTime date)
{
}
Is that only 1 call or am I overestimating the TFS API?
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
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.
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
I think I might now have the same worst case as yourself.
class TFSRepository
{
}
Rik, take a look at:
http://www.codeplex.com/SvnBridge/SourceControl/FileView.aspx?itemId=94304&changeSetId=17051
GetVersionForDate()
Amazing
Wow, you incorporated my code quickly! ;)
What's up with this? A 2d return array that always has only one element in each array?
BranchRelative[][] branches =
pb,
I will make no comment about TFS at this time.