Rev 3888: Add a trival (hence buggy :-/) --deep implementation. in file:///net/bigmamac/Volumes/home/vila/src/bzr/cases/3232-spurious-conflict/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Dec 11 15:41:04 GMT 2008


At file:///net/bigmamac/Volumes/home/vila/src/bzr/cases/3232-spurious-conflict/

------------------------------------------------------------
revno: 3888
revision-id: v.ladeuil+lp at free.fr-20081211154102-q4u21mv965375zak
parent: v.ladeuil+lp at free.fr-20081211112546-z3mkqn46dljpe95v
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: log-deep
timestamp: Thu 2008-12-11 16:41:02 +0100
message:
  Add a trival (hence buggy :-/) --deep implementation.
  
  * bzrlib/tests/blackbox/test_log.py:
  (TestLogFileDeep.setUp): Add a file deletion.
  (TestLogFileDeep.test_log_old_file_not_deep,
  TestLogFileDeep.test_log_old_file_deep): New tests.
  
  * bzrlib/log.py:
  (show_log, _show_log): Add a *private* _path_filter parameter.
  (_show_log): Simple-minded-passing-superficial tests
  implementation of revision filtering by path.
  
  * bzrlib/builtins.py:
  (cmd_log.run): Allow file to be unknown in tip when using --deep.
  Reuse delta_filter as  a path_filter for show_log.
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-12-11 11:16:04 +0000
+++ b/bzrlib/builtins.py	2008-12-11 15:41:02 +0000
@@ -1826,6 +1826,9 @@
         # log everything
         specific_file_id = None
         specific_file_path = None
+        # TODO: interpreting 'location' should be reworked to allow several
+        # files to be specified while still allowing the first one to be,
+        # optionally, a branch.
         if location:
             # find the file id to log:
 
@@ -1834,11 +1837,12 @@
             if fp != '':
                 if tree is None:
                     tree = b.basis_tree()
-                specific_file_id = tree.path2id(fp)
-                if specific_file_id is None:
-                    raise errors.BzrCommandError(
-                        "Path does not have any revision history: %s" %
-                        location)
+                if not deep:
+                    specific_file_id = tree.path2id(fp)
+                    if specific_file_id is None:
+                        raise errors.BzrCommandError(
+                            "Path does not have any revision history: %s" %
+                            location)
                 specific_file_path = fp
         else:
             # local dir only
@@ -1875,20 +1879,23 @@
             if log_format is None:
                 log_format = log.log_formatter_registry.get_default(b)
 
-            if specific_file_id is None:
+            if specific_file_id or specific_file_path:
+                if deep:
+                    def only_that_file(path, file_id):
+                        return path == specific_file_path
+                    # the specific file id doesn't apply anymore
+                    specific_file_id = None
+                    _path_filter = only_that_file
+                else:
+                    def only_that_file(path, file_id):
+                        return file_id == specific_file_id
+                    _path_filter = None
+                delta_filter = only_that_file
+            else:
                 delta_filter = None
                 if deep:
                     # FIXME: missing test
                     warning('No file specified, --deep ignored')
-            else:
-                if deep:
-                    def only_that_file(path, file_id):
-                        return path == specific_file_path
-                    specific_file_id = None # FIXME: Ugly
-                else:
-                    def only_that_file(path, file_id):
-                        return file_id == specific_file_id
-                delta_filter = only_that_file
 
             lf = log_format(show_ids=show_ids, to_file=self.outf,
                             show_timezone=timezone,
@@ -1903,7 +1910,8 @@
                      start_revision=rev1,
                      end_revision=rev2,
                      search=message,
-                     limit=limit)
+                     limit=limit,
+                     _path_filter=_path_filter)
         finally:
             b.unlock()
 

=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2008-12-11 11:16:04 +0000
+++ b/bzrlib/log.py	2008-12-11 15:41:02 +0000
@@ -117,7 +117,8 @@
             # deleted here
             yield revno, revision_id, "deleted " + last_path
         elif this_path != last_path:
-            yield revno, revision_id, ("renamed %s => %s" % (last_path, this_path))
+            yield revno, revision_id, ("renamed %s => %s"
+                                       % (last_path, this_path))
         elif (this_ie.text_size != last_ie.text_size
               or this_ie.text_sha1 != last_ie.text_sha1):
             yield revno, revision_id, "modified " + this_path
@@ -144,7 +145,8 @@
              start_revision=None,
              end_revision=None,
              search=None,
-             limit=None):
+             limit=None,
+             _path_filter=None):
     """Write out human-readable log of commits to this branch.
 
     :param lf: The LogFormatter object showing the output.
@@ -166,6 +168,9 @@
 
     :param limit: If set, shows only 'limit' revisions, all revisions are shown
         if None or 0.
+
+    :param _path_filter: Private parameter. If not None, list only the commits
+        affecting the specified file, rather than all commits.
     """
     branch.lock_read()
     try:
@@ -173,7 +178,8 @@
             lf.begin_log()
 
         _show_log(branch, lf, specific_fileid, verbose, direction,
-                  start_revision, end_revision, search, limit)
+                  start_revision, end_revision, search, limit,
+                  _path_filter=_path_filter)
 
         if getattr(lf, 'end_log', None):
             lf.end_log()
@@ -189,7 +195,8 @@
              start_revision=None,
              end_revision=None,
              search=None,
-             limit=None):
+             limit=None,
+             _path_filter=None):
     """Worker function for show_log - see show_log."""
     if not isinstance(lf, LogFormatter):
         warn("not a LogFormatter instance: %r" % lf)
@@ -203,7 +210,8 @@
                                               end_revision, direction,
                                               specific_fileid,
                                               generate_merge_revisions,
-                                              allow_single_merge_revision)
+                                              allow_single_merge_revision,
+                                              _path_filter=_path_filter)
     rev_tag_dict = {}
     generate_tags = getattr(lf, 'supports_tags', False)
     if generate_tags:
@@ -215,9 +223,31 @@
     # now we just print all the revisions
     log_count = 0
     revision_iterator = make_log_rev_iterator(branch, view_revisions,
-        generate_delta, search)
+                                              (generate_delta
+                                               or _path_filter is not None),
+                                              search)
     for revs in revision_iterator:
         for (rev_id, revno, merge_depth), rev, delta in revs:
+            if _path_filter is not None:
+                matches = 0
+                for item in delta.added:
+                    if _path_filter(item[0], item[1]): matches += 1
+                for item in delta.removed:
+                    if _path_filter(item[0], item[1]): matches += 1
+                for item in delta.renamed:
+                    if _path_filter(item[0], item[1]): matches += 1
+                for item in delta.kind_changed:
+                    if _path_filter(item[0], item[1]): matches += 1
+                for item in delta.modified:
+                    if _path_filter(item[0], item[1]): matches += 1
+                for item in delta.renamed:
+                    if (_path_filter(item[0], item[2])
+                        or _path_filter(item[1], item[2])):
+                        matches += 1
+                if not matches:
+                    continue
+                if not generate_delta:
+                    delta = None
             lr = LogRevision(rev, revno, merge_depth, delta,
                              rev_tag_dict.get(rev_id))
             lf.log_revision(lr)
@@ -229,7 +259,8 @@
 
 def calculate_view_revisions(branch, start_revision, end_revision, direction,
                              specific_fileid, generate_merge_revisions,
-                             allow_single_merge_revision):
+                             allow_single_merge_revision,
+                             _path_filter=None):
     if (    not generate_merge_revisions
         and start_revision is end_revision is None
         and direction == 'reverse'
@@ -265,6 +296,10 @@
         view_revisions = _filter_revisions_touching_file_id(branch,
                                                             specific_fileid,
                                                             view_revisions)
+#    if _path_filter:
+#        view_revisions = _filter_revisions_touching_path(branch,
+#                                                         view_revisions,
+#                                                         _path_filter)
 
     # rebase merge_depth - unless there are no revisions or 
     # either the first or last revision have merge_depth = 0.
@@ -609,6 +644,28 @@
     return result
 
 
+#def _filter_revisions_touching_path(branch,view_revisions, filter):
+#   """Return the list of revision ids which touch paths matching filter.
+#
+#   :param branch: The branch where we can get text revision information.
+#
+#   :param view_revisions: A list of (revision_id, dotted_revno, merge_depth)
+#       tuples. This is the list of revisions which will be filtered. It is
+#       assumed that view_revisions is in merge_sort order (i.e. newest
+#       revision first ).
+#
+#   :return: A list of (revision_id, dotted_revno, merge_depth) tuples.
+#   """
+#    
+#    kept = []
+#    first = view_revisions[0]
+#    
+#    for revid, revno, depth in view_revisions[1:]:
+
+#       use iter_changes from previous revision to current and filter from a
+#       path list.
+    return view_revisions
+
 def get_view_revisions(mainline_revs, rev_nos, branch, direction,
                        include_merges=True):
     """Produce an iterator of revisions to show

=== modified file 'bzrlib/tests/blackbox/test_log.py'
--- a/bzrlib/tests/blackbox/test_log.py	2008-12-11 11:25:46 +0000
+++ b/bzrlib/tests/blackbox/test_log.py	2008-12-11 15:41:02 +0000
@@ -555,8 +555,9 @@
         wt.add(['f1', 'f2', 'dir'],
                ['f1-id', 'f2-id', 'dir-id'])
         wt.commit('commit one', rev_id='1', committer='joe')
+        wt.remove('f1')
         wt.remove('f2')
-        wt.commit('delete f2', rev_id='2', committer='joe')
+        wt.commit('delete f1 and f2', rev_id='2', committer='joe')
         self.build_tree_contents([('branch/f2', '2bis\n')])
         wt.add(['f2'], ['f2-id-bis'])
         wt.commit('add f2 again', rev_id='3', committer='joe')
@@ -577,7 +578,17 @@
         # revno 2 appears and mentions deleting f2
         self.assertNotContainsRe(log, '(?sm)^ +2 joe.*D f2\n')
 
+    def test_log_old_file_not_deep(self):
+        # Without deep, we can't query an old file
+        log = self.run_bzr(['log', '-v', 'f1'], retcode=3)[0]
+
+    def test_log_old_file_deep(self):
+        log = self.run_bzr(['log', '-v', '--short', '--deep', 'f1'])[0]
+        # revnos 1 and 2 appear and mention adding and deleting f1
+        self.assertContainsRe(log, '(?sm)^ +2 joe.*D  f1\n.*^ +1 joe.*A  f1\n')
+        self.assertNotContainsRe(log, '(?sm)^ +3 joe')
+
+
 # tests for:
-# --deep accept file not existing anymore
-# --deep filter revisions not mentionning file
 # --deep warning if no file specified
+# -- filter out already merged revisions a la _filter_revisions_touching_file_id



More information about the bazaar-commits mailing list