Fix 'rbt close' to not require a working directory if the server is specified.

Because of rbt's post-review heritage, it often requires a working directory,
even if all it uses it for is to detect the Review Board server path. This
change fixes 'rbt close' to skip the SCM detection if a server is specified
(either via the command-line or the home directory ~/.reviewboardrc).

Testing Done:

Closed https://reviews.reviewboard.org/r/5464/ by running
    rbt close --server=https://reviews.reviewboard.org/ 5464 --description="Closing review with rbt close --server=https://reviews.reviewboard.org/ 5464"

Bugs closed: 3249

Reviewed at https://reviews.reviewboard.org/r/5465/
rbt should find repositories based on mirror_path

"rbt post -u" doesn't work if the repository is being identified using a
mirror_path - get_repository_id returns None which causes an error trying to do
the update.

The patch matches the logic in commands/setup_repo.py and clients/svn.py.

Testing Done:
Tested locally against reviewboard 1.7 - repo with the path of
http://svn.DOMAIN/svn/foo and mirror_path of http://svn/svn/foo works with `rbt
post -u` when my local checkout is http://svn/svn/foo

Reviewed at https://reviews.reviewboard.org/r/5468/
Fix svn client incorrectly detecting "history scheduled with commit" with changelists

Scenario:
1. Add a new file X to branch BrA, commit
2. svn merge X from branch BrA to branch BrB in working copy (status "A +")
3. Modify file Y in working copy, send ONLY file Y (status "M) to changelist CL
4. rbt post --svn-changelist=CL

Expected: post succeeds, because changelist only contains modified files
Actual: post fails with "Please try again with
'--svn-show-copies-as-adds=y/n'"; this is because rbt "sees" file X, despite
explicitly only posting Y for review.

This patch modifies history_scheduled_with_commit in rbtools/clients/svn.py to
pass the --changelist option, if present, down to 'svn st'

Testing done:
* The scenario described above now works as expected.
* Unit tests pass.

Fixes bug 3248.
Organize the rbt post --help output.

rbt post has a lot of options, and it was hard to figure out which
options were intended to serve which purposes, unless you knew what you
were looking for.

This organizes all the options into groups. To do this, I've implemented
a custom OptionGroup class that just wraps optparse's OptionGroup.
Commands can use this to group instances of our Option class under a
name and optional description.

The options are divided into the following groups:

* Posting Options
* Review Board Server Options
* Repository Options
* Review Request Field Options
* Diff Generation Options
* Git Options
* Perforce Options
* Subversion Options
Don't use _convert_symbolic_revision with 'BASE'

In the case that the BASE revision is not present on the current working
directory (such as when the latest synced change is on a branch, and cwd is
trunk), trying to convert the BASE symbol to a numbered revision will fail.

This change just passes through the string 'BASE' as the base revision, which
should be both more efficient and cover all the possible situations.

Fixes bug 3250.
Change how commit message parsing and diff calls work.

The SCMClients had some confusing responsibilities where they attempted
to handle the guessed summary/description logic in the diff methods,
getting and setting data in the options object. This logic had no
business being in the diff method, or in SCMClients for that matter, and
should have exclusively been in rbt post.

On top of that, we had some variations in how the commit summary and
description were fetched and processed in the different SCMClients. This
led to differences in behavior and subtle bugs. For example, Mercurial
was grabbing the summary from the wrong end of a commit range, and
Bazaar was providing extraneous information for the descriptions.

Now, instead of extract_summary() and extract_description() methods,
SCMClients only need to implement get_raw_commit_message(). This returns
the full set of commit messages for the provided revisions. The base
SCMClient class then provides a get_commit_message() that calls that and
splits the result into a summary and a description.

The description also no longer includes the summary line, preventing the
first line of the Description field from mirroring the Summary field
unnecessarily.

rbt post is then responsible for calling this when it needs to generate
the guessed content or match an existing review request in order to
update it.

Since both get_commit_message() and diff() need parsed revisions, it no
longer makes sense for diff() to call parse_revision_spec(). That's now
the job of the caller, which results in diff() being just a bit simpler.

At this point, the get_diff() utility function is no longer necessary
either, so it's been removed.

Now that `rbt post` owns more of the logic, it can also be smarter about
when things are called. Previously, if using -u, we'd parse the
revision spec twice (once in diff() and once when generating the
summary/description for matching).

We also would make at least two calls to get the summary and description
(more, if using -g and the description was blank).

`rbt post` now caches the parsed revision spec, and the commit message,
preventing us from having to run as many costly commands.

This all results in a cleaner design with less responsibility in
SCMClient, fewer usages of the options object, and faster posting.
Normalize path case names for perforce client path comparison.

When checking that the current working directory is within the perforce client,
we weren't normalizing the case of the paths. This was fine on case-sensitive
file systems, like Linux, but broke for Windows systems. Trivial fix.

Testing done: Ran unit tests

Fixes bug 3221.
Merge branch 'release-0.5.x'
Allow posting filenames of retina images with svn.

When adding or changing files whose filenames include '@' (such as
image@2x.png), we need to clarify in our 'svn info' command line that the '@'
in the filename isn't a revision indicator. This is done by adding an extra '@'
at the end of the filename.

Testing done:
Added a file called image@2x.png and ran 'rbt post --debug'. Saw that there
were no longer a bunch of errors running 'svn info'.

Fixes bug 2702.

Reviewed at https://reviews.reviewboard.org/r/5477/
Limit Bazaar logs to one fewer revision with revision ranges.

When guessing the summary and description for Bazaar using revision ranges, the
guessed results would include the commit message for the orig revision of the
diff, which isn't right. This change does one log operation to get the number
of revisions, and then another one, limiting the results to that number less
one.

Testing done: Ran unit tests.

Fixes bug 2959.

Reviewed at https://reviews.reviewboard.org/r/5491/
Don't use _convert_symbolic_revision with 'BASE'

In the case that the BASE revision is not present on the current working
directory (such as when the latest synced change is on a branch, and cwd is
trunk), trying to convert the BASE symbol to a numbered revision will fail.

This change just passes through the string 'BASE' as the base revision, which
should be both more efficient and cover all the possible situations.

Fixes bug 3250.
Fix unit tests for changes to 'BASE' treatment in SVNClient.

We no longer try to convert the string 'BASE' to a numeric revision, so the
unit tests shouldn't expect that. Trivial change.
Merge branch 'release-0.5.x'
Handle git-p4 metadata with additional options in the revision tags.

When the git-p4 clone is used with an option like 'keepRepoPath', it breaks our
revision parsing. Making a trivial change to the regex handles these cases.

Fixes bug 3220.
Execute subcommands using the "C" locale.

A while back, we changed rbtools to exec the various command-line tools it uses
using the en_US locale (so that we wouldn't get diffs with localized strings in
them). This is nice, but annoying when users don't have the en_US locale on
their system. This change updates things to use the "C" locale instead.

Testing done: Ran unit tests.

Fixes bug 3253.

Reviewed at https://reviews.reviewboard.org/r/5498/
Merge branch 'release-0.5.x'
Add --ignore-externals to all 'svn status' calls.

Posting changes that involve directories brought in with svn:externals will
break. While the basic diffing mechanism in rbtools is OK, we don't ask our
'svn status' calls to ignore externals, which could cause some problems.

Testing done: Ran unit tests.

Fixes bug 2545.
Reduce duplication of options.

Many of the rbt commands use similar options. For example, any command that
talks to the server is going to want to have --server, --username, --password,
and --disable-proxy. In many cases, we had duplicates of these options, but
with slight differences and omissions scattered throughout.

This change moves the common OptionGroup definitions into the Command class,
and references those from each Command subclass's option_list.

Testing done: Ran rbt <command> --help for every command.

Reviewed at https://reviews.reviewboard.org/r/5506/
Pass p4 port, client, and password on the command line instead of using env.

The p4 client prefers, in order, arguments on the command line, .p4config
settings, and finally P4* environment variables. This meant that if someone had
a .p4config file, and then specified --p4-port and --p4-client with something
different, it wouldn't actually override their file.

I've changed the client implementation to use -p, -c, and -P arguments to 'p4'
instead of setting things in the environment.

Testing done: Ran unit tests.

Fixes bug 2712.

Reviewed at https://reviews.reviewboard.org/r/5363/
Merge branch 'release-0.5.x'