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.

188 lines
4.6 KiB

  1. # __________________________________________________________________________________
  2. #
  3. # Purpose:
  4. # PERL Script to emulate SLM's 'enlist' 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. # Call usage and exit if $ProjectPathName is not set
  32. #
  33. if (!$ProjectPathName)
  34. {
  35. print "\nError: must specify a project\n\n";
  36. &Usage;
  37. exit 1;
  38. }
  39. #
  40. # Initialize Strings
  41. #
  42. $ClientName = "";
  43. $RootName = "";
  44. #
  45. # Set @CurrentClientList equal to $SourceControlClient client output
  46. #
  47. open(CLIENT, "$SourceControlClient client -o |");
  48. @CurrentClientList = <CLIENT>;
  49. close (CLIENT);
  50. foreach $ClientLine (@CurrentClientList)
  51. {
  52. if ($ClientLine =~ /^Root:\s*(\S*).*\n/)
  53. {
  54. $RootName = $1;
  55. }
  56. if ($ClientLine =~ /^Client:\s*(\S*).*\n/)
  57. {
  58. $ClientName = $1;
  59. }
  60. }
  61. if ($Cwd =~ /\Q$RootName\E(.*)/i)
  62. {
  63. $CwdMinusRoot = $1;
  64. $Branch = $ENV{SOURCECONTROLMAINBRANCH};
  65. #
  66. # Change \'s to /'s in $ProjectPathName.
  67. #
  68. $ProjectPathName =~ s/\\/\//g;
  69. #
  70. # If /'s exist in $ProjectPathName look for a valid branch name
  71. # and then strip it off.
  72. #
  73. if ($ProjectPathName =~ /^([^\/]*)\/(.*)/)
  74. {
  75. $Branch = $1;
  76. $ProjectPathName = $2;
  77. #
  78. # Get list of branches from Perforce Server.
  79. #
  80. open(BRANCHES, $SourceControlClient . ' dirs //depot/* 2>&1|');
  81. @Branches = <BRANCHES>;
  82. close(BRANCHES);
  83. #
  84. # grep for $Branch in @Branches List.
  85. #
  86. if (!grep { /^\s*\/\/depot\/$Branch\s*$/i } @Branches)
  87. {
  88. print "\nError: Branch $Branch not valid for this depot\n\n";
  89. &Usage;
  90. exit 1;
  91. }
  92. }
  93. #
  94. # Look for /'s in $ProjectPathName which isn't supported.
  95. #
  96. if ($ProjectPathName =~ /\//)
  97. {
  98. print "\nError: enlisting in subprojects is not supported\n\n";
  99. &Usage;
  100. exit 1;
  101. }
  102. else
  103. {
  104. #
  105. # Get list of projects from Perforce Server.
  106. #
  107. open(PROJECTS, $SourceControlClient . ' dirs //depot/' . $Branch . '/* 2>&1|');
  108. @Projects = <PROJECTS>;
  109. close(PROJECTS);
  110. #
  111. # grep for $ProjectPathName in @Projects List.
  112. #
  113. if (!grep { /^\s*\/\/depot\/$Branch\/$ProjectPathName\s*$/i } @Projects)
  114. {
  115. print "\nError: Project $ProjectPathName not valid for this branch\n\n";
  116. &Usage;
  117. exit 1;
  118. }
  119. }
  120. #
  121. # Change \'s to /'s in $CwdMinusRoot
  122. #
  123. $CwdMinusRoot =~ s/\\/\//g;
  124. push @CurrentClientList, "\t//depot/$Branch/$ProjectPathName/... //$ClientName$CwdMinusRoot/...\n";
  125. &SlmSubs::CleanUpList(\@CurrentClientList);
  126. open( TemporaryClientFile, ">$ENV{tmp}\\TmpClientFile");
  127. print TemporaryClientFile @CurrentClientList;
  128. close (TemporaryClientFile);
  129. system "$SourceControlClient client -i < $ENV{tmp}\\TmpClientFile >nul";
  130. unlink "$ENV{tmp}\\TmpClientFile";
  131. system "$SourceControlClient sync ... 2>&1";
  132. }
  133. else
  134. {
  135. print "\nError: current directory not under Perforce client root\n\n";
  136. &Usage;
  137. exit 1;
  138. }
  139. sub Usage
  140. # __________________________________________________________________________________
  141. #
  142. # Prints out a usage statement for this script. In this case usurped from SLM's
  143. # 'enlist' usage statement
  144. #
  145. # Parameters:
  146. # None
  147. #
  148. # Output:
  149. # The usage statement
  150. #
  151. # __________________________________________________________________________________
  152. {
  153. print q/enlist - enlists a directory in a project
  154. Usage: enlist [-?fh] [-s Server:Port] -p [branch]\/projname
  155. Arguments:
  156. -h prints out this message.
  157. -p use this flag to specify the name of the project to enlist in. The
  158. project name can be preceeded by a branch name. The default branch
  159. is the main branch.
  160. -s use this flag to specify the network location of the project in which
  161. to enlist, using the format: -s Server:Port "Server" is the network
  162. server name and "Port" is the Perforce Server's TCP\/IP port number.
  163. /;
  164. }