Mercurial > jhg
comparison cmdline/org/tmatesoft/hg/console/Cat.java @ 143:b9700740553a
Command line tools parse and respect most of command-line arguments
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Thu, 17 Feb 2011 22:16:25 +0100 |
| parents | a3a2e5deb320 |
| children | 6b55f10ef54b |
comparison
equal
deleted
inserted
replaced
| 142:37a34044e6bd | 143:b9700740553a |
|---|---|
| 14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
| 15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.console; | 17 package org.tmatesoft.hg.console; |
| 18 | 18 |
| 19 import org.tmatesoft.hg.internal.DigestHelper; | 19 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
| 20 | |
| 21 import java.io.OutputStream; | |
| 22 import java.nio.ByteBuffer; | |
| 23 | |
| 20 import org.tmatesoft.hg.repo.HgDataFile; | 24 import org.tmatesoft.hg.repo.HgDataFile; |
| 21 import org.tmatesoft.hg.repo.HgRepository; | 25 import org.tmatesoft.hg.repo.HgRepository; |
| 22 import org.tmatesoft.hg.repo.HgInternals; | 26 import org.tmatesoft.hg.util.ByteChannel; |
| 23 | 27 |
| 24 | 28 |
| 25 /** | 29 /** |
| 26 * @author Artem Tikhomirov | 30 * @author Artem Tikhomirov |
| 27 * @author TMate Software Ltd. | 31 * @author TMate Software Ltd. |
| 33 HgRepository hgRepo = cmdLineOpts.findRepository(); | 37 HgRepository hgRepo = cmdLineOpts.findRepository(); |
| 34 if (hgRepo.isInvalid()) { | 38 if (hgRepo.isInvalid()) { |
| 35 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); | 39 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
| 36 return; | 40 return; |
| 37 } | 41 } |
| 38 HgInternals debug = new HgInternals(hgRepo); | 42 int rev = cmdLineOpts.getSingleInt(TIP, "-r", "--rev"); |
| 39 String[] toCheck = new String[] {"design.txt", "src/com/tmate/hgkit/ll/Changelog.java", "src/Extras.java", "bin/com/tmate/hgkit/ll/Changelog.class"}; | 43 OutputStreamChannel out = new OutputStreamChannel(System.out); |
| 40 boolean[] checkResult = debug.checkIgnored(toCheck); | 44 for (String fname : cmdLineOpts.getList("")) { |
| 41 for (int i = 0; i < toCheck.length; i++) { | |
| 42 System.out.println("Ignored " + toCheck[i] + ": " + checkResult[i]); | |
| 43 } | |
| 44 DigestHelper dh = new DigestHelper(); | |
| 45 for (String fname : cmdLineOpts.files) { | |
| 46 System.out.println(fname); | 45 System.out.println(fname); |
| 47 HgDataFile fn = hgRepo.getFileNode(fname); | 46 HgDataFile fn = hgRepo.getFileNode(fname); |
| 48 if (fn.exists()) { | 47 if (fn.exists()) { |
| 49 int total = fn.getRevisionCount(); | 48 fn.content(rev, out, true); |
| 50 System.out.printf("Total revisions: %d\n", total); | 49 System.out.println(); |
| 51 for (int i = 0; i < total; i++) { | |
| 52 byte[] content = fn.content(i); | |
| 53 System.out.println("==========>"); | |
| 54 System.out.println(new String(content)); | |
| 55 int[] parentRevisions = new int[2]; | |
| 56 byte[] parent1 = new byte[20]; | |
| 57 byte[] parent2 = new byte[20]; | |
| 58 fn.parents(i, parentRevisions, parent1, parent2); | |
| 59 System.out.println(dh.sha1(parent1, parent2, content).asHexString()); | |
| 60 } | |
| 61 } else { | 50 } else { |
| 62 System.out.println(">>>Not found!"); | 51 System.out.printf("%s not found!\n", fname); |
| 63 } | 52 } |
| 64 } | 53 } |
| 65 } | 54 } |
| 55 | |
| 56 private static class OutputStreamChannel implements ByteChannel { | |
| 57 | |
| 58 private final OutputStream stream; | |
| 59 | |
| 60 public OutputStreamChannel(OutputStream out) { | |
| 61 stream = out; | |
| 62 } | |
| 63 | |
| 64 public int write(ByteBuffer buffer) throws Exception { | |
| 65 int count = buffer.remaining(); | |
| 66 while(buffer.hasRemaining()) { | |
| 67 stream.write(buffer.get()); | |
| 68 } | |
| 69 return count; | |
| 70 } | |
| 71 } | |
| 66 } | 72 } |
