Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/HgChangelog.java @ 423:9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 23 Mar 2012 22:51:18 +0100 |
parents | 7f136a3fa671 |
children | 6437d261048a |
rev | line source |
---|---|
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
1 /* |
418
528b6780a8bd
A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
2 * Copyright (c) 2010-2012 TMate Software Ltd |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
13 * For information on how to redistribute this software under |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
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:
97
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
157
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
19 import java.io.IOException; |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
20 import java.io.UnsupportedEncodingException; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
21 import java.util.ArrayList; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
22 import java.util.Arrays; |
146
8c9f729f4dfa
Timezone finally in use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
137
diff
changeset
|
23 import java.util.Calendar; |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
24 import java.util.Collection; |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
25 import java.util.Collections; |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
26 import java.util.Date; |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
27 import java.util.Formatter; |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
28 import java.util.HashMap; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
29 import java.util.List; |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
30 import java.util.Locale; |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
31 import java.util.Map; |
146
8c9f729f4dfa
Timezone finally in use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
137
diff
changeset
|
32 import java.util.TimeZone; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
33 |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
34 import org.tmatesoft.hg.core.HgBadArgumentException; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
35 import org.tmatesoft.hg.core.Nodeid; |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
36 import org.tmatesoft.hg.internal.Callback; |
157
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
37 import org.tmatesoft.hg.internal.DataAccess; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
38 import org.tmatesoft.hg.internal.IterateControlMediator; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
39 import org.tmatesoft.hg.internal.Lifecycle; |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
40 import org.tmatesoft.hg.internal.Pool; |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
41 import org.tmatesoft.hg.internal.RevlogStream; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
42 import org.tmatesoft.hg.util.CancelSupport; |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
43 import org.tmatesoft.hg.util.Pair; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
44 import org.tmatesoft.hg.util.ProgressSupport; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
45 |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 /** |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 * Representation of the Mercurial changelog file (list of ChangeSets) |
153 | 48 * |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
49 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
50 * @author TMate Software Ltd. |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 */ |
97
ee2c750b036d
Changelog to HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
52 public class HgChangelog extends Revlog { |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 |
153 | 54 /* package-local */HgChangelog(HgRepository hgRepo, RevlogStream content) { |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
55 super(hgRepo, content); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
56 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
57 |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
58 public void all(final HgChangelog.Inspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { |
137
144d771ee73c
explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
135
diff
changeset
|
59 range(0, getLastRevision(), inspector); |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
60 } |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
61 |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
62 public void range(int start, int end, final HgChangelog.Inspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
63 if (inspector == null) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
64 throw new IllegalArgumentException(); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
65 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
66 content.iterate(start, end, true, new RawCsetParser(inspector)); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
67 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
68 |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
69 public List<RawChangeset> range(int start, int end) throws HgInvalidRevisionException, HgInvalidControlFileException { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
70 final RawCsetCollector c = new RawCsetCollector(end - start + 1); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
71 range(start, end, c); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
72 return c.result; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
73 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
74 |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
75 /** |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
76 * Access individual revisions. Note, regardless of supplied revision order, inspector gets |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
77 * changesets strictly in the order they are in the changelog. |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
78 * @param inspector callback to get changesets |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
79 * @param revisions revisions to read, unrestricted ordering. |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
80 */ |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
81 public void range(final HgChangelog.Inspector inspector, final int... revisions) throws HgInvalidRevisionException, HgInvalidControlFileException { |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
82 Arrays.sort(revisions); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
83 rangeInternal(inspector, revisions); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
84 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
85 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
86 /** |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
87 * Friends-only version of {@link #range(Inspector, int...)}, when callers know array is sorted |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
88 */ |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
89 /*package-local*/ void rangeInternal(HgChangelog.Inspector inspector, int[] sortedRevisions) throws HgInvalidRevisionException, HgInvalidControlFileException { |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
90 if (sortedRevisions == null || sortedRevisions.length == 0) { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
91 return; |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
92 } |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
93 if (inspector == null) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
94 throw new IllegalArgumentException(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
95 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
96 content.iterate(sortedRevisions, true, new RawCsetParser(inspector)); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
97 } |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
98 |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
99 /** |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
100 * @throws HgInvalidRevisionException if supplied nodeid doesn't identify any revision from this revlog |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
101 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
102 */ |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
103 public RawChangeset changeset(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
104 int x = getRevisionIndex(nid); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
211
diff
changeset
|
105 return range(x, x).get(0); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
211
diff
changeset
|
106 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
107 |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
108 @Callback |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
109 public interface Inspector { |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
110 /** |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
111 * Access next changeset |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
112 * TODO describe what revisionNumber is when Inspector is used with HgBundle (BAD_REVISION or bundle's local order?) |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
113 * |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
114 * @param revisionIndex index of revision being inspected, local to the inspected object |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
115 * @param nodeid revision being inspected |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
116 * @param cset changeset raw data |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
117 */ |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
118 void next(int revisionIndex, Nodeid nodeid, RawChangeset cset); |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
119 } |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
120 |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
121 /** |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
122 * Unlike regular {@link Inspector}, this one supplies changeset revision along with its parents and children according |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
123 * to parent information of the revlog this inspector visits. |
419
7f136a3fa671
Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
124 * @see HgDataFile#history(HgChangelog.TreeInspector) |
7f136a3fa671
Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
125 * @deprecated use {@link org.tmatesoft.hg.core.HgChangesetTreeHandler} and HgLogCommand#execute(org.tmatesoft.hg.core.HgChangesetTreeHandler)} |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
126 */ |
328
a674b8590362
Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
317
diff
changeset
|
127 @Deprecated |
317
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
128 public interface TreeInspector { |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
129 // the reason TreeInsector is in HgChangelog, not in Revlog, because despite the fact it can |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
130 // be applied to any revlog, it's not meant to provide revisions of any revlog it's beeing applied to, |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
131 // but changeset revisions always. |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
132 // TODO HgChangelog.walk(TreeInspector) |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
133 void next(Nodeid changesetRevision, Pair<Nodeid, Nodeid> parentChangesets, Collection<Nodeid> childChangesets); |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
134 } |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
135 |
09628675bcee
Rework file history build approach to match rest of the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
136 /** |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
137 * Entry in the Changelog |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
138 */ |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
139 public static class RawChangeset implements Cloneable /* for those that would like to keep a copy */{ |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
140 // TODO immutable |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
141 private/* final */Nodeid manifest; |
153 | 142 private String user; |
143 private String comment; | |
144 private List<String> files; // unmodifiable collection (otherwise #files() and implicit #clone() shall be revised) | |
145 private Date time; | |
146 private int timezone; | |
161
9423235ca77b
Record possible value (and knowledge source) for extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
147 // http://mercurial.selenic.com/wiki/PruningDeadBranches - Closing changesets can be identified by close=1 in the changeset's extra field. |
153 | 148 private Map<String, String> extras; |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
149 |
153 | 150 /** |
151 * @see mercurial/changelog.py:read() | |
152 * | |
153 * <pre> | |
154 * format used: | |
155 * nodeid\n : manifest node in ascii | |
156 * user\n : user, no \n or \r allowed | |
157 * time tz extra\n : date (time is int or float, timezone is int) | |
158 * : extra is metadatas, encoded and separated by '\0' | |
159 * : older versions ignore it | |
160 * files\n\n : files modified by the cset, no \n or \r allowed | |
161 * (.*) : comment (free text, ideally utf-8) | |
162 * | |
163 * changelog v0 doesn't use extra | |
164 * </pre> | |
165 */ | |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
166 private RawChangeset() { |
153 | 167 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
168 |
153 | 169 public Nodeid manifest() { |
170 return manifest; | |
171 } | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
172 |
153 | 173 public String user() { |
174 return user; | |
175 } | |
176 | |
177 public String comment() { | |
178 return comment; | |
179 } | |
180 | |
181 public List<String> files() { | |
182 return files; | |
183 } | |
184 | |
185 public Date date() { | |
186 return time; | |
187 } | |
211
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
188 |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
189 /** |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
190 * @return time zone value, as is, positive for Western Hemisphere. |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
191 */ |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
192 public int timezone() { |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
193 return timezone; |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
194 } |
153 | 195 |
196 public String dateString() { | |
197 // XXX keep once formatted? Perhaps, there's faster way to set up calendar/time zone? | |
198 StringBuilder sb = new StringBuilder(30); | |
199 Formatter f = new Formatter(sb, Locale.US); | |
211
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
200 TimeZone tz = TimeZone.getTimeZone(TimeZone.getAvailableIDs(timezone * 1000)[0]); |
153 | 201 // apparently timezone field records number of seconds time differs from UTC, |
202 // i.e. value to substract from time to get UTC time. Calendar seems to add | |
203 // timezone offset to UTC, instead, hence sign change. | |
211
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
204 // tz.setRawOffset(timezone * -1000); |
153 | 205 Calendar c = Calendar.getInstance(tz, Locale.US); |
206 c.setTime(time); | |
207 f.format("%ta %<tb %<td %<tH:%<tM:%<tS %<tY %<tz", c); | |
208 return sb.toString(); | |
209 } | |
210 | |
211 public Map<String, String> extras() { | |
212 return extras; | |
213 } | |
214 | |
215 public String branch() { | |
216 return extras.get("branch"); | |
217 } | |
218 | |
219 @Override | |
220 public String toString() { | |
221 StringBuilder sb = new StringBuilder(); | |
222 sb.append("Changeset {"); | |
223 sb.append("User: ").append(user).append(", "); | |
224 sb.append("Comment: ").append(comment).append(", "); | |
225 sb.append("Manifest: ").append(manifest).append(", "); | |
226 sb.append("Date: ").append(time).append(", "); | |
227 sb.append("Files: ").append(files.size()); | |
228 for (String s : files) { | |
229 sb.append(", ").append(s); | |
230 } | |
231 if (extras != null) { | |
232 sb.append(", Extra: ").append(extras); | |
233 } | |
234 sb.append("}"); | |
235 return sb.toString(); | |
236 } | |
237 | |
238 @Override | |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
239 public RawChangeset clone() { |
153 | 240 try { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
241 return (RawChangeset) super.clone(); |
153 | 242 } catch (CloneNotSupportedException ex) { |
243 throw new InternalError(ex.toString()); | |
244 } | |
245 } | |
246 | |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
247 /*package*/ static RawChangeset parse(DataAccess da) throws IOException, HgBadArgumentException { |
365
3572fcb06473
Don't expose methods with DataAccess in public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
363
diff
changeset
|
248 byte[] data = da.byteArray(); |
3572fcb06473
Don't expose methods with DataAccess in public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
363
diff
changeset
|
249 RawChangeset rv = new RawChangeset(); |
3572fcb06473
Don't expose methods with DataAccess in public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
363
diff
changeset
|
250 rv.init(data, 0, data.length, null); |
3572fcb06473
Don't expose methods with DataAccess in public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
363
diff
changeset
|
251 return rv; |
153 | 252 } |
253 | |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
254 // @param usersPool - it's likely user names get repeated again and again throughout repository. can be null |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
255 // FIXME replace HgBadArgumentException with HgInvalidDataFormatException or HgInvalidControlFileException |
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
256 /* package-local */void init(byte[] data, int offset, int length, Pool<String> usersPool) throws HgBadArgumentException { |
153 | 257 final int bufferEndIndex = offset + length; |
258 final byte lineBreak = (byte) '\n'; | |
259 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex); | |
260 if (breakIndex1 == -1) { | |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
261 throw new HgBadArgumentException("Bad Changeset data", null); |
153 | 262 } |
263 Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1); | |
264 int breakIndex2 = indexOf(data, lineBreak, breakIndex1 + 1, bufferEndIndex); | |
265 if (breakIndex2 == -1) { | |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
266 throw new HgBadArgumentException("Bad Changeset data", null); |
153 | 267 } |
268 String _user = new String(data, breakIndex1 + 1, breakIndex2 - breakIndex1 - 1); | |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
269 if (usersPool != null) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
270 _user = usersPool.unify(_user); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
271 } |
153 | 272 int breakIndex3 = indexOf(data, lineBreak, breakIndex2 + 1, bufferEndIndex); |
273 if (breakIndex3 == -1) { | |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
274 throw new HgBadArgumentException("Bad Changeset data", null); |
153 | 275 } |
276 String _timeString = new String(data, breakIndex2 + 1, breakIndex3 - breakIndex2 - 1); | |
277 int space1 = _timeString.indexOf(' '); | |
278 if (space1 == -1) { | |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
279 throw new HgBadArgumentException(String.format("Bad Changeset data: %s in [%d..%d]", "time string", breakIndex2+1, breakIndex3), null); |
153 | 280 } |
281 int space2 = _timeString.indexOf(' ', space1 + 1); | |
282 if (space2 == -1) { | |
283 space2 = _timeString.length(); | |
284 } | |
363
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
285 long unixTime = Long.parseLong(_timeString.substring(0, space1)); |
153 | 286 int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2)); |
363
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
287 // unixTime is local time, and timezone records difference of the local time to UTC. |
153 | 288 Date _time = new Date(unixTime * 1000); |
289 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null; | |
290 Map<String, String> _extrasMap; | |
252
a6d19adc2636
HgRepository.getWorkingCopyBranchName() to retrieve branch associated with working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
242
diff
changeset
|
291 final String extras_branch_key = "branch"; |
386
73e875154afb
Do not fail with empty extras string in changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
292 if (_extras == null || _extras.trim().length() == 0) { |
252
a6d19adc2636
HgRepository.getWorkingCopyBranchName() to retrieve branch associated with working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
242
diff
changeset
|
293 _extrasMap = Collections.singletonMap(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME); |
153 | 294 } else { |
295 _extrasMap = new HashMap<String, String>(); | |
296 for (String pair : _extras.split("\00")) { | |
363
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
297 pair = decode(pair); |
153 | 298 int eq = pair.indexOf(':'); |
299 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1)); | |
300 } | |
252
a6d19adc2636
HgRepository.getWorkingCopyBranchName() to retrieve branch associated with working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
242
diff
changeset
|
301 if (!_extrasMap.containsKey(extras_branch_key)) { |
a6d19adc2636
HgRepository.getWorkingCopyBranchName() to retrieve branch associated with working directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
242
diff
changeset
|
302 _extrasMap.put(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME); |
153 | 303 } |
304 _extrasMap = Collections.unmodifiableMap(_extrasMap); | |
305 } | |
306 | |
307 // | |
308 int lastStart = breakIndex3 + 1; | |
309 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); | |
310 ArrayList<String> _files = null; | |
311 if (breakIndex4 > lastStart) { | |
312 // if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision) | |
313 _files = new ArrayList<String>(5); | |
314 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) { | |
315 _files.add(new String(data, lastStart, breakIndex4 - lastStart)); | |
316 lastStart = breakIndex4 + 1; | |
317 if (data[breakIndex4 + 1] == lineBreak) { | |
318 // found \n\n | |
319 break; | |
320 } else { | |
321 breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
322 } |
153 | 323 } |
324 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) { | |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
325 throw new HgBadArgumentException("Bad Changeset data", null); |
153 | 326 } |
327 } else { | |
328 breakIndex4--; | |
329 } | |
330 String _comment; | |
331 try { | |
332 _comment = new String(data, breakIndex4 + 2, bufferEndIndex - breakIndex4 - 2, "UTF-8"); | |
418
528b6780a8bd
A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
333 // TODO post-1.0 respect ui.fallbackencoding and try to decode if set; use EncodingHelper |
153 | 334 } catch (UnsupportedEncodingException ex) { |
335 _comment = ""; | |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
336 // Could hardly happen |
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
337 throw new HgBadArgumentException("Bad Changeset data", ex); |
153 | 338 } |
339 // change this instance at once, don't leave it partially changes in case of error | |
340 this.manifest = _nodeid; | |
341 this.user = _user; | |
342 this.time = _time; | |
343 this.timezone = _timezone; | |
344 this.files = _files == null ? Collections.<String> emptyList() : Collections.unmodifiableList(_files); | |
345 this.comment = _comment; | |
346 this.extras = _extrasMap; | |
347 } | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
348 |
153 | 349 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) { |
350 for (int i = startOffset; i < endIndex; i++) { | |
351 if (src[i] == what) { | |
352 return i; | |
353 } | |
354 } | |
355 return -1; | |
356 } | |
363
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
357 |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
358 private static String decode(String s) { |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
359 if (s != null && s.indexOf('\\') != -1) { |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
360 // TestAuxUtilities#testChangelogExtrasDecode |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
361 return s.replace("\\\\", "\\").replace("\\n", "\n").replace("\\r", "\r").replace("\\0", "\00"); |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
362 } |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
363 return s; |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
364 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
365 } |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
366 |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
367 private static class RawCsetCollector implements Inspector { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
368 final ArrayList<RawChangeset> result; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
369 |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
370 public RawCsetCollector(int count) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
371 result = new ArrayList<RawChangeset>(count > 0 ? count : 5); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
372 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
373 |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
374 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
375 result.add(cset.clone()); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
376 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
377 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
378 |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
379 private static class RawCsetParser implements RevlogStream.Inspector, Lifecycle { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
380 |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
381 private final Inspector inspector; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
382 private final Pool<String> usersPool; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
383 private final RawChangeset cset = new RawChangeset(); |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
384 private final ProgressSupport progressHelper; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
385 private IterateControlMediator iterateControl; |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
386 |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
387 public RawCsetParser(HgChangelog.Inspector delegate) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
388 assert delegate != null; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
389 inspector = delegate; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
390 usersPool = new Pool<String>(); |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
391 progressHelper = ProgressSupport.Factory.get(delegate); |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
392 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
393 |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
394 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
395 try { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
396 byte[] data = da.byteArray(); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
397 cset.init(data, 0, data.length, usersPool); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
398 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
399 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
400 progressHelper.worked(1); |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
401 } catch (HgBadArgumentException ex) { |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
402 // see below about better exception |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
403 throw new HgInvalidControlFileException("Failed reading changelog", ex, null).setRevisionIndex(revisionNumber); |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
404 } catch (IOException ex) { |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
405 // XXX need better exception, perhaps smth like HgChangelogException (extends HgInvalidControlFileException) |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
419
diff
changeset
|
406 throw new HgInvalidControlFileException("Failed reading changelog", ex, null).setRevisionIndex(revisionNumber); |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
407 } |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
408 if (iterateControl != null) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
409 iterateControl.checkCancelled(); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
410 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
411 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
412 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
413 public void start(int count, Callback callback, Object token) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
414 CancelSupport cs = CancelSupport.Factory.get(inspector, null); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
415 iterateControl = cs == null ? null : new IterateControlMediator(cs, callback); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
416 progressHelper.start(count); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
417 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
418 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
419 public void finish(Object token) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
420 progressHelper.done(); |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
421 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
422 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
423 } |