Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgChangelog.java @ 363:d9dfa9fe9cec
Decode escape sequences in changeset extras field
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 09 Dec 2011 02:08:09 +0100 |
parents | 150500515714 |
children | 3572fcb06473 |
comparison
equal
deleted
inserted
replaced
362:4937e35b805b | 363:d9dfa9fe9cec |
---|---|
278 } | 278 } |
279 int space2 = _timeString.indexOf(' ', space1 + 1); | 279 int space2 = _timeString.indexOf(' ', space1 + 1); |
280 if (space2 == -1) { | 280 if (space2 == -1) { |
281 space2 = _timeString.length(); | 281 space2 = _timeString.length(); |
282 } | 282 } |
283 long unixTime = Long.parseLong(_timeString.substring(0, space1)); // XXX Float, perhaps | 283 long unixTime = Long.parseLong(_timeString.substring(0, space1)); |
284 int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2)); | 284 int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2)); |
285 // 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 | 285 // unixTime is local time, and timezone records difference of the local time to UTC. |
286 // on commit and timezone is recorded to adjust it to UTC. | |
287 Date _time = new Date(unixTime * 1000); | 286 Date _time = new Date(unixTime * 1000); |
288 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null; | 287 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null; |
289 Map<String, String> _extrasMap; | 288 Map<String, String> _extrasMap; |
290 final String extras_branch_key = "branch"; | 289 final String extras_branch_key = "branch"; |
291 if (_extras == null) { | 290 if (_extras == null) { |
292 _extrasMap = Collections.singletonMap(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME); | 291 _extrasMap = Collections.singletonMap(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME); |
293 } else { | 292 } else { |
294 _extrasMap = new HashMap<String, String>(); | 293 _extrasMap = new HashMap<String, String>(); |
295 for (String pair : _extras.split("\00")) { | 294 for (String pair : _extras.split("\00")) { |
295 pair = decode(pair); | |
296 int eq = pair.indexOf(':'); | 296 int eq = pair.indexOf(':'); |
297 // FIXME need to decode key/value, @see changelog.py:decodeextra | |
298 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1)); | 297 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1)); |
299 } | 298 } |
300 if (!_extrasMap.containsKey(extras_branch_key)) { | 299 if (!_extrasMap.containsKey(extras_branch_key)) { |
301 _extrasMap.put(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME); | 300 _extrasMap.put(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME); |
302 } | 301 } |
350 return i; | 349 return i; |
351 } | 350 } |
352 } | 351 } |
353 return -1; | 352 return -1; |
354 } | 353 } |
354 | |
355 private static String decode(String s) { | |
356 if (s != null && s.indexOf('\\') != -1) { | |
357 // TestAuxUtilities#testChangelogExtrasDecode | |
358 return s.replace("\\\\", "\\").replace("\\n", "\n").replace("\\r", "\r").replace("\\0", "\00"); | |
359 } | |
360 return s; | |
361 } | |
355 } | 362 } |
356 | 363 |
357 private static class RawCsetCollector implements Inspector { | 364 private static class RawCsetCollector implements Inspector { |
358 final ArrayList<RawChangeset> result; | 365 final ArrayList<RawChangeset> result; |
359 | 366 |