Using P4CONFIG variables in p4 commands - perforce

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".

Related

perforce: 'p4 changes' with its change 'diff' between two changesets

is there a way to list out all the changes with each change's subject and its change difference between two changesets?
p4 diff2 -u //depot/build/stage/gobuild/...#676277 //depot/build/stage/gobuild/...#676640
this giving only consolidated diff
Here's how to script Bartek's answer, in one easy line:
p4 -Ztag -F "describe %change%" changes -s submitted #676277,676640 | p4 -x - run
If you want to massage the output further you'll need to buckle down and learn a scripting language -- the p4 command line can do a lot on its own but it's no substitute for Perl. :)
p4 changes won't show you diffs. You could use it for collecting changelist numbers and then you could call p4 describe for each which will produce a diff.
See p4 help describe for the formats of diffs.

Perforce: How to move unresolved files to a separate CL

I'm currently (and regularly) performing very large integrations (usually 50k+ files). In P4V, it is technically possible to display and manually work with those files, but it's slow and unwieldy.
Is there some way to move unresolved files to a separate CL without needing to write an application? I was taking a look at "p4 resolve -n" but I can't figure out how to use that output with p4 reopen (assuming this is even the best way of doing what I want.)
Any help would be appreciated.
You can use this:
p4 -F %localPath% resolve -n | p4 -x - reopen -c default
Explanation:
-F %localPath%: tells p4 to output paths in local format
resolve -n: means "list unresolved files without actually resolving them". (P4 Resolve)
-x -: Tells p4 we'll be working on a list of files, and '-' means that the list of files is coming from stdin (piped) (p4 Global options)
reopen -c default: reopen incoming specified files in given changelist ("default" can be replaced by an existing changelist number). (p4 reopen)
Update:
For very big changelists, sometimes the command gets stuck. You can do it in 2 steps to workaround the problem:
p4 -F %localPath% resolve –n > c:\p4_output.txt 2>c:\p4_errors.txt
p4 -x - reopen -c default < c:\p4_output.txt
Note: When reopening files that were moved, p4 reopen will only move "half" of the change (the add) and leave the delete in the previous changelist. I haven't found a solution other than moving those manually.
Something like:
p4 -F %localFile% resolve -n | p4 -x - reopen -c CHANGE
ought to do it. (Run "p4 -e resolve -n" to see the list of available variables in the output, I think localFile is the one you want.)
I had a similar problem sometime ago.
To move a Perforce changelist to another computer/workspace,
follow the steps given in the below link:
movng unresolved files/changelists

p4 describe for multiple changelists

I want to redirect the output pf "p4 describe" for a set of Changelists, into a xls file.
As I saw the syntax for p4 describe, we can only give a single changelist with "p4 describe" for ex: p4 describe -df .
Could you please help me get p4 describe for multiple CLs?
Here's the syntax for 'p4 describe', from 'p4 help describe':
describe -- Display a changelist description
p4 describe [-d<flags> -s -S -f -O] changelist# ...
Note that '...' at the end. That means that you can pass multiple arguments.
So, for example,
p4 describe -df 1704 1722 1903
works fine, and describes each changelist, in turn, one after the next, in a single command.
Now, as to the bit about trying to put this in a xls file, I'm confused, because I'm not sure what sort of xls file you're talking about. The output of describe doesn't seem very useful as a spreadsheet, to me.

Find a string in Perforce file without syncing

Not sure if this is possible or not, but I figured I'd ask to see if anyone knows. Is it possible to find a file containing a string in a Perforce repository? Specifically, is it possible to do so without syncing the entire repository to a local directory first? (It's quite large - I don't think I'd have room even if I deleted lots of stuff - that's what the archive servers are for anyhow.)
There's any number of tools that can search through files in a local directory (I personally use Agent Ransack, but it's just one of many), but these will not search a remote Perforce directory, unless there's some (preferably free) tool I'm not aware of that has this capability, or maybe some hidden feature within Perforce itself?
p4 grep is your friend. From the perforce blog
'p4 grep' allows users to use simple file searches as well as regular
expressions to search through file contents of head as well as earlier
revisions of files stored on the server. While not every single option
of a standard grep is supported, the most important options are
available. Here is the syntax of the command according to 'p4 help
grep':
p4 grep [ -a -i -n -v -A after -B before -C context -l -L -t -s -F -G ] -e pattern file[revRange]...
See also, the manual page.
Update: Note that there is a limitation on the number of files that Perforce will search in a single p4 grep command. Presumably this is to help keep the load on the server down. This manifests as an error:
Grep revision limit exceeded (over 10000).
If you have sufficient perforce permissions, you can use p4 configure to increase the dm.grep.maxrevs setting from this default of 10K to something larger. e.g. to set to 1 million:
p4 configure set dm.grep.maxrevs=1M
If you do not have permission to change this, you can work around it by splitting the p4 grep up into multiple commands over the subdirectories. You may have need to split further into sub-subdirectories etc depending on your depot structure.
For example, this command can be used at a bash shell to search each subdirectory of //depot/trunk one at a time. Makes use of the p4 dirs command to obtain the list of subdirectories from the server.
for dir in $(p4 dirs //depot/trunk/*); do
p4 grep -s -i -e the_search_string $dir/...
done
Actually, solved this one myself. p4 grep indeed does the trick. Doc here. You have to carefully narrow it down before it'll work properly - on our server at least you have to get it down to < 10000 files. I also had to redirect the output to a file instead of printing it out in the console, adding > output.txt, because there's a limit of 4096 chars per line in the console and the file paths are quite long.
It's not something you can do with the standard perforce tools. One helpful command might be p4 print but it's not really faster than syncing I would think.
This is a big if but if you have access to the server you can run agent ransack on the perforce directory. Perforce stores all versioned files on disk, it's only the metadata that's in a database.

Is there a single Perforce command to display a list of all the check-ins to a file/dir along with the list of files that changed and the description?

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

Resources