Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/Changelog.java @ 74:6f1b88693d48
Complete refactoring to org.tmatesoft
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 24 Jan 2011 03:14:45 +0100 |
parents | src/com/tmate/hgkit/ll/Changelog.java@e34f90b9ded1 |
children | c677e1593919 |
comparison
equal
deleted
inserted
replaced
73:0d279bcc4442 | 74:6f1b88693d48 |
---|---|
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 | |
25 | |
26 /** | |
27 * Representation of the Mercurial changelog file (list of ChangeSets) | |
28 * | |
29 * @author Artem Tikhomirov | |
30 * @author TMate Software Ltd. | |
31 */ | |
32 public class Changelog extends Revlog { | |
33 | |
34 /*package-local*/ Changelog(HgRepository hgRepo, RevlogStream content) { | |
35 super(hgRepo, content); | |
36 } | |
37 | |
38 public void all(final Changeset.Inspector inspector) { | |
39 range(0, content.revisionCount() - 1, inspector); | |
40 } | |
41 | |
42 public void range(int start, int end, final Changeset.Inspector inspector) { | |
43 Revlog.Inspector i = new Revlog.Inspector() { | |
44 | |
45 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | |
46 Changeset cset = Changeset.parse(data, 0, data.length); | |
47 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse | |
48 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); | |
49 } | |
50 }; | |
51 content.iterate(start, end, true, i); | |
52 } | |
53 | |
54 public List<Changeset> range(int start, int end) { | |
55 final ArrayList<Changeset> rv = new ArrayList<Changeset>(end - start + 1); | |
56 Revlog.Inspector i = new Revlog.Inspector() { | |
57 | |
58 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | |
59 Changeset cset = Changeset.parse(data, 0, data.length); | |
60 rv.add(cset); | |
61 } | |
62 }; | |
63 content.iterate(start, end, true, i); | |
64 return rv; | |
65 } | |
66 | |
67 public void range(final Changeset.Inspector inspector, final int... revisions) { | |
68 if (revisions == null || revisions.length == 0) { | |
69 return; | |
70 } | |
71 Revlog.Inspector i = new Revlog.Inspector() { | |
72 | |
73 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | |
74 if (Arrays.binarySearch(revisions, revisionNumber) >= 0) { | |
75 Changeset cset = Changeset.parse(data, 0, data.length); | |
76 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); | |
77 } | |
78 } | |
79 }; | |
80 Arrays.sort(revisions); | |
81 content.iterate(revisions[0], revisions[revisions.length - 1], true, i); | |
82 } | |
83 } |