Bruce Adams
Bruce Adams

Reputation: 5599

git p4 clone file history including integration history

tl;dr; I wish to retain the history for files migrated to git including the history from earlier integrations. i.e. git p4 clone such that git log --all --follow <file> == p4 filelog -li <file>

Longer version:

I have a project in perforce which includes files that have been moved and copied around other projects in the reposotory in the past.

p4 filelog -l <file2>

shows the history for the file (-l for long form) in its current position. Files are moved (copied) around with p4 integrate e.g.

p4 integrate <file1> file2>

To see the history before the move you use:

p4 filelog -li <file2>

The equivalent git command is:

git log --follow <file2>

Now if I clone part of the perforce project using:

git p4 clone //depot/some/path/...@all .

I get the full history for the file as I would for the same file its current directory location in perforce.

(You get a single commit for the file at is now without @all see Getting the whole files history with git-p4)

How do I get git log --follow <file2> to give me the full history that I would have seen with p4 filelog -li ?

You may note that the file history is less useful on its own than the repository history. For example, a lone file may not even compile without other files at the right version in the right relative location. However, the full perforce repository contains history of many other unrelated projects which must not be included in the git repo. I don't want pruning the repository or grafting history to be a long painful process (am relatively new to git and want to avoid the darker corners for now).

What would it take to add an option to git p4 clone that copied the files history across integrations so that --follow works?

This is very similar to git p4: migrate full history - including integration history

Unlike that question I have always moved files within the repository using p4 integrate so the file history recorded by perforce is unbroken. That ought to make my task easier. Though I'm not sure if it does in practice.

Upvotes: 0

Views: 1001

Answers (1)

Vitor
Vitor

Reputation: 1976

Git works differently from Perforce and will not track file copies and renames, so there is no way of importing that information through git p4. Instead Git is able to identify file renames and/or copies automatically while analyzing commits. Obviously, this requires more processing, so it is not enabled by default.

What you are looking for are the arguments -M, -C and --find-copies-harder. In general you want to use the first two arguments in the format -M85, where the number 85 represents the amount of code that must be equal to consider that the files are the same. This allows detecting files that were renamed and also modified in the same commit. Note that if you enable -C then you don't need to enable -M.

Git p4 provides the detectCopies and detectCopiesHarder configuration parameters in order to detect this and submit the changes using p4 integrate instead of p4 delete and/or p4 add.

Upvotes: 1

Related Questions