# HG changeset patch # User FUJIWARA Katsunori # Date 1365528455 -32400 # Node ID 257afe5489d4a6ebca6a9e13bba1b69a9289b89d # Parent 7d2a7f8e9da45a0bbd6d07b8156349278b8a7bcf largefiles: improve repo wrapping detection Before this patch, repo wrapping detection in "reposetup()" of largefiles can detect only limited repo wrapping: replacing target functions by another one named as "wrap". So, it can't detect repo wrapping even in recommended style: replacing "__class__" of repo by derived class. This patch can detect repo wrapping in both styles below: - replacing "__class__" of repo by derived class (recommended style): class derived(repo.__class__): def push(self, *args, **kwargs): return super(derived, self).push(*args, **kwargs) repo.__class__ = derived - replacing function of repo by another one (not recommended style): orgpush = repo.push def push(*args, **kwargs): return orgpush(*args, **kwargs) repo.push = push diff -r 7d2a7f8e9da4 -r 257afe5489d4 hgext/largefiles/reposetup.py --- a/hgext/largefiles/reposetup.py Thu Mar 21 23:27:37 2013 +0100 +++ b/hgext/largefiles/reposetup.py Wed Apr 10 02:27:35 2013 +0900 @@ -27,10 +27,11 @@ if not repo.local(): return proto.wirereposetup(ui, repo) + origclass = localrepo.localrepository + repoclass = repo.__class__ for name in ('status', 'commitctx', 'commit', 'push'): - method = getattr(repo, name) - if (isinstance(method, types.FunctionType) and - method.func_name == 'wrap'): + if (getattr(origclass, name) != getattr(repoclass, name) or + isinstance(getattr(repo, name), types.FunctionType)): ui.warn(_('largefiles: repo method %r appears to have already been' ' wrapped by another extension: ' 'largefiles may behave incorrectly\n') diff -r 7d2a7f8e9da4 -r 257afe5489d4 tests/test-largefiles.t --- a/tests/test-largefiles.t Thu Mar 21 23:27:37 2013 +0100 +++ b/tests/test-largefiles.t Wed Apr 10 02:27:35 2013 +0900 @@ -180,6 +180,34 @@ $ cat sub/large4 large22 +Test repo method wrapping detection + + $ cat > $TESTTMP/wrapping1.py < from hgext import largefiles + > def reposetup(ui, repo): + > class derived(repo.__class__): + > def push(self, *args, **kwargs): + > return super(derived, self).push(*args, **kwargs) + > repo.__class__ = derived + > largefiles.reposetup(ui, repo) + > uisetup = largefiles.uisetup + > EOF + $ hg --config extensions.largefiles=$TESTTMP/wrapping1.py status + largefiles: repo method 'push' appears to have already been wrapped by another extension: largefiles may behave incorrectly + + $ cat > $TESTTMP/wrapping2.py < from hgext import largefiles + > def reposetup(ui, repo): + > orgpush = repo.push + > def push(*args, **kwargs): + > return orgpush(*args, **kwargs) + > repo.push = push + > largefiles.reposetup(ui, repo) + > uisetup = largefiles.uisetup + > EOF + $ hg --config extensions.largefiles=$TESTTMP/wrapping2.py status + largefiles: repo method 'push' appears to have already been wrapped by another extension: largefiles may behave incorrectly + Test copies and moves from a directory other than root (issue3516) $ cd ..