Perforce diff sorted by date - diff

How do I get perforce diff's sorted by order in which changes were made .
can we have output of diff only after certain date .
Solutions to above output only for certain user, files..

You would definitely have to write a tool to do this efficiently, but here's some pointers
p4 changes Documentation
This command allows you to list every changelists that fit with certain criteria such as -u user for a specific user, #date for everything before date, #date1,#date2 for anything submitted between date1 and date2, /depot/location' to retrieve only changelists affecting files in/depot/location`, etc... check documentation for more.
It will output a list items formatted like this:
Change ChangeNumber on Year/Month/Day by User#WorkspaceName 'Shortened Description'
Now that you have the changelists, you need to see the details of them, so parse your output from p4 changes and then call p4 describe.
p4 describe Documentation
This command allows you to get the description of a changelist by providing its ChangeNumber (from our change output).
The output of this command will look something like:
Change ChangeNumber by User#WorkspaceName on Year/Month/Day Time
*new line*
*tab*Full Description
*new line*
Affected files ...
*new line*
... //depot/path/file#RevisionNumber operation(add/change/delete...) // repeated for as many files that were in the changelist
p4 diff2 Documentation
This command will now allow you to diff two revisions on the depot. You can use flags sur as -ds to only have a summary. Not providing a revision number will use the HEAD revision.
As an example, I added // test and a new line to a document, testing it against its previous revision gives this kind of output
==== //depot/path/file#RevisionNumber (text) - //depot/path/file#2ndRevisionNumber (text) ==== content
2a3,4
> // test
>
p4 diff Documentation
diff will be very similar to diff2 but it diffs with the file on the machine, useful if you have pending changes.
This should help you get started!

Related

Is it possible to get a list of files changed and a list of lines modified from Perforce changelist

My goal is to produce a JSON file that contains a list of all the files in a changelist and associated line numbers for each file. Something that looks like this:
[
{
"name":"file1.cpp",
"lines":[[1,3],[5,7]]
},
{
"name":"file2.h",
"lines":[9,14]
}
]
'p4 describe' gives us a list of files participating in the given changelist. But, I am interested in getting to the set of lines changed in each file.
For the purpose of this question, the working assumptions are
Local(personal) sandbox with all permissions.
A changeset has already been created using 'p4 change'.
A post-processing utility operating on changeset info is fine as well.
Can work with 'p4 diff' as a backup option.
The formatting flag -d[formatting option] for p4 describe should help here. For example, p4 describe -dc1 [changelist] will give you a format like this:
Change 2238074 by user#client on 2014/09/02 11:23:44
Change description
Affected files ...
... //depot/path/file1.java#3 edit
Differences ...
==== //depot/path/file1.java#3 (text) ====
***************
*** 8,11 ****
credentials {
! username 'olduser'
! password 'oldpass'
}
--- 8,11 ----
credentials {
! username 'newuser'
! password 'newpass'
}
So you get the line numbers and starting columns for each change. (The "1" at the end of the format flag limits the number of context lines printed per diff, as you only want the line numbers).
See "p4 help describe" for other options.
Since you're doing a lot of parsing and output formatting, you might want to look at one of the Perforce APIs rather than the command line to get the change data.

How can I get a diff of all edits made by a particular author since a particular date in Perforce?

In Perforce, I'm trying to find out what edits were made to the code for a particular long-running task. I know that all the changes were made by the same author, and that he was almost invariably working on this particular task.
Given that, I'm trying to find a way to do a diff of all the edits he has made to the code since a particular date. How would I go about it please?
(An alternative might be a way to get a unified diff of all the changes made in a number of specified changelists - I could then sit down and specify all the changelists manually and get a sensible result at the end of it.)
Something along the lines of this ought to do it:
p4 changes -u bruno | awk '{print $2}' | xargs p4 describe

Perforce (version control) - File change list since specific revision

I'm extremely new to perforce and wasn't having very much luck searching online... but...
Is there an way to get a list of all the files that have changed since a specific revision number? I'm going to have to push something to our production server and instead of going through all of the files and checking, I'd like to tell Perforce to give me any files that have change since revision X.
Personaly I think it makes a lot more sense (and I believe it is much faster) too work with changeslists instead. Something like:
p4 changes /myrepository...#changelist
Please note that revisions and changelists are not the same thing in perforce.
In perforce you have revisions of a file for example revision 3 means the 3'rd change to THAT file. You also have changelists which map of the whole perforce depot. They represent a bunch of changed revisions mapped together when you commit. So for example you commit 3 files (file1: rev 3 file2: rev 5, and file3 also at rev3) and the changeset could be something like 5200 since you have committed 5199 times before this new commit.
Hope that helps.
While the p4 changes command is good, it shows all the changelists, not all the individual files that have changed. Google leads folks to this question when they are searching for how to list all files with Perforce, as that's what the question asked.
To list the files that have changed between your #start,#stop times,
p4 -c WORKSPACENAME files //Path/You/Care/About/...#2013/03/20:13:40,#2014/06/016:17:00
You can start with p4 changes:
Use p4 changes to view a list of submitted and pending changelist
# Display all changelists submitted from April 1, 2001 to the present.
p4 changes #2001/04/01,#now
From there, to display the files in each changelist, see p4 describe as detailed in "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?".
If you want all the files up to a particular change, then use the 'p4 files' command.
For example:
$ p4 files //...#7
//depot/dev/fileA#2 - edit change 7 (text)
//depot/dev/fileB#2 - edit change 7 (text)
//depot/dev/fileC#2 - edit change 7 (text)
//depot/main/fileA#1 - add change 1 (text)
//depot/main/fileB#1 - add change 1 (text)
//depot/main/fileC#1 - add change 1 (text)
//depot/r1.0/fileA#1 - branch change 2 (text)
//depot/r1.0/fileB#1 - branch change 2 (text)
//depot/r1.0/fileC#1 - branch change 2 (text)
If you want files for only one particular changelist then use the #n,#n notation such as:
$ p4 files //...#7,#7
//depot/dev/fileA#2 - edit change 7 (text)
//depot/dev/fileB#2 - edit change 7 (text)
//depot/dev/fileC#2 - edit change 7 (text)
More details on 'p4 files' is found in the command reference:
http://www.perforce.com/perforce/doc.current/manuals/cmdref/p4_files.html
More details on file specifications here:
http://www.perforce.com/perforce/doc.current/manuals/cmdref/filespecs.html

How to find all checkins to a perforce depot folder during two timestamps

I am using both command line and p4v.
I need to find all checkins that went to a folder between two timestamps ( or times).
Any help will be appreciated.
This can be accomplished using P4V or the P4 command line application. Either way, you will need to understand some of the intricacies of using the Perforce File Specifications. Specifically for what you are asking, we will be using the #yyyy/mm/dd format to specify a date range to examine files.
To start off, I am going to just simply type p4 changes to show a list of all changes for the current client spec:
C:\Project>p4 changes
Change 5 on 2011/03/16 by goyuix#laptop 'Initial commit for upgrade to .'
Change 4 on 2010/07/02 by goyuix#desktop 'fixed a bug for really bad reco'
Change 3 on 2010/04/19 by goyuix#desktop 'deleted project.dll from the sourc'
Change 2 on 2010/04/19 by goyuix#desktop 'deletion of library.dll '
Change 1 on 2010/04/18 by goyuix#desktop 'Initial commit '
As you can see, I have five change lists and their dates available. If I wanted to limit that down, I would modify the p4 changes command using the date file spec as follows:
C:\Project>p4 changes //depot/Project/MAIN/*#2010/01/01,#2010/12/31
Change 1 on 2010/04/18 by goyuix#desktop 'Initial commit '
This tells me a few things: First, I used the * wild card which only examines the contents of the specified folder - no children. If you need to look recursively, use the ... spec instead of the *. Also, I gave a date range by separating out the start and end dates with a comma, appended at the end of the file spec. The output of this command tells me that only change list 1 actually made a change to any of the files in this folder during 2010.
To do the same thing using P4V, you can see it in two different views. The easy way is to simple navigate to the folder in question with the Depot or Workspace views, and then open the History tab (click the icon that looks like a clock). Change lists are typically sorted by date anyway, but in case they are not, you can just click on the column header to adjust the sort order and visually inspect for a given date range.
Using the Time Lapse view is a little convoluted - but will give you a more precise view as well. Open P4V, navigate to the folder you wish to examine the history of using either the Depot or Workspace view and right click on that folder. In the popup menu choose the Revision Graph, and once it is opened, drop down the Tools menu and choose Time Lapse View.
In the Time Lapse window, you have choices along the top to choose the Mode (choose multiple revisions) and the content range (pick the scale of dates). This should let you visually identify the files in question.
Try
p4 changes //depot_name/my_folder/...#2011/02/01,2011/03/01 to get all the changes in the my_folder folder between Feb 01, 2011 and March 01, 2011. If you need it between Feb 01, 2011 and the latest revision use #now in place of 2011/03/01. For dates, you can also put in times, in the format hh:mm:ss so p4 changes //depot_name/my_folder/...#2011/02/01:03:22:50,2011/03/01:04:05:06 will only look between the dates Feb 01, 2011 at 3:22:50AM and March 01, 2011 4:05:06AM
Not sure if revision range actually works for views, versus specific files are you are indicating. One of the most intuitive uses for this would be to get a range of changes lists:
p4 changes //view/...#1210,#1200
You would expect to get 10 or less changelists reported back, but what you get is either nothing, or all of them. This is my client version, not sure if they fixed this with subsequent releases.
Perforce - The Fast Software Configuration Management System.
Copyright 1995-2010 Perforce Software. All rights reserved.
Rev. P4/NTX86/2010.1/265509 (2010/09/24).

All change comments to perforce branch between 2 labels? (including merges)

Our perforce admin limits "max-row" scans so that my first idea of running the following will not work:
All changes including integrates into a branch at particular label time 1
All changes including integrates into a branch at particular earlier label time 2
Subtract time 2 changes from time 1 to get the new changes with comments.
Is there an alternative way of getting the same result without having such a massive query(when perforce contains 7yrs of history and -i triggers a scan back to the dawn of history)
Based on Gregs comments added this comment:
Basically the point is to see what bugs got fixed in a particular release branch between 2 labels(or more commonly, some old label and today).
I wish to simplify(speedup) way too complex script that we currently have which looks at changes that went into a release branch, it follows files that went into them at least 2 branches up in order to printout all the changeset comments from the original change(the interim merge comments tend to just say something like merge123 etc instead of description of the actual change comments, so we need to walk up the tree to the original comment as well), script finally outputs something like below(we put quality center IDs into changeset comments):
qualityCenterId123 - fixed some bug
in gui qcId124 - fixed some other
bug qcId125 - fixed some other bug
merge123
UPDATE based on comments:
Problem with Toby's approach is that most of the changes into the code branch came via integrations, -i would include those change, but as stated that explodes the query to such a degree that due the load on perforce server our admin won't allow it to run. So this is why I am looking for an alternative approach to get the same result.
I can't see an easy answer to this, but do have a couple more suggestions that perhaps may help point in the right direction.
Persuade your admin to raise the maxscan rows limit. If he is nervous that this will lead to problems with the whole user base, just get him to add you to a new user group (e.g. "Scripting"), and set the limits for just that group. That will have the effect that only members of that group can use the upper limits, and you can then negotiate for suitable times to run the script. You could even do it overnight.
Have a look at the P4 admin guide and see if any of the hints on scripting will help - e.g. maybe a tighter view on the data will limit the query enough to not break the maxscanrows limits.
How's your SQL? You may be able to construct an efficient query using the P4Report tool.
Try asking the question on the Perforce mailing list. It's a very active list that has a lot of very experienced people who are very helpful. See this link for the sign-up page. There's a good chance that they will suggest some good approaches.
Probably too late for yoru existing labels, but consider using the job system to track work. Perforce has inbuilt query tools to track what jobs have made it into different branches. It does require a working-practice change for your team, however.
Sorry I can't provide a more specific answer.
Are your labels more than simply the most recent changelist when they were created? Eg did you really need to record specific files in client workspaces? If not you can very easily compare the two changelists closest to labels.
Say the closest change to your first label date is 23000 and your closes change to your second label date is 25000 then
p4 changes //depot/PATHTOMYCODE/...#23000,#25000
will give you all changes to your code path between these two changelists.
Won't a normal Label-diff do what you want?
From P4V, Tools->Diff. Select the two labels
From P4Win, right click label, select diff files in 2 labels
From command line, p4 diff2 //codeline/...#label1 //codeline/...#label2
Or am I missing exactly what you are after?
Further suggestion after Ville's comment on the above
If you are only after the info per changelist, rather than per file, then try "p4 interchanges" from the command line. This will give you just the summary of what changes in one branch have not happened in another, and you can supply a revision range to limit it to the labels you need.
Do "p4 help interchanges" from command line for details.
Unfortunately the interchanges command is not yet exposed in P4V or P4Win.
Toby Allen's Answer is the best approach if your labels are simple changelists.
If the labels are more complicated, then I think you need to look at all the files in each label and where their versions differ, find the changelist where the version changed.
You can get the file and version lists with:
p4 fstat -Of //...#MyLabel
EDIT:
Consider two complex labels:
VERSION_A:
//depot/file_A.cpp#4
//depot/file_B.cpp#7
//depot/file_C.cpp#1
VERSION_B:
//depot/file_A.cpp#6
//depot/file_B.cpp#5
//depot/file_C.cpp#4
In this example, the labels do not describe a particular changelist, the head change for each file may be different.
If you can have labels like this, then you can run the p4 fstat command on each label and then find the differences. In this example, file_A.cpp has changed twice and file_C.cpp has changed 3 times. file_B.cpp is older in the second label, so it can be ignored.
So now you need to look at the changes that involved these versions:
file_A.cpp#5
file_A.cpp#6
file_C.cpp#2
file_C.cpp#3
file_C.cpp#4
Those changes can be retrieved with p4 filelog, so you want to run something like this:
p4 filelog file_A.cpp#6
p4 filelog file_C.cpp#4
Then you need to remove any duplicates and any history for earlier versions.
Like I said, you only need this if you have messy lables. If there's any way to make your labels represent changelists, you should use Toby Allen's answer.