annotate src/com/tmate/hgkit/ll/StatusCollector.java @ 64:19e9e220bf68

Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 21 Jan 2011 05:56:43 +0100
parents b771e94a4f7c
children 0e499fed9b3d
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>();
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
27 ManifestRevisionInspector emptyFakeState = new ManifestRevisionInspector(-1, -1);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
28 emptyFakeState.begin(-1, null);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
29 emptyFakeState.end(-1);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
30 cache.put(-1, emptyFakeState);
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
33 public HgRepository getRepo() {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
34 return repo;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
35 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
36
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 private ManifestRevisionInspector get(int rev) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 ManifestRevisionInspector i = cache.get(rev);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 if (i == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 i = new ManifestRevisionInspector(rev, rev);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 cache.put(rev, i);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 repo.getManifest().walk(rev, rev, i);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 return i;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 }
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
46
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
47 /*package-local*/ ManifestRevisionInspector raw(int rev) {
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
48 return get(rev);
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
49 }
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 56
diff changeset
50
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
51 // hg status --change <rev>
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
52 public void change(int rev, Inspector inspector) {
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
53 int[] parents = new int[2];
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
54 repo.getChangelog().parents(rev, parents, null, null);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
55 walk(parents[0], rev, inspector);
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
56 }
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
58 // I assume revision numbers are the same for changelog and manifest - here
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
59 // user would like to pass changelog revision numbers, and I use them directly to walk manifest.
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
60 // if this assumption is wrong, fix this (lookup manifest revisions from changeset).
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 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
62 if (rev1 == rev2) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
65 if (inspector == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
66 throw new IllegalArgumentException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
67 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
68 if (inspector instanceof Record) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
69 ((Record) inspector).init(rev1, rev2, this);
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
70 }
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 // 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
72 // 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
73 ManifestRevisionInspector r1, r2;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 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
75 int minRev = rev1 < rev2 ? rev1 : rev2;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 int maxRev = minRev == rev1 ? rev2 : rev1;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 r1 = r2 = new ManifestRevisionInspector(minRev, maxRev);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 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
79 cache.put(i, r1);
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 repo.getManifest().walk(minRev, maxRev, r1);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 } else {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 r1 = get(rev1);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 r2 = get(rev2);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 }
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 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
88 for (String fname : r2.files(rev2)) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 if (r1Files.remove(fname)) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 Nodeid nidR1 = r1.nodeid(rev1, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 Nodeid nidR2 = r2.nodeid(rev2, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 String flagsR1 = r1.flags(rev1, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 String flagsR2 = r2.flags(rev2, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 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
95 inspector.clean(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 } else {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 inspector.modified(fname);
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 } else {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 inspector.added(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 for (String left : r1Files) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 inspector.removed(left);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 // 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
107 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 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
110 Record rv = new Record();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 walk(rev1, rev2, rv);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 return rv;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
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 public interface Inspector {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 void modified(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 void added(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 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
119 void removed(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 void clean(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 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
122 void unknown(String fname); // not tracked
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 void ignored(String fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 }
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 // 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
127 public static class Record implements Inspector {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 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
129 private Map<String, String> copied;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
131 private int startRev, endRev;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
132 private StatusCollector statusHelper;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
133
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
134 // XXX StatusCollector may additionally initialize Record instance to speed lookup of changed file revisions
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
135 // here I need access to ManifestRevisionInspector via #raw(). Perhaps, non-static class (to get
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
136 // implicit reference to StatusCollector) may be better?
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
137 // Since users may want to reuse Record instance we've once created (and initialized), we need to
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
138 // ensure functionality is correct for each/any call (#walk checks instanceof Record and fixes it up)
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
139 // Perhaps, distinct helper (sc.getRevisionHelper().nodeid(fname)) would be better, just not clear
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
140 // how to supply [start..end] values there easily
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
141 /*package-local*/void init(int startRevision, int endRevision, StatusCollector self) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
142 startRev = startRevision;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
143 endRev = endRevision;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
144 statusHelper = self;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
145 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
146
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
147 public Nodeid nodeidBeforeChange(String fname) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
148 if ((modified == null || !modified.contains(fname)) && (removed == null || !removed.contains(fname))) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
149 return null;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
150 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
151 return statusHelper.raw(startRev).nodeid(startRev, fname);
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
152 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
153 public Nodeid nodeidAfterChange(String fname) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
154 if ((modified == null || !modified.contains(fname)) && (added == null || !added.contains(fname))) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
155 return null;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
156 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
157 return statusHelper.raw(endRev).nodeid(endRev, fname);
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
158 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
159
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 public List<String> getModified() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 return proper(modified);
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 List<String> getAdded() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 return proper(added);
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 List<String> getRemoved() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 return proper(removed);
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 Map<String,String> getCopied() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 if (copied == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 return Collections.emptyMap();
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 return Collections.unmodifiableMap(copied);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 }
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 public List<String> getClean() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 return proper(clean);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 }
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 public List<String> getMissing() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 return proper(missing);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 public List<String> getUnknown() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 return proper(unknown);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 }
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 public List<String> getIgnored() {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 return proper(ignored);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 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
196 if (l == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 return Collections.emptyList();
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 return Collections.unmodifiableList(l);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 //
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
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 public void modified(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 modified = doAdd(modified, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 public void added(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210 added = doAdd(added, fname);
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
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 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
214 if (copied == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 copied = new LinkedHashMap<String, String>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 copied.put(fnameOrigin, fnameAdded);
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
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 public void removed(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 removed = doAdd(removed, fname);
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
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 public void clean(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 clean = doAdd(clean, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 public void missing(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229 missing = doAdd(missing, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 }
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 public void unknown(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233 unknown = doAdd(unknown, fname);
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
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
236 public void ignored(String fname) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
237 ignored = doAdd(ignored, fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238 }
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 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
241 if (l == null) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 l = new LinkedList<String>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 l.add(s);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 return l;
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 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
248
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
249 // XXX in fact, indexed access brings more trouble than benefits, get rid of it? Distinct instance per revision is good enough
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
250 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
251 private final HashMap<String, Nodeid>[] idsMap;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 private final HashMap<String, String>[] flagsMap;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
253 private final int baseRevision;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
254 private int r = -1; // cursor
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 * [minRev, maxRev]
56
576d6e8a09f6 Analog of 'hg status --change' command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
258 * [-1,-1] also accepted (for fake empty instance)
55
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
259 * @param minRev - inclusive
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
260 * @param maxRev - inclusive
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
261 */
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
262 @SuppressWarnings("unchecked")
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
263 public ManifestRevisionInspector(int minRev, int maxRev) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
264 baseRevision = minRev;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
265 int range = maxRev - minRev + 1;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
266 idsMap = new HashMap[range];
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
267 flagsMap = new HashMap[range];
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
268 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
269
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
270 public Collection<String> files(int rev) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
271 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
272 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
273 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
274 return idsMap[rev - baseRevision].keySet();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
275 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
276
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
277 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
278 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
279 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
280 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
281 return idsMap[rev - baseRevision].get(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
282 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
283
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
284 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
285 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
286 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
287 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
288 return flagsMap[rev - baseRevision].get(fname);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
289 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
290
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
291 //
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
292
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
293 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
294 idsMap[r].put(fname, nid);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
295 flagsMap[r].put(fname, flags);
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
296 return true;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
297 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
298
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
299 public boolean end(int revision) {
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
300 assert revision == r + baseRevision;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
301 r = -1;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
302 return revision+1 < baseRevision + idsMap.length;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
303 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
304
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
305 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
306 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
307 throw new IllegalArgumentException();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
308 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
309 r = revision - baseRevision;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
310 idsMap[r] = new HashMap<String, Nodeid>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
311 flagsMap[r] = new HashMap<String, String>();
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
312 return true;
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
313 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
314 }
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
315
05829a70b30b Status operation extracted into separate, cache-friendly class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
316 }