D7143: largefiles: avoid dynamically subclassing context instances
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Mon Nov 11 12:34:11 UTC 2019
Closed by commit rHG7f4d58c21aec: largefiles: avoid dynamically subclassing context instances (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D7143?vs=17355&id=18008
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D7143/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D7143
AFFECTED FILES
hgext/largefiles/reposetup.py
CHANGE DETAILS
diff --git a/hgext/largefiles/reposetup.py b/hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py
+++ b/hgext/largefiles/reposetup.py
@@ -15,6 +15,7 @@
from mercurial import (
error,
+ extensions,
localrepo,
match as matchmod,
scmutil,
@@ -47,45 +48,46 @@
ctx = super(lfilesrepo, self).__getitem__(changeid)
if self.lfstatus:
- class lfilesctx(ctx.__class__):
- def files(self):
- filenames = super(lfilesctx, self).files()
- return [lfutil.splitstandin(f) or f for f in filenames]
+ def files(orig):
+ filenames = orig()
+ return [lfutil.splitstandin(f) or f for f in filenames]
- def manifest(self):
- man1 = super(lfilesctx, self).manifest()
+ extensions.wrapfunction(ctx, 'files', files)
+
+ def manifest(orig):
+ man1 = orig()
- class lfilesmanifest(man1.__class__):
- def __contains__(self, filename):
- orig = super(lfilesmanifest, self).__contains__
- return orig(filename) or orig(
- lfutil.standin(filename)
- )
+ class lfilesmanifest(man1.__class__):
+ def __contains__(self, filename):
+ orig = super(lfilesmanifest, self).__contains__
+ return orig(filename) or orig(
+ lfutil.standin(filename)
+ )
- man1.__class__ = lfilesmanifest
- return man1
+ man1.__class__ = lfilesmanifest
+ return man1
- def filectx(self, path, fileid=None, filelog=None):
- orig = super(lfilesctx, self).filectx
- try:
- if filelog is not None:
- result = orig(path, fileid, filelog)
- else:
- result = orig(path, fileid)
- except error.LookupError:
- # Adding a null character will cause Mercurial to
- # identify this as a binary file.
- if filelog is not None:
- result = orig(
- lfutil.standin(path), fileid, filelog
- )
- else:
- result = orig(lfutil.standin(path), fileid)
- olddata = result.data
- result.data = lambda: olddata() + b'\0'
- return result
+ extensions.wrapfunction(ctx, 'manifest', manifest)
- ctx.__class__ = lfilesctx
+ def filectx(orig, path, fileid=None, filelog=None):
+ try:
+ if filelog is not None:
+ result = orig(path, fileid, filelog)
+ else:
+ result = orig(path, fileid)
+ except error.LookupError:
+ # Adding a null character will cause Mercurial to
+ # identify this as a binary file.
+ if filelog is not None:
+ result = orig(lfutil.standin(path), fileid, filelog)
+ else:
+ result = orig(lfutil.standin(path), fileid)
+ olddata = result.data
+ result.data = lambda: olddata() + b'\0'
+ return result
+
+ extensions.wrapfunction(ctx, 'filectx', filectx)
+
return ctx
# Figure out the status of big files and insert them into the
To: martinvonz, #hg-reviewers, pulkit
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list