Rev 2835: annotate.py code cleanups (Ian Clatworthy) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Sep 20 01:57:45 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2835
revision-id: pqm at pqm.ubuntu.com-20070920005743-h4qqzyty2apbhjta
parent: pqm at pqm.ubuntu.com-20070919153217-w7hwnvh6v3wg6p8g
parent: ian.clatworthy at internode.on.net-20070919234756-btxjnvwq0qrsvnsb
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2007-09-20 01:57:43 +0100
message:
  annotate.py code cleanups (Ian Clatworthy)
modified:
  bzrlib/annotate.py             annotate.py-20050922133147-7c60541d2614f022
    ------------------------------------------------------------
    revno: 2834.1.1
    merged: ian.clatworthy at internode.on.net-20070919234756-btxjnvwq0qrsvnsb
    parent: pqm at pqm.ubuntu.com-20070919153217-w7hwnvh6v3wg6p8g
    parent: ian.clatworthy at internode.on.net-20070919081541-d6ivbn32hnx9i6dn
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: ianc-integration
    timestamp: Thu 2007-09-20 09:47:56 +1000
    message:
      annotate.py code cleanups (Ian Clatworthy)
    ------------------------------------------------------------
    revno: 2831.3.1
    merged: ian.clatworthy at internode.on.net-20070919081541-d6ivbn32hnx9i6dn
    parent: pqm at pqm.ubuntu.com-20070918045733-es6jch43pxvogvhj
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: bzr.annotate
    timestamp: Wed 2007-09-19 18:15:41 +1000
    message:
      code cleanups for annotate.py
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py	2007-08-31 19:38:52 +0000
+++ b/bzrlib/annotate.py	2007-09-19 08:15:41 +0000
@@ -42,12 +42,10 @@
     if to_file is None:
         to_file = sys.stdout
 
-    prevanno=''
+    # Handle the show_ids case
     last_rev_id = None
     if show_ids:
-        w = branch.repository.weave_store.get_weave(file_id,
-            branch.repository.get_transaction())
-        annotations = list(w.annotate_iter(rev_id))
+        annotations = _annotations(branch.repository, file_id, rev_id)
         max_origin_len = max(len(origin) for origin, text in annotations)
         for origin, text in annotations:
             if full or last_rev_id != origin:
@@ -58,6 +56,7 @@
             last_rev_id = origin
         return
 
+    # Calculate the lengths of the various columns
     annotation = list(_annotate_file(branch, rev_id, file_id))
     if len(annotation) == 0:
         max_origin_len = max_revno_len = max_revid_len = 0
@@ -65,11 +64,14 @@
         max_origin_len = max(len(x[1]) for x in annotation)
         max_revno_len = max(len(x[0]) for x in annotation)
         max_revid_len = max(len(x[3]) for x in annotation)
-
     if not verbose:
         max_revno_len = min(max_revno_len, 12)
     max_revno_len = max(max_revno_len, 3)
 
+    # Output the annotations
+    prevanno = ''
+    encoding = getattr(to_file, 'encoding', None) or \
+            osutils.get_terminal_encoding()
     for (revno_str, author, date_str, line_rev_id, text) in annotation:
         if verbose:
             anno = '%-*s %-*s %8s ' % (max_revno_len, revno_str,
@@ -78,8 +80,8 @@
             if len(revno_str) > max_revno_len:
                 revno_str = revno_str[:max_revno_len-1] + '>'
             anno = "%-*s %-7s " % (max_revno_len, revno_str, author[:7])
-
-        if anno.lstrip() == "" and full: anno = prevanno
+        if anno.lstrip() == "" and full:
+            anno = prevanno
         try:
             to_file.write(anno)
         except UnicodeEncodeError:
@@ -89,11 +91,15 @@
             # a user function (non-scripting), so shouldn't die because of
             # unrepresentable annotation characters. So encode using 'replace',
             # and write them again.
-            encoding = getattr(to_file, 'encoding', None) or \
-                    osutils.get_terminal_encoding()
             to_file.write(anno.encode(encoding, 'replace'))
         print >>to_file, '| %s' % (text,)
-        prevanno=anno
+        prevanno = anno
+
+
+def _annotations(repo, file_id, rev_id):
+    """Return the list of (origin,text) for a revision of a file in a repository."""
+    w = repo.weave_store.get_weave(file_id, repo.get_transaction())
+    return list(w.annotate_iter(rev_id))
 
 
 def _annotate_file(branch, rev_id, file_id):
@@ -103,10 +109,8 @@
     date string for the commit, rather than just the revision id.
     """
     revision_id_to_revno = branch.get_revision_id_to_revno_map()
-    w = branch.repository.weave_store.get_weave(file_id,
-        branch.repository.get_transaction())
+    annotations = _annotations(branch.repository, file_id, rev_id)
     last_origin = None
-    annotations = list(w.annotate_iter(rev_id))
     revision_ids = set(o for o, t in annotations)
     revision_ids = [o for o in revision_ids if 
                     branch.repository.has_revision(o)]
@@ -173,11 +177,11 @@
 
 def _reannotate(parent_lines, new_lines, new_revision_id,
                 matching_blocks=None):
-    plain_parent_lines = [l for r, l in parent_lines]
-    matcher = patiencediff.PatienceSequenceMatcher(None, plain_parent_lines,
-                                                   new_lines)
     new_cur = 0
     if matching_blocks is None:
+        plain_parent_lines = [l for r, l in parent_lines]
+        matcher = patiencediff.PatienceSequenceMatcher(None,
+            plain_parent_lines, new_lines)
         matching_blocks = matcher.get_matching_blocks()
     for i, j, n in matching_blocks:
         for line in new_lines[new_cur:j]:




More information about the bazaar-commits mailing list