Mercurial > hg4j
changeset 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 | 4937e35b805b |
children | ac8e1ce67730 |
files | src/org/tmatesoft/hg/repo/HgChangelog.java test/org/tmatesoft/hg/test/TestAuxUtilities.java |
diffstat | 2 files changed, 22 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgChangelog.java Fri Dec 09 01:14:41 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgChangelog.java Fri Dec 09 02:08:09 2011 +0100 @@ -280,10 +280,9 @@ if (space2 == -1) { space2 = _timeString.length(); } - long unixTime = Long.parseLong(_timeString.substring(0, space1)); // XXX Float, perhaps + long unixTime = Long.parseLong(_timeString.substring(0, space1)); int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2)); - // 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 - // on commit and timezone is recorded to adjust it to UTC. + // unixTime is local time, and timezone records difference of the local time to UTC. Date _time = new Date(unixTime * 1000); String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null; Map<String, String> _extrasMap; @@ -293,8 +292,8 @@ } else { _extrasMap = new HashMap<String, String>(); for (String pair : _extras.split("\00")) { + pair = decode(pair); int eq = pair.indexOf(':'); - // FIXME need to decode key/value, @see changelog.py:decodeextra _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1)); } if (!_extrasMap.containsKey(extras_branch_key)) { @@ -352,6 +351,14 @@ } return -1; } + + private static String decode(String s) { + if (s != null && s.indexOf('\\') != -1) { + // TestAuxUtilities#testChangelogExtrasDecode + return s.replace("\\\\", "\\").replace("\\n", "\n").replace("\\r", "\r").replace("\\0", "\00"); + } + return s; + } } private static class RawCsetCollector implements Inspector {
--- a/test/org/tmatesoft/hg/test/TestAuxUtilities.java Fri Dec 09 01:14:41 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestAuxUtilities.java Fri Dec 09 02:08:09 2011 +0100 @@ -289,6 +289,17 @@ Assert.assertFalse(p.hasDefaultPush() ^ p.getDefaultPush() != null); } + @Test + public void testChangelogExtrasDecode() { + final String s = "abc\u0123\r\ndef\n\txx\\yy"; + String r = s.replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r").replace("\0", "\\0"); +// System.out.println(r); + String r2 = r.replace("\\\\", "\\").replace("\\n", "\n").replace("\\r", "\r").replace("\\0", "\00"); +// System.out.println(r2); + Assert.assertTrue(s.equals(r2)); + } + + public static void main(String[] args) throws Exception { new TestAuxUtilities().testRepositoryConfig(); }