Mercurial > jhg
annotate 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 |
rev | line source |
---|---|
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.core; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.File; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.io.IOException; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.net.URL; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.util.List; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.internal.BundleGenerator; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.tmatesoft.hg.internal.RepositoryComparator; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import org.tmatesoft.hg.repo.HgBundle; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.repo.HgChangelog; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import org.tmatesoft.hg.repo.HgInternals; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgInvalidStateException; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import org.tmatesoft.hg.repo.HgLookup; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgParentChildMap; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import org.tmatesoft.hg.repo.HgRemoteRepository; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import org.tmatesoft.hg.repo.HgRepository; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 import org.tmatesoft.hg.repo.HgRuntimeException; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import org.tmatesoft.hg.util.CancelledException; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import org.tmatesoft.hg.util.ProgressSupport; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 /** |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 * |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 * @author Artem Tikhomirov |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * @author TMate Software Ltd. |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 */ |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 public class HgPushCommand extends HgAbstractCommand<HgPushCommand> { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 private final HgRepository repo; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 private HgRemoteRepository remoteRepo; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 public HgPushCommand(HgRepository hgRepo) { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 repo = hgRepo; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 public HgPushCommand destination(HgRemoteRepository hgRemote) { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 remoteRepo = hgRemote; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 return this; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 public void execute() throws HgRemoteConnectionException, HgIOException, CancelledException, HgLibraryFailureException { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 final ProgressSupport progress = getProgressSupport(null); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 try { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 progress.start(100); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 // |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 // find out missing |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 // TODO refactor same code in HgOutgoingCommand #getComparator and #getParentHelper |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 final HgParentChildMap<HgChangelog> parentHelper = new HgParentChildMap<HgChangelog>(repo.getChangelog()); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 parentHelper.init(); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 final RepositoryComparator comparator = new RepositoryComparator(parentHelper, remoteRepo); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 comparator.compare(new ProgressSupport.Sub(progress, 50), getCancelSupport(null, true)); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 List<Nodeid> l = comparator.getLocalOnlyRevisions(); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 // |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 // prepare bundle |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 BundleGenerator bg = new BundleGenerator(HgInternals.getImplementationRepo(repo)); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 File bundleFile = bg.create(l); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 progress.worked(20); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 HgBundle b = new HgLookup(repo.getSessionContext()).loadBundle(bundleFile); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 // |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 // send changes |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 remoteRepo.unbundle(b, comparator.getRemoteHeads()); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 progress.worked(20); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 // |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 // FIXME update phase information |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 // remote.listkeys("phases"); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 progress.worked(5); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 // |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 // FIXME update bookmark information |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 // remote.listkeys("bookmarks"); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 progress.worked(5); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } catch (IOException ex) { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 throw new HgIOException(ex.getMessage(), null); // XXX not a nice idea to throw IOException from BundleGenerator#create |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 } catch (HgRepositoryNotFoundException ex) { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 final HgInvalidStateException e = new HgInvalidStateException("Failed to load a just-created bundle"); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 e.initCause(ex); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 throw new HgLibraryFailureException(e); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 } catch (HgRuntimeException ex) { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 throw new HgLibraryFailureException(ex); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 } finally { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 progress.done(); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 /* |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 * To test, start a server: |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 * $ hg --config web.allow_push=* --config web.push_ssl=False --config server.validate=True --debug serve |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 */ |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 public static void main(String[] args) throws Exception { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 final HgLookup hgLookup = new HgLookup(); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 HgRepository r = hgLookup.detect("/home/artem/hg/junit-test-repos/log-1/"); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 HgRemoteRepository rr = hgLookup.detect(new URL("http://localhost:8000/")); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 new HgPushCommand(r).destination(rr).execute(); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 } |