0

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.

3
  • Fundamentally, Perforce records more information about the work you did than git does. There are actions you may have taken that git simply has no way to represent. Why don't you simply just leave your Perforce server online, so that you can consult it for historical analysis in the future, even after your new work is being committed in git? Nov 9, 2016 at 15:04
  • git can represent deltas to files it just needs a location for the file. I will allow that the location cannot be correct if the location is in a tree that does not exist in the git repo but presumably we can fake the file as being in a location that is (e.g. in a branch). Nov 9, 2016 at 16:40
  • An aim of moving some code to git would be to open source it leaving the perforce repo closed source. So external git users will not have access to it. Nov 9, 2016 at 16:41

1 Answer 1

1

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.

2
  • Are you talking about transferring data from git to perforce or from perforce to git? Your last comment "submit using p4 integrate" suggests from git to perforce but I am going the other way. Nov 9, 2016 at 21:48
  • Just adding extra information. That part is not relevant for your objective.
    – Vitor
    Nov 9, 2016 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.