I need to get the local path of a depot file, for example:
input: //MyDepot/MyBranch/my file.txt
output (mac): /Volumes/p4/MyDepot/MyBranch/my file.txt
or:
output (windows): F:\p4\MyDepot\MyBranch\my file.txt
both 'p4 have' and 'p4 where' produce parse-unfriendly output, including mapping info I don't need. Is there a p4 command for that simple task?
On a non-Windows OS, Run:
p4 -ztag -F %path% where <depotFilePath>
This will give you the one-liner with only the local path.
On Windows, %path% expands to the system environment path so this only works on non-Windows systems.
The -F is a client-side option, so if you don't have it, you may need to update your p4 binary. If you don't have it, and can't update the binary, you can also just run p4 -ztag where <depotFilePath>.
You'd get back easy to parse output. The key is path to get the local path to the file.
The output will look like:
... depotFile //depot/a
... clientFile //gabe/a
... path /Users/gabe/tmp/a
Very close, Samwise. I would have made this a comment on the main answer, but not enough rep yet, sorry.
To prevent Windows from expanding the environment variable, both percents need to be carrot escaped, and that part of the expression must not be in quotes.
example: p4 -ztag -F ^%change^%,^%time^%,^%path^% changes -m 3
example from 2020/4/2: https://community.perforce.com/s/article/15148
Related
Is it possible to use variables defined in P4CONFIG files in p4 commands? Let's say I want to define an alias for quickly seeing pending changelists in the current workspace. So something like:
p4 changes -s pending -c $P4CLIENT
I don't want to define P4CLIENT in my bashrc as I switch between different workspaces a lot. I much prefer it to come from the current P4CONFIG file. Is that possible?
This should do it:
p4 -Ztag -F %clientName% info | p4 -x - changes -s pending -c
Note that you need a relatively current p4 client to use the undoc -F flag, which is described more here: http://www.perforce.com/blog/130826/fun-formatting
You could also script something around "p4 set P4CLIENT", which is a purely client-side query and therefore a bit faster, but you'll need to manipulate the output a bit to make it suitable as an argument to "p4 changes".
Given a path (on my computer), how can I test whether that file is under version control (ie. a copy exists in the Perforce depot)? I'd like to test this at the command line.
Check p4 help files. In short, you run p4 files <your path here> and it will give you the depot path to that file. If it isn't in the depot, you'll get "no such file(s)".
For scripting, p4 files FILE is insufficient because it doesn't change its exit code when there is no such file.
Instead, you can pass it through grep, which looks for perforce paths' telltale pair of leading slashes:
# silently true when the file exists or false when it does not.
p4_exists() {
p4 files -e "$1" 2>/dev/null |grep -q ^//
}
You can get rid of the 2>/dev/null and grep's -q if you want visible output.
Before p4 files version 2012.1 (say p4 files version 2011.1), it didn't support -e. You'll have to add |grep -v ' - delete [^-]*$' before the grep above.
Warning: A future p4 release could change the formatting and break this logic.
Similar to Adam Katz's solution except more likely to be supported by future releases of p4, you can pass global option -s which 'prepends a descriptive field' to each line. This is one of 'text', 'info', 'error' or 'exit' followed by a colon (and a space, it seems). This is intended for facilitating scripting.
For all files passed in to the p4 -s files command, you should get one line back per file. If the file exists in the depot, the line starts with info: whereas if the file does not exist in the depot, the line starts with error:. For example:
info: //depot/<depot-path-to-file>
error: <local-path-to-file>
So, essentially, the status lines are the equivalent of an exit code but on a per-file basis. An exit code alone wouldn't cope neatly with an arbitrary number of files passed in.
Note that if there is a different error (e.g. a connection error) then an error line is still output. So, if you really want the processing to be robust, you may want to combine this with what Adam Katz suggested or perhaps grep for the basename of the file in the output line.
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 -l ... shows us the list of check-ins and the description, but it doesn't show the list of files that were modified in the check-in. Is there a way to do that in one command, without the need to create a wrapper script that combines the output of another command like p4 describe or p4 file?
In Subversion, I can do this by running svn log -v.
The 'files' command can do what you're looking for. An easy way is:
p4 files //...#=<changelist>
That example will list the files modified by that changelist, under the view specified.
You can use the "describe" command to get the description of a changelist, along with the files affected.
For example, p4 describe -s <changelist> will describe the changelist, and the "-s" will prevent it from displaying file diffs.
One liner, list all changes made to a branch, with description and list of affected files, without showing the diff. Thanks to a combination of answers. Works on windows with Unix utils
p4 changes -s submitted //depot/xxx/yyy/zzz/... | grep -o "^Change [0-9]*" | cut -f2 -d" " | p4 -x- describe -s
Output:
Change 1753385 by user#clientspec on 2019/03/08 06:29:44
Changing the world
Affected files ...
... //depot/xx/yy/zz.h#6 edit
Change 1751752 by name#clientspec on 2019/03/05 15:24:00
I made a change to a file
Affected files ...
... //depot/xx/yy/zz.h#3 integrate
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>