Exemple #1
0
    def run(self, destination=None, remember=False, overwrite=False):
        from repopush import repo_push

        # get the repository for the branch we're currently in
        bzrdir = BzrDir.open_containing('.')[0]
        try:
            branch = bzrdir.open_branch()
            src_repo = branch.repository
        except errors.NotBranchError:
            src_repo = bzrdir.open_repository()
        repo_config = LocationConfig(src_repo.bzrdir.root_transport.base)

        if destination is None:
            destination = repo_config.get_user_option('public_repository')
            if destination is None:
                raise errors.BzrCommandError('No destination specified')

        dst_repo = BzrDir.open(destination).open_repository()

        if remember or (repo_config.get_user_option('public_repository')
                        is None):
            repo_config.set_user_option('public_repository',
                                        dst_repo.bzrdir.root_transport.base)

        pb = ui_factory.nested_progress_bar()
        try:
            repo_push(src_repo, dst_repo, pb=pb, overwrite=overwrite)
        finally:
            pb.finished()
 def _find_missing_files(self, basis):
     missing_files = set()
     missing_parents = {}
     candidate_files = set()
     task = ui_factory.nested_progress_bar()
     iterator = self.tree.iter_changes(basis, want_unversioned=True,
                                       pb=task)
     try:
         for (file_id, paths, changed_content, versioned, parent, name,
              kind, executable) in iterator:
             if kind[1] is None and versioned[1]:
                 missing_parents.setdefault(parent[0], set()).add(file_id)
                 if kind[0] == 'file':
                     missing_files.add(file_id)
                 else:
                     #other kinds are not handled
                     pass
             if versioned == (False, False):
                 if self.tree.is_ignored(paths[1]):
                     continue
                 if kind[1] == 'file':
                     candidate_files.add(paths[1])
                 if kind[1] == 'directory':
                     for _dir, children in self.tree.walkdirs(paths[1]):
                         for child in children:
                             if child[2] == 'file':
                                 candidate_files.add(child[0])
     finally:
         task.finished()
     return missing_files, missing_parents, candidate_files
Exemple #3
0
 def _find_missing_files(self, basis):
     missing_files = set()
     missing_parents = {}
     candidate_files = set()
     task = ui_factory.nested_progress_bar()
     iterator = self.tree.iter_changes(basis,
                                       want_unversioned=True,
                                       pb=task)
     try:
         for (file_id, paths, changed_content, versioned, parent, name,
              kind, executable) in iterator:
             if kind[1] is None and versioned[1]:
                 missing_parents.setdefault(parent[0], set()).add(file_id)
                 if kind[0] == 'file':
                     missing_files.add(file_id)
                 else:
                     #other kinds are not handled
                     pass
             if versioned == (False, False):
                 if self.tree.is_ignored(paths[1]):
                     continue
                 if kind[1] == 'file':
                     candidate_files.add(paths[1])
                 if kind[1] == 'directory':
                     for _dir, children in self.tree.walkdirs(paths[1]):
                         for child in children:
                             if child[2] == 'file':
                                 candidate_files.add(child[0])
     finally:
         task.finished()
     return missing_files, missing_parents, candidate_files
Exemple #4
0
    def run(self, destination=None, remember=False, overwrite=False):
        from repopush import repo_push

        # get the repository for the branch we're currently in
        bzrdir = BzrDir.open_containing('.')[0]
        try:
            branch = bzrdir.open_branch()
            src_repo = branch.repository
        except errors.NotBranchError:
            src_repo = bzrdir.open_repository()
        repo_config = LocationConfig(src_repo.bzrdir.root_transport.base)

        if destination is None:
            destination = repo_config.get_user_option('public_repository')
            if destination is None:
                raise errors.BzrCommandError('No destination specified')

        dst_repo = BzrDir.open(destination).open_repository()

        if remember or (repo_config.get_user_option('public_repository') is
                        None):
            repo_config.set_user_option('public_repository',
                                        dst_repo.bzrdir.root_transport.base)

        pb = ui_factory.nested_progress_bar()
        try:
            repo_push(src_repo, dst_repo, pb=pb, overwrite=overwrite)
        finally:
            pb.finished()
    def get_all_hits(self, paths):
        """Find all the hit counts for the listed paths in the tree.

        :return: A list of tuples of count, path, file_id.
        """
        all_hits = []
        task = ui_factory.nested_progress_bar()
        try:
            for num, path in enumerate(paths):
                task.update(gettext('Determining hash hits'), num, len(paths))
                hits = self.hitcounts(self.tree.get_file_lines(None,
                                                               path=path))
                all_hits.extend((v, path, k) for k, v in hits.items())
        finally:
            task.finished()
        return all_hits
Exemple #6
0
    def get_all_hits(self, paths):
        """Find all the hit counts for the listed paths in the tree.

        :return: A list of tuples of count, path, file_id.
        """
        all_hits = []
        task = ui_factory.nested_progress_bar()
        try:
            for num, path in enumerate(paths):
                task.update(gettext('Determining hash hits'), num, len(paths))
                hits = self.hitcounts(self.tree.get_file_lines(None,
                                                               path=path))
                all_hits.extend((v, path, k) for k, v in hits.items())
        finally:
            task.finished()
        return all_hits
    def add_file_edge_hashes(self, tree, file_ids):
        """Update to reflect the hashes for files in the tree.

        :param tree: The tree containing the files.
        :param file_ids: A list of file_ids to perform the updates for.
        """
        desired_files = [(f, f) for f in file_ids]
        task = ui_factory.nested_progress_bar()
        try:
            for num, (file_id, contents) in enumerate(
                tree.iter_files_bytes(desired_files)):
                task.update(gettext('Calculating hashes'), num, len(file_ids))
                s = StringIO()
                s.writelines(contents)
                s.seek(0)
                self.add_edge_hashes(s.readlines(), file_id)
        finally:
            task.finished()
Exemple #8
0
    def add_file_edge_hashes(self, tree, file_ids):
        """Update to reflect the hashes for files in the tree.

        :param tree: The tree containing the files.
        :param file_ids: A list of file_ids to perform the updates for.
        """
        desired_files = [(f, f) for f in file_ids]
        task = ui_factory.nested_progress_bar()
        try:
            for num, (file_id, contents) in enumerate(
                    tree.iter_files_bytes(desired_files)):
                task.update(gettext('Calculating hashes'), num, len(file_ids))
                s = StringIO()
                s.writelines(contents)
                s.seek(0)
                self.add_edge_hashes(s.readlines(), file_id)
        finally:
            task.finished()
    def guess_renames(klass, tree, dry_run=False):
        """Guess which files to rename, and perform the rename.

        We assume that unversioned files and missing files indicate that
        versioned files have been renamed outside of Bazaar.

        :param tree: A write-locked working tree.
        """
        required_parents = {}
        task = ui_factory.nested_progress_bar()
        try:
            pp = progress.ProgressPhase('Guessing renames', 4, task)
            basis = tree.basis_tree()
            basis.lock_read()
            try:
                rn = klass(tree)
                pp.next_phase()
                missing_files, missing_parents, candidate_files = (
                    rn._find_missing_files(basis))
                pp.next_phase()
                rn.add_file_edge_hashes(basis, missing_files)
            finally:
                basis.unlock()
            pp.next_phase()
            matches = rn.file_match(candidate_files)
            parents_matches = matches
            while len(parents_matches) > 0:
                required_parents = rn.get_required_parents(
                    parents_matches)
                parents_matches = rn.match_parents(required_parents,
                                                   missing_parents)
                matches.update(parents_matches)
            pp.next_phase()
            delta = rn._make_inventory_delta(matches)
            for old, new, file_id, entry in delta:
                trace.note( gettext("{0} => {1}").format(old, new) )
            if not dry_run:
                tree.add(required_parents)
                tree.apply_inventory_delta(delta)
        finally:
            task.finished()
Exemple #10
0
    def guess_renames(klass, tree, dry_run=False):
        """Guess which files to rename, and perform the rename.

        We assume that unversioned files and missing files indicate that
        versioned files have been renamed outside of Bazaar.

        :param tree: A write-locked working tree.
        """
        required_parents = {}
        task = ui_factory.nested_progress_bar()
        try:
            pp = progress.ProgressPhase('Guessing renames', 4, task)
            basis = tree.basis_tree()
            basis.lock_read()
            try:
                rn = klass(tree)
                pp.next_phase()
                missing_files, missing_parents, candidate_files = (
                    rn._find_missing_files(basis))
                pp.next_phase()
                rn.add_file_edge_hashes(basis, missing_files)
            finally:
                basis.unlock()
            pp.next_phase()
            matches = rn.file_match(candidate_files)
            parents_matches = matches
            while len(parents_matches) > 0:
                required_parents = rn.get_required_parents(parents_matches)
                parents_matches = rn.match_parents(required_parents,
                                                   missing_parents)
                matches.update(parents_matches)
            pp.next_phase()
            delta = rn._make_inventory_delta(matches)
            for old, new, file_id, entry in delta:
                trace.note(gettext("{0} => {1}").format(old, new))
            if not dry_run:
                tree.add(required_parents)
                tree.apply_inventory_delta(delta)
        finally:
            task.finished()