Rename variables in HgStatusCommand with "my" prefix; make HgStatusCommnd immutable; rename methods in HgStatusCommand.Builder

This commit is contained in:
Nadya.Zabrodina
2013-03-19 21:30:40 +04:00
parent f55ad922b2
commit dc02052ec9
5 changed files with 63 additions and 55 deletions
@@ -99,7 +99,7 @@ public class HgVFSListener extends VcsVFSListener {
pi.setText(repo.getPresentableUrl());
try {
untrackedFiles
.addAll(new HgStatusCommand.Builder(false).includeUnknown(true).build(myProject)
.addAll(new HgStatusCommand.Builder(false).unknown(true).build(myProject)
.getHgUntrackedFiles(repo, new ArrayList<VirtualFile>(files)));
}
catch (final VcsException ex) {
@@ -148,7 +148,7 @@ public class HgVFSListener extends VcsVFSListener {
LOG.assertTrue(myProject != null, "Project is null");
Collection<VirtualFile> unversionedAndIgnoredFiles = new ArrayList<VirtualFile>();
final Map<VirtualFile, Collection<VirtualFile>> sortedSourceFilesByRepos = HgUtil.sortByHgRoots(myProject, copyFromMap.values());
HgStatusCommand statusCommand = new HgStatusCommand.Builder(false).includeUnknown(true).includeIgnored(true).build(myProject);
HgStatusCommand statusCommand = new HgStatusCommand.Builder(false).unknown(true).ignored(true).build(myProject);
for (VirtualFile repo : sortedSourceFilesByRepos.keySet()) {
Set<HgChange> changes = statusCommand.execute(repo);
for (HgChange change : changes) {
@@ -39,18 +39,18 @@ public class HgStatusCommand {
private static final int ITEM_COUNT = 3;
private static final int STATUS_INDEX = 0;
private final Project project;
private final Project myProject;
private final boolean includeAdded;
private final boolean includeModified;
private final boolean includeRemoved;
private final boolean includeDeleted;
private final boolean includeUnknown;
private final boolean includeIgnored;
private final boolean includeCopySource;
private final boolean myIncludeAdded;
private final boolean myIncludeModified;
private final boolean myIncludeRemoved;
private final boolean myIncludeDeleted;
private final boolean myIncludeUnknown;
private final boolean myIncludeIgnored;
private final boolean myIncludeCopySource;
@Nullable private HgRevisionNumber baseRevision;
@Nullable private HgRevisionNumber targetRevision;
@Nullable private final HgRevisionNumber myBaseRevision;
@Nullable private final HgRevisionNumber myTargetRevision;
public static class Builder {
@@ -62,6 +62,9 @@ public class HgStatusCommand {
private boolean includeIgnored;
private boolean includeCopySource;
private HgRevisionNumber baseRevision;
private HgRevisionNumber targetRevision;
public Builder(boolean initValue) {
includeAdded = initValue;
includeModified = initValue;
@@ -70,23 +73,35 @@ public class HgStatusCommand {
includeUnknown = initValue;
includeIgnored = initValue;
includeCopySource = initValue;
baseRevision = null;
targetRevision = null;
}
public Builder includeUnknown(boolean val) {
public Builder unknown(boolean val) {
includeUnknown = val;
return this;
}
public Builder includeIgnored(boolean val) {
public Builder ignored(boolean val) {
includeIgnored = val;
return this;
}
public Builder includeCopySource(boolean val) {
public Builder copySource(boolean val) {
includeCopySource = val;
return this;
}
public Builder baseRevision(HgRevisionNumber val) {
baseRevision = val;
return this;
}
public Builder targetRevision(HgRevisionNumber val) {
targetRevision = val;
return this;
}
public HgStatusCommand build(Project project) {
return new HgStatusCommand(project, this);
}
@@ -94,22 +109,16 @@ public class HgStatusCommand {
}
private HgStatusCommand(Project project, Builder builder) {
this.project = project;
includeAdded = builder.includeAdded;
includeModified = builder.includeModified;
includeRemoved = builder.includeRemoved;
includeDeleted = builder.includeDeleted;
includeUnknown = builder.includeUnknown;
includeIgnored = builder.includeIgnored;
includeCopySource = builder.includeCopySource;
}
public void setBaseRevision(@Nullable HgRevisionNumber base) {
baseRevision = base;
}
public void setTargetRevision(@Nullable HgRevisionNumber target) {
targetRevision = target;
this.myProject = project;
myIncludeAdded = builder.includeAdded;
myIncludeModified = builder.includeModified;
myIncludeRemoved = builder.includeRemoved;
myIncludeDeleted = builder.includeDeleted;
myIncludeUnknown = builder.includeUnknown;
myIncludeIgnored = builder.includeIgnored;
myIncludeCopySource = builder.includeCopySource;
myBaseRevision = builder.baseRevision;
myTargetRevision = builder.targetRevision;
}
public Set<HgChange> execute(VirtualFile repo) {
@@ -121,37 +130,37 @@ public class HgStatusCommand {
return Collections.emptySet();
}
HgCommandExecutor executor = new HgCommandExecutor(project, null);
HgCommandExecutor executor = new HgCommandExecutor(myProject, null);
executor.setSilent(true);
List<String> options = new LinkedList<String>();
if (includeAdded) {
if (myIncludeAdded) {
options.add("--added");
}
if (includeModified) {
if (myIncludeModified) {
options.add("--modified");
}
if (includeRemoved) {
if (myIncludeRemoved) {
options.add("--removed");
}
if (includeDeleted) {
if (myIncludeDeleted) {
options.add("--deleted");
}
if (includeUnknown) {
if (myIncludeUnknown) {
options.add("--unknown");
}
if (includeIgnored) {
if (myIncludeIgnored) {
options.add("--ignored");
}
if (includeCopySource) {
if (myIncludeCopySource) {
options.add("--copies");
}
if (baseRevision != null && !baseRevision.getRevision().isEmpty()) {
if (myBaseRevision != null && !myBaseRevision.getRevision().isEmpty()) {
options.add("--rev");
options.add(baseRevision.getChangeset().isEmpty() ? baseRevision.getRevision() : baseRevision.getChangeset());
if (targetRevision != null) {
options.add(myBaseRevision.getChangeset().isEmpty() ? myBaseRevision.getRevision() : myBaseRevision.getChangeset());
if (myTargetRevision != null) {
options.add("--rev");
options.add(targetRevision.getChangeset());
options.add(myTargetRevision.getChangeset());
}
}
@@ -134,8 +134,7 @@ public class HgCheckinEnvironment implements CheckinEnvironment {
private Set<HgFile> getChangedFilesNotInCommit(VirtualFile repo, Set<HgFile> selectedFiles) {
List<HgRevisionNumber> parents = new HgWorkingCopyRevisionsCommand(myProject).parents(repo);
HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).includeUnknown(false).includeIgnored(false).build(myProject);
statusCommand.setBaseRevision(parents.get(0));
HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).unknown(false).ignored(false).baseRevision(parents.get(0)).build(myProject);
Set<HgChange> allChangedFilesInRepo = statusCommand.execute(repo);
Set<HgFile> filesNotIncluded = new HashSet<HgFile>();
@@ -216,7 +216,7 @@ public class HgRegularUpdater implements HgUpdater {
}
private Set<HgChange> getLocalChanges() {
HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).includeUnknown(false).includeIgnored(false).build(project);
HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).unknown(false).ignored(false).build(project);
return statusCommand.execute(repository);
}
@@ -264,9 +264,8 @@ public class HgRegularUpdater implements HgUpdater {
if (parentAfterUpdate.equals(parentBeforeUpdate)) { // nothing to update => returning not to capture local uncommitted changes
return;
}
HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).build(project);
statusCommand.setBaseRevision(parentBeforeUpdate);
statusCommand.setTargetRevision(parentAfterUpdate);
HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).baseRevision(parentBeforeUpdate).targetRevision(
parentAfterUpdate).build(project);
Set<HgChange> changes = statusCommand.execute(repo);
for (HgChange change : changes) {
HgFileStatusEnum status = change.getStatus();
@@ -285,8 +285,7 @@ public abstract class HgUtil {
public static HgFile getFileNameInTargetRevision(Project project, HgRevisionNumber vcsRevisionNumber, HgFile localHgFile) {
HgStatusCommand statCommand = new HgStatusCommand.Builder(true).includeUnknown(false).build(project);
statCommand.setBaseRevision(vcsRevisionNumber);
HgStatusCommand statCommand = new HgStatusCommand.Builder(true).unknown(false).baseRevision(vcsRevisionNumber).build(project);
Set<HgChange> changes = statCommand.execute(localHgFile.getRepo());
@@ -400,16 +399,18 @@ public abstract class HgUtil {
@NotNull final FilePath path,
@Nullable final HgFileRevision rev1,
@Nullable final HgFileRevision rev2) {
HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).includeCopySource(false).build(project);
HgStatusCommand statusCommand;
HgRevisionNumber revNumber1 = null;
if (rev1 != null) {
revNumber1 = rev1.getRevisionNumber();
statusCommand.setBaseRevision(revNumber1);
statusCommand.setTargetRevision(rev2 != null ? rev2.getRevisionNumber() : null); //rev2==null means "compare with local version"
//rev2==null means "compare with local version"
statusCommand = new HgStatusCommand.Builder(true).copySource(false).baseRevision(revNumber1)
.targetRevision(rev2 != null ? rev2.getRevisionNumber() : null).build(project);
}
else {
LOG.assertTrue(rev2 != null, "revision1 and revision2 can't both be null. Path: " + path); //rev1 and rev2 can't be null both//
statusCommand.setBaseRevision(rev2.getRevisionNumber()); //get initial changes//
//get initial changes//
statusCommand = new HgStatusCommand.Builder(true).copySource(false).baseRevision(rev2.getRevisionNumber()).build(project);
}
Collection<HgChange> hgChanges = statusCommand.execute(root, Collections.singleton(path));