~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Aaron Bentley
  • Date: 2005-09-29 04:59:47 UTC
  • mto: (1393.1.21) (1185.14.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: aaron.bentley@utoronto.ca-20050929045947-ff08a7f6578f9657
Conflict handling where OTHER is deleted

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
import bzrlib.errors
 
17
from bzrlib.trace import mutter, note
 
18
from bzrlib.branch import Branch
 
19
from bzrlib.progress import ProgressBar
 
20
import sys
 
21
import os
 
22
 
 
23
def has_revision(branch, revision_id):
 
24
    try:
 
25
        branch.get_revision_xml(revision_id)
 
26
        return True
 
27
    except bzrlib.errors.NoSuchRevision:
 
28
        return False
 
29
 
 
30
 
 
31
def greedy_fetch(to_branch, from_branch, revision=None, pb=None):
 
32
    """Copy a revision and all available ancestors from one branch to another
 
33
    If no revision is specified, uses the last revision in the source branch's
 
34
    revision history.
 
35
    """
 
36
    from_history = from_branch.revision_history()
 
37
    required_revisions = set(from_history)
 
38
    all_failed = set()
 
39
    if revision is not None:
 
40
        required_revisions.add(revision)
 
41
        try:
 
42
            rev_index = from_history.index(revision)
 
43
        except ValueError:
 
44
            rev_index = None
 
45
        if rev_index is not None:
 
46
            from_history = from_history[:rev_index + 1]
 
47
        else:
 
48
            from_history = [revision]
 
49
    to_history = to_branch.revision_history()
 
50
    missing = []
 
51
    for rev_id in from_history:
 
52
        if not has_revision(to_branch, rev_id):
 
53
            missing.append(rev_id)
 
54
    
 
55
    count = 0
 
56
    while len(missing) > 0:
 
57
        installed, failed = to_branch.install_revisions(from_branch, 
 
58
                                                        revision_ids=missing,
 
59
                                                        pb=pb)
 
60
        count += installed
 
61
        required_failed = failed.intersection(required_revisions)
 
62
        if len(required_failed) > 0:
 
63
            raise bzrlib.errors.InstallFailed(required_failed)
 
64
        for rev_id in failed:
 
65
            note("Failed to install %s" % rev_id)
 
66
        all_failed.update(failed)
 
67
        new_missing = set() 
 
68
        for rev_id in missing:
 
69
            try:
 
70
                revision = from_branch.get_revision(rev_id)
 
71
            except bzrlib.errors.NoSuchRevision:
 
72
                if revision in from_history:
 
73
                    raise
 
74
                else:
 
75
                    continue
 
76
            for parent in [p.revision_id for p in revision.parents]:
 
77
                if not has_revision(to_branch, parent):
 
78
                    new_missing.add(parent)
 
79
        missing = new_missing
 
80
    return count, all_failed
 
81
 
 
82