Mercurial > hg4j
comparison src/com/tmate/hgkit/ll/LocalHgRepo.java @ 21:e929cecae4e1
Refactor to move revlog content to base class
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 05 Jan 2011 04:10:28 +0100 |
parents | 11cfabe692b3 |
children | 603806cd2dc6 |
comparison
equal
deleted
inserted
replaced
20:11cfabe692b3 | 21:e929cecae4e1 |
---|---|
45 return repoLocation; | 45 return repoLocation; |
46 } | 46 } |
47 | 47 |
48 @Override | 48 @Override |
49 public void status(int rev1, int rev2, final StatusInspector inspector) { | 49 public void status(int rev1, int rev2, final StatusInspector inspector) { |
50 final HashMap<String, Nodeid> idsMap = new HashMap<String, Nodeid>(); | 50 final ManifestRevisionCollector collect = new ManifestRevisionCollector(); |
51 final HashMap<String, String> flagsMap = new HashMap<String, String>(); | |
52 HgManifest.Inspector collect = new HgManifest.Inspector() { | |
53 | |
54 | |
55 public boolean next(Nodeid nid, String fname, String flags) { | |
56 idsMap.put(fname, nid); | |
57 flagsMap.put(fname, flags); | |
58 return true; | |
59 } | |
60 | |
61 public boolean end(int revision) { | |
62 return false; | |
63 } | |
64 | |
65 public boolean begin(int revision, Nodeid nid) { | |
66 return true; | |
67 } | |
68 }; | |
69 getManifest().walk(rev1, rev1, collect); | 51 getManifest().walk(rev1, rev1, collect); |
70 | 52 |
71 HgManifest.Inspector compare = new HgManifest.Inspector() { | 53 HgManifest.Inspector compare = new HgManifest.Inspector() { |
72 | 54 |
73 public boolean begin(int revision, Nodeid nid) { | 55 public boolean begin(int revision, Nodeid nid) { |
74 return true; | 56 return true; |
75 } | 57 } |
76 | 58 |
77 public boolean next(Nodeid nid, String fname, String flags) { | 59 public boolean next(Nodeid nid, String fname, String flags) { |
78 Nodeid nidR1 = idsMap.remove(fname); | 60 Nodeid nidR1 = collect.idsMap.remove(fname); |
79 String flagsR1 = flagsMap.remove(fname); | 61 String flagsR1 = collect.flagsMap.remove(fname); |
80 if (nidR1 == null) { | 62 if (nidR1 == null) { |
81 inspector.added(fname); | 63 inspector.added(fname); |
82 } else { | 64 } else { |
83 if (nidR1.compareTo(nid) == 0 && ((flags == null && flagsR1 == null) || flags.equals(flagsR1))) { | 65 if (nidR1.compareTo(nid) == 0 && ((flags == null && flagsR1 == null) || flags.equals(flagsR1))) { |
84 inspector.clean(fname); | 66 inspector.clean(fname); |
88 } | 70 } |
89 return true; | 71 return true; |
90 } | 72 } |
91 | 73 |
92 public boolean end(int revision) { | 74 public boolean end(int revision) { |
93 for (String fname : idsMap.keySet()) { | 75 for (String fname : collect.idsMap.keySet()) { |
94 inspector.removed(fname); | 76 inspector.removed(fname); |
95 } | 77 } |
96 if (idsMap.size() != flagsMap.size()) { | 78 if (collect.idsMap.size() != collect.flagsMap.size()) { |
97 throw new IllegalStateException(); | 79 throw new IllegalStateException(); |
98 } | 80 } |
99 return false; | 81 return false; |
100 } | 82 } |
101 }; | 83 }; |
102 getManifest().walk(rev2, rev2, compare); | 84 getManifest().walk(rev2, rev2, compare); |
103 } | 85 } |
104 | 86 |
105 public void statusLocal(int rev1, StatusInspector inspector) { | 87 public void statusLocal(int baseRevision, StatusInspector inspector) { |
106 LinkedList<File> folders = new LinkedList<File>(); | 88 LinkedList<File> folders = new LinkedList<File>(); |
107 final File rootDir = repoDir.getParentFile(); | 89 final File rootDir = repoDir.getParentFile(); |
108 folders.add(rootDir); | 90 folders.add(rootDir); |
109 final HgDirstate dirstate = loadDirstate(); | 91 final HgDirstate dirstate = loadDirstate(); |
110 final HgIgnore hgignore = loadIgnore(); | 92 final HgIgnore hgignore = loadIgnore(); |
111 TreeSet<String> knownEntries = dirstate.all(); | 93 TreeSet<String> knownEntries = dirstate.all(); |
94 final boolean isTipBase = baseRevision == TIP || baseRevision == getManifest().revisionCount(); | |
95 final ManifestRevisionCollector collect = isTipBase ? null : new ManifestRevisionCollector(); | |
96 if (!isTipBase) { | |
97 getManifest().walk(baseRevision, baseRevision, collect); | |
98 } | |
112 do { | 99 do { |
113 File d = folders.removeFirst(); | 100 File d = folders.removeFirst(); |
114 for (File f : d.listFiles()) { | 101 for (File f : d.listFiles()) { |
115 if (f.isDirectory()) { | 102 if (f.isDirectory()) { |
116 if (!".hg".equals(f.getName())) { | 103 if (!".hg".equals(f.getName())) { |
334 if (path.startsWith("/")) { | 321 if (path.startsWith("/")) { |
335 path = path.substring(1); | 322 path = path.substring(1); |
336 } | 323 } |
337 return path; | 324 return path; |
338 } | 325 } |
326 | |
327 private final class ManifestRevisionCollector implements HgManifest.Inspector { | |
328 final HashMap<String, Nodeid> idsMap = new HashMap<String, Nodeid>(); | |
329 final HashMap<String, String> flagsMap = new HashMap<String, String>(); | |
330 | |
331 public boolean next(Nodeid nid, String fname, String flags) { | |
332 idsMap.put(fname, nid); | |
333 flagsMap.put(fname, flags); | |
334 return true; | |
335 } | |
336 | |
337 public boolean end(int revision) { | |
338 return false; | |
339 } | |
340 | |
341 public boolean begin(int revision, Nodeid nid) { | |
342 return true; | |
343 } | |
344 } | |
339 } | 345 } |