anchor.diff:  #nowarn "49"
   
   open System
  +open System.IO
   open System.Text.RegularExpressions
   open Fake
   open Fake.AssemblyInfoFile
  
positive.code:             if lastVersion.Major <> baseVersion.Major || lastVersion.Minor <> baseVersion.Minor then
                  0u
              else
                  let head = Git.Information.getCurrentSHA1 "."
                  let tagged =
                      match tag with
                      | Some tag -> Git.Branches.getSHA1 "." ("refs/tags/" + tag)
                      | None -> head
                  if head = tagged then
                      lastVersion.Patch
  
negative.code:     | [] -> None
      | l -> Some (List.max l)
  
  let shell program cmd =
      Printf.kprintf (fun cmd ->
          shellExec {
              Program = program
              WorkingDirectory = "."
              CommandLine = cmd
              Args = []
          }
          |> function
              | 0 -> ()
              | n -> failwithf "%s %s failed with code %i" program cmd n
      ) cmd
  
  let shellOut program cmd =
      Printf.kprintf (fun cmd ->
          let psi =
              System.Diagnostics.ProcessStartInfo(
                  FileName = program,
                  Arguments = cmd,
                  RedirectStandardOutput = true,
                  UseShellExecute = false
              )
          let proc = System.Diagnostics.Process.Start(psi)
          let out = proc.StandardOutput.ReadToEnd()
          proc.WaitForExit()
          match proc.ExitCode with
          | 0 -> out
          | n -> failwithf "%s %s failed with code %i" program cmd n
      ) cmd
  
  let git cmd =
      Printf.kprintf (fun s ->
          logfn "> git %s" s
          Git.CommandHelper.directRunGitCommandAndFail "." s
      ) cmd
  
  let hg cmd = shell "hg" cmd
  let hg' cmd = shellOut "hg" cmd
  
  let private splitLines (s: string) =
      s.Split([| "\r\n"; "\n" |], StringSplitOptions.None)
  
  module Hg =
      let getBookmarks() =
          hg' """bookmark -T "{bookmark} {node|short}\n" """
          |> splitLines
          |> Array.map (fun s -> s.Split(' ').[0])
  
      let getCurrentCommitId() =
          (hg' "id -i").Trim()
  
      let commitIdForBookmark (b: string) =
          hg' """bookmark -T "{bookmark} {node|short}\n" """
          |> splitLines
          |> Array.pick (fun s ->
              let a = s.Split(' ')
              if a.[0] = b then Some a.[1] else None
          )
  
      let branchExists (b: string) =
          hg' "branches -T {branch}"
          |> splitLines
          |> Array.contains b
  
      let isAncestorOfCurrent (ref: string) =
          let currentRef = getCurrentCommitId()
          let o = hg' """log --rev "ancestors(.) and %s" """ ref
          not (String.IsNullOrWhiteSpace o)
  
  module VC =
      let isGit = Directory.Exists ".git"
  
      let getTags() =
          if isGit then
              let ok, out, err = Git.CommandHelper.runGitCommand "." "tag --merged"
              out.ToArray()
          else
              Hg.getBookmarks()
  
      let getCurrentCommitId() =
          if isGit then
              Git.Information.getCurrentSHA1 "."
          else
              Hg.getCurrentCommitId()
  
      let commitIdForTag tag =
          if isGit then
              Git.Branches.getSHA1 "." ("refs/tags/" + tag)
          else Hg.commitIdForBookmark tag
  
  let ComputeVersion (baseVersion: option<Paket.SemVerInfo>) =
      let lastVersion, tag =
          try
              let tags = VC.getTags()
              let re = Regex("""^(?:[a-zA-Z]+[-.]?)?([0-9]+(?:\.[0-9]+){0,3})(?:-.*)?$""")
              match tags |> Array.choose (fun tag ->
                  try
                      let m = re.Match(tag)
                      if m.Success then
                          let v = m.Groups.[1].Value |> Paket.SemVer.Parse
                          Some (v, Some tag)
                      else None
                  with _ -> None) with
              | [||] ->
                  traceImportant "Warning: no latest tag found"
                  Paket.SemVer.Zero, None
  