private static TreeDefinition CreateTreeFromDirectoryCore(string path, ObjectDatabase objectDatabase, TreeDefinition treeDefinition, Func <string, string> convertToGitPath) { foreach (string filePath in Directory.GetFiles(path)) { var gitPath = convertToGitPath(filePath); using (var fs = File.OpenRead(filePath)) { var blob = objectDatabase.CreateBlob(fs, gitPath); var mode = GetFileModeForPath(filePath); treeDefinition = treeDefinition.Add(gitPath, blob, mode); } } foreach (string subPath in Directory.GetDirectories(path)) { treeDefinition = CreateTreeFromDirectoryCore(subPath, objectDatabase, treeDefinition, convertToGitPath); } return(treeDefinition); }
/// <summary> /// Creates a TreeDefinition from the state of the Workspace object. /// </summary> public static Tree CreateTreeFromWorkspace(Workspace workspace, string workspacePath, ObjectDatabase objectDatabase) { var treeDefinition = new TreeDefinition(); var itemSpec = new ItemSpec(workspacePath, RecursionType.Full); var allItems = workspace.GetItems(new[] { itemSpec }, DeletedState.NonDeleted, ItemType.File, generateDownloadUrls: false, getItemsOptions: GetItemsOptions.LocalOnly); Release.Assert(allItems.Length == 1); foreach (var item in allItems[0].Items) { var filePath = item.LocalItem; var gitPath = filePath.Substring(workspacePath.Length + 1); gitPath = gitPath.Replace('\\', '/'); using (var fs = File.OpenRead(filePath)) { var blob = objectDatabase.CreateBlob(fs, gitPath); var mode = GetFileModeForPath(filePath); treeDefinition = treeDefinition.Add(gitPath, blob, mode); } } return(objectDatabase.CreateTree(treeDefinition)); }