public static ObjectHash WriteFixedTree(string vcsPath, Tree tree) { var resultingTreeLines = new List <Tree.TreeLine>(); bool fixRequired = false; foreach (var treeLine in tree.Lines) { if (!treeLine.IsDirectory()) { resultingTreeLines.Add(treeLine); continue; } var childTree = GitObjectFactory.ReadTree(vcsPath, treeLine.Hash); var fixedTreeHash = WriteFixedTree(vcsPath, childTree); resultingTreeLines.Add(new Tree.TreeLine(treeLine.TextBytes, fixedTreeHash)); if (fixedTreeHash != childTree.Hash) { fixRequired = true; } } if (fixRequired || Tree.HasDuplicateLines(resultingTreeLines)) { tree = Tree.GetFixedTree(resultingTreeLines); HashContent.WriteObject(vcsPath, tree); } return(tree.Hash); }
public static bool IsDefectiveTree(string vcsPath, Tree tree) { if (SeenTrees.TryGetValue(tree.Hash, out bool isDefective)) { return(isDefective); } if (Tree.HasDuplicateLines(tree.Lines)) { SeenTrees.TryAdd(tree.Hash, true); return(true); } var childTrees = tree.GetDirectories(); foreach (var childTree in childTrees) { if (SeenTrees.TryGetValue(childTree.Hash, out isDefective)) { if (isDefective) { return(true); } continue; } var childTreeObject = (Tree)GitObjectFactory.ReadGitObject(vcsPath, childTree.Hash); if (IsDefectiveTree(vcsPath, childTreeObject)) { return(true); } } SeenTrees.TryAdd(tree.Hash, false); return(false); }