/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
16
17
"""Push implementation that simply prints message saying push is not supported."""
18
0.200.1594 by Jelmer Vernooij
Use absolute_import everywhere.
19
from __future__ import absolute_import
20
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
21
22
class MissingObjectsIterator(object):
23
    """Iterate over git objects that are missing from a target repository.
24
25
    """
26
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
27
    def __init__(self, store, source, pb=None):
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
28
        """Create a new missing objects iterator.
29
30
        """
31
        self.source = source
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
32
        self._object_store = store
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
33
        self._pending = []
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
34
        self.pb = pb
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
35
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
36
    def import_revisions(self, revids, lossy):
0.200.947 by Jelmer Vernooij
Add convenience method for getting missing objects iterator.
37
        """Import a set of revisions into this git repository.
38
39
        :param revids: Revision ids of revisions to import
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
40
        :param lossy: Whether to not roundtrip bzr metadata
0.200.947 by Jelmer Vernooij
Add convenience method for getting missing objects iterator.
41
        """
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
42
        for i, revid in enumerate(revids):
43
            if self.pb:
44
                self.pb.update("pushing revisions", i, len(revids))
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
45
            git_commit = self.import_revision(revid, lossy)
0.252.6 by Jelmer Vernooij
Roundtripping support for revision ids works.
46
            yield (revid, git_commit)
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
47
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
48
    def import_revision(self, revid, lossy):
0.200.947 by Jelmer Vernooij
Add convenience method for getting missing objects iterator.
49
        """Import a revision into this Git repository.
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
50
0.200.947 by Jelmer Vernooij
Add convenience method for getting missing objects iterator.
51
        :param revid: Revision id of the revision
52
        :param roundtrip: Whether to roundtrip bzr metadata
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
53
        """
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
54
        tree = self._object_store.tree_cache.revision_tree(revid)
0.200.548 by Jelmer Vernooij
Extract unusual file modes from revision when reconstructing Trees.
55
        rev = self.source.get_revision(revid)
0.200.784 by Jelmer Vernooij
Use common object generation code in push.
56
        commit = None
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
57
        for path, obj, ie in self._object_store._revision_to_objects(rev, tree, lossy):
0.200.829 by Jelmer Vernooij
Cope with the fact that _type is gone in upstream dulwich.
58
            if obj.type_name == "commit":
0.200.784 by Jelmer Vernooij
Use common object generation code in push.
59
                commit = obj
0.200.786 by Jelmer Vernooij
Simplify push code.
60
            self._pending.append((obj, path))
0.200.1482 by Jelmer Vernooij
Add extra assertion.
61
        if commit is None:
62
            raise AssertionError("no commit object generated for revision %s" %
63
                revid)
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
64
        return commit.id
65
66
    def __len__(self):
67
        return len(self._pending)
68
69
    def __iter__(self):
0.200.786 by Jelmer Vernooij
Simplify push code.
70
        return iter(self._pending)