public virtual ActionResult Commit(string account, string repository, string commit)
        {
            var model = new CommitViewModel();
            PopulateCommon(model, account, repository);

            model.Commit = _sourceControlManager.GetCommit(model.Project, commit);
            model.Commit = model.Commit;

            return View(model);
        }
        public async Task SetFilterAsync(RepositoryViewModel repositoryViewModel, string filterText)
        {
            if (string.IsNullOrEmpty(filterText))
            {
                List <Branch> preFilterBranches =
                    repositoryViewModel.PreFilterBranches?.ToList() ?? new List <Branch>();
                CommitViewModel preFilterSelectedItem = repositoryViewModel.PreFilterSelectedItem;
                repositoryViewModel.PreFilterBranches     = null;
                repositoryViewModel.PreFilterSelectedItem = null;

                var commit = repositoryViewModel.SelectedItem as CommitViewModel;
                if (commit != null && !preFilterBranches.Contains(commit.Commit.Branch))
                {
                    preFilterBranches.Add(commit.Commit.Branch);
                }
                else if (commit == null)
                {
                    repositoryViewModel.SelectedItem = preFilterSelectedItem;
                }

                repositoryViewModel.SpecifiedBranches = preFilterBranches;
                UpdateViewModel(repositoryViewModel);
            }
            else
            {
                Timing        t       = new Timing();
                List <Commit> commits = await GetFilteredCommitsAsync(filterText);

                t.Log($"Got filtered {commits.Count} commits");

                if (repositoryViewModel.PreFilterBranches == null)
                {
                    // Storing pre-filter mode state to be used when leaving filter mode
                    repositoryViewModel.PreFilterBranches     = repositoryViewModel.SpecifiedBranches;
                    repositoryViewModel.PreFilterSelectedItem = repositoryViewModel.SelectedItem as CommitViewModel;
                    repositoryViewModel.PreFilterSelectedItem = null;
                }

                Branch[] branches = new Branch[0];
                UpdateViewModel(repositoryViewModel, branches, commits);
            }
        }
Beispiel #3
0
        private void OnSelectedItemViewModelChanged(Ear <NodeItemViewModel> ear, NodeItemViewModel oldValue, NodeItemViewModel newValue)
        {
            if (newValue != null)
            {
                switch (newValue)
                {
                case CommitNodeItemViewModel commitNodeViewModel:
                    var commitViewModel = new CommitViewModel(ViewModel.Repository, commitNodeViewModel.Commit);
                    commitViewModel.Listen(x => x.SelectedFileContent).Then(() => ViewModel.SelectedFileContent = commitViewModel.SelectedFileContent);
                    commitView.ViewModel     = commitViewModel;
                    selectedItemView.Content = commitView;
                    break;

                case ChangesNodeItemViewModel changesNodeViewModel:
                    var changesViewModel = new ChangesViewModel(ViewModel.Repository, changesNodeViewModel.Status);
                    changesViewModel.Listen(x => x.SelectedFileContent).Then(() => ViewModel.SelectedFileContent = changesViewModel.SelectedFileContent);
                    changesView.ViewModel    = changesViewModel;
                    selectedItemView.Content = changesView;
                    break;
                }

                if (rightColumn.Width == new GridLength(0))
                {
                    var settings = Properties.Settings.Default;
                    splitterColumn.Width = new GridLength(5);
                    rightColumn.Width    = new GridLength(settings.RightSidebarWidth);
                }
            }
            else
            {
                if (rightColumn.Width != new GridLength(0))
                {
                    splitterColumn.Width = new GridLength(0);
                    rightColumn.Width    = new GridLength(0);
                }
            }
        }
        private void SetMerge(
            MergeViewModel merge,
            IReadOnlyCollection <BranchViewModel> branches,
            CommitViewModel childCommit,
            CommitViewModel parentCommit,
            bool isMerge = true)
        {
            BranchViewModel childBranch = branches
                                          .First(b => b.Branch == childCommit.Commit.Branch);
            BranchViewModel parentBranch = branches
                                           .First(b => b.Branch == parentCommit.Commit.Branch);

            if (isMerge)
            {
                childCommit.BrushInner = themeService.Theme.GetDarkerBrush(childCommit.Brush);
            }

            int childRow     = childCommit.RowIndex;
            int parentRow    = parentCommit.RowIndex;
            int childColumn  = childBranch.BranchColumn;
            int parentColumn = parentBranch.BranchColumn;

            bool isBranchStart = (childCommit.Commit.HasFirstParent &&
                                  childCommit.Commit.FirstParent.Branch != childCommit.Commit.Branch) ||
                                 (childCommit.Commit.Branch.IsLocalPart && parentCommit.Commit.Branch.IsMainPart);

            BranchViewModel mainBranch = childColumn >= parentColumn ? childBranch : parentBranch;

            int childX  = childCommit.X;
            int parentX = parentCommit.X;

            int x1 = childX <= parentX ? 0 : childX - parentX - 6;
            int y1 = 0;
            int x2 = parentX <= childX ? 0 : parentX - childX - 6;
            int y2 = Converters.ToY(parentRow - childRow) + Converters.HalfRow - 8;

            if (isBranchStart && x1 != x2)
            {
                y1 = y1 + 2;
                x1 = x1 + 2;
            }

            merge.ChildRow  = childRow;
            merge.ParentRow = parentRow;

            double y = (double)Converters.ToY(childRow);

            merge.Rect = new Rect(
                (double)Math.Min(childX, parentX) + 10,
                y + Converters.HalfRow,
                Math.Abs(childX - parentX) + 2 + (x1 == x2 ? 2 : 0),
                y2 + 2);
            merge.Width = merge.Rect.Width;

            merge.Line       = $"M {x1},{y1} L {x2},{y2}";
            merge.Brush      = mainBranch.Brush;
            merge.Stroke     = isBranchStart ? 2 : 1;
            merge.StrokeDash =
                (childCommit.Commit.Branch.IsLocalPart && parentCommit.Commit.Branch.IsMainPart) ||
                (parentCommit.Commit.Branch.IsLocalPart && childCommit.Commit.Branch.IsMainPart)
                                ? "1" : "";

            merge.NotifyAll();
        }
        public int ToggleMergePoint(RepositoryViewModel repositoryViewModel, Commit commit)
        {
            List <Branch> currentlyShownBranches = repositoryViewModel.SpecifiedBranches.ToList();

            BranchViewModel clickedBranch = repositoryViewModel
                                            .Branches.First(b => b.Branch == commit.Branch);

            Commit stableCommit = commit;

            if (commit.HasSecondParent && !currentlyShownBranches.Contains(commit.SecondParent.Branch))
            {
                // Showing the specified branch
                Log.Usage("Open branch");
                Track.Command("Open-Branch");
                Log.Info($"Open branch {commit.SecondParent.Branch}");
                currentlyShownBranches.Add(commit.SecondParent.Branch);
                if (commit.SecondParent.Branch.IsMainPart)
                {
                    currentlyShownBranches.Add(commit.SecondParent.Branch.LocalSubBranch);
                }
            }
            else
            {
                // Closing shown branch
                BranchViewModel otherBranch;

                if (commit.HasSecondParent &&
                    commit.SecondParent.Branch != commit.Branch &&
                    currentlyShownBranches.Contains(commit.SecondParent.Branch))
                {
                    otherBranch = repositoryViewModel.Branches
                                  .First(b => b.Branch == commit.SecondParent.Branch);

                    if (clickedBranch.BranchColumn > otherBranch.BranchColumn)
                    {
                        // Closing the branch that was clicked on since that is to the right
                        otherBranch  = clickedBranch;
                        stableCommit = commit.SecondParent;
                    }
                }
                else if (!commit.HasFirstChild ||
                         commit.Branch.TipCommit == commit)
                {
                    // A branch tip, closing the clicked branch
                    otherBranch = clickedBranch;
                    if (commit.Branch.HasParentBranch)
                    {
                        stableCommit = commit.Branch.ParentCommit;
                    }
                    else
                    {
                        Branch repositoryBranch = commit.Repository.Branches.First(b => b.Name == BranchName.Master && b.IsActive);

                        stableCommit = repositoryBranch.TipCommit;
                    }

                    if (clickedBranch.Branch.IsLocalPart)
                    {
                        otherBranch = repositoryViewModel
                                      .Branches.First(b => b.Branch == clickedBranch.Branch.MainbBranch);
                        stableCommit = otherBranch.Branch.ParentCommit;
                    }
                }
                else
                {
                    otherBranch = repositoryViewModel.Branches
                                  .First(b => b.Branch == commit.FirstParent.Branch);

                    if (clickedBranch.BranchColumn > otherBranch.BranchColumn)
                    {
                        // Closing the branch that was clicked on since that is to the right
                        otherBranch  = clickedBranch;
                        stableCommit = commit.FirstParent;
                    }
                }

                if (otherBranch.Branch.IsLocalPart)
                {
                    otherBranch = repositoryViewModel.Branches
                                  .First(b => b.Branch == otherBranch.Branch.MainbBranch);
                    stableCommit = otherBranch.Branch.ParentCommit;
                }

                Log.Usage("Close branch");
                Track.Command("Close-Branch");
                Log.Info($"Close branch {otherBranch.Branch}");
                IEnumerable <Branch> closingBranches = GetBranchAndDescendants(
                    currentlyShownBranches, otherBranch.Branch);

                currentlyShownBranches.RemoveAll(b => b.Name != BranchName.Master && closingBranches.Contains(b));
            }

            CommitViewModel stableCommitViewModel = repositoryViewModel.CommitsById[stableCommit.Id];

            int currentRow = stableCommitViewModel.RowIndex;

            repositoryViewModel.SelectedIndex     = currentRow;
            repositoryViewModel.SpecifiedBranches = currentlyShownBranches;
            UpdateViewModel(repositoryViewModel);

            CommitViewModel newCommitViewModel = repositoryViewModel.CommitsById[stableCommit.Id];

            int newRow = newCommitViewModel.RowIndex;

            Log.Debug($"Row {currentRow}->{newRow} for {stableCommit}");

            return(currentRow - newRow);
        }
Beispiel #6
0
 public MergeWindow(Guid repositoryId)
 {
     InitializeComponent();
     DataContext = new CommitViewModel(repositoryId);
 }
Beispiel #7
0
 public CommitWindow(Guid id)
 {
     InitializeComponent();
     DataContext = new CommitViewModel(id);
 }
Beispiel #8
0
        public IHttpActionResult GetCommits()
        {
            CommitViewModel vm;
            UnitOfWork      unitOfWork = null;

            System.Diagnostics.Trace.TraceInformation("Get Commits");

            try
            {
                unitOfWork = new UnitOfWork();

                var         parameters = this.Request.GetQueryNameValuePairs();
                CommitQuery query      = new CommitQuery(unitOfWork.Context.Commits);
                var         keyword    = parameters.FirstOrDefault(p => p.Key == "keyword").Value;

                if (string.IsNullOrEmpty(keyword) == false)
                {
                    query.Keyword         = parameters.FirstOrDefault(p => p.Key == "keyword").Value;
                    query.ExcludeApproved = false;
                }
                else
                {
                    query.ExcludeApproved = true;
                }

                query.Max           = ParseNullable <int>(parameters.FirstOrDefault(p => p.Key == "max").Value);
                query.IncludeAuthor = parameters.FirstOrDefault(p => p.Key == "include").Value;
                query.ExcludeAuthor = parameters.FirstOrDefault(p => p.Key == "exclude").Value;

                var list = new List <Tuple <Commit, CommitStats> >();
                foreach (var commit in query.Execute())
                {
                    var comments = unitOfWork.Context.Comments.Where(c => c.Revision == commit.Revision);

                    var replies = comments.Where(c => c.User == commit.Author);
                    var reviews = comments.Where(c => c.User != commit.Author);

                    var stats = new CommitStats(
                        reviews.Select(c => c.User).Distinct().Count(),
                        reviews.Count(),
                        replies.Count());

                    list.Add(new Tuple <Commit, CommitStats>(commit, stats));
                }
                vm = new CommitViewModel(list);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError("GetRevision: " + ex);
                return(InternalServerError(ex));
            }
            finally
            {
                if (unitOfWork != null)
                {
                    unitOfWork.Dispose();
                }
            }

            return(Ok(vm));  // try catch?
        }