Kwcodereview
The kwcodereview command creates pre-checkin code reviews. In a pre-checkin code review, Code Review compares locally modified source code with the base SCM version.
kwcodereview is designed to mimic the functionality of your native SCM client. You can assume it works the same way as your SCM unless noted otherwise below.
Prerequisites
- The directory containing your SCM tool must be in your path (for example, Git or SVN). For ClearCase, CVS, and Team Foundation, the SCM executables must be in your path.
- To view and cite detected issues as part of your code review, you need to have a local Klocwork project (.kwlp) set up on your desktop, and it must be connected to an integration project. If you're already using the connected desktop, this step will be taken care of; otherwise, go to Fixing issues before check-in with Klocwork Desktop Analysis and pick your development environment.
Tip: Since the code review will display issues detected in your code, it's a good idea to keep your desktop analysis up to date, fix the issues that you can and cite the remaining issues before launching your pre-checkin review.
Usage
kwcodereview [--project-dir <local_project_dir>] [--message <message>] [--reviewer <user1>,<user2>...] <scm> [<file1>|<directory1> <file2>|<directory2>...]|<scm_path>
where
- <local_project_dir> is the location of your local Klocwork project (.kwlp). If your local project directory is named .kwlp and it is located in the folder you are scanning for changes or one of its parent folders, you do not have to specify the --project-dir option.
- <message> is the message that will be displayed with your code review in Code Review. You can link to another code review by specifying the keyword ref: and the code review's revisionID in the message. This can be helpful when a review has been rejected, and you want to submit a new version of your code for review. To get a code review's revisionID, hover over the revision in an Code Review feed to see the URL. The URL can also be accessed within your IDE or by kwcodereview. For example, you'd use ref:4 from this URL: http://jlee.example.com:8080/codereview/CodeReview.htm#revision_goto:revisionId=4. If you don't specify --message, kwcodereview will prompt you to enter a message; to end your message, go to a new line and enter Ctrl+D (Unix) or Ctrl+Z and <Enter> (Windows).
- <scm> is your source code management system
- <file>|<directory> is one or more files or directories to be scanned for changes since checking out of version control. If you specify a '.' for your path and your SCM supports this usage, the current directory is scanned. You can also specify a text file containing a list of files to be reviewed, one file per line.
- <scm_path> is the path to your SCM repository or local path
Example
kwcodereview --project-dir e:\myproj\.kwlp --message "Fix for PR55555" --reviewer fbrown,jblack svn e:\myproj\sources\engine
Tip: You can also set up a pre-checkin code review that doesn't show locally detected issues. You might want to do this, for example, for a file that's not part of a Klocwork project. In this situation, use the --url option instead of the --project-dir option. You still need to point to a Klocwork Server host, port and project, but your files do not have to be part of this project:
kwcodereview --url http://<klocwork_server_host>:<klocwork_server_port>/<project> [--message <message>] [--reviewer <user1>,<user2>...] <scm> [<files>|<directories>]|<scm_path>
Example
kwcodereview --url http://server01:8080/myproject --message "Fix for PR55555" --reviewer fbrown,jblack cvs /path/to/project
In this example:
- server01 is the Klocwork Server host
- 8080 is the Klocwork Server port
- myproject is an integration project on the Klocwork Server
- "Fix for PR55555" is the message that will be displayed with the code review in Code Review
- fbrown,jblack are the reviewers you want to invite to your code review
- /path/to/project is the path to the CVS source
Troubleshooting
If kwcodereview fails, it will print out the command that was used, the output of the command and the return code. If you need more information, add the --verbose option to your original command line. If the error message indicates a problem that you're unable to troubleshoot, contact Customer Support.
Options that apply to all subcommands
Name | Short name | Description |
--dry-run | print out a list of locally modified/added/deleted files so that you can verify the list before submitting a code review | |
--encoding <string> | encoding of the source files used in the project. The default is your system encoding. Use the --list option of kwconv to find the list of acceptable values. For more information, see the --encoding option of kwbuildproject. | |
--fix <code_review_ID> | specify the ID for a code review that has been fixed; this allows you to re-submit a code review that was previously rejected, so that your reviewer(s) can approve or reject your fixes. | |
--force | -f | force execution if command-line tools exit with non-zero exit code; if something fails but you want to bypass it, specifying force will ignore the error and execute the command |
--help | display command-line help; this option is available for kwcodereview and the SCM subcommands. | |
--message <message> | -m | message you want to display with this code review in Code Review |
--project-dir <Klocwork_local_project_dir> | -pd | specify local project location, in order to upload any issues detected in your pre-checkin code. Allows reviewers to be able to view and cite detected issues. If your local project directory is named .kwlp and it is located in the folder you are scanning for changes or one of its parent folders, you do not have to specify the --project-dir option. Note that you can't use this option in combination with the --url option. |
--reviewer <string> | -r | specify a list of participants to invite to the review. This review will appear in each participant's "to do" feed in Code Review, and they will be able to approve or reject the review. You can specify this option once for each participant, or specify a comma-separated list of user names. If a user name contains spaces, surround it with double quotes ("). To invite a participant with this option, the participant must already have logged in to Code Review. |
--tags <string> | -t | specify tag(s) that you want to assign to your code review. These tags can be used to organize your feed and control whether or not other users can see code reviews with particular tags. |
--url http://<host>:<port>/<project> | URL for a project on the Klocwork Server, of the form http://<server_host>:<server_port>/<project> Use https:// if a secure Klocwork Server connection has been configured. Use this option when you do not want to display detected issues in your code review. Note that you can't use this option in combination with the --project-dir option. | |
--verbose | print verbose information about program execution, which can help to troubleshoot errors. | |
--version | show version |
kwcodereview cc
Prerequisites
- The cleartool executable must be specified in your path.
Example
kwcodereview --url http://server01:8080 --message "Fix for PR55555" --reviewer fbrown,jblack --tags myTag1,myTag2 cc -R .
Options
Name | Short name | Description |
--base | specify the base revision or label for pre-checkin code review | |
--cview | restrict the listing to checkouts made in the current view | |
--recurse | -R | list checkouts of elements in the entire subtree below any directory encountered in the current view |
Restriction: ClearCase Remote Client and ClearCase snapshot views are not supported.
kwcodereview cvs
Prerequisites
- The cvs executable must be specified in your path.
Example
kwcodereview --url http://server01:8080 --message "Fix for PR55555" --reviewer fbrown,jblack --tags myTag1,myTag2 cvs .
Options
Name | Short name | Description |
-d <cvs_root> | specify $CVSROOT as the root of the CVS tree |
kwcodereview git
Example
kwcodereview --url http://server01:8080 --message "Fix for PR55555" --reviewer fbrown,jblack --tags myTag1,myTag2 git .
Options
Name | Short name | Description |
--git-dir <path> | set the path to the repository | |
--revision <string> | -r | specify revision(s) |
--work-tree <path> | set the path to the working tree |
kwcodereview p4
Example
kwcodereview --url http://server01:8080 --message "Fix for PR55555" --reviewer fbrown,jblack --tags myTag1,myTag2 p4 e:\myproject\sources\engine
Options
Name | Short name | Description |
--changelist <integer> | -C | specify a non-default changelist# |
--charset <string> | specify the perforce charset (which overrides the value of $P4CHARSET in the environment). | |
--client <string> | -c | specify the perforce client workspace, which overrides the value of $P4CLIENT. Defaults to the hostname of the machine (COMPUTERNAME environment variable on Windows) or $P4CLIENT if set. |
--password <password> | -P | specify the password (overrides the value of $P4PASSWD in the environment). |
--server <string> | specify the perforce server [protocol (tcp or sll)]:<host>:<port> location. This overrides the $P4PORT value. Defaults to 'perforce:1666' or the value of $P4PORT if set. | |
--user <string> | -u | specify the user name (overrides the value of $P4USER, $USER, and $USERNAME in the environment). |
kwcodereview svn
Example
kwcodereview --url http://server01:8080 --message "Fix for PR55555" --reviewer fbrown,jblack --tags myTag1,myTag2 svn .
kwcodereview tf
Prerequisites
- You should use kwcodereview from a Visual Studio command prompt.
Example
kwcodereview --url http://server01:8080 --message "Fix for PR55555" --reviewer fbrown,jblack --tags myTag1,myTag2 tf .
Options
Name | Short name | Description |
--server <server> | identifies the Team Foundation Server. Required if the command is invoked from a directory that is not mapped to a workspace. |