[debrepatch] 01/01: More robustness fixes, planning to put this in devscripts
Ximin Luo
infinity0 at debian.org
Thu Nov 17 18:22:14 UTC 2016
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository debrepatch.
commit c7210cbac57c9f99734cfca07a9753d5581be322
Author: Ximin Luo <infinity0 at debian.org>
Date: Thu Nov 17 19:21:58 2016 +0100
More robustness fixes, planning to put this in devscripts
---
debpatch | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/debpatch b/debpatch
index 3aedb53..20cd852 100755
--- a/debpatch
+++ b/debpatch
@@ -57,6 +57,8 @@ def read_dch_patch(dch_patch):
hunk = dch_patch[0]
source_str = hunk_lines_to_str(hunk.source_lines()) + DCH_DUMMY_TAIL
target_str = hunk_lines_to_str(hunk.target_lines())
+ # here we assume the debdiff has enough context to see the previous version
+ # this should be true all the time in practice
source_version = parse_dch(source_str, "-SVersion")
target = read_dch(target_str)
return source_version, target
@@ -105,12 +107,21 @@ def apply_dch_patch(source_file, current, patch_name, old_version, target, dry_r
if changes.lstrip().startswith("["):
changes = "\n" + changes
- # TODO: make this a bit more atomic; if any of the C()s fail we should rewind
token = "DEBPATCH PLACEHOLDER %s DELETEME" % random.randint(0, 2**64)
- C(["dch", "-c", source_file] + dch_args +
- [marker])
- C(["dch", "-c", source_file, "-a", token], env=dch_env)
- C(["sed", "-e", "/%s/c\\\n%s" % (token, changes.replace("\n", "\\\n")), "-i", source_file])
+ shutil.copy(source_file, source_file + ".debpatch.bak")
+ try:
+ C(["dch", "-c", source_file] + dch_args + [marker])
+ C(["dch", "-c", source_file, "-a", token], )
+ C(["sed", "-e", "/%s/c\\\n%s" % (token, changes.replace("\n", "\\\n")), "-i", source_file])
+ except:
+ os.rename(source_file, source_file + ".debpatch.err")
+ logging.warn("failed to patch %s", source_file)
+ logging.warn("half-applied changes in %s", source_file + ".debpatch.err")
+ logging.warn("current working directory is %s", os.getcwd())
+ os.rename(source_file + ".debpatch.bak", source_file)
+ raise
+ else:
+ os.unlink(source_file + ".debpatch.bak")
def call_patch(patch_str, *args, check=True, **kwargs):
return subprocess.run(
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debrepatch.git
More information about the Reproducible-commits
mailing list