[SCM]源碼管理 – Perforce命令列

來源:互聯網
上載者:User

一 P4(perforce)環境和sample project

p4 環境:

sample project:

 

二 P4命令列

1)p4env.bat

set path=C:\Program Files\Perforce;%path%

set P4Port=localhost:1666
set p4user=AAA
set p4passwd=aaa
set p4client=TestProject_AAA

set p4Root=//depot/TestProject
set p4LocalRoot=c:\MyLocalTestProject

set p4Drive=H:

if exist %p4Drive% (subst /d %p4Drive%)
subst %p4Drive% %p4LocalRoot%

在所有命令執行前設定p4port,p4user,p4password,p4client;
一般需要subst虛擬盤來避免絕對路徑,保證開發環境在所有的developers上可用。

 

2)p4login+logout.bat

call p4env.bat

echo %p4passwd%|p4 login

pause

p4 logout

pause

所有p4命令執行前需要執行p4 login來獲得ticket(表示用當前%p4user%來login)。

 

3)p4set.bat

call p4env.bat

p4 set

pause

查看當前的p4的環境變數的設定,包含p4user,p4passwd,p4client,p4port...。

 

4) p4sync.bat

call p4env.bat

REM sync to head
p4 sync -f %p4Root%/...

pause

REM sync to CL
p4 sync -f %p4Root%/...@9

pause

REM sync to label
p4 sync -f %p4Root%/...@label1

pause

可以sync到最新head,sync到指定的CL(changelist),或是sync到指定的label;
sync到指定的label時,只sync在label中包含的檔案,在label後新加的檔案不sync。

 

5)p4label.bat

call p4env.bat

REM label the head version and create the label
p4 tag -l label2 %p4Root%/...

pause

REM label to one CL and create the label
REM this is the best way to label p4 by one CL
p4 tag -l label1_1 %p4Root%/...@12

pause

REM show all files in one label
p4 files @label2

pause

label用來標識特定版本的某些檔案;

label可以標識當前的p4上的最新檔案,也可以標識某些檔案在指定CL時刻的版本;

Labelsync 使用當前client的內容來更新label。需要先使用label來建立label。

 

6)p4latestcl.bat

call p4env.bat

for /f "tokens=2" %%i IN ('p4 changes -m 1 %p4Root%/...') do (@echo %%i > CL.txt)

set /p latestCL=<CL.txt
echo %latestCL%

pause

用來擷取當前最新的CL。

 

7)p4checkin.bat

call p4env.bat

set FileBeChanged=%p4Drive%\TestProject\components.txt

REM generate p4 change form for new CL
printf "\n">change.txt
printf "Change:\tnew\n">>change.txt
printf "\n">>change.txt
printf "Status:\tnew\n">>change.txt
printf "\n">>change.txt
printf "Description:\n">>change.txt
printf "\tUpdate BBB components.txt!\n">>change.txt

pause

REM new CL
cat change.txt | p4 change -i | awk '{print $2}'>newCL.txt
set /p newcl=<newcl.txt 

pause

REM add the changed files into the CL
p4 edit -c %newcl% %FileBeChanged%

pause

REM update BBB component to 5
attrib -r %FileBeChanged%
set newversion=5

sed s/'BBB.*'/'BBB  %newversion%'/ %FileBeChanged% > temp.txt
cat temp.txt> %FileBeChanged%

pause

REM submit the CL
p4 submit -c %newcl%

pause

components.txt如下:

BBB  4
CCC  9

此指令碼示範了自動修改componets.txt檔案,然後自動submit的過程;

其中p4 change用來產生新的CL,需要輸入change.txt檔案;

其中p4 edit用來把修改的檔案加入到CL;

其中p4 submit用來提交CL;

第三方的sed.exe,cat.exe。

 

完!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.