Patchwork [3,of,6] patch: add __getitem__ method to filestore

login
register
mail settings
Submitter Sean Farley
Date Aug. 6, 2014, 8:42 p.m.
Message ID <ccdd920b71df87e4cdc9.1407357729@178.1.168.192.in-addr.arpa>
Download mbox | patch
Permalink /patch/5297/
State Accepted
Headers show

Comments

Sean Farley - Aug. 6, 2014, 8:42 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1406333735 18000
#      Fri Jul 25 19:15:35 2014 -0500
# Node ID ccdd920b71df87e4cdc9c14dfe3698f18bd91bc0
# Parent  834969abe553deadc8072b18561bdbfe4d1071bb
patch: add __getitem__ method to filestore

Future patches will use this feature to allow building a memctx directly
instead of needing helper methods.
Matt Mackall - Aug. 6, 2014, 10:01 p.m.
On Wed, 2014-08-06 at 15:42 -0500, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1406333735 18000
> #      Fri Jul 25 19:15:35 2014 -0500
> # Node ID ccdd920b71df87e4cdc9c14dfe3698f18bd91bc0
> # Parent  834969abe553deadc8072b18561bdbfe4d1071bb
> patch: add __getitem__ method to filestore

This creates an import loop that's breaking several tests:

Failed test-contrib.t: output changed
Failed test-parseindex.t: output changed
Failed test-doctest.py: output changed and returned error code 1
Failed test-module-imports.t: output changed

Dropping 3-6 for now.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -14,10 +14,11 @@  import email.Generator
 import email.Parser
 
 from i18n import _
 from node import hex, short
 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
+import context
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
 
 class PatchError(Exception):
     pass
@@ -530,10 +531,15 @@  class filestore(object):
         if not self.opener or fname not in self.files:
             raise IOError
         fn, mode, copied = self.files[fname]
         return self.opener.read(fn), mode, copied
 
+    def __getitem__(self, fname):
+        data, (islink, isexec), copied = self.getfile(fname)
+        return context.memfilectx(None, fname, data, islink=islink,
+                                  isexec=isexec, copied=copied)
+
     def close(self):
         if self.opener:
             shutil.rmtree(self.opener.base)
 
 class repobackend(abstractbackend):