How do remove a particular change number in perforce? - perforce

I have a perforce client which synced to a particular change number. I want to remove changes for a particular change number.
eg. lets say I have a function in a file.
void printnames() { //M
printf("John\n"); //M
printf("Joseph\n"); //N
printf("Harry\n"); //M
printf("Mary\n"); //N
}
where M and N denote the latest change numbers which added/modified these lines. I want to remove change number N(or if I may say - unsync change number N).
Is it possible to do that, and what would be the steps? (I want to this for Perforce). I know I can manually p4 edit the file, but that's not what I am looking for.

p4 sync #(N-1)
p4 sync -k #(N)
p4 reconcile
And then optionally (if there are changes after N you want to sync to your workspace, which will be necessary if you want to submit the change that undoes N):
p4 sync
p4 resolve [-am]

Related

Determining changelist number for unshelve

I temporarily shelved my current changelist in order to work on something else. When I went back to it, I had to scroll through hundreds of lines in my terminal to determine the changelist number. Is there another way to get this number?
In Git, you can use git stash to save an arbitrary number of changesets. when you pop a stash, you can specify which stash to pop. Similar functionality is also available in Mercurial. I use Mercurial Queues (mq) because I am familiar with them but there are a number of ways to do this in Mercurial.
Is similar functionality available in Perforce? Are these changelist numbers stored anywhere or do I have to remember them? I am using the command line (not P4V).
Yes, you can use the 'p4 changes' command along with any of the flags for 'shelved' status and/or user. See the examples below.
$ p4 changes -s shelved
Change 12118 on 2014/06/25 by admin#admin14streams *pending* 'original shelve changes by admi'
Change 12105 on 2011/11/08 by John_Wakeman#jw_admin *pending* 'Demo changes by John Wakeman '
Change 12102 on 2011/11/07 by Joe_Coder#jc_admin *pending* 'Joe_Coder_gwt-streams work '
Change 12101 on 2011/11/07 by John_Wakeman#jw_admin *pending* 'Demo changes by John Wakeman '
Change 12100 on 2011/11/07 by Joe_Coder#jc_admin *pending* 'Joe_Coder classic work in progr'
Here is using both the '-s' status flag and '-u' user flag
$ p4 changes -s shelved -u admin
Change 12118 on 2014/06/25 by admin#admin14streams *pending* 'original shelve changes by admi'
'p4 change' command reference
http://www.perforce.com/perforce/doc.current/manuals/cmdref/p4_changes.html

How can I list P4 changes since a specific changelist

Is there a way get the list of changelists after a particular changelist for a particular branch?
p4 changes (some flag ?) (CL#) //depot/project
This can be done with the following syntax (assuming you want to see all the changes submitted to this branch since changelist 12345 inclusive):
p4 changes //depot/project/...#12345,#head
To successfully use Perforce it is crucial to understand the intricacies of the Perforce File Specifications or filespecs. Think of it as the query language of Perforce.
For example, if you want to do something with a branch between two points you would need a filespec similar to below:
//depot/branches/branch_name/...#12345,#head specifies a range between changelist 12345 and head/latest.
//depot/branches/branch_name/...#12345,23456 specifies a range between changelist 12345 and 23456.
//depot/branches/branch_name/...#2012/08/01,#2012/08/21 specifies a range between two dates.
p4 changes "//depot/project/...#>nnn"
where nnn is your CL#.
If you're into Perforce Integration, and you need to get the next CL to Integrate (the CL right after the last one you've integrated, say #12345), try this:
p4 changes "//depot/branches/branch_name/...#>12345" | tail -1 | cut -d ' ' -f 2

How to find which changelists will be copied?

I want to be able to do a 'p4 describe' on all the changelists that will be copied upon a 'p4 copy' command. How can this be done?
I could do something like:
p4 copy -n from-branch/... to-branch/... | sed -e 's|.* ||' | xargs -n 1 p4 filelog
to find the list of changes per file and truncate the list at the point of the last branch or integrate action into to-branch (if there is one). But this could potentially take a long time. Is there a better way?
Try p4 interchanges. I like the -l and -f flags, which print the whole changelist description and list the files changed:
p4 interchanges -lf from-branch/... to-branch/...
I haven't actually used this command with p4 copy, though, so the results might be slightly different. If you're doing especially fancy integrations (cherry-picking revisions) Perforce might show a changelist as needing to be integrated even when it's already been integrated.
I think the easiest thing to do would be to create a label and tag from-branch/... at the last CL that was copied to to-branch from from-branch. Then finding out the list of CLs not copied is as easy as:
p4 changes 'from-branch/...#>copied-up-to' # where copied-up-to is the name of the dynamic label
If everything under from-branch is all tagged at the same CL, I could use a dynamic label whose Revision spec would be the last CL that was copied to to-branch from from-branch.
A script is probably the right way to go. I'd use the perl, python, or ruby API to make it more efficient and easier to maintain.
The basic outline would be:
Run p4 copy -n to get the list of candidate files
Parse out the source revisions that are being copied. For instance, each line of output has something like "branch/sync from //depot/foo.c#1,#3". For that file you'd want to know how revisions 1-3 were created.
Run p4 changes to get the changelists that affected each file (e.g. p4 changes -l //depot/foo.c#1,#3
Again, doing this using an API will be much more efficient, as you can use a single connection for all the command calls.

Diff multiple files in perforce across a revision range

I'd like to diff a bunch of lines across several revisions. Like, I'd like to see a.c, b.c, and c.c from changelist X to changelist Y.
p4 diff2 a.c#X a.c#Y (where X & Y are changelist numbers) seems to work, but only sometimes. Specifically, if a.c is non-existent at X, I don't get a diff. I'd like to be able to get the diff (even though it'll be the whole file with only adds) anyways.
To get the bigger picture: I have several files, across several commits, and I'd like to merge the diffs of these files in these commits, to basically say "this is a diff of what changed in this set of files during this set of changelists"
If I understand your problem right, p4 diff -f ... should be your friend.
From the p4-help:
The -f flag forces a diff for every file, regardless of whether
they are opened or if the client has the named revision.
This can be used to verify the client contents.
(see p4 help diff on the command line).

How do you search the text of changelist descriptions in Perforce?

On occasion, I find myself wanting to search the text of changelist descriptions in Perforce. There doesn't appear to be a way to do this in P4V. I can do it by redirecting the output of the changes command to a file...
p4 changes -l > p4changes.txt
...(the -l switch tells it to dump the full text of the changelist descriptions) and then searching the file, but this is rather cumbersome. Has anyone found a better way?
When the submitted changelist pane has focus, a CTRL+F lets you do an arbitrary text search, which includes changelist descriptions.
The only limitation is that it searches just those changelists that have been fetched from the server, so you may need to up the number retrieved. This is done via the "Number of changelists, jobs, branch mappings or labels to fetch at a time" setting which can be found by navigating to Edit->Preferences->Server Data.
p4 changes -L | grep -B 3 searchstring
-B 3 means show 3 lines before the matched string, should be enough to show the change id with 2 line comments but you can change it as necessary.
I use p4sql and run a query on the "changes" database. Here's the perforce database schema
The query looks something like this (untested)
select change from changes where description like '%text%' and p4options = 'longdesc'
edit: added the p4options to return more than 31 characters in the description.
Here is a Powershell version of Paul's "grep" answer. Again, it searches for the specified string within the change description and returns the 3 lines before it, to include the change id:
p4 changes -L | select-string "search string" -Context (3,0)
Why redirect to a file when you can pipe the output through less and use less's search?
p4 changes -l | less
And then press / to prompt for a search string. Afterward, n will jump to the next match, and Shift+n will jump to the previous one.
An implementation of less for Windows is available as part of UnxUtils.
Using p4sql is really the only way to effectively do what you want. I am not aware of any other way. The benefit of course is that you can use the select statements to limit the range of changelist values (via date, user, etc). Your method will work but will get cumbersome very quickly as you generate more changelists. You can limit the scope of the changes command, but you won't get the flexibility of p4sql.
Eddie on Games posted his Perforce Changelist Search 0.1 at http://www.eddiescholtz.com/blog/archives/130
But, I do like using my favorite text editor with the simple:
p4 changes -s submitted //prog/stuff/main/... >temp.txt
If you still love your command line, you can write a small perl script that:
changes the record separator $/ to
double newline "\n\n" so it filters
the input into full records of the
ztagged p4 output.
scans
the '/^... desc/..//' part with
regular expressions from the args.
usage would be something like 'p4 -ztag changes -l | yourperlfilter.pl searchterm1 searchterm2'
if that worked ok, you could integrate it into the p4win tools menu.

Resources