diff src/org/tmatesoft/hg/core/HgPullCommand.java @ 663:46b56864b483

Pull: phase2 - update phases from remote, fncache with added files. Tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 10 Jul 2013 16:41:49 +0200
parents 4fd317a2fecf
children ae2d439fbed3
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgPullCommand.java	Wed Jul 10 11:53:19 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgPullCommand.java	Wed Jul 10 16:41:49 2013 +0200
@@ -16,6 +16,9 @@
  */
 package org.tmatesoft.hg.core;
 
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import org.tmatesoft.hg.internal.AddRevInspector;
@@ -44,6 +47,7 @@
 
 	private final HgRepository repo;
 	private HgRemoteRepository remote;
+	private RevisionSet added;
 
 	public HgPullCommand(HgRepository hgRepo) {
 		repo = hgRepo;
@@ -76,30 +80,32 @@
 			Transaction tr = trFactory.create(repo);
 			try {
 				incoming.inspectAll(insp = new AddRevInspector(implRepo, tr));
+				insp.done();
 				tr.commit();
 			} catch (HgRuntimeException ex) {
 				tr.rollback();
 				throw ex;
+			} catch (IOException ex) {
+				tr.rollback();
+				throw new HgIOException(ex.getMessage(), ex, null); // FIXME throw HgIOException right away
 			} catch (RuntimeException ex) {
 				tr.rollback();
 				throw ex;
 			}
 			progress.worked(45);
-			RevisionSet added = insp.addedChangesets();
+			added = insp.addedChangesets();
 			
+			if (!added.isEmpty()) {
+				// FIXME refresh parentHelper with newly added revisions in effective way
+				parentHelper.init(); 
+			}
 			// get remote phases, update local phases to match that of remote
+			// do not update any remote phase (it's pull, after all)
 			final PhasesHelper phaseHelper = new PhasesHelper(implRepo, parentHelper);
 			if (phaseHelper.isCapableOfPhases()) {
 				RevisionSet rsCommon = new RevisionSet(common);
 				HgRemoteRepository.Phases remotePhases = remote.getPhases();
-				if (remotePhases.isPublishingServer()) {
-					final RevisionSet knownPublic = rsCommon.union(added);
-					RevisionSet newDraft = phaseHelper.allDraft().subtract(knownPublic);
-					RevisionSet newSecret = phaseHelper.allSecret().subtract(knownPublic);
-					phaseHelper.updateRoots(newDraft.asList(), newSecret.asList());
-				} else {
-					// FIXME refactor reuse from HgPushCommand
-				}
+				phaseHelper.synchronizeWithRemote(remotePhases, rsCommon.union(added));
 			}
 			progress.worked(5);
 		} catch (HgRuntimeException ex) {
@@ -108,4 +114,8 @@
 			progress.done();
 		}
 	}
+	
+	public Collection<Nodeid> getPulledRevisions() {
+		return added == null ? Collections.<Nodeid>emptyList() : added.asList();
+	}
 }