mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-51710 (CVS Compare compares with wrong version)
This commit is contained in:
@@ -69,15 +69,17 @@ public class CvsRevisionNumber implements VcsRevisionNumber {
|
||||
String[] stringSubRevisions = revision.split("\\.");
|
||||
subRevisions = new int[stringSubRevisions.length];
|
||||
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < stringSubRevisions.length; i++) {
|
||||
try {
|
||||
subRevisions[i] = Integer.parseInt(stringSubRevisions[i]);
|
||||
++ cnt;
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
subRevisions[i] = 0;
|
||||
}
|
||||
}
|
||||
return subRevisions;
|
||||
return (cnt == 0) ? new int[0] : subRevisions;
|
||||
}
|
||||
|
||||
private CvsRevisionNumber(String sringRepresentation, @NotNull int[] subRevisions) {
|
||||
|
||||
@@ -15,31 +15,25 @@
|
||||
*/
|
||||
package com.intellij.cvsSupport2;
|
||||
|
||||
import com.intellij.CvsBundle;
|
||||
import com.intellij.cvsSupport2.application.CvsEntriesManager;
|
||||
import com.intellij.cvsSupport2.changeBrowser.CvsBinaryContentRevision;
|
||||
import com.intellij.cvsSupport2.changeBrowser.CvsContentRevision;
|
||||
import com.intellij.cvsSupport2.connections.CvsConnectionSettings;
|
||||
import com.intellij.cvsSupport2.connections.CvsRootProvider;
|
||||
import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutor;
|
||||
import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutorCallback;
|
||||
import com.intellij.cvsSupport2.cvsExecution.ModalityContext;
|
||||
import com.intellij.cvsSupport2.cvsExecution.ModalityContextImpl;
|
||||
import com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler;
|
||||
import com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment;
|
||||
import com.intellij.cvsSupport2.cvsoperations.common.PostCvsActivity;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorProcessor;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsLog.LogOperation;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsLog.LocalPathIndifferentLogOperation;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsStatus.StatusOperation;
|
||||
import com.intellij.cvsSupport2.cvsoperations.dateOrRevision.RevisionOrDate;
|
||||
import com.intellij.cvsSupport2.cvsoperations.dateOrRevision.RevisionOrDateImpl;
|
||||
import com.intellij.cvsSupport2.cvsoperations.dateOrRevision.SimpleRevision;
|
||||
import com.intellij.cvsSupport2.history.CvsRevisionNumber;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.FilePathImpl;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.ContentRevision;
|
||||
import com.intellij.openapi.vcs.diff.DiffProvider;
|
||||
@@ -49,15 +43,10 @@ import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.netbeans.lib.cvsclient.admin.Entry;
|
||||
import org.netbeans.lib.cvsclient.command.Command;
|
||||
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
|
||||
import org.netbeans.lib.cvsclient.command.log.LogCommand;
|
||||
import org.netbeans.lib.cvsclient.command.log.LogInformation;
|
||||
import org.netbeans.lib.cvsclient.command.status.StatusCommand;
|
||||
import org.netbeans.lib.cvsclient.file.FileStatus;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CvsDiffProvider implements DiffProvider{
|
||||
@@ -123,80 +112,37 @@ public class CvsDiffProvider implements DiffProvider{
|
||||
return null;
|
||||
}
|
||||
|
||||
private ItemLatestState getLastRevision(final File file) {
|
||||
// shouldn't use sticky date: we are to get latest revision that exists _in repository_
|
||||
CvsOperationExecutor executor = new CvsOperationExecutor(myProject);
|
||||
final List<File> files = Collections.singletonList(file);
|
||||
final StatusOperation statusOperation = new StatusOperation(files) {
|
||||
@Override
|
||||
protected Command createCommand(CvsRootProvider root, CvsExecutionEnvironment cvsExecutionEnvironment) {
|
||||
final StatusCommand command = (StatusCommand) super.createCommand(root, cvsExecutionEnvironment);
|
||||
command.setIncludeTags(true);
|
||||
return command;
|
||||
}
|
||||
};
|
||||
final Ref<Boolean> success = new Ref<Boolean>();
|
||||
final CvsOperationExecutorCallback callback = new CvsOperationExecutorCallback() {
|
||||
public void executionFinished(final boolean successfully) {
|
||||
}
|
||||
|
||||
public void executionFinishedSuccessfully() {
|
||||
success.set(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void executeInProgressAfterAction(final ModalityContext modaityContext) {
|
||||
}
|
||||
};
|
||||
final CommandCvsHandler cvsHandler = new CommandCvsHandler(CvsBundle.message("operation.name.get.file.status"), statusOperation) {
|
||||
@Override
|
||||
protected boolean runInReadThread() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
//executor.performActionSync(cvsHandler, callback);
|
||||
|
||||
if (Boolean.TRUE.equals(success.get())) {
|
||||
if ((statusOperation.getStickyDate() != null) || (statusOperation.getStickyTag() != null)) {
|
||||
final String headRevision = getHeadRevisionFromLog(statusOperation.getRepositoryRevision(), file);
|
||||
if (headRevision != null) {
|
||||
return new ItemLatestState(new CvsRevisionNumber(headRevision),
|
||||
(statusOperation.getStatus() != null) && (! FileStatus.REMOVED.equals(statusOperation.getStatus())),
|
||||
false);
|
||||
}
|
||||
} else {
|
||||
return new ItemLatestState(new CvsRevisionNumber(statusOperation.getRepositoryRevision()),
|
||||
(statusOperation.getStatus() != null) && (! FileStatus.REMOVED.equals(statusOperation.getStatus())),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
return new ItemLatestState(new CvsRevisionNumber("HEAD"), true, true);
|
||||
}
|
||||
|
||||
private ItemLatestState getLastState(final VirtualFile parent, final String name) {
|
||||
final Entry entry = CvsEntriesManager.getInstance().getEntryFor(parent, name);
|
||||
if (entry == null) return new ItemLatestState(new CvsRevisionNumber("HEAD"), true, true);
|
||||
if (entry.getStickyDate() != null || entry.getStickyTag() != null || entry.getStickyRevision() != null) {
|
||||
final String headRevision = getHeadRevisionFromLog(entry.getRevision(), new File(parent.getPath(), name));
|
||||
if (headRevision != null) {
|
||||
return new ItemLatestState(new CvsRevisionNumber(headRevision), (! entry.isRemoved()), false);
|
||||
}
|
||||
|
||||
String headRevision = null;
|
||||
if (entry.getStickyDate() != null) {
|
||||
headRevision = new StickyHeadGetter.MyStickyDateGetter(entry.getStickyDateString(), entry.getStickyDate(), entry.getRevision()).getHead(parent, name);
|
||||
} else if (entry.getStickyRevision() != null) {
|
||||
headRevision = entry.getStickyRevision();
|
||||
} else if (entry.getStickyTag() != null) {
|
||||
headRevision = new StickyHeadGetter.MyStickyBranchHeadGetter(entry.getRevision()).getHead(parent, name);
|
||||
} else {
|
||||
return new ItemLatestState(new CvsRevisionNumber(entry.getRevision()), (! entry.isRemoved()), false);
|
||||
headRevision = new StickyHeadGetter.MyStickyBranchHeadGetter(entry.getRevision()).getHead(parent, name);
|
||||
}
|
||||
return new ItemLatestState(new CvsRevisionNumber("HEAD"), true, true);
|
||||
if (headRevision != null) {
|
||||
return new ItemLatestState(new CvsRevisionNumber(headRevision), (! entry.isRemoved()), false);
|
||||
}
|
||||
|
||||
return new ItemLatestState(new CvsRevisionNumber("HEAD"), (! entry.isRemoved()), true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getHeadRevisionFromLog(final String latestKnownRevision, final File file) {
|
||||
final LogOperation operation = new LogOperation(Collections.<FilePath>singletonList(new FilePathImpl(file, false))) {
|
||||
@Override
|
||||
protected Command createCommand(CvsRootProvider root, CvsExecutionEnvironment cvsExecutionEnvironment) {
|
||||
final LogCommand command = (LogCommand) super.createCommand(root, cvsExecutionEnvironment);
|
||||
command.setRevisionFilter(latestKnownRevision + ":");
|
||||
return command;
|
||||
}
|
||||
};
|
||||
private String getBranchHeadRevision(final VirtualFile parent, final String name, final String currentRevNumber) {
|
||||
final int[] subRevisions = new CvsRevisionNumber(currentRevNumber).getSubRevisions();
|
||||
if (subRevisions == null || subRevisions.length < 2) return currentRevNumber;
|
||||
|
||||
final int[] top = new int[subRevisions.length - 1];
|
||||
System.arraycopy(subRevisions, 1, top, 0, subRevisions.length - 1);
|
||||
final String branchRoot = StringUtil.join(top, ".");
|
||||
|
||||
final LocalPathIndifferentLogOperation operation = new LocalPathIndifferentLogOperation(new File(parent.getPath(), name));
|
||||
final Ref<Boolean> logSuccess = new Ref<Boolean>(Boolean.TRUE);
|
||||
final ModalityContext context = ModalityContextImpl.NON_MODAL;
|
||||
final CvsExecutionEnvironment cvsExecutionEnvironment = new CvsExecutionEnvironment(new CvsMessagesAdapter(),
|
||||
@@ -222,9 +168,14 @@ public class CvsDiffProvider implements DiffProvider{
|
||||
//
|
||||
}
|
||||
if (Boolean.TRUE.equals(logSuccess.get())) {
|
||||
final List<LogInformation> informations = operation.getLogInformationList();
|
||||
if (informations != null && (! informations.isEmpty())) {
|
||||
return informations.get(0).getHeadRevision();
|
||||
final Collection<CvsRevisionNumber> numberCollection = operation.getAllRevisions();
|
||||
if (numberCollection == null) return null;
|
||||
|
||||
for (CvsRevisionNumber revisionNumber : numberCollection) {
|
||||
final String stringPresentation = revisionNumber.asString();
|
||||
if (stringPresentation.startsWith(branchRoot)) {
|
||||
return stringPresentation;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.cvsSupport2;
|
||||
|
||||
import com.intellij.cvsSupport2.cvsExecution.ModalityContext;
|
||||
import com.intellij.cvsSupport2.cvsExecution.ModalityContextImpl;
|
||||
import com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment;
|
||||
import com.intellij.cvsSupport2.cvsoperations.common.PostCvsActivity;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorProcessor;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsLog.LocalPathIndifferentLogOperation;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter;
|
||||
import com.intellij.cvsSupport2.history.CvsRevisionNumber;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.Convertor;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
|
||||
import org.netbeans.lib.cvsclient.command.log.LogInformation;
|
||||
import org.netbeans.lib.cvsclient.command.log.Revision;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class StickyHeadGetter {
|
||||
protected final String myStickyData;
|
||||
|
||||
protected StickyHeadGetter(final String stickyData) {
|
||||
myStickyData = stickyData;
|
||||
}
|
||||
|
||||
public static class MyStickyBranchHeadGetter extends StickyHeadGetter {
|
||||
public MyStickyBranchHeadGetter(final String headRevision) {
|
||||
super(headRevision);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHead(final VirtualFile parent, final String name) {
|
||||
final String branchRoot = getTagStart(myStickyData);
|
||||
if (branchRoot == null) return myStickyData;
|
||||
|
||||
return getBranchHeadRevision(parent, name, new Convertor<CvsRevisionNumber, Boolean>() {
|
||||
public Boolean convert(CvsRevisionNumber o) {
|
||||
return o.asString().startsWith(branchRoot);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getTagStart(final String currentRevision) {
|
||||
final int[] subRevisions = new CvsRevisionNumber(currentRevision).getSubRevisions();
|
||||
if (subRevisions == null || subRevisions.length < 2) return null;
|
||||
|
||||
final int[] top = new int[subRevisions.length - 1];
|
||||
System.arraycopy(subRevisions, 0, top, 0, subRevisions.length - 1);
|
||||
return StringUtil.join(top, ".");
|
||||
}
|
||||
|
||||
public static class MyStickyTagGetter extends StickyHeadGetter {
|
||||
public MyStickyTagGetter(final String stickyData) {
|
||||
super(stickyData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHead(final VirtualFile parent, final String name) {
|
||||
return myStickyData;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyStickyDateGetter extends StickyHeadGetter {
|
||||
private final Date myStickyDate;
|
||||
private String myTagStart;
|
||||
|
||||
public MyStickyDateGetter(String stickyData, final Date stickyDate, final String currentRevision) {
|
||||
super(stickyData);
|
||||
myStickyDate = stickyDate;
|
||||
myTagStart = getTagStart(currentRevision);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHead(final VirtualFile parent, final String name) {
|
||||
if (myTagStart == null) return myStickyData;
|
||||
return getBranchHeadRevision(parent, name, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String extractRevision(LocalPathIndifferentLogOperation operation, Convertor<CvsRevisionNumber, Boolean> chooser) {
|
||||
final List<LogInformation> informations = operation.getLogInformationList();
|
||||
for (LogInformation information : informations) {
|
||||
final List<Revision> revisionList = information.getRevisionList();
|
||||
for (Revision revision : revisionList) {
|
||||
if (revision.getNumber().startsWith(myTagStart)) {
|
||||
if (Comparing.compare(revision.getDate(), myStickyDate) <= 0) {
|
||||
return revision.getNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return myStickyData;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String getHead(final VirtualFile parent, final String name);
|
||||
|
||||
@Nullable
|
||||
protected String getBranchHeadRevision(final VirtualFile parent, final String name, final Convertor<CvsRevisionNumber, Boolean> chooser) {
|
||||
final LocalPathIndifferentLogOperation operation = new LocalPathIndifferentLogOperation(new File(parent.getPath(), name));
|
||||
final Ref<Boolean> logSuccess = new Ref<Boolean>(Boolean.TRUE);
|
||||
final ModalityContext context = ModalityContextImpl.NON_MODAL;
|
||||
final CvsExecutionEnvironment cvsExecutionEnvironment = new CvsExecutionEnvironment(new CvsMessagesAdapter(),
|
||||
CvsExecutionEnvironment.DUMMY_STOPPER, new ErrorProcessor() {
|
||||
public void addError(VcsException ex) {
|
||||
logSuccess.set(Boolean.FALSE);
|
||||
}
|
||||
public void addWarning(VcsException ex) {
|
||||
}
|
||||
public List getErrors() {
|
||||
return null;
|
||||
}
|
||||
}, context, PostCvsActivity.DEAF);
|
||||
try {
|
||||
// should already be logged in
|
||||
//operation.login(context);
|
||||
operation.execute(cvsExecutionEnvironment);
|
||||
}
|
||||
catch (VcsException e) {
|
||||
//
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
//
|
||||
}
|
||||
if (Boolean.TRUE.equals(logSuccess.get())) {
|
||||
return extractRevision(operation, chooser);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String extractRevision(final LocalPathIndifferentLogOperation operation, final Convertor<CvsRevisionNumber, Boolean> chooser) {
|
||||
final Collection<CvsRevisionNumber> numberCollection = operation.getAllRevisions();
|
||||
if (numberCollection == null) return null;
|
||||
|
||||
for (CvsRevisionNumber revisionNumber : numberCollection) {
|
||||
final String stringPresentation = revisionNumber.asString();
|
||||
if (chooser.convert(revisionNumber)) {
|
||||
return stringPresentation;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user