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