Unpack a perforce changelist saved with packChange

  1  # !/bin/bash
  2  # $Id$
  3  #
  4  # Unpack a perforce changelist saved with packChange
  5  #
  6  # Copyright (C) 2004-2004 The Eigenbase Project
  7  #
  8  # This program is free software; you can redistribute it and/or modify
  9  # it under the terms of the GNU General Public License as published by
 10  # the Free Software Foundation; either version 2 of the License, or
 11  # (at your option) any later version.
 12  #
 13  # This program is distributed in the hope that it will be useful,
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16  # GNU General Public License for more details.
 17  #
 18  # You should have received a copy of the GNU General Public License
 19  # along with this program; if not, write to the Free Software
 20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 21 
 22  usage() {
 23    echo  " Usage: unpackChange [-c changelist#] changefile.tar.gz "
 24    echo
 25    echo  "     -c changelist# Opens as part of an existing changelist. "
 26    echo  "         changelist# can be an existing changelist number, or "
 27    echo  "         'default'. "
 28  }
 29 
 30  if  [  " $1 "   =   - - " $1 "   =   -- help ]; then
 31      usage
 32       exit   0
 33  fi
 34 
 35  changeno = new
 36  if  [  " $1 "   =   - c ]; then
 37      changeno = " $2 "
 38       shift   2
 39  fi
 40 
 41  tarfile = $ 1
 42  if  [  !   " $tarfile "  ]; then 
 43      usage
 44      echo  " Error: you must specify an input tar file "
 45       exit   1
 46  fi
 47 
 48  tar  - xzf  $tarfile  changelist . txt changelist . desc
 49 
 50  #  check for conflicts between opened files and packed files
 51  p4 opened  >  opened . txt
 52  join   - " # "   - 0  opened . txt changelist . txt  >  conflicts . txt
 53  if  [  - s conflicts . txt ] 
 54  then
 55      echo The following packed files are already checked out :
 56      cat conflicts . txt
 57      echo You must submit or revert these changes before unpacking
 58       exit   1
 59  fi
 60 
 61  #  create a new changelist with the packed description
 62  if  [  " $changeno "   =  new ]; then
 63       if  [  !   - s changelist . desc ]; then
 64          echo  No  packed description :  cannot create a new changelist automatically .
 65          echo Create one by hand and try again .
 66           exit   1
 67      fi
 68      changeno = $(
 69          awk  ' /^Files:/ {exit} {print} '  changelist . desc  \
 70           |  p4 change  - \
 71           |  cut  - 2   - "   " )
 72  fi
 73 
 74  #  sync each file to the packed version number and check it out
 75  # on the new changelist
 76  cat changelist . txt  |
 77  dos2unix  |
 78  while   read  file;  do
 79      lfile = `echo  $file   |  cut  - 1   - " # " `
 80      case  " $file "  in
 81           *\   \-\  edit ) 
 82          p4 sync  " `echo $file | sed -e 's/ - edit//g'` " ;
 83          p4 edit  - $changeno   " $lfile " ;
 84          ;;
 85           *\   \-\  add ) 
 86          p4 add  - $changeno   " $lfile " ;
 87          ;;
 88           *\   \-\   delete  ) 
 89          p4  delete   - $changeno   " $lfile " ;
 90          ;;
 91           *\   \-\  branch ) 
 92          fromfile = `echo  " $file "   |  sed  - ' s/ - branch//g '   |  cut  - 2 , 3 , 4   - " # " `;
 93          p4 integrate  - $changeno   " $fromfile "   " $lfile " ;
 94          ;;
 95      esac
 96  done
 97 
 98  #  extract the packed file images
 99  # don't extract modification time -- if source host's time is skewed, timestamps
100  # from the past may confuse make or ant.
101  tar  - xmzf  $tarfile
102 
103  #  convert format
104  cygwin = false;
105  case  " `uname` "  in
106    CYGWIN * ) cygwin = true ;;
107  esac
108 
109  if   $cygwin ; then
110       :
111  else
112      echo  " Converting line-endings "
113      cat changelist . txt  |
114       grep   - '  \- delete$ '   |
115      dos2unix  |
116       while   read  file;  do
117          lfile = `echo  $file   |  cut  - 1   - " # " #  e.g. //open/foo/bar
118          pfile = `p4 where  $lfile   |  cut  - 3   - '   ' #  e.g. /src/foo/bar
119          case  " $pfile "  in
120               *. java |*. xml |*. sh)
121                  dos2unix  " $pfile "  ;;
122          esac
123      done
124  fi
125 
126  #  clean up
127  rm changelist . txt changelist . desc opened . txt conflicts . txt
128 
129  echo New change number is  $changeno
130 
131  #  End unpackChange.ksh
132 

你可能感兴趣的:(change)