Patchwork [2,of,5,V2] patch: add __getitem__ method to filestore

login
register
mail settings
Submitter Sean Farley
Date Aug. 6, 2014, 11:20 p.m.
Message ID <28eed68e6f02e5a7ac85.1407367223@laptop.local>
Download mbox | patch
Permalink /patch/5303/
State Changes Requested
Headers show

Comments

Sean Farley - Aug. 6, 2014, 11:20 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 28eed68e6f02e5a7ac85e8bab0fbcaf59f8a2408
# Parent  db7d8fec711c7d5469bd351628029dbd27d9a82a
patch: add __getitem__ method to filestore

Future patches will use this feature to allow building a memctx directly
instead of needing helper methods.

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):