(command.CommandList
  children: [
    (command.Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (lhs_expr.LhsName name:test_description)
          op: Equal
          rhs: {(SQ <'git p4 rcs keywords'>)}
        )
      ]
    )
    (C {(.)} {(./lib-git-p4.sh)})
    (C {(test_expect_success)} {(SQ <'start p4d'>)} {(SQ <'\n'> <'\tstart_p4d\n'>)})
    (C {(test_expect_success)} {(SQ <'init depot'>)} 
      {
        (SQ <'\n'> <'\t(\n'> <'\t\tcd "$cli" &&\n'> <'\t\tcat <<-\\EOF >filek &&\n'> <'\t\t$Id$\n'> 
          <'\t\t/* $Revision$ */\n'> <'\t\t# $Change$\n'> <'\t\tline4\n'> <'\t\tline5\n'> <'\t\tline6\n'> <'\t\tline7\n'> <'\t\tline8\n'> 
          <'\t\tEOF\n'> <'\t\tsed "s/Revision/Revision: do not scrub me/" <filek >fileko &&\n'> 
          <'\t\tsed "s/Id/Id: do not scrub me/" <fileko >file_text &&\n'> <'\t\tp4 add -t text+k filek &&\n'> <'\t\tp4 submit -d "filek" &&\n'> 
          <'\t\tp4 add -t text+ko fileko &&\n'> <'\t\tp4 submit -d "fileko" &&\n'> <'\t\tp4 add -t text file_text &&\n'> 
          <'\t\tp4 submit -d "file_text"\n'> <'\t)\n'>
        )
      }
    )
    (command.FuncDef
      name: write_scrub_scripts
      body: 
        (command.BraceGroup
          children: [
            (command.AndOr
              ops: [Op_DAmp]
              children: [
                (command.SimpleCommand
                  words: [{(cat)}]
                  redirects: [
                    (redir.Redir
                      op: <Redir_Great '>'>
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_DollarName '$TRASH_DIRECTORY') (/scrub_k.py))}
                    )
                    (redir.HereDoc
                      op: <Redir_DLessDash '<<-'>
                      fd: 16777215
                      here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)}
                      here_end_span_id: 107
                      stdin_parts: [
                        ('import re, sys\n')
                        (
"sys.stdout.write(re.sub(r'(?i)\\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\\$', r'$\\1$', sys.stdin.read()))\n"
                        )
                      ]
                    )
                  ]
                )
                (command.SimpleCommand
                  words: [{(cat)}]
                  redirects: [
                    (redir.Redir
                      op: <Redir_Great '>'>
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_DollarName '$TRASH_DIRECTORY') (/scrub_ko.py))}
                    )
                    (redir.HereDoc
                      op: <Redir_DLessDash '<<-'>
                      fd: 16777215
                      here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)}
                      here_end_span_id: 123
                      stdin_parts: [
                        ('import re, sys\n')
                        (
"sys.stdout.write(re.sub(r'(?i)\\$(Id|Header):[^$]*\\$', r'$\\1$', sys.stdin.read()))\n"
                        )
                      ]
                    )
                  ]
                )
              ]
            )
          ]
        )
    )
    (C {(test_expect_success)} {(SQ <'scrub scripts'>)} {(SQ <'\n'> <'\twrite_scrub_scripts\n'>)})
    (command.FuncDef
      name: scrub_k_check
      body: 
        (command.BraceGroup
          children: [
            (command.AndOr
              ops: [Op_DAmp Op_DAmp Op_DAmp Op_DAmp Op_DAmp]
              children: [
                (command.Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (lhs_expr.LhsName name:file)
                      op: Equal
                      rhs: {(DQ ($ VSub_Number '$1'))}
                    )
                  ]
                )
                (command.Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (lhs_expr.LhsName name:scrub)
                      op: Equal
                      rhs: 
                        {(DQ ($ VSub_DollarName '$TRASH_DIRECTORY') (/) ($ VSub_DollarName '$file'))}
                    )
                  ]
                )
                (command.SimpleCommand
                  words: [
                    {(DQ ($ VSub_DollarName '$PYTHON_PATH'))}
                    {(DQ ($ VSub_DollarName '$TRASH_DIRECTORY') (/scrub_k.py))}
                  ]
                  redirects: [
                    (redir.Redir
                      op: <Redir_Less '<'>
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_DollarName '$git') (/) ($ VSub_DollarName '$file'))}
                    )
                    (redir.Redir
                      op: <Redir_Great '>'>
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_DollarName '$scrub'))}
                    )
                  ]
                )
                (command.Pipeline
                  children: [
                    (C {(test_cmp)} {(DQ ($ VSub_DollarName '$cli') (/) ($ VSub_DollarName '$file'))} 
                      {(DQ ($ VSub_DollarName '$scrub'))}
                    )
                  ]
                  negated: T
                )
                (C {(test_cmp)} {(DQ ($ VSub_DollarName '$git') (/) ($ VSub_DollarName '$file'))} 
                  {(DQ ($ VSub_DollarName '$scrub'))}
                )
                (C {(rm)} {(DQ ($ VSub_DollarName '$scrub'))})
              ]
            )
          ]
        )
    )
    (command.FuncDef
      name: scrub_ko_check
      body: 
        (command.BraceGroup
          children: [
            (command.AndOr
              ops: [Op_DAmp Op_DAmp Op_DAmp Op_DAmp Op_DAmp]
              children: [
                (command.Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (lhs_expr.LhsName name:file)
                      op: Equal
                      rhs: {(DQ ($ VSub_Number '$1'))}
                    )
                  ]
                )
                (command.Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (lhs_expr.LhsName name:scrub)
                      op: Equal
                      rhs: 
                        {(DQ ($ VSub_DollarName '$TRASH_DIRECTORY') (/) ($ VSub_DollarName '$file'))}
                    )
                  ]
                )
                (command.SimpleCommand
                  words: [
                    {(DQ ($ VSub_DollarName '$PYTHON_PATH'))}
                    {(DQ ($ VSub_DollarName '$TRASH_DIRECTORY') (/scrub_ko.py))}
                  ]
                  redirects: [
                    (redir.Redir
                      op: <Redir_Less '<'>
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_DollarName '$git') (/) ($ VSub_DollarName '$file'))}
                    )
                    (redir.Redir
                      op: <Redir_Great '>'>
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_DollarName '$scrub'))}
                    )
                  ]
                )
                (command.Pipeline
                  children: [
                    (C {(test_cmp)} {(DQ ($ VSub_DollarName '$cli') (/) ($ VSub_DollarName '$file'))} 
                      {(DQ ($ VSub_DollarName '$scrub'))}
                    )
                  ]
                  negated: T
                )
                (C {(test_cmp)} {(DQ ($ VSub_DollarName '$git') (/) ($ VSub_DollarName '$file'))} 
                  {(DQ ($ VSub_DollarName '$scrub'))}
                )
                (C {(rm)} {(DQ ($ VSub_DollarName '$scrub'))})
              ]
            )
          ]
        )
    )
    (C {(test_expect_success)} {(SQ <'edit far away from RCS lines'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> 
          <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> 
          <'\t\tsed "s/^line7/line7 edit/" <filek >filek.tmp &&\n'> <'\t\tmv -f filek.tmp filek &&\n'> <'\t\tgit commit -m "filek line7 edit" filek &&\n'> 
          <'\t\tgit p4 submit &&\n'> <'\t\tscrub_k_check filek\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'edit near RCS lines'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> 
          <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> 
          <'\t\tgit config git-p4.attemptRCSCleanup true &&\n'> <'\t\tsed "s/^line4/line4 edit/" <filek >filek.tmp &&\n'> <'\t\tmv -f filek.tmp filek &&\n'> 
          <'\t\tgit commit -m "filek line4 edit" filek &&\n'> <'\t\tgit p4 submit &&\n'> <'\t\tscrub_k_check filek\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'edit keyword lines'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> 
          <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> 
          <'\t\tgit config git-p4.attemptRCSCleanup true &&\n'> <'\t\tsed "/Revision/d" <filek >filek.tmp &&\n'> <'\t\tmv -f filek.tmp filek &&\n'> 
          <'\t\tgit commit -m "filek remove Revision line" filek &&\n'> <'\t\tgit p4 submit &&\n'> <'\t\tscrub_k_check filek\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'scrub ko files differently'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> 
          <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> 
          <'\t\tgit config git-p4.attemptRCSCleanup true &&\n'> <'\t\tsed "s/^line4/line4 edit/" <fileko >fileko.tmp &&\n'> <'\t\tmv -f fileko.tmp fileko &&\n'> 
          <'\t\tgit commit -m "fileko line4 edit" fileko &&\n'> <'\t\tgit p4 submit &&\n'> <'\t\tscrub_ko_check fileko &&\n'> <'\t\t! scrub_k_check fileko\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'cleanup after failure'>)} 
      {(SQ <'\n'> <'\t(\n'> <'\t\tcd "$cli" &&\n'> <'\t\tp4 revert ...\n'> <'\t)\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'ktext expansion should not expand multi-line $File::'>)} 
      {
        (SQ <'\n'> <'\t(\n'> <'\t\tcd "$cli" &&\n'> <'\t\tcat >lv.pm <<-\\EOF\n'> 
          <'\t\tmy $wanted = sub { my $f = $File::Find::name;\n'> <'\t\t\t\t    if ( -f && $f =~ /foo/ ) {\n'> <'\t\tEOF\n'> <'\t\tp4 add -t ktext lv.pm &&\n'> 
          <'\t\tp4 submit -d "lv.pm"\n'> <'\t) &&\n'> <'\ttest_when_finished cleanup_git &&\n'> <'\tgit p4 clone --dest="$git" //depot &&\n'> 
          <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\ttest_cmp "$cli/lv.pm" lv.pm\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'do not scrub plain text'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> 
          <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> 
          <'\t\tgit config git-p4.attemptRCSCleanup true &&\n'> <'\t\tsed "s/^line4/line4 edit/" <file_text >file_text.tmp &&\n'> 
          <'\t\tmv -f file_text.tmp file_text &&\n'> <'\t\tgit commit -m "file_text line4 edit" file_text &&\n'> <'\t\t(\n'> <'\t\t\tcd "$cli" &&\n'> 
          <'\t\t\tp4 open file_text &&\n'> <'\t\t\tsed "s/^line5/line5 p4 edit/" <file_text >file_text.tmp &&\n'> 
          <'\t\t\tmv -f file_text.tmp file_text &&\n'> <'\t\t\tp4 submit -d "file5 p4 edit"\n'> <'\t\t) &&\n'> 
          <'\t\techo s | test_expect_code 1 git p4 submit &&\n'> <'\t\t(\n'> <'\t\t\t# make sure the file is not left open\n'> <'\t\t\tcd "$cli" &&\n'> 
          <'\t\t\t! p4 fstat -T action file_text\n'> <'\t\t)\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'cleanup after failure 2'>)} 
      {(SQ <'\n'> <'\t(\n'> <'\t\tcd "$cli" &&\n'> <'\t\tp4 revert ...\n'> <'\t)\n'>)}
    )
    (command.FuncDef
      name: create_kw_file
      body: 
        (command.BraceGroup
          children: [
            (command.SimpleCommand
              words: [{(cat)}]
              redirects: [
                (redir.HereDoc
                  op: <Redir_DLess '<<'>
                  fd: 16777215
                  here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)}
                  here_end_span_id: 613
                  stdin_parts: [
                    ('/* A file\n')
                    ('\tId: $Id$\n')
                    ('\tRevision: $Revision$\n')
                    ('\tFile: $File$\n')
                    (' */\n')
                    ('int main(int argc, const char **argv) {\n')
                    ('\treturn 0;\n')
                    ('}\n')
                  ]
                )
                (redir.Redir
                  op: <Redir_Great '>'>
                  fd: 16777215
                  arg_word: {(DQ ($ VSub_Number '$1'))}
                )
              ]
            )
          ]
        )
    )
    (C {(test_expect_success)} {(SQ <'add kwfile'>)} 
      {
        (SQ <'\n'> <'\t(\n'> <'\t\tcd "$cli" &&\n'> <'\t\techo file1 >file1 &&\n'> 
          <'\t\tp4 add file1 &&\n'> <'\t\tp4 submit -d "file 1" &&\n'> <'\t\tcreate_kw_file kwfile1.c &&\n'> <'\t\tp4 add kwfile1.c &&\n'> 
          <'\t\tp4 submit -d "Add rcw kw file" kwfile1.c\n'> <'\t)\n'>
        )
      }
    )
    (command.FuncDef
      name: p4_append_to_file
      body: 
        (command.BraceGroup
          children: [
            (command.AndOr
              ops: [Op_DAmp Op_DAmp Op_DAmp]
              children: [
                (command.Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (lhs_expr.LhsName name:f)
                      op: Equal
                      rhs: {(DQ ($ VSub_Number '$1'))}
                    )
                  ]
                )
                (C {(p4)} {(edit)} {(-t)} {(ktext)} {(DQ ($ VSub_DollarName '$f'))})
                (command.SimpleCommand
                  words: [
                    {(echo)}
                    {
                      (DQ ('/* ') 
                        (word_part.CommandSubPart
                          command_list: (command.CommandList children:[(C {(date)})])
                          left_token: <Left_CommandSub '$('>
                        ) (' */')
                      )
                    }
                  ]
                  redirects: [
                    (redir.Redir
                      op: <Redir_DGreat '>>'>
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_DollarName '$f'))}
                    )
                  ]
                )
                (C {(p4)} {(submit)} {(-d)} {(DQ ('appending a line in p4'))})
              ]
            )
          ]
        )
    )
    (C {(test_expect_success)} {(SQ <'cope with rcs keyword expansion damage'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> 
          <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> 
          <'\t\tgit config git-p4.attemptRCSCleanup true &&\n'> <'\t\t(cd "$cli" && p4_append_to_file kwfile1.c) &&\n'> <'\t\told_lines=$(wc -l <kwfile1.c) &&\n'> 
          <'\t\tperl -n -i -e "print unless m/Revision:/" kwfile1.c &&\n'> <'\t\tnew_lines=$(wc -l <kwfile1.c) &&\n'> <'\t\ttest $new_lines = $(($old_lines - 1)) &&\n'> <'\n'> 
          <'\t\tgit add kwfile1.c &&\n'> <'\t\tgit commit -m "Zap an RCS kw line" &&\n'> <'\t\tgit p4 submit &&\n'> <'\t\tgit p4 rebase &&\n'> 
          <'\t\tgit diff p4/master &&\n'> <'\t\tgit p4 commit &&\n'> <'\t\techo "try modifying in both" &&\n'> <'\t\tcd "$cli" &&\n'> 
          <'\t\tp4 edit kwfile1.c &&\n'> <'\t\techo "line from p4" >>kwfile1.c &&\n'> <'\t\tp4 submit -d "add a line in p4" kwfile1.c &&\n'> 
          <'\t\tcd "$git" &&\n'> <'\t\techo "line from git at the top" | cat - kwfile1.c >kwfile1.c.new &&\n'> 
          <'\t\tmv kwfile1.c.new kwfile1.c &&\n'> <'\t\tgit commit -m "Add line in git at the top" kwfile1.c &&\n'> <'\t\tgit p4 rebase &&\n'> 
          <'\t\tgit p4 submit\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'cope with rcs keyword file deletion'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> <'\t(\n'> <'\t\tcd "$cli" &&\n'> 
          <'\t\techo "\\$Revision\\$" >kwdelfile.c &&\n'> <'\t\tp4 add -t ktext kwdelfile.c &&\n'> <'\t\tp4 submit -d "Add file to be deleted" &&\n'> 
          <'\t\tcat kwdelfile.c &&\n'> <'\t\tgrep 1 kwdelfile.c\n'> <'\t) &&\n'> <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> 
          <'\t\tcd "$git" &&\n'> <'\t\tgrep Revision kwdelfile.c &&\n'> <'\t\tgit rm -f kwdelfile.c &&\n'> 
          <'\t\tgit commit -m "Delete a file containing RCS keywords" &&\n'> <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> 
          <'\t\tgit config git-p4.attemptRCSCleanup true &&\n'> <'\t\tgit p4 submit\n'> <'\t) &&\n'> <'\t(\n'> <'\t\tcd "$cli" &&\n'> <'\t\tp4 sync &&\n'> 
          <'\t\t! test -f kwdelfile.c\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'Add keywords in git which match the default p4 values'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> 
          <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\techo "NewKW: \\$Revision\\$" >>kwfile1.c &&\n'> 
          <'\t\tgit add kwfile1.c &&\n'> <'\t\tgit commit -m "Adding RCS keywords in git" &&\n'> 
          <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> <'\t\tgit config git-p4.attemptRCSCleanup true &&\n'> <'\t\tgit p4 submit\n'> <'\t) &&\n'> <'\t(\n'> 
          <'\t\tcd "$cli" &&\n'> <'\t\tp4 sync &&\n'> <'\t\ttest -f kwfile1.c &&\n'> <'\t\tgrep "NewKW.*Revision.*[0-9]" kwfile1.c\n'> 
          <'\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_failure)} {(SQ <'Add keywords in git which do not match the default p4 values'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished cleanup_git &&\n'> 
          <'\tgit p4 clone --dest="$git" //depot &&\n'> <'\t(\n'> <'\t\tcd "$git" &&\n'> <'\t\techo "NewKW2: \\$Revision:1\\$" >>kwfile1.c &&\n'> 
          <'\t\tgit add kwfile1.c &&\n'> <'\t\tgit commit -m "Adding RCS keywords in git" &&\n'> 
          <'\t\tgit config git-p4.skipSubmitEdit true &&\n'> <'\t\tgit config git-p4.attemptRCSCleanup true &&\n'> <'\t\tgit p4 submit\n'> <'\t) &&\n'> <'\t(\n'> 
          <'\t\tcd "$cli" &&\n'> <'\t\tp4 sync &&\n'> <'\t\tgrep "NewKW2.*Revision.*[0-9]" kwfile1.c\n'> <'\n'> <'\t)\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'kill p4d'>)} {(SQ <'\n'> <'\tkill_p4d\n'>)})
    (C {(test_done)})
  ]
)