annotate src/com/tmate/hgkit/ll/Changeset.java @ 159:f5aed108754e wrap-data-access

Approach with DataAccess instead of plain byte[] was merged into default branch
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 09 Mar 2011 13:28:02 +0100
parents 26e3eeaa3962
children fd4f2c98995b
rev   line source
38
50dfc69c108e Nodeid is confusing, denote it's reference to manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 5
diff changeset
1 /*
50dfc69c108e Nodeid is confusing, denote it's reference to manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 5
diff changeset
2 * Copyright (c) 2010, 2011 Artem Tikhomirov
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 */
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 package com.tmate.hgkit.ll;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 import java.io.UnsupportedEncodingException;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 import java.util.ArrayList;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
8 import java.util.Collections;
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
9 import java.util.Date;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
10 import java.util.Formatter;
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
11 import java.util.HashMap;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
12 import java.util.List;
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
13 import java.util.Locale;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
14 import java.util.Map;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 /**
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 * @see mercurial/changelog.py:read()
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18 * <pre>
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 format used:
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 nodeid\n : manifest node in ascii
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 user\n : user, no \n or \r allowed
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 time tz extra\n : date (time is int or float, timezone is int)
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 : extra is metadatas, encoded and separated by '\0'
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 : older versions ignore it
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 files\n\n : files modified by the cset, no \n or \r allowed
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 (.*) : comment (free text, ideally utf-8)
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 changelog v0 doesn't use extra
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 * </pre>
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 * @author artem
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 */
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
32 public class Changeset implements Cloneable /*for those that would like to keep a copy*/ {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
33 // TODO immutable
38
50dfc69c108e Nodeid is confusing, denote it's reference to manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 5
diff changeset
34 private /*final*/ Nodeid manifest;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 private String user;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 private String comment;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
37 private List<String> files; // unmodifiable collection (otherwise #files() and implicit #clone() shall be revised)
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
38 private Date time;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
39 private int timezone; // not sure it's of any use
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
40 private Map<String,String> extras;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
42 private Changeset() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
43 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
44
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
45 public Nodeid manifest() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
46 return manifest;
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
47 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
48
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
49 public String user() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
50 return user;
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
51 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
52
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
53 public String comment() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
54 return comment;
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
55 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
56
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
57 public List<String> files() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
58 return files;
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
59 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
60
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
61 public Date date() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
62 return time;
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
63 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
64
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
65 public String dateString() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
66 StringBuilder sb = new StringBuilder(30);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
67 Formatter f = new Formatter(sb, Locale.US);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
68 f.format("%ta %<tb %<td %<tH:%<tM:%<tS %<tY %<tz", time);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
69 return sb.toString();
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
70 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
71
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
72 public Map<String, String> extras() {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
73 return extras;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
74 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
75
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
76 public String branch() {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
77 return extras.get("branch");
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
78 }
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
79
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
80 @Override
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
81 public String toString() {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
82 StringBuilder sb = new StringBuilder();
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
83 sb.append("Changeset {");
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
84 sb.append("User: ").append(user).append(", ");
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
85 sb.append("Comment: ").append(comment).append(", ");
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
86 sb.append("Manifest: ").append(manifest).append(", ");
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
87 sb.append("Date: ").append(time).append(", ");
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
88 sb.append("Files: ").append(files.size());
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
89 for (String s : files) {
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
90 sb.append(", ").append(s);
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
91 }
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
92 if (extras != null) {
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
93 sb.append(", Extra: ").append(extras);
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
94 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
95 sb.append("}");
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
96 return sb.toString();
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
99 public static Changeset parse(byte[] data, int offset, int length) {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
100 Changeset rv = new Changeset();
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
101 rv.init(data, offset, length);
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
102 return rv;
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
103 }
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
104
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
105 /*package-local*/ void init(byte[] data, int offset, int length) {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 final int bufferEndIndex = offset + length;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 final byte lineBreak = (byte) '\n';
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
108 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 if (breakIndex1 == -1) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 throw new IllegalArgumentException("Bad Changeset data");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 }
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
112 Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1);
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
113 int breakIndex2 = indexOf(data, lineBreak, breakIndex1+1, bufferEndIndex);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 if (breakIndex2 == -1) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 throw new IllegalArgumentException("Bad Changeset data");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 }
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
117 String _user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1);
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
118 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 if (breakIndex3 == -1) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 throw new IllegalArgumentException("Bad Changeset data");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 }
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
122 String _timeString = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1);
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
123 int space1 = _timeString.indexOf(' ');
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
124 if (space1 == -1) {
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
125 throw new IllegalArgumentException("Bad Changeset data");
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
126 }
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
127 int space2 = _timeString.indexOf(' ', space1+1);
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
128 if (space2 == -1) {
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
129 space2 = _timeString.length();
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
130 }
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
131 long unixTime = Long.parseLong(_timeString.substring(0, space1)); // XXX Float, perhaps
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
132 int _timezone = Integer.parseInt(_timeString.substring(space1+1, space2));
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
133 // XXX not sure need to add timezone here - I can't figure out whether Hg keeps GMT time, and records timezone just for info, or unixTime is taken local
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
134 // on commit and timezone is recorded to adjust it to UTC.
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
135 Date _time = new Date(unixTime * 1000);
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
136 String _extras = space2 < _timeString.length() ? _timeString.substring(space2+1) : null;
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
137 Map<String, String> _extrasMap;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
138 if (_extras == null) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
139 _extrasMap = Collections.singletonMap("branch", "default");
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
140 } else {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
141 _extrasMap = new HashMap<String, String>();
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
142 for (String pair : _extras.split("\00")) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
143 int eq = pair.indexOf('=');
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
144 // FIXME need to decode key/value, @see changelog.py:decodeextra
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
145 _extrasMap.put(pair.substring(0, eq), pair.substring(eq+1));
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
146 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
147 if (!_extrasMap.containsKey("branch")) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
148 _extrasMap.put("branch", "default");
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
149 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
150 _extrasMap = Collections.unmodifiableMap(_extrasMap);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
151 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 //
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 int lastStart = breakIndex3 + 1;
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
155 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
156 ArrayList<String> _files = new ArrayList<String>(5);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) {
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
158 _files.add(new String(data, lastStart, breakIndex4 - lastStart));
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 lastStart = breakIndex4 + 1;
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
160 if (data[breakIndex4 + 1] == lineBreak) {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 // found \n\n
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 break;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 } else {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
164 breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 throw new IllegalArgumentException("Bad Changeset data");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 }
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
170 String _comment;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 try {
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
172 _comment = new String(data, breakIndex4+2, bufferEndIndex - breakIndex4 - 2, "UTF-8");
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 } catch (UnsupportedEncodingException ex) {
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
174 _comment = "";
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 throw new IllegalStateException("Could hardly happen");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 }
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
177 // change this instance at once, don't leave it partially changes in case of error
38
50dfc69c108e Nodeid is confusing, denote it's reference to manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 5
diff changeset
178 this.manifest = _nodeid;
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
179 this.user = _user;
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
180 this.time = _time;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
181 this.timezone = _timezone;
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
182 this.files = Collections.unmodifiableList(_files);
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
183 this.comment = _comment;
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
184 this.extras = _extrasMap;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 for (int i = startOffset; i < endIndex; i++) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 if (src[i] == what) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 return i;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 return -1;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
195
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
196 public interface Inspector {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
197 // first(), last(), single().
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
198 // <T>
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
199 // TODO describe whether cset is new instance each time
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
200 void next(int revisionNumber, Nodeid nodeid, Changeset cset);
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
201 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 }