/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/plugins/rewrite/upgrade.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2009 by Jelmer Vernooij
 
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 3 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
"""Upgrading revisions made with older versions of the mapping."""
 
19
 
 
20
from ... import (
 
21
    osutils,
 
22
    trace,
 
23
    ui,
 
24
    )
 
25
from ...errors import (
 
26
    BzrError,
 
27
    )
 
28
from .rebase import (
 
29
    generate_transpose_plan,
 
30
    CommitBuilderRevisionRewriter,
 
31
    rebase,
 
32
    rebase_todo,
 
33
    )
 
34
 
 
35
 
 
36
class UpgradeChangesContent(BzrError):
 
37
    """Inconsistency was found upgrading the mapping of a revision."""
 
38
    _fmt = """Upgrade will change contents in revision %(revid)s. Use --allow-changes to override."""
 
39
 
 
40
    def __init__(self, revid):
 
41
        self.revid = revid
 
42
 
 
43
 
 
44
def create_deterministic_revid(revid, new_parents):
 
45
    """Create a new deterministic revision id with specified new parents.
 
46
 
 
47
    Prevents suffix to be appended needlessly.
 
48
 
 
49
    :param revid: Original revision id.
 
50
    :return: New revision id
 
51
    """
 
52
    if "-rebase-" in revid:
 
53
        revid = revid[0:revid.rfind("-rebase-")]
 
54
    return revid + "-rebase-" + osutils.sha_string(":".join(new_parents))[:8]
 
55
 
 
56
 
 
57
def upgrade_tags(tags, repository, generate_rebase_map, determine_new_revid,
 
58
                 allow_changes=False, verbose=False, branch_renames=None,
 
59
                 branch_ancestry=None):
 
60
    """Upgrade a tags dictionary."""
 
61
    renames = {}
 
62
    if branch_renames is not None:
 
63
        renames.update(branch_renames)
 
64
    pb = ui.ui_factory.nested_progress_bar()
 
65
    try:
 
66
        tags_dict = tags.get_tag_dict()
 
67
        for i, (name, revid) in enumerate(tags_dict.iteritems()):
 
68
            pb.update("upgrading tags", i, len(tags_dict))
 
69
            if revid not in renames:
 
70
                try:
 
71
                    repository.lock_read()
 
72
                    revid_exists = repository.has_revision(revid)
 
73
                finally:
 
74
                    repository.unlock()
 
75
                if revid_exists:
 
76
                    renames.update(upgrade_repository(
 
77
                        repository,
 
78
                        generate_rebase_map, determine_new_revid,
 
79
                        revision_id=revid, allow_changes=allow_changes,
 
80
                        verbose=verbose))
 
81
            if (revid in renames and
 
82
                    (branch_ancestry is None or revid not in branch_ancestry)):
 
83
                tags.set_tag(name, renames[revid])
 
84
    finally:
 
85
        pb.finished()
 
86
 
 
87
 
 
88
def upgrade_branch(branch, generate_rebase_map, determine_new_revid,
 
89
                   allow_changes=False, verbose=False):
 
90
    """Upgrade a branch to the current mapping version.
 
91
 
 
92
    :param branch: Branch to upgrade.
 
93
    :param foreign_repository: Repository to fetch new revisions from
 
94
    :param allow_changes: Allow changes in mappings.
 
95
    :param verbose: Whether to print verbose list of rewrites
 
96
    """
 
97
    revid = branch.last_revision()
 
98
    renames = upgrade_repository(
 
99
        branch.repository, generate_rebase_map,
 
100
        determine_new_revid, revision_id=revid,
 
101
        allow_changes=allow_changes, verbose=verbose)
 
102
    if revid in renames:
 
103
        branch.generate_revision_history(renames[revid])
 
104
    ancestry = branch.repository.get_ancestry(
 
105
        branch.last_revision(), topo_sorted=False)
 
106
    upgrade_tags(
 
107
        branch.tags, branch.repository, generate_rebase_map,
 
108
        determine_new_revid, allow_changes=allow_changes, verbose=verbose,
 
109
        branch_renames=renames, branch_ancestry=ancestry)
 
110
    return renames
 
111
 
 
112
 
 
113
def check_revision_changed(oldrev, newrev):
 
114
    """Check if two revisions are different. This is exactly the same
 
115
    as Revision.equals() except that it does not check the revision_id."""
 
116
    if (newrev.inventory_sha1 != oldrev.inventory_sha1 or
 
117
            newrev.timestamp != oldrev.timestamp or
 
118
            newrev.message != oldrev.message or
 
119
            newrev.timezone != oldrev.timezone or
 
120
            newrev.committer != oldrev.committer or
 
121
            newrev.properties != oldrev.properties):
 
122
        raise UpgradeChangesContent(oldrev.revision_id)
 
123
 
 
124
 
 
125
def create_upgrade_plan(repository, generate_rebase_map, determine_new_revid,
 
126
                        revision_id=None, allow_changes=False):
 
127
    """Generate a rebase plan for upgrading revisions.
 
128
 
 
129
    :param repository: Repository to do upgrade in
 
130
    :param foreign_repository: Subversion repository to fetch new revisions
 
131
        from.
 
132
    :param new_mapping: New mapping to use.
 
133
    :param revision_id: Revision to upgrade (None for all revisions in
 
134
        repository.)
 
135
    :param allow_changes: Whether an upgrade is allowed to change the contents
 
136
        of revisions.
 
137
    :return: Tuple with a rebase plan and map of renamed revisions.
 
138
    """
 
139
 
 
140
    graph = repository.get_graph()
 
141
    upgrade_map = generate_rebase_map(revision_id)
 
142
 
 
143
    if not allow_changes:
 
144
        for oldrevid, newrevid in upgrade_map.iteritems():
 
145
            oldrev = repository.get_revision(oldrevid)
 
146
            newrev = repository.get_revision(newrevid)
 
147
            check_revision_changed(oldrev, newrev)
 
148
 
 
149
    if revision_id is None:
 
150
        heads = repository.all_revision_ids()
 
151
    else:
 
152
        heads = [revision_id]
 
153
 
 
154
    plan = generate_transpose_plan(
 
155
        graph.iter_ancestry(heads), upgrade_map, graph, determine_new_revid)
 
156
    def remove_parents(entry):
 
157
        (oldrevid, (newrevid, parents)) = entry
 
158
        return (oldrevid, newrevid)
 
159
    upgrade_map.update(dict(map(remove_parents, plan.iteritems())))
 
160
 
 
161
    return (plan, upgrade_map)
 
162
 
 
163
 
 
164
def upgrade_repository(repository, generate_rebase_map,
 
165
                       determine_new_revid, revision_id=None,
 
166
                       allow_changes=False, verbose=False):
 
167
    """Upgrade the revisions in repository until the specified stop revision.
 
168
 
 
169
    :param repository: Repository in which to upgrade.
 
170
    :param foreign_repository: Repository to fetch new revisions from.
 
171
    :param new_mapping: New mapping.
 
172
    :param revision_id: Revision id up until which to upgrade, or None for
 
173
                        all revisions.
 
174
    :param allow_changes: Allow changes to mappings.
 
175
    :param verbose: Whether to print list of rewrites
 
176
    :return: Dictionary of mapped revisions
 
177
    """
 
178
    # Find revisions that need to be upgraded, create
 
179
    # dictionary with revision ids in key, new parents in value
 
180
    with repository.lock_write():
 
181
        (plan, revid_renames) = create_upgrade_plan(
 
182
            repository, generate_rebase_map, determine_new_revid,
 
183
            revision_id=revision_id, allow_changes=allow_changes)
 
184
        if verbose:
 
185
            for revid in rebase_todo(repository, plan):
 
186
                trace.note("%s -> %s" % (revid, plan[revid][0]))
 
187
        rebase(repository, plan, CommitBuilderRevisionRewriter(repository))
 
188
        return revid_renames