Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/SantaClaas/fun-with-git. Playing around with git and fsharp
Something went wrong. Try again.
4.7 kB · 145 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146open System.Collections.Genericopen System.IOopen System.Textopen FunWithGitopen LibGit2Sharpopen System
// let buildGraph () =// use repository = new Repository("../electron-api-demos")
// //// // let rec prong (commit : Commit) count =// // // Get first parent under commit// // // Is parent next commit in line ->// // let parents = commit.Parents |> Array.ofSeq// // printfn "%s %i" commit.MessageShort parents.Length// // if count > 20 then// // ()// // else// // prong parents[0] (count + 1)// // // printfn "commit %s"
// // prong repository.Head.Tip 0
// repository.Commits |> Seq.take 100 |> Seq.iter (printfn "%A")
// let isSameBranch (current: Commit) (next: Commit) =// let parent = current.Parents |> Seq.head// parent = next
// let poop (repository: Repository) =
// let enumerator = repository.Commits.GetEnumerator()
// // If next is parent then we are on the same branch// // If next is not parent then we need to start a new branch
// let rec createRow iterationNumber previousLaneIndex (enumerator : Commit IEnumerator) =
// let current = enumerator.Current
// let laneIndex = if isSameBranch current next then previousLaneIndex else previousLaneIndex + 1// let row = Array.create (laneIndex + 1) false// row[laneIndex] <- true// if not (enumerator.MoveNext()) || iterationNumber = 100 then// [row]// else// let next = enumerator.Current// row :: createRow (iterationNumber + 1) laneIndex enumerator
// ()
// for branch in repository.Branches do// printfn "B %s" branch.FriendlyName
// // repository.Commits.QueryBy(CommitFilter())// // |> Seq.take 100// // |> Seq.map (fun commit -> commit.MessageShort, commit.Parents |> Seq.length)// // |> Seq.iter (printfn "%A")
// printfn "Complete"// ()
let paths = [| Path.Combine(__SOURCE_DIRECTORY__, "../auster") Path.Combine(__SOURCE_DIRECTORY__, "../electron-api-demos") |]// buildGraph()use repository = new Repository(paths[1])//// let limit = 100////// let commits =// // repository.Commits.QueryBy(CommitFilter()) |> Seq.take limit |> Array.ofSeq// repository.Commits.QueryBy(CommitFilter()) |> Seq.take limit |> Array.ofSeq// // Can not get a list of all commits in chronological order// let orderedBranches = repository.Branches |> Array.ofSeq |> Array.filter (fun branch -> not branch.IsRemote) |> Array.sortByDescending (fun branch -> branch.Tip.Committer.When)// orderedBranches |> Array.iter (fun branch -> printfn $"%A{branch.FriendlyName} {branch.CanonicalName}")////// let mutable lanes = [ (0, 0) ]// let mutable activeLane = 0//// for index = 0 to orderedBranches.Length - 1 do// let branch = orderedBranches[index]// ()//// let isSameBranch firstParent (next: Commit) = firstParent = next//// let builder = StringBuilder()//// // Branch counts represent the current amount of branches from top to bottom. So merge commits create new branches and splits close them.// let mutable branchCount = 0////// for index = 0 to limit - 1 do// let commit = commits[index]// let parents = commit.Parents |> Array.ofSeq//// let isMergeCommit = parents |> Array.length |> (<) 1//// if isMergeCommit then// branchCount <- branchCount + 1//// if index + 1 = limit || isSameBranch parents[0] commits[index + 1] then// let row = String.replicate branchCount " "// builder.Append(row).Append("|").AppendLine() |> ignore// else// branchCount <- branchCount + 1// let row = String.replicate branchCount " "// builder.Append(row).Append("|").AppendLine() |> ignore////// Console.WriteLine(builder.ToString())//////////let commits = CommitGraph.listCommits repository |> Seq.take 10 |> Seq.toArray
let sorted = CommitGraph.sortTemporalTopological commitslet coordinates = CommitGraph.curvedBranches sorted |> Seq.toArraylet maxX, _, _ = coordinates |> Array.maxBy (fun (x, _, _) -> x)let _, maxY, _ = coordinates |> Array.maxBy (fun (_, y, _) -> y)let grid = Array2D.create (maxX + 1) (maxY + 1) Nonefor x, y, commit in coordinates do Array2D.set grid x y (Some commit)
printfn $"{grid}"