(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'git p4 rcs keywords'>)}
          spids: [4]
        )
      ]
    )
    (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.ShFunction
      name: write_scrub_scripts
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [{<cat>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {(DQ ($ Id.VSub_DollarName '$TRASH_DIRECTORY') <'/scrub_k.py'>)}
                    )
                    (redir
                      op: <Id.Redir_DLessDash '<<-'>
                      loc: (redir_loc.Fd fd:0)
                      arg: 
                        (redir_param.MultiLine
                          here_begin: 
                            {(word_part.EscapedLiteral token:<Id.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'
                            >
                          ]
                        )
                    )
                  ]
                  do_fork: T
                )
                (command.Simple
                  words: [{<cat>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {(DQ ($ Id.VSub_DollarName '$TRASH_DIRECTORY') <'/scrub_ko.py'>)}
                    )
                    (redir
                      op: <Id.Redir_DLessDash '<<-'>
                      loc: (redir_loc.Fd fd:0)
                      arg: 
                        (redir_param.MultiLine
                          here_begin: 
                            {(word_part.EscapedLiteral token:<Id.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'
                            >
                          ]
                        )
                    )
                  ]
                  do_fork: T
                )
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'scrub scripts'>)} {(SQ <'\n'> <'\twrite_scrub_scripts\n'>)})
    (command.ShFunction
      name: scrub_k_check
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:file)
                      op: assign_op.Equal
                      rhs: {(DQ ($ Id.VSub_Number '$1'))}
                      spids: [159]
                    )
                  ]
                )
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:scrub)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (DQ ($ Id.VSub_DollarName '$TRASH_DIRECTORY') <'/'> 
                            ($ Id.VSub_DollarName '$file')
                          )
                        }
                      spids: [167]
                    )
                  ]
                )
                (command.Simple
                  words: [
                    {(DQ ($ Id.VSub_DollarName '$PYTHON_PATH'))}
                    {(DQ ($ Id.VSub_DollarName '$TRASH_DIRECTORY') <'/scrub_k.py'>)}
                  ]
                  redirects: [
                    (redir
                      op: <Id.Redir_Less '<'>
                      loc: (redir_loc.Fd fd:0)
                      arg: {(DQ ($ Id.VSub_DollarName '$git') <'/'> ($ Id.VSub_DollarName '$file'))}
                    )
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {(DQ ($ Id.VSub_DollarName '$scrub'))}
                    )
                  ]
                  do_fork: T
                )
                (command.Pipeline
                  children: [
                    (C {<test_cmp>} 
                      {(DQ ($ Id.VSub_DollarName '$cli') <'/'> ($ Id.VSub_DollarName '$file'))} {(DQ ($ Id.VSub_DollarName '$scrub'))}
                    )
                  ]
                  negated: T
                )
                (C {<test_cmp>} 
                  {(DQ ($ Id.VSub_DollarName '$git') <'/'> ($ Id.VSub_DollarName '$file'))} {(DQ ($ Id.VSub_DollarName '$scrub'))}
                )
                (C {<rm>} {(DQ ($ Id.VSub_DollarName '$scrub'))})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: scrub_ko_check
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:file)
                      op: assign_op.Equal
                      rhs: {(DQ ($ Id.VSub_Number '$1'))}
                      spids: [249]
                    )
                  ]
                )
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:scrub)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (DQ ($ Id.VSub_DollarName '$TRASH_DIRECTORY') <'/'> 
                            ($ Id.VSub_DollarName '$file')
                          )
                        }
                      spids: [257]
                    )
                  ]
                )
                (command.Simple
                  words: [
                    {(DQ ($ Id.VSub_DollarName '$PYTHON_PATH'))}
                    {(DQ ($ Id.VSub_DollarName '$TRASH_DIRECTORY') <'/scrub_ko.py'>)}
                  ]
                  redirects: [
                    (redir
                      op: <Id.Redir_Less '<'>
                      loc: (redir_loc.Fd fd:0)
                      arg: {(DQ ($ Id.VSub_DollarName '$git') <'/'> ($ Id.VSub_DollarName '$file'))}
                    )
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {(DQ ($ Id.VSub_DollarName '$scrub'))}
                    )
                  ]
                  do_fork: T
                )
                (command.Pipeline
                  children: [
                    (C {<test_cmp>} 
                      {(DQ ($ Id.VSub_DollarName '$cli') <'/'> ($ Id.VSub_DollarName '$file'))} {(DQ ($ Id.VSub_DollarName '$scrub'))}
                    )
                  ]
                  negated: T
                )
                (C {<test_cmp>} 
                  {(DQ ($ Id.VSub_DollarName '$git') <'/'> ($ Id.VSub_DollarName '$file'))} {(DQ ($ Id.VSub_DollarName '$scrub'))}
                )
                (C {<rm>} {(DQ ($ Id.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.ShFunction
      name: create_kw_file
      body: 
        (BraceGroup
          children: [
            (command.Simple
              words: [{<cat>}]
              redirects: [
                (redir
                  op: <Id.Redir_DLess '<<'>
                  loc: (redir_loc.Fd fd:0)
                  arg: 
                    (redir_param.MultiLine
                      here_begin: {(word_part.EscapedLiteral token:<Id.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
                  op: <Id.Redir_Great '>'>
                  loc: (redir_loc.Fd fd:1)
                  arg: {(DQ ($ Id.VSub_Number '$1'))}
                )
              ]
              do_fork: T
            )
          ]
        )
    )
    (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.ShFunction
      name: p4_append_to_file
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:f)
                      op: assign_op.Equal
                      rhs: {(DQ ($ Id.VSub_Number '$1'))}
                      spids: [645]
                    )
                  ]
                )
                (C {<p4>} {<edit>} {<-t>} {<ktext>} {(DQ ($ Id.VSub_DollarName '$f'))})
                (command.Simple
                  words: [
                    {<echo>}
                    {
                      (DQ <'/* '> (command_sub left_token:<Id.Left_DollarParen '$('> child:(C {<date>})) 
                        <' */'>
                      )
                    }
                  ]
                  redirects: [
                    (redir
                      op: <Id.Redir_DGreat '>>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {(DQ ($ Id.VSub_DollarName '$f'))}
                    )
                  ]
                  do_fork: T
                )
                (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>})
  ]
)