Source code of Windows XP (NT5)
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.

174 lines
4.5 KiB

  1. # __________________________________________________________________________________
  2. #
  3. # Purpose:
  4. # PERL Script to emulate SLM's 'ssync' command
  5. #
  6. # Parameters:
  7. # See Usage below
  8. #
  9. # Output:
  10. # Perforce output or the appropriate error message or usage statement
  11. #
  12. # __________________________________________________________________________________
  13. #
  14. # Load common SLM wrapper subroutine module
  15. #
  16. use SlmSubs;
  17. #
  18. # Parse command line arguments
  19. #
  20. SlmSubs::ParseArgs(@ARGV);
  21. #
  22. # Call usage and exit if ParseArgs has set the Usage or InvalidFlag flags
  23. #
  24. if ($Usage or $InvalidFlag)
  25. {
  26. print $ErrorMessage;
  27. &Usage;
  28. exit 1;
  29. }
  30. #
  31. # Deal with ghost and unghost
  32. #
  33. if ($Ghost or $UnGhost)
  34. {
  35. #
  36. # Set @CurrentClientList equal to $SourceControlClient client output
  37. #
  38. open(CLIENT, "$SourceControlClient client -o |");
  39. @CurrentClientList = <CLIENT>;
  40. close (CLIENT);
  41. if ((@FileList) or (@DirList))
  42. {
  43. foreach $FileName (@FileList)
  44. {
  45. if ($FileName =~ /$\"(.*)\"/)
  46. {
  47. $FileName = $1;
  48. }
  49. if (($FileName eq "*") and ($main::Recursive))
  50. {
  51. $FileName = '...';
  52. }
  53. if ($UnGhost)
  54. {
  55. push @CurrentClientList, "\t$DepotMap$FileName $LocalMap\/$FileName\n";
  56. }
  57. else
  58. {
  59. push @CurrentClientList, "\t-$DepotMap$FileName $LocalMap\/$FileName\n";
  60. }
  61. }
  62. foreach $DirName (@DirList)
  63. {
  64. if ($DirName =~ /$\"(.*)\"/)
  65. {
  66. $DirName = $1;
  67. }
  68. if ($DirName =~ /\.\.\./)
  69. {
  70. if ($UnGhost)
  71. {
  72. push @CurrentClientList, "\t$DepotMap$DirName $LocalMap\/$DirName\n";
  73. }
  74. else
  75. {
  76. push @CurrentClientList, "\t-$DepotMap$DirName $LocalMap\/$DirName\n";
  77. }
  78. }
  79. }
  80. }
  81. else
  82. {
  83. $ModifiedAllFilesSymbol = $AllFilesSymbol;
  84. if (!$Recursive)
  85. {
  86. $ModifiedAllFilesSymbol = "*";
  87. }
  88. if ($UnGhost)
  89. {
  90. push @CurrentClientList, "\t$DepotMap$ModifiedAllFilesSymbol $LocalMap\/$ModifiedAllFilesSymbol\n";
  91. }
  92. else
  93. {
  94. push @CurrentClientList, "\t-$DepotMap$ModifiedAllFilesSymbol $LocalMap\/$ModifiedAllFilesSymbol\n";
  95. }
  96. }
  97. &SlmSubs::CleanUpList(\@CurrentClientList);
  98. open( TemporaryClientFile, ">$ENV{tmp}\\TmpClientFile");
  99. print TemporaryClientFile @CurrentClientList;
  100. close (TemporaryClientFile);
  101. system "$SourceControlClient client -i < $ENV{tmp}\\TmpClientFile >nul";
  102. unlink "$ENV{tmp}\\TmpClientFile";
  103. }
  104. if ((@FileList) or (@DirList))
  105. {
  106. open(SSYNCNOUTPUT, "$SourceControlClient sync -n $ExtraSsyncFlags @FileList @DirList 2>&1|");
  107. system "$SourceControlClient sync $ExtraSsyncFlags @FileList @DirList";
  108. system "$SourceControlClient resolve -af @FileList @DirList 2>nul";
  109. }
  110. else
  111. {
  112. open(SSYNCNOUTPUT, "$SourceControlClient sync -n $ExtraSsyncFlags $AllFilesSymbol 2>&1|");
  113. system "$SourceControlClient sync $ExtraSsyncFlags $AllFilesSymbol";
  114. system "$SourceControlClient resolve -af $AllFilesSymbol 2>nul";
  115. }
  116. #
  117. # Set @SyncOutput equal to $SourceControlClient sync output
  118. #
  119. @SsyncnOutput = <SSYNCNOUTPUT>;
  120. close (SSYNCNOUTPUT);
  121. #
  122. # Remove any empty directories if we see deleted in $SourceControlClient sync -n's output.
  123. #
  124. if ($Recursive)
  125. {
  126. if (grep { /deleted/ } @SsyncnOutput)
  127. {
  128. system "mtdir /d /e";
  129. }
  130. }
  131. sub Usage
  132. # __________________________________________________________________________________
  133. #
  134. # Prints out a usage statement for this script. In this case usurped from SLM's
  135. # 'ssync' usage statement
  136. #
  137. # Parameters:
  138. # None
  139. #
  140. # Output:
  141. # The usage statement
  142. #
  143. # __________________________________________________________________________________
  144. {
  145. print q/ssync - synchronizes enlisted directories
  146. Usage: ssync [-?!fhrgu] [file1] [file2... ]
  147. Arguments:
  148. -h prints out this message.
  149. -! forces a fresh copy of all files specified.
  150. -r (recursive) synchronizes all files in a given directory and in every
  151. subdirectory beneath it. If a pattern is given, matches the pattern.
  152. -g (ghost) remove the local copies of the specified files from your local
  153. project directories.
  154. -u (un-ghost) make local copies of the current version of the specified
  155. files so that they can be checked out and used.
  156. /;
  157. }