tikhomirov@13: /* tikhomirov@19: * Copyright (c) 2010, 2011 Artem Tikhomirov tikhomirov@2: */ tikhomirov@2: package com.tmate.hgkit.ll; tikhomirov@2: tikhomirov@2: /** tikhomirov@2: * tikhomirov@2: * @author artem tikhomirov@2: */ tikhomirov@2: public class HgManifest extends Revlog { tikhomirov@2: tikhomirov@13: private final RevlogStream content; tikhomirov@13: tikhomirov@13: /*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) { tikhomirov@2: super(hgRepo); tikhomirov@13: this.content = content; tikhomirov@13: } tikhomirov@13: tikhomirov@19: public void walk(int start, int end, final Inspector inspector) { tikhomirov@13: Revlog.Inspector insp = new Revlog.Inspector() { tikhomirov@19: tikhomirov@19: private boolean gtg = true; // good to go tikhomirov@19: tikhomirov@13: public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { tikhomirov@19: if (!gtg) { tikhomirov@19: return; tikhomirov@19: } tikhomirov@19: gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid)); tikhomirov@13: int i; tikhomirov@13: String fname = null; tikhomirov@13: String flags = null; tikhomirov@13: Nodeid nid = null; tikhomirov@19: for (i = 0; gtg && i < actualLen; i++) { tikhomirov@13: int x = i; tikhomirov@13: for( ; data[i] != '\n' && i < actualLen; i++) { tikhomirov@13: if (fname == null && data[i] == 0) { tikhomirov@13: fname = new String(data, x, i - x); tikhomirov@13: x = i+1; tikhomirov@13: } tikhomirov@13: } tikhomirov@13: if (i < actualLen) { tikhomirov@13: assert data[i] == '\n'; tikhomirov@13: int nodeidLen = i - x < 40 ? i-x : 40; tikhomirov@13: nid = Nodeid.fromAscii(data, x, nodeidLen); tikhomirov@13: if (nodeidLen + x < i) { tikhomirov@13: // 'x' and 'l' for executable bits and symlinks? tikhomirov@13: // hg --debug manifest shows 644 for each regular file in my repo tikhomirov@13: flags = new String(data, x + nodeidLen, i-x-nodeidLen); tikhomirov@13: } tikhomirov@19: gtg = gtg && inspector.next(nid, fname, flags); tikhomirov@13: } tikhomirov@13: nid = null; tikhomirov@13: fname = flags = null; tikhomirov@13: } tikhomirov@19: gtg = gtg && inspector.end(revisionNumber); tikhomirov@13: } tikhomirov@13: }; tikhomirov@19: content.iterate(start, end, true, insp); tikhomirov@19: } tikhomirov@19: tikhomirov@19: public interface Inspector { tikhomirov@19: boolean begin(int revision, Nodeid nid); tikhomirov@19: boolean next(Nodeid nid, String fname, String flags); tikhomirov@19: boolean end(int revision); tikhomirov@2: } tikhomirov@2: }