Patchwork [1,of,3] manifest: make copy logic local to copy()

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 27, 2015, 12:02 a.m.
Message ID <8415c2e64dd7ce24ee3b.1424995367@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7842/
State Accepted
Headers show

Comments

Martin von Zweigbergk - Feb. 27, 2015, 12:02 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1424727662 28800
#      Mon Feb 23 13:41:02 2015 -0800
# Node ID 8415c2e64dd7ce24ee3bd56fcd44941efbe05491
# Parent  e7785573a4af258101d0cc0b0947a6de65273096
manifest: make copy logic local to copy()

The optional arguments to the manfifestdict constructor are only used
by copy(), so assign the fields from that method instead so it's clear
that the arguments are not used for anything else.

Patch

diff -r e7785573a4af -r 8415c2e64dd7 mercurial/manifest.py
--- a/mercurial/manifest.py	Wed Feb 18 16:45:16 2015 -0800
+++ b/mercurial/manifest.py	Mon Feb 23 13:41:02 2015 -0800
@@ -10,13 +10,8 @@ 
 import array, struct
 
 class manifestdict(dict):
-    def __init__(self, mapping=None, flags=None):
-        if mapping is None:
-            mapping = {}
-        if flags is None:
-            flags = {}
-        dict.__init__(self, mapping)
-        self._flags = flags
+    def __init__(self):
+        self._flags = {}
     def __setitem__(self, k, v):
         assert v is not None
         dict.__setitem__(self, k, v)
@@ -26,7 +21,10 @@ 
         """Set the flags (symlink, executable) for path f."""
         self._flags[f] = flags
     def copy(self):
-        return manifestdict(self, dict.copy(self._flags))
+        copy = manifestdict()
+        dict.__init__(copy, self)
+        copy._flags = dict.copy(self._flags)
+        return copy
     def intersectfiles(self, files):
         '''make a new manifestdict with the intersection of self with files