From dc103c35ab0214e790a744396183a62131285d0e Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 4 Oct 2012 22:30:46 +0200 Subject: [PATCH] IDEA-67535 (Cannot move CVS branch) & IDEA-16311 (Misleading status message for CVS "Create Tag" command) --- .../intellij/cvsSupport2/CvsBundle.properties | 1 + .../cvsSupport2/actions/BranchAction.java | 27 ++++---- .../cvsSupport2/actions/CreateTagAction.java | 27 ++++---- .../cvsSupport2/actions/DeleteTagAction.java | 24 +++---- .../cvshandlers/CommandCvsHandler.java | 46 ++++++++------ .../cvsMessages/CvsMessagesTranslator.java | 4 +- .../cvsTagOrBranch/BranchOperation.java | 26 ++++---- .../cvsTagOrBranch/TagOperation.java | 19 ++---- .../cvsTagOrBranch/TagsHelper.java | 63 ++++++++++--------- .../cvsTagOrBranch/ui/CreateTagDialog.java | 52 +++++---------- .../cvsTagOrBranch/ui/DeleteTagDialog.java | 28 ++------- 11 files changed, 132 insertions(+), 185 deletions(-) diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties index 1bcc61876fdf..89385066f85a 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties @@ -315,6 +315,7 @@ label.add.file.confirmation.keyword.substitution=keyword substitution? label.add.file.confirmation.keyword.substitution.to.cvs.with=to CVS with label.add.file.confirmation.keyword.substitution.add.file=Add file checkbox.create.tag.override.existing=Override existing (-F) +checkbox.create.tag.override.existing.branch=Override existing (-F -B) label.delete.tag.tag.name=Tag name: radio.corrupted.project.files.get.all.silently=Get all silently radio.corrupted.project.files.skip.all.silently=Skip all silently diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/BranchAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/BranchAction.java index 707376ab8af4..7c6aa46aafcf 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/BranchAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/BranchAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.actions; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.actions.actionVisibility.CvsActionVisibility; import com.intellij.cvsSupport2.actions.cvsContext.CvsContext; import com.intellij.cvsSupport2.config.CvsConfiguration; @@ -24,9 +25,6 @@ import com.intellij.cvsSupport2.cvsoperations.cvsTagOrBranch.ui.CreateTagDialog; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.actions.VcsContext; -import com.intellij.CvsBundle; - -import java.util.Arrays; /** * author: lesya @@ -35,7 +33,7 @@ public class BranchAction extends ActionOnSelectedElement{ public BranchAction() { super(true); - CvsActionVisibility visibility = getVisibility(); + final CvsActionVisibility visibility = getVisibility(); visibility.canBePerformedOnSeveralFiles(); visibility.canBePerformedOnLocallyDeletedFile(); visibility.addCondition(FILES_EXIST_IN_CVS); @@ -46,17 +44,14 @@ public class BranchAction extends ActionOnSelectedElement{ } protected CvsHandler getCvsHandler(CvsContext context) { - FilePath[] selectedFiles = context.getSelectedFilePaths(); - Project project = context.getProject(); - CreateTagDialog createBranchDialog = new CreateTagDialog(Arrays.asList(selectedFiles), - project, false); - createBranchDialog.show(); - if (!createBranchDialog.isOK()) return CvsHandler.NULL; + final FilePath[] selectedFiles = context.getSelectedFilePaths(); + final Project project = context.getProject(); + final CreateTagDialog dialog = new CreateTagDialog(selectedFiles, project, false); + dialog.show(); + if (!dialog.isOK()) return CvsHandler.NULL; - return CommandCvsHandler.createBranchOrTagHandler(selectedFiles, - createBranchDialog.getTagName(), - createBranchDialog.switchToThisBranch(), - createBranchDialog.getOverrideExisting(), - false, CvsConfiguration.getInstance(context.getProject()).MAKE_NEW_FILES_READONLY, project); + final boolean makeNewFilesReadOnly = CvsConfiguration.getInstance(project).MAKE_NEW_FILES_READONLY; + return CommandCvsHandler.createBranchHandler( + selectedFiles, dialog.getTagName(), dialog.switchToThisBranch(), dialog.getOverrideExisting(), makeNewFilesReadOnly, project); } } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/CreateTagAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/CreateTagAction.java index f151e238a06b..91913b60ec1a 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/CreateTagAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/CreateTagAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.actions; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.actions.actionVisibility.CvsActionVisibility; import com.intellij.cvsSupport2.actions.cvsContext.CvsContext; import com.intellij.cvsSupport2.config.CvsConfiguration; @@ -25,8 +26,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.actions.VcsContext; -import java.util.Arrays; - /** * author: lesya */ @@ -34,27 +33,25 @@ public class CreateTagAction extends ActionOnSelectedElement{ public CreateTagAction() { super(true); - CvsActionVisibility visibility = getVisibility(); + final CvsActionVisibility visibility = getVisibility(); visibility.canBePerformedOnSeveralFiles(); visibility.canBePerformedOnLocallyDeletedFile(); visibility.addCondition(FILES_EXIST_IN_CVS); } protected String getTitle(VcsContext context) { - return com.intellij.CvsBundle.message("operation.name.create.tag"); + return CvsBundle.message("operation.name.create.tag"); } protected CvsHandler getCvsHandler(CvsContext context) { - FilePath[] selectedFiles = context.getSelectedFilePaths(); - Project project = context.getProject(); - CreateTagDialog dialog = new CreateTagDialog(Arrays.asList(selectedFiles), - project, true); + final FilePath[] selectedFiles = context.getSelectedFilePaths(); + final Project project = context.getProject(); + final CreateTagDialog dialog = new CreateTagDialog(selectedFiles, project, true); dialog.show(); - if (!dialog.isOK()) - return CvsHandler.NULL; - return CommandCvsHandler.createBranchOrTagHandler(selectedFiles, dialog.getTagName(), - dialog.switchToThisBranch(), dialog.getOverrideExisting(), - true, CvsConfiguration.getInstance(project).MAKE_NEW_FILES_READONLY, project); - } + if (!dialog.isOK()) return CvsHandler.NULL; + final boolean makeNewFilesReadOnly = CvsConfiguration.getInstance(project).MAKE_NEW_FILES_READONLY; + return CommandCvsHandler.createTagHandler( + selectedFiles, dialog.getTagName(), dialog.switchToThisBranch(), dialog.getOverrideExisting(), makeNewFilesReadOnly, project); + } } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/DeleteTagAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/DeleteTagAction.java index b8ca2c53b339..dae87468f801 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/DeleteTagAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/DeleteTagAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.actions; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.actions.actionVisibility.CvsActionVisibility; import com.intellij.cvsSupport2.actions.cvsContext.CvsContext; import com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler; @@ -23,9 +24,6 @@ import com.intellij.cvsSupport2.cvsoperations.cvsTagOrBranch.ui.DeleteTagDialog; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.actions.VcsContext; -import java.util.Arrays; -import java.util.Collection; - /** * author: lesya */ @@ -33,27 +31,21 @@ public class DeleteTagAction extends ActionOnSelectedElement{ public DeleteTagAction() { super(false); - CvsActionVisibility visibility = getVisibility(); + final CvsActionVisibility visibility = getVisibility(); visibility.canBePerformedOnSeveralFiles(); visibility.addCondition(FILES_EXIST_IN_CVS); } protected String getTitle(VcsContext context) { - return com.intellij.CvsBundle.message("action.name.delete.tag"); + return CvsBundle.message("action.name.delete.tag"); } protected CvsHandler getCvsHandler(CvsContext context) { - DeleteTagDialog deleteTagDialog = new DeleteTagDialog(collectFiles(context), - context.getProject()); + final FilePath[] selectedFiles = context.getSelectedFilePaths(); + final DeleteTagDialog deleteTagDialog = new DeleteTagDialog(selectedFiles, context.getProject()); deleteTagDialog.show(); - if (!deleteTagDialog.isOK()) - return CvsHandler.NULL; - return CommandCvsHandler.createRemoveTagAction(context.getSelectedFiles(), - deleteTagDialog.getTagName()); - } + if (!deleteTagDialog.isOK()) return CvsHandler.NULL; - private Collection collectFiles(VcsContext context) { - return Arrays.asList(context.getSelectedFilePaths()); + return CommandCvsHandler.createRemoveTagAction(selectedFiles, deleteTagDialog.getTagName()); } - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvshandlers/CommandCvsHandler.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvshandlers/CommandCvsHandler.java index 6299eb2e7dc7..e2d08b10202e 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvshandlers/CommandCvsHandler.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvshandlers/CommandCvsHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -54,7 +54,7 @@ import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.update.UpdatedFiles; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; @@ -71,6 +71,7 @@ import java.util.*; * @author lesya */ public class CommandCvsHandler extends CvsHandler { + private static final Logger LOG = Logger.getInstance("#com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler"); protected final CvsOperation myCvsOperation; @@ -161,16 +162,25 @@ public class CommandCvsHandler extends CvsHandler { return new UpdateHandler(files, updateSettings, project, updatedFiles); } - public static CvsHandler createBranchOrTagHandler(FilePath[] selectedFiles, String branchName, - boolean switchToThisAction, boolean overrideExisting, - boolean isTag, boolean makeNewFilesReadOnly, Project project) { + public static CvsHandler createTagHandler(FilePath[] selectedFiles, String tagName, boolean switchToThisTag, + boolean overrideExisting, boolean makeNewFilesReadOnly, Project project) { final CompositeOperation operation = new CompositeOperation(); - operation.addOperation(new BranchOperation(selectedFiles, branchName, overrideExisting, isTag)); - if (switchToThisAction) { + operation.addOperation(new TagOperation(selectedFiles, tagName, false, overrideExisting)); + if (switchToThisTag) { + operation.addOperation(new UpdateOperation(selectedFiles, tagName, makeNewFilesReadOnly, project)); + } + return new CommandCvsHandler(CvsBundle.message("operation.name.create.tag"), operation, + FileSetToBeUpdated.selectedFiles(selectedFiles)); + } + + public static CvsHandler createBranchHandler(FilePath[] selectedFiles, String branchName, boolean switchToThisBranch, + boolean overrideExisting, boolean makeNewFilesReadOnly, Project project) { + final CompositeOperation operation = new CompositeOperation(); + operation.addOperation(new BranchOperation(selectedFiles, branchName, overrideExisting)); + if (switchToThisBranch) { operation.addOperation(new UpdateOperation(selectedFiles, branchName, makeNewFilesReadOnly, project)); } - return new CommandCvsHandler(isTag ? CvsBundle.message("operation.name.create.tag") - : CvsBundle.message("operation.name.create.branch"), operation, + return new CommandCvsHandler(CvsBundle.message("operation.name.create.branch"), operation, FileSetToBeUpdated.selectedFiles(selectedFiles)); } @@ -204,7 +214,8 @@ public class CommandCvsHandler extends CvsHandler { final CommandCvsHandler result = new CommandCvsHandler(title, operation, FileSetToBeUpdated.selectedFiles(selectedFiles)); if (tagFilesAfterCommit) { - result.addOperation(new TagOperation(selectedFiles, tagName, CvsConfiguration.getInstance(project).OVERRIDE_EXISTING_TAG_FOR_PROJECT)); + result.addOperation(new TagOperation(selectedFiles, tagName, false, + CvsConfiguration.getInstance(project).OVERRIDE_EXISTING_TAG_FOR_PROJECT)); } return result; @@ -225,7 +236,7 @@ public class CommandCvsHandler extends CvsHandler { operation.addFile(info.getFile(), info.getKeywordSubstitution()); } return new CommandCvsHandler(CvsBundle.message("action.name.add"), operation, - FileSetToBeUpdated.selectedFiles(VfsUtil.toVirtualFileArray(addedFiles)), + FileSetToBeUpdated.selectedFiles(VfsUtilCore.toVirtualFileArray(addedFiles)), VcsConfiguration.getInstance(project).getAddRemoveOption()); } @@ -246,13 +257,13 @@ public class CommandCvsHandler extends CvsHandler { final VirtualFile cvsAdminDirectory = CvsVfsUtil.findFileByIoFile(new File(parentFile, CvsUtil.CVS)); if (cvsAdminDirectory != null) result.add(cvsAdminDirectory); } - return VfsUtil.toVirtualFileArray(result); + return VfsUtilCore.toVirtualFileArray(result); } public static CvsHandler createRestoreFileHandler(final VirtualFile parent, String name, boolean makeNewFilesReadOnly) { - final File ioFile = new File(VfsUtil.virtualToIoFile(parent), name); + final File ioFile = new File(VfsUtilCore.virtualToIoFile(parent), name); final Entry entry = CvsEntriesManager.getInstance().getEntryFor(parent, name); @@ -267,7 +278,7 @@ public class CommandCvsHandler extends CvsHandler { @Override public void run() { final List errors = cvsHandler.getErrors(); - if (errors != null && (! errors.isEmpty())) return; + if (errors != null && !errors.isEmpty()) return; if (entry != null) { entry.setRevision(revision); @@ -299,7 +310,7 @@ public class CommandCvsHandler extends CvsHandler { return new CommandCvsHandler(CvsBundle.message("operation.name.unedit"), operation, FileSetToBeUpdated.selectedFiles(selectedFiles)); } - public static CvsHandler createRemoveTagAction(VirtualFile[] selectedFiles, String tagName) { + public static CvsHandler createRemoveTagAction(FilePath[] selectedFiles, String tagName) { return new CommandCvsHandler(CvsBundle.message("action.name.delete.tag"), new TagOperation(selectedFiles, tagName, true, false), FileSetToBeUpdated.EMPTY); } @@ -434,9 +445,8 @@ public class CommandCvsHandler extends CvsHandler { null); compositeOperation.addOperation(checkoutFileOperation); } - - return new CommandCvsHandler(CvsBundle.message("action.name.get.file.from.repository"), compositeOperation, FileSetToBeUpdated.allFiles(), true); - + return new CommandCvsHandler(CvsBundle.message("action.name.get.file.from.repository"), + compositeOperation, FileSetToBeUpdated.allFiles(), true); } private static String getAlternativeCheckoutPath(CvsLightweightFile cvsLightweightFile, File workingDirectory) { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsMessages/CvsMessagesTranslator.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsMessages/CvsMessagesTranslator.java index 567e35792d0c..97d1d7a4f6a9 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsMessages/CvsMessagesTranslator.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsMessages/CvsMessagesTranslator.java @@ -78,6 +78,7 @@ public class CvsMessagesTranslator implements IFileInfoListener, IMessageListene new CvsMessagePattern("cvs server: cannot make path to *: Permission denied"), new CvsMessagePattern("cvs server: cannot find module `*' - ignored"), new CvsMessagePattern("W * : * already exists on version * : NOT MOVING tag to version *"), + new CvsMessagePattern("W * : * already exists on branch * : NOT MOVING tag to branch *"), new CvsMessagePattern(new String[]{"cvs server: ", "*", " added independently by second party"}, 2), new CvsMessagePattern("cvs server: failed to create lock directory for `*' (*#cvs.lock): No such file or directory"), new CvsMessagePattern("cvs server: failed to obtain dir lock in repository `*'"), @@ -145,15 +146,12 @@ public class CvsMessagesTranslator implements IFileInfoListener, IMessageListene myListener.addFileMessage(message, myCvsFileSystem); return; } - if (isMessage(message)) { lastMessage = MessageType.MESSAGE; myListener.addMessage(message); return; } - if (!error) return; - final CvsMessagePattern errorMessagePattern = getErrorMessagePattern(message, ERRORS_PATTERNS); if (errorMessagePattern != null) { if (message.contains(CORRECT_ABOVE_ERRORS_FIRST_PREFIX)) { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/BranchOperation.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/BranchOperation.java index 8f2df645f5f8..e3ce972477c0 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/BranchOperation.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/BranchOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -29,25 +29,25 @@ public class BranchOperation extends CvsOperationOnFiles{ private final String myBranchName; private final boolean myOverrideExisting; - private final boolean myIsTag; - public BranchOperation(FilePath[] files, String branchName, - boolean overrideExisting, boolean isTag) { + public BranchOperation(FilePath[] files, String branchName, boolean overrideExisting) { myBranchName = branchName; myOverrideExisting = overrideExisting; - myIsTag = isTag; - for (int i = 0; i < files.length; i++) { - addFile(files[i].getIOFile()); + for (FilePath file : files) { + addFile(file.getIOFile()); } } protected Command createCommand(CvsRootProvider root, CvsExecutionEnvironment cvsExecutionEnvironment) { - TagCommand result = new TagCommand(); - result.setMakeBranchTag(!myIsTag); - result.setTag(myBranchName); - result.setOverrideExistingTag(myOverrideExisting); - addFilesToCommand(root, result); - return result; + final TagCommand tagCommand = new TagCommand(); + tagCommand.setMakeBranchTag(true); + tagCommand.setTag(myBranchName); + tagCommand.setOverrideExistingTag(myOverrideExisting); + if (myOverrideExisting) { + tagCommand.setAllowMoveDeleteBranchTag(true); + } + addFilesToCommand(root, tagCommand); + return tagCommand; } protected String getOperationName() { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/TagOperation.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/TagOperation.java index f30ae2446832..e0b3d8374053 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/TagOperation.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/TagOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -19,7 +19,6 @@ import com.intellij.cvsSupport2.connections.CvsRootProvider; import com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment; import com.intellij.cvsSupport2.cvsoperations.common.CvsOperationOnFiles; import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vfs.VirtualFile; import org.netbeans.lib.cvsclient.command.Command; import org.netbeans.lib.cvsclient.command.tag.TagCommand; @@ -27,30 +26,22 @@ import org.netbeans.lib.cvsclient.command.tag.TagCommand; * author: lesya */ public class TagOperation extends CvsOperationOnFiles{ + private final String myTag; private final boolean myRemoveTag; private final boolean myOverrideExisting; - public TagOperation(VirtualFile[] files, String tag, boolean removeTag, boolean overrideExisting) { - for (VirtualFile file : files) { - addFile(file); - } - myRemoveTag = removeTag; - myTag = tag; - myOverrideExisting = overrideExisting; - } - - public TagOperation(FilePath[] files, String tag, boolean overrideExisting) { + public TagOperation(FilePath[] files, String tag, boolean removeTag, boolean overrideExisting) { for (FilePath file : files) { addFile(file.getIOFile()); } - myRemoveTag = false; myTag = tag; + myRemoveTag = removeTag; myOverrideExisting = overrideExisting; } protected Command createCommand(CvsRootProvider root, CvsExecutionEnvironment cvsExecutionEnvironment) { - TagCommand tagCommand = new TagCommand(); + final TagCommand tagCommand = new TagCommand(); addFilesToCommand(root, tagCommand); tagCommand.setTag(myTag); tagCommand.setDeleteTag(myRemoveTag); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/TagsHelper.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/TagsHelper.java index cb5c98c17bea..064a526c0534 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/TagsHelper.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/TagsHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -32,7 +32,10 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.actions.VcsContextFactory; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.Nullable; import org.netbeans.lib.cvsclient.command.log.LogInformation; @@ -57,7 +60,7 @@ public class TagsHelper { try { final CvsCommandOperation operation = tagsProvider.getOperation(); if (operation == null) return null; - BranchesProvider branchesProvider = getBranchesProvider(operation, project); + final BranchesProvider branchesProvider = getBranchesProvider(operation, project); return chooseFrom(branchesProvider.getAllBranches(), branchesProvider.getAllRevisions()); } catch (VcsException e) { @@ -81,26 +84,22 @@ public class TagsHelper { field.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - String branchName = TagsHelper.chooseBranch(files, project); + final String branchName = chooseBranch(files, project); if (branchName != null) field.setText(branchName); } }); } public static Collection getAllBranches(List log) { - HashSet branches = new HashSet(); - + final HashSet branches = new HashSet(); for (final LogInformation logInformation : log) { collectBranches(logInformation, branches); } - return branches; - } - private static void collectBranches(LogInformation logInformation, - HashSet branches) { - List allSymbolicNames = logInformation.getAllSymbolicNames(); + private static void collectBranches(LogInformation logInformation, HashSet branches) { + final List allSymbolicNames = logInformation.getAllSymbolicNames(); for (final SymbolicName symbolicName : allSymbolicNames) { branches.add(symbolicName.getName()); } @@ -114,23 +113,32 @@ public class TagsHelper { private static BranchesProvider getBranchesProvider(CvsOperation operation, Project project) throws VcsException { LOG.assertTrue(operation instanceof BranchesProvider); - CvsOperationExecutor executor = new CvsOperationExecutor(true, project, - new ModalityContextImpl(ModalityState.defaultModalityState() - )); - CommandCvsHandler handler = new CommandCvsHandler(CvsBundle.message("load.tags.operation.name"), operation, true); + final CvsOperationExecutor executor = + new CvsOperationExecutor(true, project, new ModalityContextImpl(ModalityState.defaultModalityState())); + final CommandCvsHandler handler = new CommandCvsHandler(CvsBundle.message("load.tags.operation.name"), operation, true); executor.performActionSync(handler, CvsOperationExecutorCallback.EMPTY); - CvsResult executionResult = executor.getResult(); + final CvsResult executionResult = executor.getResult(); if (executionResult.hasErrors()) throw executionResult.composeError(); return (BranchesProvider)operation; } - private static Collection collectAllBranches(Collection files, - Project project) throws VcsException { - ArrayList result = new ArrayList(); + private static Collection collectAllBranches(Collection files, Project project) throws VcsException { if (files.isEmpty()) { - return result; + return Collections.emptyList(); } - return getBranchesProvider(new LogOperation(files), project).getAllBranches(); + final Collection roots = new HashSet(); + final Set seen = new HashSet(); + for(FilePath filePath : files) { + final VirtualFile root = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(filePath); + if (root == null || !seen.add(root)) { + continue; + } + roots.add(VcsContextFactory.SERVICE.getInstance().createFilePathOn(root)); + } + if (roots.isEmpty()) { + return Collections.emptyList(); + } + return getBranchesProvider(new LogOperation(roots), project).getAllBranches(); } private static void showErrorMessage(VcsException e1) { @@ -141,8 +149,7 @@ public class TagsHelper { @Nullable private static String chooseFrom(Collection tags, Collection revisions) { if (tags == null) return null; - Collection revisionsNames = collectSortedRevisionsNames(revisions); - + final Collection revisionsNames = collectSortedRevisionsNames(revisions); if (tags.isEmpty() && revisionsNames.isEmpty()) { Messages.showMessageDialog(CvsBundle.message("message.no.tags.found"), CvsBundle.message("operation.name.select.tag"), Messages.getInformationIcon()); @@ -153,19 +160,18 @@ public class TagsHelper { if (selectTagDialog.isOK()) { return selectTagDialog.getTag(); } - return null; } private static Collection collectSortedTags(Collection tags) { - ArrayList result = new ArrayList(tags); + final ArrayList result = new ArrayList(tags); Collections.sort(result); return result; } private static Collection collectSortedRevisionsNames(Collection revisions) { if (revisions == null) return new ArrayList(); - ArrayList list = new ArrayList(revisions); + final ArrayList list = new ArrayList(revisions); Collections.sort(list, new Comparator() { @Override public int compare(CvsRevisionNumber o, CvsRevisionNumber o1) { @@ -173,7 +179,7 @@ public class TagsHelper { } }); - ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList(); for (final CvsRevisionNumber aList : list) { result.add(aList.toString()); } @@ -181,13 +187,10 @@ public class TagsHelper { } public static Collection getAllRevisions(List logs) { - ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList(); for (final LogInformation log : logs) { collectRevisions(log, result); } - return result; } - - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/CreateTagDialog.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/CreateTagDialog.java index 12cd73e3924f..46ad32b8b6b0 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/CreateTagDialog.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/CreateTagDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -21,15 +21,9 @@ import com.intellij.cvsSupport2.ui.experts.importToCvs.CvsFieldValidator; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.actions.VcsContextFactory; -import com.intellij.openapi.vfs.VirtualFile; import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Collection; -import java.util.HashSet; +import java.util.Arrays; /** * author: lesya @@ -43,38 +37,23 @@ public class CreateTagDialog extends CvsTagDialog { private JLabel myTagOrBranchLabel; private JLabel myErrorLabel; - public CreateTagDialog(final Collection files, final Project project, boolean isTag) { - - myTagOrBranchLabel.setText(isTag ? CvsBundle.message("label.tag.name") : CvsBundle.message("label.branch.name")); - mySwitchToThisTag.setText( - isTag ? CvsBundle.message("checkbox.switch.to.this.tag") : CvsBundle.message("checkbox.switch.to.this.branch")); - - myTagName.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String branchName = TagsHelper.chooseBranch(collectVcsRoots(project, files), project); - if (branchName != null) - myTagName.setText(branchName); - } - }); - - setTitle((isTag ? CvsBundle.message("operation.name.create.tag") : CvsBundle.message("operation.name.create.branch"))); - + public CreateTagDialog(final FilePath[] files, final Project project, boolean isTag) { + if (isTag) { + myTagOrBranchLabel.setText(CvsBundle.message("label.tag.name")); + mySwitchToThisTag.setText(CvsBundle.message("checkbox.switch.to.this.tag")); + myOverrideExisting.setText(CvsBundle.message("checkbox.create.tag.override.existing")); + } + else { + myTagOrBranchLabel.setText(CvsBundle.message("label.branch.name")); + mySwitchToThisTag.setText(CvsBundle.message("checkbox.switch.to.this.branch")); + myOverrideExisting.setText(CvsBundle.message("checkbox.create.tag.override.existing.branch")); + } + TagsHelper.addChooseBranchAction(myTagName, Arrays.asList(files), project); + setTitle(isTag ? CvsBundle.message("operation.name.create.tag") : CvsBundle.message("operation.name.create.branch")); CvsFieldValidator.installOn(this, myTagName.getTextField(), myErrorLabel); init(); } - public static Collection collectVcsRoots(final Project project, final Collection files) { - Collection result = new HashSet(); - for(FilePath filePath: files) { - final VirtualFile root = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(filePath); - if (root != null) { - result.add(VcsContextFactory.SERVICE.getInstance().createFilePathOn(root)); - } - } - return result; - } - public String getTagName() { return myTagName.getText(); } @@ -106,5 +85,4 @@ public class CreateTagDialog extends CvsTagDialog { public boolean tagFieldIsActive() { return true; } - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/DeleteTagDialog.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/DeleteTagDialog.java index 0059f3bbd1cc..ef928a174915 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/DeleteTagDialog.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/DeleteTagDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -23,41 +23,24 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.vcs.FilePath; import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Collection; +import java.util.Arrays; /** * author: lesya */ public class DeleteTagDialog extends CvsTagDialog { + private TextFieldWithBrowseButton myTagName; private JPanel myPanel; - private final Collection myFiles; - private final Project myProject; private JLabel myErrorLabel; - public DeleteTagDialog(Collection files, Project project) { - myFiles = files; - myProject = project; - myTagName.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectTag(); - } - }); + public DeleteTagDialog(final FilePath[] files, final Project project) { + TagsHelper.addChooseBranchAction(myTagName, Arrays.asList(files), project); CvsFieldValidator.installOn(this, myTagName.getTextField(), myErrorLabel); - setTitle(CvsBundle.message("action.name.delete.tag")); init(); } - private void selectTag() { - String branchName = TagsHelper.chooseBranch(CreateTagDialog.collectVcsRoots(myProject, myFiles), myProject); - if (branchName != null) - myTagName.setText(branchName); - } - public String getTagName() { return myTagName.getText(); } @@ -81,5 +64,4 @@ public class DeleteTagDialog extends CvsTagDialog { public boolean tagFieldIsActive() { return true; } - }