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

     


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM