[SCM]源码管理 - Perforce命令行

一 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   / " 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。

 

完!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值