/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 bzrlib/fetch.py

  • Committer: Martin Pool
  • Date: 2005-09-13 01:12:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050913011211-47c8a4f18ac40dda
- fix up import
- fix creation of test directory
- shorten test directory names by removing __main__

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
 
 
17
import sys
 
18
import os
 
19
 
 
20
import bzrlib.errors
 
21
from bzrlib.trace import mutter, note
 
22
from bzrlib.branch import Branch
 
23
from bzrlib.progress import ProgressBar
 
24
 
 
25
def has_revision(branch, revision_id):
 
26
    try:
 
27
        branch.get_revision_xml(revision_id)
 
28
        return True
 
29
    except bzrlib.errors.NoSuchRevision:
 
30
        return False
 
31
 
 
32
 
 
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
 
36
    revision history.
 
37
    """
 
38
    from_history = from_branch.revision_history()
 
39
    required_revisions = set(from_history)
 
40
    all_failed = set()
 
41
    if revision is not None:
 
42
        required_revisions.add(revision)
 
43
        try:
 
44
            rev_index = from_history.index(revision)
 
45
        except ValueError:
 
46
            rev_index = None
 
47
        if rev_index is not None:
 
48
            from_history = from_history[:rev_index + 1]
 
49
        else:
 
50
            from_history = [revision]
 
51
    to_history = to_branch.revision_history()
 
52
    missing = []
 
53
    for rev_id in from_history:
 
54
        if not has_revision(to_branch, rev_id):
 
55
            missing.append(rev_id)
 
56
    
 
57
    count = 0
 
58
    while len(missing) > 0:
 
59
        installed, failed = to_branch.install_revisions(from_branch, 
 
60
                                                        revision_ids=missing,
 
61
                                                        pb=pb)
 
62
        count += installed
 
63
        required_failed = failed.intersection(required_revisions)
 
64
        if len(required_failed) > 0:
 
65
            raise bzrlib.errors.InstallFailed(required_failed)
 
66
        for rev_id in failed:
 
67
            note("Failed to install %s" % rev_id)
 
68
        all_failed.update(failed)
 
69
        new_missing = set() 
 
70
        for rev_id in missing:
 
71
            try:
 
72
                revision = from_branch.get_revision(rev_id)
 
73
            except bzrlib.errors.NoSuchRevision:
 
74
                if revision in from_history:
 
75
                    raise
 
76
                else:
 
77
                    continue
 
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)
 
81
        missing = new_missing
 
82
    return count, all_failed
 
83
 
 
84