comparison hg4j/src/main/java/org/tmatesoft/hg/repo/HgManifest.java @ 213:6ec4af642ba8 gradle

Project uses Gradle for build - actual changes
author Alexander Kitaev <kitaev@gmail.com>
date Tue, 10 May 2011 10:52:53 +0200
parents
children
comparison
equal deleted inserted replaced
212:edb2e2829352 213:6ec4af642ba8
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@hg4j.com
16 */
17 package org.tmatesoft.hg.repo;
18
19 import java.io.IOException;
20
21 import org.tmatesoft.hg.core.HgBadStateException;
22 import org.tmatesoft.hg.core.Nodeid;
23 import org.tmatesoft.hg.internal.DataAccess;
24 import org.tmatesoft.hg.internal.Pool;
25 import org.tmatesoft.hg.internal.RevlogStream;
26
27
28 /**
29 *
30 * @author Artem Tikhomirov
31 * @author TMate Software Ltd.
32 */
33 public class HgManifest extends Revlog {
34
35 /*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) {
36 super(hgRepo, content);
37 }
38
39 public void walk(int start, int end, final Inspector inspector) {
40 if (inspector == null) {
41 throw new IllegalArgumentException();
42 }
43 content.iterate(start, end, true, new ManifestParser(inspector));
44 }
45
46 public interface Inspector {
47 boolean begin(int revision, Nodeid nid);
48 boolean next(Nodeid nid, String fname, String flags);
49 boolean end(int revision);
50 }
51
52 private static class ManifestParser implements RevlogStream.Inspector {
53 private boolean gtg = true; // good to go
54 private final Inspector inspector;
55 private final Pool<Nodeid> nodeidPool;
56 private final Pool<String> fnamePool;
57 private final Pool<String> flagsPool;
58
59 public ManifestParser(Inspector delegate) {
60 assert delegate != null;
61 inspector = delegate;
62 nodeidPool = new Pool<Nodeid>();
63 fnamePool = new Pool<String>();
64 flagsPool = new Pool<String>();
65 }
66
67 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) {
68 if (!gtg) {
69 return;
70 }
71 try {
72 gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid, true));
73 int i;
74 String fname = null;
75 String flags = null;
76 Nodeid nid = null;
77 byte[] data = da.byteArray();
78 for (i = 0; gtg && i < actualLen; i++) {
79 int x = i;
80 for( ; data[i] != '\n' && i < actualLen; i++) {
81 if (fname == null && data[i] == 0) {
82 fname = fnamePool.unify(new String(data, x, i - x));
83 x = i+1;
84 }
85 }
86 if (i < actualLen) {
87 assert data[i] == '\n';
88 int nodeidLen = i - x < 40 ? i-x : 40;
89 nid = nodeidPool.unify(Nodeid.fromAscii(data, x, nodeidLen));
90 if (nodeidLen + x < i) {
91 // 'x' and 'l' for executable bits and symlinks?
92 // hg --debug manifest shows 644 for each regular file in my repo
93 flags = flagsPool.unify(new String(data, x + nodeidLen, i-x-nodeidLen));
94 }
95 gtg = gtg && inspector.next(nid, fname, flags);
96 }
97 nid = null;
98 fname = flags = null;
99 }
100 gtg = gtg && inspector.end(revisionNumber);
101 } catch (IOException ex) {
102 throw new HgBadStateException(ex);
103 }
104 }
105 }
106 }