mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[hg] rename hg Add & Copy command, move last one to CurrentThread
* cleanUp
This commit is contained in:
@@ -181,13 +181,13 @@ public class HgVFSListener extends VcsVFSListener {
|
||||
|
||||
// add for all files at once
|
||||
if (!adds.isEmpty()) {
|
||||
new HgAddCommand(myProject).execute(adds);
|
||||
new HgAddCommand(myProject).executeInCurrentThread(adds);
|
||||
}
|
||||
|
||||
// copy needs to be run for each file separately
|
||||
if (!copies.isEmpty()) {
|
||||
for(Map.Entry<VirtualFile, VirtualFile> copy : copies.entrySet()) {
|
||||
new HgCopyCommand(myProject).execute(copy.getKey(), copy.getValue());
|
||||
for (Map.Entry<VirtualFile, VirtualFile> copy : copies.entrySet()) {
|
||||
new HgCopyCommand(myProject).executeInCurrentThread(copy.getKey(), copy.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,47 +40,54 @@ public class HgAddCommand {
|
||||
|
||||
/**
|
||||
* Adds given files to their Mercurial repositories.
|
||||
* @param hgFiles files to be added.
|
||||
* @param files files to be added.
|
||||
*/
|
||||
public void execute(@NotNull Collection<VirtualFile> files) {
|
||||
execute(files, null);
|
||||
public void executeInCurrentThread(@NotNull Collection<VirtualFile> files) {
|
||||
executeInCurrentThread(files, null);
|
||||
}
|
||||
|
||||
public void addWithProgress(final Collection<VirtualFile> files) {
|
||||
if (files.size() >= HgUtil.MANY_FILES) {
|
||||
new Task.Backgroundable(myProject, "Adding files to Mercurial", true) {
|
||||
@Override public void run(@NotNull ProgressIndicator indicator) {
|
||||
new Task.Backgroundable(myProject, "Adding Files to Mercurial", true) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
indicator.setIndeterminate(false);
|
||||
execute(files, indicator);
|
||||
executeInCurrentThread(files, indicator);
|
||||
}
|
||||
}.queue();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override public void run() {
|
||||
execute(files);
|
||||
@Override
|
||||
public void run() {
|
||||
executeInCurrentThread(files);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void execute(@NotNull Collection<VirtualFile> files, @Nullable ProgressIndicator indicator) {
|
||||
private void executeInCurrentThread(@NotNull Collection<VirtualFile> files, @Nullable ProgressIndicator indicator) {
|
||||
final Map<VirtualFile, Collection<VirtualFile>> sorted = HgUtil.sortByHgRoots(myProject, files);
|
||||
for (Map.Entry<VirtualFile, Collection<VirtualFile>> entry : sorted.entrySet()) {
|
||||
if (indicator != null) {
|
||||
if (indicator.isCanceled()) { return; }
|
||||
if (indicator.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
indicator.setFraction(0);
|
||||
indicator.setText2("Adding files to " + entry.getKey().getPresentableUrl());
|
||||
}
|
||||
addFiles(entry.getKey(), entry.getValue(), indicator);
|
||||
addFilesSynchronously(entry.getKey(), entry.getValue(), indicator);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFiles(VirtualFile repo, Collection<VirtualFile> files, @Nullable ProgressIndicator indicator) {
|
||||
private void addFilesSynchronously(VirtualFile repo, Collection<VirtualFile> files, @Nullable ProgressIndicator indicator) {
|
||||
final List<List<String>> chunks = VcsFileUtil.chunkFiles(repo, files);
|
||||
int currentChunk = 0;
|
||||
for (List<String> paths : chunks) {
|
||||
if (indicator != null) {
|
||||
if (indicator.isCanceled()) { return; }
|
||||
if (indicator.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
indicator.setFraction((double)currentChunk / chunks.size());
|
||||
currentChunk++;
|
||||
}
|
||||
|
||||
@@ -29,20 +29,20 @@ public class HgCopyCommand {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public void execute(VirtualFile source, VirtualFile target) {
|
||||
public void executeInCurrentThread(VirtualFile source, VirtualFile target) {
|
||||
VirtualFile sourceRepo = VcsUtil.getVcsRootFor(myProject, source);
|
||||
VirtualFile targetRepo = VcsUtil.getVcsRootFor(myProject, target);
|
||||
HgCommandExecutor executor = new HgCommandExecutor(myProject, VcsFileUtil.relativeOrFullPath(sourceRepo, source));
|
||||
if (sourceRepo != null && targetRepo != null && sourceRepo.equals(targetRepo)) {
|
||||
executor.execute(sourceRepo, "copy", Arrays.asList("--after",
|
||||
VcsFileUtil.relativeOrFullPath(sourceRepo, source),
|
||||
VcsFileUtil.relativeOrFullPath(targetRepo, target)), null);
|
||||
} else {
|
||||
executor.executeInCurrentThread(sourceRepo, "copy", Arrays.asList("--after",
|
||||
VcsFileUtil.relativeOrFullPath(sourceRepo, source),
|
||||
VcsFileUtil.relativeOrFullPath(targetRepo, target)));
|
||||
}
|
||||
else {
|
||||
// copying from one repository to another => 'hg add' in new repo
|
||||
if (targetRepo != null) {
|
||||
new HgAddCommand(myProject).execute(Collections.singleton(target));
|
||||
new HgAddCommand(myProject).executeInCurrentThread(Collections.singleton(target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user