1
# Copyright (C) 2005 by Canonical Ltd
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.
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.
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
21
from bzrlib.trace import mutter, note
22
from bzrlib.branch import Branch
23
from bzrlib.progress import ProgressBar
25
def has_revision(branch, revision_id):
27
branch.get_revision_xml(revision_id)
29
except bzrlib.errors.NoSuchRevision:
33
def greedy_fetch(to_branch, from_branch, revision=None, pb=None):
34
"""Copy a revision and all available ancestors from one branch to another
35
If no revision is specified, uses the last revision in the source branch's
38
from_history = from_branch.revision_history()
39
required_revisions = set(from_history)
41
if revision is not None:
42
required_revisions.add(revision)
44
rev_index = from_history.index(revision)
47
if rev_index is not None:
48
from_history = from_history[:rev_index + 1]
50
from_history = [revision]
51
to_history = to_branch.revision_history()
53
for rev_id in from_history:
54
if not has_revision(to_branch, rev_id):
55
missing.append(rev_id)
58
while len(missing) > 0:
59
installed, failed = to_branch.install_revisions(from_branch,
63
required_failed = failed.intersection(required_revisions)
64
if len(required_failed) > 0:
65
raise bzrlib.errors.InstallFailed(required_failed)
67
note("Failed to install %s" % rev_id)
68
all_failed.update(failed)
70
for rev_id in missing:
72
revision = from_branch.get_revision(rev_id)
73
except bzrlib.errors.NoSuchRevision:
74
if revision in from_history:
78
for parent in [p.revision_id for p in revision.parents]:
79
if not has_revision(to_branch, parent):
80
new_missing.add(parent)
82
return count, all_failed