Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.6 KiB

  1. @rem = 'Perl from *.bat boilerplate
  2. @echo off
  3. setlocal
  4. set file=%0.bat
  5. set args=%1 %2 %3 %4 %5 %6 %7 %8 %9
  6. :loop
  7. shift
  8. set args=%args% %9
  9. if not "%9"=="" goto loop
  10. perl -S %file% %args%
  11. goto endofperl
  12. ';
  13. #===============================================================================
  14. # This script copies a SLM source file from one location to another while
  15. # preserving history.
  16. $usage =<<END
  17. smove: Relocate SLM source files while preserving history.
  18. usage: smove <file> <new copy>
  19. The smove command moves a SLM source file to another location while
  20. preserving history and revision information. Note that it does not delfile the
  21. original source file, so it's actually closer to a copy command -- you'll have
  22. to perform the delfile yourself after you're satisfied that the move went
  23. successfully.
  24. As an exmaple, "smove foo.xxx ../gargle/mutter" will create a new file
  25. ../gargle/mutter/foo.xxx with the same history information as the original
  26. foo.xxx. The destination may be either a new file name, or a directory. If
  27. the destination is a directory, the old file name will be used.
  28. END
  29. ;
  30. die $usage if ($#ARGV != 1);
  31. $src = $ARGV[0];
  32. $dest = $ARGV[1];
  33. # Ensure that the destination is a relative path.
  34. if (($dest =~ /^\\/) || ($dest =~ /^\//)) {
  35. die "smove: Destination must be a relative pathname.\n";
  36. }
  37. # Ensure that the source file exists.
  38. die "smove: Source file \"$src\" not found.\n" if (! -f $src);
  39. # If the destination is a directory, form the full destination path.
  40. if (-d $dest) {
  41. ($basename = $src) =~ s:.*/::;
  42. ($dest = "$dest/$basename") =~ s://:/:g;
  43. }
  44. # Ensure that the destination doesn't already exist.
  45. if (-e $dest) { die "smove: \"$dest\" already exists.\n"; }
  46. print "\nMoving $src to $dest.\n\n";
  47. # Open a stream from the SLM log command to get information for each version
  48. # of the source file we're copying from. This information will contain the
  49. # timestamp, originating machine name, SLM source name, version number, and
  50. # revision comment.
  51. open (LOG, "log -999 -z $src |") || die "Couldn't run \"log -999 -z $src\".\n";
  52. @log = ();
  53. # Add each revision record to a list of strings for later processing.
  54. while (<LOG>) {
  55. chop;
  56. $time = substr ($_, 0, 14);
  57. ($machine = substr ($_, 16, 8)) =~ s/ .*//;
  58. ($remainder = substr ($_, 43)) =~ s/ +/ /g;
  59. $remainder =~ s/ *$//;
  60. ($original, $version, $comment) = split (/ /, $remainder, 3);
  61. $original =~ s:\\:/:g;
  62. $version = substr ($version, 1);
  63. push (@log, "$original\n$version\n$time\n$machine\n$comment");
  64. }
  65. $sep = "--------------------------------------------------------------------\n";
  66. # Take the first version and use it to 'addfile' the new destination file.
  67. ($original, $version, $time, $machine, $comment) = split(/\n/, shift(@log));
  68. die "smove: \"$src\" doesn't seem to be in the project.\n" if ($version eq "");
  69. &printinfo ($original, $version, $time, $machine, $comment);
  70. &slmcmd ("catsrc $src\@v$version >$dest");
  71. &slmcmd ("addfile -c \"$comment (from $original $time $machine)\" $dest");
  72. # For each remaining revision, check out the file, update the contents, and
  73. # check it back in with the revision information.
  74. foreach (@log) {
  75. ($original, $version, $time, $machine, $comment) = split(/\n/);
  76. &printinfo ($original, $version, $time, $machine, $comment);
  77. &slmcmd ("out $dest");
  78. &slmcmd ("catsrc $src\@v$version >$dest");
  79. &slmcmd ("in -c \"$comment (from $original $time $machine)\" $dest");
  80. }
  81. close (LOG);
  82. # All done.
  83. ##############################################################################
  84. # This subroutine prints and executes a SLM command. If the command fails
  85. # (probably because of a network error or a project lock), it will wait a bit
  86. # and then retry until successful.
  87. ##############################################################################
  88. sub slmcmd {
  89. $cmd = $_[0];
  90. print "$cmd\n";
  91. while (0 != system ($cmd)) {
  92. print "SLM command failed; will retry.\n";
  93. sleep (5);
  94. }
  95. }
  96. ##############################################################################
  97. sub printinfo {
  98. print "------------------------------------------------------------------------------\n";
  99. print "Original \"$_[0]\"\n";
  100. print "Version \"$_[1]\"\n";
  101. print "Time \"$_[2]\"\n";
  102. print "Machine \"$_[3]\"\n";
  103. print "Comment \"$_[4]\"\n\n";
  104. }
  105. __END__
  106. #===============================================================================
  107. :endofperl
  108. endlocal