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

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.

Related

Get gerrit commit with only short hash [duplicate]

When working with Gerrit (Code Review), I often need to get a copy of a given patch set for testing or validation purpose. The obvious and easiest way is to download the archive or the patch file through the Gerrit Web interface and manually apply it to my local source.
While the above steps are pretty straightforward and fulfill my needs, in the best world I would like to have the patch set appearing as a commit in my local Git.
I was looking around and didn't find the solution. I found some sparse info that once compiled together gives the following solution.
Say that you want to pull the patch set 2 of the Gerrit change 1222:
Find the remote refs we are interested in:
$ git ls-remote | grep 1220
From http://something.com:8081/MyProject
e2e0212a59240ac5cd7c11220c35542523f44b59 refs/changes/13/713/1
b8c4dceea5eaf1bad711b0ea6938c80ec932726a refs/changes/20/1220/1
6f20c182ec7f54a2aa9e8f6188a0eef1b0790df4 refs/changes/20/1220/2
ed94a98386d224ce3d86004ce99f61220905a077 refs/changes/22/1222/1
Pull the refs:
git pull origin refs/changes/20/1220/2
This will create a Git commit point that you could eventually rebase:
git rebase
This feature is standard in the Gerrit UI.
On the top right of the UI for a patch, click Download, and you will see something like:
When you are navigating the patches you go to the download section and copy the command line command for checking out the patch set, for example like this:
git fetch https://gerrit.googlesource.com/gerrit refs/changes/03/64403/2 && git checkout FETCH_HEAD
Then I normally create a branch with the review number and patchset as name
git checkout -b b64403-2
For here you can work normally and commit your changes or cherry-pick/rebase your changes on this change.
Once the review of r64403 is done your code can be merged or when there is another patchset submitted you will need to do the same thing again.
If you do not see the options to download the option to Checkout or Cherry Pick you need to edit the gerrit.config, something like this:
[download]
scheme = ssh
command = checkout
command = cherry_pick
More details can be found in the Gerrit Documentation
Update:
As barryku correctly points out, in the later version you need to download the downloads-commands plugin. This can be done during the initial setup or by using the following command:
java -jar gerrit-2.11.4.war init -d review_site --batch --install-plugin download-commands
Or you can use the -d option to git-review. For example, assuming you were working the with nova-docker repository and were interested in this change in gerrit:
https://review.openstack.org/#/c/148486/
You could download the latest patchset like this:
git review -d 148486
Or you can use the change id:
git review -d I35729a86e211391f67cc959d19416c9125c6f9eb
You can also request a specific revision of the patch by appending a comma and the patch number. E.g, to get the second revision of that patch:
git review -d 148486,2
I am not 100% sure what your question is. Sounds like you want to easy the workflow or typing. larsks mentioned already git review which is mostly used.
For your case, maybe it helps to download all ref's automatically so you can reference them directly. You can always all specified ref's like with
git fetch origin "+refs/changes/*:refs/remotes/origin/changes/*"
Then you can work locally with the commit id.
A simple git alias or scripting it for all refs can be easily done. An example of such a while loop can be found in the script on https://github.com/saper/gerrit-fetch-all With such a small shell snippet you can easily accomplish to skip one part of the ref id to easier reference them:
Server side: Client side:
refs/changes/13/713/1 refs/head/713/1
refs/changes/20/1220/1 refs/head/1220/1
refs/changes/20/1220/2 refs/head/1220/2
refs/changes/22/1222/1 refs/head/1222/1
As mentioned in the comments, you can just get the right git command from the gerrit GUI. If you really dislike GUIs, or you want to automate it (and for some reason can't use git-review), you can use the gerrit API:
curl -s 'https://<your gerrit server>/r/changes/<change id>?o=CURRENT_REVISION&o=DOWNLOAD_COMMANDS' | tail -n+2 | jq -r '.revisions[.current_revision].fetch["anonymous http"].commands.Pull' | bash -
or
git pull origin `curl -s 'https://<your gerrit server>/r/changes/<change id>?o=CURRENT_REVISION' | tail -n+2 | jq -r '.revisions[.current_revision].ref'`

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

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

How do I stop Mercurial's "hg serve -d" service under Windows?

I'm technically savvy but don't have extensive experience with servers/daemons (I'm a Windows guy, so...command lines intimidate me).
I started a Mercurial server using the hg serve -d command, and all was well.
Now, I want to stop it, and can't find a process to kill. Does anybody know the process name or a relatively simply CLI command to get it done?
Here's a link to stop and start the Mercurial server via command line
https://www.mercurial-scm.org/wiki/hgserve
The information you're looking for is at the bottom of the page.
You can choice one of below ways:
1: You must enter Processes tab in Window Task Manager and try to kill process which names hg.exe, its description is Mecurial Distributed SCM.
Note: I sent ps -W | grep hg to cygwin to find it. Hope this way can help you
2: Another way, you can using ToitorseHg to start and stop server instead using command line hg serve
[ Open ToitorseHg -> Repository -> Web Server ]
Good luck
Did you try accessing the "Services" GUI? Not sure if mercurial shows up there, but its worth a try...
Start -> Administrative Tools -> Services
If Administrative Tools does not show up, right click the taskbar, click properties, click "start Menu" and customize. Then check "Show Administrative Tools". This is from memory since our IT department prevents us average users from doing this :-)
Good luck

Apache Ant: Run ant without showing the target names

When I run my build file, it always shows the target name.
For example, in my build file if I have targets A, B, C.
Then on when I type the command ant A, it shows
A: <...whatever>
How do I avoid displaying the A?
Any help is very much appreciated.
The command line switch is -q
$ ant -q A
A few options:
try -q for quiet mode
try -emacs (not sure if this dumps the targets or not, but worth trying)
write a custom logger
You might also have a look at the following blog entry http://codefeed.com/blog/?p=82. The author provides some code for a custom task to set the loglevel in a build script. This way you can enable and disable log output for specific operations.

Analysing a shell script

This would be part of a reverse-engineering project.
To determine and document what a shell script (ksh, bash, sh) does, it is comfortable, if you have information about what other programs/scripts it calls.
How could one automate this task? Do you know any program or framework that can parse a shell script? This way for instance, I could recognize external command calls -- a step to the right direction.
For bash/sh/ksh, I think you can easily modify their source to log what has been executed. That would be a solution.
How about:
Get a list of distinct words in that script
Search $PATH to find a hit for each
?
bash -v script.sh ?
Bash's xtrace is your friend.
You can invoke it with:
set -x at the top of your script,
by calling your script with bash -x (or even bash --debugger -x),
or recursively by doing (set -x; export SHELLOPTS; your-script; )
If you can't actually run the script, try loading it into a text editor that supports syntax highlighting for Bash. It will color-code all of the text and should help indicate what is a reserved word, variable, external command, etc.

Resources