【问题标题】:git-p4 migrate branches in different subdirectoriesgit-p4 迁移不同子目录中的分支
【发布时间】:2016-06-03 06:30:04
【问题描述】:

我想将源代码树从 perforce 迁移到 git。源代码包含分散在 perforce 仓库中的多个开发分支,不一定在同一目录中。例如结构是这样的 -

//depot/dev/project/master 
//depot/dev/project/branch1 
//depot/dev/project/branch2
//depot/dev/sub-project/branch3 
//depot/dev/sub-project/branch4 
//depot/patch-project/branch5 
//depot/patch-project/special/developern/branch6 

我浏览了 git-p4 文档 https://git-scm.com/docs/git-p4 BRANCH DETECTION 部分以及类似的文章 http://forums.perforce.com/index.php?/topic/1395-git-p4-and-multiple-branches/

我可以迁移具有历史记录的分支,用于直接父级下的分支,例如

 //depot/dev/project/branch1 and 
 //depot/dev/project/branch2 

我无法实现的是如何同时迁移所有六个分支。

我尝试在指定分支规范后在 //depot@all 级别运行迁移,但是由于 perforce 服务器很大,它失败了,它给出了 maxresults 异常或会话超时。有人可以指导如何处理这种情况吗?

我看到的另一个选择是分别迁移分支(一个分支到一个 git 存储库),然后将所有分支合并到一个新的 git 存储库中。我不确定这样做是否会产生影响/不利影响。

Thanks and Regards,
Amar Kumbhar.

【问题讨论】:

    标签: git branch perforce git-p4


    【解决方案1】:

    总结: 好用,git-p4 是一个很棒的工具,非常智能,带有很多可配置的选项。分散在仓库树各处的多个分支成功迁移。我们需要在涵盖所有子目录或感兴趣的分支的最高级别(最顶层)perforce 目录中运行导入。为了高效操作,建议使用 --changesfile 选项,明确指定要导入的更改列表。还可以使用 git-p4.branchUsergit-p4.branchList 来明确指定分支规范。

    详细信息:我在这里展示了适合我的设置。可能有更好的方法来实现目标。

    Perforce 仓库结构:(如问题所述)

    Perforce 客户端: 这是设置在最高(最顶层)的 p4 目录。这非常重要,否则 git-p4 可能会将更改列表(由于客户端视图限制)排除为空提交。

       //depot/... //myp4client/...
    

    Perforce 分支规范:我创建了一个涵盖所有分支依赖(父/子)信息的分支规范

    $ p4 branch -o test1 | grep "//"
    
        //depot/dev/project/master/... //depot/dev/project/branch1/...
        //depot/dev/project/master/... //depot/dev/project/branch2/...
        //depot/dev/project/branch1/... //depot/dev/sub-project/branch3/...
        //depot/dev/project/branch1/... //depot/dev/sub-project/branch4/...
        //depot/dev/project/master/... //depot/patch-project/branch5/...
        //depot/patch-project/branch5/... //depot/patch-project/special/developern/branch6
    

    git-p4 配置项: 接下来,我设置一个空的 git 存储库和以下配置项。

     mkdir workdir
     cd workdir
     git init
    

    (** perforce 变量)

    git config git-p4.user myp4user
    git config git-p4.passwowrd myp4password
    git config git-p4.port myp4port
    git config git-p4.client myp4client
    

    (** 强制使用 perforce 客户端规范)

    git config git-p4.useClientSpec true
    git config git-p4.client myp4client
    

    ( ** 限制探索仅由我创建的分支规范)

    git config git-p4.branchUser myp4user
    

    ( ** 分支信息,依赖关系,有趣的是只需要提及姓氏(分支路径中的目录名称),git-p4 会自动检测/选择所需内容,即完全扩展分支名称)

    git config git-p4.branchList master:branch1
    git config --add git-p4.branchList master:branch2
    git config --add git-p4.branchList branch1:branch3
    git config --add git-p4.branchList branch1:branch4
    git config --add git-p4.branchList master:branch5
    git config --add git-p4.branchList branch5:branch6
    

    变更列表文件:接下来,我收集了所有变更列表,用于我要迁移的所有分支。

    p4 changes //depot/dev/project/master/...  | cut -d' ' -f2 >> master.txt
    p4 changes //depot/dev/project/branch1/...  | cut -d' ' -f2 >> master.txt
    p4 changes //depot/dev/project/branch2/...  | cut -d' ' -f2 >> master.txt
    p4 changes //depot/dev/sub-project/branch3/...  | cut -d' ' -f2 >> master.txt
    p4 changes //depot/dev/sub-project/branch4/...  | cut -d' ' -f2 >> master.txt
    p4 changes //depot/patch-project/branch5/...  | cut -d' ' -f2 >> master.txt
    p4 changes //depot/patch-project/special/developern/branch6/...  | cut -d' ' -f2 >> master.txt
    
    sort -n master.txt | uniq > master_sorted.txt
    

    导入:最后我运行导入如下,我使用“同步”而不是克隆。

    cd workdir 
    ../git-p4.py sync //depot/... --detect-branches --verbose --changesfile /home/myp4user/master_sorted.txt
    

    在较小的 depot 上“ ../git-p4.py sync //depot@all --detect-branches --verbose ”也可以工作,在这种情况下不需要创建更改列表文件(前面的步骤)

    导入完成后,我可以看到 git-p4 在单个 git 存储库中创建了所有远程 perforce 分支。

     git branch -a
      remotes/p4/depot/dev/project/master
      remotes/p4/depot/dev/project/branch1
      remotes/p4/depot/dev/dev/project/branch2
      remotes/p4/depot/dev/dev/sub-project/branch3
      remotes/p4/depot/dev/dev/sub-project/branch4
      remotes/p4/depot/patch-project/branch5
      remotes/p4/depot/patch-project/special/developern/branch6
    

    然后我从远程 p4 分支创建了本地分支

      git checkout -b master  remotes/p4/depot/dev/project/master
      git checkout -b branch1  remotes/p4/depot/dev/project/branch1
      git checkout -b branch2   remotes/p4/depot/dev/dev/project/branch2
      git checkout -b branch3   remotes/p4/depot/dev/dev/sub-project/branch3
      git checkout -b branch4   remotes/p4/depot/dev/dev/sub-project/branch4
      git checkout -b branch5   remotes/p4/depot/patch-project/branch5
      git checkout -b branch6   remotes/p4/depot/patch-project/special/developern/branch6
    

    接下来我只是添加了一个远程源并将代码推送到 git repo。
    感谢 stackoverflow 和在线提供的各种指针/帮助。

    【讨论】:

    • 这是非常有用的信息。此类有用示例中的文档非常缺乏,通常我永远不会感谢 Stack OverFlow 上的任何人,但谢谢。这将为我节省大量时间。
    • 这太棒了!非常感谢!!
    【解决方案2】:

    最新版本的 git-p4 不应报告 maxresults 异常,因为它一次最多会检索 500 个更改。您可以尝试使用 --changes-block-size 参数修改此值,这可能会帮助您克服您报告的问题。

    这里是这个参数的描述,可以看到here

    --changes-block-size <n>::
        The internal block size to use when converting a revision
        specifier such as '@all' into a list of specific change
        numbers. Instead of using a single call to 'p4 changes' to
        find the full list of changes for the conversion, there are a
        sequence of calls to 'p4 changes -m', each of which requests
        one block of changes of the given size. The default block size
        is 500, which should usually be suitable.
    

    【讨论】:

    • 感谢您的意见。我尝试将 --changes-block-size 设置为较低的值,例如 100 和 50 甚至 5,因为 p4 服务器的大小很大,它仍然会为某些更改提供 maxresults execption 并且我的 p4 管理员抱怨我的脚本试图杀死服务器使其变慢/无响应。
    【解决方案3】:

    我之前遇到过类似的问题,在我的情况下,我必须找到一种解决方法,就是你描述的那个,我将每个分支克隆到它自己的 Git 存储库中。

    即使当时个别分支有太多对象,P4 管理员也不愿意提高请求对象的限制,所以我也不得不限制我克隆的历史数量。

    对于非活动分支,我只会克隆最新版本并丢弃其所有历史记录。

    对于更活跃的分支,我会保留 4-6 周的历史记录。

    这意味着您必须手动确定要保留的历史记录数量的 CL 编号:

    来自git-p4 docs(部分:DEPOT PATH SYNTAX):

    $ git p4 clone //depot/my/project@1,6 # Import only changes 1 through 6.

    【讨论】:

    • 感谢分享。我尝试了范围选项 //depot/my/project@1,6 这对我不起作用,因为我需要在顶级目录中运行。这启发了我尝试使用 --changesfile :: 准确导入“文件”中列出的 p4 更改编号,每行一个。通常,“git p4”检查当前 p4 存储库状态并检测它应该导入的更改。我将分享经验。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多