Example #1
0
 public void ViewCurrentChanges(string fileName, string oldFileName, bool staged,
                                bool isSubmodule, Task <GitSubmoduleStatus> status)
 {
     if (!isSubmodule)
     {
         _async.Load(() => Module.GetCurrentChanges(fileName, oldFileName, staged, GetExtraDiffArguments(), Encoding),
                     ViewStagingPatch);
     }
     else if (status != null)
     {
         _async.Load(() =>
         {
             if (status.Result == null)
             {
                 return(string.Format("Submodule \"{0}\" has unresolved conflicts", fileName));
             }
             return(LocalizationHelpers.ProcessSubmoduleStatus(Module, status.Result));
         }, ViewPatch);
     }
     else
     {
         _async.Load(() => LocalizationHelpers.ProcessSubmodulePatch(Module, fileName,
                                                                     Module.GetCurrentChanges(fileName, oldFileName, staged, GetExtraDiffArguments(), Encoding)), ViewPatch);
     }
 }
Example #2
0
            static string GetSelectedPatch(
                FileViewer fileViewer,
                ObjectId firstId,
                ObjectId selectedId,
                GitItemStatus file)
            {
                if (firstId == ObjectId.CombinedDiffId)
                {
                    var diffOfConflict = fileViewer.Module.GetCombinedDiffContent(selectedId, file.Name,
                                                                                  fileViewer.GetExtraDiffArguments(), fileViewer.Encoding);

                    return(string.IsNullOrWhiteSpace(diffOfConflict)
                        ? Strings.UninterestingDiffOmitted
                        : diffOfConflict);
                }

                if (file.IsSubmodule && file.GetSubmoduleStatusAsync() is not null)
                {
                    // Patch already evaluated
                    var status = ThreadHelper.JoinableTaskFactory.Run(file.GetSubmoduleStatusAsync);
                    return(status is not null
                        ? LocalizationHelpers.ProcessSubmoduleStatus(fileViewer.Module, status)
                        : $"Failed to get status for submodule \"{file.Name}\"");
                }

                var patch = GetItemPatch(fileViewer.Module, file, firstId, selectedId,
                                         fileViewer.GetExtraDiffArguments(), fileViewer.Encoding);

                return(file.IsSubmodule
                    ? LocalizationHelpers.ProcessSubmodulePatch(fileViewer.Module, file.Name, patch)
                    : patch?.Text);
        public static string GetSelectedPatch(this FileViewer diffViewer, string firstRevision, string secondRevision, GitItemStatus file)
        {
            if (!file.IsTracked)
            {
                var fullPath = Path.Combine(diffViewer.Module.WorkingDir, file.Name);
                if (Directory.Exists(fullPath) && GitModule.IsValidGitWorkingDir(fullPath))
                {
                    // git-status does not detect details for untracked and git-diff --no-index will not give info
                    return(LocalizationHelpers.GetSubmoduleText(diffViewer.Module, file.Name.TrimEnd('/'), ""));
                }
            }

            if (file.IsSubmodule && file.SubmoduleStatus != null)
            {
                return(LocalizationHelpers.ProcessSubmoduleStatus(diffViewer.Module, file.SubmoduleStatus.Result));
            }

            PatchApply.Patch patch = GetItemPatch(diffViewer.Module, file, firstRevision, secondRevision,
                                                  diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
            {
                return(string.Empty);
            }

            if (file.IsSubmodule)
            {
                return(LocalizationHelpers.ProcessSubmodulePatch(diffViewer.Module, file.Name, patch));
            }

            return(patch.Text);
        }
            static string?GetSelectedPatch(
                FileViewer fileViewer,
                ObjectId firstId,
                ObjectId selectedId,
                GitItemStatus file)
            {
                if (firstId == ObjectId.CombinedDiffId)
                {
                    var diffOfConflict = fileViewer.Module.GetCombinedDiffContent(selectedId, file.Name,
                                                                                  fileViewer.GetExtraDiffArguments(), fileViewer.Encoding);

                    return(string.IsNullOrWhiteSpace(diffOfConflict)
                        ? TranslatedStrings.UninterestingDiffOmitted
                        : diffOfConflict);
                }

                if (file.IsSubmodule)
                {
#pragma warning disable VSTHRD103 // Call async methods when in an async method
                    var status = ThreadHelper.JoinableTaskFactory.Run(file.GetSubmoduleStatusAsync !);
#pragma warning restore VSTHRD103 // Call async methods when in an async method
                    return(status is not null
                        ? LocalizationHelpers.ProcessSubmoduleStatus(fileViewer.Module, status)
                        : $"Failed to get status for submodule \"{file.Name}\"");
                }

                var patch = GetItemPatch(fileViewer.Module, file, firstId, selectedId,
                                         fileViewer.GetExtraDiffArguments(), fileViewer.Encoding);

                return(file.IsSubmodule
                    ? LocalizationHelpers.ProcessSubmodulePatch(fileViewer.Module, file.Name, patch)
                    : patch?.Text);
            internal async Task SetStatusToolTipAsync(CancellationToken token)
            {
                string toolTip;

                if (Info.Detailed?.RawStatus is not null)
                {
                    // Prefer submodule status, shows ahead/behind
                    toolTip = LocalizationHelpers.ProcessSubmoduleStatus(
                        new GitModule(Info.Path),
                        Info.Detailed.RawStatus,
                        moduleIsParent: false,
                        limitOutput: true);
                }
                else if (GitStatus is not null)
                {
                    var changeCount = new ArtificialCommitChangeCount();
                    changeCount.Update(GitStatus);
                    toolTip = changeCount.GetSummary();
                }
                else
                {
                    // No data need to be set
                    return;
                }

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                token.ThrowIfCancellationRequested();
                TreeViewNode.ToolTipText = toolTip;
            }
        public static string GetSelectedPatch(this FileViewer diffViewer, string firstRevision, string secondRevision, GitItemStatus file)
        {
            if (firstRevision == null)
            {
                return(null);
            }

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
            {
                string temp = firstRevision;
                firstRevision  = secondRevision;
                secondRevision = temp;
            }

            if (IsItemUntracked(file, firstRevision, secondRevision))
            {
                var fullPath = Path.Combine(diffViewer.Module.WorkingDir, file.Name);
                if (Directory.Exists(fullPath) && GitModule.IsValidGitWorkingDir(fullPath))
                {
                    return(LocalizationHelpers.GetSubmoduleText(diffViewer.Module, file.Name.TrimEnd('/'), ""));
                }
                return(FileReader.ReadFileContent(fullPath, diffViewer.Encoding));
            }

            if (file.IsSubmodule && file.SubmoduleStatus != null)
            {
                return(LocalizationHelpers.ProcessSubmoduleStatus(diffViewer.Module, file.SubmoduleStatus.Result));
            }

            PatchApply.Patch patch = GetItemPatch(diffViewer.Module, file, firstRevision, secondRevision,
                                                  diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
            {
                return(string.Empty);
            }

            if (file.IsSubmodule)
            {
                return(LocalizationHelpers.ProcessSubmodulePatch(diffViewer.Module, file.Name, patch));
            }
            return(patch.Text);
        }
Example #7
0
            static async Task <string?> GetSelectedPatchAsync(
                FileViewer fileViewer,
                ObjectId firstId,
                ObjectId selectedId,
                GitItemStatus file,
                CancellationToken cancellationToken)
            {
                if (firstId == ObjectId.CombinedDiffId)
                {
                    var diffOfConflict = fileViewer.Module.GetCombinedDiffContent(selectedId, file.Name,
                                                                                  fileViewer.GetExtraDiffArguments(), fileViewer.Encoding);

                    cancellationToken.ThrowIfCancellationRequested();
                    return(string.IsNullOrWhiteSpace(diffOfConflict)
                        ? TranslatedStrings.UninterestingDiffOmitted
                        : diffOfConflict);
                }

                var task = file.GetSubmoduleStatusAsync();

                if (file.IsSubmodule && task is not null)
                {
                    // Patch already evaluated
                    var status = await task;

                    cancellationToken.ThrowIfCancellationRequested();
                    return(status is not null
                        ? LocalizationHelpers.ProcessSubmoduleStatus(fileViewer.Module, status)
                        : $"Failed to get status for submodule \"{file.Name}\"");
                }

                var patch = await GetItemPatchAsync(fileViewer.Module, file, firstId, selectedId,
                                                    fileViewer.GetExtraDiffArguments(), fileViewer.Encoding);

                cancellationToken.ThrowIfCancellationRequested();
                return(file.IsSubmodule
                    ? LocalizationHelpers.ProcessSubmodulePatch(fileViewer.Module, file.Name, patch)
                    : patch?.Text);
Example #8
0
        private static string GetSelectedPatch(
            [NotNull] this FileViewer diffViewer,
            [CanBeNull] ObjectId firstRevision,
            [CanBeNull] ObjectId secondRevision,
            [NotNull] GitItemStatus file)
        {
            if (!file.IsTracked)
            {
                var fullPath = Path.Combine(diffViewer.Module.WorkingDir, file.Name);
                if (Directory.Exists(fullPath) && GitModule.IsValidGitWorkingDir(fullPath))
                {
                    // git-status does not detect details for untracked and git-diff --no-index will not give info
                    return(LocalizationHelpers.GetSubmoduleText(diffViewer.Module, file.Name.TrimEnd('/'), ""));
                }
            }

            if (file.IsSubmodule && file.GetSubmoduleStatusAsync() != null)
            {
                return(LocalizationHelpers.ProcessSubmoduleStatus(diffViewer.Module, ThreadHelper.JoinableTaskFactory.Run(() => file.GetSubmoduleStatusAsync())));
            }

            Patch patch = GetItemPatch(diffViewer.Module, file, firstRevision, secondRevision,
                                       diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
            {
                return(string.Empty);
            }

            if (file.IsSubmodule)
            {
                return(LocalizationHelpers.ProcessSubmodulePatch(diffViewer.Module, file.Name, patch));
            }

            return(patch.Text);
        }
Example #9
0
            protected override void ApplyStyle()
            {
                base.ApplyStyle();

                Trace.Assert(TreeViewNode is not null);

                if (IsCurrent)
                {
                    TreeViewNode.NodeFont = new Font(AppSettings.Font, FontStyle.Bold);
                }

                if (Info.Detailed?.RawStatus is not null)
                {
                    // Prefer submodule status, shows ahead/behind
                    TreeViewNode.ToolTipText = LocalizationHelpers.ProcessSubmoduleStatus(
                        new GitModule(Info.Path),
                        Info.Detailed.RawStatus,
                        moduleIsParent: false,
                        limitOutput: true);
                }
                else if (GitStatus is not null)
                {
                    var changeCount = new ArtificialCommitChangeCount();
                    changeCount.Update(GitStatus);
                    TreeViewNode.ToolTipText = changeCount.GetSummary();
                }
                else
                {
                    TreeViewNode.ToolTipText = DisplayText();
                }

                TreeViewNode.ImageKey         = GetSubmoduleItemImage(Info.Detailed);
                TreeViewNode.SelectedImageKey = TreeViewNode.ImageKey;

                return;

                // NOTE: Copied and adapated from FormBrowse.GetSubmoduleItemImage
                string GetSubmoduleItemImage(DetailedSubmoduleInfo details)
                {
                    if (details?.Status is null)
                    {
                        return(nameof(Images.FolderSubmodule));
                    }

                    if (details.Status == SubmoduleStatus.FastForward)
                    {
                        return(details.IsDirty ? nameof(Images.SubmoduleRevisionUpDirty) : nameof(Images.SubmoduleRevisionUp));
                    }

                    if (details.Status == SubmoduleStatus.Rewind)
                    {
                        return(details.IsDirty ? nameof(Images.SubmoduleRevisionDownDirty) : nameof(Images.SubmoduleRevisionDown));
                    }

                    if (details.Status == SubmoduleStatus.NewerTime)
                    {
                        return(details.IsDirty ? nameof(Images.SubmoduleRevisionSemiUpDirty) : nameof(Images.SubmoduleRevisionSemiUp));
                    }

                    if (details.Status == SubmoduleStatus.OlderTime)
                    {
                        return(details.IsDirty ? nameof(Images.SubmoduleRevisionSemiDownDirty) : nameof(Images.SubmoduleRevisionSemiDown));
                    }

                    // Unknown
                    return(details.IsDirty ? nameof(Images.SubmoduleDirty) : nameof(Images.FileStatusModified));
                }
            }