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