##// END OF EJS Templates
patch: make filestore store data in memory and fallback to fs
Patrick Mezard -
r14658:7ddf9a60 default
parent child Browse files
Show More
@@ -487,23 +487,34 b' class workingbackend(fsbackend):'
487 return sorted(self.changed)
487 return sorted(self.changed)
488
488
489 class filestore(object):
489 class filestore(object):
490 def __init__(self):
490 def __init__(self, maxsize=None):
491 self.opener = None
491 self.opener = None
492 self.files = {}
492 self.files = {}
493 self.created = 0
493 self.created = 0
494 self.maxsize = maxsize
495 if self.maxsize is None:
496 self.maxsize = 4*(2**20)
497 self.size = 0
498 self.data = {}
494
499
495 def setfile(self, fname, data, mode, copied=None):
500 def setfile(self, fname, data, mode, copied=None):
496 if self.opener is None:
501 if self.maxsize < 0 or (len(data) + self.size) <= self.maxsize:
497 root = tempfile.mkdtemp(prefix='hg-patch-')
502 self.data[fname] = (data, mode, copied)
498 self.opener = scmutil.opener(root)
503 self.size += len(data)
499 # Avoid filename issues with these simple names
504 else:
500 fn = str(self.created)
505 if self.opener is None:
501 self.opener.write(fn, data)
506 root = tempfile.mkdtemp(prefix='hg-patch-')
502 self.created += 1
507 self.opener = scmutil.opener(root)
503 self.files[fname] = (fn, mode, copied)
508 # Avoid filename issues with these simple names
509 fn = str(self.created)
510 self.opener.write(fn, data)
511 self.created += 1
512 self.files[fname] = (fn, mode, copied)
504
513
505 def getfile(self, fname):
514 def getfile(self, fname):
506 if fname not in self.files:
515 if fname in self.data:
516 return self.data[fname]
517 if not self.opener or fname not in self.files:
507 raise IOError()
518 raise IOError()
508 fn, mode, copied = self.files[fname]
519 fn, mode, copied = self.files[fname]
509 return self.opener.read(fn), mode, copied
520 return self.opener.read(fn), mode, copied
General Comments 0
You need to be logged in to leave comments. Login now