add--interactive: refactor patch mode argument processing

The existing parser was very inflexible and tree-like;
seeing "--patch=$mode" would put us into a conditional for
parsing the options for that particular $mode. That made it
very difficult to add additional options that would work for
all patch modes.

This cleanup turns the argument processing into a proper
loop ready to handle multiple arguments. To replace the
mode-specific parsing, we restructure the mode definitions
to better reflect the various cases (i.e., no revision given
versus "HEAD" versus an arbitrary revision).

As a bonus, our parsing is now a little more robust. For
example, we catch the bogus "add--interactive --patch HEAD
--", which is meaningless, but was silently accepted before.
In practice this probably doesn't matter, since we are
always called by other parts of git, but it might catch a
bug in another part of git.

Signed-off-by: Jeff King <peff@peff.net>
add--interactive: factor out regex error handling

When perl complains about compiling a regex the user has
given us, we trim the error to get a nicer message. It's
only one line of code, but it's ugly and non-obvious, so
let's factor it into a reusable function.

Signed-off-by: Jeff King <peff@peff.net>
add--interactive: allow hunk filtering on command line

If you have a lot of uninteresting hunks (e.g., because you
have a file with boilerplate that changed, but you want to
add only the interesting bits and discard the rest), it can
be cumbersome to sift through the boring hunks.

This patch provides an option to match hunks by regular
expression, pretending as if the non-matching changes do not
exist at all (similar to how path-limiting ignores
non-matching paths entirely).

There are two special case pseudo-hunks to consider in the
code: mode hunks and deletion hunks.

  - If a filter is given, this patch will never include mode
    hunks, since the user has asked for a specific subset of
    hunks, and the mode has no text to match.

  - Deletion hunks actually require no special care. In a
    deletion there will be only a single giant diff hunk of
    deleted content. If it matches the filter, then the
    deletion can be presented as normal. If it doesn't
    match, then we exit early from patch_update_file and
    never consider showing the deletion at all (since there
    is nothing to delete).

This patch provides only the perl portion; it is up to
individual callers of add--interactive to pass the option
through to the perl code.

Signed-off-by: Jeff King <peff@peff.net>
add--interactive: allow negatation of hunk filters

This patch lets you filter out certain boring hunks, rather
than trying to match particular interesting ones (which may
be much easier, depending on your file contents).

Signed-off-by: Jeff King <peff@peff.net>
add--interactive: add option to autosplit hunks

It is sometimes useful to see changes in their smallest
possible form, rather than complete hunks with overlapping
context. You can do this manually, of course, with the
's'plit hunk command. But when filtering hunks, you may want
to pre-split to give your filtering a finer granularity.

This patch adds only the perl infrastructure; to expose this
to the user, the various callers of add--interactive need to
pass the new option through to the perl script.

Signed-off-by: Jeff King <peff@peff.net>