/// <inheritdoc/>
        public bool ShowDeleteInvalidRepositoryDialog(string repositoryPath)
        {
            int invalidPathCount = ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Locals.LoadRecentHistoryAsync())
                                   .Count(repo => !VsrModule.IsValidVersionrWorkingDir(repo.Path));
            string commandButtonCaptions = Strings.RemoveSelectedInvalidRepository;

            if (invalidPathCount > 1)
            {
                commandButtonCaptions =
                    string.Format("{0}|{1}", commandButtonCaptions, string.Format(Strings.RemoveAllInvalidRepositories, invalidPathCount));
            }

            int dialogResult = PSTaskDialog.cTaskDialog.ShowCommandBox(
                Title: Strings.Open,
                MainInstruction: Strings.DirectoryInvalidRepository,
                Content: "",
                CommandButtons: commandButtonCaptions,
                ShowCancelButton: true);

            if (dialogResult < 0)
            {
                /* Cancel */
                return(false);
            }
            else if (PSTaskDialog.cTaskDialog.CommandButtonResult == 0)
            {
                /* Remove selected invalid repo */
                ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Locals.RemoveRecentAsync(repositoryPath));
            }
            else if (PSTaskDialog.cTaskDialog.CommandButtonResult == 1)
            {
                /* Remove all invalid repos */
                ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Locals.RemoveInvalidRepositoriesAsync(repoPath => VsrModule.IsValidVersionrWorkingDir(repoPath)));
            }

            return(true);
        }
Ejemplo n.º 2
0
        private async Task ExecuteAsync(
            VsrModule module,
            IReadOnlyList <IGitRef> refs,
            IObserver <GitRevision> subject,
            RefFilterOptions refFilterOptions,
            string branchFilter,
            string revisionFilter,
            string pathFilter,
            [CanBeNull] Func <GitRevision, bool> revisionPredicate)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var token = _cancellationTokenSequence.Next();

            var revisionCount = 0;

            await TaskScheduler.Default;

            token.ThrowIfCancellationRequested();

            var branchName = module.IsValidVersionrWorkingDir()
                ? module.GetSelectedBranch()
                : "";

            token.ThrowIfCancellationRequested();

            UpdateSelectedRef(module, refs, branchName);
            var refsByObjectId = refs.ToLookup(head => head.ObjectId);

            token.ThrowIfCancellationRequested();

            var arguments = BuildArguments(refFilterOptions, branchFilter, revisionFilter, pathFilter);

#if TRACE
            var sw = Stopwatch.StartNew();
#endif

            var versions = module.GetLog(1000); // TODO: VSR - limit is in revisionFilter variable

            foreach (var version in versions)
            {
                token.ThrowIfCancellationRequested();

                var revision = new GitRevision(new ObjectId(version.ID))
                {
                    ParentIds           = version.Parent.HasValue ? new[] { new ObjectId(version.Parent.Value) } : null,
                    TreeGuid            = null, // TODO: VSR
                    Author              = version.Author,
                    AuthorEmail         = version.Email,
                    AuthorDate          = version.Timestamp, // TODO: VSR
                    Committer           = version.Author,    // TODO: VSR
                    CommitterEmail      = version.Email,     // TODO: VSR
                    CommitDate          = version.Timestamp,
                    MessageEncoding     = null,              // TODO: VSR
                    Subject             = version.Message,
                    Body                = version.Message,   // TODO: VSR
                    Name                = version.ShortName, // TODO: VSR
                    HasMultiLineMessage = false,             // TODO: VSR - !ReferenceEquals(Subject, Body),
                    HasNotes            = false
                };

                if (revisionPredicate == null || revisionPredicate(revision))
                {
                    // The full commit message body is used initially in InMemFilter, after which it isn't
                    // strictly needed and can be re-populated asynchronously.
                    //
                    // We keep full multiline message bodies within the last six months.
                    // Commits earlier than that have their properties set to null and the
                    // memory will be GCd.
                    if (DateTime.Now - revision.AuthorDate > TimeSpan.FromDays(30 * 6))
                    {
                        revision.Body = null;
                    }

                    // Look up any refs associated with this revision
                    revision.Refs = refsByObjectId[revision.ObjectId].AsReadOnlyList();

                    revisionCount++;

                    subject.OnNext(revision);
                }
            }

            // This property is relatively expensive to call for every revision, so
            // cache it for the duration of the loop.
            var logOutputEncoding = module.LogOutputEncoding;

            if (!token.IsCancellationRequested)
            {
                subject.OnCompleted();
            }
        }
Ejemplo n.º 3
0
        private void UpdateSelectedFileViewers(bool force = false)
        {
            var selectedRevisions = FileChanges.GetSelectedRevisions();

            if (selectedRevisions.Count == 0)
            {
                return;
            }

            GitRevision revision = selectedRevisions[0];
            var         children = FileChanges.GetRevisionChildren(revision.ObjectId);

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = FileName;
            }

            SetTitle(fileName);

            if (revision.IsArtificial)
            {
                tabControl1.SelectedTab = DiffTab;

                CommitInfoTabPage.Parent = null;
                BlameTab.Parent          = null;
                ViewTab.Parent           = null;
            }
            else
            {
                if (CommitInfoTabPage.Parent == null)
                {
                    tabControl1.TabPages.Insert(0, CommitInfoTabPage);
                }

                if (ViewTab.Parent == null)
                {
                    var index = tabControl1.TabPages.IndexOf(DiffTab);
                    Debug.Assert(index != -1, "TabControl should contain diff tab page");
                    tabControl1.TabPages.Insert(index + 1, ViewTab);
                }

                if (BlameTab.Parent == null)
                {
                    var index = tabControl1.TabPages.IndexOf(ViewTab);
                    Debug.Assert(index != -1, "TabControl should contain view tab page");
                    tabControl1.TabPages.Insert(index + 1, BlameTab);
                }
            }

            if (tabControl1.SelectedTab == BlameTab)
            {
                Blame.LoadBlame(revision, children, fileName, FileChanges, BlameTab, Diff.Encoding, force: force);
            }
            else if (tabControl1.SelectedTab == ViewTab)
            {
                View.Encoding = Diff.Encoding;
                var file = new GitItemStatus
                {
                    IsTracked   = true,
                    Name        = fileName,
                    IsSubmodule = VsrModule.IsValidVersionrWorkingDir(_fullPathResolver.Resolve(fileName))
                };
                View.ViewGitItemRevisionAsync(file, revision.ObjectId);
            }
            else if (tabControl1.SelectedTab == DiffTab)
            {
                var file = new GitItemStatus
                {
                    IsTracked   = true,
                    Name        = fileName,
                    IsSubmodule = VsrModule.IsValidVersionrWorkingDir(_fullPathResolver.Resolve(fileName))
                };
                var revisions   = FileChanges.GetSelectedRevisions();
                var selectedRev = revisions.FirstOrDefault();
                var firstId     = revisions.Skip(1).LastOrDefault()?.ObjectId ?? selectedRev?.FirstParentGuid;
                Diff.ViewChangesAsync(firstId, selectedRev, file,
                                      defaultText: "You need to select at least one revision to view diff.");
            }
            else if (tabControl1.SelectedTab == CommitInfoTabPage)
            {
                CommitDiff.SetRevision(revision.ObjectId, fileName);
            }

            if (_buildReportTabPageExtension == null)
            {
                _buildReportTabPageExtension = new BuildReportTabPageExtension(() => Module, tabControl1, _buildReportTabCaption.Text);
            }

            _buildReportTabPageExtension.FillBuildReport(selectedRevisions.Count == 1 ? revision : null);
        }
Ejemplo n.º 4
0
        public static string ProcessSubmoduleStatus([NotNull] VsrModule module, [NotNull] GitSubmoduleStatus status)
        {
            if (module == null)
            {
                throw new ArgumentNullException(nameof(module));
            }

            if (status == null)
            {
                throw new ArgumentNullException(nameof(status));
            }

            VsrModule gitModule = module.GetSubmodule(status.Name);
            var       sb        = new StringBuilder();

            sb.AppendLine("Submodule " + status.Name + " Change");

            // TEMP, will be moved in the follow up refactor
            ICommitDataManager commitDataManager = new CommitDataManager(() => gitModule);

            sb.AppendLine();
            sb.AppendLine("From:\t" + (status.OldCommit?.ToString() ?? "null"));
            CommitData oldCommitData = null;

            // TODO File access for Git revision access
            if (gitModule.IsValidVersionrWorkingDir())
            {
                if (status.OldCommit != null)
                {
                    oldCommitData = commitDataManager.GetCommitData(status.OldCommit.ToString(), out _);
                }

                if (oldCommitData != null)
                {
                    sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, oldCommitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(oldCommitData.CommitDate) + ")");
                    var delimiter = new[] { '\n', '\r' };
                    var lines     = oldCommitData.Body.Trim(delimiter).Split(new[] { "\r\n" }, 0);
                    foreach (var line in lines)
                    {
                        sb.AppendLine("\t\t" + line);
                    }
                }
            }
            else
            {
                sb.AppendLine();
            }

            sb.AppendLine();
            string dirty = !status.IsDirty ? "" : " (dirty)";

            sb.AppendLine("To:\t\t" + (status.Commit?.ToString() ?? "null") + dirty);
            CommitData commitData = null;

            // TODO File access for Git revision access
            if (gitModule.IsValidVersionrWorkingDir())
            {
                if (status.Commit != null)
                {
                    commitData = commitDataManager.GetCommitData(status.Commit.ToString(), out _);
                }

                if (commitData != null)
                {
                    sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(commitData.CommitDate) + ")");
                    var delimiter = new[] { '\n', '\r' };
                    var lines     = commitData.Body.Trim(delimiter).Split(new[] { "\r\n" }, 0);
                    foreach (var line in lines)
                    {
                        sb.AppendLine("\t\t" + line);
                    }
                }
            }
            else
            {
                sb.AppendLine();
            }

            sb.AppendLine();
            var submoduleStatus = gitModule.CheckSubmoduleStatus(status.Commit, status.OldCommit, commitData, oldCommitData);

            sb.Append("Type: ");
            switch (submoduleStatus)
            {
            case SubmoduleStatus.NewSubmodule:
                sb.AppendLine("New submodule");
                break;

            case SubmoduleStatus.FastForward:
                sb.AppendLine("Fast Forward");
                break;

            case SubmoduleStatus.Rewind:
                sb.AppendLine("Rewind");
                break;

            case SubmoduleStatus.NewerTime:
                sb.AppendLine("Newer commit time");
                break;

            case SubmoduleStatus.OlderTime:
                sb.AppendLine("Older commit time");
                break;

            case SubmoduleStatus.SameTime:
                sb.AppendLine("Same commit time");
                break;

            default:
                sb.AppendLine("Unknown");
                break;
            }

            if (status.AddedCommits != null && status.RemovedCommits != null &&
                (status.AddedCommits != 0 || status.RemovedCommits != 0))
            {
                sb.Append("\nCommits: ");

                if (status.RemovedCommits > 0)
                {
                    sb.Append(status.RemovedCommits + " removed");

                    if (status.AddedCommits > 0)
                    {
                        sb.Append(", ");
                    }
                }

                if (status.AddedCommits > 0)
                {
                    sb.Append(status.AddedCommits + " added");
                }

                sb.AppendLine();
            }

            if (status.Commit != null && status.OldCommit != null)
            {
                if (status.IsDirty)
                {
                    string statusText = gitModule.GetStatusText(untracked: false);
                    if (!string.IsNullOrEmpty(statusText))
                    {
                        sb.AppendLine("\nStatus:");
                        sb.Append(statusText);
                    }
                }

                string diffs = gitModule.GetDiffFilesText(status.OldCommit.ToString(), status.Commit.ToString());
                if (!string.IsNullOrEmpty(diffs))
                {
                    sb.AppendLine("\nDifferences:");
                    sb.Append(diffs);
                }
            }

            return(sb.ToString());
        }