Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/ext/MqManager.java @ 493:ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Thu, 18 Oct 2012 18:36:13 +0200 | 
| parents | b3c16d1aede0 | 
| children | d2f6ab541330 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 492:e4eaa23e3442 | 493:ba36f66c32b4 | 
|---|---|
| 26 import java.util.LinkedList; | 26 import java.util.LinkedList; | 
| 27 import java.util.List; | 27 import java.util.List; | 
| 28 import java.util.Map; | 28 import java.util.Map; | 
| 29 | 29 | 
| 30 import org.tmatesoft.hg.core.Nodeid; | 30 import org.tmatesoft.hg.core.Nodeid; | 
| 31 import org.tmatesoft.hg.internal.Internals; | |
| 31 import org.tmatesoft.hg.internal.LineReader; | 32 import org.tmatesoft.hg.internal.LineReader; | 
| 32 import org.tmatesoft.hg.repo.HgInternals; | 33 import org.tmatesoft.hg.repo.HgInternals; | 
| 33 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | 34 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | 
| 34 import org.tmatesoft.hg.repo.HgInvalidFileException; | 35 import org.tmatesoft.hg.repo.HgInvalidFileException; | 
| 35 import org.tmatesoft.hg.repo.HgRepository; | 36 import org.tmatesoft.hg.repo.HgRepository; | 
| 61 * Updates manager with up-to-date state of the mercurial queues. | 62 * Updates manager with up-to-date state of the mercurial queues. | 
| 62 */ | 63 */ | 
| 63 public void refresh() throws HgInvalidControlFileException { | 64 public void refresh() throws HgInvalidControlFileException { | 
| 64 applied = allKnown = Collections.emptyList(); | 65 applied = allKnown = Collections.emptyList(); | 
| 65 queueNames = Collections.emptyList(); | 66 queueNames = Collections.emptyList(); | 
| 66 File repoDir = HgInternals.getRepositoryDir(repo); | 67 Internals repoImpl = HgInternals.getImplementationRepo(repo); | 
| 67 final LogFacility log = repo.getSessionContext().getLog(); | 68 final LogFacility log = repo.getSessionContext().getLog(); | 
| 68 try { | 69 try { | 
| 69 File queues = new File(repoDir, "patches.queues"); | 70 File queues = repoImpl.getFileFromRepoDir("patches.queues"); | 
| 70 if (queues.isFile()) { | 71 if (queues.isFile()) { | 
| 71 LineReader lr = new LineReader(queues, log).trimLines(true).skipEmpty(true); | 72 LineReader lr = new LineReader(queues, log).trimLines(true).skipEmpty(true); | 
| 72 lr.read(new LineReader.SimpleLineCollector(), queueNames = new LinkedList<String>()); | 73 lr.read(new LineReader.SimpleLineCollector(), queueNames = new LinkedList<String>()); | 
| 73 } | 74 } | 
| 74 final String queueLocation; // path under .hg to patch queue information (status, series and diff files) | 75 final String queueLocation; // path under .hg to patch queue information (status, series and diff files) | 
| 75 File activeQueueFile = new File(repoDir, "patches.queue"); | 76 File activeQueueFile = repoImpl.getFileFromRepoDir("patches.queue"); | 
| 76 // file is there only if it's not default queue ('patches') that is active | 77 // file is there only if it's not default queue ('patches') that is active | 
| 77 if (activeQueueFile.isFile()) { | 78 if (activeQueueFile.isFile()) { | 
| 78 ArrayList<String> contents = new ArrayList<String>(); | 79 ArrayList<String> contents = new ArrayList<String>(); | 
| 79 new LineReader(activeQueueFile, log).read(new LineReader.SimpleLineCollector(), contents); | 80 new LineReader(activeQueueFile, log).read(new LineReader.SimpleLineCollector(), contents); | 
| 80 if (contents.isEmpty()) { | 81 if (contents.isEmpty()) { | 
| 97 sb.append(queueLocation); | 98 sb.append(queueLocation); | 
| 98 sb.append(p); | 99 sb.append(p); | 
| 99 return Path.create(sb); | 100 return Path.create(sb); | 
| 100 } | 101 } | 
| 101 }; | 102 }; | 
| 102 final File fileStatus = new File(repoDir, queueLocation + "status"); | 103 final File fileStatus = repoImpl.getFileFromRepoDir(queueLocation + "status"); | 
| 103 final File fileSeries = new File(repoDir, queueLocation + "series"); | 104 final File fileSeries = repoImpl.getFileFromRepoDir(queueLocation + "series"); | 
| 104 if (fileStatus.isFile()) { | 105 if (fileStatus.isFile()) { | 
| 105 new LineReader(fileStatus, log).read(new LineReader.LineConsumer<List<PatchRecord>>() { | 106 new LineReader(fileStatus, log).read(new LineReader.LineConsumer<List<PatchRecord>>() { | 
| 106 | 107 | 
| 107 public boolean consume(String line, List<PatchRecord> result) throws IOException { | 108 public boolean consume(String line, List<PatchRecord> result) throws IOException { | 
| 108 int sep = line.indexOf(':'); | 109 int sep = line.indexOf(':'); | 
