From a3f0009853861c2d226e894b50aa5a0135ba2d7e Mon Sep 17 00:00:00 2001 From: "Ilia.Shulgin" Date: Wed, 11 Sep 2024 21:44:37 +0200 Subject: [PATCH] [diff] IJPL-162088 Fix missing path in shelves diff GitOrigin-RevId: e649ebd0c5d056bffbcf96b79ea0a529c0d5e5b7 --- platform/vcs-impl/api-dump.txt | 2 +- .../diff/ChangeDiffRequestProducer.java | 8 ++-- .../patch/PatchDiffRequestFactory.java | 38 ++++++++++++------- .../DiffShelvedChangesActionProvider.java | 26 +++++++++++-- .../ShelvedWrapperDiffRequestProducer.java | 5 +-- .../history/DiffTitleFilePathCustomizer.kt | 6 ++- 6 files changed, 57 insertions(+), 28 deletions(-) diff --git a/platform/vcs-impl/api-dump.txt b/platform/vcs-impl/api-dump.txt index b4085e0cc90b..87e95c5e4a2b 100644 --- a/platform/vcs-impl/api-dump.txt +++ b/platform/vcs-impl/api-dump.txt @@ -3345,7 +3345,6 @@ f:com.intellij.openapi.vcs.changes.patch.PatchDiffRequestFactory - s:createBadMergeRequest(com.intellij.openapi.project.Project,com.intellij.openapi.editor.Document,com.intellij.openapi.vfs.VirtualFile,java.lang.String,com.intellij.openapi.vcs.changes.patch.AppliedTextPatch,java.lang.String,java.lang.String,java.lang.String,java.lang.String,com.intellij.util.Consumer):com.intellij.diff.merge.MergeRequest - s:createConflictDiffRequest(com.intellij.openapi.project.Project,com.intellij.openapi.vfs.VirtualFile,com.intellij.openapi.diff.impl.patch.TextFilePatch,java.lang.String,com.intellij.openapi.vcs.changes.patch.ApplyPatchForBaseRevisionTexts,java.lang.String):com.intellij.diff.requests.DiffRequest - s:createDiffRequest(com.intellij.openapi.project.Project,com.intellij.openapi.vcs.changes.Change,java.lang.String,com.intellij.openapi.util.UserDataHolder,com.intellij.openapi.progress.ProgressIndicator):com.intellij.diff.requests.DiffRequest -- s:createDiffRequest(com.intellij.openapi.project.Project,com.intellij.openapi.vfs.VirtualFile,java.util.List,java.lang.String,java.util.List):com.intellij.diff.requests.DiffRequest - s:createMergeRequest(com.intellij.openapi.project.Project,com.intellij.openapi.editor.Document,com.intellij.openapi.vfs.VirtualFile,java.lang.String,java.lang.String,java.lang.String,com.intellij.util.Consumer):com.intellij.diff.merge.MergeRequest - s:createMergeRequest(com.intellij.openapi.project.Project,com.intellij.openapi.editor.Document,com.intellij.openapi.vfs.VirtualFile,java.util.List,java.lang.String,java.util.List,com.intellij.util.Consumer):com.intellij.diff.merge.MergeRequest c:com.intellij.openapi.vcs.changes.patch.PatchFileType @@ -5945,6 +5944,7 @@ f:com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer - sf:EMPTY_CUSTOMIZER:com.intellij.diff.DiffEditorTitleCustomizer - sf:INSTANCE:com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer - sf:getTitleCustomizer(com.intellij.openapi.project.Project,com.intellij.openapi.vcs.FilePath,java.lang.String):com.intellij.diff.DiffEditorTitleCustomizer +- sf:getTitleCustomizers(com.intellij.openapi.project.Project,com.intellij.openapi.vcs.changes.Change,java.lang.String,java.lang.String):java.util.List - sf:getTitleCustomizers(com.intellij.openapi.project.Project,com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer$RevisionWithTitle,com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer$RevisionWithTitle):java.util.List - sf:getTitleCustomizers(com.intellij.openapi.project.Project,com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer$RevisionWithTitle,com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer$RevisionWithTitle,com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer$RevisionWithTitle):java.util.List - sf:getTitleCustomizers(java.lang.String,java.lang.String):java.util.List diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java index 74b2b640312b..c9e532a260ac 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java @@ -266,11 +266,9 @@ public final class ChangeDiffRequestProducer implements DiffRequestProducer, Cha } private @NotNull List createTitleCustomizers() { - return DiffTitleFilePathCustomizer.getTitleCustomizers(myProject, - RevisionWithTitle.create(myChange.getBeforeRevision(), (String)myChangeContext.get( - DiffUserDataKeysEx.VCS_DIFF_LEFT_CONTENT_TITLE)), - RevisionWithTitle.create(myChange.getAfterRevision(), (String)myChangeContext.get( - DiffUserDataKeysEx.VCS_DIFF_RIGHT_CONTENT_TITLE)) + return DiffTitleFilePathCustomizer.getTitleCustomizers(myProject, myChange, + (String)myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_LEFT_CONTENT_TITLE), + (String)myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_RIGHT_CONTENT_TITLE) ); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDiffRequestFactory.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDiffRequestFactory.java index aa34bef35e6b..062901b4c666 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDiffRequestFactory.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDiffRequestFactory.java @@ -2,6 +2,7 @@ package com.intellij.openapi.vcs.changes.patch; import com.intellij.diff.DiffContentFactory; +import com.intellij.diff.DiffEditorTitleCustomizer; import com.intellij.diff.DiffRequestFactory; import com.intellij.diff.InvalidDiffRequestException; import com.intellij.diff.chains.DiffRequestProducerException; @@ -27,8 +28,10 @@ import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.actions.diff.ChangeDiffRequestProducer; import com.intellij.openapi.vcs.changes.patch.tool.ApplyPatchDiffRequest; import com.intellij.openapi.vcs.changes.patch.tool.ApplyPatchMergeRequest; +import com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; +import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.*; import java.util.Arrays; @@ -77,37 +80,35 @@ public final class PatchDiffRequestFactory { String baseContent = texts.getBase(); String patchedContent = texts.getPatched(); - return createDiffRequest(project, file, Arrays.asList(localContent, baseContent, patchedContent), null, + return createDiffRequest(project, file, Arrays.asList(localContent, baseContent, patchedContent), Arrays.asList(DiffBundle.message("merge.version.title.current"), DiffBundle.message("merge.version.title.base"), afterTitle)); } } @NotNull - public static DiffRequest createDiffRequest(@Nullable Project project, - @Nullable VirtualFile file, - @NotNull List contents, - @Nullable @NlsContexts.DialogTitle String windowTitle, - @NotNull List<@NlsContexts.Label String> titles) { + private static DiffRequest createDiffRequest(@Nullable Project project, + @NotNull VirtualFile file, + @NotNull List contents, + @NotNull List<@NlsContexts.Label String> titles) { assert contents.size() == 3; assert titles.size() == 3; - if (windowTitle == null) windowTitle = getPatchTitle(file); - String localTitle = StringUtil.notNullize(titles.get(0), VcsBundle.message("patch.apply.conflict.local.version")); String baseTitle = StringUtil.notNullize(titles.get(1), DiffBundle.message("merge.version.title.base")); String patchedTitle = StringUtil.notNullize(titles.get(2), VcsBundle.message("patch.apply.conflict.patched.version")); - FileType fileType = file != null ? file.getFileType() : null; + FileType fileType = file.getFileType(); DiffContentFactory contentFactory = DiffContentFactory.getInstance(); - DocumentContent localContent = file != null ? contentFactory.createDocument(project, file) : null; + DocumentContent localContent = contentFactory.createDocument(project, file); if (localContent == null) localContent = contentFactory.create(project, contents.get(0), fileType); DocumentContent baseContent = contentFactory.create(project, contents.get(1), fileType); DocumentContent patchedContent = contentFactory.create(project, contents.get(2), fileType); - return new SimpleDiffRequest(windowTitle, localContent, baseContent, patchedContent, - localTitle, baseTitle, patchedTitle); + SimpleDiffRequest request = new SimpleDiffRequest(null, localContent, baseContent, patchedContent, + localTitle, baseTitle, patchedTitle); + return DiffUtil.addTitleCustomizers(request, get3WayDiffCustomizers(project, file, baseTitle)); } @NotNull @@ -126,7 +127,18 @@ public final class PatchDiffRequestFactory { DocumentContent resultContent = DiffContentFactory.getInstance().createDocument(project, file); if (resultContent == null) resultContent = DiffContentFactory.getInstance().create(project, localContent, file); - return new ApplyPatchDiffRequest(resultContent, textPatch, localContent, windowTitle, localTitle, resultTitle, patchTitle); + DiffRequest request = + new ApplyPatchDiffRequest(resultContent, textPatch, localContent, windowTitle, localTitle, resultTitle, patchTitle); + + return DiffUtil.addTitleCustomizers(request, get3WayDiffCustomizers(project, file, resultTitle)); + } + + private static @NotNull List get3WayDiffCustomizers(Project project, VirtualFile file, String centerTitle) { + return Arrays.asList( + DiffTitleFilePathCustomizer.EMPTY_CUSTOMIZER, + DiffTitleFilePathCustomizer.getTitleCustomizer(project, VcsUtil.getFilePath(file), centerTitle), + DiffTitleFilePathCustomizer.EMPTY_CUSTOMIZER + ); } @NotNull diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/DiffShelvedChangesActionProvider.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/DiffShelvedChangesActionProvider.java index c99e9a8837ab..71981df40401 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/DiffShelvedChangesActionProvider.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/DiffShelvedChangesActionProvider.java @@ -3,6 +3,7 @@ package com.intellij.openapi.vcs.changes.shelf; import com.intellij.diff.DiffContentFactory; import com.intellij.diff.DiffDialogHints; +import com.intellij.diff.DiffEditorTitleCustomizer; import com.intellij.diff.DiffManager; import com.intellij.diff.chains.DiffRequestChain; import com.intellij.diff.chains.DiffRequestProducerException; @@ -42,6 +43,7 @@ import com.intellij.openapi.vcs.changes.actions.diff.ChangeDiffRequestProducer; import com.intellij.openapi.vcs.changes.patch.ApplyPatchForBaseRevisionTexts; import com.intellij.openapi.vcs.changes.patch.tool.PatchDiffRequest; import com.intellij.openapi.vcs.changes.ui.ChangeDiffRequestChain; +import com.intellij.openapi.vcs.history.DiffTitleFilePathCustomizer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.ExperimentalUI; import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; @@ -54,6 +56,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.concurrent.locks.ReadWriteLock; @@ -420,8 +423,10 @@ public final class DiffShelvedChangesActionProvider implements AnActionExtension DiffContent leftContent = contentFactory.create(myProject, file); DiffContent rightContent = contentFactory.create(myProject, patch.getSingleHunkPatchText(), file); - return new SimpleDiffRequest(getRequestTitle(), leftContent, rightContent, DiffBundle.message("merge.version.title.current"), - VcsBundle.message("shelve.shelved.version")); + String leftTitle = DiffBundle.message("merge.version.title.current"); + String rightTitle = VcsBundle.message("shelve.shelved.version"); + DiffRequest request = new SimpleDiffRequest(getRequestTitle(), leftContent, rightContent, leftTitle, rightTitle); + return DiffUtil.addTitleCustomizers(request, DiffTitleFilePathCustomizer.getTitleCustomizers(myProject, myChange.getChange(), leftTitle, rightTitle)); } catch (VcsException e) { throw new DiffRequestProducerException(VcsBundle.message("changes.error.can.t.show.diff.for", getFilePath()), e); @@ -506,7 +511,12 @@ public final class DiffShelvedChangesActionProvider implements AnActionExtension DiffContent rightContent = contentFactory.createEmpty(); String rightTitle = null; - return new SimpleDiffRequest(getRequestTitle(), leftContent, rightContent, leftTitle, rightTitle); + DiffRequest request = new SimpleDiffRequest(getRequestTitle(), leftContent, rightContent, leftTitle, rightTitle); + List titleCustomizers = Arrays.asList( + DiffTitleFilePathCustomizer.getTitleCustomizer(myProject, VcsUtil.getFilePath(myFile), leftTitle), + DiffTitleFilePathCustomizer.EMPTY_CUSTOMIZER + ); + return DiffUtil.addTitleCustomizers(request, titleCustomizers); } @NotNull @@ -525,7 +535,15 @@ public final class DiffShelvedChangesActionProvider implements AnActionExtension } DiffContent rightContent = contentFactory.create(myProject, texts.getPatched(), myFile); - return new SimpleDiffRequest(getRequestTitle(), leftContent, rightContent, leftTitle, VcsBundle.message("shelve.shelved.version")); + + DiffRequest request = + new SimpleDiffRequest(getRequestTitle(), leftContent, rightContent, leftTitle, VcsBundle.message("shelve.shelved.version")); + + List titleCustomizers = Arrays.asList( + DiffTitleFilePathCustomizer.getTitleCustomizer(myProject, VcsUtil.getFilePath(myFile), leftTitle), + DiffTitleFilePathCustomizer.EMPTY_CUSTOMIZER + ); + return DiffUtil.addTitleCustomizers(request, titleCustomizers); } private DiffRequest createDiffRequestUsingLocal(@NotNull ApplyPatchForBaseRevisionTexts texts, diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedWrapperDiffRequestProducer.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedWrapperDiffRequestProducer.java index e6b6e43395d3..fb73b9f355d0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedWrapperDiffRequestProducer.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedWrapperDiffRequestProducer.java @@ -116,10 +116,7 @@ public class ShelvedWrapperDiffRequestProducer implements DiffRequestProducer, C DiffRequest request = createTextShelveRequest(title, patch, contextFilePath, leftTitle, rightTitle, commitContext); Change change = shelvedChange.getChange(); - List titleCustomizers = - DiffTitleFilePathCustomizer.getTitleCustomizers(myProject, - RevisionWithTitle.create(change.getBeforeRevision(), leftTitle), - RevisionWithTitle.create(change.getAfterRevision(), rightTitle)); + List titleCustomizers = DiffTitleFilePathCustomizer.getTitleCustomizers(myProject, change, leftTitle, rightTitle); return DiffUtil.addTitleCustomizers(request, titleCustomizers); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/DiffTitleFilePathCustomizer.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/DiffTitleFilePathCustomizer.kt index 4b69f9312215..9cc7908d3642 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/DiffTitleFilePathCustomizer.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/DiffTitleFilePathCustomizer.kt @@ -8,10 +8,10 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.NlsSafe import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vcs.FilePath +import com.intellij.openapi.vcs.changes.Change import com.intellij.openapi.vcs.changes.ContentRevision import com.intellij.openapi.vcs.changes.CurrentContentRevision import com.intellij.openapi.vcs.changes.actions.diff.ChangeDiffRequestProducer -import com.intellij.openapi.vfs.VirtualFile import com.intellij.vcsUtil.VcsUtil /** @@ -31,6 +31,10 @@ object DiffTitleFilePathCustomizer { getTitleCustomizer(afterRevision, project, showPath = beforeRevision == null || beforeRevision.revision.file != afterRevision?.revision?.file), ) + @JvmStatic + fun getTitleCustomizers(project: Project?, change: Change, tileBefore: String?, titleAfter: String?): List = + getTitleCustomizers(project, RevisionWithTitle.create(change.beforeRevision, tileBefore), RevisionWithTitle.create(change.afterRevision, titleAfter)) + @JvmStatic fun getTitleCustomizers(beforeFilePath: String?, afterFilePath: String?): List = listOf( beforeFilePath?.let { FilePathDiffTitleCustomizer(beforeFilePath) } ?: EMPTY_CUSTOMIZER,