P4IGNORE 与 Typemap
P4IGNORE 与 Typemap
新建一个 P4 仓库,头两件要配的事就是 P4IGNORE(别把临时文件、本地配置加进去)和 typemap(让二进制资源加锁、文本文件按文本处理)。这篇把这两块的配置方式和我用的模板攒在一起。
P4IGNORE
P4IGNORE 只对正在被 add 的文件生效,不会忽略已经在 depot 里的文件。
默认文件名
2023.2 之前的 Helix Core Server 没有默认规则文件名。从 2023.2 起,满足下列条件就会自动查找默认文件名:
- Helix Core Server 2023.2 及以上
- 兼容的客户端,比如 2023.2 Server 自带的 p4 client,或 P4V 2023.4 及以上
| 操作系统 | 文件名 | 说明 |
|---|---|---|
| 全部 | .p4ignore、p4ignore.txt | 先处理 .p4ignore(如存在),再处理 p4ignore.txt |
查看当前机器生效的规则:p4 ignores -v。
改默认文件名:p4 set P4IGNORE=newname.txt。
参考:P4IGNORE 文档。
配置 P4IGNORE
通过 P4CONFIG 把 P4IGNORE 指到一个具体文件:
$ cat ~/.bashrc | grep P4CONFIG
export P4CONFIG=.p4c
$ cat .p4c | grep P4IGNORE
P4IGNORE=/home/perforce/.p4ignore
$ p4 set | grep P4IGNORE
P4IGNORE=/home/perforce/.p4ignore (config '/home/perforce/.p4c')
写一个 ignore 文件验证:
$ cat /home/perforce/.p4ignore
*.blah
*/#*
$ p4 add -f \#pound.txt
//depot/main/release1/perl_proj/%23pound.txt#1 - opened for add
/home/perforce/main/release1/perl_proj/#pound.txt - ignored file can't be added.
P4IGNORE 也可以用非绝对路径:
$ p4 set P4IGNORE=.p4ignore
这样客户端会从当前工作目录一直往上找到文件系统根目录,把找到的每个 .p4ignore 累加成一套完整的忽略规则。
查看生效的规则
p4 ignores -v 列出 server 找到的每个 P4IGNORE 文件以及它们各自展开的规则:
$ p4 ignores -v
#FILE - defaults
#LINE 2:**/.p4root
.../.p4root/...
.../.p4root
#FILE /home/perforce/workspace/.p4ignore
#LINE 2:*/#*
/home/perforce/workspace/.../#*/...
#LINE 1:*.blah
/home/perforce/workspace/....blah/...
-i 可以查某个具体文件为什么被忽略,会告诉你是哪一行规则命中的:
$ p4 ignores -v -i file.d
/home/perforce/workspace/file.d not ignored
$ p4 ignores -v -i file.blah
/home/perforce/workspace/file.blah ignored by /home/perforce/workspace/.p4ignore:1:*.blah
规则示例
忽略 P4IGNORE 和 P4CONFIG 文件本身(P4CONFIG 通常不适用于别人,P4IGNORE 你也未必想共享)。注意从 p4 2015.1 起,P4CONFIG 文件默认被忽略,真想入库可以用 p4 add -I:
p4ignore.txt
.p4ignore
p4config.txt
.p4config
忽略叫 thingy 的文件、.rubbish 后缀的文件,以及 dubious 文件夹的内容:
thingy.*
*.rubbish
dubious/
禁掉叫 disallowed 的条目,但允许它名下的文件(也允许名为 disallowed 的文件夹内部):
disallowed
!disallowed/
禁掉根目录的 media 文件夹,但允许出现在更深层的 media:
!media/
/media/
这会允许 C:\p4client\depot\deeper\media\media-deeper,禁掉 C:\p4client\depot\media\media-in-root。
P4V 里启用 P4IGNORE
从 2012.3 起 P4V 支持 P4IGNORE,通过 p4 reconcile 起作用。前提是 Server 至少 2012.1。配置两步:
- 在 client root 建一个文本文件,列出要忽略的类型,文件名随意,建议起
p4ignore.txt这种有意义的名字。 - 设环境变量
p4 set P4IGNORE=p4ignore.txt,然后重启 P4V 生效。
Windows 例子:
cd C:\Perforce
notepad p4ignore.txt
(写入)
*.o
p4 set P4IGNORE=C:\Perforce\p4ignore.txt
关掉再重启 P4V,然后试着在 P4V 里 add 一个 .o 文件,会看到提示 "The following files were not marked for add, since they are 'ignored'"。在 Windows 上还可以把 P4V 图标的 "Start in" 目录改成 client workspace root。
Mac 例子:Mac 上桌面程序不会启动 shell,所以要靠 p4 set 写进 ~/.p4enviro 才能被 P4V 自动读到:
p4 set P4IGNORE=.p4ignore
重启 P4V,选一个含可忽略文件的文件夹右键 "Reconcile Offline Work",确认这些文件不出现在 "Local Files not in depot" 里。
参考:using P4IGNORE with Perforce Helix P4V。
Typemap
typemap 决定每类文件按什么类型入库:文本走 text、二进制走 binary,需要独占编辑的二进制资源加 +l(exclusive lock),保留多版本加 +Sn,可写加 +w。新仓库必配。
p4 typemap # 编辑 typemap
p4 typemap -o # 查看整个 typemap
UE 仓库的 typemap(Charset: Unicode)
这是我给 UE 工程用的一版。.uasset/.umap/.upk 等资源加 +l 独占锁,引擎二进制 .dll/.pdb/.exe 用 +S32 只留最近 32 个版本:
binary+w //....lib
binary+w //....app
binary+w //....dylib
binary+w //....stub
binary+w //....ipa
binary //....bmp
binary //....dat
text //....ini
text //....config
text //....cpp
text //....h
text //....c
text //....cs
text //....m
text //....mm
text //....py
text //....txt
text //....xml
text //....md
text //....po
text //....html
text //....json
text //....udn
text //....js
text //....hpp
text //....inl
text //....lua
text //....yml
text //....css
text //....usf
text //....ush
text+w //....dll.config
text+w //....exe.config
binary+l //....uasset
binary+l //....umap
binary+l //....upk
binary+l //....udk
binary+l //....ubulk
binary+S32w //....dll
binary+S32w //....pdb
text+S32w //....modules
binary+S32w //....exe
binary+S32w //....target
完整的 UE 与 Unity typemap 模板,可以参考官方文档:Using Perforce as source control for Unreal Engine、Perforce typemap for Unity。
只保留最近 n 个版本
+Sn 让仓库只存某文件最近的 n 个版本(n 取 1-10 或 16/32/64/128/256/512),对会频繁改的大二进制很有用:
text+k //depot/project/src/....c
text+k //depot/project/src/....h
text //depot/project/src/....txt