In perforce how to check if any changes were made in the entire folder, and run a post processing script only if changes were made? - perforce

I am planning to create a cron job that does a p4 sync on a specific folder every day at a certain time and does some post processing of the files in the folder.
However, before doing the post processing I would like to check if the files in the folder differ from that of the perforce repository, and only if there are changes, I'd go ahead with the post processing.
How do I integrate a p4 diff with my csh script and if there's any other elegant way to check for differences and trigger the post processing.
In summary, I'm trying to achieve this:
if (check for differences in <my directory>) then
{ run my post-processing script }
else
{ dont run}

If you want to see if any new revisions have been added to the depot since your sync completed, you could run:
p4 have
in your workspace, and compare this to the output from:
p4 files
run against the corresponding depot files and/or directories.
Example:
jen#Jen: ~/workspaces/testing/depot/depot/testingjen#Jen:~/workspaces/testing/depot/depot/testing$ p4 have //depot/testing/...
//depot/testing/test#1 - /home/jen/workspaces/testing/depot/depot/testing/test
jen#Jen: ~/workspaces/testing/depot/depot/testingjen#Jen:~/workspaces/testing/depot/depot/testing$ p4 files //depot/testing/...
//depot/testing/test#2 - edit change 7445 (text)
Hope this helps,
Jen.

Related

git p4 branches not exported

I'm trying to migrate some p4 depots to github using git-p4.py script but I have trouble in exporting branches.
p4 structure is like this:
//depot1/first_directory/second_directory/projects_directory [eg: project_AA] (multiple directories that I want to migrate to separate github repositories)
//depot1/versions_directory/project_AA-or-BB-or-CC_xx_yy [eg: project_AA_01_01) (other directories that contains different release versions of project_directories that should go in github repo project_aa, project_bb etc
P4 branches exist like AA-version_branch and have one or multiple mapping views.
I managed to get tags, commit history (without commits from //depot1/versions_directory/project_AA-or-BB- etc) and content.
The main issue that branches are detected when 'git p4 sync --detect-branches --verbose' is executed, but there are no branch resulted to be added in github.
I executed 'git p4 clone --detect-branches --verbose //depot1#all' just to check what branches will be exported at the depot level, but the result was far away from the expectation like:
remotes/p4/depot1/first_directory/second_directory/project_AA/directory_inside_project_AA
or remotes/p4/depot1/other_directory/tags/a_tag_or_label/project_BB/directory_inside_project_BB
But all resulted branches are not in p4 branch list
I tried the method described on #37607393 but without any result. I believe this is due to perforce repository structure.
Any info or idea that I should try further?

Perforce: The submitted file doesn't match workspace version

I am facing a weird behavior in perforce submitted files, after p4 integrate
Scenario
Repo contains C# code and the built DLL. I wished to integrate a changeset from one branch to another
so I am following the steps which I had discussed, a while ago
The .cs files doesn't complain. If there is resolve conflict in the DLL, I choose either of Accept Source or Accept Target without much care. Reason being, I always rebuild the DLL before submitting
Issue
The DLL which was built in local workspace and reflected in the changeset is correct. I tested it locally and do p4 submit. But to my amazement, the DLL submitted is not the one which I had built. Instead the one which came from that other branch was submitted
Confusion
I thought that with perforce, when a file is opened in a changeset, always the latest(local) copy will be submitted. That is why I don't pay much attention if there are conflict reported in DLL
Isn't that correct ?
Why would the submitted file be different from my workspace version ?
When you "accept source" you're recording that you want the target file to be an exact copy of the source file; consequently, if you submit the file, it's not even transferred from the workspace (in order to save time) -- instead it's just copied server-side. If you tampered with the workspace file, this leads to the situation you describe where the workspace is now inconsistent with the depot, just like if you'd modified a file that wasn't open for edit.
If you submit with the -t flag (for "tamper checking"), it will check for tampered files by comparing what's in your workspace with what should be in your workspace according to the resolve options you picked:
C:\Perforce\test\integ>p4 integ source target
//depot/integ/target#2 - integrate from //depot/integ/source#3
C:\Perforce\test\integ>p4 resolve -at
c:\Perforce\test\integ\target - vs //depot/integ/source#3
//Samwise-dvcs-1509687817/integ/target - copy from //depot/integ/source
C:\Perforce\test\integ>echo tampertampertamper >> target
C:\Perforce\test\integ>p4 submit -t -d "submitting tampered file"
Submitting change 190.
Locking 1 files ...
integrate //depot/integ/target#3
//Samwise-dvcs-1509687817/integ/target tampered with after resolve - edit or revert.
Submit aborted -- fix problems then use 'p4 submit -c 190'.
Some file(s) could not be transferred from client.
If you p4 edit the file, it's changed from a pure copy to an edit, and will be read from the workspace instead of from the source file:
C:\Perforce\test\integ>p4 edit target
//depot/integ/target#2 - reopened for edit
C:\Perforce\test\integ>p4 submit -c 190
Submitting change 190.
edit //depot/integ/target#3
Change 190 submitted.

Get only one folder from a stream depot in Perforce

I am new to Perforce "stream depots" and stuck at step 1. I am trying to create a workspace that includes only one folder from a huge stream depot.
Every time I try, it seems to want to download the entire stream, which is a huge amount of files. I can see now way to limit it to just one folder.
This is what virtual streams are for.
Create a new stream that is a child of the stream in question, with type "virtual", and specify its Paths as the single folder, e.g.:
Stream: //streams/just_the_facts
Parent: //streams/main
Type: virtual
Paths:
share path/to/the/facts/...
Now switch to that stream:
p4 switch just_the_facts
and you only have the files from the facts folder.
What I ended up doing was:
p4 set P4CLIENT=MyWorkspace then
p4 client -s -S //My/Stream to create the workspace.
Then p4 sync //My/Stream/just/the/dir/I/want...

Checking out to another commit with git while reading the file

I am creating a server that handles version control of files in server and let the client view them at specific commit if they wanted.
The way I implement this is that when user clicks a specific commit, I call checkout [hash of commit] to revert the file back to what it was and then read from that file.
The problem is that two people may be trying to read different commits of the same repository at the same time, meaning the state of file may change while reading from the file.
I tried checking out another commit while reading from it and it seems to work okay but I cannot be sure when the it is scaled.
I am using nodeJS and express for my server. When nodeJS starts reading file, will it still be the same state as the point when it started reading or would it change along with the change that is forced by git if I checkout another commit while reading the file?
Instead of using checkout, consider show:
git show <commit id>:<filename>
This will print the contents of the file at that commit. If you absolutely need it in a file, generate a unique temporary filename and redirect the output:
git show <commit id>:<filename> > tmpfile_uniquesuffix

Uploading delta changes to perforce and label

Every month I need to sync big chunk of files from git and upload it to perforce and create a p4 label with all files uploaded, and from p4 I do builds, this is odd but we cannot change this now. so far I am uploading the files to new directory in p4 every time and creating label with all uploaded files, so I get a clean label for "this month's build" though most of the files didn't change compared to last month's upload, this happens through shell script, is there a way to upload only the delta changes and create label with old files (not uploaded as it didn't change) + changed/brand new files uploaded? any high level directions will help, thanks.
Do I understand correctly that "I am uploading the files to new directory in p4 every time" means that, each time you perform a 'p4 submit', the files in your changelist are actually different file names, not just newer revisions of the same files?
That is, if you did 'p4 describe' of the first changelist you submitted, would it look like:
//depot/dir/r1/A.c#1
//depot/dir/r1/B.c#1
//depot/dir/r1/C.c#1
while the next time you ran your tool, and did a 'p4 describe' of the changelist, it would look like:
//depot/dir/r2/A.c#1
//depot/dir/r2/B.c#1
//depot/dir/r2/C.c#1
If that is what you are doing, then if you could instead copy the files to the same location each time, so that the first time your tool ran you got:
//depot/dir/A.c#1
//depot/dir/B.c#1
//depot/dir/C.c#1
and the second time your tool ran you got:
//depot/dir/A.c#2
//depot/dir/B.c#2
//depot/dir/C.c#2
If you did things that way, then you could use the 'revertunchanged' feature of Perforce, and the files that were unchanged from the previous run of your tool would not be submitted, and the revision number would not change, so that over time you might get:
//depot/dir/A.c#7
//depot/dir/B.c#4
//depot/dir/C.c#19
Each time you run your tool, you can still create a label, because the label includes not just the file name but also the revision number, so the first label you created might include:
//depot/dir/A.c#1
//depot/dir/B.c#1
//depot/dir/C.c#1
while the 19th label you created might include:
//depot/dir/A.c#7
//depot/dir/B.c#4
//depot/dir/C.c#19
Hopefully this will get you pointed in a direction that is more suited to your goals.

Resources