use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.
the class GitShelveChangesSaver method save.
@Override
protected void save(@NotNull Collection<VirtualFile> rootsToSave) throws VcsException {
LOG.info("save " + rootsToSave);
final Map<String, Map<VirtualFile, Collection<Change>>> lists = new LocalChangesUnderRoots(myChangeManager, myVcsManager).getChangesByLists(rootsToSave);
String oldProgressTitle = myProgressIndicator.getText();
myProgressIndicator.setText(GitBundle.getString("update.shelving.changes"));
List<VcsException> exceptions = new ArrayList<>(1);
myShelvedLists = new HashMap<>();
for (Map.Entry<String, Map<VirtualFile, Collection<Change>>> entry : lists.entrySet()) {
final Map<VirtualFile, Collection<Change>> map = entry.getValue();
final Set<Change> changes = new HashSet<>();
for (Collection<Change> changeCollection : map.values()) {
changes.addAll(changeCollection);
}
if (!changes.isEmpty()) {
final ShelvedChangeList list = GitShelveUtils.shelveChanges(myProject, myShelveManager, changes, myStashMessage + " [" + entry.getKey() + "]", exceptions, false, true);
myShelvedLists.put(entry.getKey(), list);
}
}
if (!exceptions.isEmpty()) {
LOG.info("save " + exceptions, exceptions.get(0));
// no restore here since during shelving changes are not rolled back...
myShelvedLists = null;
throw exceptions.get(0);
} else {
for (VirtualFile root : rootsToSave) {
GitRollbackEnvironment.resetHardLocal(myProject, root);
}
}
myProgressIndicator.setText(oldProgressTitle);
}
use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.
the class GitShelveUtils method shelveChanges.
/**
* Shelve changes
*
*
* @param project the context project
* @param shelveManager the shelve manager
* @param changes the changes to process
* @param description the description of for the shelve
* @param exceptions the generated exceptions
* @param rollback
* @return created shelved change list or null in case failure
*/
@Nullable
public static ShelvedChangeList shelveChanges(final Project project, final ShelveChangesManager shelveManager, Collection<Change> changes, final String description, final List<VcsException> exceptions, boolean rollback, boolean markToBeDeleted) {
try {
ShelvedChangeList shelve = shelveManager.shelveChanges(changes, description, rollback, markToBeDeleted);
project.getMessageBus().syncPublisher(ShelveChangesManager.SHELF_TOPIC).stateChanged(new ChangeEvent(GitStashUtils.class));
return shelve;
} catch (IOException e) {
//noinspection ThrowableInstanceNeverThrown
exceptions.add(new VcsException("Shelving changes failed: " + description, e));
return null;
} catch (VcsException e) {
exceptions.add(e);
return null;
}
}
use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.
the class ImportToShelfExecutor method apply.
@Override
public void apply(@NotNull List<FilePatch> remaining, @NotNull final MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable final String fileName, @Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
if (fileName == null) {
LOG.error("Patch file name shouldn't be null");
return;
}
final VcsCatchingRunnable vcsCatchingRunnable = new VcsCatchingRunnable() {
@Override
public void runImpl() throws VcsException {
final VirtualFile baseDir = myProject.getBaseDir();
final File ioBase = new File(baseDir.getPath());
final List<FilePatch> allPatches = new ArrayList<>();
for (VirtualFile virtualFile : patchGroupsToApply.keySet()) {
final File ioCurrentBase = new File(virtualFile.getPath());
allPatches.addAll(ContainerUtil.map(patchGroupsToApply.get(virtualFile), new Function<TextFilePatchInProgress, TextFilePatch>() {
public TextFilePatch fun(TextFilePatchInProgress patchInProgress) {
final TextFilePatch was = patchInProgress.getPatch();
was.setBeforeName(PathUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase, new File(ioCurrentBase, was.getBeforeName()))));
was.setAfterName(PathUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase, new File(ioCurrentBase, was.getAfterName()))));
return was;
}
}));
}
if (!allPatches.isEmpty()) {
PatchEP[] patchTransitExtensions = null;
if (additionalInfo != null) {
try {
final Map<String, PatchEP> extensions = new HashMap<>();
for (Map.Entry<String, Map<String, CharSequence>> entry : additionalInfo.compute().entrySet()) {
final String filePath = entry.getKey();
Map<String, CharSequence> extToValue = entry.getValue();
for (Map.Entry<String, CharSequence> innerEntry : extToValue.entrySet()) {
TransitExtension patchEP = (TransitExtension) extensions.get(innerEntry.getKey());
if (patchEP == null) {
patchEP = new TransitExtension(innerEntry.getKey());
extensions.put(innerEntry.getKey(), patchEP);
}
patchEP.put(filePath, innerEntry.getValue());
}
}
Collection<PatchEP> values = extensions.values();
patchTransitExtensions = values.toArray(new PatchEP[values.size()]);
} catch (PatchSyntaxException e) {
VcsBalloonProblemNotifier.showOverChangesView(myProject, "Can not import additional patch info: " + e.getMessage(), MessageType.ERROR);
}
}
try {
final ShelvedChangeList shelvedChangeList = ShelveChangesManager.getInstance(myProject).importFilePatches(fileName, allPatches, patchTransitExtensions);
ShelvedChangesViewManager.getInstance(myProject).activateView(shelvedChangeList);
} catch (IOException e) {
throw new VcsException(e);
}
}
}
};
ProgressManager.getInstance().runProcessWithProgressSynchronously(vcsCatchingRunnable, "Import Patch to Shelf", true, myProject);
if (!vcsCatchingRunnable.get().isEmpty()) {
AbstractVcsHelper.getInstance(myProject).showErrors(vcsCatchingRunnable.get(), IMPORT_TO_SHELF);
}
}
use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.
the class CreatePatchFromChangesAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
final Change[] changes = e.getData(VcsDataKeys.CHANGES);
if ((changes == null) || (changes.length == 0))
return;
String commitMessage = null;
List<ShelvedChangeList> shelvedChangeLists = ShelvedChangesViewManager.getShelvedLists(e.getDataContext());
if (!shelvedChangeLists.isEmpty()) {
commitMessage = shelvedChangeLists.get(0).DESCRIPTION;
} else {
ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS);
if (changeLists != null && changeLists.length > 0) {
commitMessage = changeLists[0].getComment();
}
}
if (commitMessage == null) {
commitMessage = e.getData(VcsDataKeys.PRESET_COMMIT_MESSAGE);
}
if (commitMessage == null) {
commitMessage = "";
}
List<Change> changeCollection = new ArrayList<>();
Collections.addAll(changeCollection, changes);
createPatch(project, commitMessage, changeCollection);
}
use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.
the class GitShelveChangesSaver method load.
@Override
public void load() {
if (myShelvedLists != null) {
LOG.info("load ");
String oldProgressTitle = myProgressIndicator.getText();
myProgressIndicator.setText(GitBundle.getString("update.unshelving.changes"));
for (ShelvedChangeList list : myShelvedLists.values()) {
GitShelveUtils.doSystemUnshelve(myProject, list, myShelveManager, getConflictLeftPanelTitle(), getConflictRightPanelTitle());
}
myProgressIndicator.setText(oldProgressTitle);
}
}
Aggregations