Use script to speed file move in code refactory

When do code refactor, we will need to move files from lib to lib, when it comes to move a very common used file, we will need to change a lot of file and check all of them out, this is boring. We could use script to speed the process and make life a little easier.

For example, when we want to move "libAAA/SomeHeaderFile.h" to "libBBB/SomeHeaderFile.h", after we had done the moving, we need to do following things to make it can compile through:

  1. Check out all the files included "libAAA/SomeHeaderFile.h". (P4 in linux could not auto checkout files when we modified them).
  2. Change all the "libAAA/SomeHeaderFile.h" to "libBBB/SomeHeaderFile.h"

First, we need to find out which file include "libAAA/SomeHeaderFile.h", use find may not be the best way, but it's OK when we limit the search within the project .

find .|xargs grep -ri "libAAA/SomeHeaderFile.h" -l | sort | uniq >> myFile.txt

Second, we can use script to checkout all the files in myFile.txt, the command it's like below:

./bunchCheckOut.sh myFile.txt <change-list-id>

And the script bunchCheckOut.sh:

#!/bin/bash
FILENAME="$1"
CHANGELIST="$2"
while read line
do
    p4 edit -c $CHANGELIST  $line
done < $FILENAME
echo "done"

The third step is to change all the related files.(This step should be very careful!)

sed -i "s/libAAA\/SomeHeaderFile.h/libBBB\/SomeHeaderFile.h/g" `grep  libAAA/SomeHeaderFile.h -rl ~/gui_10/SQL`

If want to exclude multi folders when grep, can do as below:

grep --exclude-dir=.git --exclude-dir=build_root --exclude-dir=build --exclude-dir=dll_build_root --exclude-dir=.vscode -nr

The last step is to compile and check if there is some file missed to checkout or modified.

We can also combine the above script into one file, but I think we should always check the result of the command before we carry on.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值