tests/artifacts/scripts/generate-churning-bundle.py
changeset 43076 2372284d9457
parent 41800 5f198b690301
child 43110 1fcf79e9943a
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
    37 
    37 
    38 # constants for generating the large file we keep updating
    38 # constants for generating the large file we keep updating
    39 #
    39 #
    40 # At each revision, the beginning on the file change,
    40 # At each revision, the beginning on the file change,
    41 # and set of other lines changes too.
    41 # and set of other lines changes too.
    42 FILENAME='SPARSE-REVLOG-TEST-FILE'
    42 FILENAME = 'SPARSE-REVLOG-TEST-FILE'
    43 NB_LINES = 10500
    43 NB_LINES = 10500
    44 ALWAYS_CHANGE_LINES = 500
    44 ALWAYS_CHANGE_LINES = 500
    45 OTHER_CHANGES = 300
    45 OTHER_CHANGES = 300
    46 
    46 
       
    47 
    47 def nextcontent(previous_content):
    48 def nextcontent(previous_content):
    48     """utility to produce a new file content from the previous one"""
    49     """utility to produce a new file content from the previous one"""
    49     return hashlib.md5(previous_content).hexdigest()
    50     return hashlib.md5(previous_content).hexdigest()
       
    51 
    50 
    52 
    51 def filecontent(iteridx, oldcontent):
    53 def filecontent(iteridx, oldcontent):
    52     """generate a new file content
    54     """generate a new file content
    53 
    55 
    54     The content is generated according the iteration index and previous
    56     The content is generated according the iteration index and previous
    70             current = nextcontent(current)
    72             current = nextcontent(current)
    71         else:
    73         else:
    72             to_write = oldcontent[idx]
    74             to_write = oldcontent[idx]
    73         yield to_write
    75         yield to_write
    74 
    76 
       
    77 
    75 def updatefile(filename, idx):
    78 def updatefile(filename, idx):
    76     """update <filename> to be at appropriate content for iteration <idx>"""
    79     """update <filename> to be at appropriate content for iteration <idx>"""
    77     existing = None
    80     existing = None
    78     if idx is not None:
    81     if idx is not None:
    79         with open(filename, 'rb') as old:
    82         with open(filename, 'rb') as old:
    80             existing = old.readlines()
    83             existing = old.readlines()
    81     with open(filename, 'wb') as target:
    84     with open(filename, 'wb') as target:
    82         for line in filecontent(idx, existing):
    85         for line in filecontent(idx, existing):
    83             target.write(line)
    86             target.write(line)
       
    87 
    84 
    88 
    85 def hg(command, *args):
    89 def hg(command, *args):
    86     """call a mercurial command with appropriate config and argument"""
    90     """call a mercurial command with appropriate config and argument"""
    87     env = os.environ.copy()
    91     env = os.environ.copy()
    88     if 'CHGHG' in env:
    92     if 'CHGHG' in env:
    98         # avoid conflicts by picking the local variant
   102         # avoid conflicts by picking the local variant
    99         full_cmd.extend(['--tool', ':merge-local'])
   103         full_cmd.extend(['--tool', ':merge-local'])
   100     full_cmd.extend(args)
   104     full_cmd.extend(args)
   101     env['HGRCPATH'] = ''
   105     env['HGRCPATH'] = ''
   102     return subprocess.check_call(full_cmd, env=env)
   106     return subprocess.check_call(full_cmd, env=env)
       
   107 
   103 
   108 
   104 def run(target):
   109 def run(target):
   105     tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-')
   110     tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-')
   106     try:
   111     try:
   107         os.chdir(tmpdir)
   112         os.chdir(tmpdir)
   129 
   134 
   130     finally:
   135     finally:
   131         shutil.rmtree(tmpdir)
   136         shutil.rmtree(tmpdir)
   132     return 0
   137     return 0
   133 
   138 
       
   139 
   134 if __name__ == '__main__':
   140 if __name__ == '__main__':
   135     orig = os.path.realpath(os.path.dirname(sys.argv[0]))
   141     orig = os.path.realpath(os.path.dirname(sys.argv[0]))
   136     target = os.path.join(orig, os.pardir, 'cache', BUNDLE_NAME)
   142     target = os.path.join(orig, os.pardir, 'cache', BUNDLE_NAME)
   137     sys.exit(run(target))
   143     sys.exit(run(target))
   138