(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:test_description)
          op: Equal
          rhs: {(SQ <'git p4 rcs keywords'>)}
          spids: [4]
        )
      ]
      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'>
        )
      }
    )
    (FuncDef
      name: write_scrub_scripts
      body: 
        (BraceGroup
          children: [
            (AndOr
              ops: [Op_DAmp]
              children: [
                (SimpleCommand
                  words: [{(cat)}]
                  redirects: [
                    (Redir
                      op_id: Redir_Great
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_Name '$TRASH_DIRECTORY') (/scrub_k.py))}
                      spids: [93]
                    )
                    (HereDoc
                      op_id: Redir_DLessDash
                      fd: 16777215
                      body: 
                        {('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_expansion: False
                      here_end: EOF
                      was_filled: T
                      spids: [99]
                    )
                  ]
                )
                (SimpleCommand
                  words: [{(cat)}]
                  redirects: [
                    (Redir
                      op_id: Redir_Great
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_Name '$TRASH_DIRECTORY') (/scrub_ko.py))}
                      spids: [108]
                    )
                    (HereDoc
                      op_id: Redir_DLessDash
                      fd: 16777215
                      body: 
                        {('import re, sys\n') 
                          (
"sys.stdout.write(re.sub(r'(?i)\\$(Id|Header):[^$]*\\$', r'$\\1$', sys.stdin.read()))\n"
                          )
                        }
                      do_expansion: False
                      here_end: EOF
                      was_filled: T
                      spids: [114]
                    )
                  ]
                )
              ]
            )
          ]
          spids: [88]
        )
      spids: [83 87]
    )
    (C {(test_expect_success)} {(SQ <'scrub scripts'>)} {(SQ <'\n'> <'\twrite_scrub_scripts\n'>)})
    (FuncDef
      name: scrub_k_check
      body: 
        (BraceGroup
          children: [
            (AndOr
              ops: [Op_DAmp Op_DAmp Op_DAmp Op_DAmp Op_DAmp]
              children: [
                (Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (LhsName name:file)
                      op: Equal
                      rhs: {(DQ ($ VSub_Number '$1'))}
                      spids: [153]
                    )
                  ]
                  spids: [153]
                )
                (Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (LhsName name:scrub)
                      op: Equal
                      rhs: {(DQ ($ VSub_Name '$TRASH_DIRECTORY') (/) ($ VSub_Name '$file'))}
                      spids: [161]
                    )
                  ]
                  spids: [161]
                )
                (SimpleCommand
                  words: [
                    {(DQ ($ VSub_Name '$PYTHON_PATH'))}
                    {(DQ ($ VSub_Name '$TRASH_DIRECTORY') (/scrub_k.py))}
                  ]
                  redirects: [
                    (Redir
                      op_id: Redir_Less
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_Name '$git') (/) ($ VSub_Name '$file'))}
                      spids: [180]
                    )
                    (Redir
                      op_id: Redir_Great
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_Name '$scrub'))}
                      spids: [187]
                    )
                  ]
                )
                (Pipeline
                  children: [
                    (C {(test_cmp)} {(DQ ($ VSub_Name '$cli') (/) ($ VSub_Name '$file'))} 
                      {(DQ ($ VSub_Name '$scrub'))}
                    )
                  ]
                  negated: T
                )
                (C {(test_cmp)} {(DQ ($ VSub_Name '$git') (/) ($ VSub_Name '$file'))} 
                  {(DQ ($ VSub_Name '$scrub'))}
                )
                (C {(rm)} {(DQ ($ VSub_Name '$scrub'))})
              ]
            )
          ]
          spids: [150]
        )
      spids: [145 149]
    )
    (FuncDef
      name: scrub_ko_check
      body: 
        (BraceGroup
          children: [
            (AndOr
              ops: [Op_DAmp Op_DAmp Op_DAmp Op_DAmp Op_DAmp]
              children: [
                (Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (LhsName name:file)
                      op: Equal
                      rhs: {(DQ ($ VSub_Number '$1'))}
                      spids: [243]
                    )
                  ]
                  spids: [243]
                )
                (Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (LhsName name:scrub)
                      op: Equal
                      rhs: {(DQ ($ VSub_Name '$TRASH_DIRECTORY') (/) ($ VSub_Name '$file'))}
                      spids: [251]
                    )
                  ]
                  spids: [251]
                )
                (SimpleCommand
                  words: [
                    {(DQ ($ VSub_Name '$PYTHON_PATH'))}
                    {(DQ ($ VSub_Name '$TRASH_DIRECTORY') (/scrub_ko.py))}
                  ]
                  redirects: [
                    (Redir
                      op_id: Redir_Less
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_Name '$git') (/) ($ VSub_Name '$file'))}
                      spids: [270]
                    )
                    (Redir
                      op_id: Redir_Great
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_Name '$scrub'))}
                      spids: [277]
                    )
                  ]
                )
                (Pipeline
                  children: [
                    (C {(test_cmp)} {(DQ ($ VSub_Name '$cli') (/) ($ VSub_Name '$file'))} 
                      {(DQ ($ VSub_Name '$scrub'))}
                    )
                  ]
                  negated: T
                )
                (C {(test_cmp)} {(DQ ($ VSub_Name '$git') (/) ($ VSub_Name '$file'))} 
                  {(DQ ($ VSub_Name '$scrub'))}
                )
                (C {(rm)} {(DQ ($ VSub_Name '$scrub'))})
              ]
            )
          ]
          spids: [240]
        )
      spids: [235 239]
    )
    (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'>)}
    )
    (FuncDef
      name: create_kw_file
      body: 
        (BraceGroup
          children: [
            (SimpleCommand
              words: [{(cat)}]
              redirects: [
                (HereDoc
                  op_id: Redir_DLess
                  fd: 16777215
                  body: 
                    {('/* 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')
                    }
                  do_expansion: False
                  here_end: EOF
                  was_filled: T
                  spids: [590]
                )
                (Redir
                  op_id: Redir_Great
                  fd: 16777215
                  arg_word: {(DQ ($ VSub_Number '$1'))}
                  spids: [594]
                )
              ]
            )
          ]
          spids: [585]
        )
      spids: [580 584]
    )
    (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'>
        )
      }
    )
    (FuncDef
      name: p4_append_to_file
      body: 
        (BraceGroup
          children: [
            (AndOr
              ops: [Op_DAmp Op_DAmp Op_DAmp]
              children: [
                (Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (LhsName name:f)
                      op: Equal
                      rhs: {(DQ ($ VSub_Number '$1'))}
                      spids: [630]
                    )
                  ]
                  spids: [630]
                )
                (C {(p4)} {(edit)} {(-t)} {(ktext)} {(DQ ($ VSub_Name '$f'))})
                (SimpleCommand
                  words: [
                    {(echo)}
                    {
                      (DQ ('/* ') 
                        (CommandSubPart
                          command_list: (CommandList children:[(C {(date)})])
                          left_token: <Left_CommandSub '$('>
                          spids: [657 659]
                        ) (' */')
                      )
                    }
                  ]
                  redirects: [
                    (Redir
                      op_id: Redir_DGreat
                      fd: 16777215
                      arg_word: {(DQ ($ VSub_Name '$f'))}
                      spids: [663]
                    )
                  ]
                )
                (C {(p4)} {(submit)} {(-d)} {(DQ ('appending a line in p4'))})
              ]
            )
          ]
          spids: [627]
        )
      spids: [622 626]
    )
    (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)})
  ]
)