Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/HgChangelog.java @ 668:d25f0324a27a
Delete bundle with push/pull changes once command completes successfully. Test for bundle generator
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 11 Jul 2013 18:41:40 +0200 |
parents | fba85bc1dfb8 |
children | 545b1d4cc11d |
rev | line source |
---|---|
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
1 /* |
589
c18095eedde0
Username in changeset uses UTF-8, not system encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
520
diff
changeset
|
2 * Copyright (c) 2010-2013 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; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
20 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
|
21 import java.util.Arrays; |
146
8c9f729f4dfa
Timezone finally in use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
137
diff
changeset
|
22 import java.util.Calendar; |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
23 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
|
24 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
|
25 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
|
26 import java.util.HashMap; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
27 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
|
28 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
|
29 import java.util.Map; |
146
8c9f729f4dfa
Timezone finally in use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
137
diff
changeset
|
30 import java.util.TimeZone; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
31 |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
32 import org.tmatesoft.hg.core.Nodeid; |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
33 import org.tmatesoft.hg.core.SessionContext; |
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
|
34 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
|
35 import org.tmatesoft.hg.internal.DataAccess; |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
36 import org.tmatesoft.hg.internal.EncodingHelper; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
37 import org.tmatesoft.hg.internal.Internals; |
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.Lifecycle; |
520
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
39 import org.tmatesoft.hg.internal.LifecycleBridge; |
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; |
520
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
42 import org.tmatesoft.hg.util.Adaptable; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
43 import org.tmatesoft.hg.util.CancelSupport; |
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 */ |
426
063b0663495a
HgManifest#getFileRevisions refactored into #walkFileRevisions to match pattern throught rest of the library
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
424
diff
changeset
|
52 public final 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) { |
600
46f29b73e51e
Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
589
diff
changeset
|
55 super(hgRepo, content, true); |
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 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
58 /** |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
59 * Iterate over whole changelog |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
60 * @param inspector callback to process entries |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
61 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
62 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
63 */ |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
64 public void all(final HgChangelog.Inspector inspector) throws HgRuntimeException { |
137
144d771ee73c
explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
135
diff
changeset
|
65 range(0, getLastRevision(), inspector); |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
66 } |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
67 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
68 /** |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
69 * Iterate over changelog part |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
70 * @param start first changelog entry to process |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
71 * @param end last changelog entry to process |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
72 * @param inspector callback to process entries |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
73 * @throws HgInvalidRevisionException if any supplied revision doesn't identify revision from this revlog. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
74 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
75 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
76 */ |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
77 public void range(int start, int end, final HgChangelog.Inspector inspector) throws HgRuntimeException { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
78 if (inspector == null) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
79 throw new IllegalArgumentException(); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
80 } |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
81 content.iterate(start, end, true, new RawCsetParser(getRepo(), inspector)); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
82 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
83 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
84 /** |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
85 * @see #range(int, int, Inspector) |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
86 * @return changeset entry objects, never <code>null</code> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
87 * @throws HgInvalidRevisionException if any supplied revision doesn't identify revision from this revlog. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
88 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
89 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
90 */ |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
91 public List<RawChangeset> range(int start, int end) throws HgRuntimeException { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
92 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
|
93 range(start, end, c); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
94 return c.result; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
95 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
96 |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
97 /** |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
98 * 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
|
99 * 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
|
100 * @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
|
101 * @param revisions revisions to read, unrestricted ordering. |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
102 * @throws HgInvalidRevisionException if any supplied revision doesn't identify revision from this revlog <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
103 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
104 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em> |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
105 */ |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
106 public void range(final HgChangelog.Inspector inspector, final int... revisions) throws HgRuntimeException { |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
107 Arrays.sort(revisions); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
108 rangeInternal(inspector, revisions); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
109 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
110 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
111 /** |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
112 * 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
|
113 */ |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
114 /*package-local*/ void rangeInternal(HgChangelog.Inspector inspector, int[] sortedRevisions) throws HgRuntimeException { |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
115 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
|
116 return; |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
117 } |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
118 if (inspector == null) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
119 throw new IllegalArgumentException(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
120 } |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
121 content.iterate(sortedRevisions, true, new RawCsetParser(getRepo(), inspector)); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
122 } |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
123 |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
124 /** |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
125 * Get changeset entry object |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
126 * @throws HgInvalidRevisionException if supplied nodeid doesn't identify any revision from this revlog. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
127 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
128 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em> |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
329
diff
changeset
|
129 */ |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
130 public RawChangeset changeset(Nodeid nid) throws HgRuntimeException { |
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
|
131 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
|
132 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
|
133 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
134 |
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
|
135 @Callback |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
136 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
|
137 /** |
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
|
138 * 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
|
139 * 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
|
140 * |
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
|
141 * @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
|
142 * @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
|
143 * @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
|
144 */ |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
145 void next(int revisionIndex, Nodeid nodeid, RawChangeset cset) throws HgRuntimeException; |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
146 } |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
147 |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
148 /** |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
149 * 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
|
150 */ |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
151 public static final class RawChangeset implements Cloneable /* for those that would like to keep a copy */{ |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
152 // would be nice to get it immutable, but then we can't reuse instances |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
153 private/* final */Nodeid manifest; |
153 | 154 private String user; |
155 private String comment; | |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
156 private String[] files; // shall not be modified (#clone() does shallow copy) |
153 | 157 private Date time; |
158 private int timezone; | |
161
9423235ca77b
Record possible value (and knowledge source) for extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
159 // http://mercurial.selenic.com/wiki/PruningDeadBranches - Closing changesets can be identified by close=1 in the changeset's extra field. |
153 | 160 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
|
161 |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
162 private RawChangeset() { |
153 | 163 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
164 |
153 | 165 public Nodeid manifest() { |
166 return manifest; | |
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 String user() { |
170 return user; | |
171 } | |
172 | |
173 public String comment() { | |
174 return comment; | |
175 } | |
176 | |
177 public List<String> files() { | |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
178 return Arrays.asList(files); |
153 | 179 } |
180 | |
181 public Date date() { | |
182 return time; | |
183 } | |
211
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
184 |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
185 /** |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
186 * @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
|
187 */ |
644ee58c9f16
Compound HgDate object to provide flexible access to change date/time information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
188 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
|
189 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
|
190 } |
153 | 191 |
192 public String dateString() { | |
193 // XXX keep once formatted? Perhaps, there's faster way to set up calendar/time zone? | |
194 StringBuilder sb = new StringBuilder(30); | |
195 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
|
196 TimeZone tz = TimeZone.getTimeZone(TimeZone.getAvailableIDs(timezone * 1000)[0]); |
153 | 197 // apparently timezone field records number of seconds time differs from UTC, |
198 // i.e. value to substract from time to get UTC time. Calendar seems to add | |
199 // 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
|
200 // tz.setRawOffset(timezone * -1000); |
153 | 201 Calendar c = Calendar.getInstance(tz, Locale.US); |
202 c.setTime(time); | |
203 f.format("%ta %<tb %<td %<tH:%<tM:%<tS %<tY %<tz", c); | |
204 return sb.toString(); | |
205 } | |
206 | |
207 public Map<String, String> extras() { | |
208 return extras; | |
209 } | |
210 | |
211 public String branch() { | |
212 return extras.get("branch"); | |
213 } | |
214 | |
215 @Override | |
216 public String toString() { | |
217 StringBuilder sb = new StringBuilder(); | |
218 sb.append("Changeset {"); | |
219 sb.append("User: ").append(user).append(", "); | |
220 sb.append("Comment: ").append(comment).append(", "); | |
221 sb.append("Manifest: ").append(manifest).append(", "); | |
222 sb.append("Date: ").append(time).append(", "); | |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
223 sb.append("Files: ").append(files.length); |
153 | 224 for (String s : files) { |
225 sb.append(", ").append(s); | |
226 } | |
227 if (extras != null) { | |
228 sb.append(", Extra: ").append(extras); | |
229 } | |
230 sb.append("}"); | |
231 return sb.toString(); | |
232 } | |
233 | |
234 @Override | |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
235 public RawChangeset clone() { |
153 | 236 try { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
237 return (RawChangeset) super.clone(); |
153 | 238 } catch (CloneNotSupportedException ex) { |
239 throw new InternalError(ex.toString()); | |
240 } | |
241 } | |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
242 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
243 |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
244 /** |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
245 * @see mercurial/changelog.py:read() |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
246 * |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
247 * <pre> |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
248 * format used: |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
249 * nodeid\n : manifest node in ascii |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
250 * user\n : user, no \n or \r allowed |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
251 * time tz extra\n : date (time is int or float, timezone is int) |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
252 * : extra is metadatas, encoded and separated by '\0' |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
253 * : older versions ignore it |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
254 * files\n\n : files modified by the cset, no \n or \r allowed |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
255 * (.*) : comment (free text, ideally utf-8) |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
256 * |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
257 * changelog v0 doesn't use extra |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
258 * </pre> |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
259 */ |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
260 /*package-local*/static final class ChangesetParser { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
261 private final EncodingHelper encHelper; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
262 // it's likely user names get repeated again and again throughout repository. |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
263 private final Pool<String> usersPool; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
264 private final Pool<String> filesPool; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
265 private final boolean reuseChangesetInstance; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
266 private RawChangeset target; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
267 |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
268 public ChangesetParser(SessionContext.Source sessionContex, boolean shallReuseCsetInstance) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
269 encHelper = Internals.buildFileNameEncodingHelper(sessionContex); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
270 usersPool = new Pool<String>(); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
271 filesPool = new Pool<String>(); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
272 reuseChangesetInstance = shallReuseCsetInstance; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
273 if (shallReuseCsetInstance) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
274 target = new RawChangeset(); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
275 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
276 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
277 |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
278 public void dispose() { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
279 usersPool.clear(); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
280 filesPool.clear(); |
153 | 281 } |
282 | |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
283 public RawChangeset parse(DataAccess da) throws IOException, HgInvalidDataFormatException { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
284 byte[] data = da.byteArray(); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
285 if (!reuseChangesetInstance) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
286 target = new RawChangeset(); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
287 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
288 init(data, 0, data.length); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
289 return target; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
290 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
291 |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
292 private void init(byte[] data, int offset, int length) throws HgInvalidDataFormatException { |
153 | 293 final int bufferEndIndex = offset + length; |
294 final byte lineBreak = (byte) '\n'; | |
295 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex); | |
296 if (breakIndex1 == -1) { | |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
426
diff
changeset
|
297 throw new HgInvalidDataFormatException("Bad Changeset data"); |
153 | 298 } |
299 Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1); | |
300 int breakIndex2 = indexOf(data, lineBreak, breakIndex1 + 1, bufferEndIndex); | |
301 if (breakIndex2 == -1) { | |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
426
diff
changeset
|
302 throw new HgInvalidDataFormatException("Bad Changeset data"); |
153 | 303 } |
589
c18095eedde0
Username in changeset uses UTF-8, not system encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
520
diff
changeset
|
304 String _user; |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
305 _user = encHelper.userFromChangeset(data, breakIndex1 + 1, breakIndex2 - breakIndex1 - 1); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
306 _user = usersPool.unify(_user); |
589
c18095eedde0
Username in changeset uses UTF-8, not system encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
520
diff
changeset
|
307 |
153 | 308 int breakIndex3 = indexOf(data, lineBreak, breakIndex2 + 1, bufferEndIndex); |
309 if (breakIndex3 == -1) { | |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
426
diff
changeset
|
310 throw new HgInvalidDataFormatException("Bad Changeset data"); |
153 | 311 } |
312 String _timeString = new String(data, breakIndex2 + 1, breakIndex3 - breakIndex2 - 1); | |
313 int space1 = _timeString.indexOf(' '); | |
314 if (space1 == -1) { | |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
426
diff
changeset
|
315 throw new HgInvalidDataFormatException(String.format("Bad Changeset data: %s in [%d..%d]", "time string", breakIndex2+1, breakIndex3)); |
153 | 316 } |
317 int space2 = _timeString.indexOf(' ', space1 + 1); | |
318 if (space2 == -1) { | |
319 space2 = _timeString.length(); | |
320 } | |
363
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
321 long unixTime = Long.parseLong(_timeString.substring(0, space1)); |
153 | 322 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
|
323 // unixTime is local time, and timezone records difference of the local time to UTC. |
153 | 324 Date _time = new Date(unixTime * 1000); |
325 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null; | |
656
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
326 Map<String, String> _extrasMap = parseExtras(_extras); |
153 | 327 // |
328 int lastStart = breakIndex3 + 1; | |
329 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); | |
330 ArrayList<String> _files = null; | |
331 if (breakIndex4 > lastStart) { | |
332 // if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision) | |
333 _files = new ArrayList<String>(5); | |
334 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) { | |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
335 String fname = encHelper.fileFromChangeset(data, lastStart, breakIndex4 - lastStart); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
336 _files.add(filesPool.unify(fname)); |
153 | 337 lastStart = breakIndex4 + 1; |
338 if (data[breakIndex4 + 1] == lineBreak) { | |
339 // found \n\n | |
340 break; | |
341 } else { | |
342 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
|
343 } |
153 | 344 } |
345 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) { | |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
426
diff
changeset
|
346 throw new HgInvalidDataFormatException("Bad Changeset data"); |
153 | 347 } |
348 } else { | |
349 breakIndex4--; | |
350 } | |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
351 String _comment = encHelper.commentFromChangeset(data, breakIndex4 + 2, bufferEndIndex - breakIndex4 - 2); |
153 | 352 // change this instance at once, don't leave it partially changes in case of error |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
353 target.manifest = _nodeid; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
354 target.user = _user; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
355 target.time = _time; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
356 target.timezone = _timezone; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
357 target.files = _files == null ? new String[0] : _files.toArray(new String[_files.size()]); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
358 target.comment = _comment; |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
359 target.extras = _extrasMap; |
153 | 360 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
361 |
656
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
362 private Map<String, String> parseExtras(String _extras) { |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
363 final String extras_branch_key = "branch"; |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
364 _extras = _extras == null ? null : _extras.trim(); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
365 if (_extras == null || _extras.length() == 0) { |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
366 return Collections.singletonMap(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
367 } |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
368 Map<String, String> _extrasMap = new HashMap<String, String>(); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
369 int lastIndex = 0; |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
370 do { |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
371 String pair; |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
372 int sp = _extras.indexOf('\0', lastIndex); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
373 if (sp == -1) { |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
374 sp = _extras.length(); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
375 } |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
376 if (sp > lastIndex) { |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
377 pair = _extras.substring(lastIndex, sp); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
378 pair = decode(pair); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
379 int eq = pair.indexOf(':'); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
380 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1)); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
381 lastIndex = sp + 1; |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
382 } |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
383 } while (lastIndex < _extras.length()); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
384 if (!_extrasMap.containsKey(extras_branch_key)) { |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
385 _extrasMap.put(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
386 } |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
387 return Collections.unmodifiableMap(_extrasMap); |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
388 } |
a937e63b6e02
Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
389 |
153 | 390 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) { |
391 for (int i = startOffset; i < endIndex; i++) { | |
392 if (src[i] == what) { | |
393 return i; | |
394 } | |
395 } | |
396 return -1; | |
397 } | |
363
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
398 |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
399 private static String decode(String s) { |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
400 if (s != null && s.indexOf('\\') != -1) { |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
401 // TestAuxUtilities#testChangelogExtrasDecode |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
402 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
|
403 } |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
404 return s; |
d9dfa9fe9cec
Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
360
diff
changeset
|
405 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
406 } |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
407 |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
408 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
|
409 final ArrayList<RawChangeset> result; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
410 |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
411 public RawCsetCollector(int count) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
412 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
|
413 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
414 |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
415 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
|
416 result.add(cset.clone()); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
417 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
418 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
419 |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
420 private static final class RawCsetParser implements RevlogStream.Inspector, Adaptable, Lifecycle { |
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 private final Inspector inspector; |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
423 private final ChangesetParser csetBuilder; |
520
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
424 // non-null when inspector uses high-level lifecycle entities (progress and/or cancel supports) |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
425 private final LifecycleBridge lifecycleStub; |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
426 // non-null when inspector relies on low-level lifecycle and is responsible |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
427 // to proceed any possible high-level entities himself. |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
428 private final Lifecycle inspectorLifecycle; |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
429 |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
430 public RawCsetParser(SessionContext.Source sessionContext, HgChangelog.Inspector delegate) { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
431 assert delegate != null; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
432 inspector = delegate; |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
433 csetBuilder = new ChangesetParser(sessionContext, true); |
520
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
434 inspectorLifecycle = Adaptable.Factory.getAdapter(delegate, Lifecycle.class, null); |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
435 if (inspectorLifecycle == null) { |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
436 ProgressSupport ph = Adaptable.Factory.getAdapter(delegate, ProgressSupport.class, null); |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
437 CancelSupport cs = Adaptable.Factory.getAdapter(delegate, CancelSupport.class, null); |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
438 if (cs != null || ph != null) { |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
439 lifecycleStub = new LifecycleBridge(ph, cs); |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
440 } else { |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
441 lifecycleStub = null; |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
442 } |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
443 } else { |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
444 lifecycleStub = null; |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
445 } |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
446 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
447 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
600
diff
changeset
|
448 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) throws HgRuntimeException { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
449 try { |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
450 RawChangeset cset = csetBuilder.parse(da); |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
451 // 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
|
452 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); |
520
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
453 if (lifecycleStub != null) { |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
454 lifecycleStub.nextStep(); |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
455 } |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
426
diff
changeset
|
456 } catch (HgInvalidDataFormatException ex) { |
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
426
diff
changeset
|
457 throw ex.setRevisionIndex(revisionNumber); |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
365
diff
changeset
|
458 } 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
|
459 // 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
|
460 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
|
461 } |
520
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
462 } |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
463 |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
464 public <T> T getAdapter(Class<T> adapterClass) { |
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
465 if (adapterClass == Lifecycle.class) { |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
466 return adapterClass.cast(this); |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
467 } |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
468 // XXX what if caller takes Progress/Cancel (which we update through lifecycleStub, too) |
520
1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
469 return Adaptable.Factory.getAdapter(inspector, adapterClass, null); |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
470 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
252
diff
changeset
|
471 |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
472 public void start(int count, Callback callback, Object token) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
473 if (inspectorLifecycle != null) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
474 inspectorLifecycle.start(count, callback, token); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
475 } else if (lifecycleStub != null) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
476 lifecycleStub.start(count, callback, token); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
477 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
478 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
479 |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
480 public void finish(Object token) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
481 if (inspectorLifecycle != null) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
482 inspectorLifecycle.finish(token); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
483 } else if (lifecycleStub != null) { |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
484 lifecycleStub.finish(token); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
485 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
486 csetBuilder.dispose(); |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
487 } |
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
656
diff
changeset
|
488 |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
489 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
490 } |