comparison src/com/tmate/hgkit/ll/Changelog.java @ 3:24bb4f365164

Rudimentary log functionality with basic infrastructure is in place
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 Dec 2010 02:50:36 +0100
parents 08db726a0fb7
children e929cecae4e1
comparison
equal deleted inserted replaced
2:08db726a0fb7 3:24bb4f365164
1 /** 1 /**
2 * Copyright (c) 2010 Artem Tikhomirov 2 * Copyright (c) 2010 Artem Tikhomirov
3 */ 3 */
4 package com.tmate.hgkit.ll; 4 package com.tmate.hgkit.ll;
5 5
6 import java.io.DataInput;
7 import java.io.EOFException;
8 import java.io.IOException;
9 import java.util.ArrayList; 6 import java.util.ArrayList;
10 import java.util.Collections; 7 import java.util.Arrays;
11 import java.util.List; 8 import java.util.List;
12 9
13 /** 10 /**
14 * Representation of the Mercurial changelog file (list of ChangeSets) 11 * Representation of the Mercurial changelog file (list of ChangeSets)
15 * @author artem 12 * @author artem
16 */ 13 */
17 public class Changelog extends Revlog { 14 public class Changelog extends Revlog {
18 15
19 private RevlogStream content; 16 private final RevlogStream content;
20 17
21 /*package-local*/ Changelog(HgRepository hgRepo) { 18 /*package-local*/ Changelog(HgRepository hgRepo, RevlogStream content) {
22 super(hgRepo); 19 super(hgRepo);
23 content = hgRepo.resolve(".hg/store/00changelog.i"); 20 this.content = content;
24 } 21 }
25 22
26 public List<Changeset> all() { 23 public void all(final Changeset.Inspector inspector) {
27 throw HgRepository.notImplemented(); 24 Revlog.Inspector i = new Revlog.Inspector() {
28 } 25
29 26 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
30 public void all(Changeset.Callback callback) { 27 Changeset cset = Changeset.parse(data, 0, data.length);
31 throw HgRepository.notImplemented(); 28 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse
29 inspector.next(cset);
30 }
31 };
32 content.iterate(0, content.revisionCount() - 1, true, i);
32 } 33 }
33 34
34 public List<Changeset> range(int start, int end) { 35 public List<Changeset> range(int start, int end) {
35 //read from outline[start].start .. (outline[end].start + outline[end].length)
36 // parse changesets
37 final ArrayList<Changeset> rv = new ArrayList<Changeset>(end - start + 1); 36 final ArrayList<Changeset> rv = new ArrayList<Changeset>(end - start + 1);
38 Revlog.Inspector i = new Revlog.Inspector() { 37 Revlog.Inspector i = new Revlog.Inspector() {
39 38
40 public void next(int compressedLen, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { 39 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
41 // TODO Auto-generated method stub 40 Changeset cset = Changeset.parse(data, 0, data.length);
42 Changeset.parse(data); 41 rv.add(cset);
43 i.add();
44 throw HgRepository.notImplemented();
45 } 42 }
46 }; 43 };
47 content.iterate(start, end, true, i); 44 content.iterate(start, end, true, i);
48 return rv; 45 return rv;
49 } 46 }
47
48 public void range(final Changeset.Inspector inspector, final int... revisions) {
49 if (revisions == null || revisions.length == 0) {
50 return;
51 }
52 Revlog.Inspector i = new Revlog.Inspector() {
53
54 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
55 if (Arrays.binarySearch(revisions, revisionNumber) >= 0) {
56 Changeset cset = Changeset.parse(data, 0, data.length);
57 inspector.next(cset);
58 }
59 }
60 };
61 Arrays.sort(revisions);
62 content.iterate(revisions[0], revisions[revisions.length - 1], true, i);
63 }
50 } 64 }