Mercurial > hg4j
annotate src/com/tmate/hgkit/console/Status.java @ 46:4022c34a4804
Better hashCode impl
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 14 Jan 2011 04:56:53 +0100 |
parents | 603806cd2dc6 |
children | 05829a70b30b |
rev | line source |
---|---|
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
20
11cfabe692b3
Status operation for two repository revisions (no local dir involved)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
18
diff
changeset
|
2 * Copyright (c) 2010, 2011 Artem Tikhomirov |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 */ |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 package com.tmate.hgkit.console; |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 |
18
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
6 import static com.tmate.hgkit.ll.HgRepository.TIP; |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
7 |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 import com.tmate.hgkit.fs.RepositoryLookup; |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
9 import com.tmate.hgkit.ll.HgDataFile; |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 import com.tmate.hgkit.ll.HgRepository; |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 import com.tmate.hgkit.ll.LocalHgRepo; |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
12 import com.tmate.hgkit.ll.Nodeid; |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 /** |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 * @author artem |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 */ |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 public class Status { |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 public static void main(String[] args) throws Exception { |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 RepositoryLookup repoLookup = new RepositoryLookup(); |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 HgRepository hgRepo = repoLookup.detect(cmdLineOpts); |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 if (hgRepo.isInvalid()) { |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 return; |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 } |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 System.out.println(hgRepo.getLocation()); |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 ((LocalHgRepo) hgRepo).loadDirstate().dump(); |
18
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
30 final StatusDump dump = new StatusDump(); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
31 dump.showIgnored = false; |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
32 dump.showClean = false; |
20
11cfabe692b3
Status operation for two repository revisions (no local dir involved)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
18
diff
changeset
|
33 final int r1 = 0, r2 = 11; |
11cfabe692b3
Status operation for two repository revisions (no local dir involved)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
18
diff
changeset
|
34 System.out.printf("Status for changes between revision %d and %d:\n", r1, r2); |
11cfabe692b3
Status operation for two repository revisions (no local dir involved)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
18
diff
changeset
|
35 hgRepo.status(r1, r2, dump); |
11cfabe692b3
Status operation for two repository revisions (no local dir involved)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
18
diff
changeset
|
36 System.out.println("\nStatus against working dir:"); |
18
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
37 ((LocalHgRepo) hgRepo).statusLocal(TIP, dump); |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
38 System.out.println(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
39 System.out.printf("Manifest of the revision %d:\n", r2); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
40 hgRepo.getManifest().walk(r2, r2, new Manifest.Dump()); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
41 System.out.println(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
42 System.out.printf("\nStatus of working dir against %d:\n", r2); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
43 ((LocalHgRepo) hgRepo).statusLocal(r2, dump); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
44 } |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
45 |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
46 protected static void testStatusInternals(HgRepository hgRepo) { |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
47 HgDataFile n = hgRepo.getFileNode("design.txt"); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
48 for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) { |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
49 // expected: 359, 2123, 3079 |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
50 byte[] b = s.getBytes(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
51 final Nodeid nid = Nodeid.fromAscii(b, 0, b.length); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
52 System.out.println(s + " : " + n.length(nid)); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
53 } |
18
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
54 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
55 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
56 private static class StatusDump implements HgRepository.StatusInspector { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
57 public boolean hideStatusPrefix = false; // hg status -n option |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
58 public boolean showCopied = true; // -C |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
59 public boolean showIgnored = true; // -i |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
60 public boolean showClean = true; // -c |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
61 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
62 public void modified(String fname) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
63 print('M', fname); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
64 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
65 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
66 public void added(String fname) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
67 print('A', fname); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
68 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
69 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
70 public void copied(String fnameOrigin, String fnameAdded) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
71 added(fnameAdded); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
72 if (showCopied) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
73 print(' ', fnameOrigin); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
74 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
75 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
76 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
77 public void removed(String fname) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
78 print('R', fname); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
79 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
80 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
81 public void clean(String fname) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
82 if (showClean) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
83 print('C', fname); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
84 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
85 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
86 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
87 public void missing(String fname) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
88 print('!', fname); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
89 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
90 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
91 public void unknown(String fname) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
92 print('?', fname); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
93 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
94 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
95 public void ignored(String fname) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
96 if (showIgnored) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
97 print('I', fname); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
98 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
99 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
100 |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
101 private void print(char status, String fname) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
102 if (!hideStatusPrefix) { |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
103 System.out.print(status); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
104 System.out.print(' '); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
105 } |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
106 System.out.println(fname); |
02ee376bee79
status operation against current working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
107 } |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 } |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } |