Comment attachments

P4 Code Review supports attaching arbitrary files to comments in code reviews and jobs. The name of user who attached the file to the comment is capture within the P4 filelog.

You can preview image files once they have been added to a comment, or download them by clicking on the download icon.

A configuration change only takes effect when the configuration cache has been reloaded. You must be an admin or super user to reload the P4 Code Review config cache. Navigate to the User id dropdown menu, select System Information, click the Cache Info tab, and click the System Information.

If changes to the config.php file might have caused the P4 Code Review web interface to become unresponsive, remove the problematic changes from the config.php file, then clear the configuration cache by running this command:
rm -f /opt/perforce/swarm/data/cache/module-config-cache.php

Comment attachment storage

To store files attached to comments, P4 Code Review looks for a depot named //.swarm. As P4 Code Review does not create this depot, you need to create it, or specify another depot that the P4 Code Review admin user can write to.

The depot used to store P4 Code Review attachments must be:

  • a classic depot because other depot types, such as stream, unload, archive, and spec depots, are not supported. To learn more, see Work with depots in the P4 CLI Reference.
  • a local depot (remote depots are not supported)
  • a depot that the P4 Code Review admin user can write to but other users cannot access. For more information about permissions, see Access authorization in the P4 Server Administration Documentation.
  • It is best practice to use a depot directory that is not used to store any other files, this stops other users having access to the attachments stored in the depot. We recommend that you use //.swarm

Create a directory for the comment attachments

We recommend that you use //.swarm because it is best practice to use a depot directory that is not used to store any other files This prevents other users from having direct access to the comment attachments.

  1. To create a //.swarm depot, run the following as a user with admin-level privileges:
  2. $ p4 depot .swarm

  3. Ensure that the P4 Code Review admin user can write to the //.swarm depot and make sure that other users cannot access it.
  4. For information on creating depots, see Working with depots in P4 Server Administration Documentation.

Specify the location for the comment attachments

By default P4 Code Review looks for a depot named //.swarm, to specify a different depot path for comment attachments, use the depot_storage configuration block in the SWARM_ROOT/data/config.php file.

It is mandatory to include the depot_storage configuration block in the P4 Code Review configuration. Failure to include the depot_storage configuration block will result in the option to add an attachment to a comment being unavailable in the P4 Code Review UI.

Replace depot_name with the depot where comment attachments are stored. The P4 Code Review admin needs to be able to write to this depot but make sure that other users cannot access it:

<?php
    // this block should be a peer of 'p4'
    'depot_storage' => array(
        'base_path'  => '//depot_name',
    ),

The base_path can be more than just the depot name, for example //depot/perforce/.swarm would work.

Maximum comment attachment size

By default, the maximum file size of a single comment attachment is limited to:

  • Ubuntu: 8 Mb

  • RHEL 8 and later: 2 Mb

Increasing the maximum attachment file size

Your can increase the maximum attachment size if required.

Ubuntu

Edit the php_value upload_max_filesize and php_value post_max_size configurables in the .htaccess file.

RHEL 8 and later

Edit the upload_max_filesize and post_max_size configurables in the /etc/php.ini file.