Perforce refers to a different root while editing - perforce

I have the following perforce client perforce.myClient that contains different directories. When I open a file for edit using /perforce.myClient/p4 edit someFile
it fails with the following message /perforce.myClient/someFile is not under clients root '/my/other/perforce/client'
I did the following to ensure that perforce is picking up the right client
setenv P4CLIENT perforce.myClient
checked to see if the root points to the correct location using p4 client perforce.myClient
How else can I enforce the client?

P4CONFIG files are hugely useful for this. Do this:
p4 set P4CONFIG=.p4config
echo P4CLIENT=perforce.myClient>/perforce.myClient/.p4config
echo P4CLIENT=my.other.perforce.client>/my/other/perforce/client/.p4config
Now your P4CLIENT will change automatically based on your working directory.
http://www.perforce.com/perforce/doc.current/manuals/cmdref/P4CONFIG.html

You should be able to use the global options in your command like
p4 -c myclient edit -c mychangelist //...
Global options appear before the command name.

Related

Revert file in Perforce P4V from a different computer

I have a couple files checked out in Perforce on a different computer that I won't have access to until tomorrow. I received a request to revert them but I'm not sure how to do that from my home computer. I don't see an option and I can't find any results about this for the visual client. Is it even possible?
I ended up finding a suitable solution for myself.
I opened P4V and navigated to my workspaces. I edited the one with the checked out files and changed the workspace root and host to be from my current computer. After applying that, I was able to revert them as I normally would from the P4V client.
p4 revert takes as an option the client name, i.e workspace name.
From P4V>File> Open Command window here and try :
p4 revert -C *yourotherworkspace* -c changelist //...
If this is not enough you might have to add some global options settings like :
p4 -H remote_computer_name revert -C *yourotherworkspace* -c changelist //...

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

How can I open for edit 10k perforce files using list of files as parameter?

I have 10k perforce files mentioned in my file.txt.
I need to open them using p4 edit command.
I expect some command like "p4 edit ?????file.txt". Can you help me to check these files out?
You can use the -x flag on p4. This is assuming a UNIX shell.
cat file.txt | p4 -x - edit
I assume you have some copy of directories structure where you have changes, and now you need to add those files to a change list. Which is impossible to do without checking them out. Am I right?
If I needed to change that much amount of files, I would do like this:
Copy all files I wanted to check in replacing read-only files (Wondows Explorer can do that)
In P4V go to a directory you need to check out files in, and then call "Reconcile offline work".
In appeared dialog choose all files.
Get new changelist with changed files being checked out.
I used this solution a couple of times - it works for added, changed and deleted files.
Just use below command to edit all files present in file.txt
p4 -x file.txt edit

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