annotate cmdline/org/tmatesoft/hg/console/Incoming.java @ 178:62665d8f0686

Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 06 Apr 2011 01:34:16 +0200
parents e10225daface
children cd3371670f0b
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
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
19 import static org.tmatesoft.hg.core.Nodeid.NULL;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
20
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
21 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
22 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
23 import java.util.ArrayList;
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
24 import java.util.Arrays;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
25 import java.util.Collections;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
26 import java.util.Comparator;
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
27 import java.util.HashMap;
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.HashSet;
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
29 import java.util.Iterator;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
30 import java.util.LinkedHashMap;
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import java.util.LinkedList;
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 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
33 import java.util.ListIterator;
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
34 import java.util.Map;
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
35 import java.util.Map.Entry;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
36
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
37 import org.tmatesoft.hg.core.HgBadStateException;
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
38 import org.tmatesoft.hg.core.HgException;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
39 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
40 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
41 import org.tmatesoft.hg.internal.Internals;
97
ee2c750b036d Changelog to HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
42 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
43 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
44 import org.tmatesoft.hg.repo.HgRemoteRepository;
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
45 import org.tmatesoft.hg.repo.HgRemoteRepository.Range;
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
46 import org.tmatesoft.hg.repo.HgRemoteRepository.RemoteBranch;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
47 import org.tmatesoft.hg.repo.HgRepository;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
48
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 /**
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
51 * 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
52 * hg incoming counterpart
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
53 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
54 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
55 * @author TMate Software Ltd.
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 */
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 public class Incoming {
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 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
60 if (Boolean.FALSE.booleanValue()) {
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
61 new SequenceConstructor().test();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
62 return;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
63 }
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
64 Options cmdLineOpts = Options.parse(args);
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
65 HgRepository hgRepo = cmdLineOpts.findRepository();
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 if (hgRepo.isInvalid()) {
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 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
68 return;
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 }
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
70 String key = "svnkit";
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
71 ConfigFile cfg = new Internals().newConfigFile();
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
72 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc"));
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
73 String server = cfg.getSection("paths").get(key);
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
74 if (server == null) {
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
75 throw new HgException(String.format("Can't find server %s specification in the config", key));
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
76 }
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
77 HgRemoteRepository hgRemote = new HgLookup().detect(new URL(server));
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
78 //
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 // 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
80 // 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
81 final HgChangelog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker();
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 pw.init();
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 //
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
84 List<BranchChain> missingBranches0 = calculateMissingBranches(pw, hgRemote);
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 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
86 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
87
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 List<Nodeid> missing = visitBranches(hgRemote, bc);
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 // 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
90 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
91 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
92 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
93 } 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
94 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
95 }
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
96 }
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
97 System.out.println("Branch done");
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 }
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
99
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 }
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
101
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 private static class BranchChain {
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 // when we construct a chain, we know head which is missing locally, hence init it right away.
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 // as for root (branch unknown start), we might happen to have one locally, and need further digging to find out right branch start
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
105 public final Nodeid branchHead;
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
106 public Nodeid branchRoot;
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 // either of these can be null, or both.
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 // although RemoteBranch has either both parents null, or both non-null, when we construct a chain
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 // we might encounter that we locally know one of branch's parent, hence in the chain corresponding field will be blank.
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 public BranchChain p1;
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 public BranchChain p2;
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
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 public BranchChain(Nodeid head) {
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 assert head != 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
115 branchHead = head;
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 }
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 public boolean 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
118 return p1 == null || p2 == 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
119 }
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 @Override
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 public String toString() {
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 return String.format("BranchChain [%s, %s]", branchRoot, branchHead);
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 }
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 void 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
126 System.out.println(toString());
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 internalDump(" ");
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 }
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 void internalDump(String prefix) {
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
130 if (p1 != 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
131 System.out.println(prefix + p1.toString());
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 }
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 if (p2 != 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
134 System.out.println(prefix + p2.toString());
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 }
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
136 prefix += " ";
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
137 if (p1 != 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
138 p1.internalDump(prefix);
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
139 }
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
140 if (p2 != 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
141 p2.internalDump(prefix);
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 }
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 }
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 }
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
145
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
146 private static List<Nodeid> visitBranches(HgRemoteRepository hgRemote, BranchChain bc) throws HgException {
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
147 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
148 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
149 }
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
150 List<Nodeid> mine = completeBranch(hgRemote, bc.branchRoot, bc.branchHead);
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
151 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
152 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
153 }
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
154 List<Nodeid> parentBranch1 = visitBranches(hgRemote, bc.p1);
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
155 List<Nodeid> parentBranch2 = visitBranches(hgRemote, bc.p2);
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
156 // 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 } 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
165 // 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
166 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
167 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
168 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
169 }
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
170 }
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
171 // 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
172 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
173 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
174 }
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
175 // 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
176 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
177 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
178 }
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 //
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
180 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
181 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
182 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
183 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
184 }
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
185
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
186 // somewhat similar to Outgoing.findCommonWithRemote()
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
187 private static List<BranchChain> calculateMissingBranches(HgChangelog.ParentWalker pwLocal, HgRemoteRepository hgRemote) throws HgException {
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
188 List<Nodeid> remoteHeads = hgRemote.heads();
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
189 LinkedList<Nodeid> common = new LinkedList<Nodeid>(); // these remotes are known in local
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
190 LinkedList<Nodeid> toQuery = new LinkedList<Nodeid>(); // these need further queries to find common
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
191 for (Nodeid rh : remoteHeads) {
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
192 if (pwLocal.knownNode(rh)) {
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
193 common.add(rh);
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
194 } 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
195 toQuery.add(rh);
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
196 }
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
197 }
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
198 if (toQuery.isEmpty()) {
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
199 return Collections.emptyList(); // no incoming changes
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
200 }
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
201 LinkedList<BranchChain> branches2load = new LinkedList<BranchChain>(); // return value
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
202 // detailed comments are in Outgoing.findCommonWithRemote
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
203 LinkedList<RemoteBranch> checkUp2Head = new LinkedList<RemoteBranch>();
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
204 // records relation between branch head and its parent branch, if any
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
205 HashMap<Nodeid, BranchChain> head2chain = new HashMap<Nodeid, Incoming.BranchChain>();
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
206 while (!toQuery.isEmpty()) {
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
207 List<RemoteBranch> remoteBranches = hgRemote.branches(toQuery); //head, root, first parent, second parent
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
208 toQuery.clear();
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
209 while(!remoteBranches.isEmpty()) {
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
210 RemoteBranch rb = remoteBranches.remove(0);
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
211 BranchChain chainElement = head2chain.get(rb.head);
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
212 if (chainElement == 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
213 chainElement = new BranchChain(rb.head);
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
214 // record this unknown branch to download later
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
215 branches2load.add(chainElement);
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
216 }
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
217 if (pwLocal.knownNode(rb.root)) {
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
218 // we known branch start, common head is somewhere in its descendants line
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
219 checkUp2Head.add(rb);
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
220 } 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
221 chainElement.branchRoot = rb.root;
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
222 // dig deeper in the history, if necessary
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
223 if (!NULL.equals(rb.p1) && !pwLocal.knownNode(rb.p1)) {
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
224 toQuery.add(rb.p1);
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
225 head2chain.put(rb.p1, chainElement.p1 = new BranchChain(rb.p1));
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
226 }
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
227 if (!NULL.equals(rb.p2) && !pwLocal.knownNode(rb.p2)) {
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
228 toQuery.add(rb.p2);
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
229 head2chain.put(rb.p2, chainElement.p2 = new BranchChain(rb.p2));
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
230 }
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
231 }
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
232 }
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
233 }
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
234 for (RemoteBranch rb : checkUp2Head) {
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
235 Nodeid h = rb.head;
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
236 Nodeid r = rb.root;
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
237 int watchdog = 1000;
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
238 BranchChain bc = head2chain.get(h);
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
239 assert 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
240 // if we know branch root locally, there could be no parent branch chain elements.
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
241 assert bc.p1 == 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
242 assert bc.p2 == 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
243 do {
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
244 List<Nodeid> between = hgRemote.between(h, r);
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
245 if (between.isEmpty()) {
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
246 bc.branchRoot = r;
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
247 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
248 } 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
249 Collections.reverse(between);
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
250 for (Nodeid n : between) {
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
251 if (pwLocal.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
252 r = 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
253 } 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
254 h = 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
255 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
256 }
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
257 }
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
258 Nodeid lastInBetween = between.get(between.size() - 1);
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
259 if (r.equals(lastInBetween)) {
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
260 bc.branchRoot = r;
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
261 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
262 } else if (h.equals(lastInBetween)) { // the only chance for current head pointer to point to the sequence tail
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
263 // is when r is second from the between list end (iow, head,1,[2],4,8...,root)
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
264 bc.branchRoot = r;
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
265 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
266 }
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
267 }
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
268 } while(--watchdog > 0);
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
269 if (watchdog == 0) {
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
270 throw new HgBadStateException(String.format("Can't narrow down branch [%s, %s]", rb.head.shortNotation(), rb.root.shortNotation()));
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
271 }
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
272 }
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
273 return branches2load;
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
274 }
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
275
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
276 /**
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
277 * @return list of nodeids from branchRoot to branchHead, inclusive. IOW, first element of the list is always root of the 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
278 */
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
279 private static List<Nodeid> completeBranch(HgRemoteRepository hgRemote, final Nodeid branchRoot, final Nodeid branchHead) throws HgException {
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
280 class DataEntry {
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
281 public final Nodeid queryHead;
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
282 public final int headIndex;
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
283 public List<Nodeid> entries;
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
284
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
285 public DataEntry(Nodeid head, int index, List<Nodeid> data) {
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
286 queryHead = head;
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
287 headIndex = index;
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
288 entries = data;
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
289 }
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
290 };
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
291
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
292 List<Nodeid> initial = hgRemote.between(branchHead, branchRoot);
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
293 Nodeid[] result = new Nodeid[1 + (1 << initial.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
294 result[0] = branchHead;
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
295 int rootIndex = -1; // index in the result, where to place branche's root.
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
296 if (initial.isEmpty()) {
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
297 rootIndex = 1;
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
298 } else if (initial.size() == 1) {
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
299 rootIndex = 2;
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
300 }
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
301 LinkedList<DataEntry> datas = new LinkedList<DataEntry>();
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
302 // DataEntry in datas has entries list filled with 'between' data, whereas
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
303 // DataEntry in toQuery keeps only nodeid and its index, with entries to be initialized before
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
304 // moving to datas.
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
305 LinkedList<DataEntry> toQuery = new LinkedList<DataEntry>();
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
306 //
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
307 datas.add(new DataEntry(branchHead, 0, initial));
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
308 int totalQueries = 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
309 HashSet<Nodeid> queried = new HashSet<Nodeid>();
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
310 while(!datas.isEmpty()) {
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
311 // keep record of those planned to be queried next time we call between()
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
312 // although may keep these in queried, if really don't want separate collection
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
313 HashSet<Nodeid> scheduled = new HashSet<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
314 do {
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
315 DataEntry de = datas.removeFirst();
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
316 // populate result with discovered elements between de.qiueryRoot and branch's head
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
317 for (int i = 1, j = 0; j < de.entries.size(); i = i << 1, j++) {
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
318 int idx = de.headIndex + i;
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
319 result[idx] = de.entries.get(j);
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
320 }
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
321 // form next query entries from new unknown elements
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
322 if (de.entries.size() > 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
323 /* when entries has only one element, it means de.queryRoot was at head-2 position, and thus
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
324 * no new information can be obtained. E.g. when it's 2, it might be case of [0..4] query with
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
325 * [1,2] result, and we need one more query to get element 3.
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
326 */
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
327 for (int i =1, j = 0; j < de.entries.size(); i = i<<1, j++) {
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
328 int idx = de.headIndex + i;
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
329 Nodeid x = de.entries.get(j);
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
330 if (!queried.contains(x) && !scheduled.contains(x) && (rootIndex == -1 || rootIndex - de.headIndex > 1)) {
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
331 /*queries for elements right before head is senseless, but unless we know head's index, do it anyway*/
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
332 toQuery.add(new DataEntry(x, idx, null));
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
333 scheduled.add(x);
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
334 }
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
335 }
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
336 }
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
337 } while (!datas.isEmpty());
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
338 if (!toQuery.isEmpty()) {
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
339 totalQueries++;
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
340 }
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
341 // for each query, create an between request range, keep record Range->DataEntry to know range's start index
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
342 LinkedList<HgRemoteRepository.Range> betweenBatch = new LinkedList<HgRemoteRepository.Range>();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
343 HashMap<HgRemoteRepository.Range, DataEntry> rangeToEntry = new HashMap<HgRemoteRepository.Range, DataEntry>();
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
344 for (DataEntry de : toQuery) {
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
345 queried.add(de.queryHead);
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
346 HgRemoteRepository.Range r = new HgRemoteRepository.Range(branchRoot, de.queryHead);
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
347 betweenBatch.add(r);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
348 rangeToEntry.put(r, de);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
349 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
350 if (!betweenBatch.isEmpty()) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
351 Map<Range, List<Nodeid>> between = hgRemote.between(betweenBatch);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
352 for (Entry<Range, List<Nodeid>> e : between.entrySet()) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
353 DataEntry de = rangeToEntry.get(e.getKey());
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
354 assert de != null;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
355 de.entries = e.getValue();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
356 if (rootIndex == -1 && de.entries.size() == 1) {
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
357 // returned sequence of length 1 means we used element from [head-2] as root
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
358 int numberOfElementsExcludingRootAndHead = de.headIndex + 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
359 rootIndex = numberOfElementsExcludingRootAndHead + 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
360 System.out.printf("On query %d found out exact number of missing elements: %d\n", totalQueries, numberOfElementsExcludingRootAndHead);
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
361 }
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
362 datas.add(de); // queue up to record result and construct further requests
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
363 }
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
364 betweenBatch.clear();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
365 rangeToEntry.clear();
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
366 }
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
367 toQuery.clear();
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
368 }
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
369 if (rootIndex == -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
370 throw new HgBadStateException("Shall not happen, provided between output is correct"); // FIXME
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
371 }
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
372 result[rootIndex] = branchRoot;
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
373 boolean resultOk = true;
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
374 LinkedList<Nodeid> fromRootToHead = new LinkedList<Nodeid>();
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
375 for (int i = 0; i <= rootIndex; i++) {
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
376 Nodeid n = result[i];
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
377 if (n == null) {
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
378 System.out.printf("ERROR: element %d wasn't found\n",i);
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
379 resultOk = false;
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
380 }
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
381 fromRootToHead.addFirst(n); // reverse order
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
382 }
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
383 System.out.println("Total queries:" + totalQueries);
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
384 if (!resultOk) {
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
385 throw new HgBadStateException("See console for details"); // FIXME
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
386 }
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
387 return fromRootToHead;
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
388 }
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
389
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
390 private static class SequenceConstructor {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
391
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
392 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
393 if (head <= (root+1)) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
394 return new int[0];
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
395 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
396 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
397 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
398 int[] rv = new int[size];
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
399 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
400 rv[i] = root + v;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
401 v = v << 1;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
402 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
403 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
404 return rv;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
405 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
406
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
407 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
408 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
409 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
410 // 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
411 // 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
412 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
413 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
414 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
415 datas.put(root, data);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
416 int totalQueries = 1;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
417 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
418 int[] checkSequence = null;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
419 while(!datas.isEmpty()) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
420 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
421 do {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
422 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
423 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
424 int r = next.getKey();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
425 data = next.getValue();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
426 it.remove();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
427 populate(r, head, data, finalSequence);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
428 if (checkSequence != null) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
429 boolean match = true;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
430 // 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
431 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
432 // System.out.println(i);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
433 // 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
434 // 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
435 if (checkSequence[i] != finalSequence[i]) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
436 match = false;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
437 } else {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
438 match &= true;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
439 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
440 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
441 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
442 }
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
443 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
444 /*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
445 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
446 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
447 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
448 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
449 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
450 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
451 } while (!datas.isEmpty()) ;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
452 if (!toQuery.isEmpty()) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
453 System.out.println();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
454 totalQueries++;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
455 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
456 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
457
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
458 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
459 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
460 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
461 });
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
462 for (int[] x : toQuery) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
463 if (!queried.contains(x[0])) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
464 queried.add(x[0]);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
465 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
466 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
467 exactNumberOfElements = x[0] + 1;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
468 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
469 // 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
470 // 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
471 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
472 int trailingBits = (exactNumberOfElements + 2) & 0x1f;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
473 if (trailingBits != 0) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
474 totalInts++;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
475 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
476 checkSequence = new int[totalInts];
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
477 Arrays.fill(checkSequence, 0xffffffff);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
478 checkSequence[0] &= 0x7FFFFFFF;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
479 if (trailingBits == 0) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
480 checkSequence[totalInts-1] &= 0xFFFFFFFE;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
481 } else if (trailingBits == 1) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
482 checkSequence[totalInts-1] = 0;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
483 } else {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
484 // 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
485 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
486 checkSequence[totalInts - 1] &= mask;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
487 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
488 for (int e : checkSequence) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
489 System.out.print(toBinaryString(e, ' '));
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
490 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
491 System.out.println();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
492 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
493 datas.put(x[0], data);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
494 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
495 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
496 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
497
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
498 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
499 for (int x : finalSequence) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
500 System.out.print(toBinaryString(x, ' '));
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
501 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
502 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
503
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
504 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
505 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
506 int value = data[x];
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
507 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
508 if (value != value_check) {
b1de83ffa7f8 Build shall succeed with no precompiled classes, too
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 173
diff changeset
509 throw new IllegalStateException();
b1de83ffa7f8 Build shall succeed with no precompiled classes, too
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 173
diff changeset
510 }
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
511 int wordIx = (root + i) >>> 5;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
512 int bitIx = (root + i) & 0x1f;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
513 finalSequence[wordIx] |= 1 << (31-bitIx);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
514 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
515 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
516
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
517 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
518 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
519 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
520 sb.append(byteSeparator);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
521 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
522 sb.append(byteSeparator);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
523 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
524 sb.append(byteSeparator);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
525 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
526 sb.append(byteSeparator);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
527 return sb.toString();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
528 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
529
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
530 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
531 final String nibbles = "0000000100100011010001010110011110001001101010111100110111101111";
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
532 assert nibbles.length() == 16*4;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
533 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
534 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
535 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
536 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
537 }
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
538 }