Mercurial > jhg
comparison cmdline/org/tmatesoft/hg/console/Status.java @ 74:6f1b88693d48
Complete refactoring to org.tmatesoft
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 24 Jan 2011 03:14:45 +0100 |
parents | 9a03a80a0f2f |
children | 61eedab3eb3e |
comparison
equal
deleted
inserted
replaced
73:0d279bcc4442 | 74:6f1b88693d48 |
---|---|
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@svnkit.com | 15 * contact TMate Software at support@svnkit.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.console; | 17 package org.tmatesoft.hg.console; |
18 | 18 |
19 import static com.tmate.hgkit.ll.HgRepository.TIP; | 19 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
20 | 20 |
21 import java.util.ArrayList; | 21 import java.util.ArrayList; |
22 import java.util.Collections; | 22 import java.util.Collections; |
23 import java.util.List; | 23 import java.util.List; |
24 import java.util.Map; | |
24 | 25 |
25 import com.tmate.hgkit.fs.RepositoryLookup; | 26 import org.tmatesoft.hg.core.Nodeid; |
26 import com.tmate.hgkit.ll.HgDataFile; | 27 import org.tmatesoft.hg.core.Path; |
27 import com.tmate.hgkit.ll.HgRepository; | 28 import org.tmatesoft.hg.repo.HgDataFile; |
28 import com.tmate.hgkit.ll.Internals; | 29 import org.tmatesoft.hg.repo.HgRepository; |
29 import com.tmate.hgkit.ll.LocalHgRepo; | 30 import org.tmatesoft.hg.repo.Internals; |
30 import com.tmate.hgkit.ll.Nodeid; | 31 import org.tmatesoft.hg.repo.StatusCollector; |
31 import com.tmate.hgkit.ll.StatusCollector; | 32 import org.tmatesoft.hg.repo.WorkingCopyStatusCollector; |
32 import com.tmate.hgkit.ll.WorkingCopyStatusCollector; | |
33 | 33 |
34 /** | 34 /** |
35 * | 35 * |
36 * @author Artem Tikhomirov | 36 * @author Artem Tikhomirov |
37 * @author TMate Software Ltd. | 37 * @author TMate Software Ltd. |
38 */ | 38 */ |
39 public class Status { | 39 public class Status { |
40 | 40 |
41 public static void main(String[] args) throws Exception { | 41 public static void main(String[] args) throws Exception { |
42 RepositoryLookup repoLookup = new RepositoryLookup(); | 42 Options cmdLineOpts = Options.parse(args); |
43 RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); | 43 HgRepository hgRepo = cmdLineOpts.findRepository(); |
44 HgRepository hgRepo = repoLookup.detect(cmdLineOpts); | |
45 if (hgRepo.isInvalid()) { | 44 if (hgRepo.isInvalid()) { |
46 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); | 45 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
47 return; | 46 return; |
48 } | 47 } |
49 System.out.println(hgRepo.getLocation()); | 48 System.out.println(hgRepo.getLocation()); |
49 // | |
50 // bunchOfTests(hgRepo); | |
51 // | |
52 // new Internals(hgRepo).dumpDirstate(); | |
53 // | |
54 mardu(hgRepo); | |
55 } | |
56 | |
57 private static void mardu(HgRepository hgRepo) { | |
58 WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(hgRepo); | |
59 StatusCollector.Record r = new StatusCollector.Record(); | |
60 wcc.walk(TIP, r); | |
61 sortAndPrint('M', r.getModified()); | |
62 sortAndPrint('A', r.getAdded(), r.getCopied()); | |
63 sortAndPrint('R', r.getRemoved()); | |
64 sortAndPrint('?', r.getUnknown()); | |
65 // sortAndPrint('I', r.getIgnored()); | |
66 // sortAndPrint('C', r.getClean()); | |
67 sortAndPrint('!', r.getMissing()); | |
68 } | |
69 | |
70 private static void bunchOfTests(HgRepository hgRepo) throws Exception { | |
50 Internals debug = new Internals(hgRepo); | 71 Internals debug = new Internals(hgRepo); |
51 debug.dumpDirstate(); | 72 debug.dumpDirstate(); |
52 final StatusDump dump = new StatusDump(); | 73 final StatusDump dump = new StatusDump(); |
53 dump.showIgnored = false; | 74 dump.showIgnored = false; |
54 dump.showClean = false; | 75 dump.showClean = false; |
64 sortAndPrint('R', r.getRemoved()); | 85 sortAndPrint('R', r.getRemoved()); |
65 // | 86 // |
66 System.out.println("\n\nTry hg status --change <rev>:"); | 87 System.out.println("\n\nTry hg status --change <rev>:"); |
67 sc.change(0, dump); | 88 sc.change(0, dump); |
68 System.out.println("\nStatus against working dir:"); | 89 System.out.println("\nStatus against working dir:"); |
69 WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(hgRepo, ((LocalHgRepo) hgRepo).createWorkingDirWalker()); | 90 WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(hgRepo); |
70 wcc.walk(TIP, dump); | 91 wcc.walk(TIP, dump); |
71 System.out.println(); | 92 System.out.println(); |
72 System.out.printf("Manifest of the revision %d:\n", r2); | 93 System.out.printf("Manifest of the revision %d:\n", r2); |
73 hgRepo.getManifest().walk(r2, r2, new Manifest.Dump()); | 94 hgRepo.getManifest().walk(r2, r2, new Manifest.Dump()); |
74 System.out.println(); | 95 System.out.println(); |
75 System.out.printf("\nStatus of working dir against %d:\n", r2); | 96 System.out.printf("\nStatus of working dir against %d:\n", r2); |
76 r = wcc.status(r2); | 97 r = wcc.status(r2); |
77 sortAndPrint('M', r.getModified()); | 98 sortAndPrint('M', r.getModified()); |
78 sortAndPrint('A', r.getAdded()); | 99 sortAndPrint('A', r.getAdded(), r.getCopied()); |
79 sortAndPrint('R', r.getRemoved()); | 100 sortAndPrint('R', r.getRemoved()); |
80 sortAndPrint('?', r.getUnknown()); | 101 sortAndPrint('?', r.getUnknown()); |
81 sortAndPrint('I', r.getIgnored()); | 102 sortAndPrint('I', r.getIgnored()); |
82 sortAndPrint('C', r.getClean()); | 103 sortAndPrint('C', r.getClean()); |
83 sortAndPrint('!', r.getMissing()); | 104 sortAndPrint('!', r.getMissing()); |
84 } | 105 } |
85 | 106 |
86 private static void sortAndPrint(char prefix, List<String> ul) { | 107 private static void sortAndPrint(char prefix, List<String> ul) { |
108 sortAndPrint(prefix, ul, null); | |
109 } | |
110 private static void sortAndPrint(char prefix, List<String> ul, Map<String, String> copies) { | |
87 ArrayList<String> sortList = new ArrayList<String>(ul); | 111 ArrayList<String> sortList = new ArrayList<String>(ul); |
88 Collections.sort(sortList); | 112 Collections.sort(sortList); |
89 for (String s : sortList) { | 113 for (String s : sortList) { |
90 System.out.print(prefix); | 114 System.out.print(prefix); |
91 System.out.print(' '); | 115 System.out.print(' '); |
92 System.out.println(s); | 116 System.out.println(s); |
117 if (copies != null && copies.containsKey(s)) { | |
118 System.out.println(" " + copies.get(s)); | |
119 } | |
93 } | 120 } |
94 } | 121 } |
95 | 122 |
96 protected static void testStatusInternals(HgRepository hgRepo) { | 123 protected static void testStatusInternals(HgRepository hgRepo) { |
97 HgDataFile n = hgRepo.getFileNode("design.txt"); | 124 HgDataFile n = hgRepo.getFileNode(Path.create("design.txt")); |
98 for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) { | 125 for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) { |
99 // expected: 359, 2123, 3079 | 126 // expected: 359, 2123, 3079 |
100 byte[] b = s.getBytes(); | 127 byte[] b = s.getBytes(); |
101 final Nodeid nid = Nodeid.fromAscii(b, 0, b.length); | 128 final Nodeid nid = Nodeid.fromAscii(b, 0, b.length); |
102 System.out.println(s + " : " + n.length(nid)); | 129 System.out.println(s + " : " + n.length(nid)); |