tests/generate-working-copy-states.py
changeset 23447 815e76a45b24
parent 23446 e51027c85dcd
child 23494 3849b89459b0
equal deleted inserted replaced
23446:e51027c85dcd 23447:815e76a45b24
     1 # generate proper file state to test working copy behavior
     1 # Helper script used for generating history and working copy files and content.
       
     2 # The file's name corresponds to its history. The number of changesets can
       
     3 # be specified on the command line. With 2 changesets, files with names like
       
     4 # content1_content2_content1-untracked are generated. The first two filename
       
     5 # segments describe the contents in the two changesets. The third segment
       
     6 # ("content1-untracked") describes the state in the working copy, i.e.
       
     7 # the file has content "content1" and is untracked (since it was previously
       
     8 # tracked, it has been forgotten).
       
     9 #
       
    10 # This script generates the filenames and their content, but it's up to the
       
    11 # caller to tell hg about the state.
       
    12 #
       
    13 # There are two subcommands:
       
    14 #   filelist <numchangesets>
       
    15 #   state <numchangesets> (<changeset>|wc)
       
    16 #
       
    17 # Typical usage:
       
    18 #
       
    19 # $ python $TESTDIR/generate-working-copy-states.py state 2 1
       
    20 # $ hg addremove --similarity 0
       
    21 # $ hg commit -m 'first'
       
    22 #
       
    23 # $ python $TESTDIR/generate-working-copy-states.py state 2 1
       
    24 # $ hg addremove --similarity 0
       
    25 # $ hg commit -m 'second'
       
    26 #
       
    27 # $ python $TESTDIR/generate-working-copy-states.py state 2 wc
       
    28 # $ hg addremove --similarity 0
       
    29 # $ hg forget *_*_*-untracked
       
    30 # $ rm *_*_missing-*
       
    31 
     2 import sys
    32 import sys
     3 import os
    33 import os
     4 
    34 
     5 # Generates pairs of (filename, contents), where 'contents' is a list
    35 # Generates pairs of (filename, contents), where 'contents' is a list
     6 # describing the file's content at each revision (or in the working copy).
    36 # describing the file's content at each revision (or in the working copy).
    19                       set(parentcontents)):
    49                       set(parentcontents)):
    20             for combination in generatestates(maxchangesets,
    50             for combination in generatestates(maxchangesets,
    21                                               parentcontents + [content]):
    51                                               parentcontents + [content]):
    22                 yield combination
    52                 yield combination
    23 
    53 
       
    54 # retrieve the command line arguments
       
    55 target = sys.argv[1]
       
    56 maxchangesets = int(sys.argv[2])
       
    57 if target == 'state':
       
    58     depth = sys.argv[3]
       
    59 
    24 # sort to make sure we have stable output
    60 # sort to make sure we have stable output
    25 combinations = sorted(generatestates(2, []))
    61 combinations = sorted(generatestates(maxchangesets, []))
    26 
       
    27 # retrieve the state we must generate
       
    28 target = sys.argv[1]
       
    29 
    62 
    30 # compute file content
    63 # compute file content
    31 content = []
    64 content = []
    32 for filename, [base, parent, wcc] in combinations:
    65 for filename, states in combinations:
    33     if target == 'filelist':
    66     if target == 'filelist':
    34         print filename
    67         print filename
    35     elif target == 'base':
    68     elif target == 'state':
    36         content.append((filename, base))
    69         if depth == 'wc':
    37     elif target == 'parent':
    70             # Make sure there is content so the file gets written and can be
    38         content.append((filename, parent))
    71             # tracked. It will be deleted outside of this script.
    39     elif target == 'wc':
    72             content.append((filename, states[maxchangesets] or 'TOBEDELETED'))
    40         # Make sure there is content so the file gets written and can be
    73         else:
    41         # tracked. It will be deleted outside of this script.
    74             content.append((filename, states[int(depth) - 1]))
    42         content.append((filename, wcc or 'TOBEDELETED'))
       
    43     else:
    75     else:
    44         print >> sys.stderr, "unknown target:", target
    76         print >> sys.stderr, "unknown target:", target
    45         sys.exit(1)
    77         sys.exit(1)
    46 
    78 
    47 # write actual content
    79 # write actual content