annotate src/com/tmate/hgkit/ll/StatusCollector.java @ 55:05829a70b30b

Status operation extracted into separate, cache-friendly class
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 17 Jan 2011 04:45:09 +0100
parents
children 576d6e8a09f6
rev   line source
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 Artem Tikhomirov
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 */
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 package com.tmate.hgkit.ll;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 import java.util.Collection;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 import java.util.Collections;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 import java.util.HashMap;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 import java.util.LinkedHashMap;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 import java.util.LinkedList;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 import java.util.List;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 import java.util.Map;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 import java.util.TreeSet;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 /**
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 * RevisionWalker?
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 * @author artem
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18 */
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 public class StatusCollector {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 private final HgRepository repo;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 private final Map<Integer, ManifestRevisionInspector> cache; // sparse array, in fact
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 public StatusCollector(HgRepository hgRepo) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 this.repo = hgRepo;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 cache = new HashMap<Integer, ManifestRevisionInspector>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 private ManifestRevisionInspector get(int rev) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 ManifestRevisionInspector i = cache.get(rev);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 if (i == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 i = new ManifestRevisionInspector(rev, rev);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 cache.put(rev, i);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 repo.getManifest().walk(rev, rev, i);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 return i;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 public void walk(int rev1, int rev2, Inspector inspector) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 if (rev1 == rev2) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 // in fact, rev1 and rev2 are often next (or close) to each other,
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 // thus, we can optimize Manifest reads here (manifest.walk(rev1, rev2))
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 ManifestRevisionInspector r1, r2;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 if (!cache.containsKey(rev1) && !cache.containsKey(rev2) && Math.abs(rev1 - rev2) < 5 /*subjective equivalent of 'close enough'*/) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 int minRev = rev1 < rev2 ? rev1 : rev2;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 int maxRev = minRev == rev1 ? rev2 : rev1;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 r1 = r2 = new ManifestRevisionInspector(minRev, maxRev);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 for (int i = minRev; i <= maxRev; i++) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 cache.put(i, r1);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 repo.getManifest().walk(minRev, maxRev, r1);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 } else {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 r1 = get(rev1);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 r2 = get(rev2);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 TreeSet<String> r1Files = new TreeSet<String>(r1.files(rev1));
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 for (String fname : r2.files(rev2)) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 if (r1Files.remove(fname)) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 Nodeid nidR1 = r1.nodeid(rev1, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 Nodeid nidR2 = r2.nodeid(rev2, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 String flagsR1 = r1.flags(rev1, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 String flagsR2 = r2.flags(rev2, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 if (nidR1.equals(nidR2) && ((flagsR2 == null && flagsR1 == null) || flagsR2.equals(flagsR1))) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 inspector.clean(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 } else {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 inspector.modified(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 } else {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 inspector.added(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 for (String left : r1Files) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 inspector.removed(left);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 // inspector.done() if useful e.g. in UI client
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 public Record status(int rev1, int rev2) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 Record rv = new Record();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 walk(rev1, rev2, rv);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 return rv;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 public interface Inspector {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 void modified(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 void added(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 void copied(String fnameOrigin, String fnameAdded); // if copied files of no interest, should delegate to self.added(fnameAdded);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 void removed(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 void clean(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 void missing(String fname); // aka deleted (tracked by Hg, but not available in FS any more
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 void unknown(String fname); // not tracked
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 void ignored(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 // XXX for r1..r2 status, only modified, added, removed (and perhaps, clean) make sense
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 public static class Record implements Inspector {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 private List<String> modified, added, removed, clean, missing, unknown, ignored;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 private Map<String, String> copied;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 public List<String> getModified() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 return proper(modified);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 public List<String> getAdded() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 return proper(added);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 public List<String> getRemoved() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 return proper(removed);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 public Map<String,String> getCopied() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 if (copied == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 return Collections.emptyMap();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 return Collections.unmodifiableMap(copied);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 public List<String> getClean() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 return proper(clean);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 public List<String> getMissing() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 return proper(missing);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 public List<String> getUnknown() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 return proper(unknown);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 public List<String> getIgnored() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 return proper(ignored);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 private List<String> proper(List<String> l) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 if (l == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 return Collections.emptyList();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 return Collections.unmodifiableList(l);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 //
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 //
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 public void modified(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 modified = doAdd(modified, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 public void added(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 added = doAdd(added, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 public void copied(String fnameOrigin, String fnameAdded) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 if (copied == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 copied = new LinkedHashMap<String, String>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 copied.put(fnameOrigin, fnameAdded);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 public void removed(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 removed = doAdd(removed, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 public void clean(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 clean = doAdd(clean, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 public void missing(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 missing = doAdd(missing, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 public void unknown(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 unknown = doAdd(unknown, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 public void ignored(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 ignored = doAdd(ignored, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 private static List<String> doAdd(List<String> l, String s) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 if (l == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 l = new LinkedList<String>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 l.add(s);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 return l;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 public /*XXX private, actually. Made public unless repo.statusLocal finds better place*/ static final class ManifestRevisionInspector implements HgManifest.Inspector {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 private final HashMap<String, Nodeid>[] idsMap;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 private final HashMap<String, String>[] flagsMap;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 private final int baseRevision;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 private int r = -1; // cursor
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 /**
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 * [minRev, maxRev]
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 * @param minRev - inclusive
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 * @param maxRev - inclusive
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 */
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 @SuppressWarnings("unchecked")
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 public ManifestRevisionInspector(int minRev, int maxRev) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 baseRevision = minRev;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 int range = maxRev - minRev + 1;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 idsMap = new HashMap[range];
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 flagsMap = new HashMap[range];
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 public Collection<String> files(int rev) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 if (rev < baseRevision || rev >= baseRevision + idsMap.length) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 return idsMap[rev - baseRevision].keySet();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 public Nodeid nodeid(int rev, String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 if (rev < baseRevision || rev >= baseRevision + idsMap.length) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
222 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 return idsMap[rev - baseRevision].get(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 public String flags(int rev, String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227 if (rev < baseRevision || rev >= baseRevision + idsMap.length) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 return flagsMap[rev - baseRevision].get(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
232
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233 //
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
235 public boolean next(Nodeid nid, String fname, String flags) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
236 idsMap[r].put(fname, nid);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
237 flagsMap[r].put(fname, flags);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238 return true;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 public boolean end(int revision) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 assert revision == r + baseRevision;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 r = -1;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 return revision+1 < baseRevision + idsMap.length;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
246
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
247 public boolean begin(int revision, Nodeid nid) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
248 if (revision < baseRevision || revision >= baseRevision + idsMap.length) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
249 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
250 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
251 r = revision - baseRevision;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 idsMap[r] = new HashMap<String, Nodeid>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
253 flagsMap[r] = new HashMap<String, String>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
254 return true;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
255 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
256 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
257
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
258 }