annotate test/org/tmatesoft/hg/test/ManifestOutputParser.java @ 656:a937e63b6e02

Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 04 Jul 2013 18:40:03 +0200
parents 4a948ec83980
children
rev   line source
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
15 * contact TMate Software at support@hg4j.com
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.util.LinkedHashMap;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.util.Map;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.util.regex.Matcher;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.regex.Pattern;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 70
diff changeset
24 import org.tmatesoft.hg.core.Nodeid;
133
4a948ec83980 core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
25 import org.tmatesoft.hg.util.Path;
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 /**
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 *
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 * @author Artem Tikhomirov
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 * @author TMate Software Ltd.
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 */
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 public class ManifestOutputParser implements OutputParser {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 private final Pattern pattern;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 private final LinkedHashMap<Path, Nodeid> result = new LinkedHashMap<Path, Nodeid>();
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 public ManifestOutputParser() {
70
993f6f8e1314 Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 67
diff changeset
39 pattern = Pattern.compile("^([a-f0-9]{40}) (\\d{3}) (.+)$", Pattern.MULTILINE);
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 public void reset() {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 result.clear();
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 public Map<Path, Nodeid> getResult() {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 return result;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public void parse(CharSequence seq) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 Matcher m = pattern.matcher(seq);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 while (m.find()) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 result.put(Path.create(m.group(3)), Nodeid.fromAscii(m.group(1).getBytes(), 0, 40));
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 }