Mercurial > hg4j
annotate src/com/tmate/hgkit/console/Log.java @ 61:fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 18 Jan 2011 18:32:49 +0100 |
parents | 613c936d74e4 |
children | e21df6259f83 |
rev | line source |
---|---|
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
1 /* |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
2 * Copyright (c) 2010, 2011 Artem Tikhomirov |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 */ |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 package com.tmate.hgkit.console; |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
6 import java.util.Formatter; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
7 import java.util.LinkedHashSet; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
8 import java.util.LinkedList; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
9 import java.util.List; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
10 import java.util.Map; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
11 import java.util.Set; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
12 |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
1
diff
changeset
|
13 import com.tmate.hgkit.fs.RepositoryLookup; |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
1
diff
changeset
|
14 import com.tmate.hgkit.ll.Changeset; |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
1
diff
changeset
|
15 import com.tmate.hgkit.ll.HgDataFile; |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 import com.tmate.hgkit.ll.HgRepository; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
17 import com.tmate.hgkit.ll.Nodeid; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
18 import com.tmate.hgkit.ll.Revlog; |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
19 import com.tmate.hgkit.ll.StatusCollector; |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 /** |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 * @author artem |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 */ |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 public class Log { |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 public static void main(String[] args) throws Exception { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
1
diff
changeset
|
27 RepositoryLookup repoLookup = new RepositoryLookup(); |
4
aa1912c70b36
Fix offset issue for inline revlogs. Commandline processing.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
28 RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); |
aa1912c70b36
Fix offset issue for inline revlogs. Commandline processing.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
29 HgRepository hgRepo = repoLookup.detect(cmdLineOpts); |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 if (hgRepo.isInvalid()) { |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 return; |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 } |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 System.out.println(hgRepo.getLocation()); |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
35 final Dump dump = new Dump(hgRepo); |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
36 dump.complete = true; //cmdLineOpts; |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
37 dump.verbose = false; //cmdLineOpts; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
38 dump.reverseOrder = true; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
39 dump.branches = cmdLineOpts.branches; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
40 if (cmdLineOpts.users != null) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
41 dump.users = new LinkedHashSet<String>(); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
42 for (String u : cmdLineOpts.users) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
43 dump.users.add(u.toLowerCase()); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
44 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
45 } |
6
5abe5af181bd
Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
46 if (cmdLineOpts.files.isEmpty()) { |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
47 if (cmdLineOpts.limit == -1) { |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
48 // no revisions and no limit |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
49 hgRepo.getChangelog().all(dump); |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
50 } else { |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
51 // in fact, external (to dump inspector) --limit processing yelds incorrect results when other args |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
52 // e.g. -u or -b are used (i.e. with -u shall give <limit> csets with user, not check last <limit> csets for user |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
53 int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() }; |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
54 if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) { |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
55 System.out.println("No changes"); |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
56 return; |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
57 } |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
58 hgRepo.getChangelog().range(r[0], r[1], dump); |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
59 } |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
60 dump.complete(); |
6
5abe5af181bd
Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
61 } else { |
5abe5af181bd
Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
62 for (String fname : cmdLineOpts.files) { |
5abe5af181bd
Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
63 HgDataFile f1 = hgRepo.getFileNode(fname); |
8
a78c980749e3
Filename mangling according to requires options of the store (fncache incomplete for long names)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
64 System.out.println("History of the file: " + f1.getPath()); |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
65 if (cmdLineOpts.limit == -1) { |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
66 f1.history(dump); |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
67 } else { |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
68 int[] r = new int[] { 0, f1.getRevisionCount() }; |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
69 if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) { |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
70 System.out.println("No changes"); |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
71 continue; |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
72 } |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
73 f1.history(r[0], r[1], dump); |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
74 } |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
75 dump.complete(); |
6
5abe5af181bd
Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
76 } |
5abe5af181bd
Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
77 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
1
diff
changeset
|
78 // |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
79 // XXX new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor); |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 } |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
81 |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
82 private static int fixRange(int[] start_end, boolean reverse, int limit) { |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
83 assert start_end.length == 2; |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
84 if (limit < start_end[1]) { |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
85 if (reverse) { |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
86 // adjust left boundary of the range |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
87 start_end[0] = start_end[1] - limit; |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
88 } else { |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
89 start_end[1] = limit; // adjust right boundary |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
90 } |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
91 } |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
92 int rv = start_end[1] - start_end[0]; |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
93 start_end[1]--; // range needs index, not length |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
94 return rv; |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
95 } |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
96 |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
97 // Differences with standard hg log output |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
98 // - complete == true (--debug) files are not broke down to modified,+ and - |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
99 private static final class Dump implements Changeset.Inspector { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
100 // params |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
101 boolean complete = false; // roughly --debug |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
102 boolean reverseOrder = false; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
103 Set<String> branches; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
104 Set<String> users; // shall be lowercased |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
105 boolean verbose = true; // roughly -v |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
106 // own |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
107 private LinkedList<String> l = new LinkedList<String>(); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
108 private final HgRepository repo; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
109 private Revlog.ParentWalker changelogWalker; |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
110 private final int tip ; |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
111 private StatusCollector statusHelper; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
112 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
113 public Dump(HgRepository hgRepo) { |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
114 repo = hgRepo; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
115 tip = hgRepo.getChangelog().getRevisionCount() - 1; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
116 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
117 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
118 public void next(int revisionNumber, Nodeid nodeid, Changeset cset) { |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
119 if (branches != null && !branches.contains(cset.branch())) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
120 return; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
121 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
122 if (users != null) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
123 String csetUser = cset.user().toLowerCase(); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
124 boolean found = false; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
125 for (String u : users) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
126 if (csetUser.indexOf(u) != -1) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
127 found = true; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
128 break; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
129 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
130 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
131 if (!found) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
132 return; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
133 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
134 } |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
135 final String s = print(revisionNumber, nodeid, cset); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
136 if (reverseOrder) { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
137 l.addFirst(s); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
138 } else { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
139 System.out.print(s); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
140 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
141 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
142 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
143 public void complete() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
144 if (!reverseOrder) { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
145 return; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
146 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
147 for (String s : l) { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
148 System.out.print(s); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
149 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
150 l.clear(); |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
151 changelogWalker = null; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
152 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
153 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
154 private String print(int revNumber, Nodeid csetNodeid, Changeset cset) { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
155 StringBuilder sb = new StringBuilder(); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
156 Formatter f = new Formatter(sb); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
157 f.format("changeset: %d:%s\n", revNumber, complete ? csetNodeid : csetNodeid.shortNotation()); |
50
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
158 if (revNumber == tip || repo.getTags().isTagged(csetNodeid)) { |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
159 |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
160 sb.append("tag: "); |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
161 for (String t : repo.getTags().tags(csetNodeid)) { |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
162 sb.append(t); |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
163 sb.append(' '); |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
164 } |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
165 if (revNumber == tip) { |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
166 sb.append("tip"); |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
167 } |
f1db8610da62
Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
168 sb.append('\n'); |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
169 } |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
170 if (complete) { |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
171 if (changelogWalker == null) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
172 changelogWalker = repo.getChangelog().new ParentWalker(); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
173 changelogWalker.init(); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
174 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
175 Nodeid p1 = changelogWalker.safeFirstParent(csetNodeid); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
176 Nodeid p2 = changelogWalker.safeSecondParent(csetNodeid); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
177 int p1x = p1 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevisionNumber(p1); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
178 int p2x = p2 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevisionNumber(p2); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
179 int mx = repo.getManifest().getLocalRevisionNumber(cset.manifest()); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
180 f.format("parent: %d:%s\nparent: %d:%s\nmanifest: %d:%s\n", p1x, p1, p2x, p2, mx, cset.manifest()); |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
181 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
182 f.format("user: %s\ndate: %s\n", cset.user(), cset.dateString()); |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
183 if (!complete && verbose) { |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
184 final List<String> files = cset.files(); |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
185 sb.append("files: "); |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
186 for (String s : files) { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
187 sb.append(' '); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
188 sb.append(s); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
189 } |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
190 sb.append('\n'); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
191 } |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
192 if (complete) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
193 if (statusHelper == null) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
194 statusHelper = new StatusCollector(repo); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
195 } |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
196 StatusCollector.Record r = new StatusCollector.Record(); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
197 statusHelper.change(revNumber, r); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
198 if (!r.getModified().isEmpty()) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
199 sb.append("files: "); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
200 for (String s : r.getModified()) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
201 sb.append(' '); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
202 sb.append(s); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
203 } |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
204 sb.append('\n'); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
205 } |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
206 if (!r.getAdded().isEmpty()) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
207 sb.append("files+: "); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
208 for (String s : r.getAdded()) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
209 sb.append(' '); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
210 sb.append(s); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
211 } |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
212 sb.append('\n'); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
213 } |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
214 if (!r.getRemoved().isEmpty()) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
215 sb.append("files-: "); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
216 for (String s : r.getRemoved()) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
217 sb.append(' '); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
218 sb.append(s); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
219 } |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
220 sb.append('\n'); |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
221 } |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
222 if (cset.extras() != null) { |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
223 sb.append("extra: "); |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
224 for (Map.Entry<String, String> e : cset.extras().entrySet()) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
225 sb.append(' '); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
226 sb.append(e.getKey()); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
227 sb.append('='); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
228 sb.append(e.getValue()); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
229 } |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
230 sb.append('\n'); |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
231 } |
60
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
232 } |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
233 if (complete || verbose) { |
613c936d74e4
Log operation to output mode detailed (added, removed) files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
50
diff
changeset
|
234 f.format("description:\n%s\n\n", cset.comment()); |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
235 } else { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
236 f.format("summary: %s\n\n", cset.comment()); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
237 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
238 return sb.toString(); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
239 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
8
diff
changeset
|
240 } |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
241 } |