Add the --basedir option to post-review.

This new option can be used to override the base directory generated by post-review.
Fix post-review error when svn diffs contain a delete.

post-review would try to call 'svn info' on the deleted files, and would fail. This patch causes post-review to ignore the failure, and continue.
Add bazaar support to post-review

I updated the change from http://reviews.reviewboard.org/r/1739/ which added
support for Bazaar to post-review, but is now out of date.

Testing done: Ran the unit tests included, and used it locally to submit some
changes.

Fixes bug 773.
Reviewed at http://reviews.reviewboard.org/r/3424/
Add a missing file.

I forgot to add bazaar.py when submitting the previous change.
Defaulting rb_version attribute

A ReviewBoardServer's rb_version attribute is set via its check_api_version()
method. This is fine, but our __init__ didn't set a default (dangerous) and if
the check_api_version() lookup failed then the attribute simply didn't exist
(broken). This caused stacktraces when the lookup fails, a user reports that
this happens when his clock is out of sync causing authentication issues...

Traceback (most recent call last):
File "/share/rbtools/rbtools/postreview.py", line 4114, in <module>
  main()
File "/share/rbtools/rbtools/postreview.py", line 4081, in main
  if (parse_version(server.rb_version) >= parse_version('1.5.2') and
AttributeError: 'ReviewBoardServer' object has no attribute 'rb_version'

Adding a default parameter so check_api_version() failures will simply result
in version checks reporting that we're ancient. Also fixed a version check
which was doing string comparison rather than comparing versions.

Tested by disabling my authentication credentials and running post-review for a
perforce repository.

We've been using this change against RBTools 0.3. I've adapted the change for
the current master but this copy of it hasn't been exercised.
Fix what I think is a bug in postreview.

I think this commit http://reviews.reviewboard.org/r/2776/ has moved the server
= initialization a little bit too high in the main() function. It seems that
server might now be uninitialized when going inside this if on line 1270.

Reviewed at http://reviews.reviewboard.org/r/3637/
Print the "Username:" prompt on stderr.

The python builtin function raw_input prints its prompt to stdout, whereas
getpass.getpass() prints it to stderr. This change fixes the username prompt to
print manually so that even if stdout is redirected, the user will still see
both prompts.

Testing done:
Removed my cookies file and posted this review with stdout redirected to a file.
Saw both username and password prompts.

Fixes bug 2831.
Reviewed at http://reviews.reviewboard.org/r/3687/
Capabilities with better moved files support.

Added post-review client capability checking and git moved-files
support.

Git diffs will no longer show renames/moves/copies by default. If the
Review Board server supports moves, then git diff will use -M to show
move information.

Reviewed at http://reviews.reviewboard.org/r/2918/
Fix the location where we load server capabilities.

The load_capabilities call was being called too soon, before the server
was invoked, due to some other code shuffling.
Make sure unicode URLs are encoded as UTF-8

If the server URL is unicode, then trying to make requests would end up with an
encoding conflict between different headers. The bug included a simple fix that
makes urllib happy: manually encoding the url as utf-8 into a string object.

Fixes bug 2238.
Refactor capabilities and fix bug

There was a bug with capabilities not being initialized when they were
used due to the server being contacted after diff generation. The
server is now contacted and the capabilities downloaded before a diff
is generated. This makes it that post-review must contact the Review
Board server even when only generating diffs, so diffs may no longer
be generated offline.

The way capabilities were passed to the SCM tools needed to be
refactored to support the new rbt commands. Capabilities were being
attached to the server object and being passed to the tool, but since
the server object is no longer present in the new commands this had to
change. The Capabilities object itself is now passed directly to the
tools.
Refactor p4 invocation from PerforceClient, and add unit tests.

In an effort to clean up PerforceClient a little and make it testable,
this change consolidates all the p4 invocation into a class called
P4Wrapper. A P4Wrapper class is passed to PerforceClient (defaults to
P4Wrapper, but unit tests can override this), and an instance will be
created from this. Callers can call into this and just deal with the
results, regardless of how p4 is called.

This allowed some unit tests to be written. While this is by no means
comprehensive, it does add some basic testing for things like old-style
and new-style Perforce counters, get_repository_info, and basic diff
building.

I'll be making use of these new tests for Perforce moved file support.

Going forward, we probably should look into using p4 -G to get
marshalled Python objects as results from the commands (in order to
avoid doing our own parsing), and add some exceptions for failure so
that PerforceClient doesn't have to parse error strings.
Fix running Perforce commands with -G.

The -G parameter was being passed after the arguments to p4, rather than
right after p4, which is required. This reorders things to pass -G
first.
Generate proper diffs with moved file information for Perforce.

Modern versions of Perforce support file move operations. These may
either be straight moves, or moves with file changes. We now handle this
information and diff the files correctly. We also inject some custom
fields indicating the move information, so it can be processed by
Review Board.

This feature is funded by NetApp, Inc.
Merge branch 'master' into api
Port 85f43d522e from post-review to rbt post
Port 494a21d145 from post-review to rbt post
Port capabilities to rbt diff

rbt diff will now use the new capabilities change when generating
diffs. This adds moved file detection to git diffs.

The python API bindings were also modified to allow accessing resource
fields using the '[]' operator. Now fields may be accessed either by
attribute (e.g. 'resource.<field_name>') or using the '[]' operator
(e.g. 'resource["<field_name>"]').

Adding '[]' operator access made porting the capabilities change while
maintaining compatibility with post-review much cleaner.
Refactor rbt post to use common code

Removed a lot of the repeated code rbt post was using which had been
moved into the Command base class. Also stopped creating some of the
variables on self, and instead passed them into the methods which need
them.
Port capabilities to rbt post

rbt post will now download and use capabilities when generating
diffs. Diffs generated by git may now use -M.