예제 #1
0
        public List <Branch> GetBranches(string repositoryPath)
        {
            List <Branch> branches = new List <Branch>();

            using (GitRepository gitRepositoryInfo = new GitRepository(repositoryPath))
            {
                GitBranch headBranch = null;
                gitRepositoryInfo.Branches.ForEach(branch =>
                {
                    if (branch.IsRemote)
                    {
                        return;
                    }
                    if (headBranch == null || headBranch.Commits.Count() < branch.Commits.Count())
                    {
                        headBranch = branch;
                    }
                });

                List <Commit> commits = GetCommits(headBranch, repositoryPath);

                gitRepositoryInfo.Branches.ForEach(branch =>
                {
                    if (branch.IsRemote)
                    {
                        return;
                    }
                    Branch branchInstance = new Branch()
                    {
                        Name = branch.FriendlyName
                    };

                    var uniqueCommits = branch.Commits.Where(c => commits.All(c1 => c1.Revision != c.Sha));
                    var enumerable    = uniqueCommits as IList <GitCommit> ?? uniqueCommits.ToList();
                    if (enumerable.Any())
                    {
                        enumerable.ForEach(uCommit =>
                        {
                            var newCommit = GetCommitFromGitCommit(uCommit, repositoryPath);
                            branchInstance.AddCommit(newCommit);
                        });
                    }

                    commits.ForEach(commit =>
                    {
                        if (branch.Commits.Any(c => c.Sha == commit.Revision))
                        {
                            branchInstance.AddCommit(commit);
                        }
                    });
                    branches.Add(branchInstance);
                });
            }
            return(branches);
        }
        public List <Branch> GetBranches(string path)
        {
            List <Branch> branches = new List <Branch>();
            string        branchesPath;

            if (path.EndsWith("/"))
            {
                branchesPath = path + "branches";
            }
            else
            {
                branchesPath = path + "/branches";
            }
            //key-key : path, key-value : fullPath, value: count of revisions
            Dictionary <KeyValuePair <string, string>, int> branchesPathes = new Dictionary <KeyValuePair <string, string>, int>();

            using (SvnClient svnClient = new SvnClient())
            {
                Collection <SvnListEventArgs> contents;
                if (svnClient.GetList(new Uri(branchesPath), out contents))
                {
                    contents.ForEach(content =>
                    {
                        string name     = !string.IsNullOrEmpty(content.Path) ? content.Path : "trunk";
                        string fullPath = ZetaLongPaths.ZlpPathHelper.Combine(branchesPath, content.Path);
                        branchesPathes.Add(new KeyValuePair <string, string>(name, fullPath), GetCountOfCommitsInBranch(fullPath));
                    });
                }

                Dictionary <KeyValuePair <string, string>, int> orderedPathes =
                    branchesPathes.OrderByDescending(p => p.Value)
                    .ToDictionary(p => new KeyValuePair <string, string>(p.Key.Key, p.Key.Value), p => p.Value);
                if (orderedPathes.Any())
                {
                    string        headPath    = orderedPathes.First().Key.Value;
                    List <Commit> headCommits = GetCommits(headPath);
                    foreach (var branch in branchesPathes)
                    {
                        List <Commit> commitItems = GetCommits(branch.Key.Value, headCommits);
                        Branch        branchItem  = new Branch()
                        {
                            Name = branch.Key.Key,
                            Path = branch.Key.Value
                        };
                        commitItems.ForEach(commitItem => branchItem.AddCommit(commitItem));
                        branches.Add(branchItem);
                    }
                }
            }

            return(branches);
        }