diff options
author | Dan Winship <danw@gnome.org> | 2011-08-02 10:57:48 -0400 |
---|---|---|
committer | Owen W. Taylor <otaylor@fishsoup.net> | 2012-03-01 13:52:04 -0500 |
commit | f69a952c5d66fcd2da40d125374608c04f39960b (patch) | |
tree | 6358e0a2f34c3687a1b1385fdd4a2f7c2be986d2 | |
parent | ce11237046a1af9728f7d0544c6aae8eb1d5c7d3 (diff) | |
download | git-bz-f69a952c5d66fcd2da40d125374608c04f39960b.tar.gz |
apply: attempt to handle plain diffs
If a bug has a plain diff (as opposed to git-format-patch output),
prepend some minimal headers to it to get it into a format git-am will
accept, and then make the user write a commit message for it before
proceeding.
https://bugzilla.gnome.org/show_bug.cgi?id=657558
-rwxr-xr-x | git-bz | 32 | ||||
-rw-r--r-- | git-bz.txt | 4 |
2 files changed, 34 insertions, 2 deletions
@@ -1152,6 +1152,7 @@ class Bug(object): # the attachment patch.description = attachment.find("desc").text patch.date = attachment.find("date").text + patch.attacher = attachment.find("attacher").text status = attachment.find("status") patch.status = None if status is None else status.text patch.filename = attachment.find("filename").text @@ -1562,7 +1563,8 @@ def do_apply(*args): lines = f.read().rstrip().split('\n') bug_ref = lines[0] orig_head = lines[1] - patch_ids = map(int, lines[2:]) + need_amend = lines[2] == "True" + patch_ids = map(int, lines[3:]) f.close() except: die("Not inside a 'git bz apply' operation") @@ -1575,6 +1577,12 @@ def do_apply(*args): if global_options.abort: sys.exit(0) + if need_amend: + try: + git.commit(amend=True) + except CalledProcessError: + print >>sys.stderr, "Warning: left dummy commit message" + else: if resuming: die(parser.get_usage()) @@ -1640,6 +1648,21 @@ def do_apply(*args): die("No patches to apply, aborting") for patch in patches: + if re.search(r'(^|\n)From ', patch.data) is None: + # Plain diff... rewrite it into something git-am will accept + users = bug.server.get_xmlrpc_proxy().User.get({ 'names': [patch.attacher] })['users'] + name = users[0]['real_name'] + email = users[0]['email'] + headers = """From xxx +From: %s <%s> +Date: %s +Subject: %s +""" % (name, email, patch.date, patch.description) + patch.data = headers + "\n\nFIXME: need commit message\n---\n" + patch.data + need_amend = True + else: + need_amend = False + handle, filename = tempfile.mkstemp(".patch", make_filename(patch.description) + "-") f = os.fdopen(handle, "w") f.write(patch.data) @@ -1655,6 +1678,7 @@ def do_apply(*args): f = open(git_dir + "/rebase-apply/git-bz", "w") f.write("%s\n" % bug_ref) f.write("%s\n" % orig_head) + f.write("%r\n" % need_amend) for i in range(patches.index(patch) + 1, len(patches)): f.write("%s\n" % patches[i].attach_id) f.close() @@ -1663,6 +1687,12 @@ def do_apply(*args): os.remove(filename) + if need_amend: + try: + git.commit(amend=True) + except CalledProcessError: + print >>sys.stderr, "Warning: left dummy commit message" + if global_options.add_url: # Slightly hacky. We could add the URLs as we go by using # git-mailinfo to parse each patch, calling @@ -143,7 +143,9 @@ apply them. In addition to simply accepting or rejecting the list of patches, you can also type "i" to interactively choose which patches to apply, and in what order, as with 'git rebase -i'. If any patches are selected, it runs 'git am' on each one to apply it to the current -branch. +branch. (If the bug contains patches in the form of plain diffs, 'git +bz apply' will create a commit based on the other patch metadata, and +prompt you for a commit message.) If a 'git am' operation fails, 'git bz apply' will save its state and then exit, at which point you can attempt to apply the patch by hand |