annotate src/org/tmatesoft/hg/repo/HgChangelog.java @ 153:ab7ea2ac21cb

Format code
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 24 Feb 2011 21:38:46 +0100
parents 8c9f729f4dfa
children ba2bf656f00f
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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) {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
55 Changeset cset = Changeset.parse(data, 0, data.length);
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
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
63 public List<Changeset> range(int start, int end) {
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
64 final ArrayList<Changeset> rv = new ArrayList<Changeset>(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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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) {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
68 Changeset cset = Changeset.parse(data, 0, data.length);
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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) {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
84 Changeset cset = Changeset.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
645829962785 core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
95 void next(int revisionNumber, Nodeid nodeid, Changeset cset);
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 */
645829962785 core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
101 public static class Changeset implements Cloneable /* for those that would like to keep a copy */{
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
104 private String user;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
105 private String comment;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
106 private List<String> files; // unmodifiable collection (otherwise #files() and implicit #clone() shall be revised)
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
107 private Date time;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
108 private int timezone;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
111 /**
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
112 * @see mercurial/changelog.py:read()
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
113 *
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
114 * <pre>
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
115 * format used:
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
116 * nodeid\n : manifest node in ascii
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
117 * user\n : user, no \n or \r allowed
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
118 * time tz extra\n : date (time is int or float, timezone is int)
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
119 * : extra is metadatas, encoded and separated by '\0'
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
120 * : older versions ignore it
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
121 * files\n\n : files modified by the cset, no \n or \r allowed
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
122 * (.*) : comment (free text, ideally utf-8)
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
123 *
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
124 * changelog v0 doesn't use extra
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
125 * </pre>
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
126 */
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
127 private Changeset() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
130 public Nodeid manifest() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
131 return manifest;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
134 public String user() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
135 return user;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
136 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
137
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
138 public String comment() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
139 return comment;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
140 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
141
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
142 public List<String> files() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
143 return files;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
144 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
145
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
146 public Date date() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
147 return time;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
148 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
149
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
150 public String dateString() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
151 // XXX keep once formatted? Perhaps, there's faster way to set up calendar/time zone?
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
152 StringBuilder sb = new StringBuilder(30);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
153 Formatter f = new Formatter(sb, Locale.US);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
154 TimeZone tz = TimeZone.getTimeZone("GMT");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
155 // apparently timezone field records number of seconds time differs from UTC,
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
156 // i.e. value to substract from time to get UTC time. Calendar seems to add
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
157 // timezone offset to UTC, instead, hence sign change.
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
158 tz.setRawOffset(timezone * -1000);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
159 Calendar c = Calendar.getInstance(tz, Locale.US);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
160 c.setTime(time);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
161 f.format("%ta %<tb %<td %<tH:%<tM:%<tS %<tY %<tz", c);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
162 return sb.toString();
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
163 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
164
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
165 public Map<String, String> extras() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
166 return extras;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
167 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
168
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
169 public String branch() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
170 return extras.get("branch");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
171 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
172
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
173 @Override
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
174 public String toString() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
175 StringBuilder sb = new StringBuilder();
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
176 sb.append("Changeset {");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
177 sb.append("User: ").append(user).append(", ");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
178 sb.append("Comment: ").append(comment).append(", ");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
179 sb.append("Manifest: ").append(manifest).append(", ");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
180 sb.append("Date: ").append(time).append(", ");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
181 sb.append("Files: ").append(files.size());
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
182 for (String s : files) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
183 sb.append(", ").append(s);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
184 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
185 if (extras != null) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
186 sb.append(", Extra: ").append(extras);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
187 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
188 sb.append("}");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
189 return sb.toString();
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
190 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
191
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
192 @Override
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
193 public Changeset clone() {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
194 try {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
195 return (Changeset) super.clone();
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
196 } catch (CloneNotSupportedException ex) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
197 throw new InternalError(ex.toString());
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
198 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
199 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
200
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
201 public static Changeset parse(byte[] data, int offset, int length) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
202 Changeset rv = new Changeset();
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
203 rv.init(data, offset, length);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
204 return rv;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
205 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
206
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
207 /* package-local */void init(byte[] data, int offset, int length) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
208 final int bufferEndIndex = offset + length;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
209 final byte lineBreak = (byte) '\n';
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
210 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
211 if (breakIndex1 == -1) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
212 throw new IllegalArgumentException("Bad Changeset data");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
213 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
214 Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
215 int breakIndex2 = indexOf(data, lineBreak, breakIndex1 + 1, bufferEndIndex);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
216 if (breakIndex2 == -1) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
217 throw new IllegalArgumentException("Bad Changeset data");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
218 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
219 String _user = new String(data, breakIndex1 + 1, breakIndex2 - breakIndex1 - 1);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
220 int breakIndex3 = indexOf(data, lineBreak, breakIndex2 + 1, bufferEndIndex);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
221 if (breakIndex3 == -1) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
222 throw new IllegalArgumentException("Bad Changeset data");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
223 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
224 String _timeString = new String(data, breakIndex2 + 1, breakIndex3 - breakIndex2 - 1);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
225 int space1 = _timeString.indexOf(' ');
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
226 if (space1 == -1) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
227 throw new IllegalArgumentException("Bad Changeset data");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
228 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
229 int space2 = _timeString.indexOf(' ', space1 + 1);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
230 if (space2 == -1) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
231 space2 = _timeString.length();
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
232 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
233 long unixTime = Long.parseLong(_timeString.substring(0, space1)); // XXX Float, perhaps
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
234 int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2));
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
236 // on commit and timezone is recorded to adjust it to UTC.
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
237 Date _time = new Date(unixTime * 1000);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
238 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
239 Map<String, String> _extrasMap;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
240 if (_extras == null) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
241 _extrasMap = Collections.singletonMap("branch", "default");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
242 } else {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
243 _extrasMap = new HashMap<String, String>();
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
244 for (String pair : _extras.split("\00")) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
245 int eq = pair.indexOf(':');
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
246 // FIXME need to decode key/value, @see changelog.py:decodeextra
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
247 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1));
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
248 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
249 if (!_extrasMap.containsKey("branch")) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
250 _extrasMap.put("branch", "default");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
251 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
252 _extrasMap = Collections.unmodifiableMap(_extrasMap);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
253 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
254
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
255 //
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
256 int lastStart = breakIndex3 + 1;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
257 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
258 ArrayList<String> _files = null;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
259 if (breakIndex4 > lastStart) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
260 // if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision)
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
261 _files = new ArrayList<String>(5);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
262 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
263 _files.add(new String(data, lastStart, breakIndex4 - lastStart));
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
264 lastStart = breakIndex4 + 1;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
265 if (data[breakIndex4 + 1] == lineBreak) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
266 // found \n\n
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
267 break;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
268 } else {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
271 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
272 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
273 throw new IllegalArgumentException("Bad Changeset data");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
274 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
275 } else {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
276 breakIndex4--;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
277 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
278 String _comment;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
279 try {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
280 _comment = new String(data, breakIndex4 + 2, bufferEndIndex - breakIndex4 - 2, "UTF-8");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
281 // FIXME respect ui.fallbackencoding and try to decode if set
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
282 } catch (UnsupportedEncodingException ex) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
283 _comment = "";
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
284 throw new IllegalStateException("Could hardly happen");
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
285 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
286 // change this instance at once, don't leave it partially changes in case of error
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
287 this.manifest = _nodeid;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
288 this.user = _user;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
289 this.time = _time;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
290 this.timezone = _timezone;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
291 this.files = _files == null ? Collections.<String> emptyList() : Collections.unmodifiableList(_files);
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
292 this.comment = _comment;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
293 this.extras = _extrasMap;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
296 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
297 for (int i = startOffset; i < endIndex; i++) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
298 if (src[i] == what) {
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
299 return i;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
300 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
301 }
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
302 return -1;
ab7ea2ac21cb Format code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 146
diff changeset
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 }