Mercurial > hg4j
annotate src/com/tmate/hgkit/ll/Changeset.java @ 48:e34f90b9ded1
Limit option for history/log
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 14 Jan 2011 23:22:20 +0100 |
parents | b01500fe2604 |
children | 26e3eeaa3962 |
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; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
11 import java.util.List; |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
12 import java.util.Locale; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
13 import java.util.Map; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 |
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 * @see mercurial/changelog.py:read() |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 * <pre> |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 format used: |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 nodeid\n : manifest node in ascii |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 user\n : user, no \n or \r allowed |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 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
|
22 : extra is metadatas, encoded and separated by '\0' |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 : older versions ignore it |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 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
|
25 (.*) : comment (free text, ideally utf-8) |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 changelog v0 doesn't use extra |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 * </pre> |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 * @author artem |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 */ |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
31 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
|
32 // TODO immutable |
38
50dfc69c108e
Nodeid is confusing, denote it's reference to manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
5
diff
changeset
|
33 private /*final*/ Nodeid manifest; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 private String user; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 private String comment; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
36 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
|
37 private Date time; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
38 private int timezone; // not sure it's of any use |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
39 private String extras; // TODO branch, etc. |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
41 private Changeset() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
42 } |
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 public Nodeid manifest() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
45 return manifest; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
46 } |
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 public String user() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
49 return user; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
50 } |
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 public String comment() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
53 return comment; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
54 } |
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 public List<String> files() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
57 return files; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
58 } |
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 public Date date() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
61 return time; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
62 } |
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 public String dateString() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
65 StringBuilder sb = new StringBuilder(30); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
66 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
|
67 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
|
68 return sb.toString(); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
69 } |
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 public Map<String, String> extras() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
72 return null; // TODO |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
73 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
74 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
75 @Override |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
76 public String toString() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
77 StringBuilder sb = new StringBuilder(); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
78 sb.append("Changeset {"); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
79 sb.append("User: ").append(user).append(", "); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
80 sb.append("Comment: ").append(comment).append(", "); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
81 sb.append("Manifest: ").append(manifest).append(", "); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
82 sb.append("Date: ").append(time).append(", "); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
83 sb.append("Files: ").append(files.size()); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
84 for (String s : files) { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
85 sb.append(", ").append(s); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
86 } |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
87 if (extras != null) { |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
88 sb.append(", Extra: ").append(extras); |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
89 } |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
90 sb.append("}"); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
91 return sb.toString(); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 return rv; |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
98 } |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
99 |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
100 /*package-local*/ void init(byte[] data, int offset, int length) { |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 final int bufferEndIndex = offset + length; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 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
|
103 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 if (breakIndex1 == -1) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
107 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
|
108 int breakIndex2 = indexOf(data, lineBreak, breakIndex1+1, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 if (breakIndex2 == -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 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
|
113 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 if (breakIndex3 == -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 } |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
117 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
|
118 int space1 = _timeString.indexOf(' '); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
119 if (space1 == -1) { |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
120 throw new IllegalArgumentException("Bad Changeset data"); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
121 } |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
122 int space2 = _timeString.indexOf(' ', space1+1); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
123 if (space2 == -1) { |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
124 space2 = _timeString.length(); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
125 } |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
126 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
|
127 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
|
128 // 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
|
129 // 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
|
130 Date _time = new Date(unixTime * 1000); |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
131 String _extras = space2 < _timeString.length() ? _timeString.substring(space2+1) : null; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 // |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 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
|
135 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
|
136 ArrayList<String> _files = new ArrayList<String>(5); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 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
|
138 _files.add(new String(data, lastStart, breakIndex4 - lastStart)); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 lastStart = breakIndex4 + 1; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
140 if (data[breakIndex4 + 1] == lineBreak) { |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 // found \n\n |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 break; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 } else { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
144 breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
150 String _comment; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 try { |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
152 _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
|
153 } catch (UnsupportedEncodingException ex) { |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
154 _comment = ""; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 throw new IllegalStateException("Could hardly happen"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
157 // 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
|
158 this.manifest = _nodeid; |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
159 this.user = _user; |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
160 this.time = _time; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
161 this.timezone = _timezone; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
162 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
|
163 this.comment = _comment; |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
164 this.extras = _extras; |
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 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
|
168 for (int i = startOffset; i < endIndex; i++) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 if (src[i] == what) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 return i; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 return -1; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
175 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
176 public interface Inspector { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
177 // first(), last(), single(). |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
178 // <T> |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
179 // 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
|
180 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
|
181 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 } |