Rev 3943: Fix log --short/--line FILE (Ian Clatworthy, #317417) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jan 15 23:32:46 GMT 2009


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

------------------------------------------------------------
revno: 3943
revision-id: pqm at pqm.ubuntu.com-20090115233242-4bxyn4zcj2a0ksfk
parent: pqm at pqm.ubuntu.com-20090115163104-30i51kcr1zepm2f7
parent: ian.clatworthy at canonical.com-20090115225127-hbl4j2cgoy7zu2oz
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-01-15 23:32:42 +0000
message:
  Fix log --short/--line FILE (Ian Clatworthy, #317417)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
    ------------------------------------------------------------
    revno: 3942.1.1
    revision-id: ian.clatworthy at canonical.com-20090115225127-hbl4j2cgoy7zu2oz
    parent: pqm at pqm.ubuntu.com-20090115163104-30i51kcr1zepm2f7
    parent: ian.clatworthy at canonical.com-20090115140513-sm71yx8s9097xydu
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: ianc-integration
    timestamp: Fri 2009-01-16 08:51:27 +1000
    message:
      Fix log --short/--line FILE (Ian Clatworthy)
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
    ------------------------------------------------------------
    revno: 3940.1.5
    revision-id: ian.clatworthy at canonical.com-20090115140513-sm71yx8s9097xydu
    parent: ian.clatworthy at canonical.com-20090115090542-d0zhsdsiqai7gvs6
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: bzr.log-short-file-fix
    timestamp: Fri 2009-01-16 00:05:13 +1000
    message:
      feedback from vila
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
    ------------------------------------------------------------
    revno: 3940.1.4
    revision-id: ian.clatworthy at canonical.com-20090115090542-d0zhsdsiqai7gvs6
    parent: ian.clatworthy at canonical.com-20090115090244-1f13robbhi2fuvbk
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: bzr.log-short-file-fix
    timestamp: Thu 2009-01-15 19:05:42 +1000
    message:
      NEWS item
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3940.1.3
    revision-id: ian.clatworthy at canonical.com-20090115090244-1f13robbhi2fuvbk
    parent: ian.clatworthy at canonical.com-20090115090225-1dxxoyq13sauesr2
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: bzr.log-short-file-fix
    timestamp: Thu 2009-01-15 19:02:44 +1000
    message:
      fix code
    modified:
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
    ------------------------------------------------------------
    revno: 3940.1.2
    revision-id: ian.clatworthy at canonical.com-20090115090225-1dxxoyq13sauesr2
    parent: ian.clatworthy at canonical.com-20090115090142-vee2hsn6231i2sum
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: bzr.log-short-file-fix
    timestamp: Thu 2009-01-15 19:02:25 +1000
    message:
      add test
    modified:
      bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
    ------------------------------------------------------------
    revno: 3940.1.1
    revision-id: ian.clatworthy at canonical.com-20090115090142-vee2hsn6231i2sum
    parent: pqm at pqm.ubuntu.com-20090115073416-vnzvkab4dfesetj0
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: bzr.log-short-file-fix
    timestamp: Thu 2009-01-15 19:01:42 +1000
    message:
      support flags when asserting re's in tests
    modified:
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
=== modified file 'NEWS'
--- a/NEWS	2009-01-15 15:27:22 +0000
+++ b/NEWS	2009-01-15 22:51:27 +0000
@@ -31,6 +31,10 @@
 
   BUG FIXES:
 
+    * ``bzr log FILE`` now correctly shows mainline revisions merging
+      a change to FILE when the ``--short`` and ``--line`` log formats
+      are used. (Ian Clatworthy, #317417)
+
     * Fix a problem with CIFS client/server lag on Windows colliding with
       an invariant-per-process algorithm for generating AtomicFile names
       (Adrian Wilkins, #304023)

=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2009-01-07 12:34:10 +0000
+++ b/bzrlib/log.py	2009-01-15 14:05:13 +0000
@@ -251,8 +251,9 @@
             raise errors.BzrCommandError('Selected log formatter only supports'
                 ' mainline revisions.')
         generate_merge_revisions = generate_single_revision
+    include_merges = generate_merge_revisions or specific_fileid
     view_revs_iter = get_view_revisions(mainline_revs, rev_nos, branch,
-                          direction, include_merges=generate_merge_revisions)
+                          direction, include_merges=include_merges)
 
     if direction == 'reverse':
         start_rev_id, end_rev_id = end_rev_id, start_rev_id
@@ -263,8 +264,8 @@
         view_revisions = view_revisions[0:1]
     if specific_fileid:
         view_revisions = _filter_revisions_touching_file_id(branch,
-                                                            specific_fileid,
-                                                            view_revisions)
+            specific_fileid, view_revisions,
+            include_merges=generate_merge_revisions)
 
     # rebase merge_depth - unless there are no revisions or 
     # either the first or last revision have merge_depth = 0.
@@ -532,7 +533,8 @@
     return view_revisions
 
 
-def _filter_revisions_touching_file_id(branch, file_id, view_revisions):
+def _filter_revisions_touching_file_id(branch, file_id, view_revisions,
+    include_merges=True):
     r"""Return the list of revision ids which touch a given file id.
 
     The function filters view_revisions and returns a subset.
@@ -565,6 +567,8 @@
         assumed that view_revisions is in merge_sort order (i.e. newest
         revision first ).
 
+    :param include_merges: include merge revisions in the result or not
+
     :return: A list of (revision_id, dotted_revno, merge_depth) tuples.
     """
     # Lookup all possible text keys to determine which ones actually modified
@@ -604,8 +608,9 @@
             for idx in xrange(len(current_merge_stack)):
                 node = current_merge_stack[idx]
                 if node is not None:
-                    result.append(node)
-                    current_merge_stack[idx] = None
+                    if include_merges or node[2] == 0:
+                        result.append(node)
+                        current_merge_stack[idx] = None
     return result
 
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-01-09 06:00:28 +0000
+++ b/bzrlib/tests/__init__.py	2009-01-15 09:01:42 +0000
@@ -909,9 +909,9 @@
         if not s.endswith(suffix):
             raise AssertionError('string %r does not end with %r' % (s, suffix))
 
-    def assertContainsRe(self, haystack, needle_re):
+    def assertContainsRe(self, haystack, needle_re, flags=0):
         """Assert that a contains something matching a regular expression."""
-        if not re.search(needle_re, haystack):
+        if not re.search(needle_re, haystack, flags):
             if '\n' in haystack or len(haystack) > 60:
                 # a long string, format it in a more readable way
                 raise AssertionError(
@@ -921,9 +921,9 @@
                 raise AssertionError('pattern "%s" not found in "%s"'
                         % (needle_re, haystack))
 
-    def assertNotContainsRe(self, haystack, needle_re):
+    def assertNotContainsRe(self, haystack, needle_re, flags=0):
         """Assert that a does not match a regular expression"""
-        if re.search(needle_re, haystack):
+        if re.search(needle_re, haystack, flags):
             raise AssertionError('pattern "%s" found in "%s"'
                     % (needle_re, haystack))
 

=== modified file 'bzrlib/tests/blackbox/test_log.py'
--- a/bzrlib/tests/blackbox/test_log.py	2008-12-12 12:14:01 +0000
+++ b/bzrlib/tests/blackbox/test_log.py	2009-01-15 14:05:13 +0000
@@ -18,7 +18,7 @@
 
 """Black-box tests for bzr log."""
 
-import os
+import os, re
 
 from bzrlib import osutils
 from bzrlib.tests.blackbox import ExternalBase
@@ -515,8 +515,7 @@
         tree.bzrdir.destroy_workingtree()
         self.run_bzr('log tree/file')
 
-    def test_log_file(self):
-        """The log for a particular file should only list revs for that file"""
+    def prepare_tree(self):
         tree = self.make_branch_and_tree('parent')
         self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
         tree.add('file1')
@@ -531,6 +530,10 @@
         tree.merge_from_branch(child_tree.branch)
         tree.commit(message='merge child branch')
         os.chdir('parent')
+
+    def test_log_file(self):
+        """The log for a particular file should only list revs for that file"""
+        self.prepare_tree()
         log = self.run_bzr('log file1')[0]
         self.assertContainsRe(log, 'revno: 1\n')
         self.assertNotContainsRe(log, 'revno: 2\n')
@@ -573,3 +576,66 @@
         self.assertNotContainsRe(log, 'revno: 3\n')
         self.assertNotContainsRe(log, 'revno: 3.1.1\n')
         self.assertNotContainsRe(log, 'revno: 4\n')
+
+    def test_line_log_file(self):
+        """The line log for a file should only list relevant mainline revs"""
+        # Note: this also implicitly  covers the short logging case.
+        # We test using --line in preference to --short because matching
+        # revnos in the output of --line is more reliable.
+        self.prepare_tree()
+
+        # full history of file1
+        log = self.run_bzr('log --line file1')[0]
+        self.assertContainsRe(log, '^1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^4:', re.MULTILINE)
+
+        # full history of file2
+        log = self.run_bzr('log --line file2')[0]
+        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
+        self.assertContainsRe(log, '^2:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
+        self.assertContainsRe(log, '^4:', re.MULTILINE)
+
+        # full history of file3
+        log = self.run_bzr('log --line file3')[0]
+        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
+        self.assertContainsRe(log, '^3:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^4:', re.MULTILINE)
+
+        # file in a merge revision
+        log = self.run_bzr('log --line -r3.1.1 file2')[0]
+        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
+        self.assertContainsRe(log, '^3.1.1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^4:', re.MULTILINE)
+
+        # file in a mainline revision
+        log = self.run_bzr('log --line -r4 file2')[0]
+        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
+        self.assertContainsRe(log, '^4:', re.MULTILINE)
+
+        # file since a revision
+        log = self.run_bzr('log --line -r3.. file2')[0]
+        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
+        self.assertContainsRe(log, '^4:', re.MULTILINE)
+
+        # file up to a revision
+        log = self.run_bzr('log --line -r..3 file2')[0]
+        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
+        self.assertContainsRe(log, '^2:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
+        self.assertNotContainsRe(log, '^4:', re.MULTILINE)




More information about the bazaar-commits mailing list