diff tests/test-lfs-serve.t @ 40268:9c4cbbb0fc51

lfs: register the flag processors per repository Previously, enabling the extension for any repo in commandserver or hgweb would enable the flags on all repos. Since localrepo.resolverevlogstorevfsoptions() is called so early, the check to see if the extension is enabled on the repo (which hasn't been instantiated yet) is a bit awkward. But I don't see a better way.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 04 Oct 2018 00:17:26 -0400
parents 393e44324037
children ef0baff11aea
line wrap: on
line diff
--- a/tests/test-lfs-serve.t	Tue Oct 09 21:53:21 2018 -0400
+++ b/tests/test-lfs-serve.t	Thu Oct 04 00:17:26 2018 -0400
@@ -35,6 +35,26 @@
   $ hg init server
   $ SERVER_REQUIRES="$TESTTMP/server/.hg/requires"
 
+  $ cat > $TESTTMP/debugprocessors.py <<EOF
+  > from mercurial import (
+  >     cmdutil,
+  >     commands,
+  >     pycompat,
+  >     registrar,
+  > )
+  > cmdtable = {}
+  > command = registrar.command(cmdtable)
+  > @command(b'debugprocessors', [], b'FILE')
+  > def debugprocessors(ui, repo, file_=None, **opts):
+  >     opts = pycompat.byteskwargs(opts)
+  >     opts[b'changelog'] = False
+  >     opts[b'manifest'] = False
+  >     opts[b'dir'] = False
+  >     rl = cmdutil.openrevlog(repo, b'debugprocessors', file_, opts)
+  >     for flag, proc in rl._flagprocessors.iteritems():
+  >         ui.status(b"registered processor '%#x'\n" % (flag))
+  > EOF
+
 Skip the experimental.changegroup3=True config.  Failure to agree on this comes
 first, and causes a "ValueError: no common changegroup version" or "abort:
 HTTP Error 500: Internal Server Error", if the extension is only loaded on one
@@ -42,6 +62,8 @@
 for flag '0x2000'!" if the extension is only loaded on one side (possibly also
 masked by the Internal Server Error message).
   $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > debugprocessors = $TESTTMP/debugprocessors.py
   > [experimental]
   > lfs.disableusercache = True
   > [lfs]
@@ -51,6 +73,8 @@
   > push_ssl=False
   > EOF
 
+  $ cp $HGRCPATH $HGRCPATH.orig
+
 #if lfsremote-on
   $ hg --config extensions.lfs= -R server \
   >    serve -p $HGPORT -d --pid-file=hg.pid --errorlog=$TESTTMP/errors.log
@@ -307,6 +331,103 @@
   $ hg identify http://localhost:$HGPORT
   c729025cc5e3
 
+  $ mv $HGRCPATH $HGRCPATH.tmp
+  $ cp $HGRCPATH.orig $HGRCPATH
+
+  >>> from __future__ import absolute_import
+  >>> from hgclient import check, readchannel, runcommand
+  >>> @check
+  ... def checkflags(server):
+  ...     readchannel(server)
+  ...     print('')
+  ...     print('# LFS required- both lfs and non-lfs revlogs have 0x2000 flag')
+  ...     runcommand(server, ['debugprocessors', 'lfs.bin', '-R',
+  ...                '../server'])
+  ...     runcommand(server, ['debugprocessors', 'nonlfs2.txt', '-R',
+  ...                '../server'])
+  ...     runcommand(server, ['config', 'extensions', '--cwd',
+  ...                '../server'])
+  ... 
+  ...     print("\n# LFS not enabled- revlogs don't have 0x2000 flag")
+  ...     runcommand(server, ['debugprocessors', 'nonlfs3.txt'])
+  ...     runcommand(server, ['config', 'extensions'])
+  
+  # LFS required- both lfs and non-lfs revlogs have 0x2000 flag
+  *** runcommand debugprocessors lfs.bin -R ../server
+  registered processor '0x8000'
+  registered processor '0x2000'
+  *** runcommand debugprocessors nonlfs2.txt -R ../server
+  registered processor '0x8000'
+  registered processor '0x2000'
+  *** runcommand config extensions --cwd ../server
+  extensions.debugprocessors=$TESTTMP/debugprocessors.py
+  extensions.lfs=
+  
+  # LFS not enabled- revlogs don't have 0x2000 flag
+  *** runcommand debugprocessors nonlfs3.txt
+  registered processor '0x8000'
+  *** runcommand config extensions
+  extensions.debugprocessors=$TESTTMP/debugprocessors.py
+
+  $ rm $HGRCPATH
+  $ mv $HGRCPATH.tmp $HGRCPATH
+
+  $ hg clone $TESTTMP/client $TESTTMP/nonlfs -qr 0 --config extensions.lfs=
+  $ cat >> $TESTTMP/nonlfs/.hg/hgrc <<EOF
+  > [extensions]
+  > lfs = !
+  > EOF
+
+  >>> from __future__ import absolute_import, print_function
+  >>> from hgclient import check, readchannel, runcommand
+  >>> @check
+  ... def checkflags2(server):
+  ...     readchannel(server)
+  ...     print('')
+  ...     print('# LFS enabled- both lfs and non-lfs revlogs have 0x2000 flag')
+  ...     runcommand(server, ['debugprocessors', 'lfs.bin', '-R',
+  ...                '../server'])
+  ...     runcommand(server, ['debugprocessors', 'nonlfs2.txt', '-R',
+  ...                '../server'])
+  ...     runcommand(server, ['config', 'extensions', '--cwd',
+  ...                '../server'])
+  ... 
+  ...     print('\n# LFS enabled without requirement- revlogs have 0x2000 flag')
+  ...     runcommand(server, ['debugprocessors', 'nonlfs3.txt'])
+  ...     runcommand(server, ['config', 'extensions'])
+  ... 
+  ...     print("\n# LFS disabled locally- revlogs don't have 0x2000 flag")
+  ...     runcommand(server, ['debugprocessors', 'nonlfs.txt', '-R',
+  ...                '../nonlfs'])
+  ...     runcommand(server, ['config', 'extensions', '--cwd',
+  ...                '../nonlfs'])
+  
+  # LFS enabled- both lfs and non-lfs revlogs have 0x2000 flag
+  *** runcommand debugprocessors lfs.bin -R ../server
+  registered processor '0x8000'
+  registered processor '0x2000'
+  *** runcommand debugprocessors nonlfs2.txt -R ../server
+  registered processor '0x8000'
+  registered processor '0x2000'
+  *** runcommand config extensions --cwd ../server
+  extensions.debugprocessors=$TESTTMP/debugprocessors.py
+  extensions.lfs=
+  
+  # LFS enabled without requirement- revlogs have 0x2000 flag
+  *** runcommand debugprocessors nonlfs3.txt
+  registered processor '0x8000'
+  registered processor '0x2000'
+  *** runcommand config extensions
+  extensions.debugprocessors=$TESTTMP/debugprocessors.py
+  extensions.lfs=
+  
+  # LFS disabled locally- revlogs don't have 0x2000 flag
+  *** runcommand debugprocessors nonlfs.txt -R ../nonlfs
+  registered processor '0x8000'
+  *** runcommand config extensions --cwd ../nonlfs
+  extensions.debugprocessors=$TESTTMP/debugprocessors.py
+  extensions.lfs=!
+
 --------------------------------------------------------------------------------
 Case #6: client with lfs content and the extension enabled; server with
 lfs content, and the extension enabled.