tikhomirov@38: /*
tikhomirov@38: * Copyright (c) 2010, 2011 Artem Tikhomirov
tikhomirov@0: */
tikhomirov@0: package com.tmate.hgkit.ll;
tikhomirov@0:
tikhomirov@0: import java.io.UnsupportedEncodingException;
tikhomirov@0: import java.util.ArrayList;
tikhomirov@40: import java.util.Date;
tikhomirov@40: import java.util.Locale;
tikhomirov@0:
tikhomirov@0: /**
tikhomirov@0: * @see mercurial/changelog.py:read()
tikhomirov@0: *
tikhomirov@0: format used:
tikhomirov@0: nodeid\n : manifest node in ascii
tikhomirov@0: user\n : user, no \n or \r allowed
tikhomirov@0: time tz extra\n : date (time is int or float, timezone is int)
tikhomirov@0: : extra is metadatas, encoded and separated by '\0'
tikhomirov@0: : older versions ignore it
tikhomirov@0: files\n\n : files modified by the cset, no \n or \r allowed
tikhomirov@0: (.*) : comment (free text, ideally utf-8)
tikhomirov@0:
tikhomirov@0: changelog v0 doesn't use extra
tikhomirov@0: *
tikhomirov@0: * @author artem
tikhomirov@0: */
tikhomirov@0: public class Changeset {
tikhomirov@3: // TODO immutable
tikhomirov@38: private /*final*/ Nodeid manifest;
tikhomirov@0: private String user;
tikhomirov@0: private String comment;
tikhomirov@0: private ArrayList files;
tikhomirov@40: private Date time;
tikhomirov@40: private String extras; // TODO branch, etc.
tikhomirov@0:
tikhomirov@0: public void dump() {
tikhomirov@40: System.out.println("User: " + user);
tikhomirov@40: System.out.println("Comment: " + comment);
tikhomirov@40: System.out.println("Manifest: " + manifest);
tikhomirov@40: System.out.printf(Locale.US, "Date: %ta % _files = new ArrayList(5);
tikhomirov@0: while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) {
tikhomirov@5: _files.add(new String(data, lastStart, breakIndex4 - lastStart));
tikhomirov@0: lastStart = breakIndex4 + 1;
tikhomirov@3: if (data[breakIndex4 + 1] == lineBreak) {
tikhomirov@0: // found \n\n
tikhomirov@0: break;
tikhomirov@0: } else {
tikhomirov@3: breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
tikhomirov@0: }
tikhomirov@0: }
tikhomirov@0: if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) {
tikhomirov@0: throw new IllegalArgumentException("Bad Changeset data");
tikhomirov@0: }
tikhomirov@5: String _comment;
tikhomirov@0: try {
tikhomirov@5: _comment = new String(data, breakIndex4+2, bufferEndIndex - breakIndex4 - 2, "UTF-8");
tikhomirov@0: } catch (UnsupportedEncodingException ex) {
tikhomirov@5: _comment = "";
tikhomirov@0: throw new IllegalStateException("Could hardly happen");
tikhomirov@0: }
tikhomirov@5: // change this instance at once, don't leave it partially changes in case of error
tikhomirov@38: this.manifest = _nodeid;
tikhomirov@5: this.user = _user;
tikhomirov@40: this.time = _time;
tikhomirov@5: this.files = _files;
tikhomirov@5: this.comment = _comment;
tikhomirov@40: this.extras = _extras;
tikhomirov@0: }
tikhomirov@0:
tikhomirov@0: private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) {
tikhomirov@0: for (int i = startOffset; i < endIndex; i++) {
tikhomirov@0: if (src[i] == what) {
tikhomirov@0: return i;
tikhomirov@0: }
tikhomirov@0: }
tikhomirov@0: return -1;
tikhomirov@0: }
tikhomirov@2:
tikhomirov@3: public interface Inspector {
tikhomirov@2: // first(), last(), single().
tikhomirov@2: //
tikhomirov@2: void next(Changeset cset);
tikhomirov@2: }
tikhomirov@0: }