diff options
author | Owen W. Taylor <otaylor@fishsoup.net> | 2009-09-05 09:06:19 -0400 |
---|---|---|
committer | Owen W. Taylor <otaylor@fishsoup.net> | 2009-09-05 09:06:19 -0400 |
commit | 837a86d1fdc632aa57423d31d4adf4073a61d36a (patch) | |
tree | d9a13c234590ee2a64d0a94593140e7ad53681c8 | |
parent | d6c6d4f9ec53a4b119b704a2d2eea6ee39ce7c00 (diff) |
Allow omitting bug reference for 'git bz attach'
When there is a single bug referenced in the commits being attached,
allow using that instead of specifying a bug reference manually.
-rw-r--r-- | TODO | 7 | ||||
-rwxr-xr-x | git-bz | 34 |
2 files changed, 31 insertions, 10 deletions
@@ -6,13 +6,6 @@ any intention of working on it myself. - Owen -Allow omitting bug reference when obvious - - When there is only one commit, and -u/--add-url has previously been used, - or the commit subject/body contains [Bb]ug #?\d+ you should be able do just: - - git bz attach HEAD^ - Default to -e/--edit when only one commit When there is only one commit to attach, we might as well default to @@ -552,6 +552,11 @@ class BugHandle: self.https = https self.id = id + def get_url(self): + return "%s://%s/show_bug.cgi?id=%s" % ("https" if self.https else "http", + self.host, + self.id) + @staticmethod def parse(bug_reference): m = re.match("http(s?)://([^/]+)/show_bug.cgi\?id=([^&]+)", bug_reference) @@ -1529,10 +1534,33 @@ def attach_commits(bug, commits, include_comments=True, edit_comments=False): obsoletes = [] bug.create_patch(commit.subject, body, filename, patch, obsoletes=obsoletes) -def do_attach(bug_reference, commit_or_revision_range): - bug = Bug.load(BugHandle.parse_or_die(bug_reference)) +def do_attach(*args): + if len(args) == 1: + commit_or_revision_range = args[0] + commits = get_commits(commit_or_revision_range) + + extracted = list(extract_and_collate_bugs(commits)) + if len(extracted) == 0: + die("No bug references found in specified commits") + elif len(extracted) > 1: + # This could be sensible in the case of "attach updated patches + # for all these commits", but for now, just make it an error + die("Found multiple bug references specified commits:\n " + + "\n ".join((handle.get_url() for handle, _ in extracted))) + + # extract_and_collate_bugs returns a list of commits that reference + # the handle, but we ignore that - we want to attach all of the + # specified commits, even if only some of the reference the bug + handle, _ = extracted[0] + else: + bug_reference = args[0] + commit_or_revision_range = args[1] + + commits = get_commits(commit_or_revision_range) + handle = BugHandle.parse_or_die(bug_reference) + + bug = Bug.load(handle) - commits = get_commits(commit_or_revision_range) if global_options.add_url: check_add_url(commits, bug.id, is_add_url=False) |