/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 push.py

  • Committer: Jelmer Vernooij
  • Date: 2018-04-02 14:59:43 UTC
  • mto: (0.200.1913 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180402145943-s5jmpbvvf1x42pao
Just don't touch the URL if it's already a valid URL.

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
 
 
22
class MissingObjectsIterator(object):
 
23
    """Iterate over git objects that are missing from a target repository.
 
24
 
 
25
    """
 
26
 
 
27
    def __init__(self, store, source, pb=None):
 
28
        """Create a new missing objects iterator.
 
29
 
 
30
        """
 
31
        self.source = source
 
32
        self._object_store = store
 
33
        self._pending = []
 
34
        self.pb = pb
 
35
 
 
36
    def import_revisions(self, revids, lossy):
 
37
        """Import a set of revisions into this git repository.
 
38
 
 
39
        :param revids: Revision ids of revisions to import
 
40
        :param lossy: Whether to not roundtrip bzr metadata
 
41
        """
 
42
        for i, revid in enumerate(revids):
 
43
            if self.pb:
 
44
                self.pb.update("pushing revisions", i, len(revids))
 
45
            git_commit = self.import_revision(revid, lossy)
 
46
            yield (revid, git_commit)
 
47
 
 
48
    def import_revision(self, revid, lossy):
 
49
        """Import a revision into this Git repository.
 
50
 
 
51
        :param revid: Revision id of the revision
 
52
        :param roundtrip: Whether to roundtrip bzr metadata
 
53
        """
 
54
        tree = self._object_store.tree_cache.revision_tree(revid)
 
55
        rev = self.source.get_revision(revid)
 
56
        commit = None
 
57
        for path, obj, ie in self._object_store._revision_to_objects(rev, tree, lossy):
 
58
            if obj.type_name == "commit":
 
59
                commit = obj
 
60
            self._pending.append((obj, path))
 
61
        if commit is None:
 
62
            raise AssertionError("no commit object generated for revision %s" %
 
63
                revid)
 
64
        return commit.id
 
65
 
 
66
    def __len__(self):
 
67
        return len(self._pending)
 
68
 
 
69
    def __iter__(self):
 
70
        return iter(self._pending)
 
71
 
 
72
 
 
73
class ObjectStoreParentsProvider(object):
 
74
 
 
75
    def __init__(self, store):
 
76
        self._store = store
 
77
 
 
78
    def get_parent_map(self, shas):
 
79
        ret = {}
 
80
        for sha in shas:
 
81
            if sha is None:
 
82
                parents = []
 
83
            else:
 
84
                try:
 
85
                    parents = self._store[sha].parents
 
86
                except KeyError:
 
87
                    parents = None
 
88
            ret[sha] = parents
 
89
        return ret
 
90
 
 
91
 
 
92
def remote_divergence(old_sha, new_sha, store):
 
93
    if old_sha is None:
 
94
        return False
 
95
    if not isinstance(old_sha, bytes):
 
96
        raise TypeError(old_sha)
 
97
    if not isinstance(new_sha, bytes):
 
98
        raise TypeError(new_sha)
 
99
    from breezy.graph import Graph
 
100
    graph = Graph(ObjectStoreParentsProvider(store))
 
101
    return not graph.is_ancestor(old_sha, new_sha)