[MERGE] annotate uncommitted changes

John Arbash Meinel john at arbash-meinel.com
Sun Dec 17 16:29:25 GMT 2006


Aaron Bentley wrote:
> Aaron Bentley wrote:
>> This revision adds a new Tree.annotate_iter interface.  This allows
>> uncommitted changes to be annotated.
> 
> Here's an update: it annotates against all parents, not just the
> leftmost parent, so correctly associates lines with pending-merge revisions.
> 
> Aaron


To start with, I really like the idea, especially that you can annotate
the working files to get where lines came from even from merged parents.


v- We need a couple more blank lines here.

+
+from bzrlib import annotate, tests
+
+def annotation(text):
+    return [tuple(l.split(' ', 1)) for l in text.splitlines(True)]
+
+parent_1 = annotation("""\
+rev1 a
+rev2 b
+rev3 c
+rev4 d
+rev5 e
+""")
+
+parent_2 = annotation("""\
+rev1 a
+rev3 c
+rev4 d
+rev6 f
+rev7 e
+rev8 h
+""")
+
+expected_2_1 = annotation("""\
+rev1 a
+blahblah b
+rev3 c
+rev4 d
+rev7 e
+""")
+

...

v- Why do you need a separate public and private 'reannotate' function,
rather than just having Tree.annotate_iter()?

+
+
+def reannotate(parents_lines, new_lines, new_revision_id):
+    """Create a new annotated version from new lines and parent
annotations.
+
+    :param parents_lines: List of annotated lines for all parents
+    :param new_lines: The un-annotated new lines
+    :param new_revision_id: The revision-id to associate with new lines
+        (will often be CURRENT_REVISION)
+    """
+    if len(parents_lines) == 1:
+        for data in _reannotate(parents_lines[0], new_lines,
new_revision_id):
+            yield data
+    else:
+        reannotations = [list(_reannotate(p, new_lines,
new_revision_id)) for
+                         p in parents_lines]
+        for annos in zip(*reannotations):
+            origins = set(a for a, l in annos)
+            line = annos[0][1]
+            if len(origins) == 1:
+                yield iter(origins).next(), line
+            elif len(origins) == 2 and new_revision_id in origins:
+                yield (x for x in origins if x !=
new_revision_id).next(), line
+            else:
+                yield new_revision_id, line
+
+
+def _reannotate(parent_lines, new_lines, new_revision_id):
+    plain_parent_lines = [l for r, l in parent_lines]
+    import patiencediff


v- At the very least, I think this line is bogus.

+    patiencediff.PatienceSequenceMatcher()
+    matcher = patiencediff.PatienceSequenceMatcher(None,
plain_parent_lines,
+                                                   new_lines)
+    new_cur = 0
+    for i, j, n in matcher.get_matching_blocks():
+        for line in new_lines[new_cur:j]:
+            yield new_revision_id, line
+        for data in parent_lines[i:i+n]:
+            yield data
+        new_cur = j + n

So, conditional +1, I'll update BB.

John
=:->





More information about the bazaar mailing list