Mercurial > hg4j
annotate cmdline/org/tmatesoft/hg/console/Outgoing.java @ 203:66fd2c73c56f
Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 26 Apr 2011 15:52:33 +0200 |
parents | e5407b5a586a |
children | 63c9fed4369e |
rev | line source |
---|---|
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
13 * For information on how to redistribute this software under |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
102
a3a2e5deb320
Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
98
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
17 package org.tmatesoft.hg.console; |
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.util.Collection; |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.util.List; |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
22 import org.tmatesoft.hg.core.Nodeid; |
181
cd3371670f0b
Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
178
diff
changeset
|
23 import org.tmatesoft.hg.internal.RepositoryComparator; |
97
ee2c750b036d
Changelog to HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
24 import org.tmatesoft.hg.repo.HgChangelog; |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
25 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
171
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
26 import org.tmatesoft.hg.repo.HgLookup; |
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
27 import org.tmatesoft.hg.repo.HgRemoteRepository; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
28 import org.tmatesoft.hg.repo.HgRepository; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
29 |
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 /** |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
32 * WORK IN PROGRESS, DO NOT USE |
171
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
33 * hg outgoing |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
34 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
35 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
36 * @author TMate Software Ltd. |
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 */ |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 public class Outgoing { |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 public static void main(String[] args) throws Exception { |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
41 final boolean debug = true; // perhaps, use hg4j.remote.debug or own property? |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
42 Options cmdLineOpts = Options.parse(args); |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
30
diff
changeset
|
43 HgRepository hgRepo = cmdLineOpts.findRepository(); |
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 if (hgRepo.isInvalid()) { |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 return; |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 } |
185
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
48 HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo); |
181
cd3371670f0b
Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
178
diff
changeset
|
49 if (hgRemote.isInvalid()) { |
cd3371670f0b
Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
178
diff
changeset
|
50 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation()); |
cd3371670f0b
Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
178
diff
changeset
|
51 return; |
172
87f40938c9b2
Configuration handling out of HgLookup (bad idea to use URL to pass keys)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
52 } |
171
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
53 |
185
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
54 HgChangelog changelog = hgRepo.getChangelog(); |
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
55 HgChangelog.ParentWalker pw = changelog.new ParentWalker(); |
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 pw.init(); |
171
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
57 |
181
cd3371670f0b
Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
178
diff
changeset
|
58 RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote); |
cd3371670f0b
Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
178
diff
changeset
|
59 repoCompare.compare(null); |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
60 if (debug) { |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
61 List<Nodeid> commonKnown = repoCompare.getCommon(); |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
62 dump("Nodes known to be both locally and at remote server", commonKnown); |
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 } |
171
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
64 // find all local children of commonKnown |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
65 List<Nodeid> result = repoCompare.getLocalOnlyRevisions(); |
185
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
66 dump("Lite", result); |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
67 // |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
68 // |
185
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
69 System.out.println("Full"); |
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
70 // show all, starting from next to common |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
71 repoCompare.visitLocalOnlyRevisions(new HgChangelog.Inspector() { |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
72 private final ChangesetFormatter formatter = new ChangesetFormatter(); |
185
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
73 |
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
74 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
75 System.out.println(formatter.simple(revisionNumber, nodeid, cset)); |
185
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
76 } |
c6fa4dbfc458
Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
181
diff
changeset
|
77 }); |
171
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
78 } |
192
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
79 |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
80 public static class ChangesetFormatter { |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
81 private final StringBuilder sb = new StringBuilder(1024); |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
82 |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
83 public CharSequence simple(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
84 sb.setLength(0); |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
85 sb.append(String.format("changeset: %d:%s\n", revisionNumber, nodeid.toString())); |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
86 sb.append(String.format("user: %s\n", cset.user())); |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
87 sb.append(String.format("date: %s\n", cset.dateString())); |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
88 sb.append(String.format("comment: %s\n\n", cset.comment())); |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
89 return sb; |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
90 } |
e5407b5a586a
Incoming and Outgoing commands are alive
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
185
diff
changeset
|
91 } |
171
2c3e96674e2a
Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
92 |
30
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 private static void dump(String s, Collection<Nodeid> c) { |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 System.out.println(s); |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 for (Nodeid n : c) { |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 System.out.println(n); |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 } |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 } |
de7217a0aa4d
Look up changes in the local repo that are not in the remote
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 } |