pq: rewrite patch export functionality

Use our own function for constructing the patch files instead of using
the format-patch command of git. This way, we get the desired output
format directly, without the need for the error-prone "format-patch,
parse patch files, mangle and re-write patch files" cycle.

Also, fix patch naming in patch generation when '--no-patch-numbers' is
used.  Previously, multiple commits with the same subject resulted in
multiple patches having the same filename. This lead into broken series
with missing patches as patch files were overwritten by the topmost
commit.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
pq.format_patch: support file path filtering

Implements a filter option that allows filtering out changes to certain
files/paths in the patch-generation. A commit is totally ignored if all
files would be filtered out. The path filter is given as a Python
regexp.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
pq: properly generate non-ascii patch files

Encode non-ascii email headers properly. Also, set MIME headers
correctly for the message body if the commit message body contains
non-ascii characters.

The reason for constructing the message in a little bit "clumsy" way is
the intention is to match the output of git-format-patch as closely as
possible.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
pq: support patch-export commands

Support giving commands to pq as a meta tag in commit message. The
format is "Gbp: <command> [args]".

Currently, only one command is supported. namely 'ignore'. That is, one
can use 'Gbp: Ignore' in the commit message for ignoring the commit in
patch-generation.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
pq: add format_diff() function

For generating a patch file from a diff between two arbitrary commits.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
pq: listen to 'Gbp-Pq:' commands, too

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
pq: support 'Topic' patch-export command

Topic can be defined with either 'Gbp: Topic <topic>' or 'Gbp-Pq: Topic
<topic>' in the commit message.

This is to replace the "gbp-pq-topic: <topic>" command.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
pq: deprecate the usage of 'gbp-pq-topic:'

Replaced by the "Gbp[-Pq]: Topic <topic>" command.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GbpOptionParser: allow using the default 'dest' attribute

Make it possible to add options without explicitly defining the 'dest'
attribute - in which case the default of OptionParser is used.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GitRepository/rev_parse: use _git_inout()

instead of the deprecated _git_getoutput() method.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GitRepository: raise GitRepositoryError instead of GbpError

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GitRepository: Implement status method

Simple wrapper to the git-status command.

Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GitRepository: allow repo inititialization from subdir

This allows initialization of a GitRepository object, even if the
current working directory (or path given to GitRepository) is not the
top level directory of the git repository.

Don't guess the git meta data dir, but, take it as reported by git
itself.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GitRepository.add_files: use GitArgs

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GitRepository.add_files: consistently update ALL tracked files

Use the --all option of git-add so that all tracked files are updated in
all conditions. Previously deletion of tracked files was not staged, for
example.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp.git: Reimplement rfc822 date parsing without dateutil

In order to get rid of dependency to dateutil.

Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
common/buildpackage: support for different archive formats

Adds support for defining the archive format of the output of
git_archive_single(), e.g. 'zip'. Defaults to 'tar', as before.

Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GitRepository/_git_inout: implement support for filtering

Support filtering of the output of git command through a python
function.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Change compressor cmdline opts in compressor_opts to a list

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
GitRepository: rewrite git_archive()

Add support for filtering. That is, allow the caller to pipe the output
of git-archive through a filter command, usually a compression program.
This utilizes the new filtering functionality of the _git_inout()
method.

Also, gets rid of the hackish use of 'cwd' option.

The 'output' is now considered to be relative to the caller's cwd, not
the git repo dir. This should be more intuitive.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>