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.

145 lines
3.7 KiB

  1. package main;
  2. if (!$__IITBUILDPM ) { use iit::build; }
  3. use File::Compare;
  4. # compare $fnNew with $fnOld
  5. # if different checkout $fnOld, replace with $fnNew, and checkin
  6. # $sspath is SS prefix to $fnOld
  7. sub SLMReplace
  8. {
  9. return(ssrepl(@_));
  10. }
  11. sub ssrepl($$;$)
  12. {
  13. # Usage: bool ssrepl(fileToReplaceWith, fileToReplace, [deleteAfterCheckin])
  14. my($fdelete) = 0;
  15. my($rc) = 1;
  16. PrintL("ssrepl @_\n", PL_VERBOSE);
  17. # if there's a delete flag, get it and shift it
  18. if ($_[0] eq '-d')
  19. {
  20. $fdelete = 1;
  21. shift @_;
  22. }
  23. my ($fnNew, $fnOld) = @_;
  24. if (!SLMOperation('ssync '.$fnOld))
  25. {
  26. PrintL("can't sync ".$fnOld."\n", PL_ERROR);
  27. $rc = 0;
  28. }
  29. elsif (!-e $fnNew)
  30. {
  31. PrintL($fnNew." does not exist\n", PL_ERROR);
  32. $rc = 0;
  33. }
  34. elsif (!-e $fnOld)
  35. {
  36. PrintL($fnOld." does not exist\n", PL_ERROR);
  37. $rc = 0;
  38. }
  39. else
  40. {
  41. my($nCompareCode) = compare($fnNew, $fnOld);
  42. if ($nCompareCode == 0)
  43. {
  44. PrintL(" - [local]".RemovePath($fnNew)." and [slm]".RemovePath($fnOld)." are identical (no check-in required)\n", PL_BLUE);
  45. if ($fdelete)
  46. {
  47. EchoedUnlink($fnNew);
  48. }
  49. }
  50. elsif ($nCompareCode == -1)
  51. {
  52. PrintL("Error comparing files, skipping file checkin\n", PL_ERROR);
  53. $rc = 0;
  54. }
  55. else
  56. {
  57. PrintL(" - ".$fnNew." and ".$fnOld." are different\n", PL_BLUE);
  58. # don't bother if not the "official" build
  59. if ($bOfficialBuild)
  60. {
  61. if (!SLMOperation('out -v '.$fnOld))
  62. {
  63. PrintL("checkout of ".$fnOld." FAILED\n", PL_ERROR);
  64. $rc = 0;
  65. }
  66. }
  67. else
  68. {
  69. SetReadOnly($fnOld, 0);
  70. }
  71. if ($rc)
  72. {
  73. PrintL(" - Replacing $fnOld with $fnNew\n", PL_BLUE);
  74. if (!EchoedCopy($fnNew, $fnOld))
  75. {
  76. if ($bOfficialBuild)
  77. {
  78. PrintL(" - Failure, Undoing checkout\n", PL_ERROR);
  79. SLMOperation('in -iv '.$fnOld);
  80. $rc = 0;
  81. }
  82. }
  83. else
  84. {
  85. # extract slm variables
  86. my(%slmvars)=();
  87. my($fhIni) = OpenFile("slm.ini", "read");
  88. if ($fhIni)
  89. {
  90. while(!$fhIni->eof())
  91. {
  92. my($curLine) = $fhIni->getline();
  93. if ($curLine =~ /^(.+) = (.+)$/)
  94. {
  95. $slmvars{$1} = $2;
  96. }
  97. }
  98. CloseFile($fhIni);
  99. }
  100. $slmvars{"sub dir"} =~ s/\"//g;
  101. my($strFullFile) = $slmvars{"project"}.$slmvars{"sub dir"}."\\$fnOld";
  102. $strFullFile =~ s/\//\\/g; # make / and \ agree
  103. if (!$bOfficialBuild)
  104. {
  105. PrintLTip($strFullFile." updated in place\n",
  106. "Replacement File Src: ".$fnNew,
  107. PL_BLUE | PL_MSG);
  108. }
  109. else
  110. {
  111. if (!SLMOperation('in "-!c" Update '.$fnOld))
  112. {
  113. PrintLTip("Checkin of ".$strFullFile." FAILED\n\n",
  114. "Replacement File Src: ".$fnNew,
  115. (IsCritical() ? PL_BIGERROR : PL_ERROR));
  116. $rc = 0;
  117. }
  118. else
  119. {
  120. PrintLTip($strFullFile." updated\n\n",
  121. "Replacement File Src: ".$fnNew,
  122. PL_BLUE | PL_MSG);
  123. }
  124. if ($fdelete)
  125. {
  126. EchoedUnlink($fnNew);
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }
  133. return($rc);
  134. }
  135. $__IITSSREPLPM = 1;
  136. 1;