Mercurial > hg4j
comparison src/com/tmate/hgkit/console/Status.java @ 55:05829a70b30b
Status operation extracted into separate, cache-friendly class
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 17 Jan 2011 04:45:09 +0100 |
parents | 603806cd2dc6 |
children | 576d6e8a09f6 |
comparison
equal
deleted
inserted
replaced
54:fd4f2c98995b | 55:05829a70b30b |
---|---|
3 */ | 3 */ |
4 package com.tmate.hgkit.console; | 4 package com.tmate.hgkit.console; |
5 | 5 |
6 import static com.tmate.hgkit.ll.HgRepository.TIP; | 6 import static com.tmate.hgkit.ll.HgRepository.TIP; |
7 | 7 |
8 import java.util.ArrayList; | |
9 import java.util.Collections; | |
10 import java.util.List; | |
11 | |
8 import com.tmate.hgkit.fs.RepositoryLookup; | 12 import com.tmate.hgkit.fs.RepositoryLookup; |
9 import com.tmate.hgkit.ll.HgDataFile; | 13 import com.tmate.hgkit.ll.HgDataFile; |
10 import com.tmate.hgkit.ll.HgRepository; | 14 import com.tmate.hgkit.ll.HgRepository; |
11 import com.tmate.hgkit.ll.LocalHgRepo; | 15 import com.tmate.hgkit.ll.LocalHgRepo; |
12 import com.tmate.hgkit.ll.Nodeid; | 16 import com.tmate.hgkit.ll.Nodeid; |
17 import com.tmate.hgkit.ll.StatusCollector; | |
13 | 18 |
14 /** | 19 /** |
15 * | 20 * |
16 * @author artem | 21 * @author artem |
17 */ | 22 */ |
28 System.out.println(hgRepo.getLocation()); | 33 System.out.println(hgRepo.getLocation()); |
29 ((LocalHgRepo) hgRepo).loadDirstate().dump(); | 34 ((LocalHgRepo) hgRepo).loadDirstate().dump(); |
30 final StatusDump dump = new StatusDump(); | 35 final StatusDump dump = new StatusDump(); |
31 dump.showIgnored = false; | 36 dump.showIgnored = false; |
32 dump.showClean = false; | 37 dump.showClean = false; |
33 final int r1 = 0, r2 = 11; | 38 StatusCollector sc = new StatusCollector(hgRepo); |
39 final int r1 = 0, r2 = 3; | |
34 System.out.printf("Status for changes between revision %d and %d:\n", r1, r2); | 40 System.out.printf("Status for changes between revision %d and %d:\n", r1, r2); |
35 hgRepo.status(r1, r2, dump); | 41 sc.walk(r1, r2, dump); |
36 System.out.println("\nStatus against working dir:"); | 42 // |
37 ((LocalHgRepo) hgRepo).statusLocal(TIP, dump); | 43 System.out.println("\n\nSame, but sorted in the way hg status does:"); |
38 System.out.println(); | 44 StatusCollector.Record r = sc.status(r1, r2); |
39 System.out.printf("Manifest of the revision %d:\n", r2); | 45 sortAndPrint('M', r.getModified()); |
40 hgRepo.getManifest().walk(r2, r2, new Manifest.Dump()); | 46 sortAndPrint('A', r.getAdded()); |
41 System.out.println(); | 47 sortAndPrint('R', r.getRemoved()); |
42 System.out.printf("\nStatus of working dir against %d:\n", r2); | 48 // System.out.println("\nStatus against working dir:"); |
43 ((LocalHgRepo) hgRepo).statusLocal(r2, dump); | 49 // ((LocalHgRepo) hgRepo).statusLocal(TIP, dump); |
50 // System.out.println(); | |
51 // System.out.printf("Manifest of the revision %d:\n", r2); | |
52 // hgRepo.getManifest().walk(r2, r2, new Manifest.Dump()); | |
53 // System.out.println(); | |
54 // System.out.printf("\nStatus of working dir against %d:\n", r2); | |
55 // ((LocalHgRepo) hgRepo).statusLocal(r2, dump); | |
56 } | |
57 | |
58 private static void sortAndPrint(char prefix, List<String> ul) { | |
59 ArrayList<String> sortList = new ArrayList<String>(ul); | |
60 Collections.sort(sortList); | |
61 for (String s : sortList) { | |
62 System.out.print(prefix); | |
63 System.out.print(' '); | |
64 System.out.println(s); | |
65 } | |
44 } | 66 } |
45 | 67 |
46 protected static void testStatusInternals(HgRepository hgRepo) { | 68 protected static void testStatusInternals(HgRepository hgRepo) { |
47 HgDataFile n = hgRepo.getFileNode("design.txt"); | 69 HgDataFile n = hgRepo.getFileNode("design.txt"); |
48 for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) { | 70 for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) { |
51 final Nodeid nid = Nodeid.fromAscii(b, 0, b.length); | 73 final Nodeid nid = Nodeid.fromAscii(b, 0, b.length); |
52 System.out.println(s + " : " + n.length(nid)); | 74 System.out.println(s + " : " + n.length(nid)); |
53 } | 75 } |
54 } | 76 } |
55 | 77 |
56 private static class StatusDump implements HgRepository.StatusInspector { | 78 private static class StatusDump implements StatusCollector.Inspector { |
57 public boolean hideStatusPrefix = false; // hg status -n option | 79 public boolean hideStatusPrefix = false; // hg status -n option |
58 public boolean showCopied = true; // -C | 80 public boolean showCopied = true; // -C |
59 public boolean showIgnored = true; // -i | 81 public boolean showIgnored = true; // -i |
60 public boolean showClean = true; // -c | 82 public boolean showClean = true; // -c |
61 | 83 |