Mercurial > hg4j
comparison src/org/tmatesoft/hg/core/HgPullCommand.java @ 660:4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 09 Jul 2013 21:46:45 +0200 |
parents | |
children | 46b56864b483 |
comparison
equal
deleted
inserted
replaced
658:d10399f80f4e | 660:4fd317a2fecf |
---|---|
1 /* | |
2 * Copyright (c) 2013 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.core; | |
18 | |
19 import java.util.List; | |
20 | |
21 import org.tmatesoft.hg.internal.AddRevInspector; | |
22 import org.tmatesoft.hg.internal.COWTransaction; | |
23 import org.tmatesoft.hg.internal.Internals; | |
24 import org.tmatesoft.hg.internal.PhasesHelper; | |
25 import org.tmatesoft.hg.internal.RepositoryComparator; | |
26 import org.tmatesoft.hg.internal.RevisionSet; | |
27 import org.tmatesoft.hg.internal.Transaction; | |
28 import org.tmatesoft.hg.repo.HgBundle; | |
29 import org.tmatesoft.hg.repo.HgChangelog; | |
30 import org.tmatesoft.hg.repo.HgInternals; | |
31 import org.tmatesoft.hg.repo.HgParentChildMap; | |
32 import org.tmatesoft.hg.repo.HgRemoteRepository; | |
33 import org.tmatesoft.hg.repo.HgRepository; | |
34 import org.tmatesoft.hg.repo.HgRuntimeException; | |
35 import org.tmatesoft.hg.util.CancelledException; | |
36 import org.tmatesoft.hg.util.ProgressSupport; | |
37 | |
38 /** | |
39 * | |
40 * @author Artem Tikhomirov | |
41 * @author TMate Software Ltd. | |
42 */ | |
43 public class HgPullCommand extends HgAbstractCommand<HgPullCommand> { | |
44 | |
45 private final HgRepository repo; | |
46 private HgRemoteRepository remote; | |
47 | |
48 public HgPullCommand(HgRepository hgRepo) { | |
49 repo = hgRepo; | |
50 } | |
51 | |
52 public HgPullCommand source(HgRemoteRepository hgRemote) { | |
53 remote = hgRemote; | |
54 return this; | |
55 } | |
56 | |
57 public void execute() throws HgRemoteConnectionException, HgIOException, HgLibraryFailureException, CancelledException { | |
58 final ProgressSupport progress = getProgressSupport(null); | |
59 try { | |
60 progress.start(100); | |
61 // TODO refactor same code in HgIncomingCommand #getComparator and #getParentHelper | |
62 final HgChangelog clog = repo.getChangelog(); | |
63 final HgParentChildMap<HgChangelog> parentHelper = new HgParentChildMap<HgChangelog>(clog); | |
64 parentHelper.init(); | |
65 final RepositoryComparator comparator = new RepositoryComparator(parentHelper, remote); | |
66 // get incoming revisions | |
67 comparator.compare(new ProgressSupport.Sub(progress, 50), getCancelSupport(null, true)); | |
68 final List<Nodeid> common = comparator.getCommon(); | |
69 // get bundle with changes from remote | |
70 HgBundle incoming = remote.getChanges(common); | |
71 // | |
72 // add revisions to changelog, manifest, files | |
73 final Internals implRepo = HgInternals.getImplementationRepo(repo); | |
74 final AddRevInspector insp; | |
75 Transaction.Factory trFactory = new COWTransaction.Factory(); | |
76 Transaction tr = trFactory.create(repo); | |
77 try { | |
78 incoming.inspectAll(insp = new AddRevInspector(implRepo, tr)); | |
79 tr.commit(); | |
80 } catch (HgRuntimeException ex) { | |
81 tr.rollback(); | |
82 throw ex; | |
83 } catch (RuntimeException ex) { | |
84 tr.rollback(); | |
85 throw ex; | |
86 } | |
87 progress.worked(45); | |
88 RevisionSet added = insp.addedChangesets(); | |
89 | |
90 // get remote phases, update local phases to match that of remote | |
91 final PhasesHelper phaseHelper = new PhasesHelper(implRepo, parentHelper); | |
92 if (phaseHelper.isCapableOfPhases()) { | |
93 RevisionSet rsCommon = new RevisionSet(common); | |
94 HgRemoteRepository.Phases remotePhases = remote.getPhases(); | |
95 if (remotePhases.isPublishingServer()) { | |
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 } | |
104 progress.worked(5); | |
105 } catch (HgRuntimeException ex) { | |
106 throw new HgLibraryFailureException(ex); | |
107 } finally { | |
108 progress.done(); | |
109 } | |
110 } | |
111 } |