Mercurial > hg4j
annotate src/org/tmatesoft/hg/repo/HgChangelog.java @ 195:c9b305df0b89
Optimization: use ParentWalker to get changeset's parents, if possible. Do not keep duplicating nodeids and strings in manifest revisions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 15 Apr 2011 05:17:44 +0200 |
parents | f26ffe04ced0 |
children | e2115da4cf6a |
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 |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
161
diff
changeset
|
97 // describe what revisionNumber is when Inspector is used with HgBundle (BAD_REVISION or bundle's local order?) |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
98 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
|
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 /** |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
102 * 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
|
103 */ |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
104 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
|
105 // TODO immutable |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
106 private/* final */Nodeid manifest; |
153 | 107 private String user; |
108 private String comment; | |
109 private List<String> files; // unmodifiable collection (otherwise #files() and implicit #clone() shall be revised) | |
110 private Date time; | |
111 private int timezone; | |
161
9423235ca77b
Record possible value (and knowledge source) for extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
112 // http://mercurial.selenic.com/wiki/PruningDeadBranches - Closing changesets can be identified by close=1 in the changeset's extra field. |
153 | 113 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
|
114 |
153 | 115 /** |
116 * @see mercurial/changelog.py:read() | |
117 * | |
118 * <pre> | |
119 * format used: | |
120 * nodeid\n : manifest node in ascii | |
121 * user\n : user, no \n or \r allowed | |
122 * time tz extra\n : date (time is int or float, timezone is int) | |
123 * : extra is metadatas, encoded and separated by '\0' | |
124 * : older versions ignore it | |
125 * files\n\n : files modified by the cset, no \n or \r allowed | |
126 * (.*) : comment (free text, ideally utf-8) | |
127 * | |
128 * changelog v0 doesn't use extra | |
129 * </pre> | |
130 */ | |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
131 private RawChangeset() { |
153 | 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 Nodeid manifest() { |
135 return manifest; | |
136 } | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
137 |
153 | 138 public String user() { |
139 return user; | |
140 } | |
141 | |
142 public String comment() { | |
143 return comment; | |
144 } | |
145 | |
146 public List<String> files() { | |
147 return files; | |
148 } | |
149 | |
150 public Date date() { | |
151 return time; | |
152 } | |
153 | |
154 public String dateString() { | |
155 // XXX keep once formatted? Perhaps, there's faster way to set up calendar/time zone? | |
156 StringBuilder sb = new StringBuilder(30); | |
157 Formatter f = new Formatter(sb, Locale.US); | |
158 TimeZone tz = TimeZone.getTimeZone("GMT"); | |
159 // apparently timezone field records number of seconds time differs from UTC, | |
160 // i.e. value to substract from time to get UTC time. Calendar seems to add | |
161 // timezone offset to UTC, instead, hence sign change. | |
162 tz.setRawOffset(timezone * -1000); | |
163 Calendar c = Calendar.getInstance(tz, Locale.US); | |
164 c.setTime(time); | |
165 f.format("%ta %<tb %<td %<tH:%<tM:%<tS %<tY %<tz", c); | |
166 return sb.toString(); | |
167 } | |
168 | |
169 public Map<String, String> extras() { | |
170 return extras; | |
171 } | |
172 | |
173 public String branch() { | |
174 return extras.get("branch"); | |
175 } | |
176 | |
177 @Override | |
178 public String toString() { | |
179 StringBuilder sb = new StringBuilder(); | |
180 sb.append("Changeset {"); | |
181 sb.append("User: ").append(user).append(", "); | |
182 sb.append("Comment: ").append(comment).append(", "); | |
183 sb.append("Manifest: ").append(manifest).append(", "); | |
184 sb.append("Date: ").append(time).append(", "); | |
185 sb.append("Files: ").append(files.size()); | |
186 for (String s : files) { | |
187 sb.append(", ").append(s); | |
188 } | |
189 if (extras != null) { | |
190 sb.append(", Extra: ").append(extras); | |
191 } | |
192 sb.append("}"); | |
193 return sb.toString(); | |
194 } | |
195 | |
196 @Override | |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
197 public RawChangeset clone() { |
153 | 198 try { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
153
diff
changeset
|
199 return (RawChangeset) super.clone(); |
153 | 200 } catch (CloneNotSupportedException ex) { |
201 throw new InternalError(ex.toString()); | |
202 } | |
203 } | |
204 | |
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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 } 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
|
212 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
|
213 } |
153 | 214 } |
215 | |
216 /* package-local */void init(byte[] data, int offset, int length) { | |
217 final int bufferEndIndex = offset + length; | |
218 final byte lineBreak = (byte) '\n'; | |
219 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex); | |
220 if (breakIndex1 == -1) { | |
221 throw new IllegalArgumentException("Bad Changeset data"); | |
222 } | |
223 Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1); | |
224 int breakIndex2 = indexOf(data, lineBreak, breakIndex1 + 1, bufferEndIndex); | |
225 if (breakIndex2 == -1) { | |
226 throw new IllegalArgumentException("Bad Changeset data"); | |
227 } | |
228 String _user = new String(data, breakIndex1 + 1, breakIndex2 - breakIndex1 - 1); | |
229 int breakIndex3 = indexOf(data, lineBreak, breakIndex2 + 1, bufferEndIndex); | |
230 if (breakIndex3 == -1) { | |
231 throw new IllegalArgumentException("Bad Changeset data"); | |
232 } | |
233 String _timeString = new String(data, breakIndex2 + 1, breakIndex3 - breakIndex2 - 1); | |
234 int space1 = _timeString.indexOf(' '); | |
235 if (space1 == -1) { | |
236 throw new IllegalArgumentException("Bad Changeset data"); | |
237 } | |
238 int space2 = _timeString.indexOf(' ', space1 + 1); | |
239 if (space2 == -1) { | |
240 space2 = _timeString.length(); | |
241 } | |
242 long unixTime = Long.parseLong(_timeString.substring(0, space1)); // XXX Float, perhaps | |
243 int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2)); | |
244 // 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 | |
245 // on commit and timezone is recorded to adjust it to UTC. | |
246 Date _time = new Date(unixTime * 1000); | |
247 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null; | |
248 Map<String, String> _extrasMap; | |
249 if (_extras == null) { | |
250 _extrasMap = Collections.singletonMap("branch", "default"); | |
251 } else { | |
252 _extrasMap = new HashMap<String, String>(); | |
253 for (String pair : _extras.split("\00")) { | |
254 int eq = pair.indexOf(':'); | |
255 // FIXME need to decode key/value, @see changelog.py:decodeextra | |
256 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1)); | |
257 } | |
258 if (!_extrasMap.containsKey("branch")) { | |
259 _extrasMap.put("branch", "default"); | |
260 } | |
261 _extrasMap = Collections.unmodifiableMap(_extrasMap); | |
262 } | |
263 | |
264 // | |
265 int lastStart = breakIndex3 + 1; | |
266 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); | |
267 ArrayList<String> _files = null; | |
268 if (breakIndex4 > lastStart) { | |
269 // if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision) | |
270 _files = new ArrayList<String>(5); | |
271 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) { | |
272 _files.add(new String(data, lastStart, breakIndex4 - lastStart)); | |
273 lastStart = breakIndex4 + 1; | |
274 if (data[breakIndex4 + 1] == lineBreak) { | |
275 // found \n\n | |
276 break; | |
277 } else { | |
278 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
|
279 } |
153 | 280 } |
281 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) { | |
282 throw new IllegalArgumentException("Bad Changeset data"); | |
283 } | |
284 } else { | |
285 breakIndex4--; | |
286 } | |
287 String _comment; | |
288 try { | |
289 _comment = new String(data, breakIndex4 + 2, bufferEndIndex - breakIndex4 - 2, "UTF-8"); | |
290 // FIXME respect ui.fallbackencoding and try to decode if set | |
291 } catch (UnsupportedEncodingException ex) { | |
292 _comment = ""; | |
293 throw new IllegalStateException("Could hardly happen"); | |
294 } | |
295 // change this instance at once, don't leave it partially changes in case of error | |
296 this.manifest = _nodeid; | |
297 this.user = _user; | |
298 this.time = _time; | |
299 this.timezone = _timezone; | |
300 this.files = _files == null ? Collections.<String> emptyList() : Collections.unmodifiableList(_files); | |
301 this.comment = _comment; | |
302 this.extras = _extrasMap; | |
303 } | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
304 |
153 | 305 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) { |
306 for (int i = startOffset; i < endIndex; i++) { | |
307 if (src[i] == what) { | |
308 return i; | |
309 } | |
310 } | |
311 return -1; | |
312 } | |
129
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
313 } |
645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
314 |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
315 } |