Mercurial > hg
view tests/fsmonitor-run-tests.py @ 37032:98663bed146e
rebase: store rebase state after each commit
Before this patch, we stored the rebase state early in the processing
of a node, before we updated the rebase state to indicate that the
node was processed. This meant that we could redo the working copy
merge and run into conflicts. However, this only happened in the
--collapse case if the rebase was interrupted while editing the final
commit message; in the case earlier interruptions, we would instead
detect the in-process revision by finding two dirstate parents.
This patch moves the writing of the rebase state to after we have
completed the revision completely, and, importantly, after we have
updated the rebase state to mark it done. This means we'll realize
that all nodes have been rebased in the case mentioned above of
editing the final commit message of a --collapse. See change to test
case.
I also moved the writing outside of the large if/elif block in
_rebasenode(). This shouldn't matter much, but seems cleaner. One
observable effect is if rebase was interrupted just after ignoring an
obsolete node ("not rebasing ####, already in destination"), we used
to come up with the same decision after --continue too, but after this
patch we'll instead say "already rebased ###". This seems more
consistent, since that's what we would do with obsolete nodes that had
been marked done earlier in the process (not only just before the
interruption).
Differential Revision: https://phab.mercurial-scm.org/D2913
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 21 Mar 2018 11:01:19 -0700 |
parents | efd6e941e933 |
children | b7ba1cfba174 |
line wrap: on
line source
#!/usr/bin/env python # fsmonitor-run-tests.py - Run Mercurial tests with fsmonitor enabled # # Copyright 2017 Facebook, Inc. # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. # # This is a wrapper around run-tests.py that spins up an isolated instance of # Watchman and runs the Mercurial tests against it. This ensures that the global # version of Watchman isn't affected by anything this test does. from __future__ import absolute_import from __future__ import print_function import argparse import contextlib import json import os import shutil import subprocess import sys import tempfile import uuid osenvironb = getattr(os, 'environb', os.environ) if sys.version_info > (3, 5, 0): PYTHON3 = True xrange = range # we use xrange in one place, and we'd rather not use range def _bytespath(p): return p.encode('utf-8') elif sys.version_info >= (3, 0, 0): print('%s is only supported on Python 3.5+ and 2.7, not %s' % (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3]))) sys.exit(70) # EX_SOFTWARE from `man 3 sysexit` else: PYTHON3 = False # In python 2.x, path operations are generally done using # bytestrings by default, so we don't have to do any extra # fiddling there. We define the wrapper functions anyway just to # help keep code consistent between platforms. def _bytespath(p): return p def getparser(): """Obtain the argument parser used by the CLI.""" parser = argparse.ArgumentParser( description='Run tests with fsmonitor enabled.', epilog='Unrecognized options are passed to run-tests.py.') # - keep these sorted # - none of these options should conflict with any in run-tests.py parser.add_argument('--keep-fsmonitor-tmpdir', action='store_true', help='keep temporary directory with fsmonitor state') parser.add_argument('--watchman', help='location of watchman binary (default: watchman in PATH)', default='watchman') return parser @contextlib.contextmanager def watchman(args): basedir = tempfile.mkdtemp(prefix='hg-fsmonitor') try: # Much of this configuration is borrowed from Watchman's test harness. cfgfile = os.path.join(basedir, 'config.json') # TODO: allow setting a config with open(cfgfile, 'w') as f: f.write(json.dumps({})) logfile = os.path.join(basedir, 'log') clilogfile = os.path.join(basedir, 'cli-log') if os.name == 'nt': sockfile = '\\\\.\\pipe\\watchman-test-%s' % uuid.uuid4().hex else: sockfile = os.path.join(basedir, 'sock') pidfile = os.path.join(basedir, 'pid') statefile = os.path.join(basedir, 'state') argv = [ args.watchman, '--sockname', sockfile, '--logfile', logfile, '--pidfile', pidfile, '--statefile', statefile, '--foreground', '--log-level=2', # debug logging for watchman ] envb = osenvironb.copy() envb[b'WATCHMAN_CONFIG_FILE'] = _bytespath(cfgfile) with open(clilogfile, 'wb') as f: proc = subprocess.Popen( argv, env=envb, stdin=None, stdout=f, stderr=f) try: yield sockfile finally: proc.terminate() proc.kill() finally: if args.keep_fsmonitor_tmpdir: print('fsmonitor dir available at %s' % basedir) else: shutil.rmtree(basedir, ignore_errors=True) def run(): parser = getparser() args, runtestsargv = parser.parse_known_args() with watchman(args) as sockfile: osenvironb[b'WATCHMAN_SOCK'] = _bytespath(sockfile) # Indicate to hghave that we're running with fsmonitor enabled. osenvironb[b'HGFSMONITOR_TESTS'] = b'1' runtestdir = os.path.dirname(__file__) runtests = os.path.join(runtestdir, 'run-tests.py') blacklist = os.path.join(runtestdir, 'blacklists', 'fsmonitor') runtestsargv.insert(0, runtests) runtestsargv.extend([ '--extra-config', 'extensions.fsmonitor=', '--blacklist', blacklist, ]) return subprocess.call(runtestsargv) if __name__ == '__main__': sys.exit(run())