comparison src/com/tmate/hgkit/ll/Changeset.java @ 40:21e26da142fa

Time parsing in Changeset
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 14 Jan 2011 03:37:06 +0100
parents 50dfc69c108e
children b01500fe2604
comparison
equal deleted inserted replaced
39:4e9b66b07a28 40:21e26da142fa
3 */ 3 */
4 package com.tmate.hgkit.ll; 4 package com.tmate.hgkit.ll;
5 5
6 import java.io.UnsupportedEncodingException; 6 import java.io.UnsupportedEncodingException;
7 import java.util.ArrayList; 7 import java.util.ArrayList;
8 import java.util.Date;
9 import java.util.Locale;
8 10
9 /** 11 /**
10 * @see mercurial/changelog.py:read() 12 * @see mercurial/changelog.py:read()
11 * <pre> 13 * <pre>
12 format used: 14 format used:
26 // TODO immutable 28 // TODO immutable
27 private /*final*/ Nodeid manifest; 29 private /*final*/ Nodeid manifest;
28 private String user; 30 private String user;
29 private String comment; 31 private String comment;
30 private ArrayList<String> files; 32 private ArrayList<String> files;
31 private String timezone; // FIXME 33 private Date time;
34 private String extras; // TODO branch, etc.
32 35
33 public void dump() { 36 public void dump() {
34 System.out.println("User:" + user); 37 System.out.println("User: " + user);
35 System.out.println("Comment:" + comment); 38 System.out.println("Comment: " + comment);
36 System.out.println("Manifest:" + manifest); 39 System.out.println("Manifest: " + manifest);
37 System.out.println("Date:" + timezone); 40 System.out.printf(Locale.US, "Date: %ta %<tb %<td %<tH:%<tM:%<tS %<tY %<tz\n", time);
38 System.out.println("Files: " + files.size()); 41 System.out.println("Files: " + files.size());
42 if (extras != null) {
43 System.out.println("Extra: " + extras);
44 }
39 for (String s : files) { 45 for (String s : files) {
40 System.out.print('\t'); 46 System.out.print('\t');
41 System.out.println(s); 47 System.out.println(s);
42 } 48 }
43 } 49 }
63 String _user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1); 69 String _user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1);
64 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex); 70 int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex);
65 if (breakIndex3 == -1) { 71 if (breakIndex3 == -1) {
66 throw new IllegalArgumentException("Bad Changeset data"); 72 throw new IllegalArgumentException("Bad Changeset data");
67 } 73 }
68 String _timezone = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1); 74 String _timeString = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1);
75 int space1 = _timeString.indexOf(' ');
76 if (space1 == -1) {
77 throw new IllegalArgumentException("Bad Changeset data");
78 }
79 int space2 = _timeString.indexOf(' ', space1+1);
80 if (space2 == -1) {
81 space2 = _timeString.length();
82 }
83 long unixTime = Long.parseLong(_timeString.substring(0, space1)); // XXX Float, perhaps
84 int timezone = Integer.parseInt(_timeString.substring(space1+1, space2));
85 // 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
86 // on commit and timezone is recorded to adjust it to UTC.
87 Date _time = new Date((unixTime + timezone) * 1000);
88 String _extras = space2 < _timeString.length() ? _timeString.substring(space2+1) : null;
69 89
70 // 90 //
71 int lastStart = breakIndex3 + 1; 91 int lastStart = breakIndex3 + 1;
72 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); 92 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
73 ArrayList<String> _files = new ArrayList<String>(5); 93 ArrayList<String> _files = new ArrayList<String>(5);
92 throw new IllegalStateException("Could hardly happen"); 112 throw new IllegalStateException("Could hardly happen");
93 } 113 }
94 // change this instance at once, don't leave it partially changes in case of error 114 // change this instance at once, don't leave it partially changes in case of error
95 this.manifest = _nodeid; 115 this.manifest = _nodeid;
96 this.user = _user; 116 this.user = _user;
97 this.timezone = _timezone; 117 this.time = _time;
98 this.files = _files; 118 this.files = _files;
99 this.comment = _comment; 119 this.comment = _comment;
120 this.extras = _extras;
100 } 121 }
101 122
102 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) { 123 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) {
103 for (int i = startOffset; i < endIndex; i++) { 124 for (int i = startOffset; i < endIndex; i++) {
104 if (src[i] == what) { 125 if (src[i] == what) {