[diff] IJPL-166427 Better title for patched version

GitOrigin-RevId: 30cf000f9b04e4f84fa260640db28b96db67efef
This commit is contained in:
Ilia.Shulgin
2024-11-13 12:03:03 +00:00
committed by intellij-monorepo-bot
parent c7d13bcc46
commit 92c7989075
7 changed files with 71 additions and 52 deletions
+1
View File
@@ -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
- <init>(java.lang.String,com.intellij.openapi.vcs.FilePath,com.intellij.openapi.vcs.history.VcsRevisionNumber):V
- <init>(java.lang.String,com.intellij.openapi.vcs.FilePath,java.lang.String):V
- getContent():java.lang.String
- getFile():com.intellij.openapi.vcs.FilePath
@@ -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;
}
}
@@ -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)
@@ -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<Data> 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 {
@@ -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
}
}
@@ -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
}
@@ -42,14 +42,13 @@ public final class TextFilePatchInProgress extends AbstractFilePatchInProgress<T
if (myNewContentRevision == null) {
myConflicts = null;
final FilePath newFilePath = getFilePath();
PatchedRevisionNumber revisionNumber = new PatchedRevisionNumber(myPatch.getAfterVersionId());
if (FilePatchStatus.ADDED.equals(myStatus)) {
final String content = myPatch.getSingleHunkPatchText();
myNewContentRevision = new SimpleContentRevision(content, newFilePath, chooseNotNull(myPatch.getAfterVersionId(), VcsBundle
.message("patch.apply.conflict.patched.version")));
myNewContentRevision = new SimpleContentRevision(content, newFilePath, revisionNumber);
}
else {
myNewContentRevision = new LazyPatchContentRevision(myCurrentBase, newFilePath, chooseNotNull(myPatch.getAfterVersionId(), VcsBundle
.message("patch.apply.conflict.patched.version")), myPatch);
myNewContentRevision = new LazyPatchContentRevision(myCurrentBase, newFilePath, revisionNumber, myPatch);
}
}
return myNewContentRevision;