Perforce - Specify target directory path for sync - perforce

Is it possible to specify the folder name where depot needs to be synced ?
I tried syncing the depot to my specified path using following command but it does not work.
p4sync -d "c:\my\path" sync //depot//branch/file
Note : My aim is just to copy the file from depot to my specified location.
Looks like sync is not the command I should be using. Is there any other command or way I can do this ?

sync - gets files from depot to your workspace, which must be already customized. To get files without workspace you need to make some hack with command "print":
p4 print -o filename //path/on/depot/filename
This command (above) gets filename and store it in "filename". Also, you can make some another workaround to get all files from some directory, probably with "p4 -x - command" ( -x stands for xargs in unix-world)

Related

perforce sync no such files

I am trying to setup perforce. I installed p4v and setup workspace.
Then I ran
C:\"Program Files"\Perforce\p4 -p perforce-test:1500 -u test-user -c test-user_test sync //test-folder/test/
But I get error //test-folder/test/ no such files(s)
I can see files and folder exist in p4v depo.
Use the path:
//test-folder/test/...
Directories aren't objects in Perforce, they're just part of the file name -- so you don't sync a directory called "//test-folder/test/", you sync all the files whose paths match the pattern "//test-folder/test/...".
Use the “...” in the end
e.g.
Wrong : p4 sync //test-folder/test/
Right : p4 sync //test-folder/test/...

how to sync the perforce client only with the files of a particular change list using p4 sync command

I'm trying to sync only the files modified in a particular change list to p4v.
Suppose in a perforce directory //demo/test I have 10 files out of which only 3 are modified as part of change list number 1234. I want only 3 files to be synced up. I have tried below options but it did not work.
p4 sync //demo/test...#1234;
This command says the files are updated but i don't see the files synced up.
p4 sync -f //demo/test...#1234;
This command is syncing all 10 files in the directory.
Use
p4 sync //demo/test...#1234,1234
or
p4 sync //demo/test...#=1234
When running tests like these, remember that 'p4 sync' won't sync a file that you already have, which is why you found the need to run 'p4 sync -f' to force the files to be sent even though the server knows you already have them. If you want to clear the server's memory of the files that you have, you can run
p4 sync //demo/test...#none
which will remove all the (p4-managed) files matching '//demo/test...' from your workspace, and then 'p4 sync' will bring them back the next time.
Oh, and since 'test' is a directory, the pattern
//demo/test/...
is preferred to
//demo/test...
since '//demo/test/...' matches only the files in the test directory, while '//demo/test...' will also match the files in the '//demo/test1', '//demo/test-and-set', and '//demo/testarossa' directories (if those should happen to exist).

How to detect if folder is under Perforce/ source control

I need to find out if file/folder is under specific source control.
The easiest way of doing this is to find some hidden folders. (this does not guaranty that partifical file is under source control, but with some probality says that this source control was used )
It's quite straightforward with SVN, GIT, as they have hidden folders.
But I can not find the same things for Perforce and ClearCase. Are there any universal way to understand what VSC is used in those paricular cases?
Perforce does not litter the drive, but keeps the info on the server. Also, files can be mapped in different structures, and mixed with non-controlled files, so it's not something you can determine by looking at the file itself.
However you can simply ask Perforce. For example, at the CLI:
P4 fstat FILENAME
Will give you info about a file if it is under source control.
If you need to script it for Perforce, there is an option (-s) that makes things easier (since the exit code of p4 doesn't indicate success or failure of the Perforce command). So, for bourne-like shells something like this should work:
if p4 -s fstat FILENAME | grep 'exit: 0' >/dev/null 2>&1 ; then
echo "Perforce knows this file"
else
echo "Perforce don't care"
fi
For ClearCase, you will find a hidden file named view.dat at the root directory of a (snapshot) view .
If the file is under M:\ (Windows) or /view/vobs (Unix), no need to look for an hidden file or directory: you know it is a dynamic view.
Another way is to execute, in the parent directory of a file:
cleartool lsview -cview.
If that directory is in a view, that command will return its name.
Similarly, i you can run a command like p4 reconcile or p4 status, and it doesn't return an error, chances are you are in a Perforce workspace.

Substituting client path on P4 sync

I have an XML file that refers to some other files. I can use neither relative paths nor variables in this file.
Is it possible to somehow add to the P4 repository a template and some script that will generate that file on the sync? E.g. I can use something trivial like sed to update paths depending on where the P4 client root is.
I really would like to make this transparent so I know that this file is always of proper version and contains actual info.
If you mean you want dynamic root, try putting "null" (no quotes) in the root path of your workspace, and the root of your workspace will be whatever directory you are in.
If you are trying to create a dynamic workspace, you can create a text file of your workspace (p4 client -o > template_worksapce.txt) and use sed on that to create a workspace, then read it in via p4 client -i
Is that what you were looking for?
Try:
p4 info | grep 'Client root'
or:
p4 -ztag client -o | grep Root

P4 changes on a specific folder/file

I am trying to get the last checkin on a particular folder structure on perforce, I know "p4 changes -m1 'filepath" does the job, but the problem is the filepath has to be the depot file-path. What I have on the other hand is the local filepath something like "C:\Android\Version10.2\MyApp\" and not "//depot/Andoid/Version10.2/MyApp".
I tried using commands like "p4 fstat", "p4 where" and "p4 files", but for all of them it works fine with the depot file path, if I give the local file path, it keeps complaining file(s) not on client/no such file(s).
The other issue is I dont have rights to change the p4client on the machine. How do I get this to work?
Basic question then to sum up is being able to get the last change on a folder/file for which I have the local filepath.
Regards
If you're going to run any commands on files those files have to be in the workspace. The problem is probably that p4 on Windows defaults to the machine name as the workspace name if you don't supply one.
So you either have to run set P4CLIENT=<clientname> then run p4 changes -m1 <filename>,
or p4 -c <clientname> changes -m1 <filepath> where <filepath> can be the file on your local file system, so C:\Android\Version10.2\MyApp\ would be acceptable.
Does p4 filelog -m 1 <filename> give you what you want? You can add the -l (lowercase L, not one) switch to get more information.
If you have a local file (as opposed to the depot-path), then you also should have a client-spec. You need to specify this with the -c option:
p4 -c <name-of-client-spec> changes -m1 <filepath>

Resources