In Perforce, how to search by content of a file in its revision graph - grep

In perforce, is it possible to search for a string in all its revisions and sources. It should be able to search in its entire "Revision graph" from where file could have been derived. I was able to find "p4 grep -a" which can search in revisions of a particular file in a branch. But I want to search in its sources also.

Do you only care about strings that are in the current head revision of the file? If that's an acceptable limitation, annotate -I is a pretty easy option:
p4 annotate -I file | grep STRING
More on p4 annotate -I here: https://www.perforce.com/blog/p4-annotate-i-going-deeper
If that doesn't do it for you, you have a lot of scripting ahead of you -- that blog post might help get you started on the general approach (you'd use p4 filelog to generate the "graph" and p4 print to get the content).
You could also try hacking on the DeepAnnotate tool I wrote before annotate -I since that's open source (it's way hackier than annotate -I though so I'd still recommend using the built-in version if you can): https://swarm.workshop.perforce.com/files/guest/sam_stafford/deepannotate

Related

What does "dump" mean in the context of the GNU tar program?

The man page for tar uses the word "dump" and its forms several times. What does it mean? For example (manual page for tar 1.26):
"-h, --dereferencefollow symlinks; archive and dump the files they point to"
Many popular systems have a "trash can" or "recycle bin." I don't want the files dumped there, but it kind of sounds that way.
At present, I don't want tar to write or delete any file, except that I want tar to create or update a single tarball.
FYI, the man page for the tar installed on the system I am using at the moment is a lot shorter than what appears to be the current version. And the description of -h, --dereference there seems very different to me:
"When reading or writing a file to be archived, tar accesses the file that a symbolic link points to, rather than the symlink itself. See section Symbolic Links."
P.S. I could not get "block quote" to work properly in this post.
File system backups are also called dumps.
—#raymond-chen, quoting GNU tar manual

Why does grep make my terminal unreadable when searching for #?

I'm trying to grep my repo searching for # sign to find some e-mail addresses because of this git issue.
I type grep -rnw '/my/path' -e '#' into the terminal and I get:
Why does it happen?
P.S. I think there is no sensitive information in the picture, but someone please tell me if you think there is.
If you have issues only on files within a .git folder, you might consider excluding it from your recursive grep, as in this answer.
grep --exclude-dir=".git" -nrw ...
On CentOS, the regular grep might not include that option though.

How to get fully working grep in git bash (msysgit) on windows?

I would like to use grep -o, but in git bash there is no -o option. Is there a way to get full working grep in git bash, just like it's in linux bash shell?
There is no -o flag for grep
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
You can use sed instead
There is an open issue for that on Github (even though it's under "nvm"). User UltCombo posted a workaround. Quoting:
Open <Git install directory>/bin and overwrite grep.exe with a more up to date version. I found two alternatives that provide -o support:
GnuWin32's grep 2.5.4 (link).
ezwinports' grep 2.10 (link). Note: You also have to extract libprce-0.dll in the same folder as grep.
Though ezwinports' grep port is much more up to date, I can't say whether any of these will cause stability/compatibility issues. I haven't found any issues yet, but use it at your own risk.
Marking this Community Wiki because it's really somebody else's work.
Alternatively, get the pretty awesome MSYS2 and enjoy full grep and co.

grep command that works on Ubuntu, but not on Fedora

I clean hacked Wordpress installations for clients on a regular basis, and I have a set of scripts that I have written to help me track down where the sites are hacked. One code snippet that I use on a regular basis worked fine on Ubuntu, but since switching to Fedora on Friday has quite behaving as expected. The command is this:
grep -Iri --exclude "*.js" "eval\s*(" * | grep -rivf ~/safeevals.txt >../foundevals.txt;
What it is supposed to happen (and did happen when I was using Ubuntu): grep through all non-binary files, excluding Javascript includes, for all occurances of the eval() function, then perform a negative match on a line by line basis against all known occurances of the eval() function in a vanilla installation of Wordpress (the patterns of which are in ~/safeevals.txt).
What is actually happening: The first part is working fine, as I ran it separately and it did find all instances of eval() in the installation. However, instead of greping through those results, after the pipe is it re-grepping through all of the files, returning a negative match of ~/safeevals.txt (ie. pretty much every line of every file in the installation).
Any idea why the second grep isn't acting on the piped data, or what I need to do to fix it? Thanks.
-Michael
Just tested on my Debian box: apparently, grep -r likes to assume a default argument of .. I am really wondering if that behaviour is valid. Anyway, I guess dropping the -r option from the second grep command will fix it.
Edit: rgrep defaulting to $PWD seems to be a recent change in grep, see this discussion on unix.stackexchange and the link there to the commit in the upstream grep code repository.

How to perform p4 submit operation ONLY on files which has diff?

I would like to know if there's a built-in function in P4 or a way to basically only allow the p4 submit to commit ONLY when the file has a diff. Let said I have rev 1, and I want to update the file with rev 2. But I should be only allow to make this change if rev 2 is actually diff from rev 1.
I checked P4 Manual on "p4 submit" , but I don't see much about this type of scenarios. The P4V GUI has one of these options, but how do we get this accomplish in command-line? Thanks.
p4 submit -d "Update new drop $now" file.txt
There are a few options.
Add either the -f revertunchanged or -f leaveunchanged options on the p4 submit command (p4 help submit).
Perform a p4 revert -a command before submitting (p4 help revert)
Change the SubmitOptions on your client (a.k.a your workspace) so that it will always revert unchanged files before submitting (p4 help client).
P4V can be considered a wrapper of the p4 command line, i.e. it performs the exact same commands.
Tips:
If you want to see what you commands P4V is performing, go to your preferences and change the log settings to output more detail.
Did you notice the way I formatted the help links? If you type that (e.g. p4 help submit) into your command prompt / terminal, it will display the help for that command. If you want to see what other commands are available type p4 help commands.
You need the -f reventunchanged or -f leaveunchanged options. See here under the options section for various options that are available to you. The former will automatically revert the unchanged files, the latter will leave them alone. In both cases changed files will be submitted.
I think 'p4 submit -f revertunchanged -d "my description" file.txt' might be useful to you.

Resources