Commits

Robert Jeppesen committed b791473

First working version. Still some work needed to be on par with C# version:
Parse repo argument
Specify alternate path to Hg.exe, when not in path

Comments (0)

Files changed (2)

TfsToHg/Program.fs

 
 let latestVersion = 0;
 
-let (|TFComment|) (x:string) = x.Substring(x.IndexOf("TF#") + 3).Trim()
- 
+let (|TFComment|TFMiss|) (x:string) = 
+   if x.Contains("TF") then
+     TFComment( x.Substring(x.IndexOf("TF#") + 3).Trim())
+   else TFMiss
+
 let printUsage = 
    let lines = [
       "TfsToHg";
       "";
       "Converts a single TFS branch changeset by changeset to a Mercurial repository";
       "";
-      "Usage: TfsToHg.exe [workingdir]";
+      "Usage: TfsToHg.exe command";
       "";
       "TfsToHg assumes that [workingdir] is in an hg repository and";
       "that it is also a TFS mapped workspace directory.";
    let logargs = "log -k TF# -l 1 --template \"{desc}\\n\""
    let comment = Process.Run(hg, logargs, workdir)
    let latest = match comment with 
-                | "" -> 1
-                | TFComment any -> System.Int32.Parse( any ) + 1
+                | TFComment(nr) -> System.Int32.Parse(nr) + 1
+                | TFMiss -> 1
 
    // Get TF history from last synced version onward
    let historyargs = "history \"" + workdir + "\" /format:detailed /noprompt /version:" + latest.ToString() + "~ /recursive /sort:ascending"
    let history = Process.Run(tf, historyargs, workdir)
-   let changesets = Changeset.parseHistory history
-   ()
+   let changesets = Changeset.parseHistory(history) |> Seq.sortBy (fun c -> c.Time) |> Seq.toArray
 
+   let total = changesets.Length;
+   printfn "Processing %i changesets" total
+
+   let mutable cnt = 0
+
+   for changeset in changesets do
+      let date = changeset.Time.ToString("s").Replace("T", " ")
+      let getargs = "get \"" + workdir + "\" /recursive /version:C" + changeset.Id + " /noprompt /overwrite";
+      let commitargs = "commit -A -y -m \"" + changeset.Comment + " TF#" + changeset.Id + "\" -u \"" + changeset.UserName + "\" -d \"" + date + "\"";
+      cnt <- cnt + 1
+      printfn "%i / %i : %s" cnt total changeset.Comment
+      
+      Process.Run(tf, getargs, workdir) |> ignore
+      Process.Run(hg, commitargs, workdir) |> ignore
 
 [<EntryPoint>]
 let main =
       | 1 -> printUsage; 0
       // By pairing up the op and number of arguments...
       | n -> match args.[1],n with
-             | "sync",2 -> PerformSync tfpath hgpath repodir; 0
+             | "sync",2 -> PerformSync ("\"" + tfpath + "\"") hgpath repodir; 0
              | "help",2 -> printUsage; 0
              | op,_       -> printfn "Invalid operation: %A" op; -1
 

TfsToHg/TfsToHg.fsproj

     <WarningLevel>3</WarningLevel>
     <PlatformTarget>x86</PlatformTarget>
     <DocumentationFile>bin\Debug\TfsToHg.XML</DocumentationFile>
+    <StartArguments>sync</StartArguments>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     <DebugType>pdbonly</DebugType>