From c302d2289ef045f7c8e3f2f3c9071414f9d8212b Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Fri, 18 Sep 2009 12:52:45 -0400 Subject: Fix adding-url to just some commits Adding an URL to just some commits was broken in the rewrite to be more like git rebase, shuffle things around to fix that. --- git-bz | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/git-bz b/git-bz index 9ede172..4d39dba 100755 --- a/git-bz +++ b/git-bz @@ -1230,19 +1230,21 @@ def add_url_to_head_commit(commit, bug): git.commit(file="-", amend=True, _input=input) def add_url(bug, commits): - # Avoid the rebase if nothing to do - commits = [commit for commit in commits if commit_needs_url(commit, bug.id)] - if len(commits) == 0: # Nothing to do + commit_map = {} + oldest_commit = None + for commit in commits: + commit_map[commit.id] = commit + if commit_needs_url(commit, bug.id): + oldest_commit = commit + + if not oldest_commit: return # Check that the add-url method is valid before starting the rebase validate_add_url_method(bug) - oldest_commit = commits[-1] - - newer_commits = rev_list_commits(commits[0].id + "..HEAD") - - orig_head = newer_commits[0].id if newer_commits else commits[0].id + all_commits = rev_list_commits(oldest_commit.id + "^..HEAD") + orig_head = all_commits[0].id try: branch_name = git.symbolic_ref("HEAD", q=True) @@ -1253,29 +1255,26 @@ def add_url(bug, commits): print "Moving to starting point" git.checkout(oldest_commit.id + "^", q=True) - for commit in reversed(commits): - if not commit_needs_url(commit, bug.id): - print "Recommitting", commit.id[0:7], commit.subject, "(already has bug #)" - git.cherry_pick(commit.id) - # Find the new commit ID, though it doesn't matter much here - commit.id = git.rev_parse("HEAD") - continue - - print "Adding bug reference ", commit.id[0:7], commit.subject - git.cherry_pick(commit.id) + for commit in reversed(all_commits): + # Map back to the original commit object so we can update it + if commit.id in commit_map: + commit = commit_map[commit.id] - add_url_to_head_commit(commit, bug) - - # In this case, we need the new commit ID, so that when we later format the - # patch, we format the patch with the added bug URL - commit.id = git.rev_parse("HEAD") + if commit.id in commit_map and commit_needs_url(commit, bug.id): + print "Adding bug reference ", commit.id[0:7], commit.subject + git.cherry_pick(commit.id) + add_url_to_head_commit(commit, bug) + else: + if commit.id in commit_map: + print "Recommitting", commit.id[0:7], commit.subject, "(already has bug #)" + else: + print "Recommitting", commit.id[0:7], commit.subject + git.cherry_pick(commit.id) - for commit in reversed(newer_commits): - print "Recommitting", commit.id[0:7], commit.subject - git.cherry_pick(commit.id) - commit.id = git.rev_parse("HEAD") + # Get the commit ID; we update the commit with the new ID, so we in the case + # where we later format the patch, we format the patch with the added bug URL + new_head = commit.id = git.rev_parse("HEAD") - new_head = newer_commits[0].id if newer_commits else commits[0].id if branch_name is not None: git.update_ref("-m", "bz add-url: adding references to %s" % bug.get_url(), branch_name, new_head) -- cgit