salesforce / p4-fusion

A fast Perforce to Git conversion tool written in C++ using Perforce Helix Core C++ API and Libgit2
BSD 3-Clause "New" or "Revised" License
78 stars 15 forks source link

Parsing CL from commit messages breaks after using bfg-repo-cleaner #50

Open yukwunhang opened 2 years ago

yukwunhang commented 2 years ago

I used https://github.com/rtyley/bfg-repo-cleaner to purge large files from a repo generated by p4-fusion. bfg adds Former-commit-id to the commit messages:

...
[p4-fusion: depot-paths = "<snip>": change = 43110426]

Former-commit-id: 9885e208a53eb53e0f691fed688eae5565a814fd

After that, p4-fusion is unable to parse the CL from commit message:

[ WARNING @ Main:177 ] Detected last CL committed as CL 814f
[ PRINT @ Main:180 ] Requesting changelists to convert from the Perforce server
[ ERROR @ HandleError:13 ] Received error: error Invalid changelist/client/label/date '@>814f'.

814f comes from Former-commit-id: 9885e208a53eb53e0f691fed688eae5565a814fd.

Workaround: run bfg with --private to omit Former-commit-id from commit messages.

twarit-waikar commented 2 years ago

Ah this would break the auto-resume for sure. As a quick workaround that might work right now, you may be able to create a new commit with the correct format by doing this:

$ git show HEAD # Record the commit ID and tree ID
$ git cat-file -p <latest commit ID> | grep tree
tree <tree ID>
$ vi commit.txt # Add the new commit message, but use the proper format that p4-fusion expects
$ echo "$(cat commit.txt)" | git commit-tree <tree ID> -p <latest commit ID>
<new commit ID>
$ git update-ref HEAD <new commit ID>
$ git show # Check if it worked

Naive implementation - p4-fusion should only consider the string from change = up until the next newline character, and not the end of the entire commit message

Probably better implementation - p4-fusion should search for a line in the commit message that has the proper semantics i.e. [p4-fusion: depot-paths = "ABCDEFGH": change = XXXXXXXX], either by regex or only considering the line that starts with [p4-fusion