Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
Exemplo n.º 3
0
        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);
Exemplo n.º 5
0
        private void StashedSelectedIndexChanged(object sender, EventArgs e)
        {
            GitStash      gitStash    = Stashes.SelectedItem as GitStash;
            GitItemStatus stashedItem = Stashed.SelectedItem;

            EnablePartialStash();

            using (WaitCursorScope.Enter())
            {
                if (stashedItem != null &&
                    gitStash == _currentWorkingDirStashItem)
                {
                    // current working directory
                    View.ViewCurrentChanges(stashedItem);
                }
                else if (stashedItem != null)
                {
                    if (stashedItem.IsNew)
                    {
                        if (!stashedItem.IsSubmodule)
                        {
                            View.ViewGitItemAsync(stashedItem.Name, stashedItem.TreeGuid);
                        }
                        else
                        {
                            View.ViewTextAsync(
                                stashedItem.Name,
                                LocalizationHelpers.GetSubmoduleText(Module, stashedItem.Name, stashedItem.TreeGuid));
                        }
                    }
                    else
                    {
                        string   extraDiffArguments = View.GetExtraDiffArguments();
                        Encoding encoding           = View.Encoding;
                        View.ViewPatchAsync(
                            () =>
                        {
                            Patch patch = Module.GetSingleDiff(gitStash.Name + "^", gitStash.Name, stashedItem.Name, stashedItem.OldName, extraDiffArguments, encoding, true, stashedItem.IsTracked);
                            if (patch == null)
                            {
                                return(text: string.Empty, openWithDifftool: null /* not applicable */);
                            }

                            if (stashedItem.IsSubmodule)
                            {
                                return(text: LocalizationHelpers.ProcessSubmodulePatch(Module, stashedItem.Name, patch),
                                       openWithDifftool: null /* not implemented */);
                            }

                            return(text: patch.Text, openWithDifftool: null /* not implemented */);
                        });
                    }
                }
                else
                {
                    View.ViewTextAsync(string.Empty, string.Empty);
                }
            }
        }
Exemplo n.º 6
0
        private void StashedSelectedIndexChanged(object sender, EventArgs e)
        {
            GitStash      gitStash    = Stashes.SelectedItem as GitStash;
            GitItemStatus stashedItem = Stashed.SelectedItem;

            EnablePartialStash();

            Cursor.Current = Cursors.WaitCursor;

            if (stashedItem != null &&
                gitStash == _currentWorkingDirStashItem)
            {
                // current working directory
                View.ViewCurrentChanges(stashedItem);
            }
            else if (stashedItem != null)
            {
                if (stashedItem.IsNew)
                {
                    if (!stashedItem.IsSubmodule)
                    {
                        View.ViewGitItem(stashedItem.Name, stashedItem.TreeGuid);
                    }
                    else
                    {
                        View.ViewText(stashedItem.Name,
                                      LocalizationHelpers.GetSubmoduleText(Module, stashedItem.Name, stashedItem.TreeGuid));
                    }
                }
                else
                {
                    string   extraDiffArguments = View.GetExtraDiffArguments();
                    Encoding encoding           = View.Encoding;
                    View.ViewPatch(() =>
                    {
                        Patch patch = Module.GetSingleDiff(gitStash.Name + "^", gitStash.Name, stashedItem.Name, stashedItem.OldName, extraDiffArguments, encoding, true, stashedItem.IsTracked);
                        if (patch == null)
                        {
                            return(string.Empty);
                        }

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

                        return(patch.Text);
                    });
                }
            }
            else
            {
                View.ViewText(string.Empty, string.Empty);
            }

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
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);
Exemplo n.º 9
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);
        }