What is the command line syntax to check whether there is file in my changelists(checkout or not) in Perforce?
I'm not entirely sure what you're asking for? Do you want to see the list of files in a changelist? That's p4 describe.
Related
Is there a command or program for Linux that allows to patch the source code interactively, printing every chunk on the screen and waiting for acknowledgement before applying it to the file?
Something like git add -p, but taking the changes from another .diff file?
You can always write script in shell/ruby/python that reads that file line by line and prompts adding diff between file signatures.
It can accept name of diff file as parameter or you can put two hashes and make a patch inside a script.
More so you can call that script git-command-name, put it in your user/bin folder and git will recognise command-name as git command.
On the other hand (just an idea) can you manipulate creation of .diff ? Maybe you can use format-patch and on applying stop after every commit diff?
Although not interactive, another option is to manually edit the .diff file and remove any changes you don't want.
If you open a diff file in emacs and put the editor in diff-mode you can edit patches and emacs will try to update the hunk markers. (Emacs will open .diff files in diff-mode automatically.)
To update markers manually after making changes do C-c C-w to regenerate the hunk.
To apply hunks one by one do C-c C-a. To reverse-apply do C-u C-c C-a. You can also M-x diff-tell-file-name to apply them to a different file.
I found patch original patch.diff to be more reliable than patch < patch.diff and patch files created with diff -u to be easier to work with.
Information also documented here.
UPDATE [5.21.21]:
C-c C-s lets you split up hunks which is very useful for manually editing. Sometimes C-c C-w (diff-ignore-whitespace-hunk) does not do what you intended, so the safest bet is to split the hunks and let emacs update the headers automatically. This is especially useful when keeping lines unchanged; just split into a hunk and delete to remove the change.
Is there a way to use regex in perforce commands like "p4 filelog"?
I am trying to get information on file but not sure which perforce branch the file exists in. For example, //something/*/something/test.pl
My Perforce-based project supports both Linux and Cygwin platforms with the same shell scripts (e.g. build_project.sh). But Perforce defaults line endings for text files to the local platform (Docs). This causes \r\n newlines in the .sh scripts, which fail on Cygwin.
Some of the ideas I've thought of so far:
Is there a way to make Cygwin accept \r\n files? (Without having to run dos2unix, the files fetch as read-only).
Is there a way to set specific files to be text, but with Unix line endings for everyone? (I am guessing, "no", but thought I'd check.)
Of course I can set the entire workspace's line endings to \n (unix). But this makes the Windows clients unhappy with their .bat files being \n instead of \r\n. Also if the setting is per workspace (I can't recall), then a workspace setup is slightly harder for the new Windows user as they must set that option.
Set the .sh files to be "binary", but then we lose the text diffs on those files. Is there a workaround for this? Is this the common (good) hack?
This is a fairly minor nit, but I suspect that some of you have a BKM for this pattern.
Thanks.
EDIT: Craig's answer in this question seems to suggest that using Unix line endings will just leave files with \r\n's alone if they are originally submitted that way.
EDIT: To force bash (i.e. Cygwin) to accept files with \r\n endings, one can specify set -o igncr in the script. This is nice if one expects Cygwin users to that might not be very Unix literate (my case) or when we can't globally impose the trigger in the solution below for some other reason.
I believe that when you install Cygwin you can configure it to use Windows line endings. Leaving that aside, though:
If you use the "unix" LineEnd for absolutely everyone, then all of your text files will have their own internally-consistent line endings (but will not be necessarily consistent with the client platforms). This works by virtue of the fact that the Windows files will end up having the \r as part of the content of the line, so when being synced out in "unix" format they'll have \r\n endings.
The thing to watch out for is mixing and matching LineEnd settings when doing this -- if somebody with a "win" or "local" LineEnd syncs that same file, now they have \r\r\n endings! So if you want to go with the per-file line ending plan, make sure EVERYONE uses "unix" as their LineEnd. This is pretty easy to do with a trigger, e.g.:
Triggers:
form-in client "sed -i %quote%s/LineEnd:.*/LineEnd: unix/%quote% %formfile%"
I have a static analysis tool which gives me the file name and line number where it suppose an issue exists. Now using P4 command i want to pin point the user who has made that particular change. Means the developer who edited the file at that particular line number.
Is there a way to find out the changelist number which made change to a particular line in a file using p4 command so that i can integrate it in my script.
You are describing p4 annotate.
By default it prints the file with each line preceded by the revision number that the line was last changed. With option -c you can have the lines preceded by the corresponding changelist.
Call p4 help annotate for more details.
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.