Mercurial > hg4j
annotate src/com/tmate/hgkit/ll/HgManifest.java @ 33:565ce0835674
TODO added, to try stream for unzip in revlog
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 13 Jan 2011 03:42:14 +0100 |
parents | b2251b7a9823 |
children | 9429c7bd1920 |
rev | line source |
---|---|
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
1 /* |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
2 * Copyright (c) 2010, 2011 Artem Tikhomirov |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 */ |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 package com.tmate.hgkit.ll; |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 /** |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * @author artem |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 */ |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 public class HgManifest extends Revlog { |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
12 /*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) { |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
13 super(hgRepo, content); |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
14 } |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
15 |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
16 public void walk(int start, int end, final Inspector inspector) { |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
17 Revlog.Inspector insp = new Revlog.Inspector() { |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
18 |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
19 private boolean gtg = true; // good to go |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
20 |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
21 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
22 if (!gtg) { |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
23 return; |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
24 } |
28
b2251b7a9823
Explicit cons arg for clone is more error-prone
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
24
diff
changeset
|
25 gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid, true)); |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
26 int i; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
27 String fname = null; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
28 String flags = null; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
29 Nodeid nid = null; |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
30 for (i = 0; gtg && i < actualLen; i++) { |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
31 int x = i; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
32 for( ; data[i] != '\n' && i < actualLen; i++) { |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
33 if (fname == null && data[i] == 0) { |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
34 fname = new String(data, x, i - x); |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
35 x = i+1; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
36 } |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
37 } |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
38 if (i < actualLen) { |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
39 assert data[i] == '\n'; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
40 int nodeidLen = i - x < 40 ? i-x : 40; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
41 nid = Nodeid.fromAscii(data, x, nodeidLen); |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
42 if (nodeidLen + x < i) { |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
43 // 'x' and 'l' for executable bits and symlinks? |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
44 // hg --debug manifest shows 644 for each regular file in my repo |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
45 flags = new String(data, x + nodeidLen, i-x-nodeidLen); |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
46 } |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
47 gtg = gtg && inspector.next(nid, fname, flags); |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
48 } |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
49 nid = null; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
50 fname = flags = null; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
51 } |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
52 gtg = gtg && inspector.end(revisionNumber); |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
53 } |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
54 }; |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
55 content.iterate(start, end, true, insp); |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
56 } |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
57 |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
58 public interface Inspector { |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
59 boolean begin(int revision, Nodeid nid); |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
60 boolean next(Nodeid nid, String fname, String flags); |
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
61 boolean end(int revision); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 } |