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.3 KiB

  1. # __________________________________________________________________________________
  2. #
  3. # Purpose:
  4. # PERL Script to emulate SLM's 'in' 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. if ($Number)
  31. {
  32. #
  33. # Call usage and exit if there were no files listed
  34. #
  35. if (!@FileList)
  36. {
  37. print "\n";
  38. print "Error: No files specified\n";
  39. print "\n";
  40. &Usage;
  41. exit 1;
  42. }
  43. else
  44. {
  45. #
  46. # Loop through filelist and 'scomp' each one by calling $SourceControlClient diff2
  47. #
  48. foreach $File (@FileList)
  49. {
  50. #
  51. # Get version of current $File so we can subtract $Number from it
  52. #
  53. open(FILES, "$SourceControlClient files $File |");
  54. $FileListing = <FILES>;
  55. close (FILES);
  56. if ($FileListing)
  57. {
  58. $FileListing =~ /^[^#]*#([0-9]*).*/;
  59. $Version = $1;
  60. $DiffVersion = $Version - $Number;
  61. if ($DiffVersion < 1)
  62. {
  63. $DiffVersion = 1;
  64. }
  65. $DiffVersionPlusOne = $DiffVersion + 1;
  66. if ($DiffVersionPlusOne > $Version)
  67. {
  68. $DiffVersionPlusOne = $Version;
  69. }
  70. while ($DiffVersion < $Version)
  71. {
  72. system "$SourceControlClient diff2 $File#$DiffVersion $File#$DiffVersionPlusOne";
  73. #
  74. # Increment DiffVersion and DiffVersionPlusOne to get next diff
  75. #
  76. $DiffVersionPlusOne++;
  77. $DiffVersion++;
  78. }
  79. }
  80. }
  81. }
  82. }
  83. else
  84. {
  85. if ((@FileList) or (@DirList))
  86. {
  87. open (P4Opened, "$SourceControlClient opened @FileList @DirList 2>&1|");
  88. @P4OpenedList = <P4Opened>;
  89. close (P4Opened);
  90. %P4OpenedHash = ();
  91. foreach $P4OpenedLine (@P4OpenedList)
  92. {
  93. if ( $P4OpenedLine =~ /.*\Q$DepotMap\E([^#]*)#[0-9]* - \S*.*/i )
  94. {
  95. $P4OpenedHash{$1}++;
  96. }
  97. }
  98. open (P4Files, "$SourceControlClient files @FileList @DirList 2>&1|");
  99. @P4FilesList = <P4Files>;
  100. close (P4Files);
  101. FilesLoop: foreach $P4FilesLine (@P4FilesList)
  102. {
  103. #
  104. # Grep current directory information out of output
  105. #
  106. if ( $P4FilesLine =~ /.*\Q$DepotMap\E([^#]*)#([0-9]*) - \S*.*/i )
  107. {
  108. $FileName = $1;
  109. $ServerVersion = $2;
  110. if ($P4OpenedHash{$FileName})
  111. {
  112. system "$SourceControlClient diff $FileName";
  113. }
  114. else
  115. {
  116. $DiffVersion = $ServerVersion - 1;
  117. if ($DiffVersion < 1)
  118. {
  119. $DiffVersion = 1;
  120. }
  121. system "$SourceControlClient diff2 $FileName#$DiffVersion $FileName";
  122. }
  123. }
  124. }
  125. }
  126. else
  127. {
  128. system "$SourceControlClient diff $AllFilesSymbol";
  129. }
  130. }
  131. sub Usage
  132. # __________________________________________________________________________________
  133. #
  134. # Prints out a usage statement for this script. In this case usurped from SLM's
  135. # 'in' usage statement
  136. #
  137. # Parameters:
  138. # None
  139. #
  140. # Output:
  141. # The usage statement
  142. #
  143. # __________________________________________________________________________________
  144. {
  145. print q/scomp - compares two versions of a file and lists the differences
  146. Usage: scomp [-?fhr] [-#] [file1] [file2... ]
  147. Arguments:
  148. -h prints out this message.
  149. -# specifies how many versions to list differences for, counting back from
  150. the present moment (-3 displays differences caused by the 3 most recent
  151. events).
  152. /;
  153. }