private static string AppendItemSubmoduleStatus(string text, GitItemStatus item)
        {
            if (item.IsSubmodule &&
                item.GetSubmoduleStatusAsync() != null &&
                item.GetSubmoduleStatusAsync().IsCompleted&&
                item.GetSubmoduleStatusAsync().CompletedResult() != null)
            {
                text += item.GetSubmoduleStatusAsync().CompletedResult().AddedAndRemovedString();
            }

            return(text);
        }
Beispiel #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);
Beispiel #3
0
        private 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.GetSubmoduleStatusAsync() != null)
            {
                return(LocalizationHelpers.ProcessSubmoduleStatus(diffViewer.Module, ThreadHelper.JoinableTaskFactory.Run(() => file.GetSubmoduleStatusAsync())));
            }

            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);
        }
Beispiel #4
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);