def iter_changes(self, branch_path, from_revnum, to_revnum, pb=None, limit=0): """Iterate over all revisions backwards. :return: iterator that returns tuples with branch path, changed paths, revision number, changed file properties and """ assert from_revnum >= to_revnum assert isinstance(branch_path, text_type) bp = branch_path i = 0 # Limit can't be passed on directly to LogWalker.iter_changes() # because we're skipping some revs # TODO: Rather than fetching everything if limit == 2, maybe just # set specify an extra X revs just to be sure? for (paths, revnum, revprops) in self._log.iter_changes([branch_path], from_revnum, to_revnum, pb=pb): assert bp is not None next = changes.find_prev_location(paths, bp, revnum) assert revnum > 0 or bp == u"" if changes.changes_path(paths, bp, False): yield (bp, paths, revnum, revprops) i += 1 if next is None: bp = None else: bp = next[0]
def iter_prefixes_changes(from_prefixes, from_revnum, to_revnum, get_revision_paths, revprop_list, limit=0): assert type(from_prefixes) is set from_prefixes = set([p.strip(u"/") for p in from_prefixes]) assert from_revnum >= to_revnum, "path: %r, %d >= %d" % ( from_prefixes, from_revnum, to_revnum) revnum = from_revnum todo_prefixes = { revnum: from_prefixes } i = 0 while revnum >= to_revnum: prefixes = todo_prefixes.pop(revnum) revpaths = get_revision_paths(revnum) assert all(isinstance(p, text_type) for p in revpaths) # Report this revision if any affected paths are changed if any(changes.changes_path(revpaths, prefix, True) for prefix in prefixes): assert isinstance(revnum, int) yield (revpaths, revnum, revprop_list(revnum)) i += 1 if limit != 0 and i == limit: break next = {} # Find the location of each prefix for the next iteration for prefix in prefixes: if not isinstance(prefix, text_type): raise TypeError(prefix) try: (p, r) = changes.find_prev_location(revpaths, prefix, revnum) except TypeError: pass # didn't exist here else: assert r < revnum todo_prefixes.setdefault(r, set()).add(p) if todo_prefixes == {}: break revnum = max(todo_prefixes)
def test_parentcopy(self): self.assertEquals((u"foo/bla", 3), find_prev_location({u"bar": ("A", u"foo", 3)}, u"bar/bla", 5))
def test_from_root(self): self.assertEquals((u"tools", 3), find_prev_location({u"trunk": ("A", u"", 3)}, u"trunk/tools", 5))
def test_rootchange(self): self.assertEquals((u"", 4), find_prev_location({}, u"", 5))
def test_endofhistory(self): self.assertEquals(None, find_prev_location({}, u"", 0))
def test_simple_prev_replaced(self): self.assertEquals(("bar", 1), find_prev_location({u"foo": ("R", u"bar", 1)}, u"foo", 2))
def test_simple_prev_notchanged(self): self.assertEquals(("foo", 1), find_prev_location({}, u"foo", 2))
def test_simple_prev_changed(self): self.assertEquals((u"foo", 1), find_prev_location({u"foo": ("M", None, -1)}, u"foo", 2))