mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Contains in branches feature implemented for mercurial log.
*test added
This commit is contained in:
@@ -203,8 +203,8 @@ public class HgLogCommand {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HgCommandResult execute(@NotNull VirtualFile repo, @NotNull String template, int limit, HgFile hgFile,
|
||||
@Nullable List<String> argsForCmd) {
|
||||
public HgCommandResult execute(@NotNull VirtualFile repo, @NotNull String template, int limit, HgFile hgFile,
|
||||
@Nullable List<String> argsForCmd) {
|
||||
List<String> arguments = new LinkedList<String>();
|
||||
if (myIncludeRemoved) {
|
||||
// There is a bug in mercurial that causes --follow --removed <file> to cause
|
||||
|
||||
@@ -241,7 +241,7 @@ public class HgLogProvider implements VcsLogProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<String> getContainingBranches(@NotNull VirtualFile root, @NotNull Hash commitHash) throws VcsException {
|
||||
return ContainerUtil.emptyList(); // TODO
|
||||
return HgHistoryUtil.getDescendingHeadsOfBranches(myProject, root, commitHash);
|
||||
}
|
||||
|
||||
private static String prepareParameter(String paramName, String value) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.zmlx.hg4idea.*;
|
||||
import org.zmlx.hg4idea.action.HgCommandResultNotifier;
|
||||
import org.zmlx.hg4idea.command.HgLogCommand;
|
||||
import org.zmlx.hg4idea.execution.HgCommandException;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.log.HgContentRevisionFactory;
|
||||
import org.zmlx.hg4idea.provider.HgCommittedChangeList;
|
||||
|
||||
@@ -205,4 +206,29 @@ public class HgHistoryUtil {
|
||||
}
|
||||
return hashArgs;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<String> getDescendingHeadsOfBranches(@NotNull Project project, @NotNull VirtualFile root, @NotNull Hash hash)
|
||||
throws VcsException {
|
||||
//hg log -r "descendants(659db54c1b6865c97c4497fa867194bcd759ca76) and head() " --template "{branch} {bookmarks}\n"
|
||||
Set<String> branchHeads = new HashSet<String>();
|
||||
List<String> params = new ArrayList<String>();
|
||||
params.add("-r");
|
||||
params.add("descendants(" + hash.asString() + ") and head()");
|
||||
HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
|
||||
HgLogCommand hgLogCommand = new HgLogCommand(project);
|
||||
hgLogCommand.setLogFile(false);
|
||||
String template = HgChangesetUtil.makeTemplate("{branch}", "{bookmarks}");
|
||||
HgCommandResult logResult = hgLogCommand.execute(root, template, -1, hgFile, params);
|
||||
if (logResult == null || logResult.getExitValue() != 0) {
|
||||
throw new VcsException("Couldn't get commit details: log command execution error.");
|
||||
}
|
||||
String output = logResult.getRawOutput();
|
||||
String[] changeSets = output.split(HgChangesetUtil.CHANGESET_SEPARATOR);
|
||||
for (String line : changeSets) {
|
||||
String[] attributes = line.split(HgChangesetUtil.ITEM_SEPARATOR);
|
||||
branchHeads.addAll(Arrays.asList(attributes));
|
||||
}
|
||||
return branchHeads;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package hg4idea.test.history;
|
||||
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.VcsTestUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.impl.HashImpl;
|
||||
import hg4idea.test.HgPlatformTest;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.zmlx.hg4idea.util.HgHistoryUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.intellij.openapi.vcs.Executor.cd;
|
||||
import static com.intellij.openapi.vcs.Executor.echo;
|
||||
import static com.intellij.openapi.vcs.Executor.touch;
|
||||
import static hg4idea.test.HgExecutor.hg;
|
||||
|
||||
/**
|
||||
* @author Nadya Zabrodina
|
||||
*/
|
||||
public class HgLogHistoryTest extends HgPlatformTest {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
createBookmarksAndBranches(myRepository);
|
||||
}
|
||||
|
||||
public void testContainedInBranchesInLogInfos() throws VcsException {
|
||||
Hash testHashForFirstCommit = HashImpl.build("0");
|
||||
Collection<String> branches = HgHistoryUtil.getDescendingHeadsOfBranches(myProject, myRepository, testHashForFirstCommit);
|
||||
//B_Bookmark should not be listed - it is inactive and not head//
|
||||
VcsTestUtil.assertEqualCollections(branches, Arrays.asList("default", "branchA", "branchB", "A_BookMark", "C_BookMark"));
|
||||
}
|
||||
|
||||
private static void createBookmarksAndBranches(@NotNull VirtualFile repositoryRoot) {
|
||||
cd(repositoryRoot);
|
||||
hg("bookmark A_BookMark");
|
||||
hg("tag tag1");
|
||||
String aFile = "A.txt";
|
||||
touch(aFile, "base");
|
||||
hg("add " + aFile);
|
||||
hg("commit -m 'create file'");
|
||||
hg("branch branchA");
|
||||
hg("tag tag2");
|
||||
echo(aFile, " modify with a");
|
||||
hg("commit -m 'create branchA'");
|
||||
hg("bookmark B_BookMark --inactive");
|
||||
echo(aFile, " modify with AA");
|
||||
hg("commit -m 'modify branchA'");
|
||||
hg("up default");
|
||||
hg("branch branchB");
|
||||
hg("tag -l localTag");
|
||||
echo(aFile, " modify with b");
|
||||
hg("commit -m 'modify file in branchB'");
|
||||
hg("bookmark C_BookMark");
|
||||
hg("up branchA");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user