Patchwork [02,of,18,helps-py3] synthrepo: move from dict() construction to {} literals

login
register
mail settings
Submitter Augie Fackler
Date March 12, 2014, 5:40 p.m.
Message ID <05e58b08fdfe2bcda370.1394646036@augie-macbookair>
Download mbox | patch
Permalink /patch/3915/
State Accepted
Commit 05e58b08fdfe2bcda3708ab6c20fbcb5fc01b3cd
Headers show

Comments

Augie Fackler - March 12, 2014, 5:40 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1394644346 14400
#      Wed Mar 12 13:12:26 2014 -0400
# Node ID 05e58b08fdfe2bcda3708ab6c20fbcb5fc01b3cd
# Parent  5442cab57b09e589e461ca27f54274f0cb503665
synthrepo: move from dict() construction to {} literals

The latter are both faster and more consistent across Python 2 and 3.

Patch

diff --git a/contrib/synthrepo.py b/contrib/synthrepo.py
--- a/contrib/synthrepo.py
+++ b/contrib/synthrepo.py
@@ -152,7 +152,7 @@ 
         if lastctx.rev() != nullrev:
             interarrival[roundto(ctx.date()[0] - lastctx.date()[0], 300)] += 1
         diff = sum((d.splitlines()
-                    for d in ctx.diff(pctx, opts=dict(git=True))), [])
+                    for d in ctx.diff(pctx, opts={'git': True})), [])
         fileadds, diradds, fileremoves, filechanges = 0, 0, 0, 0
         for filename, mar, lineadd, lineremove, binary in parsegitdiff(diff):
             if binary:
@@ -189,21 +189,21 @@ 
     def pronk(d):
         return sorted(d.iteritems(), key=lambda x: x[1], reverse=True)
 
-    json.dump(dict(revs=len(revs),
-                   lineschanged=pronk(lineschanged),
-                   children=pronk(invchildren),
-                   fileschanged=pronk(fileschanged),
-                   filesadded=pronk(filesadded),
-                   linesinfilesadded=pronk(linesinfilesadded),
-                   dirsadded=pronk(dirsadded),
-                   filesremoved=pronk(filesremoved),
-                   linelengths=pronk(linelengths),
-                   parents=pronk(parents),
-                   p1distance=pronk(p1distance),
-                   p2distance=pronk(p2distance),
-                   interarrival=pronk(interarrival),
-                   tzoffset=pronk(tzoffset),
-                   ),
+    json.dump({'revs': len(revs),
+               'lineschanged': pronk(lineschanged),
+               'children': pronk(invchildren),
+               'fileschanged': pronk(fileschanged),
+               'filesadded': pronk(filesadded),
+               'linesinfilesadded': pronk(linesinfilesadded),
+               'dirsadded': pronk(dirsadded),
+               'filesremoved': pronk(filesremoved),
+               'linelengths': pronk(linelengths),
+               'parents': pronk(parents),
+               'p1distance': pronk(p1distance),
+               'p2distance': pronk(p2distance),
+               'interarrival': pronk(interarrival),
+               'tzoffset': pronk(tzoffset),
+               },
               fp)
     fp.close()