Mercurial > hg4j
annotate src/org/tmatesoft/hg/repo/HgChangelog.java @ 155:a4ec5e087017
Dedicated location for various test data
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 24 Feb 2011 22:18:03 +0100 |
parents | ba2bf656f00f |
children | d5268ca7715b |
rev | line source |
---|---|
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
1 /* |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
2 * Copyright (c) 2010-2011 TMate Software Ltd |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
13 * For information on how to redistribute this software under |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
102
a3a2e5deb320
Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
97
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
19 import java.io.UnsupportedEncodingException; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
20 import java.util.ArrayList; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
21 import java.util.Arrays; |
146
8c9f729f4dfa
Timezone finally in use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
137
diff
changeset
|
22 import java.util.Calendar; |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
23 import java.util.Collections; |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
24 import java.util.Date; |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
25 import java.util.Formatter; |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
26 import java.util.HashMap; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
27 import java.util.List; |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
28 import java.util.Locale; |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
29 import java.util.Map; |
146
8c9f729f4dfa
Timezone finally in use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
137
diff
changeset
|
30 import java.util.TimeZone; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
31 |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
32 import org.tmatesoft.hg.core.Nodeid; |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
33 import org.tmatesoft.hg.internal.RevlogStream; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
34 |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 /** |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * Representation of the Mercurial changelog file (list of ChangeSets) |
153 | 37 * |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
38 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
48
diff
changeset
|
39 * @author TMate Software Ltd. |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 */ |
97
ee2c750b036d
Changelog to HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
41 public class HgChangelog extends Revlog { |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 |
153 | 43 /* package-local */HgChangelog(HgRepository hgRepo, RevlogStream content) { |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
44 super(hgRepo, content); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
45 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
46 |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
47 public void all(final HgChangelog.Inspector inspector) { |
137
144d771ee73c
explicit op name instead math op to get last rev number
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
135
diff
changeset
|
48 range(0, getLastRevision(), inspector); |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
49 } |
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
50 |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
51 public void range(int start, int end, final HgChangelog.Inspector inspector) { |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
52 RevlogStream.Inspector i = new RevlogStream.Inspector() { |
153 | 53 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
54 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
55 RawChangeset cset = RawChangeset.parse(data, 0, data.length); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
56 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
21
diff
changeset
|
57 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
58 } |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
59 }; |
48
e34f90b9ded1
Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
60 content.iterate(start, end, true, i); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
61 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
62 |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
63 public List<RawChangeset> range(int start, int end) { |
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
64 final ArrayList<RawChangeset> rv = new ArrayList<RawChangeset>(end - start + 1); |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
65 RevlogStream.Inspector i = new RevlogStream.Inspector() { |
153 | 66 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
67 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
68 RawChangeset cset = RawChangeset.parse(data, 0, data.length); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
69 rv.add(cset); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
70 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
71 }; |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
72 content.iterate(start, end, true, i); |
153 | 73 return rv; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
74 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
75 |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
76 public void range(final HgChangelog.Inspector inspector, final int... revisions) { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
77 if (revisions == null || revisions.length == 0) { |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
78 return; |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
79 } |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
80 RevlogStream.Inspector i = new RevlogStream.Inspector() { |
153 | 81 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
82 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
83 if (Arrays.binarySearch(revisions, revisionNumber) >= 0) { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
84 RawChangeset cset = RawChangeset.parse(data, 0, data.length); |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
21
diff
changeset
|
85 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
86 } |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
87 } |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
88 }; |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
89 Arrays.sort(revisions); |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
90 content.iterate(revisions[0], revisions[revisions.length - 1], true, i); |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
91 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
92 |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
93 public interface Inspector { |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
94 // TODO describe whether cset is new instance each time |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
95 void next(int revisionNumber, Nodeid nodeid, RawChangeset cset); |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
96 } |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
97 |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
98 /** |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
99 * Entry in the Changelog |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
100 */ |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
101 public static class RawChangeset implements Cloneable /* for those that would like to keep a copy */{ |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
102 // TODO immutable |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
103 private/* final */Nodeid manifest; |
153 | 104 private String user; |
105 private String comment; | |
106 private List<String> files; // unmodifiable collection (otherwise #files() and implicit #clone() shall be revised) | |
107 private Date time; | |
108 private int timezone; | |
109 private Map<String, String> extras; | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
110 |
153 | 111 /** |
112 * @see mercurial/changelog.py:read() | |
113 * | |
114 * <pre> | |
115 * format used: | |
116 * nodeid\n : manifest node in ascii | |
117 * user\n : user, no \n or \r allowed | |
118 * time tz extra\n : date (time is int or float, timezone is int) | |
119 * : extra is metadatas, encoded and separated by '\0' | |
120 * : older versions ignore it | |
121 * files\n\n : files modified by the cset, no \n or \r allowed | |
122 * (.*) : comment (free text, ideally utf-8) | |
123 * | |
124 * changelog v0 doesn't use extra | |
125 * </pre> | |
126 */ | |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
127 private RawChangeset() { |
153 | 128 } |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
129 |
153 | 130 public Nodeid manifest() { |
131 return manifest; | |
132 } | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
133 |
153 | 134 public String user() { |
135 return user; | |
136 } | |
137 | |
138 public String comment() { | |
139 return comment; | |
140 } | |
141 | |
142 public List<String> files() { | |
143 return files; | |
144 } | |
145 | |
146 public Date date() { | |
147 return time; | |
148 } | |
149 | |
150 public String dateString() { | |
151 // XXX keep once formatted? Perhaps, there's faster way to set up calendar/time zone? | |
152 StringBuilder sb = new StringBuilder(30); | |
153 Formatter f = new Formatter(sb, Locale.US); | |
154 TimeZone tz = TimeZone.getTimeZone("GMT"); | |
155 // apparently timezone field records number of seconds time differs from UTC, | |
156 // i.e. value to substract from time to get UTC time. Calendar seems to add | |
157 // timezone offset to UTC, instead, hence sign change. | |
158 tz.setRawOffset(timezone * -1000); | |
159 Calendar c = Calendar.getInstance(tz, Locale.US); | |
160 c.setTime(time); | |
161 f.format("%ta %<tb %<td %<tH:%<tM:%<tS %<tY %<tz", c); | |
162 return sb.toString(); | |
163 } | |
164 | |
165 public Map<String, String> extras() { | |
166 return extras; | |
167 } | |
168 | |
169 public String branch() { | |
170 return extras.get("branch"); | |
171 } | |
172 | |
173 @Override | |
174 public String toString() { | |
175 StringBuilder sb = new StringBuilder(); | |
176 sb.append("Changeset {"); | |
177 sb.append("User: ").append(user).append(", "); | |
178 sb.append("Comment: ").append(comment).append(", "); | |
179 sb.append("Manifest: ").append(manifest).append(", "); | |
180 sb.append("Date: ").append(time).append(", "); | |
181 sb.append("Files: ").append(files.size()); | |
182 for (String s : files) { | |
183 sb.append(", ").append(s); | |
184 } | |
185 if (extras != null) { | |
186 sb.append(", Extra: ").append(extras); | |
187 } | |
188 sb.append("}"); | |
189 return sb.toString(); | |
190 } | |
191 | |
192 @Override | |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
193 public RawChangeset clone() { |
153 | 194 try { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
195 return (RawChangeset) super.clone(); |
153 | 196 } catch (CloneNotSupportedException ex) { |
197 throw new InternalError(ex.toString()); | |
198 } | |
199 } | |
200 | |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
201 public static RawChangeset parse(byte[] data, int offset, int length) { |
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
202 RawChangeset rv = new RawChangeset(); |
153 | 203 rv.init(data, offset, length); |
204 return rv; | |
205 } | |
206 | |
207 /* package-local */void init(byte[] data, int offset, int length) { | |
208 final int bufferEndIndex = offset + length; | |
209 final byte lineBreak = (byte) '\n'; | |
210 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex); | |
211 if (breakIndex1 == -1) { | |
212 throw new IllegalArgumentException("Bad Changeset data"); | |
213 } | |
214 Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1); | |
215 int breakIndex2 = indexOf(data, lineBreak, breakIndex1 + 1, bufferEndIndex); | |
216 if (breakIndex2 == -1) { | |
217 throw new IllegalArgumentException("Bad Changeset data"); | |
218 } | |
219 String _user = new String(data, breakIndex1 + 1, breakIndex2 - breakIndex1 - 1); | |
220 int breakIndex3 = indexOf(data, lineBreak, breakIndex2 + 1, bufferEndIndex); | |
221 if (breakIndex3 == -1) { | |
222 throw new IllegalArgumentException("Bad Changeset data"); | |
223 } | |
224 String _timeString = new String(data, breakIndex2 + 1, breakIndex3 - breakIndex2 - 1); | |
225 int space1 = _timeString.indexOf(' '); | |
226 if (space1 == -1) { | |
227 throw new IllegalArgumentException("Bad Changeset data"); | |
228 } | |
229 int space2 = _timeString.indexOf(' ', space1 + 1); | |
230 if (space2 == -1) { | |
231 space2 = _timeString.length(); | |
232 } | |
233 long unixTime = Long.parseLong(_timeString.substring(0, space1)); // XXX Float, perhaps | |
234 int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2)); | |
235 // 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 | |
236 // on commit and timezone is recorded to adjust it to UTC. | |
237 Date _time = new Date(unixTime * 1000); | |
238 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null; | |
239 Map<String, String> _extrasMap; | |
240 if (_extras == null) { | |
241 _extrasMap = Collections.singletonMap("branch", "default"); | |
242 } else { | |
243 _extrasMap = new HashMap<String, String>(); | |
244 for (String pair : _extras.split("\00")) { | |
245 int eq = pair.indexOf(':'); | |
246 // FIXME need to decode key/value, @see changelog.py:decodeextra | |
247 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1)); | |
248 } | |
249 if (!_extrasMap.containsKey("branch")) { | |
250 _extrasMap.put("branch", "default"); | |
251 } | |
252 _extrasMap = Collections.unmodifiableMap(_extrasMap); | |
253 } | |
254 | |
255 // | |
256 int lastStart = breakIndex3 + 1; | |
257 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); | |
258 ArrayList<String> _files = null; | |
259 if (breakIndex4 > lastStart) { | |
260 // if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision) | |
261 _files = new ArrayList<String>(5); | |
262 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) { | |
263 _files.add(new String(data, lastStart, breakIndex4 - lastStart)); | |
264 lastStart = breakIndex4 + 1; | |
265 if (data[breakIndex4 + 1] == lineBreak) { | |
266 // found \n\n | |
267 break; | |
268 } else { | |
269 breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
270 } |
153 | 271 } |
272 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) { | |
273 throw new IllegalArgumentException("Bad Changeset data"); | |
274 } | |
275 } else { | |
276 breakIndex4--; | |
277 } | |
278 String _comment; | |
279 try { | |
280 _comment = new String(data, breakIndex4 + 2, bufferEndIndex - breakIndex4 - 2, "UTF-8"); | |
281 // FIXME respect ui.fallbackencoding and try to decode if set | |
282 } catch (UnsupportedEncodingException ex) { | |
283 _comment = ""; | |
284 throw new IllegalStateException("Could hardly happen"); | |
285 } | |
286 // change this instance at once, don't leave it partially changes in case of error | |
287 this.manifest = _nodeid; | |
288 this.user = _user; | |
289 this.time = _time; | |
290 this.timezone = _timezone; | |
291 this.files = _files == null ? Collections.<String> emptyList() : Collections.unmodifiableList(_files); | |
292 this.comment = _comment; | |
293 this.extras = _extrasMap; | |
294 } | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
295 |
153 | 296 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) { |
297 for (int i = startOffset; i < endIndex; i++) { | |
298 if (src[i] == what) { | |
299 return i; | |
300 } | |
301 } | |
302 return -1; | |
303 } | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
304 } |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
305 |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
306 } |