Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/ext/MqManager.java @ 463:a0507a9f3da0 smartgit3
Initial support for MqExtension
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 20 Jun 2012 21:16:21 +0200 |
parents | |
children | 1a3c18d57a8e |
rev | line source |
---|---|
463
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012 TMate Software Ltd |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.repo.ext; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.BufferedReader; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.io.File; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.io.FileReader; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.IOException; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.util.Collections; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.util.LinkedList; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.util.List; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.core.HgInvalidControlFileException; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import org.tmatesoft.hg.core.HgInvalidFileException; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import org.tmatesoft.hg.core.Nodeid; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import org.tmatesoft.hg.repo.HgInternals; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgRepository; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import org.tmatesoft.hg.util.LogFacility; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import org.tmatesoft.hg.util.Path; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 /** |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * Mercurial Queues Support. |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * Access to MqExtension functionality. |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 * @author Artem Tikhomirov |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 * @author TMate Software Ltd. |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 */ |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 public class MqManager { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 private final HgRepository repo; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 private List<PatchRecord> applied = Collections.emptyList(); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 private List<PatchRecord> allKnown = Collections.emptyList(); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 public MqManager(HgRepository hgRepo) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 repo = hgRepo; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 /** |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 * Updates manager with up-to-date state of the mercurial queues. |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 */ |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 public void refresh() throws HgInvalidControlFileException { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 File repoDir = HgInternals.getRepositoryDir(repo); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 final LogFacility log = HgInternals.getContext(repo).getLog(); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 final File fileStatus = new File(repoDir, "patches/status"); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 final File fileSeries = new File(repoDir, "patches/series"); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 try { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 if (fileStatus.isFile()) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 new LineReader(fileStatus, log).read(new LineConsumer<List<PatchRecord>>() { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 public boolean consume(String line, List<PatchRecord> result) throws IOException { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 int sep = line.indexOf(':'); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 if (sep == -1) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 log.warn(MqManager.class, "Bad line in %s:%s", fileStatus.getPath(), line); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 return true; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 Nodeid nid = Nodeid.fromAscii(line.substring(0, sep)); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 String name = new String(line.substring(sep+1)); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 result.add(new PatchRecord(nid, name, Path.create(".hg/patches/" + name))); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 return true; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 }, applied = new LinkedList<PatchRecord>()); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 if (fileSeries.isFile()) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 new LineReader(fileSeries, log).read(new LineConsumer<List<PatchRecord>>() { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 public boolean consume(String line, List<PatchRecord> result) throws IOException { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 result.add(new PatchRecord(null, line, Path.create(".hg/patches/" + line))); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 return true; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 }, allKnown = new LinkedList<PatchRecord>()); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 } catch (HgInvalidFileException ex) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 HgInvalidControlFileException th = new HgInvalidControlFileException(ex.getMessage(), ex.getCause(), ex.getFile()); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 th.setStackTrace(ex.getStackTrace()); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 throw th; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 /** |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 * Subset of the patches from the queue that were already applied to the repository |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 * |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 * <p>Clients shall call {@link #refresh()} prior to first use |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 * @return collection of records in no particular order, may be empty if none applied |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 */ |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 public List<PatchRecord> getAppliedPatches() { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 return Collections.unmodifiableList(applied); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 /** |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 * All of the patches that MQ knows about for this repository |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 * |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 * <p>Clients shall call {@link #refresh()} prior to first use |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 * @return collection of records in no particular order, may be empty if there are no patches in the queue |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 */ |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 public List<PatchRecord> getAllKnownPatches() { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 return Collections.unmodifiableList(allKnown); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 public class PatchRecord { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 private final Nodeid nodeid; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 private final String name; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 private final Path location; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 PatchRecord(Nodeid revision, String name, Path diffLocation) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 nodeid = revision; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 this.name = name; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 this.location = diffLocation; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 /** |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 * Identifies changeset of the patch that has been applied to the repository |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 * |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 * @return changeset revision or <code>null</code> if this patch is not yet applied |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 */ |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 public Nodeid getRevision() { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 return nodeid; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 /** |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 * Identifies patch, either based on a user-supplied name (<code>hg qnew <i>patch-name</i></code>) or |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 * an automatically generated name (like <code><i>revisionIndex</i>.diff</code> for imported changesets). |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 * Clients shall not rely on this naming scheme, though. |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 * |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 * @return never <code>null</code> |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 */ |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 public String getName() { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 return name; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 /** |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 * Location of diff file with the patch, relative to repository root |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 * @return path to the patch, never <code>null</code> |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 */ |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 public Path getPatchLocation() { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 return location; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 // TODO refine API and extract into separate classes |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 interface LineConsumer<T> { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 // boolean begin(File f, T paramObj) throws IOException; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 boolean consume(String line, T paramObj) throws IOException; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 // boolean end(File f, T paramObj) throws IOException; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 class LineReader { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 private final File file; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 private final LogFacility log; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 LineReader(File f, LogFacility logFacility) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 file = f; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 log = logFacility; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 <T> void read(LineConsumer<T> consumer, T paramObj) throws HgInvalidFileException { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 BufferedReader statusFileReader = null; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 try { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 // consumer.begin(file, paramObj); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 statusFileReader = new BufferedReader(new FileReader(file)); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 String line; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 boolean ok = true; |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 while (ok && (line = statusFileReader.readLine()) != null) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 line = line.trim(); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 if (line.length() > 0) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 ok = consumer.consume(line, paramObj); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 } catch (IOException ex) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 throw new HgInvalidFileException(ex.getMessage(), ex, file); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 } finally { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 try { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 statusFileReader.close(); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 } catch (IOException ex) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 log.warn(MqManager.class, ex, null); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 // try { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 // consumer.end(file, paramObj); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 // } catch (IOException ex) { |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 // log.warn(MqManager.class, ex, null); |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 // } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
199 } |
a0507a9f3da0
Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 } |