Mercurial > jhg
annotate src/com/tmate/hgkit/ll/Changeset.java @ 4:aa1912c70b36
Fix offset issue for inline revlogs. Commandline processing.
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 20 Dec 2010 04:20:52 +0100 |
parents | 24bb4f365164 |
children | fc265ddeab26 |
rev | line source |
---|---|
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /** |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2010 Artem Tikhomirov |
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; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 /** |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * @see mercurial/changelog.py:read() |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * <pre> |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 format used: |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 nodeid\n : manifest node in ascii |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 user\n : user, no \n or \r allowed |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 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
|
16 : extra is metadatas, encoded and separated by '\0' |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 : older versions ignore it |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 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
|
19 (.*) : comment (free text, ideally utf-8) |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 changelog v0 doesn't use extra |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 * </pre> |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 * @author artem |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 */ |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 public class Changeset { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
26 // TODO immutable |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 private /*final*/ Nodeid nodeid; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 private String user; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 private String comment; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 private ArrayList<String> files; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 private String timezone; // FIXME |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 public void dump() { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 System.out.println("User:" + user); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 System.out.println("Comment:" + comment); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 System.out.println("Nodeid:" + nodeid); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 System.out.println("Date:" + timezone); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 System.out.println("Files: " + files.size()); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 for (String s : files) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 System.out.print('\t'); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 System.out.println(s); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
45 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
|
46 Changeset rv = new Changeset(); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 final int bufferEndIndex = offset + length; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 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
|
49 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 if (breakIndex1 == -1) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
53 rv.nodeid = Nodeid.fromAscii(data, 0, breakIndex1); |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
54 int breakIndex2 = indexOf(data, lineBreak, breakIndex1+1, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 if (breakIndex2 == -1) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
58 rv.user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1); |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
59 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 if (breakIndex3 == -1) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
63 rv.timezone = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 // |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 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
|
67 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
68 rv.files = new ArrayList<String>(5); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
70 rv.files.add(new String(data, lastStart, breakIndex4 - lastStart)); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 lastStart = breakIndex4 + 1; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
72 if (data[breakIndex4 + 1] == lineBreak) { |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 // found \n\n |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 break; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } else { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
76 breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 try { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
83 rv.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
|
84 } catch (UnsupportedEncodingException ex) { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
85 rv.comment = ""; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 throw new IllegalStateException("Could hardly happen"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
88 return rv; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 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
|
92 for (int i = startOffset; i < endIndex; i++) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 if (src[i] == what) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 return i; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 return -1; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
99 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
100 public interface Inspector { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
101 // first(), last(), single(). |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
102 // <T> |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
103 void next(Changeset cset); |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
104 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } |