/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
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
17
"""Basic push implementation."""
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
18
0.200.1594 by Jelmer Vernooij
Use absolute_import everywhere.
19
from __future__ import absolute_import
20
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
21
from ..push import (
0.419.1 by Jelmer Vernooij
Simplify pushing to Git directories.
22
    PushResult,
23
    )
24
from .errors import (
25
    GitSmartRemoteNotSupported,
26
    )
27
7143.15.2 by Jelmer Vernooij
Run autopep8.
28
0.419.1 by Jelmer Vernooij
Simplify pushing to Git directories.
29
class GitPushResult(PushResult):
30
31
    def _lookup_revno(self, revid):
32
        from .branch import _quick_lookup_revno
33
        try:
34
            return _quick_lookup_revno(self.source_branch, self.target_branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
35
                                       revid)
0.419.1 by Jelmer Vernooij
Simplify pushing to Git directories.
36
        except GitSmartRemoteNotSupported:
37
            return None
38
39
    @property
40
    def old_revno(self):
41
        return self._lookup_revno(self.old_revid)
42
43
    @property
44
    def new_revno(self):
45
        return self._lookup_revno(self.new_revid)
46
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
47
48
class MissingObjectsIterator(object):
49
    """Iterate over git objects that are missing from a target repository.
50
51
    """
52
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
53
    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.
54
        """Create a new missing objects iterator.
55
56
        """
57
        self.source = source
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
58
        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.
59
        self._pending = []
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
60
        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.
61
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
62
    def import_revisions(self, revids, lossy):
0.200.947 by Jelmer Vernooij
Add convenience method for getting missing objects iterator.
63
        """Import a set of revisions into this git repository.
64
65
        :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.
66
        :param lossy: Whether to not roundtrip bzr metadata
0.200.947 by Jelmer Vernooij
Add convenience method for getting missing objects iterator.
67
        """
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
68
        for i, revid in enumerate(revids):
69
            if self.pb:
70
                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.
71
            git_commit = self.import_revision(revid, lossy)
0.252.6 by Jelmer Vernooij
Roundtripping support for revision ids works.
72
            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.
73
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
74
    def import_revision(self, revid, lossy):
0.200.947 by Jelmer Vernooij
Add convenience method for getting missing objects iterator.
75
        """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.
76
0.200.947 by Jelmer Vernooij
Add convenience method for getting missing objects iterator.
77
        :param revid: Revision id of the revision
78
        :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.
79
        """
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
80
        tree = self._object_store.tree_cache.revision_tree(revid)
0.200.548 by Jelmer Vernooij
Extract unusual file modes from revision when reconstructing Trees.
81
        rev = self.source.get_revision(revid)
0.200.784 by Jelmer Vernooij
Use common object generation code in push.
82
        commit = None
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
83
        for path, obj in self._object_store._revision_to_objects(
84
                rev, tree, lossy):
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
85
            if obj.type_name == b"commit":
0.200.784 by Jelmer Vernooij
Use common object generation code in push.
86
                commit = obj
0.200.786 by Jelmer Vernooij
Simplify push code.
87
            self._pending.append((obj, path))
0.200.1482 by Jelmer Vernooij
Add extra assertion.
88
        if commit is None:
89
            raise AssertionError("no commit object generated for revision %s" %
7143.15.2 by Jelmer Vernooij
Run autopep8.
90
                                 revid)
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
91
        return commit.id
92
93
    def __len__(self):
94
        return len(self._pending)
95
96
    def __iter__(self):
0.200.786 by Jelmer Vernooij
Simplify push code.
97
        return iter(self._pending)
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
98
99
100
class ObjectStoreParentsProvider(object):
101
102
    def __init__(self, store):
103
        self._store = store
104
105
    def get_parent_map(self, shas):
106
        ret = {}
107
        for sha in shas:
108
            if sha is None:
109
                parents = []
110
            else:
111
                try:
112
                    parents = self._store[sha].parents
113
                except KeyError:
114
                    parents = None
115
            ret[sha] = parents
116
        return ret
117
118
119
def remote_divergence(old_sha, new_sha, store):
120
    if old_sha is None:
121
        return False
122
    if not isinstance(old_sha, bytes):
123
        raise TypeError(old_sha)
124
    if not isinstance(new_sha, bytes):
125
        raise TypeError(new_sha)
126
    from breezy.graph import Graph
127
    graph = Graph(ObjectStoreParentsProvider(store))
128
    return not graph.is_ancestor(old_sha, new_sha)