diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-05-08 20:07:52 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-10-31 19:17:21 +0100 |
commit | 3dccca6eb983512dfaca01df4ac758a2cc420388 (patch) | |
tree | e5c013d45d2e9a5fbdf870fd1031dc6dee9eb1c0 /gbp/scripts | |
parent | 91fbdc17c8f529f649db7521f85a39e99d0cc4a4 (diff) | |
download | git-buildpackage-3dccca6eb983512dfaca01df4ac758a2cc420388.tar.gz git-buildpackage-3dccca6eb983512dfaca01df4ac758a2cc420388.tar.bz2 git-buildpackage-3dccca6eb983512dfaca01df4ac758a2cc420388.zip |
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>
Diffstat (limited to 'gbp/scripts')
-rw-r--r-- | gbp/scripts/common/pq.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index b6b2118d..7f0c0c9b 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -21,11 +21,14 @@ import re import os import subprocess +import datetime +import time from email.message import Message from email.header import Header from email.charset import Charset, QP -from gbp.git import GitRepositoryError, GitModifier +from gbp.git import GitRepositoryError +from gbp.git.modifier import GitModifier, GitTz from gbp.errors import GbpError import gbp.log @@ -200,6 +203,29 @@ def format_patch(outdir, repo, commit_info, series, numbered=True, return patch +def format_diff(outdir, filename, repo, start, end, path_exclude_regex=None): + """Create a patch of diff between two repository objects""" + + info = {'author': repo.get_author_info()} + now = datetime.datetime.now().replace(tzinfo=GitTz(-time.timezone)) + info['author'].set_date(now) + info['subject'] = "Raw diff %s..%s" % (start, end) + info['body'] = ("Raw diff between %s '%s' and\n%s '%s'\n" % + (repo.get_obj_type(start), start, + repo.get_obj_type(end), end)) + if not filename: + filename = '%s-to-%s.diff' % (start, end) + filename = os.path.join(outdir, filename) + + file_status = repo.diff_status(start, end) + paths = patch_path_filter(file_status, path_exclude_regex) + if paths: + diff = repo.diff(start, end, paths=paths, stat=80, summary=True, + text=True) + return write_patch_file(filename, info, diff) + return None + + def get_maintainer_from_control(repo): """Get the maintainer from the control file""" control = os.path.join(repo.path, 'debian', 'control') |