annotate cmdline/org/tmatesoft/hg/console/Incoming.java @ 425:48f993aa2f41

FIXMEs: exceptions, javadoc
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 28 Mar 2012 18:39:29 +0200
parents 45dc79e545f5
children
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
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
19 import java.util.Arrays;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
20 import java.util.Collections;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
21 import java.util.Comparator;
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.HashSet;
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
23 import java.util.Iterator;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
24 import java.util.LinkedHashMap;
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.LinkedList;
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.util.List;
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
27 import java.util.Map.Entry;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
28
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
29 import org.tmatesoft.hg.core.HgIncomingCommand;
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
30 import org.tmatesoft.hg.core.HgRepoFacade;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
31 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
32 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
33 import org.tmatesoft.hg.repo.HgRemoteRepository;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
34
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 /**
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
37 * <em>hg incoming</em> counterpart
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
38 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
39 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 33
diff changeset
40 * @author TMate Software Ltd.
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 */
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 public class Incoming {
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 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
45 if (Boolean.FALSE.booleanValue()) {
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
46 new SequenceConstructor().test();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
47 return;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
48 }
299
45dc79e545f5 Recognize flag options (options with no arguments) in command line sample apps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
49 Options cmdLineOpts = Options.parse(args, Collections.<String>emptySet());
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
50 HgRepoFacade hgRepo = new HgRepoFacade();
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
51 if (!hgRepo.init(cmdLineOpts.findRepository())) {
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
52 System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation());
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 return;
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 }
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
55 HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo.getRepository());
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
56 if (hgRemote.isInvalid()) {
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
57 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation());
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
58 return;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 174
diff changeset
59 }
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
60 HgIncomingCommand cmd = hgRepo.createIncomingCommand();
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
61 cmd.against(hgRemote);
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 //
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 208
diff changeset
63 List<Nodeid> missing = cmd.executeLite();
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
64 Collections.reverse(missing); // useful to test output, from newer to older
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
65 Outgoing.dump("Nodes to fetch:", missing);
208
ef8eba4aa215 Correct index of revisions to be added into a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 206
diff changeset
66 System.out.printf("Total: %d\n\n", missing.size());
184
ec1820f64d2b Complete incoming cmdline client, with both lite (revisions) and complete (full changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 182
diff changeset
67 //
ec1820f64d2b Complete incoming cmdline client, with both lite (revisions) and complete (full changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 182
diff changeset
68 // Complete
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
69 final ChangesetDumpHandler h = new ChangesetDumpHandler(hgRepo.getRepository());
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
70 h.complete(false); // this option looks up index of parent revision, done via repo.changelog (which doesn't have any of these new revisions)
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
71 // this can be fixed by tracking all nodeid->revision idx inside ChangesetDumpHandler, and refer to repo.changelog only when that mapping didn't work
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
72 h.verbose(cmdLineOpts.getBoolean("-v", "--verbose"));
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
73 cmd.executeFull(h);
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
74 }
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
75
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
77 /*
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
78 * This is for investigation purposes only
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 192
diff changeset
79 */
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
80 private static class SequenceConstructor {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
81
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
82 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
83 if (head <= (root+1)) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
84 return new int[0];
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
85 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
86 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
87 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
88 int[] rv = new int[size];
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
89 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
90 rv[i] = root + v;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
91 v = v << 1;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
92 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
93 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
94 return rv;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
95 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
96
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
97 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
98 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
99 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
100 // 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
101 // 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
102 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
103 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
104 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
105 datas.put(root, data);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
106 int totalQueries = 1;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
107 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
108 int[] checkSequence = null;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
109 while(!datas.isEmpty()) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
110 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
111 do {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
112 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
113 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
114 int r = next.getKey();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
115 data = next.getValue();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
116 it.remove();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
117 populate(r, head, data, finalSequence);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
118 if (checkSequence != null) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
119 boolean match = true;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
120 // 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
121 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
122 // System.out.println(i);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
123 // 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
124 // 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
125 if (checkSequence[i] != finalSequence[i]) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
126 match = false;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
127 } else {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
128 match &= true;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
129 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
130 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
131 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
132 }
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
133 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
134 /*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
135 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
136 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
137 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
138 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
139 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
140 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
141 } while (!datas.isEmpty()) ;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
142 if (!toQuery.isEmpty()) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
143 System.out.println();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
144 totalQueries++;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
145 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
146 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
147
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
148 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
149 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
150 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
151 });
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
152 for (int[] x : toQuery) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
153 if (!queried.contains(x[0])) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
154 queried.add(x[0]);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
155 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
156 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
157 exactNumberOfElements = x[0] + 1;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
158 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
159 // 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
160 // 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
161 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
162 int trailingBits = (exactNumberOfElements + 2) & 0x1f;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
163 if (trailingBits != 0) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
164 totalInts++;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
165 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
166 checkSequence = new int[totalInts];
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
167 Arrays.fill(checkSequence, 0xffffffff);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
168 checkSequence[0] &= 0x7FFFFFFF;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
169 if (trailingBits == 0) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
170 checkSequence[totalInts-1] &= 0xFFFFFFFE;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
171 } else if (trailingBits == 1) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
172 checkSequence[totalInts-1] = 0;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
173 } else {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
174 // 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
175 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
176 checkSequence[totalInts - 1] &= mask;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
177 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
178 for (int e : checkSequence) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
179 System.out.print(toBinaryString(e, ' '));
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
180 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
181 System.out.println();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
182 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
183 datas.put(x[0], data);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
184 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
185 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
186 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
187
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
188 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
189 for (int x : finalSequence) {
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
190 System.out.print(toBinaryString(x, ' '));
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
191 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
192 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
193
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
194 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
195 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
196 int value = data[x];
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
197 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
198 if (value != value_check) {
b1de83ffa7f8 Build shall succeed with no precompiled classes, too
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 173
diff changeset
199 throw new IllegalStateException();
b1de83ffa7f8 Build shall succeed with no precompiled classes, too
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 173
diff changeset
200 }
173
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
201 int wordIx = (root + i) >>> 5;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
202 int bitIx = (root + i) & 0x1f;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
203 finalSequence[wordIx] |= 1 << (31-bitIx);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
204 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
205 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
206
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
207 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
208 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
209 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
210 sb.append(byteSeparator);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
211 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
212 sb.append(byteSeparator);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
213 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
214 sb.append(byteSeparator);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
215 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
216 sb.append(byteSeparator);
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
217 return sb.toString();
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
218 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
219
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
220 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
221 final String nibbles = "0000000100100011010001010110011110001001101010111100110111101111";
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
222 assert nibbles.length() == 16*4;
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
223 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
224 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
225 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
226 }
4bf061a7c001 Test algorithm to build sequence of missing revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
227 }
31
346b66add79d Basic lookup for incoming changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 }