comparison src/org/tmatesoft/hg/repo/HgBundle.java @ 357:dfb8405d996f

Clean debug stacktraces
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 06 Dec 2011 19:47:01 +0100
parents 5f9073eabf06
children fc8bc2f1edbe
comparison
equal deleted inserted replaced
356:91d75e1bac9f 357:dfb8405d996f
16 */ 16 */
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import java.io.File; 19 import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.util.LinkedList;
22 21
23 import org.tmatesoft.hg.core.HgBadStateException; 22 import org.tmatesoft.hg.core.HgBadStateException;
24 import org.tmatesoft.hg.core.HgCallbackTargetException; 23 import org.tmatesoft.hg.core.HgCallbackTargetException;
25 import org.tmatesoft.hg.core.HgException;
26 import org.tmatesoft.hg.core.HgInvalidFileException; 24 import org.tmatesoft.hg.core.HgInvalidFileException;
27 import org.tmatesoft.hg.core.Nodeid; 25 import org.tmatesoft.hg.core.Nodeid;
26 import org.tmatesoft.hg.core.SessionContext;
28 import org.tmatesoft.hg.internal.ByteArrayChannel; 27 import org.tmatesoft.hg.internal.ByteArrayChannel;
29 import org.tmatesoft.hg.internal.ByteArrayDataAccess; 28 import org.tmatesoft.hg.internal.ByteArrayDataAccess;
30 import org.tmatesoft.hg.internal.DataAccess; 29 import org.tmatesoft.hg.internal.DataAccess;
31 import org.tmatesoft.hg.internal.DataAccessProvider; 30 import org.tmatesoft.hg.internal.DataAccessProvider;
32 import org.tmatesoft.hg.internal.DigestHelper; 31 import org.tmatesoft.hg.internal.DigestHelper;
43 */ 42 */
44 public class HgBundle { 43 public class HgBundle {
45 44
46 private final File bundleFile; 45 private final File bundleFile;
47 private final DataAccessProvider accessProvider; 46 private final DataAccessProvider accessProvider;
48 47 // private final SessionContext sessionContext;
49 HgBundle(DataAccessProvider dap, File bundle) { 48
49 HgBundle(SessionContext ctx, DataAccessProvider dap, File bundle) {
50 // sessionContext = ctx;
50 accessProvider = dap; 51 accessProvider = dap;
51 bundleFile = bundle; 52 bundleFile = bundle;
52 } 53 }
53 54
54 private DataAccess getDataStream() throws IOException { 55 private DataAccess getDataStream() throws IOException {
183 } catch (RuntimeException ex) { 184 } catch (RuntimeException ex) {
184 throw new HgCallbackTargetException(ex); 185 throw new HgCallbackTargetException(ex);
185 } 186 }
186 } 187 }
187 188
188 public void dump() throws HgException {
189 Dump dump = new Dump();
190 inspectAll(dump);
191 System.out.println("Total files:" + dump.names.size());
192 for (String s : dump.names) {
193 System.out.println(s);
194 }
195 }
196
197 // callback to minimize amount of Strings and Nodeids instantiated 189 // callback to minimize amount of Strings and Nodeids instantiated
198 public interface Inspector { 190 public interface Inspector {
199 void changelogStart(); 191 void changelogStart();
200 192
201 void changelogEnd(); 193 void changelogEnd();
212 * XXX desperately need exceptions here 204 * XXX desperately need exceptions here
213 * @param element data element, instance might be reused, don't keep a reference to it or its raw data 205 * @param element data element, instance might be reused, don't keep a reference to it or its raw data
214 * @return <code>true</code> to continue 206 * @return <code>true</code> to continue
215 */ 207 */
216 boolean element(GroupElement element); 208 boolean element(GroupElement element);
217 }
218
219 public static class Dump implements Inspector {
220 public final LinkedList<String> names = new LinkedList<String>();
221
222 public void changelogStart() {
223 System.out.println("Changelog group");
224 }
225
226 public void changelogEnd() {
227 }
228
229 public void manifestStart() {
230 System.out.println("Manifest group");
231 }
232
233 public void manifestEnd() {
234 }
235
236 public void fileStart(String name) {
237 names.add(name);
238 System.out.println(name);
239 }
240
241 public void fileEnd(String name) {
242 }
243
244 public boolean element(GroupElement ge) {
245 try {
246 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patch().count());
247 } catch (Exception ex) {
248 ex.printStackTrace(); // FIXME
249 }
250 return true;
251 }
252 } 209 }
253 210
254 public void inspectChangelog(Inspector inspector) throws HgInvalidFileException { 211 public void inspectChangelog(Inspector inspector) throws HgInvalidFileException {
255 if (inspector == null) { 212 if (inspector == null) {
256 throw new IllegalArgumentException(); 213 throw new IllegalArgumentException();
447 } 404 }
448 405
449 public byte[] apply(DataAccess baseContent) throws IOException { 406 public byte[] apply(DataAccess baseContent) throws IOException {
450 return patch().apply(baseContent, -1); 407 return patch().apply(baseContent, -1);
451 } 408 }
409
410 public String toString() {
411 int patchCount;
412 try {
413 patchCount = patch().count();
414 } catch (IOException ex) {
415 ex.printStackTrace();
416 patchCount = -1;
417 }
418 return String.format("%s %s %s %s; patches:%d\n", node().shortNotation(), firstParent().shortNotation(), secondParent().shortNotation(), cset().shortNotation(), patchCount);
419 }
452 } 420 }
453 } 421 }