diff options
-rw-r--r-- | becommands/comment.py | 18 | ||||
-rw-r--r-- | becommands/diff.py | 7 | ||||
-rw-r--r-- | libbe/bug.py | 19 | ||||
-rw-r--r-- | libbe/diff.py | 49 | ||||
-rw-r--r-- | libbe/tree.py | 33 |
5 files changed, 89 insertions, 37 deletions
diff --git a/becommands/comment.py b/becommands/comment.py index 9408b09..fc30a26 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -68,10 +68,10 @@ def execute(args, manipulate_encodings=True): raise cmdutil.UsageError("Please specify a bug or comment id.") if len(args) > 2: raise cmdutil.UsageError("Too many arguments.") - + shortname = args[0] if shortname.count(':') > 1: - raise cmdutil.UserError("Invalid id '%s'." % shortname) + raise cmdutil.UserError("Invalid id '%s'." % shortname) elif shortname.count(':') == 1: # Split shortname generated by Comment.comment_shortnames() bugname = shortname.split(':')[0] @@ -79,7 +79,7 @@ def execute(args, manipulate_encodings=True): else: bugname = shortname is_reply = False - + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=manipulate_encodings) bug = bd.bug_from_shortname(bugname) @@ -89,10 +89,16 @@ def execute(args, manipulate_encodings=True): bug_shortname=bugname) else: parent = bug.comment_root - + if len(args) == 1: # try to launch an editor for comment-body entry try: - body = editor.editor_string("Please enter your comment above") + if parent == bug.comment_root: + parent_body = bug.summary+"\n" + else: + parent_body = parent.body + estr = "Please enter your comment above\n\n> %s\n" \ + % ("\n> ".join(parent_body.splitlines())) + body = editor.editor_string(estr) except editor.CantFindEditor, e: raise cmdutil.UserError, "No comment supplied, and EDITOR not specified." if body is None: @@ -111,7 +117,7 @@ def execute(args, manipulate_encodings=True): body = args[1] if not body.endswith('\n'): body+='\n' - + if options.XML == False: new = parent.new_reply(body=body) if options.author != None: diff --git a/becommands/diff.py b/becommands/diff.py index 50dea7c..4b319ca 100644 --- a/becommands/diff.py +++ b/becommands/diff.py @@ -37,7 +37,6 @@ def execute(args, manipulate_encodings=True): Modified bug reports: a:cm: Bug A status: open -> closed - <BLANKLINE> """ parser = get_parser() options, args = parser.parse_args(args) @@ -54,7 +53,7 @@ def execute(args, manipulate_encodings=True): print "This directory is not revision-controlled." else: old_bd = bd.duplicate_bugdir(revision) - r,m,a = diff.diff(old_bd, bd) + r,m,a = diff.bug_diffs(old_bd, bd) optbugs = [] if options.all == True: @@ -69,7 +68,9 @@ def execute(args, manipulate_encodings=True): for bug in optbugs: print bug.uuid else : - print diff.diff_report((r,m,a), bd).encode(bd.encoding) + rep = diff.diff_report((r,m,a), old_bd, bd).encode(bd.encoding) + if len(rep) > 0: + print rep bd.remove_duplicate_bugdir() def get_parser(): diff --git a/libbe/bug.py b/libbe/bug.py index f3448e2..c1e5481 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -494,8 +494,25 @@ cmp_assigned = lambda bug_1, bug_2 : cmp_attr(bug_1, bug_2, "assigned") # chronological rankings (newer < older) cmp_time = lambda bug_1, bug_2 : cmp_attr(bug_1, bug_2, "time", invert=True) +def cmp_comments(bug_1, bug_2): + """ + Compare two bugs' comments lists. Doesn't load any new comments, + so you should call each bug's .load_comments() first if you want a + full comparison. + """ + comms_1 = sorted(bug_1.comments(), key = lambda comm : comm.uuid) + comms_2 = sorted(bug_2.comments(), key = lambda comm : comm.uuid) + result = cmp(len(comms_1), len(comms_2)) + if result != 0: + return result + for c_1,c_2 in zip(comms_1, comms_2): + result = cmp(c_1, c_2) + if result != 0: + return result + return 0 + DEFAULT_CMP_FULL_CMP_LIST = \ - (cmp_status,cmp_severity,cmp_assigned,cmp_time,cmp_creator) + (cmp_status,cmp_severity,cmp_assigned,cmp_time,cmp_creator,cmp_comments) class BugCompoundComparator (object): def __init__(self, cmp_list=DEFAULT_CMP_FULL_CMP_LIST): diff --git a/libbe/diff.py b/libbe/diff.py index 963d692..ba48efc 100644 --- a/libbe/diff.py +++ b/libbe/diff.py @@ -19,7 +19,7 @@ from libbe import cmdutil, bugdir, bug from libbe.utility import time_to_str import doctest -def diff(old_bugdir, new_bugdir): +def bug_diffs(old_bugdir, new_bugdir): added = [] removed = [] modified = [] @@ -27,6 +27,8 @@ def diff(old_bugdir, new_bugdir): old_bug = old_bugdir.bug_from_uuid(uuid) try: new_bug = new_bugdir.bug_from_uuid(uuid) + old_bug.load_comments() + new_bug.load_comments() if old_bug != new_bug: modified.append((old_bug, new_bug)) except KeyError: @@ -37,26 +39,34 @@ def diff(old_bugdir, new_bugdir): added.append(new_bug) return (removed, modified, added) -def diff_report(diff_data, bug_dir): - (removed, modified, added) = diff_data +def diff_report(bug_diffs_data, old_bugdir, new_bugdir): + bugs_removed,bugs_modified,bugs_added = bug_diffs_data def modified_cmp(left, right): return bug.cmp_severity(left[1], right[1]) - added.sort(bug.cmp_severity) - removed.sort(bug.cmp_severity) - modified.sort(modified_cmp) + bugs_added.sort(bug.cmp_severity) + bugs_removed.sort(bug.cmp_severity) + bugs_modified.sort(modified_cmp) lines = [] - if len(added) > 0: + if old_bugdir.settings != new_bugdir.settings: + bugdir_settings = sorted(new_bugdir.settings_properties) + bugdir_settings.remove("rcs_name") # tweaked by bugdir.duplicate_bugdir + change_list = change_lines(old_bugdir, new_bugdir, bugdir_settings) + if len(change_list) > 0: + lines.append("Modified bug directory:") + change_strings = ["%s: %s -> %s" % f for f in change_list] + lines.extend(change_strings) + lines.append("") + if len(bugs_added) > 0: lines.append("New bug reports:") - for bg in added: + for bg in bugs_added: lines.extend(bg.string(shortlist=True).splitlines()) lines.append("") - - if len(modified) > 0: + if len(bugs_modified) > 0: printed = False - for old_bug, new_bug in modified: - change_str = bug_changes(old_bug, new_bug, bug_dir) + for old_bug, new_bug in bugs_modified: + change_str = bug_changes(old_bug, new_bug) if change_str is None: continue if not printed: @@ -65,14 +75,13 @@ def diff_report(diff_data, bug_dir): lines.extend(change_str.splitlines()) if printed == True: lines.append("") - - if len(removed) > 0: + if len(bugs_removed) > 0: lines.append("Removed bug reports:") - for bg in removed: + for bg in bugs_removed: lines.extend(bg.string(shortlist=True).splitlines()) lines.append("") - return '\n'.join(lines) + return "\n".join(lines).rstrip("\n") def change_lines(old, new, attributes): change_list = [] @@ -86,13 +95,13 @@ def change_lines(old, new, attributes): else: return None -def bug_changes(old, new, bugs): - change_list = change_lines(old, new, ("time", "creator", "severity", - "target", "summary", "status", "assigned")) +def bug_changes(old, new): + bug_settings = sorted(new.settings_properties) + change_list = change_lines(old, new, bug_settings) + change_strings = ["%s: %s -> %s" % f for f in change_list] old_comment_ids = [c.uuid for c in old.comments()] new_comment_ids = [c.uuid for c in new.comments()] - change_strings = ["%s: %s -> %s" % f for f in change_list] for comment_id in new_comment_ids: if comment_id not in old_comment_ids: summary = comment_summary(new.comment_from_uuid(comment_id), "new") diff --git a/libbe/tree.py b/libbe/tree.py index fe791a5..45ae085 100644 --- a/libbe/tree.py +++ b/libbe/tree.py @@ -35,7 +35,7 @@ class Tree(list): >>> a = Tree(); a.n = "a" >>> a.append(c) >>> a.append(b) - + >>> a.branch_len() 5 >>> a.sort(key=lambda node : -node.branch_len()) @@ -44,7 +44,7 @@ class Tree(list): >>> a.sort(key=lambda node : node.branch_len()) >>> "".join([node.n for node in a.traverse()]) 'abdgcefhi' - >>> "".join([node.n for node in a.traverse(depthFirst=False)]) + >>> "".join([node.n for node in a.traverse(depth_first=False)]) 'abcdefghi' >>> for depth,node in a.thread(): ... print "%*s" % (2*depth+1, node.n) @@ -68,7 +68,18 @@ class Tree(list): f h i + >>> a.has_descendant(g) + True + >>> c.has_descendant(g) + False + >>> a.has_descendant(a) + False + >>> a.has_descendant(a, match_self=True) + True """ + def __eq__(self, other): + return id(self) == id(other) + def branch_len(self): """ Exhaustive search every time == SLOW. @@ -97,11 +108,11 @@ class Tree(list): for child in self: child.sort(*args, **kwargs) - def traverse(self, depthFirst=True): + def traverse(self, depth_first=True): """ Note: you might want to sort() your tree first. """ - if depthFirst == True: + if depth_first == True: yield self for child in self: for descendant in child.traverse(): @@ -119,7 +130,7 @@ class Tree(list): When flatten==False, the depth of any node is one greater than the depth of its parent. That way the inheritance is explicit, but you can end up with highly indented threads. - + When flatten==True, the depth of any node is only greater than the depth of its parent when there is a branch, and the node is not the last child. This can lead to ancestry ambiguity, @@ -138,8 +149,8 @@ class Tree(list): stack = [] # ancestry of the current node if flatten == True: depthDict = {} - - for node in self.traverse(depthFirst=True): + + for node in self.traverse(depth_first=True): while len(stack) > 0 \ and id(node) not in [id(c) for c in stack[-1]]: stack.pop(-1) @@ -157,4 +168,12 @@ class Tree(list): yield (depth,node) stack.append(node) + def has_descendant(self, descendant, depth_first=True, match_self=False): + if descendant == self: + return match_self + for d in self.traverse(depth_first): + if descendant == d: + return True + return False + suite = doctest.DocTestSuite() |