/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/push.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:26:22 UTC
  • mfrom: (7167.1.4 run-flake8)
  • Revision ID: breezy.the.bot@gmail.com-20181116182622-qw3gan3hz78a2imw
Add a flake8 test.

Merged from https://code.launchpad.net/~jelmer/brz/run-flake8/+merge/358902

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Push implementation that simply prints message saying push is not supported."""
 
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from ..push import (
 
22
    PushResult,
 
23
    )
 
24
from .errors import (
 
25
    GitSmartRemoteNotSupported,
 
26
    )
 
27
 
 
28
class GitPushResult(PushResult):
 
29
 
 
30
    def _lookup_revno(self, revid):
 
31
        from .branch import _quick_lookup_revno
 
32
        try:
 
33
            return _quick_lookup_revno(self.source_branch, self.target_branch,
 
34
                revid)
 
35
        except GitSmartRemoteNotSupported:
 
36
            return None
 
37
 
 
38
    @property
 
39
    def old_revno(self):
 
40
        return self._lookup_revno(self.old_revid)
 
41
 
 
42
    @property
 
43
    def new_revno(self):
 
44
        return self._lookup_revno(self.new_revid)
 
45
 
 
46
 
 
47
class MissingObjectsIterator(object):
 
48
    """Iterate over git objects that are missing from a target repository.
 
49
 
 
50
    """
 
51
 
 
52
    def __init__(self, store, source, pb=None):
 
53
        """Create a new missing objects iterator.
 
54
 
 
55
        """
 
56
        self.source = source
 
57
        self._object_store = store
 
58
        self._pending = []
 
59
        self.pb = pb
 
60
 
 
61
    def import_revisions(self, revids, lossy):
 
62
        """Import a set of revisions into this git repository.
 
63
 
 
64
        :param revids: Revision ids of revisions to import
 
65
        :param lossy: Whether to not roundtrip bzr metadata
 
66
        """
 
67
        for i, revid in enumerate(revids):
 
68
            if self.pb:
 
69
                self.pb.update("pushing revisions", i, len(revids))
 
70
            git_commit = self.import_revision(revid, lossy)
 
71
            yield (revid, git_commit)
 
72
 
 
73
    def import_revision(self, revid, lossy):
 
74
        """Import a revision into this Git repository.
 
75
 
 
76
        :param revid: Revision id of the revision
 
77
        :param roundtrip: Whether to roundtrip bzr metadata
 
78
        """
 
79
        tree = self._object_store.tree_cache.revision_tree(revid)
 
80
        rev = self.source.get_revision(revid)
 
81
        commit = None
 
82
        for path, obj in self._object_store._revision_to_objects(rev, tree, lossy):
 
83
            if obj.type_name == b"commit":
 
84
                commit = obj
 
85
            self._pending.append((obj, path))
 
86
        if commit is None:
 
87
            raise AssertionError("no commit object generated for revision %s" %
 
88
                revid)
 
89
        return commit.id
 
90
 
 
91
    def __len__(self):
 
92
        return len(self._pending)
 
93
 
 
94
    def __iter__(self):
 
95
        return iter(self._pending)
 
96
 
 
97
 
 
98
class ObjectStoreParentsProvider(object):
 
99
 
 
100
    def __init__(self, store):
 
101
        self._store = store
 
102
 
 
103
    def get_parent_map(self, shas):
 
104
        ret = {}
 
105
        for sha in shas:
 
106
            if sha is None:
 
107
                parents = []
 
108
            else:
 
109
                try:
 
110
                    parents = self._store[sha].parents
 
111
                except KeyError:
 
112
                    parents = None
 
113
            ret[sha] = parents
 
114
        return ret
 
115
 
 
116
 
 
117
def remote_divergence(old_sha, new_sha, store):
 
118
    if old_sha is None:
 
119
        return False
 
120
    if not isinstance(old_sha, bytes):
 
121
        raise TypeError(old_sha)
 
122
    if not isinstance(new_sha, bytes):
 
123
        raise TypeError(new_sha)
 
124
    from breezy.graph import Graph
 
125
    graph = Graph(ObjectStoreParentsProvider(store))
 
126
    return not graph.is_ancestor(old_sha, new_sha)