Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/Changeset.java @ 127:2e395db595e2
Moved HgStatus to toplevel
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 16 Feb 2011 18:42:10 +0100 |
parents | a3a2e5deb320 |
children | 44b97930570c |
rev | line source |
---|---|
38
50dfc69c108e
Nodeid is confusing, denote it's reference to manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
5
diff
changeset
|
1 /* |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
2 * Copyright (c) 2010-2011 TMate Software Ltd |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
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:
64
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:
64
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:
64
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
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:
64
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:
64
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:
64
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
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:
64
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:
87
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:
64
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.UnsupportedEncodingException; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.util.ArrayList; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
21 import java.util.Collections; |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
22 import java.util.Date; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
23 import java.util.Formatter; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
24 import java.util.HashMap; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
25 import java.util.List; |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
26 import java.util.Locale; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
27 import java.util.Map; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
29 import org.tmatesoft.hg.core.Nodeid; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
30 |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 /** |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 * @see mercurial/changelog.py:read() |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * <pre> |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 format used: |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 nodeid\n : manifest node in ascii |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 user\n : user, no \n or \r allowed |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 time tz extra\n : date (time is int or float, timezone is int) |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 : extra is metadatas, encoded and separated by '\0' |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 : older versions ignore it |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 files\n\n : files modified by the cset, no \n or \r allowed |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 (.*) : comment (free text, ideally utf-8) |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 changelog v0 doesn't use extra |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 * </pre> |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
45 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
46 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
47 * @author TMate Software Ltd. |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 */ |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
49 public class Changeset implements Cloneable /*for those that would like to keep a copy*/ { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
50 // TODO immutable |
38
50dfc69c108e
Nodeid is confusing, denote it's reference to manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
5
diff
changeset
|
51 private /*final*/ Nodeid manifest; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 private String user; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 private String comment; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
54 private List<String> files; // unmodifiable collection (otherwise #files() and implicit #clone() shall be revised) |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
55 private Date time; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
56 private int timezone; // not sure it's of any use |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
57 private Map<String,String> extras; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
59 private Changeset() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
60 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
61 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
62 public Nodeid manifest() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
63 return manifest; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
64 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
65 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
66 public String user() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
67 return user; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
68 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
69 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
70 public String comment() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
71 return comment; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
72 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
73 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
74 public List<String> files() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
75 return files; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
76 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
77 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
78 public Date date() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
79 return time; |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
80 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
81 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
82 public String dateString() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
83 StringBuilder sb = new StringBuilder(30); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
84 Formatter f = new Formatter(sb, Locale.US); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
85 f.format("%ta %<tb %<td %<tH:%<tM:%<tS %<tY %<tz", time); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
86 return sb.toString(); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
87 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
88 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
89 public Map<String, String> extras() { |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
90 return extras; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
91 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
92 |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
93 public String branch() { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
94 return extras.get("branch"); |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
95 } |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
96 |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
97 @Override |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
98 public String toString() { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
99 StringBuilder sb = new StringBuilder(); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
100 sb.append("Changeset {"); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
101 sb.append("User: ").append(user).append(", "); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
102 sb.append("Comment: ").append(comment).append(", "); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
103 sb.append("Manifest: ").append(manifest).append(", "); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
104 sb.append("Date: ").append(time).append(", "); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
105 sb.append("Files: ").append(files.size()); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
106 for (String s : files) { |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
107 sb.append(", ").append(s); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
108 } |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
109 if (extras != null) { |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
110 sb.append(", Extra: ").append(extras); |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
111 } |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
112 sb.append("}"); |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
113 return sb.toString(); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 } |
64
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
115 |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
116 @Override |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
117 public Changeset clone() { |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
118 try { |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
119 return (Changeset) super.clone(); |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
120 } catch (CloneNotSupportedException ex) { |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
121 throw new InternalError(ex.toString()); |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
122 } |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
54
diff
changeset
|
123 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
125 public static Changeset parse(byte[] data, int offset, int length) { |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
126 Changeset rv = new Changeset(); |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
127 rv.init(data, offset, length); |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
128 return rv; |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
129 } |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
130 |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
131 /*package-local*/ void init(byte[] data, int offset, int length) { |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 final int bufferEndIndex = offset + length; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 final byte lineBreak = (byte) '\n'; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
134 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 if (breakIndex1 == -1) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
138 Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
139 int breakIndex2 = indexOf(data, lineBreak, breakIndex1+1, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 if (breakIndex2 == -1) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
143 String _user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
144 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 if (breakIndex3 == -1) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 throw new IllegalArgumentException("Bad Changeset data"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 } |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
148 String _timeString = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
149 int space1 = _timeString.indexOf(' '); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
150 if (space1 == -1) { |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
151 throw new IllegalArgumentException("Bad Changeset data"); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
152 } |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
153 int space2 = _timeString.indexOf(' ', space1+1); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
154 if (space2 == -1) { |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
155 space2 = _timeString.length(); |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
156 } |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
157 long unixTime = Long.parseLong(_timeString.substring(0, space1)); // XXX Float, perhaps |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
158 int _timezone = Integer.parseInt(_timeString.substring(space1+1, space2)); |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
159 // 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 |
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
160 // on commit and timezone is recorded to adjust it to UTC. |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
161 Date _time = new Date(unixTime * 1000); |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
162 String _extras = space2 < _timeString.length() ? _timeString.substring(space2+1) : null; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
163 Map<String, String> _extrasMap; |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
164 if (_extras == null) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
165 _extrasMap = Collections.singletonMap("branch", "default"); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
166 } else { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
167 _extrasMap = new HashMap<String, String>(); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
168 for (String pair : _extras.split("\00")) { |
54
fd4f2c98995b
Correct split symbol for extra metadata
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
169 int eq = pair.indexOf(':'); |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
170 // FIXME need to decode key/value, @see changelog.py:decodeextra |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
171 _extrasMap.put(pair.substring(0, eq), pair.substring(eq+1)); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
172 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
173 if (!_extrasMap.containsKey("branch")) { |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
174 _extrasMap.put("branch", "default"); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
175 } |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
176 _extrasMap = Collections.unmodifiableMap(_extrasMap); |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
177 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 // |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 int lastStart = breakIndex3 + 1; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
181 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); |
87
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
182 ArrayList<String> _files = null; |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
183 if (breakIndex4 > lastStart) { |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
184 // if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision) |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
185 _files = new ArrayList<String>(5); |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
186 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) { |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
187 _files.add(new String(data, lastStart, breakIndex4 - lastStart)); |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
188 lastStart = breakIndex4 + 1; |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
189 if (data[breakIndex4 + 1] == lineBreak) { |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
190 // found \n\n |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
191 break; |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
192 } else { |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
193 breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
194 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 } |
87
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
196 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) { |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
197 throw new IllegalArgumentException("Bad Changeset data"); |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
198 } |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
199 } else { |
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
200 breakIndex4--; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
202 String _comment; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
203 try { |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
204 _comment = new String(data, breakIndex4+2, bufferEndIndex - breakIndex4 - 2, "UTF-8"); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 } catch (UnsupportedEncodingException ex) { |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
206 _comment = ""; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 throw new IllegalStateException("Could hardly happen"); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
208 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
209 // change this instance at once, don't leave it partially changes in case of error |
38
50dfc69c108e
Nodeid is confusing, denote it's reference to manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
5
diff
changeset
|
210 this.manifest = _nodeid; |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
211 this.user = _user; |
40
21e26da142fa
Time parsing in Changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
38
diff
changeset
|
212 this.time = _time; |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
213 this.timezone = _timezone; |
87
25f2e5d1cd8b
Fix IAE when changeset has no files listed (merged revision)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
214 this.files = _files == null ? Collections.<String>emptyList() : Collections.unmodifiableList(_files); |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
215 this.comment = _comment; |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
216 this.extras = _extrasMap; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
217 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
218 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
219 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
220 for (int i = startOffset; i < endIndex; i++) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
221 if (src[i] == what) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
222 return i; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
223 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
224 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
225 return -1; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
226 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
227 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
228 public interface Inspector { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
229 // first(), last(), single(). |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
230 // <T> |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
231 // TODO describe whether cset is new instance each time |
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
40
diff
changeset
|
232 void next(int revisionNumber, Nodeid nodeid, Changeset cset); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
233 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
234 } |