Mercurial > hg
changeset 37770:31750413f8d7
formatter: convert timestamp to int
Spotted while porting jsonchangeset printer to formatter. A timestamp may be
float type, but its meaningful part is just int.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 13 Apr 2018 22:58:49 +0900 |
parents | 6a7ff5816c5f |
children | 8c48a3c088a7 |
files | mercurial/formatter.py tests/test-export.t tests/test-grep.t tests/test-journal.t tests/test-obsolete.t |
diffstat | 5 files changed, 34 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/formatter.py Tue Apr 17 03:07:01 2018 +0200 +++ b/mercurial/formatter.py Fri Apr 13 22:58:49 2018 +0900 @@ -144,7 +144,9 @@ @staticmethod def formatdate(date, fmt): '''convert date tuple to appropriate format''' - return date + # timestamp can be float, but the canonical form should be int + ts, tz = date + return (int(ts), tz) @staticmethod def formatdict(data, key, value, fmt, sep): '''convert dict or key-value pairs to appropriate dict format'''
--- a/tests/test-export.t Tue Apr 17 03:07:01 2018 +0200 +++ b/tests/test-export.t Fri Apr 13 22:58:49 2018 +0900 @@ -165,7 +165,7 @@ [ { "branch": "default", - "date": [0.0, 0], + "date": [0, 0], "desc": "foo-0", "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n", "node": "871558de6af2e8c244222f8eea69b782c94ce3df", @@ -181,7 +181,7 @@ [ { "branch": "default", - "date": [0.0, 0], + "date": [0, 0], "desc": "foo-0", "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n", "node": "871558de6af2e8c244222f8eea69b782c94ce3df", @@ -190,7 +190,7 @@ }, { "branch": "default", - "date": [0.0, 0], + "date": [0, 0], "desc": "foo-1", "diff": "diff -r 871558de6af2 -r d1c9656e973c foo\n--- a/foo\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +1,2 @@\n foo-0\n+foo-1\n", "node": "d1c9656e973cfb5aebd5499bbd2cb350e3b12266", @@ -206,7 +206,7 @@ [ { "branch": "default", - "date": [0.0, 0], + "date": [0, 0], "desc": "foo-0", "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n", "node": "871558de6af2e8c244222f8eea69b782c94ce3df", @@ -218,7 +218,7 @@ [ { "branch": "default", - "date": [0.0, 0], + "date": [0, 0], "desc": "foo-1", "diff": "diff -r 871558de6af2 -r d1c9656e973c foo\n--- a/foo\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +1,2 @@\n foo-0\n+foo-1\n", "node": "d1c9656e973cfb5aebd5499bbd2cb350e3b12266",
--- a/tests/test-grep.t Tue Apr 17 03:07:01 2018 +0200 +++ b/tests/test-grep.t Fri Apr 13 22:58:49 2018 +0900 @@ -58,7 +58,7 @@ $ hg grep -Tjson port [ { - "date": [4.0, 0], + "date": [4, 0], "file": "port", "line_number": 1, "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", @@ -67,7 +67,7 @@ "user": "spam" }, { - "date": [4.0, 0], + "date": [4, 0], "file": "port", "line_number": 2, "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", @@ -76,7 +76,7 @@ "user": "spam" }, { - "date": [4.0, 0], + "date": [4, 0], "file": "port", "line_number": 3, "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", @@ -91,7 +91,7 @@ $ hg grep -Tjson -l port [ { - "date": [4.0, 0], + "date": [4, 0], "file": "port", "line_number": 1, "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", @@ -119,7 +119,7 @@ [ { "change": "-", - "date": [4.0, 0], + "date": [4, 0], "file": "port", "line_number": 4, "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", @@ -129,7 +129,7 @@ }, { "change": "+", - "date": [3.0, 0], + "date": [3, 0], "file": "port", "line_number": 4, "node": "95040cfd017d658c536071c6290230a613c4c2a6", @@ -139,7 +139,7 @@ }, { "change": "-", - "date": [2.0, 0], + "date": [2, 0], "file": "port", "line_number": 1, "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", @@ -149,7 +149,7 @@ }, { "change": "-", - "date": [2.0, 0], + "date": [2, 0], "file": "port", "line_number": 2, "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", @@ -159,7 +159,7 @@ }, { "change": "+", - "date": [2.0, 0], + "date": [2, 0], "file": "port", "line_number": 1, "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", @@ -169,7 +169,7 @@ }, { "change": "+", - "date": [2.0, 0], + "date": [2, 0], "file": "port", "line_number": 2, "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", @@ -179,7 +179,7 @@ }, { "change": "+", - "date": [2.0, 0], + "date": [2, 0], "file": "port", "line_number": 3, "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", @@ -189,7 +189,7 @@ }, { "change": "+", - "date": [1.0, 0], + "date": [1, 0], "file": "port", "line_number": 2, "node": "8b20f75c158513ff5ac80bd0e5219bfb6f0eb587", @@ -199,7 +199,7 @@ }, { "change": "+", - "date": [0.0, 0], + "date": [0, 0], "file": "port", "line_number": 1, "node": "f31323c9217050ba245ee8b537c713ec2e8ab226",
--- a/tests/test-journal.t Tue Apr 17 03:07:01 2018 +0200 +++ b/tests/test-journal.t Fri Apr 13 22:58:49 2018 +0900 @@ -147,7 +147,7 @@ [ { "command": "up", - "date": [5.0, 0], + "date": [5, 0], "name": ".", "newhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"], "oldhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"], @@ -155,7 +155,7 @@ }, { "command": "up 0", - "date": [2.0, 0], + "date": [2, 0], "name": ".", "newhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"], "oldhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"], @@ -163,7 +163,7 @@ }, { "command": "commit -Aqm b", - "date": [1.0, 0], + "date": [1, 0], "name": ".", "newhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"], "oldhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"], @@ -171,7 +171,7 @@ }, { "command": "commit -Aqm a", - "date": [0.0, 0], + "date": [0, 0], "name": ".", "newhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"], "oldhashes": ["0000000000000000000000000000000000000000"],
--- a/tests/test-obsolete.t Tue Apr 17 03:07:01 2018 +0200 +++ b/tests/test-obsolete.t Fri Apr 13 22:58:49 2018 +0900 @@ -715,49 +715,49 @@ $ hg debugobsolete -Tjson [ { - "date": [1339.0, 0], + "date": [1339, 0], "flag": 0, "metadata": {"user": "test"}, "prednode": "1339133913391339133913391339133913391339", "succnodes": ["ca819180edb99ed25ceafb3e9584ac287e240b00"] }, { - "date": [1339.0, 0], + "date": [1339, 0], "flag": 0, "metadata": {"user": "test"}, "prednode": "1337133713371337133713371337133713371337", "succnodes": ["5601fb93a350734d935195fee37f4054c529ff39"] }, { - "date": [121.0, 120], + "date": [121, 120], "flag": 12, "metadata": {"user": "test"}, "prednode": "245bde4270cd1072a27757984f9cda8ba26f08ca", "succnodes": ["cdbce2fbb16313928851e97e0d85413f3f7eb77f"] }, { - "date": [1338.0, 0], + "date": [1338, 0], "flag": 1, "metadata": {"user": "test"}, "prednode": "5601fb93a350734d935195fee37f4054c529ff39", "succnodes": ["6f96419950729f3671185b847352890f074f7557"] }, { - "date": [1338.0, 0], + "date": [1338, 0], "flag": 0, "metadata": {"user": "test"}, "prednode": "ca819180edb99ed25ceafb3e9584ac287e240b00", "succnodes": ["1337133713371337133713371337133713371337"] }, { - "date": [1337.0, 0], + "date": [1337, 0], "flag": 0, "metadata": {"user": "test"}, "prednode": "cdbce2fbb16313928851e97e0d85413f3f7eb77f", "succnodes": ["ca819180edb99ed25ceafb3e9584ac287e240b00"] }, { - "date": [0.0, 0], + "date": [0, 0], "flag": 0, "metadata": {"user": "test"}, "parentnodes": ["6f96419950729f3671185b847352890f074f7557"], @@ -1555,7 +1555,7 @@ $ hg debugobsolete --index --rev "3+7" -Tjson [ { - "date": [0.0, 0], + "date": [0, 0], "flag": 0, "index": 1, "metadata": {"ef1": "1", "operation": "amend", "user": "test"}, @@ -1563,7 +1563,7 @@ "succnodes": ["d27fb9b066076fd921277a4b9e8b9cb48c95bc6a"] }, { - "date": [0.0, 0], + "date": [0, 0], "flag": 0, "index": 3, "metadata": {"ef1": "1", "operation": "amend", "user": "test"},