diff options
Diffstat (limited to 'plugins/hg4idea/src/org')
8 files changed, 55 insertions, 31 deletions
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java index ca3020f06cf0..a076635a228a 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java @@ -125,6 +125,10 @@ public final class HgCommandExecutor { public HgCommandResult executeInCurrentThread(@Nullable final VirtualFile repo, @NotNull final String operation, @Nullable final List<String> arguments, @Nullable HgPromptHandler handler) { HgCommandResult result = executeInCurrentThread(repo, operation, arguments, handler, false); + if (HgErrorUtil.isUnknownEncodingError(result)) { + setCharset(Charset.forName("utf8")); + result = executeInCurrentThread(repo, operation, arguments, handler, false); + } if (HgErrorUtil.isAuthorizationError(result)) { if (HgErrorUtil.hasAuthorizationInDestinationPath(myDestination)) { new HgCommandResultNotifier(myProject) @@ -195,7 +199,7 @@ public final class HgCommandExecutor { } if (HgVcs.HGENCODING == null) { cmdLine.add("--encoding"); - cmdLine.add(myCharset.name()); + cmdLine.add(HgEncodingUtil.getNameFor(myCharset)); } HgCommandResult result; diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java index e8f170bba3c4..61e08e158601 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java @@ -24,12 +24,12 @@ import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.VcsKey; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; +import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import com.intellij.vcs.log.*; import com.intellij.vcs.log.data.VcsLogBranchFilter; import com.intellij.vcs.log.data.VcsLogUserFilter; -import com.intellij.vcs.log.impl.VcsRefImpl; import com.intellij.vcs.log.ui.filter.VcsLogTextFilter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,25 +62,21 @@ public class HgLogProvider implements VcsLogProvider { myProject = project; myRepositoryManager = repositoryManager; myRefSorter = new HgRefManager(); - myVcsObjectsFactory = ServiceManager.getService(VcsLogObjectsFactory.class); + myVcsObjectsFactory = ServiceManager.getService(project, VcsLogObjectsFactory.class); } @NotNull @Override public List<? extends VcsFullCommitDetails> readFirstBlock(@NotNull VirtualFile root, boolean ordered, int commitCount) throws VcsException { - String[] params = {"--encoding=UTF-8"}; - if (!ordered) { - params = ArrayUtil.append(params, "-r"); - params = ArrayUtil.append(params, "0:tip"); - } + String[] params = ordered ? ArrayUtil.EMPTY_STRING_ARRAY : new String[]{"-r", "0:tip"}; return HgHistoryUtil.history(myProject, root, commitCount, params); } @NotNull @Override - public List<TimedVcsCommit> readAllHashes(@NotNull VirtualFile root) throws VcsException { - return HgHistoryUtil.readAllHashes(myProject, root); + public List<TimedVcsCommit> readAllHashes(@NotNull VirtualFile root, @NotNull Consumer<VcsUser> userRegistry) throws VcsException { + return HgHistoryUtil.readAllHashes(myProject, root, userRegistry); } @NotNull @@ -115,21 +111,21 @@ public class HgLogProvider implements VcsLogProvider { Collection<VcsRef> refs = new ArrayList<VcsRef>(branches.size() + bookmarks.size()); for (HgNameWithHashInfo branchInfo : branches) { - refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(branchInfo.getHash()), branchInfo.getName(), HgRefManager.BRANCH, root)); + refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(branchInfo.getHash()), branchInfo.getName(), HgRefManager.BRANCH, root)); } for (HgNameWithHashInfo bookmarkInfo : bookmarks) { - refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(bookmarkInfo.getHash()), bookmarkInfo.getName(), + refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(bookmarkInfo.getHash()), bookmarkInfo.getName(), HgRefManager.BOOKMARK, root)); } String currentRevision = repository.getCurrentRevision(); if (currentRevision != null) { // null => fresh repository - refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(currentRevision), "HEAD", HgRefManager.HEAD, root)); + refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(currentRevision), "HEAD", HgRefManager.HEAD, root)); } for (HgNameWithHashInfo tagInfo : tags) { - refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(tagInfo.getHash()), tagInfo.getName(), HgRefManager.TAG, root)); + refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(tagInfo.getHash()), tagInfo.getName(), HgRefManager.TAG, root)); } for (HgNameWithHashInfo localTagInfo : localTags) { - refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(localTagInfo.getHash()), localTagInfo.getName(), + refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(localTagInfo.getHash()), localTagInfo.getName(), HgRefManager.LOCAL_TAG, root)); } return refs; @@ -206,7 +202,7 @@ public class HgLogProvider implements VcsLogProvider { if (userName == null) { userName = System.getenv("HGUSER"); } - return userName == null ? null : myVcsObjectsFactory.createUser(userName); + return userName == null ? null : myVcsObjectsFactory.createUser(userName, ""); } private static String prepareParameter(String paramName, String value) { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java index 740df7d22b62..7b99bdaf7817 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java @@ -51,7 +51,7 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository { super(project, rootDir, parentDisposable); myHgDir = rootDir.findChild(HgUtil.DOT_HG); assert myHgDir != null : ".hg directory wasn't found under " + rootDir.getPresentableUrl(); - myReader = new HgRepositoryReader(VfsUtilCore.virtualToIoFile(myHgDir)); + myReader = new HgRepositoryReader(project, VfsUtilCore.virtualToIoFile(myHgDir)); myConfig = HgConfig.getInstance(project, rootDir); update(); } @@ -137,7 +137,7 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository { @Override public void update() { - HgRepoInfo currentInfo = readRepoInfo(myInfo); + HgRepoInfo currentInfo = readRepoInfo(); // update only if something changed!!! if update every time - new log will be refreshed every time, too. // Then blinking and do not work properly; if (!Disposer.isDisposed(getProject()) && currentInfo != null && !currentInfo.equals(myInfo)) { @@ -153,11 +153,8 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository { } @Nullable - private HgRepoInfo readRepoInfo(@Nullable HgRepoInfo previousInfo) { + private HgRepoInfo readRepoInfo() { myIsFresh = myIsFresh && myReader.checkIsFresh(); - if (isFresh()) { - return previousInfo; - } //in GitRepositoryImpl there are temporary state object for reader fields storing! Todo Check; return new HgRepoInfo(myReader.readCurrentBranch(), myReader.readCurrentRevision(), myReader.readState(), myReader.readBranches(), diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java index 39524ad46e28..aaf7fb58e0eb 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java @@ -19,6 +19,7 @@ import com.intellij.dvcs.repo.RepoStateException; import com.intellij.dvcs.repo.Repository; import com.intellij.dvcs.repo.RepositoryUtil; import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.project.Project; import com.intellij.vcs.log.VcsLogObjectsFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,7 +50,7 @@ public class HgRepositoryReader { @NotNull private final File myLocalTagsFile; // .hg/localtags @NotNull private final VcsLogObjectsFactory myVcsObjectsFactory; - public HgRepositoryReader(@NotNull File hgDir) { + public HgRepositoryReader(@NotNull Project project, @NotNull File hgDir) { myHgDir = hgDir; RepositoryUtil.assertFileExists(myHgDir, ".hg directory not found in " + myHgDir); File branchesFile = new File(new File(myHgDir, "cache"), "branchheads-served"); //branchheads-served exist after mercurial 2.5, @@ -60,7 +61,7 @@ public class HgRepositoryReader { myCurrentBookmark = new File(myHgDir, "bookmarks.current"); myLocalTagsFile = new File(myHgDir, "localtags"); myTagsFile = new File(myHgDir.getParentFile(), ".hgtags"); - myVcsObjectsFactory = ServiceManager.getService(VcsLogObjectsFactory.class); + myVcsObjectsFactory = ServiceManager.getService(project, VcsLogObjectsFactory.class); } /** diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgInitDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgInitDialog.java index d936cb12b794..0a66ab726d41 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgInitDialog.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgInitDialog.java @@ -24,8 +24,8 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.Nullable; -import org.zmlx.hg4idea.util.HgUtil; import org.zmlx.hg4idea.HgVcsMessages; +import org.zmlx.hg4idea.util.HgUtil; import javax.swing.*; import javax.swing.event.CaretEvent; @@ -111,7 +111,8 @@ public class HgInitDialog extends DialogWrapper { public void show() { if (myShowDialog) { super.show(); - } else { + } + else { mySelectedDir = FileChooser.chooseFile(myFileDescriptor, myProject, null); } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgEncodingUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgEncodingUtil.java index c5ad07225ee0..af7d0c278c62 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgEncodingUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgEncodingUtil.java @@ -26,4 +26,14 @@ public class HgEncodingUtil { } return Charset.defaultCharset(); } + + @NotNull + public static String getNameFor(@NotNull Charset charset) { + //workaround for x_MacRoman encoding etc; todo: create map with encoding aliases because some encodings name are not supported by hg + String name = charset.name(); + if (name.startsWith("x-M")) { + return name.substring(2); // without "x-" prefix; + } + return name; + } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgErrorUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgErrorUtil.java index 8558e81ec579..ab2dba7fcfa7 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgErrorUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgErrorUtil.java @@ -93,4 +93,16 @@ public final class HgErrorUtil { } }; } + + public static boolean isUnknownEncodingError(@Nullable HgCommandResult result) { + if (result == null) { + return false; + } + List<String> errorLines = result.getErrorLines(); + if (errorLines.isEmpty()) { + return false; + } + String line = errorLines.get(0); + return !StringUtil.isEmptyOrSpaces(line) && (line.contains("abort") && line.contains("unknown encoding")); + } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgHistoryUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgHistoryUtil.java index 487355820b9a..65d5d2fe3e23 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgHistoryUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgHistoryUtil.java @@ -22,6 +22,7 @@ import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; +import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; @@ -120,7 +121,7 @@ public class HgHistoryUtil { @NotNull public static List<? extends VcsShortCommitDetails> readMiniDetails(Project project, final VirtualFile root, List<String> hashes) throws VcsException { - final VcsLogObjectsFactory factory = ServiceManager.getService(VcsLogObjectsFactory.class); + final VcsLogObjectsFactory factory = ServiceManager.getService(project, VcsLogObjectsFactory.class); return ContainerUtil.map(getCommittedChangeList(project, root, -1, false, prepareHashes(hashes)), new Function<HgCommittedChangeList, VcsShortCommitDetails>() { @Override @@ -132,15 +133,16 @@ public class HgHistoryUtil { } return factory.createShortDetails(factory.createHash(revNumber.getChangeset()), parents, record.getCommitDate().getTime(), root, - revNumber.getSubject(), revNumber.getAuthor()); + revNumber.getSubject(), revNumber.getAuthor(), ""); } }); } @NotNull - public static List<TimedVcsCommit> readAllHashes(@NotNull Project project, @NotNull VirtualFile root) throws VcsException { + public static List<TimedVcsCommit> readAllHashes(@NotNull Project project, @NotNull VirtualFile root, + @NotNull final Consumer<VcsUser> userRegistry) throws VcsException { - final VcsLogObjectsFactory factory = ServiceManager.getService(VcsLogObjectsFactory.class); + final VcsLogObjectsFactory factory = ServiceManager.getService(project, VcsLogObjectsFactory.class); return ContainerUtil.map(getCommittedChangeList(project, root, -1, false, ""), new Function<HgCommittedChangeList, TimedVcsCommit>() { @Override public TimedVcsCommit fun(HgCommittedChangeList record) { @@ -149,6 +151,7 @@ public class HgHistoryUtil { for (HgRevisionNumber parent : revNumber.getParents()) { parents.add(factory.createHash(parent.getChangeset())); } + userRegistry.consume(factory.createUser(record.getRevision().getAuthor(), "")); return factory.createTimedCommit(factory.createHash(revNumber.getChangeset()), parents, record.getCommitDate().getTime()); } @@ -174,7 +177,7 @@ public class HgHistoryUtil { private static VcsFullCommitDetails createCommit(@NotNull Project project, @NotNull VirtualFile root, @NotNull HgCommittedChangeList record) { - final VcsLogObjectsFactory factory = ServiceManager.getService(VcsLogObjectsFactory.class); + final VcsLogObjectsFactory factory = ServiceManager.getService(project, VcsLogObjectsFactory.class); HgRevisionNumber revNumber = (HgRevisionNumber)record.getRevisionNumber(); List<Hash> parents = ContainerUtil.map(revNumber.getParents(), new Function<HgRevisionNumber, Hash>() { |