annotate src/com/tmate/hgkit/console/Log.java @ 56:576d6e8a09f6

Analog of 'hg status --change' command
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 17 Jan 2011 05:15:13 +0100
parents f1db8610da62
children 613c936d74e4
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;
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19
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 * @author artem
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 */
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 public class Log {
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 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
26 RepositoryLookup repoLookup = new RepositoryLookup();
4
aa1912c70b36 Fix offset issue for inline revlogs. Commandline processing.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
27 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
28 HgRepository hgRepo = repoLookup.detect(cmdLineOpts);
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 if (hgRepo.isInvalid()) {
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 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
31 return;
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 }
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 System.out.println(hgRepo.getLocation());
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
34 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
35 dump.complete = true; //cmdLineOpts;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
36 dump.reverseOrder = true;
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
37 dump.branches = cmdLineOpts.branches;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
38 if (cmdLineOpts.users != null) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
39 dump.users = new LinkedHashSet<String>();
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
40 for (String u : cmdLineOpts.users) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
41 dump.users.add(u.toLowerCase());
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
42 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
43 }
6
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
44 if (cmdLineOpts.files.isEmpty()) {
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
45 if (cmdLineOpts.limit == -1) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
46 // no revisions and no limit
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
47 hgRepo.getChangelog().all(dump);
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
48 } else {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
49 // 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
50 // 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
51 int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() };
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
52 if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
53 System.out.println("No changes");
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
54 return;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
55 }
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
56 hgRepo.getChangelog().range(r[0], r[1], dump);
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
57 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
58 dump.complete();
6
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
59 } else {
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
60 for (String fname : cmdLineOpts.files) {
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
61 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
62 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
63 if (cmdLineOpts.limit == -1) {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
64 f1.history(dump);
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
65 } else {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
66 int[] r = new int[] { 0, f1.getRevisionCount() };
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
67 if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
68 System.out.println("No changes");
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
69 continue;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
70 }
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
71 f1.history(r[0], r[1], dump);
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
72 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
73 dump.complete();
6
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
74 }
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
75 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
76 //
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
77 // 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
78 }
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
79
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
80 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
81 assert start_end.length == 2;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
82 if (limit < start_end[1]) {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
83 if (reverse) {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
84 // adjust left boundary of the range
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
85 start_end[0] = start_end[1] - limit;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
86 } else {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
87 start_end[1] = limit; // adjust right boundary
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
88 }
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
89 }
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
90 int rv = start_end[1] - start_end[0];
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
91 start_end[1]--; // range needs index, not length
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
92 return rv;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
93 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
94
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
95 // Differences with standard hg log output
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
96 // - 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
97 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
98 // params
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
99 boolean complete = false;
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
100 boolean reverseOrder = false;
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
101 Set<String> branches;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
102 Set<String> users; // shall be lowercased
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
103 // own
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
104 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
105 private final HgRepository repo;
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
106 private Revlog.ParentWalker changelogWalker;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
107 private final int tip ;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
108
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
109 public Dump(HgRepository hgRepo) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
110 repo = hgRepo;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
111 tip = hgRepo.getChangelog().getRevisionCount() - 1;
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
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
114 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
115 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
116 return;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
117 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
118 if (users != null) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
119 String csetUser = cset.user().toLowerCase();
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
120 boolean found = false;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
121 for (String u : users) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
122 if (csetUser.indexOf(u) != -1) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
123 found = true;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
124 break;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
125 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
126 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
127 if (!found) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
128 return;
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 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
131 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
132 if (reverseOrder) {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
133 l.addFirst(s);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
134 } else {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
135 System.out.print(s);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
136 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
137 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
138
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
139 public void complete() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
140 if (!reverseOrder) {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
141 return;
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 for (String s : l) {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
144 System.out.print(s);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
145 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
146 l.clear();
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
147 changelogWalker = null;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
148 }
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 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
151 StringBuilder sb = new StringBuilder();
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
152 Formatter f = new Formatter(sb);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
153 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
154 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
155
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
156 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
157 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
158 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
159 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
160 }
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
161 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
162 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
163 }
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
164 sb.append('\n');
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
165 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
166 if (complete) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
167 if (changelogWalker == null) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
168 changelogWalker = repo.getChangelog().new ParentWalker();
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
169 changelogWalker.init();
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
170 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
171 Nodeid p1 = changelogWalker.safeFirstParent(csetNodeid);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
172 Nodeid p2 = changelogWalker.safeSecondParent(csetNodeid);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
173 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
174 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
175 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
176 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
177 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
178 f.format("user: %s\ndate: %s\n", cset.user(), cset.dateString());
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
179 if (complete) {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
180 final List<String> files = cset.files();
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
181 sb.append("files: ");
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
182 for (String s : files) {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
183 sb.append(' ');
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
184 sb.append(s);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
185 }
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
186 if (cset.extras() != null) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
187 sb.append("\nextra: ");
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
188 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
189 sb.append(' ');
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
190 sb.append(e.getKey());
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
191 sb.append('=');
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
192 sb.append(e.getValue());
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
193 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
194 }
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
195 f.format("\ndescription:\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
196 } else {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
197 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
198 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
199 return sb.toString();
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
200 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
201 }
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 }