Mercurial > hg4j
comparison 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 |
comparison
equal
deleted
inserted
replaced
662:af5223b86dd3 | 663:46b56864b483 |
---|---|
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.core; | 17 package org.tmatesoft.hg.core; |
18 | 18 |
19 import java.io.IOException; | |
20 import java.util.Collection; | |
21 import java.util.Collections; | |
19 import java.util.List; | 22 import java.util.List; |
20 | 23 |
21 import org.tmatesoft.hg.internal.AddRevInspector; | 24 import org.tmatesoft.hg.internal.AddRevInspector; |
22 import org.tmatesoft.hg.internal.COWTransaction; | 25 import org.tmatesoft.hg.internal.COWTransaction; |
23 import org.tmatesoft.hg.internal.Internals; | 26 import org.tmatesoft.hg.internal.Internals; |
42 */ | 45 */ |
43 public class HgPullCommand extends HgAbstractCommand<HgPullCommand> { | 46 public class HgPullCommand extends HgAbstractCommand<HgPullCommand> { |
44 | 47 |
45 private final HgRepository repo; | 48 private final HgRepository repo; |
46 private HgRemoteRepository remote; | 49 private HgRemoteRepository remote; |
50 private RevisionSet added; | |
47 | 51 |
48 public HgPullCommand(HgRepository hgRepo) { | 52 public HgPullCommand(HgRepository hgRepo) { |
49 repo = hgRepo; | 53 repo = hgRepo; |
50 } | 54 } |
51 | 55 |
74 final AddRevInspector insp; | 78 final AddRevInspector insp; |
75 Transaction.Factory trFactory = new COWTransaction.Factory(); | 79 Transaction.Factory trFactory = new COWTransaction.Factory(); |
76 Transaction tr = trFactory.create(repo); | 80 Transaction tr = trFactory.create(repo); |
77 try { | 81 try { |
78 incoming.inspectAll(insp = new AddRevInspector(implRepo, tr)); | 82 incoming.inspectAll(insp = new AddRevInspector(implRepo, tr)); |
83 insp.done(); | |
79 tr.commit(); | 84 tr.commit(); |
80 } catch (HgRuntimeException ex) { | 85 } catch (HgRuntimeException ex) { |
81 tr.rollback(); | 86 tr.rollback(); |
82 throw ex; | 87 throw ex; |
88 } catch (IOException ex) { | |
89 tr.rollback(); | |
90 throw new HgIOException(ex.getMessage(), ex, null); // FIXME throw HgIOException right away | |
83 } catch (RuntimeException ex) { | 91 } catch (RuntimeException ex) { |
84 tr.rollback(); | 92 tr.rollback(); |
85 throw ex; | 93 throw ex; |
86 } | 94 } |
87 progress.worked(45); | 95 progress.worked(45); |
88 RevisionSet added = insp.addedChangesets(); | 96 added = insp.addedChangesets(); |
89 | 97 |
98 if (!added.isEmpty()) { | |
99 // FIXME refresh parentHelper with newly added revisions in effective way | |
100 parentHelper.init(); | |
101 } | |
90 // get remote phases, update local phases to match that of remote | 102 // get remote phases, update local phases to match that of remote |
103 // do not update any remote phase (it's pull, after all) | |
91 final PhasesHelper phaseHelper = new PhasesHelper(implRepo, parentHelper); | 104 final PhasesHelper phaseHelper = new PhasesHelper(implRepo, parentHelper); |
92 if (phaseHelper.isCapableOfPhases()) { | 105 if (phaseHelper.isCapableOfPhases()) { |
93 RevisionSet rsCommon = new RevisionSet(common); | 106 RevisionSet rsCommon = new RevisionSet(common); |
94 HgRemoteRepository.Phases remotePhases = remote.getPhases(); | 107 HgRemoteRepository.Phases remotePhases = remote.getPhases(); |
95 if (remotePhases.isPublishingServer()) { | 108 phaseHelper.synchronizeWithRemote(remotePhases, rsCommon.union(added)); |
96 final RevisionSet knownPublic = rsCommon.union(added); | |
97 RevisionSet newDraft = phaseHelper.allDraft().subtract(knownPublic); | |
98 RevisionSet newSecret = phaseHelper.allSecret().subtract(knownPublic); | |
99 phaseHelper.updateRoots(newDraft.asList(), newSecret.asList()); | |
100 } else { | |
101 // FIXME refactor reuse from HgPushCommand | |
102 } | |
103 } | 109 } |
104 progress.worked(5); | 110 progress.worked(5); |
105 } catch (HgRuntimeException ex) { | 111 } catch (HgRuntimeException ex) { |
106 throw new HgLibraryFailureException(ex); | 112 throw new HgLibraryFailureException(ex); |
107 } finally { | 113 } finally { |
108 progress.done(); | 114 progress.done(); |
109 } | 115 } |
110 } | 116 } |
117 | |
118 public Collection<Nodeid> getPulledRevisions() { | |
119 return added == null ? Collections.<Nodeid>emptyList() : added.asList(); | |
120 } | |
111 } | 121 } |