Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RevlogDump.java @ 73:0d279bcc4442
Utility for future troubleshooting
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Sun, 23 Jan 2011 04:06:18 +0100 |
| parents | src/com/tmate/hgkit/console/Main.java@b01500fe2604 |
| children | 61eedab3eb3e |
comparison
equal
deleted
inserted
replaced
| 72:9a03a80a0f2f | 73:0d279bcc4442 |
|---|---|
| 1 /* | |
| 2 * Copyright (c) 2010-2011 TMate Software Ltd | |
| 3 * | |
| 4 * This program is free software; you can redistribute it and/or modify | |
| 5 * it under the terms of the GNU General Public License as published by | |
| 6 * the Free Software Foundation; version 2 of the License. | |
| 7 * | |
| 8 * This program is distributed in the hope that it will be useful, | |
| 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 * GNU General Public License for more details. | |
| 12 * | |
| 13 * For information on how to redistribute this software under | |
| 14 * the terms of a license other than GNU General Public License | |
| 15 * contact TMate Software at support@svnkit.com | |
| 16 */ | |
| 17 package org.tmatesoft.hg.internal; | |
| 18 | |
| 19 import java.io.BufferedInputStream; | |
| 20 import java.io.DataInput; | |
| 21 import java.io.DataInputStream; | |
| 22 import java.io.File; | |
| 23 import java.io.FileInputStream; | |
| 24 import java.math.BigInteger; | |
| 25 import java.util.zip.Inflater; | |
| 26 | |
| 27 /** | |
| 28 * Utility to test/debug/troubleshoot | |
| 29 * | |
| 30 * @author Artem Tikhomirov | |
| 31 * @author TMate Software Ltd. | |
| 32 */ | |
| 33 public class RevlogDump { | |
| 34 | |
| 35 /** | |
| 36 * Takes 3 command line arguments - | |
| 37 * repository path, | |
| 38 * path to index file (i.e. store/data/hello.c.i) in the repository (relative) | |
| 39 * and "dumpData" whether to print actual content or just revlog headers | |
| 40 */ | |
| 41 public static void main(String[] args) throws Exception { | |
| 42 String repo = "/temp/hg/hello/.hg/"; | |
| 43 String filename = "store/00changelog.i"; | |
| 44 // String filename = "store/data/hello.c.i"; | |
| 45 // String filename = "store/data/docs/readme.i"; | |
| 46 boolean dumpData = true; | |
| 47 if (args.length > 2) { | |
| 48 repo = args[0]; | |
| 49 filename = args[1]; | |
| 50 dumpData = "dumpData".equals(args[2]); | |
| 51 } | |
| 52 // | |
| 53 DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(new File(repo + filename)))); | |
| 54 DataInput di = dis; | |
| 55 dis.mark(10); | |
| 56 int versionField = di.readInt(); | |
| 57 dis.reset(); | |
| 58 final int INLINEDATA = 1 << 16; | |
| 59 | |
| 60 boolean inlineData = (versionField & INLINEDATA) != 0; | |
| 61 System.out.printf("%#8x, inline: %b\n", versionField, inlineData); | |
| 62 System.out.println("Index Offset Flags Packed Actual Base Rev Link Rev Parent1 Parent2 nodeid"); | |
| 63 int entryCount = 0; | |
| 64 while (dis.available() > 0) { | |
| 65 long l = di.readLong(); | |
| 66 long offset = l >>> 16; | |
| 67 int flags = (int) (l & 0X0FFFF); | |
| 68 int compressedLen = di.readInt(); | |
| 69 int actualLen = di.readInt(); | |
| 70 int baseRevision = di.readInt(); | |
| 71 int linkRevision = di.readInt(); | |
| 72 int parent1Revision = di.readInt(); | |
| 73 int parent2Revision = di.readInt(); | |
| 74 byte[] buf = new byte[32]; | |
| 75 di.readFully(buf, 12, 20); | |
| 76 dis.skip(12); | |
| 77 System.out.printf("%4d:%14d %6X %10d %10d %10d %10d %8d %8d %040x\n", entryCount, offset, flags, compressedLen, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, new BigInteger(buf)); | |
| 78 if (inlineData) { | |
| 79 String resultString; | |
| 80 byte[] data = new byte[compressedLen]; | |
| 81 di.readFully(data); | |
| 82 if (data[0] == 0x78 /* 'x' */) { | |
| 83 Inflater zlib = new Inflater(); | |
| 84 zlib.setInput(data, 0, compressedLen); | |
| 85 byte[] result = new byte[actualLen*2]; | |
| 86 int resultLen = zlib.inflate(result); | |
| 87 zlib.end(); | |
| 88 resultString = new String(result, 0, resultLen, "UTF-8"); | |
| 89 } else if (data[0] == 0x75 /* 'u' */) { | |
| 90 resultString = new String(data, 1, data.length - 1, "UTF-8"); | |
| 91 } else { | |
| 92 resultString = new String(data); | |
| 93 } | |
| 94 if (dumpData) { | |
| 95 System.out.println(resultString); | |
| 96 } | |
| 97 entryCount++; | |
| 98 } | |
| 99 } | |
| 100 dis.close(); | |
| 101 // | |
| 102 } | |
| 103 } |
