Mercurial > jhg
comparison src/com/tmate/hgkit/ll/StatusCollector.java @ 68:0e499fed9b3d
StatusCommand with tests. Extra constants to indicate common revision cases
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 22 Jan 2011 22:11:24 +0100 |
parents | 19e9e220bf68 |
children |
comparison
equal
deleted
inserted
replaced
67:64bddc2dcc0e | 68:0e499fed9b3d |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 Artem Tikhomirov | 2 * Copyright (c) 2011 Artem Tikhomirov |
3 */ | 3 */ |
4 package com.tmate.hgkit.ll; | 4 package com.tmate.hgkit.ll; |
5 | |
6 import static com.tmate.hgkit.ll.HgRepository.BAD_REVISION; | |
7 import static com.tmate.hgkit.ll.HgRepository.TIP; | |
5 | 8 |
6 import java.util.Collection; | 9 import java.util.Collection; |
7 import java.util.Collections; | 10 import java.util.Collections; |
8 import java.util.HashMap; | 11 import java.util.HashMap; |
9 import java.util.LinkedHashMap; | 12 import java.util.LinkedHashMap; |
24 public StatusCollector(HgRepository hgRepo) { | 27 public StatusCollector(HgRepository hgRepo) { |
25 this.repo = hgRepo; | 28 this.repo = hgRepo; |
26 cache = new HashMap<Integer, ManifestRevisionInspector>(); | 29 cache = new HashMap<Integer, ManifestRevisionInspector>(); |
27 ManifestRevisionInspector emptyFakeState = new ManifestRevisionInspector(-1, -1); | 30 ManifestRevisionInspector emptyFakeState = new ManifestRevisionInspector(-1, -1); |
28 emptyFakeState.begin(-1, null); | 31 emptyFakeState.begin(-1, null); |
29 emptyFakeState.end(-1); | 32 emptyFakeState.end(-1); // FIXME HgRepo.TIP == -1 as well, need to distinguish fake "prior to first" revision from "the very last" |
30 cache.put(-1, emptyFakeState); | 33 cache.put(-1, emptyFakeState); |
31 } | 34 } |
32 | 35 |
33 public HgRepository getRepo() { | 36 public HgRepository getRepo() { |
34 return repo; | 37 return repo; |
65 if (inspector == null) { | 68 if (inspector == null) { |
66 throw new IllegalArgumentException(); | 69 throw new IllegalArgumentException(); |
67 } | 70 } |
68 if (inspector instanceof Record) { | 71 if (inspector instanceof Record) { |
69 ((Record) inspector).init(rev1, rev2, this); | 72 ((Record) inspector).init(rev1, rev2, this); |
73 } | |
74 if (rev1 == TIP) { | |
75 rev1 = repo.getManifest().getRevisionCount() - 1; | |
76 } | |
77 if (rev2 == TIP) { | |
78 rev2 = repo.getManifest().getRevisionCount() - 1; // XXX add Revlog.tip() func ? | |
70 } | 79 } |
71 // in fact, rev1 and rev2 are often next (or close) to each other, | 80 // in fact, rev1 and rev2 are often next (or close) to each other, |
72 // thus, we can optimize Manifest reads here (manifest.walk(rev1, rev2)) | 81 // thus, we can optimize Manifest reads here (manifest.walk(rev1, rev2)) |
73 ManifestRevisionInspector r1, r2; | 82 ManifestRevisionInspector r1, r2; |
74 if (!cache.containsKey(rev1) && !cache.containsKey(rev2) && Math.abs(rev1 - rev2) < 5 /*subjective equivalent of 'close enough'*/) { | 83 if (!cache.containsKey(rev1) && !cache.containsKey(rev2) && Math.abs(rev1 - rev2) < 5 /*subjective equivalent of 'close enough'*/) { |
143 endRev = endRevision; | 152 endRev = endRevision; |
144 statusHelper = self; | 153 statusHelper = self; |
145 } | 154 } |
146 | 155 |
147 public Nodeid nodeidBeforeChange(String fname) { | 156 public Nodeid nodeidBeforeChange(String fname) { |
157 if (statusHelper == null || startRev == BAD_REVISION) { | |
158 return null; | |
159 } | |
148 if ((modified == null || !modified.contains(fname)) && (removed == null || !removed.contains(fname))) { | 160 if ((modified == null || !modified.contains(fname)) && (removed == null || !removed.contains(fname))) { |
149 return null; | 161 return null; |
150 } | 162 } |
151 return statusHelper.raw(startRev).nodeid(startRev, fname); | 163 return statusHelper.raw(startRev).nodeid(startRev, fname); |
152 } | 164 } |
153 public Nodeid nodeidAfterChange(String fname) { | 165 public Nodeid nodeidAfterChange(String fname) { |
166 if (statusHelper == null || endRev == BAD_REVISION) { | |
167 return null; | |
168 } | |
154 if ((modified == null || !modified.contains(fname)) && (added == null || !added.contains(fname))) { | 169 if ((modified == null || !modified.contains(fname)) && (added == null || !added.contains(fname))) { |
155 return null; | 170 return null; |
156 } | 171 } |
157 return statusHelper.raw(endRev).nodeid(endRev, fname); | 172 return statusHelper.raw(endRev).nodeid(endRev, fname); |
158 } | 173 } |