JavaArchitect
JavaArchitect

Reputation: 79

git-p4 migrates perforce "main" branch into git branches as subdirectories (doubled code in git branches)

The Situation

Trying to migrate 1 "main" and 2 branches from perforce to git. After mapping the branches in perforce with specs, I tried a typical migration which resulted in code directory duplication issues.

The Problem

When running "git p4" (either clone or sync), a duplicate of the master branch code is included with the branches and the branch code is in a directory next to the master. I'd expect to see only the branch code in the git staging area.

Setup

#Perforce Repo Structure
//depot/main/branches/MAINT_01
//depot/main/branches/MAINT_02
//depot/main/branches/mobile

# perforce branch maps
# note: mobile and MAINT_02 are branched (in perforce) from MAINT_01
MAINT_02 -> //depot/main/branches/MAINT_01/... //depot/main/branches/MAINT_02/...
mobile  -> //depot/main/branches/MAINT_01/... //depot/main/branches/mobile/...

# Perforce info
Server version: P4D/LINUX26X86_64/2009.2/241896 (2010/04/10)
Client Spec: (need to exclude many branches here)
//depot/main/branches/... //buildmaster-scm01/...
-//depot/main/branches/BranchA/... //buildmaster-scm01/BranchA/...
-//depot/main/branches/BranchB/... //buildmaster-scm01/BranchB/...
-//depot/main/branches/tempBranch/... //buildmaster-scm01/tempBranch/...
-//depot/main/branches/Bar/... //buildmaster-scm01/Bar/...
-//depot/main/branches/Foo/... //buildmaster-scm01/Foo/...
-//depot/main/branches/Cheese/... //buildmaster-scm01/Cheese/...

# Git Info (Linux Box)
 /git/buildmaster/git2 302  % git --version
 git version 1.7.12.rc2

Migration Attempt

Here is how it went...

agvscm01.inq.com /git/buildmaster/git 225  % git init
Initialized empty Git repository in /git/buildmaster/git/.git/
agvscm01.inq.com /git/buildmaster/git 226  % git p4 sync --detect-branches --use-client-spec //depot/main/branches@all
Importing revision 20482 (88%)
    Importing new branch branches/MAINT_01

    Resuming with change 20482
Importing revision 21137 (96%)
    Importing new branch branches/mobile

    Resuming with change 21137
Importing revision 21396 (100%)
Updated branches: MAINT_01 MAINT_02 mobile
agvscm01.inq.com /git/buildmaster/git 227  % git checkout -b master p4/branches/MAINT_01
Checking out files: 100% (14923/14923), done.
Already on 'master'
agvscm01.inq.com /git/buildmaster/git 228  % git checkout -b rel_2 p4/branches/MAINT_02
Checking out files: 100% (15142/15142), done.
Switched to a new branch 'rel_2'
agvscm01.inq.com /git/buildmaster/git 229  % git checkout -b mobile p4/branches/mobile
Checking out files: 100% (29960/29960), done.
Switched to a new branch 'mobile'
agvscm01.inq.com /git/buildmaster/git 233  % git checkout master
Switched to branch 'master'
  agvscm01.inq.com /git/buildmaster/git2 303  % git branch -a
* master
  mobile
  rel_2
  remotes/p4/branches/MAINT_01
  remotes/p4/branches/MAINT_02
  remotes/p4/branches/mobile

Results

agvscm01.inq.com /git/buildmaster/git2 304  % git checkout mobile
Checking out files: 100% (15073/15073), done.
Switched to branch 'mobile'
agvscm01.inq.com /git/buildmaster/git2 305  % ls
MAINT_01  mobile
agvscm01.inq.com /git/buildmaster/git2 306  %

Note that MAINT_01 and mobile directories have all the correct history but only the contents of mobile should be seen at this level.

Expectations

The mobile branch branch should not be including the MAINT_01 directory. mobile is a branch of MAINT_01. This is probably something really simple but I'm not seeing it. Additionally, checking out master just includes MAINT_01 as root. The contents of MAINT_01 should be the root of the branch.

agvscm01.inq.com /git/buildmaster/git2_bak 307  % git checkout master
Switched to branch 'master'
agvscm01.inq.com /git/buildmaster/git2_bak 308  % ls
MAINT_01
agvscm01.inq.com /git/buildmaster/git2_bak 309  %

Appreciate any help here.


Upvotes: 4

Views: 1390

Answers (1)

JavaArchitect
JavaArchitect

Reputation: 79

There is a confirmed bug in git as of 1.7.11 in git-p4 module that mis-maps perforce code to git repo when using --use-client-spec and the --detect-branches options together. Snippet from an email response when I reported the issue to git dev team...

Thank you for the detailed report. It is a bug in 1.7.12-rc2. This series fixes it, on top of origin/master.

The crux of the matter is that files are mapped into the wrong locations in git when both --use-client-spec and --branch-detection are enabled.

Pete Wyckoff (5):

  • git p4 test: move client_view() function to library
  • git p4 test: add broken --use-client-spec --detect-branches tests
  • git p4: set self.branchPrefixes in initialization
  • git p4: do wildcard decoding in stripRepoPath
  • git p4: make branch detection work with --use-client-spec
 git-p4.py                     | 75 +++++++++++++++++++++++++++--------------

 t/lib-git-p4.sh               | 18 ++++++++++

 t/t9801-git-p4-branch.sh      | 77 +++++++++++++++++++++++++++++++++++++++++++

 t/t9809-git-p4-client-view.sh | 17 ----------

 4 files changed, 146 insertions(+), 41 deletions(-)

Currently they published 1.7.12rc2. Awaiting the fixed version

Upvotes: 2

Related Questions