Mercurial > jhg
annotate cmdline/org/tmatesoft/hg/console/Incoming.java @ 181:cd3371670f0b
Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 12 Apr 2011 19:10:38 +0200 |
parents | 62665d8f0686 |
children | f26ffe04ced0 |
rev | line source |
---|---|
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
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:
33
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:
33
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:
33
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
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:
33
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:
33
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:
33
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
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:
33
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 |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
17 package org.tmatesoft.hg.console; |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
19 import java.io.File; |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
20 import java.net.URL; |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
21 import java.util.ArrayList; |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
22 import java.util.Arrays; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
23 import java.util.Collections; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
24 import java.util.Comparator; |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.util.HashSet; |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
26 import java.util.Iterator; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
27 import java.util.LinkedHashMap; |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import java.util.LinkedList; |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import java.util.List; |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
30 import java.util.ListIterator; |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
31 import java.util.Map.Entry; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
32 |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
33 import org.tmatesoft.hg.core.HgException; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
34 import org.tmatesoft.hg.core.Nodeid; |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
35 import org.tmatesoft.hg.internal.ConfigFile; |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
36 import org.tmatesoft.hg.internal.Internals; |
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
|
37 import org.tmatesoft.hg.internal.RepositoryComparator; |
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
|
38 import org.tmatesoft.hg.internal.RepositoryComparator.BranchChain; |
97
ee2c750b036d
Changelog to HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
39 import org.tmatesoft.hg.repo.HgChangelog; |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
40 import org.tmatesoft.hg.repo.HgLookup; |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
41 import org.tmatesoft.hg.repo.HgRemoteRepository; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
42 import org.tmatesoft.hg.repo.HgRepository; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
43 |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 /** |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
46 * WORK IN PROGRESS, DO NOT USE |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
47 * hg incoming counterpart |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
48 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
49 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
50 * @author TMate Software Ltd. |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 */ |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 public class Incoming { |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 public static void main(String[] args) throws Exception { |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
55 if (Boolean.FALSE.booleanValue()) { |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
56 new SequenceConstructor().test(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
57 return; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
58 } |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
59 Options cmdLineOpts = Options.parse(args); |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
33
diff
changeset
|
60 HgRepository hgRepo = cmdLineOpts.findRepository(); |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 if (hgRepo.isInvalid()) { |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 return; |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 } |
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
|
65 HgRemoteRepository hgRemote = new HgLookup().detectRemote("svnkit", hgRepo); |
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
|
66 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
|
67 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
|
68 return; |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
69 } |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
70 // |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 // in fact, all we need from changelog is set of all nodeids. However, since ParentWalker reuses same Nodeids, it's not too expensive |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 // to reuse it here, XXX although later this may need to be refactored |
98
225c48d964ed
Changelog to HgChangelog, Refactoring doesn't recognize name with inner class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
97
diff
changeset
|
73 final HgChangelog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker(); |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 pw.init(); |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 // |
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
|
76 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
|
77 repoCompare.compare(null); |
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
|
78 List<BranchChain> missingBranches0 = repoCompare.calculateMissingBranches(); |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
79 for (BranchChain bc : missingBranches0) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
80 bc.dump(); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
81 |
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
|
82 List<Nodeid> missing = visitBranches(repoCompare, bc); |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
83 // Collections.reverse(missing); // useful to test output, from newer to older |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
84 for (Nodeid n : missing) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
85 if (pw.knownNode(n)) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
86 System.out.println("Erroneous to fetch:" + n); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
87 } else { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
88 System.out.println(n); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
89 } |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
90 } |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
91 System.out.println("Branch done"); |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 } |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
93 |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
94 } |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
95 |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
96 |
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
|
97 private static List<Nodeid> visitBranches(RepositoryComparator repoCompare, BranchChain bc) throws HgException { |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
98 if (bc == null) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
99 return Collections.emptyList(); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
100 } |
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
|
101 List<Nodeid> mine = repoCompare.completeBranch(bc.branchRoot, bc.branchHead); |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
102 if (bc.isTerminal()) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
103 return mine; |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
104 } |
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
|
105 List<Nodeid> parentBranch1 = visitBranches(repoCompare, bc.p1); |
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
|
106 List<Nodeid> parentBranch2 = visitBranches(repoCompare, bc.p2); |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
107 // merge |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
108 LinkedList<Nodeid> merged = new LinkedList<Nodeid>(); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
109 ListIterator<Nodeid> i1 = parentBranch1.listIterator(), i2 = parentBranch2.listIterator(); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
110 while (i1.hasNext() && i2.hasNext()) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
111 Nodeid n1 = i1.next(); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
112 Nodeid n2 = i2.next(); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
113 if (n1.equals(n2)) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
114 merged.addLast(n1); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
115 } else { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
116 // first different => add both, and continue adding both tails sequentially |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
117 merged.add(n2); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
118 merged.add(n1); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
119 break; |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
120 } |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
121 } |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
122 // copy rest of second parent branch |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
123 while (i2.hasNext()) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
124 merged.add(i2.next()); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
125 } |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
126 // copy rest of first parent branch |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
127 while (i1.hasNext()) { |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
128 merged.add(i1.next()); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
129 } |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 // |
178
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
131 ArrayList<Nodeid> rv = new ArrayList<Nodeid>(mine.size() + merged.size()); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
132 rv.addAll(merged); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
133 rv.addAll(mine); |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
134 return rv; |
62665d8f0686
Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
177
diff
changeset
|
135 } |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 |
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
138 private static class SequenceConstructor { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
139 |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
140 private int[] between(int root, int head) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
141 if (head <= (root+1)) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
142 return new int[0]; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
143 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
144 System.out.printf("[%d, %d]\t\t", root, head); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
145 int size = 1 + (int) Math.floor(Math.log(head-root - 1) / Math.log(2)); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
146 int[] rv = new int[size]; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
147 for (int v = 1, i = 0; i < rv.length; i++) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
148 rv[i] = root + v; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
149 v = v << 1; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
150 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
151 System.out.println(Arrays.toString(rv)); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
152 return rv; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
153 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
154 |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
155 public void test() { |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
156 int root = 0, head = 126; |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
157 int[] data = between(root, head); // max number of elements to recover is 2**data.length-1, when head is exactly |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
158 // 2**data.length element of the branch. |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
159 // In such case, total number of elements in the branch (including head and root, would be 2**data.length+1 |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
160 int[] finalSequence = new int[1 + (1 << data.length >>> 5)]; // div 32 - total bits to integers, +1 for possible modulus |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
161 int exactNumberOfElements = -1; // exact number of meaningful bits in finalSequence |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
162 LinkedHashMap<Integer, int[]> datas = new LinkedHashMap<Integer, int[]>(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
163 datas.put(root, data); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
164 int totalQueries = 1; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
165 HashSet<Integer> queried = new HashSet<Integer>(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
166 int[] checkSequence = null; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
167 while(!datas.isEmpty()) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
168 LinkedList<int[]> toQuery = new LinkedList<int[]>(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
169 do { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
170 Iterator<Entry<Integer, int[]>> it = datas.entrySet().iterator(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
171 Entry<Integer, int[]> next = it.next(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
172 int r = next.getKey(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
173 data = next.getValue(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
174 it.remove(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
175 populate(r, head, data, finalSequence); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
176 if (checkSequence != null) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
177 boolean match = true; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
178 // System.out.println("Try to match:"); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
179 for (int i = 0; i < checkSequence.length; i++) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
180 // System.out.println(i); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
181 // System.out.println("control:" + toBinaryString(checkSequence[i], ' ')); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
182 // System.out.println("present:" + toBinaryString(finalSequence[i], ' ')); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
183 if (checkSequence[i] != finalSequence[i]) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
184 match = false; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
185 } else { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
186 match &= true; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
187 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
188 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
189 System.out.println(match ? "Match, on query:" + totalQueries : "Didn't match"); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
190 } |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
191 if (data.length > 1) { |
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
192 /*queries for elements next to head is senseless, hence data.length check above and head-x below*/ |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
193 for (int x : data) { |
176
a8df7162ec75
Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
174
diff
changeset
|
194 if (!queried.contains(x) && head - x > 1) { |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
195 toQuery.add(new int[] {x, head}); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
196 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
197 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
198 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
199 } while (!datas.isEmpty()) ; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
200 if (!toQuery.isEmpty()) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
201 System.out.println(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
202 totalQueries++; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
203 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
204 Collections.sort(toQuery, new Comparator<int[]>() { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
205 |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
206 public int compare(int[] o1, int[] o2) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
207 return o1[0] < o2[0] ? -1 : (o1[0] == o2[0] ? 0 : 1); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
208 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
209 }); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
210 for (int[] x : toQuery) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
211 if (!queried.contains(x[0])) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
212 queried.add(x[0]); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
213 data = between(x[0], x[1]); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
214 if (exactNumberOfElements == -1 && data.length == 1) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
215 exactNumberOfElements = x[0] + 1; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
216 System.out.printf("On query %d found out exact number of missing elements: %d\n", totalQueries, exactNumberOfElements); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
217 // get a bit sequence of exactNumberOfElements, 0111..110 |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
218 // to 'and' it with finalSequence later |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
219 int totalInts = (exactNumberOfElements + 2 /*heading and tailing zero bits*/) >>> 5; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
220 int trailingBits = (exactNumberOfElements + 2) & 0x1f; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
221 if (trailingBits != 0) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
222 totalInts++; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
223 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
224 checkSequence = new int[totalInts]; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
225 Arrays.fill(checkSequence, 0xffffffff); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
226 checkSequence[0] &= 0x7FFFFFFF; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
227 if (trailingBits == 0) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
228 checkSequence[totalInts-1] &= 0xFFFFFFFE; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
229 } else if (trailingBits == 1) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
230 checkSequence[totalInts-1] = 0; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
231 } else { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
232 // trailingBits include heading and trailing zero bits |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
233 int mask = 0x80000000 >> trailingBits-2; // with sign! |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
234 checkSequence[totalInts - 1] &= mask; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
235 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
236 for (int e : checkSequence) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
237 System.out.print(toBinaryString(e, ' ')); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
238 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
239 System.out.println(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
240 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
241 datas.put(x[0], data); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
242 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
243 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
244 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
245 |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
246 System.out.println("Total queries:" + totalQueries); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
247 for (int x : finalSequence) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
248 System.out.print(toBinaryString(x, ' ')); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
249 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
250 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
251 |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
252 private void populate(int root, int head, int[] data, int[] finalSequence) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
253 for (int i = 1, x = 0; root+i < head; i = i << 1, x++) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
254 int value = data[x]; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
255 int value_check = root+i; |
174
b1de83ffa7f8
Build shall succeed with no precompiled classes, too
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
173
diff
changeset
|
256 if (value != value_check) { |
b1de83ffa7f8
Build shall succeed with no precompiled classes, too
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
173
diff
changeset
|
257 throw new IllegalStateException(); |
b1de83ffa7f8
Build shall succeed with no precompiled classes, too
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
173
diff
changeset
|
258 } |
173
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
259 int wordIx = (root + i) >>> 5; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
260 int bitIx = (root + i) & 0x1f; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
261 finalSequence[wordIx] |= 1 << (31-bitIx); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
262 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
263 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
264 |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
265 private static String toBinaryString(int x, char byteSeparator) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
266 StringBuilder sb = new StringBuilder(4*8+4); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
267 sb.append(toBinaryString((byte) (x >>> 24))); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
268 sb.append(byteSeparator); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
269 sb.append(toBinaryString((byte) ((x & 0x00ff0000) >>> 16))); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
270 sb.append(byteSeparator); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
271 sb.append(toBinaryString((byte) ((x & 0x00ff00) >>> 8))); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
272 sb.append(byteSeparator); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
273 sb.append(toBinaryString((byte) (x & 0x00ff))); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
274 sb.append(byteSeparator); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
275 return sb.toString(); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
276 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
277 |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
278 private static String toBinaryString(byte b) { |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
279 final String nibbles = "0000000100100011010001010110011110001001101010111100110111101111"; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
280 assert nibbles.length() == 16*4; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
281 int x1 = (b >>> 4) & 0x0f, x2 = b & 0x0f; |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
282 x1 *= 4; x2 *= 4; // 4 characters per nibble |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
283 return nibbles.substring(x1, x1+4).concat(nibbles.substring(x2, x2+4)); |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
284 } |
4bf061a7c001
Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
171
diff
changeset
|
285 } |
31
346b66add79d
Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
286 } |