Allow --help for rbt commands.

In order to print help for a command, the user would need to call
"rbt help <command-name>". We now also allow the "--help" option
both before or after the command name.

For example, both "rbt --help <command-name>" and
"rbt <command-name> --help" will now print help for the command.
Mocking is_supported() in test_repository_info

The test_repository_info unit test for Perforce only passes if 'p4 help' can
run successfully (ie, perforce is both present and properly configured). This
is obviously inappropriate for a unit test.

Reviewed at https://reviews.reviewboard.org/r/4249/
Allow non-existant parent_branch option.

Not every command accepts a parent branch on the command line, but some of the
code for git-svn assumed that it was present. Guard with a hasattr.

Adapted from code at https://reviews.reviewboard.org/r/4241/
Go back to getattr.

The original change at https://reviews.reviewboard.org/r/4241/ used getattr,
and I (David) changed it to hasattr because I'm dumb. Trivial update.
Fix Plastic's usage of self._options.

When the plastic client is creating a diff for a branch, it tries to set the
'branch' field in the options object so that it will get set properly in the
review request. This broke when we refactored the command-line options to be
able to have different options for each rbt command.

Addresses bug 3044
Reviewed at https://reviews.reviewboard.org/r/4395/
Display more detailed errors for HTTP 400.

HTTP 400 errors were not very informative. It was unclear what was
broken and why.

The error output now contains all the field errors, making it more clear
what's wrong.

Reviewed at https://reviews.reviewboard.org/r/4340/
Add more detail for API errors.

We now log debug output for any API errors. The output shows the payload
of the error, making it easier to see what went wrong.

In the case of a failed diff upload, we also include the wrapped error
class's text in the message, instead of the raw error string we get from
the server.
Fix a typo.

s/Unexpexted/Unexpected/
Skip files where 'p4 print' provides a symlink

The riddle: how can a file both exist and not exist? The answer: symlinks! When
a symlink is checked into perforce running 'p4 print -o' will create a symlink,
not the file that it points to. This naturally makes postreview.py choke...

~% post-review
Traceback (most recent call last):
  File "/share/rbtools/rbtools/postreview.py", line 4115, in <module>
    main()
  File "/share/rbtools/rbtools/postreview.py", line 4061, in main
    diff, parent_diff = tool.diff(args)
  File "/share/rbtools/rbtools/postreview.py", line 2002, in diff
    return self._changenum_diff(changenum)
  File "/share/rbtools/rbtools/postreview.py", line 2299, in _changenum_diff
    self._write_file(old_depot_path, tmp_diff_from_filename)
  File "/share/rbtools/rbtools/postreview.py", line 2475, in _write_file
    os.chmod(tmpfile, stat.S_IREAD | stat.S_IWRITE)
OSError: [Errno 2] No such file or directory: '/tmp/tmpsCS-fw'

Resolving symlinks, especially those with a relative path would be tricky.
Also, there's no certainty that the file it points to is even in version
control. Hence I'm just dropping it from the review with a warning.

Testing done:
Tested this change both when reviewing a single symlink file and a batch of
files containing a symlink. We've been using this change against RBTools 0.3.

Reviewed at https://reviews.reviewboard.org/r/3221/
Support multiple local git commits in a git-svn repo

If you have two local commits and want to make a review for the changes
in the most recent commit, then "ancestor" will not have a corresponding
subversion revision.  This is okay, however.  We'll just use the
subversion revision for the merge-base, which is the most-recent-commit
that is in SVN.

Testing done:
Logically behavior is only changed in cases where we would crash, before.
Returning "None" causes len(None) to throw an exception.

Making a review using "post-review --revision-range=HEAD^" in a git-svn
repository with multiple local commits results in the expected behavior: a
review is created and the diff shows only the changes from HEAD.

Reviewed at https://reviews.reviewboard.org/r/3075/
Send the base commit ID for a change to the server when using Git.

When uploading a change to a new enough Review Board server, the base
commit ID is sent along in the request. This ID/revision represents the
upstream commit that the diff (or its parent diff) applies to. It can be
used by the server to communicate with hosting services that otherwise
do not work solely with the content found in the diffs.
Enhance Review Board RBTools (rbt) to support svn tree (or file) copy

RBTools (rbt post) does NOT support svn tree copy (or file/files copy) from
other branches. With this change, rbt notifies user that it has detected
tree/file copy and asks the user if the review should contain files added as
part of svn copy or not.

Testing done:
$ svn cp $svn/branch/dir .
A    dir/a.c
A    dir/b.c
Checked out revision XXXXX.
A         dir

$ svn st
A  +    dir

1. Test using NO svn changelist
$ rbt post
One or more files in your changeset has history scheduled with commit.
Please add option '--svn-show-copies-as-adds=y/n' and re-run

$ rbt post --svn-show-copies-as-adds=y
Review request #ddddd posted.

2. Test using svn changelist
$ rbt post --svn-changelist=tree_copy_1_file

One or more files in your changeset has history scheduled with commit.
Please add option '--svn-show-copies-as-adds=y/n' and re-run

$ rbt post  --svn-changelist=tree_copy_1_file
--svn-show-copies-as-adds=y
Review request #ddddd posted.

Fixes bug 3024
Reviewed at https://reviews.reviewboard.org/r/4279/
Update SCMClients and tests for the new diff dictionary change.

My recent change to convert diff results to a dictionary that also
introduced the base_commit_id value was pushed prematurely. This change
finishes that up by updating all other SCMClients, post-review, and unit
tests.
Fix several issues found throughout the test suite.

The test suite has been broken for a while, due to a variety of issues,
ranging from lack of valid configuration for certain tools to bad temp
directories, to path mismatch issues on MacOS X.

This fixes all the unit tests, getting us back to 100% test coverage,
where we are never allowed to leave again.
RBTools clean-up

This change cleans up a lot of the code to fix trailing whitespace and PEP-8
issues.

Testing done: Ran tests. No more failed than before.
Adding git-p4 support

This was taken from a previous patch request
(http://reviews.review-board.org/r/889/) and modified for the current 0.5
release. Git-p4 only supports pushing to perforce from the master branch but
the rbtools modifications allow sending reviews from and git branch.

original github pull request: https://github.com/reviewboard/rbtools/pull/16

Testing done:
The patch has been thoroughly tested within our organisation from version 0.2
right through to 0.4.1 and with the latest 0.5 development branch. We have
roughly 20 users using git-p4 on a daily basis.

Reviewed at https://reviews.reviewboard.org/r/3122/
Add release notes for 0.5.2.
Release RBTools 0.5.2.
Use only the top commit for summaries for git commits with multiple parents.

When dealing with a merge commit the '%s' pretty pattern is the newline
concatenation of the summaries...

*   4182bc3 atagar@torproject.org  (HEAD, tmp) - merging branches
|\
| * 1f71921 atagar@torproject.org  - second branch
* | b41fb93 atagar@torproject.org  - first branch
|/
* ae6aca7 atagar@torproject.org  - base commit

% git log --pretty=format:%s HEAD^..
merging branches
second branch

This previously caused 'postreview.py --guess-summary' to fail for merge
commits since summaries cannot contain newlines. This was fixed by replacing
newlines with spaces...

https://github.com/reviewboard/rbtools/commit/4ee9be4e

On reflection a summary of "merging branches second branch" isn't what we want
- it should be just the merge commit. We can achieve this by using 'HEAD^!'
instead...

% git log --pretty=format:%s HEAD^!
merging branches

Testing done:
Tested by posting a code review using '--guess-summary' with the above merge
commit.

Reviewed at https://reviews.reviewboard.org/r/4147/
Add "checkout of branch" to the bzr branch regex.

When a branch is bound to a remote location, bzr info will report the branch
name with the string "checkout of branch". We weren't handling this in our
regex.

Fixes bug 2960.