55 ! ! |
62 ! ! |
56 |
63 |
57 !HGCommandParser methodsFor:'parsing'! |
64 !HGCommandParser methodsFor:'parsing'! |
58 |
65 |
59 parseDate |
66 parseDate |
60 self shouldImplement |
67 | ts | |
|
68 ts := Timestamp readIso8601FormatFrom:stream. |
|
69 (stream peek == $+ or:[stream peek == $-]) ifFalse:[ |
|
70 self error:'Timezone expected, ' , stream peek , ' found' |
|
71 ]. |
|
72 stream next. |
|
73 4 timesRepeat:[ |
|
74 ('0123456789' includes: stream peek) ifFalse:[ |
|
75 self error:'Timezone expected, ' , stream peek , ' found' |
|
76 ]. |
|
77 stream next. |
|
78 ]. |
|
79 ^ts |
61 |
80 |
62 "Created: / 13-11-2012 / 10:22:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
81 "Created: / 13-11-2012 / 10:22:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
82 "Modified: / 13-11-2012 / 17:28:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
63 ! |
83 ! |
64 |
84 |
65 parseLog |
85 parseLog |
66 "Parse output of 'hg log' command, assuming the template given |
86 "Parse output of 'hg log' command, assuming the template given |
67 was HGCommandParser templateLog. Return a list of HGRevision." |
87 was HGCommandParser templateLog. Return a list of HGRevision." |
85 "Parse single revision entry, assuming the template given |
105 "Parse single revision entry, assuming the template given |
86 was HGCommandParser templateLog. Return a HGRevision." |
106 was HGCommandParser templateLog. Return a HGRevision." |
87 |
107 |
88 | rev line message | |
108 | rev line message | |
89 |
109 |
90 rev := HGRevision new. |
110 rev := HGChangeset new. |
91 rev setId: self parseNodeId. self nextLineEnd. |
111 rev setId: self parseNodeId. self nextLineEnd. |
92 rev setBranch: self nextLine. |
112 rev setBranch: self nextLine. |
93 rev setParent1Id: self parseNodeId. self nextSpace. |
113 rev setParent1Id: self parseNodeId. self nextSpace. |
94 rev setParent2Id: self parseNodeId. self nextLineEnd. |
114 rev setParent2Id: self parseNodeId. self nextSpace. self nextLineEnd. |
95 rev setAuthor: self nextLine. |
115 rev setAuthor: self nextLine. |
96 rev setDate: self parseDate. self nextLineEnd. |
116 rev setTimestamp: self parseDate. self nextLineEnd. |
97 message := String streamContents:[:s| |
117 message := String streamContents:[:s| |
98 [ line := self nextLine . line = '**EOE**' ] whileFalse:[ |
118 [ line := self nextLine . line = '**EOE**' ] whileFalse:[ |
99 s nextPutLine: line |
119 s nextPutLine: line |
100 ]. |
120 ]. |
101 ]. |
121 ]. |
102 rev setMessage: message |
122 rev setMessage: message. |
|
123 |
|
124 ^rev |
103 |
125 |
104 "Created: / 13-11-2012 / 09:45:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
126 "Created: / 13-11-2012 / 09:45:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
127 "Modified: / 13-11-2012 / 17:29:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
105 ! |
128 ! |
106 |
129 |
107 parseNodeId |
130 parseNodeId |
108 "Parses node id from stream and returns it. Support both, |
131 "Parses node id from stream and returns it. Support both, |
109 short and full node ids" |
132 short and full node ids" |
110 |
133 |
111 | c c2 sign short revno hash | |
134 ^HGNodeId readFrom: stream onError:[:msg|self error: msg] |
112 |
135 |
113 stream peek == $- ifTrue:[ |
136 |
114 stream next. |
|
115 sign := -1. |
|
116 ] ifFalse:[ |
|
117 sign := 1. |
|
118 ]. |
|
119 |
|
120 "/ Read revno... |
|
121 revno := 0. |
|
122 [ (c := stream peek) == $: ] whileFalse:[ |
|
123 c isDigit ifFalse:[ |
|
124 self error:'Digit ([0-9]) expected but ', c , 'found'. |
|
125 ]. |
|
126 revno := (revno * 10) + c digitValue. |
|
127 stream next. |
|
128 ]. |
|
129 stream next. "/eat : |
|
130 revno := revno * sign. |
|
131 |
|
132 "/ Read hash |
|
133 hash := ByteArray new: 20. |
|
134 short := true. |
|
135 1 to: 6 do:[:i| |
|
136 stream atEnd ifTrue:[ |
|
137 self error:'Unexpected end of stream, hex digit expected'. |
|
138 ]. |
|
139 c := stream peek. |
|
140 c isHexDigit ifFalse:[ |
|
141 self error:'Hex digit ([0-9a-z]) expected but ', c , ' found'. |
|
142 ]. |
|
143 stream next. |
|
144 stream atEnd ifTrue:[ |
|
145 self error:'Unexpected end of stream, hex digit expected'. |
|
146 ]. |
|
147 c2 := stream peek. |
|
148 c isHexDigit ifFalse:[ |
|
149 self error:'Hex digit ([0-9a-z]) expected but ', c , ' found'. |
|
150 ]. |
|
151 hash at:i put: (c digitValue << 4) + c2 digitValue. |
|
152 stream next. |
|
153 ]. |
|
154 stream peek isHexDigit ifTrue:[ |
|
155 "/OK, full 40-char node id |
|
156 short := false. |
|
157 7 to: 20 do:[:i| |
|
158 stream atEnd ifTrue:[ |
|
159 self error:'Unexpected end of stream, hex digit expected'. |
|
160 ]. |
|
161 c := stream peek. |
|
162 c isHexDigit ifFalse:[ |
|
163 self error:'Hex digit ([0-9a-z]) expected but ', c , ' found'. |
|
164 ]. |
|
165 stream next. |
|
166 stream atEnd ifTrue:[ |
|
167 self error:'Unexpected end of stream, hex digit expected'. |
|
168 ]. |
|
169 c2 := stream peek. |
|
170 c isHexDigit ifFalse:[ |
|
171 self error:'Hex digit ([0-9a-z]) expected but ', c , ' found'. |
|
172 ]. |
|
173 hash at:i put: (c digitValue << 4) + c2 digitValue. |
|
174 stream next. |
|
175 ]. |
|
176 ]. |
|
177 ^short ifTrue:[ |
|
178 self halt: 'Not yet supported' |
|
179 ] ifFalse:[ |
|
180 (HGNodeId fromBytes: hash) revno: revno. |
|
181 ] |
|
182 |
137 |
183 " |
138 " |
184 (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7' readStream) parseNodeId |
139 (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7' readStream) parseNodeId |
185 |
140 |
186 Bad ones: |
141 Bad ones: |