Mercurial > jhg
diff src/org/tmatesoft/hg/core/HgIncomingCommand.java @ 202:706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 26 Apr 2011 02:50:06 +0200 |
parents | c9b305df0b89 |
children | ffc5f6d59f7e |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgIncomingCommand.java Thu Apr 21 19:16:45 2011 +0200 +++ b/src/org/tmatesoft/hg/core/HgIncomingCommand.java Tue Apr 26 02:50:06 2011 +0200 @@ -18,6 +18,8 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -43,6 +45,7 @@ private final HgRepository localRepo; private HgRemoteRepository remoteRepo; + @SuppressWarnings("unused") private boolean includeSubrepo; private RepositoryComparator comparator; private List<BranchChain> missingBranches; @@ -105,8 +108,10 @@ RepositoryComparator repoCompare = getComparator(context); for (BranchChain bc : getMissingBranches(context)) { List<Nodeid> missing = repoCompare.visitBranches(bc); - assert bc.branchRoot.equals(missing.get(0)); - missing.remove(0); + HashSet<Nodeid> common = new HashSet<Nodeid>(); // ordering is irrelevant + repoCompare.collectKnownRoots(bc, common); + // missing could only start with common elements. Once non-common, rest is just distinct branch revision trails. + for (Iterator<Nodeid> it = missing.iterator(); it.hasNext() && common.contains(it.next()); it.remove()) ; result.addAll(missing); } ArrayList<Nodeid> rv = new ArrayList<Nodeid>(result); @@ -124,10 +129,10 @@ throw new IllegalArgumentException("Delegate can't be null"); } final List<Nodeid> common = getCommon(handler); - HgBundle changegroup = remoteRepo.getChanges(new LinkedList<Nodeid>(common)); + HgBundle changegroup = remoteRepo.getChanges(common); try { changegroup.changes(localRepo, new HgChangelog.Inspector() { - private int localIndex; + private int localIndex = -1; // in case we start with empty repo and localIndex would not get initialized in regular way private final HgChangelog.ParentWalker parentHelper; private final ChangesetTransformer transformer; private final HgChangelog changelog; @@ -161,7 +166,7 @@ } if (comparator == null) { comparator = new RepositoryComparator(getParentHelper(), remoteRepo); - comparator.compare(context); +// comparator.compare(context); // XXX meanwhile we use distinct path to calculate common } return comparator; } @@ -182,11 +187,13 @@ } private List<Nodeid> getCommon(Object context) throws HgException, CancelledException { +// return getComparator(context).getCommon(); final LinkedHashSet<Nodeid> common = new LinkedHashSet<Nodeid>(); // XXX common can be obtained from repoCompare, but at the moment it would almost duplicate work of calculateMissingBranches // once I refactor latter, common shall be taken from repoCompare. + RepositoryComparator repoCompare = getComparator(context); for (BranchChain bc : getMissingBranches(context)) { - common.add(bc.branchRoot); + repoCompare.collectKnownRoots(bc, common); } return new LinkedList<Nodeid>(common); }