comparison src/com/tmate/hgkit/ll/Changeset.java @ 5:fc265ddeab26

File content and non-effective, although working, patch application
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 21 Dec 2010 05:11:06 +0100
parents 24bb4f365164
children 50dfc69c108e
comparison
equal deleted inserted replaced
4:aa1912c70b36 5:fc265ddeab26
42 } 42 }
43 } 43 }
44 44
45 public static Changeset parse(byte[] data, int offset, int length) { 45 public static Changeset parse(byte[] data, int offset, int length) {
46 Changeset rv = new Changeset(); 46 Changeset rv = new Changeset();
47 rv.init(data, offset, length);
48 return rv;
49 }
50
51 /*package-local*/ void init(byte[] data, int offset, int length) {
47 final int bufferEndIndex = offset + length; 52 final int bufferEndIndex = offset + length;
48 final byte lineBreak = (byte) '\n'; 53 final byte lineBreak = (byte) '\n';
49 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex); 54 int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex);
50 if (breakIndex1 == -1) { 55 if (breakIndex1 == -1) {
51 throw new IllegalArgumentException("Bad Changeset data"); 56 throw new IllegalArgumentException("Bad Changeset data");
52 } 57 }
53 rv.nodeid = Nodeid.fromAscii(data, 0, breakIndex1); 58 Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1);
54 int breakIndex2 = indexOf(data, lineBreak, breakIndex1+1, bufferEndIndex); 59 int breakIndex2 = indexOf(data, lineBreak, breakIndex1+1, bufferEndIndex);
55 if (breakIndex2 == -1) { 60 if (breakIndex2 == -1) {
56 throw new IllegalArgumentException("Bad Changeset data"); 61 throw new IllegalArgumentException("Bad Changeset data");
57 } 62 }
58 rv.user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1); 63 String _user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1);
59 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex); 64 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex);
60 if (breakIndex3 == -1) { 65 if (breakIndex3 == -1) {
61 throw new IllegalArgumentException("Bad Changeset data"); 66 throw new IllegalArgumentException("Bad Changeset data");
62 } 67 }
63 rv.timezone = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1); 68 String _timezone = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1);
64 69
65 // 70 //
66 int lastStart = breakIndex3 + 1; 71 int lastStart = breakIndex3 + 1;
67 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); 72 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
68 rv.files = new ArrayList<String>(5); 73 ArrayList<String> _files = new ArrayList<String>(5);
69 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) { 74 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) {
70 rv.files.add(new String(data, lastStart, breakIndex4 - lastStart)); 75 _files.add(new String(data, lastStart, breakIndex4 - lastStart));
71 lastStart = breakIndex4 + 1; 76 lastStart = breakIndex4 + 1;
72 if (data[breakIndex4 + 1] == lineBreak) { 77 if (data[breakIndex4 + 1] == lineBreak) {
73 // found \n\n 78 // found \n\n
74 break; 79 break;
75 } else { 80 } else {
77 } 82 }
78 } 83 }
79 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) { 84 if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) {
80 throw new IllegalArgumentException("Bad Changeset data"); 85 throw new IllegalArgumentException("Bad Changeset data");
81 } 86 }
87 String _comment;
82 try { 88 try {
83 rv.comment = new String(data, breakIndex4+2, bufferEndIndex - breakIndex4 - 2, "UTF-8"); 89 _comment = new String(data, breakIndex4+2, bufferEndIndex - breakIndex4 - 2, "UTF-8");
84 } catch (UnsupportedEncodingException ex) { 90 } catch (UnsupportedEncodingException ex) {
85 rv.comment = ""; 91 _comment = "";
86 throw new IllegalStateException("Could hardly happen"); 92 throw new IllegalStateException("Could hardly happen");
87 } 93 }
88 return rv; 94 // change this instance at once, don't leave it partially changes in case of error
95 this.nodeid = _nodeid;
96 this.user = _user;
97 this.timezone = _timezone;
98 this.files = _files;
99 this.comment = _comment;
89 } 100 }
90 101
91 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) { 102 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) {
92 for (int i = startOffset; i < endIndex; i++) { 103 for (int i = startOffset; i < endIndex; i++) {
93 if (src[i] == what) { 104 if (src[i] == what) {