X-Git-Url: https://git.tld-linux.org/?p=packages%2Frpm-build-tools.git;a=blobdiff_plain;f=rediff-patches.py;fp=rediff-patches.py;h=d09c9ee93be8a4aac21e01088491f6acf1e118ee;hp=42897f41f792d92fd757cb908f00b10740bf9a96;hb=038c6e25b176e1882a8de3c3c9e2a6e85d5d39b8;hpb=45d8f2d9258214696ed2d3bba02ceb0236d47fd3 diff --git a/rediff-patches.py b/rediff-patches.py index 42897f4..d09c9ee 100755 --- a/rediff-patches.py +++ b/rediff-patches.py @@ -64,11 +64,25 @@ def unpack(spec, appsourcedir, builddir): logging.debug(line) -def diff(diffdir_org, diffdir, builddir, output): +def patch_comment_get(patch): + patch_comment = "" + patch_got = False + with open(patch, 'rt') as f: + for line in f: + if line.startswith('diff ') or line.startswith('--- '): + patch_got = True + break + patch_comment += line + return patch_comment if patch_got else "" + +def diff(diffdir_org, diffdir, builddir, patch_comment, output): diffdir_org = os.path.basename(diffdir_org) diffdir = os.path.basename(diffdir) with open(output, 'wt') as f: + if patch_comment: + f.write(patch_comment) + f.flush() cmd = [ 'diff', '-urNp', '-x', '*.orig', diffdir_org, diffdir ] logging.debug("running %s" % repr(cmd)) try: @@ -114,7 +128,10 @@ def main(): specfile = args.spec appsourcedir = os.path.dirname(os.path.abspath(specfile)) - tempdir = tempfile.TemporaryDirectory(dir="/dev/shm") + try: + tempdir = tempfile.TemporaryDirectory(dir="/dev/shm") + except FileNotFoundError as e: + tempdir = tempfile.TemporaryDirectory(dir="/tmp") topdir = tempdir.name builddir = os.path.join(topdir, 'BUILD') @@ -157,7 +174,12 @@ def main(): unpack(tempspec.name, appsourcedir, builddir) tempspec.close() - diff(appbuilddir + ".org", appbuilddir, builddir, os.path.join(topdir, os.path.join(appsourcedir, patch_name + ".rediff"))) + patch_comment = patch_comment_get(patch_name) + diff(appbuilddir + ".org", + appbuilddir, + builddir, + patch_comment, + os.path.join(topdir, os.path.join(appsourcedir, patch_name + ".rediff"))) diffstat(os.path.join(topdir, os.path.join(appsourcedir, patch_name))) diffstat(os.path.join(topdir, os.path.join(appsourcedir, patch_name + ".rediff")))