~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to fetch_ghosts.py

  • Committer: Daniel Silverstone
  • Date: 2005-11-10 20:06:23 UTC
  • mto: This revision was merged to the branch mainline in revision 279.
  • Revision ID: daniel.silverstone@canonical.com-20051110200623-77479964cab3c166
Fix up fetch_ghosts to lock the branches, and to invoke bzr fix if it fetches any ghosts into the tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from bzrlib.branch import Branch
17
17
from bzrlib.fetch import greedy_fetch
18
18
from bzrlib.errors import NoSuchRevision, InstallFailed, BzrCommandError
19
 
def fetch_ghosts(branch):
 
19
def fetch_ghosts(branch, no_fix):
20
20
    """Install ghosts from copies in another branch."""
21
21
    this_branch = Branch.open_containing('.')[0]
22
22
    if branch is None:
29
29
    other_branch = Branch.open_containing(branch)[0]
30
30
    installed = []
31
31
    failed = []
32
 
 
33
 
    # Because iter_ghosts tests for existence after our last fetch
34
 
    # is complete, it won't falsely report an ancestor as a ghost.
35
 
    # Yay iterators!
36
 
    ghosts = iter_ghosts(this_branch)
37
 
    for revision in ghosts:
 
32
    lock_other = this_branch.base != other_branch.base
 
33
    
 
34
    this_branch.lock_write()
 
35
    try:
 
36
        if lock_other:
 
37
            other_branch.lock_read()
38
38
        try:
39
 
            greedy_fetch(this_branch, other_branch, revision)
40
 
            installed.append(revision)
41
 
        except InstallFailed:
42
 
            failed.append(revision)
43
 
    if len(installed) > 0:
44
 
        print "Installed:"
45
 
    for rev in installed:
46
 
        print rev
47
 
    if len(failed) > 0:
48
 
        print "Still missing:"
49
 
    for rev in failed:
50
 
        print rev
 
39
            # Because iter_ghosts tests for existence after our last fetch
 
40
            # is complete, it won't falsely report an ancestor as a ghost.
 
41
            # Yay iterators!
 
42
            ghosts = iter_ghosts(this_branch)
 
43
            for revision in ghosts:
 
44
                try:
 
45
                    greedy_fetch(this_branch, other_branch, revision)
 
46
                    installed.append(revision)
 
47
                except InstallFailed:
 
48
                    failed.append(revision)
 
49
            if len(installed) > 0:
 
50
                print "Installed:"
 
51
                for rev in installed:
 
52
                    print rev
 
53
            if len(failed) > 0:
 
54
                print "Still missing:"
 
55
                for rev in failed:
 
56
                    print rev
 
57
        finally:
 
58
            if lock_other:
 
59
                other_branch.unlock()
 
60
    finally:
 
61
        this_branch.unlock()
51
62
 
 
63
    if not no_fix and len(installed) > 0:
 
64
        from reweave_inventory import cmd_fix
 
65
        cmd_fix().run(".")
 
66
        
52
67
def iter_ghosts(branch):
53
68
    """Find all ancestors that aren't stored in this branch."""
54
69
    seen = set()