Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgPushCommand.java @ 645:14dac192aa26
Push: phase2 - upload bundle with changes to remote server
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 20 Jun 2013 19:15:09 +0200 |
parents | |
children | 3b7d51ed4c65 |
comparison
equal
deleted
inserted
replaced
644:1deea2f33218 | 645:14dac192aa26 |
---|---|
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.io.File; | |
20 import java.io.IOException; | |
21 import java.net.URL; | |
22 import java.util.List; | |
23 | |
24 import org.tmatesoft.hg.internal.BundleGenerator; | |
25 import org.tmatesoft.hg.internal.RepositoryComparator; | |
26 import org.tmatesoft.hg.repo.HgBundle; | |
27 import org.tmatesoft.hg.repo.HgChangelog; | |
28 import org.tmatesoft.hg.repo.HgInternals; | |
29 import org.tmatesoft.hg.repo.HgInvalidStateException; | |
30 import org.tmatesoft.hg.repo.HgLookup; | |
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 HgPushCommand extends HgAbstractCommand<HgPushCommand> { | |
44 | |
45 private final HgRepository repo; | |
46 private HgRemoteRepository remoteRepo; | |
47 | |
48 public HgPushCommand(HgRepository hgRepo) { | |
49 repo = hgRepo; | |
50 } | |
51 | |
52 public HgPushCommand destination(HgRemoteRepository hgRemote) { | |
53 remoteRepo = hgRemote; | |
54 return this; | |
55 } | |
56 | |
57 public void execute() throws HgRemoteConnectionException, HgIOException, CancelledException, HgLibraryFailureException { | |
58 final ProgressSupport progress = getProgressSupport(null); | |
59 try { | |
60 progress.start(100); | |
61 // | |
62 // find out missing | |
63 // TODO refactor same code in HgOutgoingCommand #getComparator and #getParentHelper | |
64 final HgParentChildMap<HgChangelog> parentHelper = new HgParentChildMap<HgChangelog>(repo.getChangelog()); | |
65 parentHelper.init(); | |
66 final RepositoryComparator comparator = new RepositoryComparator(parentHelper, remoteRepo); | |
67 comparator.compare(new ProgressSupport.Sub(progress, 50), getCancelSupport(null, true)); | |
68 List<Nodeid> l = comparator.getLocalOnlyRevisions(); | |
69 // | |
70 // prepare bundle | |
71 BundleGenerator bg = new BundleGenerator(HgInternals.getImplementationRepo(repo)); | |
72 File bundleFile = bg.create(l); | |
73 progress.worked(20); | |
74 HgBundle b = new HgLookup(repo.getSessionContext()).loadBundle(bundleFile); | |
75 // | |
76 // send changes | |
77 remoteRepo.unbundle(b, comparator.getRemoteHeads()); | |
78 progress.worked(20); | |
79 // | |
80 // FIXME update phase information | |
81 // remote.listkeys("phases"); | |
82 progress.worked(5); | |
83 // | |
84 // FIXME update bookmark information | |
85 // remote.listkeys("bookmarks"); | |
86 progress.worked(5); | |
87 } catch (IOException ex) { | |
88 throw new HgIOException(ex.getMessage(), null); // XXX not a nice idea to throw IOException from BundleGenerator#create | |
89 } catch (HgRepositoryNotFoundException ex) { | |
90 final HgInvalidStateException e = new HgInvalidStateException("Failed to load a just-created bundle"); | |
91 e.initCause(ex); | |
92 throw new HgLibraryFailureException(e); | |
93 } catch (HgRuntimeException ex) { | |
94 throw new HgLibraryFailureException(ex); | |
95 } finally { | |
96 progress.done(); | |
97 } | |
98 } | |
99 | |
100 /* | |
101 * To test, start a server: | |
102 * $ hg --config web.allow_push=* --config web.push_ssl=False --config server.validate=True --debug serve | |
103 */ | |
104 public static void main(String[] args) throws Exception { | |
105 final HgLookup hgLookup = new HgLookup(); | |
106 HgRepository r = hgLookup.detect("/home/artem/hg/junit-test-repos/log-1/"); | |
107 HgRemoteRepository rr = hgLookup.detect(new URL("http://localhost:8000/")); | |
108 new HgPushCommand(r).destination(rr).execute(); | |
109 } | |
110 } |