From 92c7989075fd3d3fea2ff57f532a7d4e287a66a1 Mon Sep 17 00:00:00 2001 From: "Ilia.Shulgin" Date: Tue, 12 Nov 2024 15:25:52 +0100 Subject: [PATCH] [diff] IJPL-166427 Better title for patched version GitOrigin-RevId: 30cf000f9b04e4f84fa260640db28b96db67efef --- platform/vcs-impl/api-dump.txt | 1 + .../vcs/changes/SimpleContentRevision.java | 30 +++++++++++-------- .../DefaultPatchBaseVersionProvider.java | 23 +------------- .../patch/LazyPatchContentRevision.java | 16 ++-------- .../vcs/changes/patch/PatchDateParser.kt | 26 ++++++++++++++++ .../changes/patch/PatchedRevisionNumber.kt | 20 +++++++++++++ .../patch/TextFilePatchInProgress.java | 7 ++--- 7 files changed, 71 insertions(+), 52 deletions(-) create mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDateParser.kt create mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchedRevisionNumber.kt diff --git a/platform/vcs-impl/api-dump.txt b/platform/vcs-impl/api-dump.txt index 60f5d5c40b70..df54228a6496 100644 --- a/platform/vcs-impl/api-dump.txt +++ b/platform/vcs-impl/api-dump.txt @@ -1056,6 +1056,7 @@ c:com.intellij.openapi.vcs.changes.RunnableBackgroundableWrapper - run(com.intellij.openapi.progress.ProgressIndicator):V c:com.intellij.openapi.vcs.changes.SimpleContentRevision - com.intellij.openapi.vcs.changes.ContentRevision +- (java.lang.String,com.intellij.openapi.vcs.FilePath,com.intellij.openapi.vcs.history.VcsRevisionNumber):V - (java.lang.String,com.intellij.openapi.vcs.FilePath,java.lang.String):V - getContent():java.lang.String - getFile():com.intellij.openapi.vcs.FilePath diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SimpleContentRevision.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SimpleContentRevision.java index 78be21b31687..5ac7b17f42ff 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SimpleContentRevision.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SimpleContentRevision.java @@ -10,9 +10,24 @@ import org.jetbrains.annotations.Nullable; public class SimpleContentRevision implements ContentRevision { private final String myContent; private final FilePath myNewFilePath; - @NotNull private final String myRevision; + @NotNull private final VcsRevisionNumber myRevision; public SimpleContentRevision(final String content, final FilePath newFilePath, @NotNull final String revision) { + this(content, newFilePath, new VcsRevisionNumber() { + @NotNull + @Override + public String asString() { + return revision; + } + + @Override + public int compareTo(final VcsRevisionNumber o) { + return 0; + } + }); + } + + public SimpleContentRevision(final String content, final FilePath newFilePath, @NotNull final VcsRevisionNumber revision) { myContent = content; myNewFilePath = newFilePath; myRevision = revision; @@ -33,17 +48,6 @@ public class SimpleContentRevision implements ContentRevision { @Override @NotNull public VcsRevisionNumber getRevisionNumber() { - return new VcsRevisionNumber() { - @NotNull - @Override - public String asString() { - return myRevision; - } - - @Override - public int compareTo(final VcsRevisionNumber o) { - return 0; - } - }; + return myRevision; } } \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/DefaultPatchBaseVersionProvider.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/DefaultPatchBaseVersionProvider.java index bfbe125ae6d4..4947f55a2547 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/DefaultPatchBaseVersionProvider.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/DefaultPatchBaseVersionProvider.java @@ -37,10 +37,6 @@ import static com.intellij.openapi.vcs.VcsBundle.message; @ApiStatus.Internal public final class DefaultPatchBaseVersionProvider { private static final Logger LOG = Logger.getInstance(DefaultPatchBaseVersionProvider.class); - /** - * @see com.intellij.openapi.diff.impl.patch.TextPatchBuilder - */ - private static final Pattern ourTsPattern = Pattern.compile("\\(date ([0-9]+)\\)"); // NON-NLS private static final String ourRevisionPatternTemplate = "\\(revision (%s)\\)"; // NON-NLS @CalledInAny @@ -95,7 +91,7 @@ public final class DefaultPatchBaseVersionProvider { @NotNull VirtualFile file, @NotNull FilePath pathBeforeRename, @NotNull AbstractVcs vcs) throws VcsException { - Date versionDate = parseVersionAsDate(versionId); + Date versionDate = PatchDateParser.parseVersionAsDate(versionId); String vcsRevisionString = parseVersionAsRevision(versionId, vcs); VcsRevisionNumber revision = vcsRevisionString != null ? vcs.parseRevisionNumber(vcsRevisionString, pathBeforeRename) : null; @@ -153,23 +149,6 @@ public final class DefaultPatchBaseVersionProvider { return null; } - @Nullable - private static Date parseVersionAsDate(@NotNull String versionId) { - try { - Matcher tsMatcher = ourTsPattern.matcher(versionId); - if (tsMatcher.find()) { - long fromTsPattern = Long.parseLong(tsMatcher.group(1)); - return new Date(fromTsPattern); - } - else { - return new Date(versionId); - } - } - catch (IllegalArgumentException e) { - return null; - } - } - private static void runWithModalProgressIfNeeded(@Nullable Project project, @NotNull @NlsContexts.ProgressTitle String title, @NotNull VcsRunnable task) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/LazyPatchContentRevision.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/LazyPatchContentRevision.java index 6b5d3b7af10c..5d7084b4d04b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/LazyPatchContentRevision.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/LazyPatchContentRevision.java @@ -21,14 +21,14 @@ import java.util.function.Supplier; public final class LazyPatchContentRevision implements ContentRevision { private final VirtualFile myVf; private final FilePath myNewFilePath; - private final @NotNull String myRevision; + private final @NotNull PatchedRevisionNumber myRevision; private final TextFilePatch myPatch; private final Supplier myData = new SynchronizedClearableLazy<>(this::loadContent); public LazyPatchContentRevision(final VirtualFile vf, final FilePath newFilePath, - final @NotNull String revision, + final @NotNull PatchedRevisionNumber revision, final TextFilePatch patch) { myVf = vf; myNewFilePath = newFilePath; @@ -70,17 +70,7 @@ public final class LazyPatchContentRevision implements ContentRevision { @Override public @NotNull VcsRevisionNumber getRevisionNumber() { - return new VcsRevisionNumber() { - @Override - public @NotNull String asString() { - return myRevision; - } - - @Override - public int compareTo(final VcsRevisionNumber o) { - return 0; - } - }; + return myRevision; } private static class Data { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDateParser.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDateParser.kt new file mode 100644 index 000000000000..5f79795c1f92 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDateParser.kt @@ -0,0 +1,26 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.openapi.vcs.changes.patch + +import java.util.* + +internal object PatchDateParser { + /** + * @see com.intellij.openapi.diff.impl.patch.TextPatchBuilder + */ + private val dateRegex = "\\(date ([0-9]+)\\)".toRegex() // NON-NLS + + @JvmStatic + fun parseVersionAsDate(versionId: String): Date? = try { + val tsMatcher = dateRegex.matchEntire(versionId) + if (tsMatcher != null) { + val fromTsPattern = tsMatcher.groupValues[1].toLong() + Date(fromTsPattern) + } + else { + Date(versionId) + } + } + catch (_: IllegalArgumentException) { + null + } +} \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchedRevisionNumber.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchedRevisionNumber.kt new file mode 100644 index 000000000000..1d2c5903a78b --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchedRevisionNumber.kt @@ -0,0 +1,20 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.openapi.vcs.changes.patch + +import com.intellij.openapi.util.NlsSafe +import com.intellij.openapi.vcs.VcsBundle +import com.intellij.openapi.vcs.history.VcsRevisionNumber +import com.intellij.util.text.DateFormatUtil +import java.util.Date + +internal class PatchedRevisionNumber(private val version: String?): VcsRevisionNumber { + private val versionAsDate: Date? = version?.let(PatchDateParser::parseVersionAsDate) + + override fun asString(): @NlsSafe String = VcsBundle.message("patch.apply.conflict.patched.version") + when { + versionAsDate != null -> " (" + DateFormatUtil.formatDateTime(versionAsDate) + ")" + version != null -> " $version" + else -> "" + } + + override fun compareTo(other: VcsRevisionNumber?): Int = 0 +} \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/TextFilePatchInProgress.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/TextFilePatchInProgress.java index 64f0a2e5e3bd..92b42f367aec 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/TextFilePatchInProgress.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/TextFilePatchInProgress.java @@ -42,14 +42,13 @@ public final class TextFilePatchInProgress extends AbstractFilePatchInProgress