comparison hgext/largefiles/reposetup.py @ 15628:2b40513384ca

largefiles: use lfutil functions Using regular expressions to cut off a (fixed) string prefix is overly complicated and wasteful.
author Martin Geisler <mg@aragost.com>
date Fri, 09 Dec 2011 17:34:57 +0100
parents 931dc4af0d95
children e6868bd17f24
comparison
equal deleted inserted replaced
15627:9d7a83a42f8c 15628:2b40513384ca
8 8
9 '''setup for largefiles repositories: reposetup''' 9 '''setup for largefiles repositories: reposetup'''
10 import copy 10 import copy
11 import types 11 import types
12 import os 12 import os
13 import re
14 13
15 from mercurial import context, error, manifest, match as match_, node, util 14 from mercurial import context, error, manifest, match as match_, node, util
16 from mercurial.i18n import _ 15 from mercurial.i18n import _
17 16
18 import lfcommands 17 import lfcommands
52 def __contains__(self, filename): 51 def __contains__(self, filename):
53 if super(lfiles_manifestdict, 52 if super(lfiles_manifestdict,
54 self).__contains__(filename): 53 self).__contains__(filename):
55 return True 54 return True
56 return super(lfiles_manifestdict, 55 return super(lfiles_manifestdict,
57 self).__contains__(lfutil.shortname+'/' + filename) 56 self).__contains__(lfutil.standin(filename))
58 class lfiles_ctx(ctx.__class__): 57 class lfiles_ctx(ctx.__class__):
59 def files(self): 58 def files(self):
60 filenames = super(lfiles_ctx, self).files() 59 filenames = super(lfiles_ctx, self).files()
61 return [re.sub('^\\'+lfutil.shortname+'/', '', 60 return [lfutil.splitstandin(f) or f for f in filenames]
62 filename) for filename in filenames]
63 def manifest(self): 61 def manifest(self):
64 man1 = super(lfiles_ctx, self).manifest() 62 man1 = super(lfiles_ctx, self).manifest()
65 man1.__class__ = lfiles_manifestdict 63 man1.__class__ = lfiles_manifestdict
66 return man1 64 return man1
67 def filectx(self, path, fileid=None, filelog=None): 65 def filectx(self, path, fileid=None, filelog=None):
70 fileid, filelog) 68 fileid, filelog)
71 except error.LookupError: 69 except error.LookupError:
72 # Adding a null character will cause Mercurial to 70 # Adding a null character will cause Mercurial to
73 # identify this as a binary file. 71 # identify this as a binary file.
74 result = super(lfiles_ctx, self).filectx( 72 result = super(lfiles_ctx, self).filectx(
75 lfutil.shortname + '/' + path, fileid, 73 lfutil.standin(path), fileid, filelog)
76 filelog)
77 olddata = result.data 74 olddata = result.data
78 result.data = lambda: olddata() + '\0' 75 result.data = lambda: olddata() + '\0'
79 return result 76 return result
80 ctx.__class__ = lfiles_ctx 77 ctx.__class__ = lfiles_ctx
81 return ctx 78 return ctx