P4 命令行操作

设置环境变量:

export P4USER='xxx'
export P4CLIENT='xxx'
export P4PORT='192.xxx:1666'

拉取最新代码:

p4 sync -f //xxx/xxx/xx/software/...@xxxxx

 

1. check out:

  p4 edit -c default testfile1 testfile2 testfile3

2. modify the file:

  cp xxx .

3. checkin the modified files to a new pending changelist

  p4 change -o > CL.log

    and modify the description part in the CL.log.

  p4 change -i < CL.log

    Then it will generate the new change list.

4.  submit the pending changelist

  p4 submit -c testfile1 testfile2 testfile3

 

Issues:

1. 如果遇到"file(s) not on client " 报错, 可以先p4 sync 拉取最新的代码,然后再p4 edit xxxx(需要保证client 下已经有这两个文件,才能执行p4 edit)。

2. 如果遇到"Client 'xxx' unknown - use 'client' command to create it" 的错误, 检查下当前export P4CLIENT的client 是否还存在(client 不存在,会影响后面的p4 sync 等一系列的操作):

  可以使用 #p4 clients | grep Test_CLIENTNAME 来查看是否还有client;

  如果client 已经不存在,#p4 client Test_CLIENTNAME  去创建Test_CLIENTNAME, 并修改其中的 Root, View 等配置 ;

    Root 表示当前client sync 代码的work 路径; View 是从当前user 能有权限从p4 拉取代码map 路径, 一般只需增删。

   

 

  使用#p4 -d Test_CLIENTNAME   可以删除client.

 3. p4 describe -S 10001 > d.txt  可以列出已提交(入库后)的Changelist 10001的修改文件及修改内容, 方便获取修改的文件和内容判断

     p4 diff2 //depot/branches/xxx/pageutils.c#1 ///depot/branches/xxx/pageutils.c#2 可以获取到入库后的文件内容的差别

4. 有时候p4 的 某个 client 下会有很多pending change list, 可以通过 如下命令查看:

p4 changes -c CLIENTNAME

某些 pending change list 想要删掉, 如果没有被修改的文件, 可以直接p4 change -d CHANGELIST 删除;

如果这个pending change list 存在已经被修改的文件,

需要 先 revert files: p4 revert -c CHANGELIST //brances/xxx.c ,

再执行 p4 change -d CHANGELIST 

p4 changes //xxx_branch/...@123456  可以查看server端xxx_branch 在CL123456之前的checkin 信息.

 

5. 应用example:

5.1 获取列举出来的所有CL的checkin comments:

  • 通过诸如p4 changes //xxx_branch/...@123456的命令信息,获取并整理所有需要检查的checkin CL,按找从小到大的顺序排列,方便后面为patch 取CL;比如附件的changelist.txt
  • 通过p4 describe -s CL 来获取当前CL的checkin 信息,包括checkin comments.
复制代码
#!/bin/bash
#dump the checkin comments to checkin_comments.txt file 

export P4PORT="xxx:1666"
export P4USER="xxx"
export P4CLIENT="xxx"
echo "xxx" | p4 -u $P4USER login

if [ -f "checkin_comments.txt" ]; then
        rm -f checkin_comments.txt
fi
cat changelist.txt | while read line
do
    proposal_CL_Num=$(echo $line | awk '{print $2}')

    if [ -f "checkin.log" ]; then
        rm -f checkin.log
    fi
    p4 describe -s $proposal_CL_Num >> checkin.log  #p4 describe to get the p4 checkin information
    echo ${proposal_CL_Num}:  >> checkin_comments.txt

    lin_temp1=`grep -n "Change ${proposal_CL_Num}" checkin.log | awk -F: '{print $1}'`   #get the line num of the checkin information
    line_end=`grep -n "Affected files" checkin.log | awk -F: '{print $1}'`

    for i in `seq $lin_temp1 $line_end`  #betwee change and Affected files are about the comments
    do 
        if [[ $i == $lin_temp1 || $i == $line_end ]]; then
            continue
        else
            echo `awk "NR==$i" checkin.log` >> checkin_comments.txt
        fi
    done
    
done
复制代码

 

5.2 对每个列举出来的CL num, 基于base CL 生成patch

  • 获取并整理所有需要检查的checkin CL, 得到changelist.txt
  • 由于p4 diff2生成的文件不能直接作为patch打到base code上, 所以采用的思想时,先把base code 和proposal code sync到本地后, 使用diff 直接去生成patch
  • 通过p4 diff2 -du //branch_1/...@123456  //branch_2/...@123468 > check.txt , cat check.txt | grep -v "==== identical" 可以获取到这两个CL之间改动过的文件及内容,但不是标准的patch 文件
  • 复制代码
    base_CL_Num=627285  
    p4_depot_path="example_branch/..."
    p4_src_local_path="local_src_path/src"
    
    cat changelist.txt | while read line
    do
        echo "start line: "$line
        echo "base version is: "$base_CL_Num
        proposal_CL_Num=$(echo $line | awk '{print $2}')if [ -d "base_code" ]; then
            rm -fr base_code
        fi
        mkdir base_code
       
        if [ -d "proposal_code" ]; then
            rm -fr proposal_code
        fi
        mkdir proposal_code
    
        p4 sync -fq $p4_depot_path@$base_CL_Num
        sudo cp -r $p4_src_local_path/* ./base_code
    
        p4 sync -fq $p4_depot_path@$proposal_CL_Num
        sudo cp -r $p4_src_local_path/* ./proposal_code
    
        echo "To generate the patch: diff -ruN ./base_code ./proposal_code > VSI_vc8000d_proposal_${proposal_CL_Num}_base_${base_CL_Num}.patch"
        diff -ruN ./base_code ./proposal_code > VSI_vc8000d_proposal_${proposal_CL_Num}_base_${base_CL_Num}.patch
    
        base_CL_Num=$proposal_CL_Num
    
    done
    复制代码

     

posted @   123容之  阅读(3730)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示