Slide 1

Slide 1 text

From Perforce To Git: Lessons Learned Lars Schneider Technical Lead GitHub Solutions Autodesk larsxschneider kit3bus [email protected]

Slide 2

Slide 2 text

‣ Best known for AutoCAD - 2D and 3D computer-aided design ‣ 33 years in business ‣ 4000 engineers, hundreds of products, terabytes of code and assets ‣ Architecture, engineering and construction (e.g. Revit) ‣ Manufacturing (e.g. Inventor) ‣ Media and entertainment (e.g. Maya) ‣ 3D printing (e.g. Spark) Who is Autodesk?

Slide 3

Slide 3 text

Why do we migrate code to Git? ‣ Standardize ‣ Discover ‣ Share/Reuse ‣ Collaborate Quality!

Slide 4

Slide 4 text

What you learn? 1. Migrate repositories using git-p4 ‣ History ‣ File encodings ‣ Branches ‣ Binary files 2. Restructure repositories 3. Non-technical issues

Slide 5

Slide 5 text

Migration from Perforce (p4) to Git export P4USER="lars" export P4PORT=“tcp:my-perforce-server.com:12345” p4 login mkdir demo && cd demo git-p4 clone //depot@all . --verbose git remote add origin [email protected]:org/demo.git git push origin Demo migration using git-p4: Downloads: https://www.perforce.com https://github.com/git/git/blob/next/git-p4.py

Slide 6

Slide 6 text

Perforce client spec ! ! Client: projectX-spec! Owner: lars! Root: /workspaces/temp! Options: noallwrite noclobber nocompress unlocked nomodtime normdir
 SubmitOptions: submitunchanged! LineEnd: local! View:! //depot/projectX/src/... //myspec/src/...
 //depot/tests/projectX/... //myspec/tests/... File:/path/to/client.spec ... p4 login p4 client -i < /path/to/client.spec mkdir demo && cd demo git init git config git-p4.useClientSpec true git config git-p4.client projectX-spec git-p4 clone //depot@all . --verbose ...

Slide 7

Slide 7 text

Path case ! 
 Client: myspec! Owner: lars! Root: /workspaces/temp! Options: noallwrite noclobber ...! SubmitOptions: submitunchanged! LineEnd: local! View:! //depot/case/... //myspec/...! File:/path/to/client.spec !

Slide 8

Slide 8 text

Path case ? !

Slide 9

Slide 9 text

Path case !

Slide 10

Slide 10 text

Path case export P4USER="lars"! export P4PORT="tcp:server.com:12345"! ! p4 login! p4 client -i < /path/to/client.spec! ! mkdir demo && cd demo! git init! git config git-p4.useClientSpec true! git config git-p4.client myspec! git config core.ignorecase true" git-p4 clone //depot@all . --verbose! ... !

Slide 11

Slide 11 text

Path case ? !

Slide 12

Slide 12 text

Path case bug !

Slide 13

Slide 13 text

Path case …fixed in Git 2.6 ! !

Slide 14

Slide 14 text

! Path encoding Perforce Git cp1252 (Wester European Windows) UTF-8 (usually on Linux/OSX) UTF-8 UTF-8

Slide 15

Slide 15 text

export P4USER="lars"! export P4PORT="tcp:server.com:12345"! ! p4 login! ! mkdir demo && cd demo! git init! git config git-p4.pathEncoding cp1252" git-p4 clone //depot@all . --verbose! git remote add origin [email protected]:org/demo.git! git push origin! ! Windows Path encoding !

Slide 16

Slide 16 text

export P4USER="lars"! export P4PORT="tcp:server.com:12345"! ! p4 login! ! mkdir demo && cd demo! git init! git config git-p4.pathEncoding cp1252" git-p4 clone //depot@all . --verbose! git remote add origin [email protected]:org/demo.git! git push origin! ! Windows Path encoding …in Git “next”, part of 2.7 ?! !

Slide 17

Slide 17 text

UTF16/Unicode file encoding What?!!

Slide 18

Slide 18 text

UTF16/Unicode file encoding Perforce text file line ending conversions Windows Unix CR LF LF as defined on migration Git binary file no conversions Windows Unix

Slide 19

Slide 19 text

UTF16/Unicode file encoding Git binary file no conversions Windows Unix ! ! Client: myspec! Owner: lars! Root: /workspaces/temp! Options: noallwrite noclobber ...! SubmitOptions: submitunchanged! LineEnd: win! View:! //depot/path/... //myspec/...! File:/path/to/client.spec CR LF

Slide 20

Slide 20 text

File encodings ‣ Perforce added UTF16 support in 2007 ‣ Old file revisions might be in a bad state: ! Translation of file content failed near line 1" Details: http://answers.perforce.com/articles/KB/3117 ...! git-p4 clone //depot@all . --verbose" ... …scheduled for Git “next”, part of 2.7 ?! !

Slide 21

Slide 21 text

Branches ‣ Directories (Perforce) vs. Graph (Git) ‣ Git-P4 branch import did not work for me ‣ Poor man’s branch import!

Slide 22

Slide 22 text

Branches 1. Import Perforce branch directories as individual Git branches A B Release 1 2 3 Master

Slide 23

Slide 23 text

Branches 2. Create a copy of your branch Release 1 2 3 Master A B p4-history/Release

Slide 24

Slide 24 text

Branches 3. Squash and rename your branch X Squashed Release 1 2 3 Master A B p4-history/Release

Slide 25

Slide 25 text

Branches 4. Create a new Git branch based on Master X Squashed Release 1 2 3 Master A B p4-history/Release Release

Slide 26

Slide 26 text

Branches 5. Commit the delta of the squashed branch X 1 2 3 Master A B p4-history/Release Release

Slide 27

Slide 27 text

Branches 6. Continue to work with Git branches X 1 2 3 Master A B p4-history/ 4 5 Y Release

Slide 28

Slide 28 text

‣ Difficult due to Git’s design ‣ Git extensions to the rescue: ‣ git-annex ‣ git-fat ‣ git-media ‣ Git LFS Git Repo File Server 1011 0101 1101 1011 0101 1101 1011 0101 1101 1011 0101 1101 1011 0101 1101 Pointer Pointer .gitattributes Large binary files Details: https://git-lfs.github.com/

Slide 29

Slide 29 text

Large binary files Yeah!!

Slide 30

Slide 30 text

Large binary files export P4USER="lars" export P4PORT="tcp:server.com:12345" p4 login mkdir demo && cd demo git init git config git-p4.largeFileSystem GitLFS git config git-p4.largeFileExtensions mp4 git config git-p4.largeFilePush True git remote add origin [email protected]:org/demo.git git-p4 clone //depot@all . --verbose git push origin ! ! #! # Git LFS (see https://git-lfs.github.com/)! #! *.mp4 filter=lfs -text" File:.gitattributes

Slide 31

Slide 31 text

Large binary files What file extensions should you pick?

Slide 32

Slide 32 text

Large binary files export P4USER="lars"! export P4PORT="tcp:server.com:12345"! ! p4 login! ! mkdir demo && cd demo! git init! git config git-p4.largeFileSystem GitLFS! git config git-p4.largeFileCompressedThreshold 200k" git config git-p4.largeFilePush True! git remote add origin [email protected]:org/demo.git! git-p4 clone //depot@all . --verbose! git push origin ! ! #! # Git LFS (see https://git-lfs.github.com/)! #! /images/bigscreen.png filter=lfs -text! /libs/gigantic.mp4 filter=lfs -text" File:.gitattributes …scheduled for Git “next”, part of 2.7 ?!

Slide 33

Slide 33 text

Restructure repositories Source: https://marc.info/?l=git&m=124121401124923 – Linus Torvalds “Git fundamentally never really looks at less than the whole repo.”

Slide 34

Slide 34 text

Exclude undesired files Not part of the project!

Slide 35

Slide 35 text

Exclude undesired files ! ! Client: myspec! Owner: lars! Root: /workspaces/temp! Options: noallwrite noclobber nocompress ...! SubmitOptions: submitunchanged! LineEnd: local! View:! //depot/... //myspec/...! -//depot/octocats/... //myspec/octocats/..." File:/path/to/client.spec Source: http://www.perforce.com/perforce/doc.current/manuals/cmdref/views.html

Slide 36

Slide 36 text

‣ Speed up Git operations ‣ Reduce time to 
 clone/fetch Exclude undesired files ! ! Client: myspec! Owner: lars! Root: /workspaces/temp! Options: noallwrite noclobber nocompress ...! SubmitOptions: submitunchanged! LineEnd: local! View:! //depot/... //myspec/...! -//depot/octocats/... //myspec/octocats/..." File:/path/to/client.spec Source: http://www.perforce.com/perforce/doc.current/manuals/cmdref/views.html

Slide 37

Slide 37 text

Move 3rd party code ‣ Use native package manager (npm, pip, …) ‣ Use Git Submodules ‣ Zip components and upload them to Artifactory

Slide 38

Slide 38 text

Extract components ‣ Hard! Usually requires refactoring! ‣ Only viable for independent components which do not share same “pace of development”

Slide 39

Slide 39 text

Watchman ‣ Daemon to monitor file system changes, developed by Facebook ‣ Default: Git asks file system for changes ‣ Watchman: Filesystems tells Git what changed ‣ Git proof of concept by David Turner, Twitter Details: https://facebook.github.io/watchman/ https://www.mail-archive.com/git%40vger.kernel.org/msg49593.html

Slide 40

Slide 40 text

Biggest technical challenge # of files

Slide 41

Slide 41 text

How about non-technical challenges? ‣ new concepts forks staging area remotes hashes rebase Seriously?!!

Slide 42

Slide 42 text

How about non-technical challenges? ‣ new concepts ‣ new workflows pull requests feature branches

Slide 43

Slide 43 text

How about non-technical challenges? ‣ new concepts ‣ new workflows ‣ new user interface Command line? 80s again?!? SourceTree GitHub

Slide 44

Slide 44 text

How about non-technical challenges? ‣ new concepts ‣ new workflows ‣ new user interface adaptive challenges!

Slide 45

Slide 45 text

Start a movement ‣ Established a GitHub Experts Team ‣ Created GitHub Q&A page ‣ Hands on training for the first projects ‣ Create a Git fan base!

Slide 46

Slide 46 text

Summary: Perforce to Git ‣ Use git-p4, latest version ‣ Use LFS for large files ‣ Try to reduce the # of files ‣ Start a movement

Slide 47

Slide 47 text

Thanks Lars Schneider Technical Lead GitHub Solutions Autodesk From Perforce To Git: Lessons Learned larsxschneider kit3bus [email protected]