# HG changeset patch # User Artem Tikhomirov # Date 1323392889 -3600 # Node ID d9dfa9fe9cecf1fda509df410f2a31028128acfd # Parent 4937e35b805b7f475a2c2b9418c062e521f1014f Decode escape sequences in changeset extras field diff -r 4937e35b805b -r d9dfa9fe9cec src/org/tmatesoft/hg/repo/HgChangelog.java --- 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 _extrasMap; @@ -293,8 +292,8 @@ } else { _extrasMap = new HashMap(); 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 { diff -r 4937e35b805b -r d9dfa9fe9cec test/org/tmatesoft/hg/test/TestAuxUtilities.java --- 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(); }