def check(self): """ See if a folder's contents were modified or created. """ try: self.read_cache_file() local_branch = Branch.open_containing(self.folder)[0] remote_branch = Branch.open_containing(local_branch.get_parent())[0] if local_branch.get_parent() != None: self.remote_branch_label = local_branch.get_parent().replace("%7E", "~") self.local_extra, self.remote_extra = find_unmerged(local_branch, remote_branch) if len(self.local_extra) != 0: if int(self.local_extra[len(self.local_extra) - 1][0]) > self.local_branch_: self.actually_changed = True self.write_cache_file() if len(self.remote_extra) != 0: if int(self.remote_extra[len(self.remote_extra) - 1][0]) > self.remote_branch_: self.actually_changed = True self.write_cache_file() if not self.local_extra and not self.remote_extra: self.mark_as_read() else: self.set_error(_("No parent branch available, you will not be notified of differences and changes.")) except NotBranchError, e: self.set_error(str(e))
def check(self): """ See if a folder's contents were modified or created. """ try: self.read_cache_file() local_branch = Branch.open_containing(self.folder)[0] remote_branch = Branch.open_containing( local_branch.get_parent())[0] if local_branch.get_parent() != None: self.remote_branch_label = local_branch.get_parent().replace( "%7E", "~") self.local_extra, self.remote_extra = find_unmerged( local_branch, remote_branch) if len(self.local_extra) != 0: if int(self.local_extra[len(self.local_extra) - 1][0]) > self.local_branch_: self.actually_changed = True self.write_cache_file() if len(self.remote_extra) != 0: if int(self.remote_extra[len(self.remote_extra) - 1][0]) > self.remote_branch_: self.actually_changed = True self.write_cache_file() if not self.local_extra and not self.remote_extra: self.mark_as_read() else: self.set_error( _("No parent branch available, you will not be notified of differences and changes." )) except NotBranchError, e: self.set_error(str(e))
def assertUnmerged(self, local, remote, local_branch, remote_branch, restrict): """Check the output of find_unmerged_mainline_revisions""" local_extra, remote_extra = missing.find_unmerged( local_branch, remote_branch, restrict) self.assertEqual(local, local_extra) self.assertEqual(remote, remote_extra)
def __init__(self, local_branch, remote_branch): """ Initialize the Status window. """ super(MissingWindow, self).__init__(flags=Gtk.DialogFlags.MODAL) self.set_title("Missing Revisions") self.local_branch = local_branch self.remote_branch = remote_branch (self.local_extra, self.remote_extra) = find_unmerged( local_branch, remote_branch) self._create()
def _show_missing_revisions_branch(branch, outfile): """Show missing master revisions in branch.""" # Try with inaccessible branch ? master = branch.get_master_branch() if master: local_extra, remote_extra = find_unmerged(branch, master) if remote_extra: outfile.write('\n') outfile.write(('Branch is out of date: missing %d ' 'revision%s.\n') % (len(remote_extra), plural(len(remote_extra))))
def assertUnmerged(self, local, remote, local_branch, remote_branch, restrict='all', include_merged=False, backward=False, local_revid_range=None, remote_revid_range=None): """Check the output of find_unmerged_mainline_revisions""" local_extra, remote_extra = missing.find_unmerged( local_branch, remote_branch, restrict, include_merged=include_merged, backward=backward, local_revid_range=local_revid_range, remote_revid_range=remote_revid_range) self.assertEqual(local, local_extra) self.assertEqual(remote, remote_extra)
def _getUpstreamChangesets(self, sincerev): """ See what other revisions exist upstream and return them """ from bzrlib import version_info parent_branch = Branch.open(self.repository.repository) branch = self._working_tree.branch branch.lock_read() try: parent_branch.lock_read() try: if version_info > (1, 6): revisions = find_unmerged(branch, parent_branch, 'remote')[1] else: revisions = find_unmerged(branch, parent_branch)[1] self.log.info("Collecting %d missing changesets", len(revisions)) for id, revision in revisions: yield self._changesetFromRevision(parent_branch, revision) except: parent_branch.unlock() raise parent_branch.unlock() except: branch.unlock() raise branch.unlock() self.log.info("Fetching concrete changesets") branch.lock_write() try: branch.fetch(parent_branch) finally: branch.unlock()
def show_missing_xml(self, other_branch=None, reverse=False, mine_only=False, theirs_only=False, log_format=None, long=False, short=False, line=False, show_ids=False, verbose=False, this=False, other=False): """output missing info as xml""" if this: mine_only = this if other: theirs_only = other local_branch = Branch.open_containing(u".")[0] parent = local_branch.get_parent() if other_branch is None: other_branch = parent if other_branch is None: raise errors.BzrCommandError("No peer location known" " or specified.") display_url = urlutils.unescape_for_display(other_branch, self.outf.encoding) remote_branch = Branch.open(other_branch) if remote_branch.base == local_branch.base: remote_branch = local_branch local_branch.lock_read() try: remote_branch.lock_read() self.outf.write('<?xml version="1.0" encoding="%s"?>' % \ osutils.get_user_encoding()) self.outf.write('<missing>') try: self.outf.write('<last_location>' + display_url + \ '</last_location>') local_extra, remote_extra = find_unmerged(local_branch, remote_branch) if log_format is None: registry = log_formatter_registry log_format = registry.get_default(local_branch) if reverse is False: local_extra.reverse() remote_extra.reverse() if local_extra and not theirs_only: self.outf.write('<extra_revisions size="%d">' % len(local_extra)) if local_extra > 0: lf = log_format(to_file=self.outf, show_ids=show_ids, show_timezone='original') showlogs(self, iter_log_revisions(local_extra, local_branch.repository, verbose), lf) self.outf.write('</extra_revisions>') if remote_extra and not mine_only: self.outf.write('<missing_revisions size="%d">' % len(remote_extra)) if remote_extra > 0: lf = log_format(to_file=self.outf, show_ids=show_ids, show_timezone='original') showlogs(self, iter_log_revisions(remote_extra, remote_branch.repository, verbose), lf) self.outf.write('</missing_revisions>') if not remote_extra and not local_extra: status_code = 0 # self.outf.write("Branches are up to date.\n") else: status_code = 1 finally: remote_branch.unlock() finally: self.outf.write('</missing>') local_branch.unlock() if not status_code and parent is None and other_branch is not None: local_branch.lock_write() try: # handle race conditions - a parent might be set while we run. if local_branch.get_parent() is None: local_branch.set_parent(remote_branch.base) finally: local_branch.unlock() return status_code
def test_iter_log_revisions(self): base_tree = self.make_branch_and_tree('base') self.build_tree(['base/a']) base_tree.add(['a'], ['a-id']) base_tree.commit('add a', rev_id='b-1') child_tree = base_tree.bzrdir.sprout('child').open_workingtree() self.build_tree(['child/b']) child_tree.add(['b'], ['b-id']) child_tree.commit('adding b', rev_id='c-2') child_tree.remove(['a']) child_tree.commit('removing a', rev_id='c-3') self.build_tree_contents([('child/b', 'new contents for b\n')]) child_tree.commit('modifying b', rev_id='c-4') child_tree.rename_one('b', 'c') child_tree.commit('rename b=>c', rev_id='c-5') base_extra, child_extra = missing.find_unmerged(base_tree.branch, child_tree.branch) results = list(iter_log_revisions(base_extra, base_tree.branch.repository, verbose=True)) self.assertEqual([], results) results = list(iter_log_revisions(child_extra, child_tree.branch.repository, verbose=True)) self.assertEqual(4, len(results)) r0,r1,r2,r3 = results self.assertEqual([('2', 'c-2'), ('3', 'c-3'), ('4', 'c-4'), ('5', 'c-5'),], [(r.revno, r.rev.revision_id) for r in results]) delta0 = r0.delta self.assertNotEqual(None, delta0) self.assertEqual([('b', 'b-id', 'file')], delta0.added) self.assertEqual([], delta0.removed) self.assertEqual([], delta0.renamed) self.assertEqual([], delta0.modified) delta1 = r1.delta self.assertNotEqual(None, delta1) self.assertEqual([], delta1.added) self.assertEqual([('a', 'a-id', 'file')], delta1.removed) self.assertEqual([], delta1.renamed) self.assertEqual([], delta1.modified) delta2 = r2.delta self.assertNotEqual(None, delta2) self.assertEqual([], delta2.added) self.assertEqual([], delta2.removed) self.assertEqual([], delta2.renamed) self.assertEqual([('b', 'b-id', 'file', True, False)], delta2.modified) delta3 = r3.delta self.assertNotEqual(None, delta3) self.assertEqual([], delta3.added) self.assertEqual([], delta3.removed) self.assertEqual([('b', 'c', 'b-id', 'file', False, False)], delta3.renamed) self.assertEqual([], delta3.modified)
def assertUnmerged(self, expected, source, target, restrict='all', backward=False): unmerged = missing.find_unmerged(source, target, restrict=restrict, backward=backward) self.assertEqual(expected, unmerged)
def show_missing_xml(self, other_branch=None, reverse=False, mine_only=False, theirs_only=False, log_format=None, long=False, short=False, line=False, show_ids=False, verbose=False, this=False, other=False): """output missing info as xml""" if this: mine_only = this if other: theirs_only = other local_branch = Branch.open_containing(u".")[0] parent = local_branch.get_parent() if other_branch is None: other_branch = parent if other_branch is None: raise errors.BzrCommandError("No peer location known" " or specified.") display_url = urlutils.unescape_for_display(other_branch, self.outf.encoding) remote_branch = Branch.open(other_branch) if remote_branch.base == local_branch.base: remote_branch = local_branch local_branch.lock_read() try: remote_branch.lock_read() self.outf.write('<?xml version="1.0" encoding="%s"?>' % \ osutils.get_user_encoding()) self.outf.write('<missing>') try: self.outf.write('<last_location>' + display_url + \ '</last_location>') local_extra, remote_extra = find_unmerged(local_branch, remote_branch) if log_format is None: registry = log_formatter_registry log_format = registry.get_default(local_branch) if reverse is False: local_extra.reverse() remote_extra.reverse() if local_extra and not theirs_only: self.outf.write('<extra_revisions size="%d">' % len(local_extra)) if local_extra > 0: lf = log_format(to_file=self.outf, show_ids=show_ids, show_timezone='original') showlogs( self, iter_log_revisions(local_extra, local_branch.repository, verbose), lf) self.outf.write('</extra_revisions>') if remote_extra and not mine_only: self.outf.write('<missing_revisions size="%d">' % len(remote_extra)) if remote_extra > 0: lf = log_format(to_file=self.outf, show_ids=show_ids, show_timezone='original') showlogs( self, iter_log_revisions(remote_extra, remote_branch.repository, verbose), lf) self.outf.write('</missing_revisions>') if not remote_extra and not local_extra: status_code = 0 # self.outf.write("Branches are up to date.\n") else: status_code = 1 finally: remote_branch.unlock() finally: self.outf.write('</missing>') local_branch.unlock() if not status_code and parent is None and other_branch is not None: local_branch.lock_write() try: # handle race conditions - a parent might be set while we run. if local_branch.get_parent() is None: local_branch.set_parent(remote_branch.base) finally: local_branch.unlock() return status_code
def assertUnmerged(self, expected, source, target, restrict='all'): unmerged = missing.find_unmerged(source, target, restrict=restrict) self.assertEqual(expected, unmerged)