Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgManifestCommand.java @ 231:1792b37650f2
Introduced access to conflict resolution information (merge state)
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Wed, 01 Jun 2011 05:44:25 +0200 | 
| parents | 373e07cd3991 | 
| children | 4c3b9f679412 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 230:0dd9da7489dc | 231:1792b37650f2 | 
|---|---|
| 23 import java.util.ConcurrentModificationException; | 23 import java.util.ConcurrentModificationException; | 
| 24 import java.util.LinkedHashMap; | 24 import java.util.LinkedHashMap; | 
| 25 import java.util.LinkedList; | 25 import java.util.LinkedList; | 
| 26 import java.util.List; | 26 import java.util.List; | 
| 27 | 27 | 
| 28 import org.tmatesoft.hg.core.HgLogCommand.FileRevision; | |
| 29 import org.tmatesoft.hg.repo.HgManifest; | 28 import org.tmatesoft.hg.repo.HgManifest; | 
| 30 import org.tmatesoft.hg.repo.HgRepository; | 29 import org.tmatesoft.hg.repo.HgRepository; | 
| 31 import org.tmatesoft.hg.util.Path; | 30 import org.tmatesoft.hg.util.Path; | 
| 32 import org.tmatesoft.hg.util.PathPool; | 31 import org.tmatesoft.hg.util.PathPool; | 
| 33 import org.tmatesoft.hg.util.PathRewrite; | 32 import org.tmatesoft.hg.util.PathRewrite; | 
| 122 * Callback to walk file/directory tree of a revision | 121 * Callback to walk file/directory tree of a revision | 
| 123 */ | 122 */ | 
| 124 public interface Handler { | 123 public interface Handler { | 
| 125 void begin(Nodeid manifestRevision); | 124 void begin(Nodeid manifestRevision); | 
| 126 void dir(Path p); // optionally invoked (if walker was configured to spit out directories) prior to any files from this dir and subdirs | 125 void dir(Path p); // optionally invoked (if walker was configured to spit out directories) prior to any files from this dir and subdirs | 
| 127 void file(FileRevision fileRevision); // XXX allow to check p is invalid (df.exists()) | 126 void file(HgLogCommand.FileRevision fileRevision); // XXX allow to check p is invalid (df.exists()) | 
| 128 void end(Nodeid manifestRevision); | 127 void end(Nodeid manifestRevision); | 
| 129 } | 128 } | 
| 130 | 129 | 
| 131 // I'd rather let HgManifestCommand implement HgManifest.Inspector directly, but this pollutes API alot | 130 // I'd rather let HgManifestCommand implement HgManifest.Inspector directly, but this pollutes API alot | 
| 132 private class Mediator implements HgManifest.Inspector { | 131 private class Mediator implements HgManifest.Inspector { | 
| 133 // file names are likely to repeat in each revision, hence caching of Paths. | 132 // file names are likely to repeat in each revision, hence caching of Paths. | 
| 134 // However, once HgManifest.Inspector switches to Path objects, perhaps global Path pool | 133 // However, once HgManifest.Inspector switches to Path objects, perhaps global Path pool | 
| 135 // might be more effective? | 134 // might be more effective? | 
| 136 private PathPool pathPool; | 135 private PathPool pathPool; | 
| 137 private List<FileRevision> manifestContent; | 136 private List<HgFileRevision> manifestContent; | 
| 138 private Nodeid manifestNodeid; | 137 private Nodeid manifestNodeid; | 
| 139 | 138 | 
| 140 public void start() { | 139 public void start() { | 
| 141 // Manifest keeps normalized paths | 140 // Manifest keeps normalized paths | 
| 142 pathPool = new PathPool(new PathRewrite.Empty()); | 141 pathPool = new PathPool(new PathRewrite.Empty()); | 
| 147 pathPool = null; | 146 pathPool = null; | 
| 148 } | 147 } | 
| 149 | 148 | 
| 150 public boolean begin(int manifestRevision, Nodeid nid, int changelogRevision) { | 149 public boolean begin(int manifestRevision, Nodeid nid, int changelogRevision) { | 
| 151 if (needDirs && manifestContent == null) { | 150 if (needDirs && manifestContent == null) { | 
| 152 manifestContent = new LinkedList<FileRevision>(); | 151 manifestContent = new LinkedList<HgFileRevision>(); | 
| 153 } | 152 } | 
| 154 visitor.begin(manifestNodeid = nid); | 153 visitor.begin(manifestNodeid = nid); | 
| 155 return true; | 154 return true; | 
| 156 } | 155 } | 
| 157 public boolean end(int revision) { | 156 public boolean end(int revision) { | 
| 158 if (needDirs) { | 157 if (needDirs) { | 
| 159 LinkedHashMap<Path, LinkedList<FileRevision>> breakDown = new LinkedHashMap<Path, LinkedList<FileRevision>>(); | 158 LinkedHashMap<Path, LinkedList<HgFileRevision>> breakDown = new LinkedHashMap<Path, LinkedList<HgFileRevision>>(); | 
| 160 for (FileRevision fr : manifestContent) { | 159 for (HgFileRevision fr : manifestContent) { | 
| 161 Path filePath = fr.getPath(); | 160 Path filePath = fr.getPath(); | 
| 162 Path dirPath = pathPool.parent(filePath); | 161 Path dirPath = pathPool.parent(filePath); | 
| 163 LinkedList<FileRevision> revs = breakDown.get(dirPath); | 162 LinkedList<HgFileRevision> revs = breakDown.get(dirPath); | 
| 164 if (revs == null) { | 163 if (revs == null) { | 
| 165 revs = new LinkedList<FileRevision>(); | 164 revs = new LinkedList<HgFileRevision>(); | 
| 166 breakDown.put(dirPath, revs); | 165 breakDown.put(dirPath, revs); | 
| 167 } | 166 } | 
| 168 revs.addLast(fr); | 167 revs.addLast(fr); | 
| 169 } | 168 } | 
| 170 for (Path dir : breakDown.keySet()) { | 169 for (Path dir : breakDown.keySet()) { | 
| 171 visitor.dir(dir); | 170 visitor.dir(dir); | 
| 172 for (FileRevision fr : breakDown.get(dir)) { | 171 for (HgFileRevision fr : breakDown.get(dir)) { | 
| 173 visitor.file(fr); | 172 visitor.file(fr); | 
| 174 } | 173 } | 
| 175 } | 174 } | 
| 176 manifestContent.clear(); | 175 manifestContent.clear(); | 
| 177 } | 176 } | 
| 182 public boolean next(Nodeid nid, String fname, String flags) { | 181 public boolean next(Nodeid nid, String fname, String flags) { | 
| 183 Path p = pathPool.path(fname); | 182 Path p = pathPool.path(fname); | 
| 184 if (matcher != null && !matcher.accept(p)) { | 183 if (matcher != null && !matcher.accept(p)) { | 
| 185 return true; | 184 return true; | 
| 186 } | 185 } | 
| 187 FileRevision fr = new FileRevision(repo, nid, p); | 186 HgFileRevision fr = new HgFileRevision(repo, nid, p); | 
| 188 if (needDirs) { | 187 if (needDirs) { | 
| 189 manifestContent.add(fr); | 188 manifestContent.add(fr); | 
| 190 } else { | 189 } else { | 
| 191 visitor.file(fr); | 190 visitor.file(fr); | 
| 192 } | 191 } | 
