comparison src/org/tmatesoft/hg/repo/HgChangelog.java @ 97:ee2c750b036d

Changelog to HgChangelog
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 27 Jan 2011 21:25:21 +0100
parents src/org/tmatesoft/hg/repo/Changelog.java@c677e1593919
children a3a2e5deb320
comparison
equal deleted inserted replaced
96:ace7042a5ce6 97:ee2c750b036d
1 /*
2 * Copyright (c) 2010-2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@svnkit.com
16 */
17 package org.tmatesoft.hg.repo;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
22
23 import org.tmatesoft.hg.core.Nodeid;
24 import org.tmatesoft.hg.internal.RevlogStream;
25
26
27 /**
28 * Representation of the Mercurial changelog file (list of ChangeSets)
29 *
30 * @author Artem Tikhomirov
31 * @author TMate Software Ltd.
32 */
33 public class HgChangelog extends Revlog {
34
35 /*package-local*/ HgChangelog(HgRepository hgRepo, RevlogStream content) {
36 super(hgRepo, content);
37 }
38
39 public void all(final Changeset.Inspector inspector) {
40 range(0, content.revisionCount() - 1, inspector);
41 }
42
43 public void range(int start, int end, final Changeset.Inspector inspector) {
44 RevlogStream.Inspector i = new RevlogStream.Inspector() {
45
46 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
47 Changeset cset = Changeset.parse(data, 0, data.length);
48 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse
49 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset);
50 }
51 };
52 content.iterate(start, end, true, i);
53 }
54
55 public List<Changeset> range(int start, int end) {
56 final ArrayList<Changeset> rv = new ArrayList<Changeset>(end - start + 1);
57 RevlogStream.Inspector i = new RevlogStream.Inspector() {
58
59 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
60 Changeset cset = Changeset.parse(data, 0, data.length);
61 rv.add(cset);
62 }
63 };
64 content.iterate(start, end, true, i);
65 return rv;
66 }
67
68 public void range(final Changeset.Inspector inspector, final int... revisions) {
69 if (revisions == null || revisions.length == 0) {
70 return;
71 }
72 RevlogStream.Inspector i = new RevlogStream.Inspector() {
73
74 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
75 if (Arrays.binarySearch(revisions, revisionNumber) >= 0) {
76 Changeset cset = Changeset.parse(data, 0, data.length);
77 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset);
78 }
79 }
80 };
81 Arrays.sort(revisions);
82 content.iterate(revisions[0], revisions[revisions.length - 1], true, i);
83 }
84 }