public static IEnumerable <IPackage> Create(params string[] paths) { var repos = new Dictionary <string, GitRepo>(StringComparer.OrdinalIgnoreCase); foreach (var path in paths) { if (path.StartsWith("git://", StringComparison.OrdinalIgnoreCase)) { var query = new QueryString("file://" + path.Substring(6)); var filePath = query.Uri.LocalPath; if (!repos.TryGetValue(filePath, out var repo)) { repo = new GitRepo(filePath); repos[filePath] = repo; } var options = new GitDirectorySearch() { Sha = query["commit"].ToString(), Path = query["path"].ToString() }; foreach (var branch in query["branch"]) { options.BranchNames.Add(branch); } if (string.Equals(options.Sha, "tip", StringComparison.OrdinalIgnoreCase)) { options.Sha = null; } yield return(repo.GetDirectory(options)); } else if (string.Equals(Path.GetExtension(path), ".innpkg", StringComparison.OrdinalIgnoreCase)) { var isFile = false; using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var bytes = new byte[4]; if (stream.Read(bytes, 0, 4) == 4 && BitConverter.ToInt32(bytes, 0) == ZIP_LEAD_BYTES) { isFile = true; } } yield return(isFile ? new ZipPackage(path) : new DirectoryPackage(path)); } else if (string.Equals(Path.GetExtension(path), ".mf", StringComparison.OrdinalIgnoreCase)) { yield return(new DirectoryPackage(Path.GetDirectoryName(path))); } else { yield return(new DirectoryPackage(path)); } } }
public IPackage GetDirectory(GitDirectorySearch options) { var commit = default(Commit); if (!string.IsNullOrEmpty(options.Sha)) { commit = _repo.Commits.Single(c => c.Sha.StartsWith(options.Sha)); } else if (options.BranchNames.Count == 1) { commit = _repo.Branches[options.BranchNames.First()].Tip; } else if (options.BranchNames.Count > 1) { commit = MostRecentCommonAncestor(options.BranchNames); } else { commit = _repo.Head.Tip; } return(new GitPackage(_repo, commit, options.Path)); }