6

我在这里阅读了另一篇文章,我可以在没有客户端工作区的情况下将文件从 Perforce 库下载到本地磁盘。为了进一步扩展,我需要将所有文件(文本和二进制文件)从仓库目录下载到我的本地磁盘中。这是正确的 p4 命令吗?

p4 打印 //depot/dir1/...

我有几个问题:

  1. 它会从 //depot/dir1/... 下载所有子目录和文件还是只下载文件?
  2. 它会保留将要下载的文件的原始名称吗?
  3. 如果没有指定本地路径,本地磁盘上的文件在哪里?

我正在使用 p4api.net 库。这段代码能做到吗?

    public void GetFiles(string DepotFilePath) 
    {
        P4Command cmd = new P4Command( _repository, "print", true, 
        String.Format( "{0}/...", DepotFilePath ));

        results = cmd.Run();
        if (results.Success)
        {
            //do something here
        }
    }

我不确定它将文件转储到本地磁盘的哪个位置?

提前谢谢你的帮助。

4

5 回答 5

5

不需要特定于平台的脚本工具的简单解决方案:

p4 client -df TEMP_CLIENT
p4 -c TEMP_CLIENT --field View="//depot/dir1/... //TEMP_CLIENT/..." client -o | p4 client -i
p4 -c TEMP_CLIENT sync -p
p4 client -d TEMP_CLIENT

这会将所有文件/目录从//depot/dir1您的当前目录下载。如果要指定不同的目录,请在指定--field "Root=C:\Some Path"的同一位置添加到第一个命令View

于 2017-10-17T22:52:36.620 回答
3

p4 print将内容输出到标准输出(参见优秀手册)。因此,按顺序回答您的问题:

  1. 它将“下载”所有子目录中的所有文件,但只会在标准输出上打印文件内容。它不会在磁盘上生成文件。
  2. 是的,有点,但不是你想象的那样。在 stdout 上的流中,将有如下几行://depot/path/to/file#5 - edit change 430530 (text),后跟该特定文件的内容。
  3. 无处,不会在磁盘上创建文件。

如果您真的不想为您的任务创建客户端工作区(为什么?),那么您必须执行以下操作:

  1. p4 files使用例如(手动)获取文件列表
  2. 遍历此列表并调用p4 print每个文件
  3. 将输出重定向p4 print到本地磁盘上的文件,并遵循软件仓库中的目录结构。
于 2012-01-31T12:55:26.863 回答
1

单线

作为参考,这是一个 bash one 班轮,它将执行手动过程 jhwist 的回答:

for _file in $(p4 files //depot/dir/... | awk '{print $1}' | perl -ne '/(.*)#\d+$/ && print "$1\n"'); do p4 print -q $_file > /path/to/target/dir/$(basename $_file); done

您必须用相关目录替换的唯一位是//depot/dir/path/to/target/dir。注意:目标目录必须已经存在。


解释:

拉出for循环正在迭代的内容:

$(p4 files //depot/dir/... | awk '{print $1}' | perl -ne '/(.*)#\d+$/ && print "$1\n"')
  1. 从有问题的 perforce 目录中获取文件列表

  2. 输出的第一列是文件的仓库位置,所以用awk

  3. 仓库位置已#revisionNumber固定在它的末端,因此将其剥离perl

于 2017-10-17T22:44:48.883 回答
0

最新的 Perforce 已经原生支持它:

o p4 打印选项

https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_print.html#p4_print

于 2020-04-16T08:38:59.293 回答
0

所以我花了一些时间让它在 bash 的不同场景下工作,即使它不是特定于 dotnet 的,我想我会分享我的结果,因为这些概念是通用的。

您有两个选项可以从远程获取文件:

  1. 使用临时客户端/工作空间检查并同步工作空间映射,就像 Sam Stafford 在他的回答中所写的那样。这是 bash 中的注释:
# p4 uses this global variable as client/workspace name by default.
# Alternatively, you can also use -c in every command.
P4CLIENT="TEMP_SCRIPT_CLIENT"

# mapping remote folder to relative workspace folder  (recursive)
wokspaceMapping="//depot/dir1/... //$P4CLIENT/..."
p4 client -d $P4CLIENT # make sure the workspace does not exist already
# Creating a client on the console gives an editor popup to confirm the
# workspace specification, unless you provide a specification on stdin.
# You can however generate one to stdout, and pipe the result to stdin again.
p4 --field View="$wokspaceMapping" --field Root="/some/local/path" client -o |
  p4 client -i
p4 sync -p # download all the files
p4 client -d $P4CLIENT # remove workspace when you are done.
  1. 用于打印jhwist 所p4 print建议的每个文件的内容,因此您根本不需要定义工作区。缺点是您必须单独处理每个文件,并自己创建任何目录。
p4RemoteRoot="//depot/dir1"
# First, list files and strip output to file path
# because `p4 files` prints something like this:
# //depot/dir1/file1.txt#1 - add change 43444817 (text)
# //depot/dir1/folder/file2.txt#11 - edit change 43783713 (text)
files="$(p4 files $p4RemoteRoot/... | sed 's/\(.*\)#.*/\1/')"
for wsFile in $files; do
  # construct the local path from the remote one
  targetFile="$localPath/${wsFile#$p4RemoteRoot/}"
  # create the parent dir if it doesn't exist. p4 files doesn't list directories
  mkdir -p $(dirname $targetFile)
  # print the file content from remote and write that to the local file.
  p4 print -q $wsFile > $targetFile
done

注意:我找不到该--field参数的任何文档,但您似乎可以使用文档中指定的“表单字段”中的所有内容:https ://www.perforce.com/manuals/v18.2/cmdref/Content /CmdRef/p4_client.html

于 2019-09-25T11:28:29.520 回答