annotate src/com/tmate/hgkit/ll/Changeset.java @ 71:ce6d23673f2d

Tests to run from build.xml
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 23 Jan 2011 03:34:24 +0100
parents 19e9e220bf68
children
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 }
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
98
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
99 @Override
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
100 public Changeset clone() {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
101 try {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
102 return (Changeset) super.clone();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
103 } catch (CloneNotSupportedException ex) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
104 throw new InternalError(ex.toString());
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
105 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 54
diff changeset
106 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
108 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
109 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
110 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
111 return rv;
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
112 }
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
113
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
114 /*package-local*/ void init(byte[] data, int offset, int length) {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 final int bufferEndIndex = offset + length;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 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
117 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 if (breakIndex1 == -1) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 throw new IllegalArgumentException("Bad Changeset data");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 }
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
121 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
122 int breakIndex2 = indexOf(data, lineBreak, breakIndex1+1, bufferEndIndex);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 if (breakIndex2 == -1) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 throw new IllegalArgumentException("Bad Changeset data");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 }
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
126 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
127 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 if (breakIndex3 == -1) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 throw new IllegalArgumentException("Bad Changeset data");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 }
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
131 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
132 int space1 = _timeString.indexOf(' ');
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
133 if (space1 == -1) {
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
134 throw new IllegalArgumentException("Bad Changeset data");
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
135 }
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
136 int space2 = _timeString.indexOf(' ', space1+1);
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
137 if (space2 == -1) {
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
138 space2 = _timeString.length();
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
139 }
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
140 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
141 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
142 // 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
143 // 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
144 Date _time = new Date(unixTime * 1000);
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
145 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
146 Map<String, String> _extrasMap;
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
147 if (_extras == null) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
148 _extrasMap = Collections.singletonMap("branch", "default");
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
149 } else {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
150 _extrasMap = new HashMap<String, String>();
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
151 for (String pair : _extras.split("\00")) {
54
fd4f2c98995b Correct split symbol for extra metadata
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
152 int eq = pair.indexOf(':');
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
153 // 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
154 _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
155 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
156 if (!_extrasMap.containsKey("branch")) {
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
157 _extrasMap.put("branch", "default");
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
158 }
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
159 _extrasMap = Collections.unmodifiableMap(_extrasMap);
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
160 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 //
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 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
164 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
165 ArrayList<String> _files = new ArrayList<String>(5);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 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
167 _files.add(new String(data, lastStart, breakIndex4 - lastStart));
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 lastStart = breakIndex4 + 1;
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
169 if (data[breakIndex4 + 1] == lineBreak) {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 // found \n\n
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 break;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 } else {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
173 breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 throw new IllegalArgumentException("Bad Changeset data");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 }
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
179 String _comment;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 try {
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
181 _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
182 } catch (UnsupportedEncodingException ex) {
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
183 _comment = "";
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 throw new IllegalStateException("Could hardly happen");
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 }
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
186 // 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
187 this.manifest = _nodeid;
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
188 this.user = _user;
40
21e26da142fa Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 38
diff changeset
189 this.time = _time;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
190 this.timezone = _timezone;
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
191 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
192 this.comment = _comment;
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
193 this.extras = _extrasMap;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 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
197 for (int i = startOffset; i < endIndex; i++) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 if (src[i] == what) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 return i;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 return -1;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
204
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
205 public interface Inspector {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
206 // first(), last(), single().
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
207 // <T>
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 40
diff changeset
208 // 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
209 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
210 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 }