Does Perforce force the prohibition of transferring immutable files?

Perforce allows people to scan immutable files. Why does any version control system assume that this is beyond me, but this is a topic for another question. I want to create a trigger that will reject the representation of unchanged files. However, I have no experience with Perforce triggers. From what I read, I assume that this will be a Change-Content trigger, since the files that will be sent will have to be different from the corresponding changes in the chapter that they are about to replace. I will need to iterate over the incoming files and make sure that they really changed. The problem is that I have no idea how to do this.

Can anyone with experience launching Perforce offer an example, or at least point me in the right direction?

+7
perforce triggers
source share
7 answers

In the latest version of perforce, enable client configuration that prevents the sending of immutable files:

SubmitOptions: Flags to change submit behaviour. submitunchanged All open files are submitted submitunchanged+reopen (default). revertunchanged Files that have content or type revertunchanged+reopen changes are submitted. Unchanged files are reverted. leaveunchanged Files that have content or type leaveunchanged+reopen changes are submitted. Unchanged files are moved to the default changelist. +reopen appended to the submit option flag will cause submitted files to be reopened on the default changelist. 

This may be an opportunity to investigate whether the user simply checks for immutable files due to apathy.

EDIT:

Given that you want to force the restriction regardless of the parameters of the user's workspace, you will need a trigger, as suggested in other answers.

You will need to look at the Perforce documentation to find out the details, but you will need a content change trigger.

You will probably want to pass% user%, as well as% change% plus, possibly other variables, so that you can limit expensive operations to only the problem user.

+5
source share

If you look at the Triggers table in Perforce, you will see that triggers are nothing more than scripts that are called when an event occurs. In your case, a content change event is triggered.

You have several scripting options that interact with Perforce. The Perforce downloads page has libraries and modules for many widely used languages. Any of this will help you and greatly simplify what you need to do. Also, check the Perforce Documentation page and download the admin guide. He will explain how to create a trigger, etc.

Basically, you need to write a script that will receive information from the list of changes that is sent, and for each file, it runs the diff command against the server. If you find a file that has not changed, you need to cancel the feed.

The Perforce module in your favorite language and the admin guide will give you all the answers you need.

+1
source share

You want to write a content change trigger. These triggers are triggered after the files are transferred to the server, but before they are bound to the database. According to perforce documentation, you can use a command similar to the following

 p4 diff //depot/path/...@=<change> 

In the content change trigger @ = (where the change is the change list number sent to the trigger), you will receive the contents of the files that were sent. If you are looking for a way to check the server version, you can do something like

 p4 diff -sr //...@=<change> 

The -sr command will report files that open and match the contents of the current storage. Since the files have not yet been committed, Iโ€™m going to assume that you really get the list of files whose contents were transferred to the server, the same as the current version of the chapter in the repository. If p4 diff -sr returns any files that are the same, return a non-zero exit code and the feed will stop and the user will have to manually return their immutable files.

I donโ€™t think you want to actually change the contents of the change list by making a return for it. That sounds too dangerous.

Please note that you can write your trigger in any language that makes sense (as the previous poster suggested). I really think that such a trigger would be quite heavy. You will, in effect, apply diff for all content presented to all users to take one step of the developer in the queue. This may be a good price to pay, but depending on the number of users and the size of their change lists (and files), this type of trigger can take a long time.

+1
source share

Instead of using a trigger, you can edit your workspaces (provided that you have the correct permissions) by default for the presentation strategy, which avoids this. By default (again, I donโ€™t know why) peforce will send all selected files, even if they have not changed, but this can be changed. Open its workspaces and set the SubmitOptions parameter to "revertunchanged", which will return any files in the list of changes that have not changed, or "leaveunchanged", which will save them but not send them.

It is also possible to do this in a separate change list if he just wants to take a look at the "On" drop-down list.

We had this problem in our environment, but as soon as I explained to the offenders what was going on and how easy it was to change the default behavior, which they changed without any problems.

+1
source share

Below is an example script on Linux using a perl script. I am sure that you can adapt it to Windows if necessary and use a scripting language other than Perl.

As the admin user, enter p4 triggers .

Add this under the Triggers: line of your script.

Trigger_name change-content //... "/<path_to_trigger_script>/<script_name> %changelist% %serverhost% %serverport% %user%"

Trigger_name arbitrary. //... means all your version files, but you can change this as needed. Everything that % is surrounded by is a unique variable name unique to Perforce, and these will be the arguments to your script. That should be all you need. Note that anything surrounded by <> is variable and depends on your environment.

Now for the script itself. This is what I wrote.

 #!/usr/bin/perl # ----- CHECK 1 : Make sure files NOT identical # get variables passed in through triggers call 'p4 triggers' $ChangeNum = $ARGV[0]; #change number $Server = $ARGV[1]; $Port = $ARGV[2]; $User = $ARGV[3]; $p4 = "<path_to_p4_exec>/p4 -p $Port "; # get list of files opened under the submitted changelist @files = `$p4 opened -a -c $ChangeNum | cut -f1 -d"#"`; # go through each file and compare to predecessor # although workspace should be configured to not submit unchanged files # this is an additional check foreach $file (@files) { chomp($file); # get sum of depot file, the #head version $depotSum = `$p4 print -q $file\#head | sum`; # get sum of the recently submitted file, use @=$ChangeNum to do this $clientSum = `$p4 print -q $file\@=$ChangeNum | sum`; chomp $depotSum; chomp $clientSum; # if 2 sums are same, issue error if ( $depotSum eq $clientSum ) { # make sure this file is opened for edit and not for add/delete if ( `$p4 describe $ChangeNum | grep "edit"` ) { printf "\nFile $file identical to predecessor!"; exit( 1 ); } } } 
0
source share

We have a script trigger that starts by checking the SubmitOptions property of the client specification for submitunchanged. If this is not the case, the script trigger may exit because the user was unable to send the immutable file. Otherwise, we check all files in which the action is edited, and the file type has not been changed. We compare such files with the previous version.

0
source share

Add this to the triggers table:

 Triggers: myTrigger form-in client "sed -i -es/submitunchanged/leaveunchanged/ %formfile%" 

This will not allow anyone to save the client with the submitunchanged parameter, which in turn will make it difficult to send unmodified files.

0
source share

All Articles